config-audit/commands
Kjell Tore Guttormsen 09f817977c fix(commands): stop assuming shell state survives between blocks
Dogfooding `plan` + `implement` against a throwaway config surfaced one root
defect with many arms: the command templates treat consecutive fenced blocks as
one shell. They are not. Every ```bash fence runs as its own Bash call in its own
process, so a variable set in one block is empty in the next, and `$$` is a
different PID (measured: 21710 vs 22109).

The planner agent confirmed the sharpest arm at runtime, reporting that
`Mode: $RAW_FLAG` "arrived literally unsubstituted" — `--raw` was documented in
three command files while being functionally dead. A machine sweep found the same
root in 20 places across 9 files, well past the two the written fasit predicted:

  - `$RAW_FLAG` read from non-shell agent prompts (analyze, plan, implement)
  - `$TMPFILE` read across blocks (tokens, manifest, whats-active,
    plugin-health) — each command could not read the file it had just written
  - `$GLOBAL_FLAG` across blocks (fix)
  - `$TODAY` never assigned in any block (campaign), passing
    `--reference-date ""` to a write CLI in six places
  - three `$$` temp paths handed to the Read tool (fix), which expands neither

All now follow the hardened drift.md pattern: a fixed literal path, or a
re-derivation inside each block that needs it.

Also fixed, all confirmed against ground truth rather than inferred:

  - `implement` printed a rollback ID it never captured (the timestamp lived only
    inside a command substitution) — the one message a user reads after a bad run
  - `plan` reported "No analysis results found" for valid sessions, because Read
    was pointed at a glob it cannot expand; now uses Glob and verifies the
    analysis report exists before spawning the agent
  - five phase commands wrote state.yaml with two of four required fields; since
    the agent writes all four, a follow-up write silently deleted the rest
  - `implement` promised rollback deletes created files; rollback deliberately
    leaves them (M-BUG-26 still open) — the doc, not the engine, was wrong
  - `implement` claimed a score delta with no pre-change measurement
  - `verifier-agent` was told to write a report it has no tool to write
  - dead `Task` tool name in always-loaded rule context; planner-agent template
    demonstrated the inline file content its own line 110 forbids

The sweeps land as tests/commands/command-shell-state-shape.test.mjs, verified
red before the fix and proven able to fail by reintroducing the defect. Two
existing tests asserted the old bash-block mechanism rather than the intent and
were updated. Suite 1449/0; frozen v5.0.0 snapshots and all scanner code
untouched.

Not fixed, deliberately: neither command scope-gates its actions to the audit
target. The generated plan included an edit to a real file under ~/.claude,
outside the throwaway target, because the skill/agent scanners are machine-wide.
That is a design change, not a side fix.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0195udHgCcFegzm7ecKku2Yc
2026-08-01 20:12:17 +02:00
..
analyze.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00
campaign.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00
cleanup.md fix(commands): close the promises the command templates could not keep 2026-07-31 21:27:07 +02:00
config-audit.md fix(commands): close the promises the command templates could not keep 2026-07-31 21:27:07 +02:00
discover.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00
drift.md fix(commands): close the promises the command templates could not keep 2026-07-31 21:27:07 +02:00
feature-gap.md fix(commands): close the promises the command templates could not keep 2026-07-31 21:27:07 +02:00
fix.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00
help.md fix(commands): wire knowledge-refresh into router + help 2026-06-23 10:31:05 +02:00
implement.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00
interview.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00
knowledge-refresh.md feat(knowledge): knowledge-refresh — living register, deterministic stale core + web poll (v5.7 Chunk 3) 2026-06-21 19:22:57 +02:00
manifest.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00
optimize.md feat(optimize): add --subtract, the subtraction axis, behind a deterministic floor 2026-07-31 16:24:51 +02:00
plan.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00
plugin-health.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00
posture.md fix(plugin-health): make the command able to read what the scanner found 2026-07-31 21:08:32 +02:00
rollback.md fix(rollback): restore the backup path contract the engine and the commands disagreed on 2026-07-31 17:23:30 +02:00
status.md fix(commands): close the promises the command templates could not keep 2026-07-31 21:27:07 +02:00
tokens.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00
whats-active.md fix(commands): stop assuming shell state survives between blocks 2026-08-01 20:12:17 +02:00