Skip to content

feat(pi): wire project-context loader into system prompt (Unit A) - #8

Merged
srdjan merged 1 commit into
mainfrom
feat/unit-a-context-loader
Apr 20, 2026
Merged

feat(pi): wire project-context loader into system prompt (Unit A)#8
srdjan merged 1 commit into
mainfrom
feat/unit-a-context-loader

Conversation

@srdjan

@srdjan srdjan commented Apr 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds packages/pi/src/context/loader.zig with loadProjectContext(allocator) that walks cwd -> root, collects AGENTS.md and CLAUDE.md at each ancestor, and emits them in root-to-cwd order (outermost first, cwd last; within a directory AGENTS.md precedes CLAUDE.md).
  • Enforces a 32 KiB per-file cap and a 128 KiB combined budget, signalled in-band via labeled truncation markers. Reads are capped at read time via readFileCapped so large files never allocate beyond the cap.
  • Wires the loader into agent.zig::initFromEnvWithRegistry so the live Anthropic backend receives workspace context alongside the compiler snapshot, passed through expert_persona.buildSystemPromptWithContext which already applies the prompt-injection delimiters and data-not-instructions guardrail.
  • Registers the new file in packages/pi/src/tests.zig.

Plan: /Users/srdjans/.claude/plans/study-the-plan-provided-clever-wadler.md (Batch 2, Unit A).

Test plan

  • zig build test-expert-app — new tests in loader.zig pass
  • zig build test — full suite green
  • zig build — clean compile
  • printf 'help\nquit\n' | timeout 10 ./zig-out/bin/zigts expert — prints /verify and Registered tools:
  • printf '/meta\nquit\n' | timeout 10 ./zig-out/bin/zigts expert — prints "compiler_version"

Loader tests cover: returns null on empty tree, reads single AGENTS.md, nested root-to-cwd ordering with AGENTS.md-before-CLAUDE.md, per-file truncation marker when a 64 KiB file is fed in, and combined-budget truncation marker when 6x30 KiB files are stacked. Tests use a /tmp-rooted scratch dir rather than std.testing.tmpDir so the walker doesn't pick up this repo's own AGENTS.md / CLAUDE.md.

🤖 Generated with Claude Code

Add a pure loader that walks from cwd up to filesystem root, collects
AGENTS.md and CLAUDE.md at each ancestor, and emits them in root-to-cwd
order with per-file (32 KiB) and total (128 KiB) budgets. Feed the
result to expert_persona.buildSystemPromptWithContext so the live
Anthropic backend sees workspace context alongside the compiler
snapshot, guarded by the existing prompt-injection delimiters.

Plan: /Users/srdjans/.claude/plans/study-the-plan-provided-clever-wadler.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@srdjan
srdjan merged commit fdf9919 into main Apr 20, 2026
@srdjan
srdjan deleted the feat/unit-a-context-loader branch April 20, 2026 12:55
srdjan added a commit that referenced this pull request Jul 12, 2026
… caching, Sonnet default, exit codes

Wave 1 of the expert-analysis recommendations (#1, #2, #4, #5, #8).

#1 Make the retry loop information-complete. The `.run_veto` arm now records
the model's draft as an `apply_edit` tool_use and closes it with the compiler
verdict as a tool_result (session-unique id keyed on transcript index). On a
failure the tool_result carries the diagnostic + SQL escalation and the
compiler-authored repair block is persisted as a follow-up system_note, so the
whole retry context lives in the transcript instead of a transient
`extra_user_text` that a mid-repair tool call would erase. Drops `diag_history`
re-accumulation; `.retry_draft` now sends only a short framing nudge. Adds a
regression test proving the failed draft + diagnostic survive a tool interleave.

#2 Raise the per-turn wall-clock timeout 60s -> 300s (the recorded convergence
for complex handlers ran 80-96s) and drop the eval harness's `turn_timeout_ms=0`
override so measurement and production share one options struct.

#4 Add a rolling cache breakpoint on the last message block so the conversation
prefix hits the prompt cache instead of re-paying full input price every
roundtrip.

#5 Flip the default model claude-haiku -> claude-sonnet-4-6 (the measured 7/7
first-draft baseline); Haiku stays available via `--model` and the harness's
ZIGTTP_CODEGEN_MODEL knob. Docs updated.

#8 Outcome-bearing `--print` exit codes: 0 applied/clean, 1 hard error,
2 veto-exhausted, 3 budget, 4 approval-denied. Documented in the user guide.

Also lands the OpenAI honest-demotion doc note (#7, docs portion).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant