graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
merge: integrate current release fixes with desktop changes
Rach Pradhan0b78abe82036
diff --cc CHANGELOG.mdindex f829f7dc,550ef7fe..e5927470--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,13 -10,22 +10,27 @@@ The release workflow uses a tag's sectihand-written `docs/releases/<tag>.md` wins if present), so keeping this filecurrent is part of cutting a release.+ ## Unreleased++ - Prompt-cache affinity is the git root, or one scratch seed when there is+ no `.git`. Eval sandboxes and worktrees can reuse a warm system+tools+ prefix instead of paying it on every leaf cwd. An offline test fails if+ two scratch trees mint different `prompt_cache_key`s. ADR 0069.+ - `#753`: a background-agent handle survives a recoverable API interruption.+ `agent_output` replays a finished report, or says the launch ended with the+ parent turn, instead of "it may never have started". The ids ride in the+ session file. An ACP API error is a failed turn (saved), not a dead process.+ Backtested as the issue's three-handle sequence (persist → new process →+ `agent_output`) and as three live launches that still replay after reap.+ ADR 0068.+## v0.0.288 (2026-09-06)+- GPT-6 Astra is the default Codex model (`gpt-6-astra`, 272k context).+ ChatGPT login surfaces it; `/model codex` picks it. Mid-turn+ `response.steer`, vision, hosted `tool_search` / `web_search`, and OpenAI+ server-side compact all run on the Responses wire. Astra working guidance+ attaches only while Astra is selected.- Recorded user constraints ride the root prefix as live ledger JSON, includingthe empty set, so a compaction recap cannot invent a recording. A writerefreshes instructions in the same turn and drops a cached Responsesdiff --cc apps/native/app/api/acp/route.tsindex ff1d8f14,35a4248e..a26ec7dd--- a/apps/native/app/api/acp/route.ts+++ b/apps/native/app/api/acp/route.ts@@@ -259,24 -306,51 +259,25 @@@ export async function POST(req: NextReqreturn Response.json({ ok: true });}if (method === "session/prompt") {- const id = slot.nextId++;+ if (slot.streaming) return Response.json({ error: "A turn is already active" }, { status: 409 });+ slot.streaming = true;const encoder = new TextEncoder();- let finished = false;+ let cancelled = false;const stream = new ReadableStream({start(controller) {- const onData = (chunk: Buffer) => {- slot.buf += chunk.toString("utf8");- let nl: number;- while ((nl = slot.buf.indexOf("\n")) >= 0) {- const line = slot.buf.slice(0, nl);- slot.buf = slot.buf.slice(nl + 1);- if (!line.trim()) continue;- let msg: { id?: unknown; method?: string };- try {- msg = JSON.parse(line) as typeof msg;- } catch {- continue;- }- controller.enqueue(encoder.encode(`${line}\n`));- if (msg.id === id && !msg.method) {- finished = true;- slot.child.stdout.off("data", onData);- controller.close();- return;- }- }- };- slot.child.stdout.on("data", onData);- writeLine(slot, {- jsonrpc: "2.0",- id,- method: "session/prompt",- params: { sessionId: slot.sessionId, ...body.params },- });+ void slot.transport.request("session/prompt", { ...body.params, sessionId: slot.sessionId }, 24 * 60 * 60 * 1000,+ line => { if (!cancelled) controller.enqueue(encoder.encode(`${line}\n`)); })+ .then(() => { if (!cancelled) { cancelled = true; controller.close(); } })+ .catch(error => { if (!cancelled) { cancelled = true; controller.error(error); } })+ .finally(() => { slot.streaming = false; });},cancel() {- // #753: reader.cancel() after a completed error/result must not- // raise session/cancel — that stole the next continuation's handles.- if (finished) return;- writeLine(slot, { jsonrpc: "2.0", method: "session/cancel", params: { sessionId: slot.sessionId } });++ if (cancelled) return; // Completed streams must not cancel a later turn.+ cancelled = true;+ try { slot.transport.notify("session/cancel", { sessionId: slot.sessionId }); } catch {}},});- return new Response(stream, {- headers: { "content-type": "application/x-ndjson", "cache-control": "no-store" },- });+ return new Response(stream, { headers: { "content-type": "application/x-ndjson", "cache-control": "no-store" } });}const result = await rpc(slot, method, body.params);return Response.json({ result });diff --cc apps/native/electron/build.shindex a30fc2bf,00000000..f1abc471mode 100644,000000..100644--- a/apps/native/electron/build.sh+++ b/apps/native/electron/build.sh@@@ -1,41 -1,0 +1,42 @@@+#!/usr/bin/env bash+set -euo pipefail+here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+root="$(cd "$here/../../.." && pwd)"++version="${GRAFF_VERSION:-0.0.289}"+ui="$root/apps/native"+out="$root/zig-out/electron"+bundle="$out/Codegraff.app"+cd "$ui"+bun install --frozen-lockfile+if [[ ! -f node_modules/electron/path.txt ]]; then bun node_modules/electron/install.js; fi+bun run --bun build+cd "$root"- zig build graff -Doptimize=ReleaseFast++zig build graff -Doptimize=ReleaseFast -Dversion="$version"+mkdir -p "$out"+# This directory is an isolated build artifact, never the installed application.+rm -rf "$bundle"+ditto "$ui/node_modules/electron/dist/Electron.app" "$bundle"+resources="$bundle/Contents/Resources"+mkdir -p "$resources/app" "$resources/native"+cp "$here/"*.cjs "$resources/app/"- printf '{"name":"codegraff","productName":"Codegraff","version":"0.0.288","main":"main.cjs"}\n' > "$resources/app/package.json"++printf '{"name":"codegraff","productName":"Codegraff","version":"%s","main":"main.cjs"}\n' "$version" > "$resources/app/package.json"+ditto "$ui/.next/standalone" "$resources/ui"+ditto "$ui/.next/static" "$resources/ui/.next/static"+[[ ! -d "$ui/public" ]] || ditto "$ui/public" "$resources/ui/public"+rm -rf "$resources/ui/node_modules/@img"+cp "$(command -v bun)" "$resources/bun"+cp "$root/zig-out/bin/graff" "$resources/graff"+xcrun swiftc -O -emit-library -module-name GraffActivity -target arm64-apple-macosx14.0 \+ "$here/native/Activity.swift" "$here/native/ComputerUse.swift" -o "$resources/native/libGraffActivity.dylib" \+ -Xlinker -install_name -Xlinker @rpath/libGraffActivity.dylib+xcrun clang -O2 -bundle -undefined dynamic_lookup -mmacosx-version-min=14.0 \+ -I "$ui/node_modules/node-api-headers/include" "$here/native/activity.c" \+ -L "$resources/native" -lGraffActivity -Wl,-rpath,@loader_path -o "$resources/native/activity.node"+/usr/libexec/PlistBuddy -c 'Set :CFBundleIdentifier dev.codegraff.electron.local' "$bundle/Contents/Info.plist"+/usr/libexec/PlistBuddy -c 'Set :CFBundleName Codegraff' "$bundle/Contents/Info.plist"+/usr/libexec/PlistBuddy -c 'Set :CFBundleDisplayName Codegraff' "$bundle/Contents/Info.plist" 2>/dev/null || true+cp "$root/zig-out/native-local/Codegraff.app/Contents/Resources/icon.icns" "$resources/electron.icns" 2>/dev/null || true+# Local development signing; production notarization remains a separate release step.+codesign --force --deep --sign - "$bundle"+codesign --verify --deep --strict "$bundle"+echo "$bundle"diff --cc docs/adr/0070-electron-browser-and-native-panels.mdindex 5e86d273,00000000..7313ec02mode 100644,000000..100644--- a/docs/adr/0070-electron-browser-and-native-panels.md+++ b/docs/adr/0070-electron-browser-and-native-panels.md@@@ -1,44 -1,0 +1,44 @@@- # 0068. Electron renders browser pages; graff owns coding++# 0070. Electron renders browser pages; graff owns coding++Status: accepted 2026-09-06 for the local desktop trial++## Context++The desktop interface already uses React and ACP. Its browser pane ran a+separate Chrome through Kuri and displayed repeated JPEG screenshots inside+WebKit. That duplicated rendering engines and required forwarding input.++## Decision++The local Run entrypoint builds an Electron application. The existing React+interface and Bun-hosted production routes remain; coding and tool execution+remain in `graff acp`, over the existing JSON-RPC transport. No agent loop moves+into Electron. Release packaging for the earlier shell remains available.++Browser pages render directly in sandboxed, isolated `WebContentsView`s using+a separate persistent session from the application. There is no browser+prewarm and no screenshot polling. Empty chats do not start coding agents.+Closed views are destroyed. Hidden views release their renderers after one+minute and retain their URL; rapid switching retains at most three live views.+Reopening a suspended page reloads it, so unsaved page forms are not preserved.++The renderer's IPC surface permits browser navigation, geometry, picking,+and Activity only. External pages never receive that surface or the desktop+API token. Graff can act on a pinned page through an authenticated loopback+endpoint; page content remains untrusted. Browser snapshots are on demand.++SwiftUI is limited to a native Activity sheet hosted through a small Node-API+bridge. Standard SwiftUI controls and availability-gated macOS Liquid Glass+provide the native surface. The sheet samples on opening, not on an idle timer.++## Consequences++Electron owns Chromium distribution and process integration. Bun remains the+build tool and route-server runtime; Electron itself uses its bundled Node.+The app needs Chromium updates and a macOS native build step. Memory and CPU+claims require measurements with matching pages, tools, and active work; RSS+sums include shared pages. A browser engine change alone is not a memory bound.++Validation covers direct navigation, isolated page code, rejected unauthenticated+requests, pins, browser automation, suspend/reopen/close, real ACP initialization,+and native sheet loading. No provider calls are required for these checks.diff --cc docs/adr/0071-desktop-tools-and-macos-computer-use.mdindex cf849162,00000000..1245d573mode 100644,000000..100644--- a/docs/adr/0071-desktop-tools-and-macos-computer-use.md+++ b/docs/adr/0071-desktop-tools-and-macos-computer-use.md@@@ -1,40 -1,0 +1,40 @@@- # 0069. Desktop tools use the app's browser and a native macOS bridge++# 0071. Desktop tools use the app's browser and a native macOS bridge++Status: accepted for the local desktop trial++## Decision++The Electron desktop contributes a Bun stdio MCP server to graff's generated+runtime configuration. It offers `browser` and `computer`; graff retains the+model loop, tool orchestration, and existing MCP consent policy. Disabling MCP+for a workspace disables these tools too. User configuration files are not+rewritten. The endpoint and launch token are inherited by the ACP process,+not exposed to browser pages. Images remain MCP image content blocks.++Browser actions target the embedded Chromium view. Agent-opened pages reveal+their matching chat's browser pane. Kuri startup and the legacy browser API+are disabled inside this desktop host; the older web/AppKit host remains+separate. Find and zoom are available in the browser toolbar.++macOS control uses public Accessibility and Core Graphics APIs through a+small Swift/Node-API bridge inside the application. This is independent of+the signed external Codex plugin adapter in ADR 0036, which is unchanged.+Computer use starts disabled each launch. Only the app's native menu can+enable it or request OS permissions; agent tools can report permission status+but cannot grant access. The menu can disable it without restarting graff.++Snapshots are bounded and assign expiring element references. Input actions+require an explicit frontmost target PID; coordinate actions verify the app+under the point. Secure fields require user interaction. App and page text+are untrusted data. Screenshots are on demand, with display/image geometry+for coordinate scaling. There is no recording loop or persistent capture+worker. Native Accessibility references are bounded to the latest snapshot.++## Validation and limitations++Packaging compiles the bridge against the macOS SDK. Tests cover MCP discovery,+chat routing, image content, rejected actions, browser interaction, legacy+browser rejection, and native app discovery. Full input/capture verification+requires the user to grant macOS Accessibility and Screen Recording permissions.+Locally signed rebuilds can require renewed OS permission approval. Other+operating systems and distribution signing remain outside this trial.diff --cc docs/adr/0072-gui-profiler-exports-measurements-only.mdindex a81d9e7a,00000000..908192b3mode 100644,000000..100644--- a/docs/adr/0072-gui-profiler-exports-measurements-only.md+++ b/docs/adr/0072-gui-profiler-exports-measurements-only.md@@@ -1,24 -1,0 +1,24 @@@- # 0070. GUI profiling exports measurements only++# 0072. GUI profiling exports measurements only++Status: accepted for the local desktop trial++## Decision++Desktop profiling is off by default, bounded to ten minutes, and callable+through the local MCP adapter or native Performance menu. It records interval+process-tree CPU and RSS, main-loop delay, renderer long-task durations, and+allowlisted navigation/action/failure events. Baseline and candidate phases+are fixed labels; retained samples and events are bounded.++Feedback exports use an explicit measurement schema. No raw event objects,+prompts, model/account/session identifiers, paths, URLs, titles, screenshots,+exception text or free-form annotations are serialized. A native save dialog+writes a reviewable local JSON artifact. There is no automatic upload endpoint.++## Consequences++A report supports performance comparisons without reproducing user content.+It cannot diagnose failures that require a content-specific reproduction.+CPU samples may miss short-lived children, and RSS can double-count shared+pages. Tests enforce the allowlist and bounded retention with sensitive input+fixtures. Sending a report remains a separate user-directed action.diff --cc docs/adr/0073-acp-stream-and-shared-review.mdindex 92a11aff,00000000..a50bef05mode 100644,000000..100644--- a/docs/adr/0073-acp-stream-and-shared-review.md+++ b/docs/adr/0073-acp-stream-and-shared-review.md@@@ -1,27 -1,0 +1,27 @@@- # 0071 — ACP response routing and shared review++# 0073 — ACP response routing and shared review++Status: Accepted++## Context++Catalog queries and prompt streams share a graff process. Competing stdout+readers can consume each other's replies and lose assistant notifications.+Workspace review also needs to show edits from every actor, rather than only+the files mentioned in one conversation.++## Decision++Use one ACP stdout reader with request-ID routing and explicit notification+subscriptions. Reject overlapping prompt streams, settle pending requests on+process exit, and stop writing to cancelled HTTP streams.++Expose read-only `graff/changes` status and diff requests. The GUI reviews Git+working trees, refreshes only while visible, and offers staged/unstaged scopes,+worktree selection and recent commits. Uncommitted authorship is not inferred.++## Consequences++Catalog refreshes cannot steal response bytes. Git supplies shared file state,+but separate worktrees must be selected individually and remote pull-request+synchronization remains a separate feature. Diff output and subprocess time+are bounded; external diff drivers and text conversion are disabled.diff --cc docs/adr/README.mdindex cd75338d,878e3ae0..30d23f1e--- a/docs/adr/README.md+++ b/docs/adr/README.md@@@ -78,10 -78,8 +78,12 @@@ record only when you need the evidence| [0065](0065-stop-bounded-prose-repetition.md) | Stop bounded lexical prose loops before delivery without user cancellation, transport retries, or completion nudges. || [0066](0066-publication-policy-and-ledger-authority.md) | Publication safeguards survive custom prompts; recaps cannot change ledger authority, and constraint writes refresh active prompts atomically. || [0067](0067-recorded-constraints-are-ledger-state.md) | Recorded constraints are live ledger JSON in the root prefix; recap prose is not authority, and a write refreshes instructions in the same turn. |- | [0068](0068-electron-browser-and-native-panels.md) | The local Electron desktop renders browser pages directly, keeps coding in graff ACP, and hosts narrow SwiftUI panels through a native bridge. |- | [0069](0069-desktop-tools-and-macos-computer-use.md) | Desktop MCP controls embedded Chromium and a user-enabled native macOS bridge; coding stays in graff. |- | [0070](0070-gui-profiler-exports-measurements-only.md) | GUI profiling is bounded and off by default; feedback exports contain allowlisted measurements with no automatic upload. |- | [0071](0071-acp-stream-and-shared-review.md) | One ACP stdout reader routes responses; shared review reads Git working trees without inferring edit authorship. |+ | [0068](0068-background-agent-handles-survive-interrupt.md) | Background-agent ids are a session ledger; an interrupted parent turn must not report them as never started (#753). |+ | [0069](0069-cache-affinity-is-the-git-root.md) | Prompt-cache affinity is the git root (or a shared scratch seed), not the leaf cwd. |++| [0070](0070-electron-browser-and-native-panels.md) | The local Electron desktop renders browser pages directly, keeps coding in graff ACP, and hosts narrow SwiftUI panels through a native bridge. |++| [0071](0071-desktop-tools-and-macos-computer-use.md) | Desktop MCP controls embedded Chromium and a user-enabled native macOS bridge; coding stays in graff. |++| [0072](0072-gui-profiler-exports-measurements-only.md) | GUI profiling is bounded and off by default; feedback exports contain allowlisted measurements with no automatic upload. |++| [0073](0073-acp-stream-and-shared-review.md) | One ACP stdout reader routes responses; shared review reads Git working trees without inferring edit authorship. |## When to write onediff --cc src/cli.zigindex 5e54fe53,445c4a2b..db116778--- a/src/cli.zig+++ b/src/cli.zig@@@ -21,8 -21,11 +21,12 @@@ const harness_version = root.harness_vepub const changelog_text =\\What's new\\──────────+ \\0.0.289+ \\ • background-agent handles survive an interrupted API turn (#753)+ \\ • prompt-cache affinity is the git root, not the leaf cwd+ \\\\0.0.288+ \\ • GPT-6 Astra is the default Codex model: mid-turn steer, vision, hosted search, OpenAI compact\\ • Gemini is a first-class provider on Google's Interactions API\\ • recorded constraints ride the prefix as ledger JSON; recaps cannot invent them (#738)\\ • a second paste in the same batch no longer sends on its first newline (#737)