graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Merge origin/release/v0.0.276 into cursor/rlm-default-4ffc
Cursor Agent2c5cf7a5b877
diff --cc CHANGELOG.mdindex eaeccd8f,7f7349ee..1ef451c1--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -12,26 -12,26 +12,46 @@@ current is part of cutting a release## v0.0.276 (2026-08-25)+- `rlm` (Zhang/Khattab RLM + alexzhang13 spec-ptc, Zig — not Prime's+ IPython kernel) is the default loop. `--old` / `--no-rlm` (or+ `GRAFF_OLD=1` / `GRAFF_RLM=0`) restore the structured-only catalog.+ `--rlm` stays as an explicit on. Last CLI flag wins; env does not+ clobber `--old` / `--rlm`.+- The spec stays folded behind `load_tool_schemas`. `--schema` / the+ 64-cell tool-catalog kernel do not grow a new tool.+- Prompt-cache max: `GRAFF_STABLE_CATALOG` is on by default so+ `load_tool_schemas` (including `rlm`) does not rewrite tools JSON.+ Spawned subagents inherit it. Children share four role-lane+ `x-grok-conv-id` / `prompt_cache_key` values (official xAI sticky+ routing — same id, same server). rlm's `subagent("task")` uses+ label `subagent`, so siblings hit one lane. They do not reuse the+ root id. Opt out of stable catalog with `GRAFF_STABLE_CATALOG=0`+ or `GRAFF_NO_STABLE_CATALOG=1`.+- Measured default-RLM vs `--old` on grok-4.6 SuperGrok (one `rlm`+ suite rep): both 5/5, $0.0000 / $0.0000 (flat-rate). Persist+ `bind-reuse` 99.6s / 135k in → 39.2s / 25.3k in. Suite totals+ 161s / 203k in → 136s / 105k in. Scatter wall is a wash this rep+ (#619's 86.8s → 23.7s did not reproduce). See ADR 0022.+ - Root foreground `bash` no longer waits forever: after 120s (or `timeout`+ ms) a still-running command is moved to the background and the model+ gets a job id, matching grok-build. Esc still kills; the cancelled+ result tells the model to use `run_in_background`. Subagents keep the+ #93 120s kill. (#620)+ - Kimi Coding keeps User-Agent `graff/<version>` (Moonshot forbids spoofing)+ and matches kimi-code's X-Msh device fields: hostname, `Windows ${release}+ ${arch}` / `macOS ${product} ${arch}`, kernel `os.release()` (#617)+ - Codex `session_id` header is the same value as `prompt_cache_key` (openai/codex+ ModelClient default), not a per-process random UUID+ - Codex high-effort thinking no longer trips the 45s stall watchdog after+ `in_progress` (encrypted reasoning is silent). A stall notice no longer says+ "ending turn" while reconnect still has retries. Interactive sessions print a+ dim `graff update` line when GitHub has a newer release.++ ## v0.0.275 (2026-08-24)++ - OpenRouter requests carry app attribution (`categories: cli-agent, programming-app`).+ - TUI: Esc with a draft in the composer never kills a live turn.+ - Agent retries degenerate empty completions and keep-alive-only bodies.## v0.0.274 (2026-08-23)diff --cc docs/adr/0026-foreground-bash-auto-backgrounds.mdindex 00000000,efd067d7..b19fda6bmode 000000,100644..100644--- a/docs/adr/0026-foreground-bash-auto-backgrounds.md+++ b/docs/adr/0026-foreground-bash-auto-backgrounds.md@@@ -1,0 -1,37 +1,37 @@@-# 0022. Foreground bash auto-backgrounds after 120s, it is not killed++# 0026. Foreground bash auto-backgrounds after 120s, it is not killed++ Status: accepted 2026-08-25++ ## Context++ [#93](https://github.com/justrach/codegraff/issues/93) gave *subagent* bash a+ 120s kill because those children have no TTY. The root was left unbounded:+ "a human is watching and may want a long build." #607 added a dim+ `· bash still running ·` pulse so a long command did not *look* hung.++ [#620](https://github.com/justrach/codegraff/issues/620) measured the leftover:+ a durability drill sat in that pulse for 83 minutes. The model never woke.+ Esc killed the process group; the model retried the same foreground hang.++ [xai-org/grok-build](https://github.com/xai-org/grok-build) `BashTool` waits+ 120s (`timeout` default), then *promotes* a still-running command to a+ background task (`auto_background_on_timeout`) and returns a job id plus+ partial output. A real compile keeps running. The model gets the turn back.++ ## Decision++ - Root foreground `bash` waits up to 120s (or `timeout` ms, capped at 10h).+ - If the child is still running, it is moved onto the existing job registry.+ The model receives a job id. `bash_output` / `bash_kill` / `/jobs` work as+ they do for `run_in_background: true`. The process is not killed.+ - Subagent `bash` still *kills* at 120s (#93). Children have no job UI.+ - Esc during the foreground wait still kills the process group. The cancelled+ result tells the model to restart with `run_in_background: true`.+ - ADR 0010 is unchanged: `bash_output(wait_ms>0)` waits for exit, not a poll.++ ## Consequences++ A 20-minute compile or a forgotten server no longer bricks the turn. The+ heartbeat (#607) still fires during the 120s wait. Root bash output that+ finishes inside the wait is interleaved stdout+stderr (the job buffer),+ not the old split `[stderr]` block — same shape as `bash_output`.diff --cc docs/adr/0027-kimi-identity-is-graff.mdindex 00000000,88edfec1..80878557mode 000000,100644..100644--- a/docs/adr/0027-kimi-identity-is-graff.md+++ b/docs/adr/0027-kimi-identity-is-graff.md@@@ -1,0 -1,40 +1,40 @@@-# 0023. Kimi Coding identity is graff, device fields follow kimi-code++# 0027. Kimi Coding identity is graff, device fields follow kimi-code++ Status: accepted 2026-08-25++ ## Context++ [#617](https://github.com/justrach/codegraff/issues/617) is a Windows 5xx on+ `graff --model kimi` after a successful `graff login kimi`. The first-party+ Kimi CLI on the same machine succeeds.++ [MoonshotAI/kimi-code](https://github.com/MoonshotAI/kimi-code)+ `packages/oauth/src/identity.ts` sends:++ - User-Agent `kimi-code-cli/<semver>`+ - `X-Msh-Platform: kimi_code_cli`+ - `X-Msh-Device-Name`: hostname+ - `X-Msh-Device-Model`: `Windows ${release()} ${arch}` / `macOS ${productVersion} ${arch}`+ - `X-Msh-Os-Version`: `os.release()` (kernel), not the Zig OS tag++ Moonshot's third-party docs forbid spoofing User-Agent. Graff already used the+ Kimi Code OAuth client and `kimi_code_cli` platform (login works). It sent+ `User-Agent: graff/<version>` with `X-Msh-Device-Name: graff` and Zig tags+ (`windows x86_64`, `os_version=windows`) that do not match kimi-code's Node+ shapes. That Windows-only mismatch is the header gap #617 can actually close+ without impersonating the first-party CLI.++ ## Decision++ - User-Agent stays `graff/<version>`. Do not send `kimi-code-cli/` or+ `claude-code/`.+ - `X-Msh-Platform` stays `kimi_code_cli` because that is the OAuth client+ graff already uses.+ - Device headers match kimi-code's field shapes: hostname, Node `os.arch()`+ names (`x64`/`arm64`), `Windows ${release} ${arch}` / `macOS ${product} ${arch}`,+ kernel `os.release()`.++ ## Cost++ A future Kimi allowlist that requires `kimi-code-cli` in User-Agent will still+ fail honestly. Spoofing would be a membership violation; this ADR forbids it.diff --cc docs/adr/0028-codex-session-id-is-the-cache-key.mdindex 00000000,6682e189..5c4da58dmode 000000,100644..100644--- a/docs/adr/0028-codex-session-id-is-the-cache-key.md+++ b/docs/adr/0028-codex-session-id-is-the-cache-key.md@@@ -1,0 -1,31 +1,31 @@@-# 0024. Codex session_id is the prompt_cache_key++# 0028. Codex session_id is the prompt_cache_key++ Status: accepted 2026-08-25++ ## Context++ [openai/codex](https://github.com/openai/codex) `ModelClient::prompt_cache_key`+ defaults to `CodexResponsesMetadata.session_id`. The same string is sent as the+ `session_id` header (`build_session_headers`). A hit needs that key plus an+ identical instructions/tools prefix.++ Graff already sent a durable cwd `prompt_cache_key` (ADR 0009). The ChatGPT+ `session_id` header was a **per-process UUIDv4**. Trajectories of a live Codex+ session (`gpt-5.6-sol`) still recorded multi-million `cache_read_tokens` on+ later calls in a turn, and 0/0 on turns whose usage never landed in `g_cost`.+ The first-party client never splits those two ids.++ ## Decision++ - Codex `session_id` (HTTP extra headers and the WS handshake) is the same+ value as the Responses body's `prompt_cache_key` (`requestCacheKey`:+ project root for main/`/btw`, four role lanes for children).+ - `sessionId()` stays a per-process UUIDv4 for the persisted graff session+ record. It is not the ChatGPT cache partition.+ - `store: false` is unchanged (openai/codex also sends `store: false`).++ ## Cost++ ChatGPT session telemetry now groups by project/lane rather than process.+ That is the cache contract. Do not restore a random `session_id` header+ without measuring a live `cached_tokens` regression.diff --cc docs/adr/README.mdindex 773cc460,6c315819..9f5a841a--- a/docs/adr/README.md+++ b/docs/adr/README.md@@@ -32,10 -32,9 +32,13 @@@ record only when you need the evidence| [0019](0019-codedb-one-shot-over-hop-chains.md) | Advertise only `context` / `around` / `callpath` / `list_dir` / `status`; hop verbs stay callable, not on the menu. || [0020](0020-transcript-shows-decisions.md) | Transcript shows decisions: one interpreted tool line, collapsed infra failures, compact WORKING; raw output is `/debug` / TUI-fold. || [0021](0021-transcript-is-the-task-not-the-bus.md) | Transcript is the task, not the event bus: bookkeeping is silent, todos are WORKING, subagents are scouts. |-| [0022](0022-foreground-bash-auto-backgrounds.md) | Root foreground `bash` auto-backgrounds after 120s (or `timeout` ms); it is not killed. Subagents still kill at 120s (#93). |-| [0023](0023-kimi-identity-is-graff.md) | Kimi Coding User-Agent is `graff/<version>`, not a spoofed `kimi-code-cli` token. X-Msh device fields follow kimi-code's shapes. |-| [0024](0024-codex-session-id-is-the-cache-key.md) | Codex HTTP/WS `session_id` is the `prompt_cache_key` (openai/codex ModelClient default), not a per-process random UUID. |+| [0022](0022-rlm-is-opt-in-speculative-ptc.md) | `rlm` (Alex Zhang spec-ptc + RLM, Zig) is the default loop. `--old` restores structured-only. Prime persist + `subagent()` only — no IPython. |+| [0023](0023-codex-subagent-is-sidecar-not-v8.md) | Codex check: take sidecar-vs-critical-path spawn prompts; reject V8 Code Mode, extra spawn tools, and parent-history fork. |+| [0024](0024-three-harness-compare-prompt-subagent-rss.md) | Steal short child briefs + sidecar spawn; `print(read_file)` returns the file; `-p` skips the shared-tree checkpoint (evals are sibling sandboxes); reject rlm-only catalog, grok heap, Harbor. |+| [0025](0025-io-uring-is-not-the-process-io.md) | Process Io stays Zig `Threaded`. spec-ptc is already the default loop (ADR 0022). Do not take ublk or switch `main` to `std.Io.Uring`. |++| [0026](0026-foreground-bash-auto-backgrounds.md) | Root foreground `bash` auto-backgrounds after 120s (or `timeout` ms); it is not killed. Subagents still kill at 120s (#93). |++| [0027](0027-kimi-identity-is-graff.md) | Kimi Coding User-Agent is `graff/<version>`, not a spoofed `kimi-code-cli` token. X-Msh device fields follow kimi-code's shapes. |++| [0028](0028-codex-session-id-is-the-cache-key.md) | Codex HTTP/WS `session_id` is the `prompt_cache_key` (openai/codex ModelClient default), not a per-process random UUID. |## When to write onediff --cc docs/releases/v0.0.276.mdindex 1f699be2,00000000..0d596425mode 100644,000000..100644--- a/docs/releases/v0.0.276.md+++ b/docs/releases/v0.0.276.md@@@ -1,29 -1,0 +1,36 @@@+# v0.0.276 (2026-08-25)++RLM + mid-stream spec-ptc is the default harness loop.++`graff` now advertises the `rlm` REPL (persistent binds, `subagent()`,+`llm_query`, speculated host calls as the script streams). `--old` /+`--no-rlm` restore the previous structured-only catalog.++This is the Zig port of [alexzhang13/spec-ptc](https://github.com/alexzhang13/spec-ptc)+and [alexzhang13/rlm](https://github.com/alexzhang13/rlm). Prime Agent's+IPython/ZeroMQ kernel is not in the process; persist + `subagent("task")`+are the only Prime-shaped pieces, still in Zig.++`--schema` and the 64-cell tool-catalog kernel do not list `rlm` as a+new always-on tool — it still folds behind `load_tool_schemas`.++Prompt-cache max is on: the catalog stays byte-identical after a load+(`GRAFF_STABLE_CATALOG` default). Children inherit that. Sibling+`subagent()` calls share one `x-grok-conv-id` / `prompt_cache_key` lane+(official xAI sticky routing) so they land on the server that already+has the child prefix. They do not reuse the root id. Opt out of stable+catalog with `GRAFF_STABLE_CATALOG=0`.++Measured 2026-08-25 on grok-4.6 SuperGrok (`graff-dev-old` vs default+`graff-dev`, one `rlm` suite rep, ADR 0022): both **5/5**, **$0.0000**+both ways (subscription, not in $). Persist `bind-reuse` **99.6s /+135k in → 39.2s / 25.3k in**. Suite **161s / 203k in → 136s / 105k+in**. Scatter wall was a wash this rep; the #619 86.8s → 23.7s win+was one-rep `needle-files` variance.++++Also in this cut (merged from `release/v0.0.276`): root foreground++`bash` auto-backgrounds after 120s instead of waiting forever (ADR++0026 / #620); Kimi Coding keeps User-Agent `graff/<version>` and++matches kimi-code device headers (ADR 0027 / #617); Codex++`session_id` is the `prompt_cache_key` (ADR 0028), and high-effort++thinking no longer trips the stall watchdog.diff --cc src/cli.zigindex 650b128a,8dc7cdd9..c4ce6c95--- a/src/cli.zig+++ b/src/cli.zig@@@ -22,8 -22,11 +22,13 @@@ pub const changelog_text\\What's new\\──────────\\0.0.276+ \\ • rlm (RLM + mid-stream spec-ptc) is the default loop; --old / --no-rlm restores structured-only+ \\ • prompt-cache max: stable catalog is the default (loads no longer rewrite tools JSON); children share prefix lanes+ \\ • foreground bash auto-backgrounds after 120s instead of waiting forever (#620)+ \\ • Kimi identity: graff/<version> User-Agent; device headers match kimi-code (#617)+ \\ • Codex session_id header matches prompt_cache_key (openai/codex)+ \\ • Codex thinking silence uses the full stall budget; stall notice is honest+ \\ • REPL/TUI prints a dim line when a newer graff release is available\\\\0.0.275\\ • OpenRouter requests carry app attribution (categories: cli-agent, programming-app)