Skip to content
pi-c Artifact [b2297a7775]
Login

Artifact [b2297a7775]

Artifact b2297a777525a677b0a95edebbac0929841352369f49bc1fda7435e8a6fc9d83:


pic implementation plan

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:

Stages

  1. 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).
  2. Real provider: done (details below).
  3. Usable tool set and context assembly: next, detailed below. Exit: you complete a real task in it.
  4. Sessions. Resume, fork, compaction; the ctx outbox plus ctx ingest upstream (file the ctx issue with real sample records from stage 3 sessions).
  5. Clients and release. print/JSON mode, then TUI; release qualification with PGO, Fil-C, and MC/DC on the journal and parsers only.

Stage 3: usable tool set and context assembly

Goal: you do real work with pic ask "…" in a project directory, using Pi's default tools, with every tool benchmarked.

Tools match Pi's defaults (read, bash, edit, write) in name, input schema, description, truncation and messages (contracts pinned from reference/pi/packages/coding-agent/src/core/tools). Pi's grep/find/ls are opt-in there and need downloaded ripgrep/fd; bash covers them for now.

Context: system prompt in Pi's section order (preamble, tools, rules, project context, cwd). Project instructions: per directory the first of AGENTS.override.md, AGENTS.md, CLAUDE.md, from the filesystem root down to the workspace, wrapped in <project_instructions path=…>.

Use: pic ask TEXT submits under a fresh key and runs it, with the workspace defaulting to the current directory and the journal to .pic/journal.sqlite; it prints each tool call as it starts and the answer at the end. pic cancel KEY fails an admitted submission. Multi-turn sessions are stage 4.

Benchmarks: make bench-pic on the release build. Per tool: the tool alone (small, medium and large inputs), the durability cost (its two journal commits), and a scripted multi-turn run mixing every tool; median and p95 per call and per turn, plus process start-up. Results go to a per-machine baseline file; a run fails when a median regresses past an agreed tolerance. A tool is not done without its benchmark row.

Tests: contract tests per tool (truncation boundaries, notices, edit errors, overlap, CRLF/BOM), crash cases for edit's plan replay and write's directory creation, the provider suite with the new tool names, Fil-C run.

Status (2026-11-18): tools, context assembly, pic ask/cancel, contract tests (128 checks in make test-pic) and make bench-pic are in; a live pic ask fixed a bug in a scratch project end to end. First baseline (Darwin-arm64, medians): read 1KB 22µs, 10MB 2.4ms; write and edit about 9ms, almost all the durable sync; one journal commit 4.1ms (each tool call makes two); bash true 9ms, down from 60ms after the supervisor stopped sleeping 50ms between exit checks; a whole scripted turn 30-70ms; start-up and check 5ms. Remaining: the Fil-C run, then your real-task exit test.

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:

Journal changes:

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). Live smoke run passed (claude-haiku-5-5, key via doppler run): one turn with two parallel tool calls (write, then exec), then the answer; pic check clean; the key absent from the database. The API added a caller field to tool_use blocks that the fixtures lack; verbatim replay carried it through. Fil-C on hetzner-hel (tools/remote/run.sh mode pic: guarded transient units, verified teardown): the first run caught a varargs over-read in record_reply (six bind types for five values) that ASan and every local test missed; fixed, and run_stmt now rejects a type count that differs from the statement's parameters. The second run passed everything: SSE, decoder and HTTP suites, all crash cases and all provider cases. Stage 2 is complete.

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):

Out of scope: OpenAI-family decoders (a second decoder later on the same framer), prompt caching tuning, message threads, compaction, token counting.