Replaces the earlier 11-stage plan (preserved in history at check-in 11f47eadde20), which assumed an embedded context core and front-loaded qualification work. Decisions in force:
- The harness owns its own libfossil-hosted SQLite database (
pic_*tables). ctx is optional and later receives finished turns through an outbox and actx ingestcommand added upstream in ctx. Nothing in the harness waits on ctx. - C core and tests; Make/POSIX shell orchestration; Python frozen at its current helpers.
- Dependencies: vendored libfossil + SQLite, zlib and BearSSL only, each pinned file by file (
vendor/*/SHA256SUMS). The binary links only libc, libm and pthread. No libcurl, no system TLS, no iconv, no-ldl. - Credentials: API keys and provider-sanctioned OAuth only, never subscription tokens; a separate credential project after stage 2 (
docs/credential-project.md). - Every stage ends in a command you can run and a test that crashes it. Qualification extras (MC/DC, Fil-C, PGO, contract registry, remote lifecycle) come back only when a stage needs them.
Stages
- Durable loop: done. Merged at
f4faaeff6422. Journal, idempotent admission, replay-safe vs replay-unsafe effects, supervised exec, single-writer fencing, 26-case crash suite (make test-pic). - Real provider: next, detailed below.
- Usable tool set and context assembly. read/edit/grep/ls, output limits, cancellation, system prompt and project instructions. Exit: you complete a real task in it.
- Sessions. Resume, fork, compaction; the ctx outbox plus
ctx ingestupstream (file the ctx issue with real sample records from stage 3 sessions). - Clients and release. print/JSON mode, then TUI; release qualification with PGO, Fil-C, and MC/DC on the journal and parsers only.
Stage 2: real provider
Goal: pic run --provider anthropic completes a small task against the live API with the existing write/exec tools, and survives a crash at any point, including mid-stream.
Protocol: Anthropic Messages, streaming SSE, anthropic-version: 2026-10-21. Default model claude-opus-5-5, overridable with --model. That model always thinks: thinking is omitted. max_tokens 64000. Tool inputs are validated by the tools themselves. stop_reason refusal fails the submission, never a tool run; max_tokens without tool calls ends as the answer; pause_turn continues. Deferred until needed: eager_input_streaming, server-side fallbacks, output_config.effort.
Modules:
net.c: TCP plus TLS 1.2 on vendored BearSSL (adapted from suit): trust anchors from$SSL_CERT_FILEor the system bundle, deadline-bounded name lookup and connect, plain HTTP to loopback only. The only file that includes BearSSL, so the TLS library can be swapped (mbedTLS is the fallback if the API drops TLS 1.2).http.c: strict HTTP/1.1 response parser (fuzzed) and one-shot POST.provider_anthropic.c: request from the journal; retries 429/5xx/529 and connection errors withRetry-Afterand capped backoff, only before a stream starts. No retries after any byte of a successful stream.sse.c: provider-neutral SSE framer (event/data lines, multi-line data, comments, CR/LF variants, size caps). Pure function over bytes; no I/O.anthropic.c: event decoder (message_start, content_block_start/delta/stop, message_delta, message_stop, ping, error) into an assistant message; request builder.- JSON uses the vendored SQLite JSON functions (
json_extract,json_object,json_valid) on an in-memory connection, not a hand-written parser. SQLite's JSON is already in the binary and fuzzed upstream, and ctx uses the same approach. The hand-written trust boundary is the SSE framer and the event state machine.
Journal changes:
- Assistant entries store the provider's raw
contentarray verbatim. Requests replay it byte for byte, which keeps thinking signatures valid and the history append-only. - One assistant message may carry several tool calls: effects gain an ordinal per assistant entry, and the next request sends every tool_result for that turn in one user message.
- New
pic_generationrow per provider request:intent → started → done | failed, attempt count, usage, stop reason, provider request id.
Mid-stream crash semantics: a provider request is a billed, replay-unsafe effect, but it has no outside-world side effect, so re-requesting is safe; it only costs money. Decision: the partial stream is never journaled. On recovery, a started generation is marked failed (interrupted) and the turn is re-requested, up to 3 attempts per turn, after which the submission stops with an error. Attempts and any usage seen are recorded, so the cost of a crash is visible. Incremental persistence of partial output is deferred to stage 5, where clients need it.
Status (2026-11-18): everything above is built and tested against a local fake server (make test-pic: 37 crash cases, 14 provider cases including a crash mid-stream and the key-leak test, plus SSE/decoder/HTTP unit tests and two fuzz targets). TLS verified against api.anthropic.com up to authentication. Remaining: the live smoke run (needs a Console API key in Doppler) and the Fil-C run on hetzner-hel.
Credentials: the API key comes from ANTHROPIC_API_KEY only, read by src/cred.c (the credential project's helper later). It lives in memory for one request, is never journaled, logged, or put in error text, and request headers are never stored. A test runs with a sentinel key and fails if the bytes appear anywhere in the database, WAL, or output.
Tests (exit criteria):
- A local fake server (C, test-only, plain HTTP on 127.0.0.1) replays recorded SSE fixtures: text answer; single and parallel tool calls; thinking blocks with signatures;
refusal;max_tokens; error event; 429 then success; 5xx exhaustion; connection cut mid-stream; malformed frames. - Crash points: after generation started; mid-stream (pic killed while the server is streaming); after generation committed. Recovery re-requests; the crash suite verifies attempts, final state, and no duplicate tool runs.
- Fuzz targets for the SSE framer and the event decoder, seeded from the fixtures; saved crashes become regressions.
- Sentinel-key leak test as above.
make test-picstays green; sanitizer build for all of the above.- One live smoke run against the real API once the fake-server suite passes: a small task, expected cost cents, run with your approval of the key source.
Out of scope: OpenAI-family decoders (a second decoder later on the same framer), prompt caching tuning, message threads, compaction, token counting.