Goal
The layer is done when mil-verify.ts lists nothing under LATER. Today it still reports six capabilities as NOT TESTED: fallback, escalation records, context budgeting, recovery, goldfish freshness and Model Scout. Every one of them must turn into a PASS, or into an UNSUPPORTED that names its reason, on each harness, without weakening any human gate. Phase B covers the owner's v2.0 brief, sections 6 to 16. Section 17, the personal-assistant portability, gets a plan of its own.
The gap check that produced this plan said for every section of the brief whether it is built, partly built or missing, with the file that proves it. That check was a read, not a test run.
Decisions made in planning (the owner can overturn any of them)
- M1. The supervisor is code, not an agent. It is a deterministic
supervisor.tscommand that the hooks and the OpenCode plugin call. - M2. Each new record gets one home.
- Escalation and fallback transitions go into the existing usage ledger as a new
kind. - A recovery checkpoint goes to
artifacts/handoffs/<date>-<plan>-recovery.md. A clean handoff keeps its current form, so the two never blur. - Model Scout's evidence goes to
artifacts/scout/, and its recommendations go to the DECISIONS inbox. - M3. Context metadata lives in the registry. Each model entry gets a
contextblock: advertised, usable, maxOut, overhead, method and confidence. A model nobody has calibrated getsconfidence: unverifiedand no thresholds. The existingCONTEXT_WARNandCONTEXT_STOPstay authoritative. - M4. The goldfish gate checks the order, the location and the findings of a review. It cannot prove a review's context was isolated. That proof stays with the freshness-token probe, which becomes
goldfish.freshin mil-verify. - M5. Each editing spawn gets its own worktree. The envelope names a
Worktree:path that is not the parent's folder and is not claimed by another live session. Read-only spawns are exempt.
Owner decisions (2026-11-22, in chat)
- O1. Paid DeepSeek is escalation only. It leaves
lightChain. Every paid call needs a recorded approval, and that overrides tokenomics D10. When the plans and the free chain are both spent, the result is checkpoint and stop, plus an escalation request. - O2. Approving the free models: not asked yet. The default is that the per-repository clearance from tokenomics D5 counts as the approval. The owner can overturn it.
- O3. Plans that need a goldfish review: plans marked
lane: gated, plus any plan whosetouchesname hooks, settings orstandards/. - O4. Supervisor limits: concurrency 3, delegation depth 2, retries 2, spawns 4 per task.
- O5. Model Scout runs by hand only.
- O6. Confirming the prose role, and the Phase A model-probe FAIL: still open. Only the final verification waits on it.
- O7. The auditor at finish warns and does not block.
Contracts (fixed before the build, from the goldfish review)
- The brief. The owner's v2.0 brief is stored privately at
claude-config:artifacts/briefs/2026-11-22-model-intelligence-layer-v2.md. Section 7 lists the seven fields an escalation record carries: reason, source model and role, destination model, capability justification, approval, actual or estimated resource use, and outcome. Section 11 lists the per-model context metadata and the eight decisions. - Related plans. Phase A, the model guard (whose restart path is in
claude-config:shared/tools/model-guard.sh) and tokenomics. - What replaces each LATER row. An entry leaves
LATERinmil-verify.tsonly in the commit that adds its replacement check, and only once that check passes. A test asserts that every id once inLATERis now a live check id.
| Was in LATER | Becomes | Step |
|---|---|---|
| fallback | fallback.recorded (transition lines and the exhaustion exit) | 2 |
| escalation-records | escalation.recorded | 1 |
| context-budgeting | context.budgeted (metadata valid, budget fixtures) | 10, 11 |
| recovery | recovery.lineage (checkpoint, verify, supersede) | 12, 13 |
| goldfish-freshness | goldfish.fresh and goldfish.gated | 4, 5 |
| model-scout | scout.readonly (the registry hash is unchanged by recommend) | 15 |
- Exit codes. Every new command uses route-check's codes, so callers read them the same way:
- 0 means ok and 2 a usage error.
- 3 means ask the owner. That covers both an unapproved escalation and a supervisor limit, and the printed reason tells the two apart.
- 4 means no private model is available, and 5 a gate refusal.
- 6 and 7 are new and get added to route-check's usage text in step 1: 6 means credentials are missing, and 7 means every candidate is spent, so checkpoint and stop.
- Any other exit is a crash. The caller fails closed and treats it as a refusal.
- The goldfish gate's trigger. Its three triggers are listed under Third review fixes.
- The side-effect key. It is stored at
~/.claude/state/route-check/effects.jsonl, one JSON line per key:{key, model, at, state}, where state is started or done. Whoever runs the side effect writes done. A retry against a done key exits 5. - Context metadata schema.
methodis one of transcript, provider-usage or estimate.confidenceis one of measured, estimated or unverified.- The next-task estimate is the byte size of the plan's
touchesfiles divided by 4, plus a fixed allowance for tool output, plus maxOut. - The thresholds are the measured
CONTEXT_WARNandCONTEXT_STOP. A model without them gets 70 and 85, marked unverified, as the brief allows. - The way back. Each new gate has an off switch, named in the hooks standard,
standards/HOOKS.md, which step 17 updates. The goldfish gate isGOLDFISH_GATE=offand the worktree rule isENVELOPE_WORKTREE=off. Reverting the step's commit also restores the old behavior. - The baseline. Step 0 records the current
bun test shared/toolstotals and failing test names in the run report before anything changes. - One resolver.
model-roles.pyis read by no hook or settings file (checked by grep, 2026-11-22). Step 0 records the callers that remain. If none remain, it is retired in that step, with the owner told in the run report. - Owner-applied steps. A step marked OWNER APPLIES is done in the build once its tests pass. Its live check waits for
--apply-settings. Step 9's wiring is tested against the script, and its live row stays NOT TESTED until the owner has applied the settings. - The worktree claim store.
~/.claude/state/worktrees.jsonlholds one line per claim:{path, session, at, released}. - The envelope hook writes the line when it admits an editing spawn.
- The spawning session's finish gate writes
released. - A claim is live when it has no
releasedand itsatis under 30 minutes old, PANTRY's own expiry. The heartbeat refreshesat. - A missing or unreadable store denies nothing. The rule fails open on a broken store, so a bad file cannot lock every spawn out, and it prints a warning.
- Which plans the goldfish gate covers. A plan with
track: chat, the ones auto-plan.py creates, is never gated. Neither is a plan with three steps or fewer: that is what a small fix means here. Every other plan that meets O3 is gated. - Every harness.
mil-verify.tsbuilds its OpenCode rows on a separate path (lines 83 to 89), wherelater.*rows are hardcoded. Step 5 removes that path, so every harness builds its rows from the same check list. A test asserts that--harness opencodeprints nolater.*rows. - Shared formats. These are fixed here so builders working side by side agree:
- Ledger kinds:
usagestays as it is. Step 2 addstransition:{kind, from, to, role, cause, at}. Step 1 addsescalation, with the seven brief fields. These are format version 2 lines, and version 1 readers skip any unknown kind. - Approval: a line in
~/.claude/state/escalation/approvals.jsonl,{request, approvedBy: "owner", at, capUsd}. Onlyescalation-record approvewrites it, and the command asks for a typed confirmation on the terminal. An agent runs with no terminal input and cannot answer, so it is refused with exit 3.human-lane.shstays unchanged. - Tool-output allowance: a fixed 8,000 tokens per task.
- LOOP's ask: exit 3, with a stderr line that starts
ask:and names the repeated cause.
Third review fixes
- One integrator owns
mil-verify.ts. A workstream never edits it. Each one ships its checks in its own file,shared/tools/mil-checks/<capability>.ts, with their tests. A single integrator session then adds each capability's rows and removes its LATER entry, one commit per capability, so the per-commit rule holds and no two builders touch the file. The integrator also ownssession-checklist.sh, and runs once the workstreams are committed. - Approval has one source:
approvals.jsonl, written only by the owner's typedapprove. Step 1's test uses a fixture approvals file. A DECISIONS answer is never approval. - The goldfish gate's triggers. All three are PreToolUse hooks:
- Edit or Write to
plans/*.mdthat setsstatus: doing. - Bash whose command writes to
plans/and containsstatus: doing. mcp__pantry__pantry_claimon a plan that qualifies.
auto-plan.py is not a trigger, because it only ever touches exempt chat plans.
- Worktree claims stay live.
- The existing per-tool hook,
session-event.sh, refreshesaton every claim the session holds, keyed by the session id. A working session never expires. - The finish gate releases every claim carrying its own session id.
session-event.shandfinish-gate.share intouches.- Counting steps for the small-fix exemption. Every line under
## Stepsthat is a numbered item or a checkbox, at any depth, counts. Three or fewer means the plan is exempt. - "Same cause twice." One function,
sameCauseTwice(kind, key)inusage-ledger.ts, reads today's and yesterday's ledgers. - For route-check, the key is model plus cause on
transitionlines. - For escalation, the key is the denial reason on
escalationlines. - Two matches inside the cooldown window give the LOOP ask: exit 3 and
ask:. - Resolving
touchesfor the budget. - A
claude-config:prefix resolves to the claude-config root. - Directories are summed recursively, and globs are expanded.
- A path that does not resolve counts as zero and lowers the estimate's confidence to estimated.
- It never fails closed, because the budget is advice.
- Every check names its harnesses. Each check declares the harnesses it applies to. On any other harness it reports UNSUPPORTED, with the reason "not on <harness>". The hook file comes from one map:
- claude uses
settings.json; - codex uses
hooks.json; - opencode uses the plugin under
shared/opencode/; - dsh uses its profile.
- Two finish lines.
- Build-done: every new test is green, nothing sits under LATER, and the auditor review is written. A row that waits on the owner reads NOT TESTED with the reason "owner apply pending".
- Layer-done: after the owner has applied the settings, answered O6, and the Mac run has finished.
Readiness fixes (fourth review)
- Who wrote the audit. An auditor review is
artifacts/reviews/<date>-<plan-id>-audit.md, and its frontmatter carriessession:, the writing session's id. The finish gate compares that with its own session id and with thesessionon the plan's claim. A match with either one means the builder audited its own work, and the gate warns. - The window for "same cause twice" is the routing block's
cooldownDefaultMinutes, 60 minutes.sameCauseTwicereads today's ledger and yesterday's, so a window that crosses midnight is still counted. - Where the claim refresh goes. In
session-event.sh, the refresh runs first, before the Edge exit, the event filter and the throttle, and it is throttled on its own to once every 60 seconds. It rewritesworktrees.jsonlatomically: an exclusive lock file, a write to a temporary file, then a rename. It stays silent. - Exit 4 wins over exit 7. When every candidate is gone because only private models were allowed, route-check exits 4. Exit 7 means candidates existed and every one failed.
- Two review files, one folder.
- The goldfish review is
artifacts/reviews/<plan-id>.md. - The auditor review is
artifacts/reviews/<date>-<plan-id>-audit.md. - Both live in the repository that holds the plan file. The gates find that repository by walking up from the plan's path to its git root. This plan's reviews are in the portfolio repo.
- Claim-refresh files.
- The throttle stamp is
~/.claude/state/worktrees.refresh, holding the epoch seconds of the last refresh. - The lock is
~/.claude/state/worktrees.lock, created with an exclusive create. - When the lock is held, the refresh is skipped; the next tool call tries again.
- A lock older than 30 seconds counts as left behind and is removed before the next try. Each removal writes one line to
~/.claude/state/worktrees.log, so a stuck lock leaves a trace. - The Docker command on Windows:
MSYS_NO_PATHCONV=1 docker run --rm -v C:/Users/tjako/claude-config:/app -w /app oven/bun:1.4.2-slim bun test shared/tools, run from Git Bash. The same image runs the BREAD gates. On the Mac, tests run on the host, where symlinks work. - The Mac payload. The Codex hook payload that the Mac's MODELS-VERIFY run records goes to
claude-config:shared/tools/fixtures/codex/spawn-payload.json. Step 8 reads it from there. - Where the baseline runs. On Windows, step 0 and every later test run use the Docker gate environment, because the host cannot make symlinks. Each run report names the environment it used.
- What done means on each machine. Windows is done when every Claude Code row passes and no row sits under LATER. Codex and OpenCode rows may read assisted or NOT TESTED with the reason "Mac run pending". The layer is done when the Mac run (W7) turns those rows into PASS or UNSUPPORTED.
Steps
- Record the test baseline, and decide the future of
model-roles.py(see Contracts).
Every step that changes behavior writes its failing test first, and the run report records the red output and then the green one. A step marked OWNER APPLIES stops at the link-machine.sh --apply-settings command and never runs it.
W1. Escalation and fallback records
escalation-record.ts.
- Without approval, a request exits 3 and writes no approved line.
- An approval read from a fixture approvals.jsonl writes all seven fields the brief lists in section 7.
- Missing credentials exit 6 without making a network call.
- Two failures with the same cause trigger LOOP's ask.
mil-verifyshowsescalation.recordedPASS.
route-checkchanges.
failwrites a transition line: source, destination, role and cause.pick --prefer-returnbrings the preferred model back once its cooldown ends, at the next delegation only, never in the middle of a session.- A side-effect key already recorded as done makes a retry refuse.
- When every candidate is spent, it exits 7 for "checkpoint and stop".
- Apply O1 to
lightChainand to its tests.
W2. Elephant-Goldfish enforcement
goldfish-gate.sh.
- A plan that qualifies under O3 cannot move to
doingwithoutartifacts/reviews/<plan-id>.mdholding Comprehension, Critic and Readiness, in that order, ending in GO. - A review filed under
plans/is rejected. - A failed Comprehension stops the sequence there.
- A small fix passes without a review.
- OWNER APPLIES.
goldfish.freshin mil-verify. Claude Code is checked by test. Codex and OpenCode stay "assisted" until the Mac runs them.- The auditor check in
finish-gate.sh. A behavior change with no auditor artifact, or with one written by the session that built it, warns (O7). It never blocks.
W3. Spawn, worktree and claim
spawn-envelope.shanddsh/guard.mjs.
- An editing spawn is denied when it has no
Worktree:, when its worktree is the parent's folder, or when another session has claimed that worktree. - A scope cap outside the repository with no
Repo:heading is denied. - OWNER APPLIES.
- The Codex envelope in
machines/*/codex/hooks.json, on the Mac. It needs the payload that the Mac's MODELS-VERIFY run recorded. Without that payload the step reports NOT TESTED.
W4. The supervisor
supervisor.ts.
decidereturns the role, the model taken from route-check, and whether to delegate.admit-spawnexits 3 at the O4 limits.- It defers to
human-lane.shand never overrides it. - Wired into the envelope after step 7.
W5. Context and continuation
- Context metadata in the registry, with its validation.
context-budget.ts.
- It returns one of: continue, narrow, delegate, compact, checkpoint, fresh-session, transfer, stop-handoff.
- It uses the measured usage, an estimate of the next task, and the maxOut reserve.
- It is advice from context-trigger.sh, never a block.
checkpoint.ts: write, validate, lineage and supersede.
- A recovery checkpoint records the dirty tree.
- A complete checkpoint refuses a red gate.
- supersede refuses until the successor has written
recovered: verified.
- Continuation on Claude Code reuses the model guard's restart path.
- The successor's prompt carries the envelope and the checkpoint, and never "pick the next backlog item".
- The archive is offered only after the lineage is verified.
- This is assisted, not automatic: archiving needs the owner's approval.
W6. Ledger, Scout and the runtime brief
run-report.ts. It generates the run report's skeleton, including the model transitions taken from the ledger.model-scout.ts: inventory, evaluate and recommend.
- It never writes the registry, which a hash check before and after proves.
- An unapproved provider is never added to
lightChain. - Evaluations against free models run on the Mac.
- The runtime brief in
session-checklist.sh. A healthy start still prints one line. Drift, or--brief, prints the policy, the cooldowns, the context confidence and the capability levels. It shows the preferred model and the active model side by side. - The standard: MODELS.md and MODELS-VERIFY gain each new piece, the standards index is refreshed in the same commit, and LOOP and SESSION-LOOP are linked rather than restated.
W7. Mac and OpenCode
- A handoff for the Mac. It covers:
- the OpenCode plugin calling the supervisor, route-check and escalation-record;
- verifying the free model ids;
- the Codex envelope;
- MODELS-VERIFY runs on Codex and OpenCode;
- the brief's fallback scenarios.
DSH is on hold (owner, 2026-11-23). Its rows read UNSUPPORTED with the reason "on hold".
- Main-session failover in OpenCode, a first-class acceptance requirement (owner, 2026-11-23). Today only bounded light subagents fall back, through
routed_subagent. An OpenCode main session running on the Codex-backed Sol allowance stops when that allowance runs out, and does not move to DeepSeek Flash. A wired API token does not keep the main session going.
- Investigate first. Read OpenCode's actual request and failure hooks and what it can do to switch models, from its source and documentation, before choosing an approach. Record the findings in the run report.
- Keep the rules. The conversation context, the repository's privacy clearance, explicit approval for metered spend (O1: paid Flash is escalation), the cooldowns, and a bounded retry of at most two.
- If seamless switching in place is supported, wire it through route-check, so the quota failure is recorded as a
transitionline and the next model comes frompick. - If it is not supported, build an honest, resumable handoff instead: a recovery checkpoint (step 12) plus a new session on the next eligible model, which carries the conversation summary and the envelope. Document it as assisted, not automatic.
- Acceptance needs a live event. Deterministic tests are required but not enough. The check
opencode.main-failoverstays NOT TESTED until a real transition from quota exhaustion to the next provider has happened on its own and been recorded in the ledger and the run report. - Covers OpenCode and Codex. The Codex side is the same: what happens to a Codex main session when its plan runs out, recorded honestly as supported, assisted or unsupported.
Order
- Can run side by side, since they touch different files:
- W2;
- W3;
- steps 14 and 15;
- steps 11 and 12, once step 10 has landed.
- Must run one after another, because they share files:
- The registry, in the order 10, then 1 and 3, then 9.
- The ledger, in step 1, before steps 2 and 14.
- The envelope, in step 7, before step 9's wiring.
- mil-verify and the checklist (steps 5 and 16) last.
- Step 13 after step 12.
- Step 17 after all the claude-config work.
- W7 after the owner pushes.
Hard stops
- No push, merge or delete; the owner does those.
- No CareerEdgeDevOps/edge, and work context stays on company Claude and Codex.
- No session writes
~/.claude/settings.jsonor~/.codex/*. - No change to
human-lane.shor pr-review-kit. - No AI trailers in commits.
- No paid call without a recorded approval.
- Model Scout never writes the registry.
- Nothing picks the next backlog item on its own.
Ask-triggers
- An open owner decision when its step comes up.
- A test that cannot be made red first.
- The same gate red twice for the same cause.
- A harness payload that differs from its fixture.
Verification
mil-verify --harness claudeprints nolater.*rows.- Every new test was red, then green.
bun test shared/toolsshows no new failures against the baseline.- An auditor review in
artifacts/reviews/, written by a session other than the builder's. - A goldfish pass on this plan before it is built.
- MODELS-VERIFY runs on the Mac for Codex, DSH and OpenCode.
Points where the brief conflicts with what exists
- Section 7 against tokenomics D10. The brief keeps paid DeepSeek out of the fallback chain, while D10 lets it run at the end of the chain under a daily cap. This is O1.
- The section 16 banner. A full banner on every start is noise, so it prints only on drift or on request.
- Sections 4 and 16 show OpenCode on Sol, while its light tiers now run free models first. The brief should show the preferred model and the active model side by side.
- Section 8. A goldfish on Claude Code still loads CLAUDE.md and memory. Isolation from the main conversation can be proven; "no memory at all" cannot, so it is recorded as assisted.
- Section 12. Archiving needs the owner's approval, so continuation is assisted, not automatic.
- Section 6. The main session's model cannot be switched mid-session, so a return to the preferred model happens at the next delegation or the next session.
- Section 17 stays out of this plan.
- Two resolvers exist,
model-roles.pyandmodel-roles.ts. One should be retired.