crewforth 3.1.0 → 3.2.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +151 -0
  2. package/README.md +4 -3
  3. package/VERSION +1 -1
  4. package/adopt.sh +91 -11
  5. package/kit/AGENT_TEMPLATE.md +2 -1
  6. package/kit/CLAUDE.md +9 -8
  7. package/kit/agents/crew-commit-agent.md +7 -2
  8. package/kit/agents/crew-docs-agent.md +71 -0
  9. package/kit/agents/crew-planner.md +2 -0
  10. package/kit/agents/crew-refuter.md +77 -0
  11. package/kit/agents/crew-security-expert.md +3 -1
  12. package/kit/agents/crew-session-manager.md +11 -9
  13. package/kit/eval/doctor.sh +91 -3
  14. package/kit/eval/golden-routing.txt +9 -0
  15. package/kit/eval/lib/crew-map/crew-map.sh +26 -0
  16. package/kit/eval/lib/crew-map/detect.mjs +238 -0
  17. package/kit/eval/lib/crew-map/narrative.mjs +98 -0
  18. package/kit/eval/lib/crew-map/parse.mjs +305 -0
  19. package/kit/eval/lib/crew-map/project.mjs +163 -0
  20. package/kit/eval/lib/crew-map/rules/names.json +38 -0
  21. package/kit/eval/lib/crew-map/rules/packages.json +142 -0
  22. package/kit/eval/lib/crew-map/rules/python-stdlib.json +197 -0
  23. package/kit/eval/lib/crew-map/scan.mjs +214 -0
  24. package/kit/eval/lib/crew-map/stacks.mjs +441 -0
  25. package/kit/eval/lib/crew-map/surface.mjs +457 -0
  26. package/kit/eval/lib/findings/findings.mjs +410 -0
  27. package/kit/eval/lib/findings/findings.schema.json +122 -0
  28. package/kit/eval/lib/findings/findings.sh +29 -0
  29. package/kit/eval/lib/settings-json.awk +5 -0
  30. package/kit/eval/lib/star.sh +23 -7
  31. package/kit/eval/lib/statusline.settings.json +6 -0
  32. package/kit/eval/lib/statusline.sh +115 -0
  33. package/kit/eval/smoke-test.sh +465 -38
  34. package/kit/hooks/agent-outcome.sh +6 -3
  35. package/kit/hooks/guard-agent-model.sh +15 -5
  36. package/kit/hooks/guard-bash.sh +240 -182
  37. package/kit/hooks/guard-question.sh +73 -0
  38. package/kit/hooks/guard-write.sh +21 -0
  39. package/kit/hooks/prompt-approval.sh +320 -103
  40. package/kit/hooks/refuter-ledger.sh +80 -0
  41. package/kit/owned-blobs.tsv +4 -1
  42. package/kit/settings.json +33 -0
  43. package/kit/skills/crew-approve/SKILL.md +7 -0
  44. package/kit/skills/crew-doctor/SKILL.md +5 -1
  45. package/kit/skills/crew-handoff/SKILL.md +3 -2
  46. package/kit/skills/crew-map/SKILL.md +44 -0
  47. package/kit/skills/crew-review/SKILL.md +2 -0
  48. package/kit/skills/crew-update/SKILL.md +1 -1
  49. package/kit/skills/incident-runbook/SKILL.md +2 -2
  50. package/kit/skills/security-scan/references/verify.md +6 -3
  51. package/kit/studio/README.md +12 -0
  52. package/kit/studio/server/index.js +114 -11
  53. package/kit/studio/server/lib/crew-map.js +113 -0
  54. package/kit/studio/server/lib/model-outcomes.js +130 -15
  55. package/kit/studio/server/lib/pricing.js +3 -0
  56. package/kit/studio/server/lib/remote.js +99 -0
  57. package/kit/studio/server/lib/usage.js +74 -14
  58. package/kit/studio/web/app.js +214 -12
  59. package/kit/studio/web/canvas.js +44 -120
  60. package/kit/studio/web/graph-plan.js +10 -4
  61. package/kit/studio/web/index.html +10 -5
  62. package/kit/studio/web/map-plan.js +341 -0
  63. package/kit/studio/web/map.js +503 -0
  64. package/kit/studio/web/models-plan.js +61 -7
  65. package/kit/studio/web/models.js +19 -3
  66. package/kit/studio/web/style.css +125 -0
  67. package/kit/studio/web/usage.js +12 -0
  68. package/kit/studio/web/viewport.js +160 -0
  69. package/package.json +6 -5
  70. package/start.sh +10 -0
@@ -109,6 +109,10 @@ note(){ echo " · $1"; } # informational; never counts as a failure
109
109
  # Scope. Declared HERE rather than beside the block it first guards, because it now gates cases that run
110
110
  # EARLIER than that block — see §6h. Reading an env var costs nothing; the note stays where the big skip is.
111
111
  UNITS=1; [ "${CREW_SMOKE_SCOPE:-full}" = install ] && UNITS=0
112
+ # THE USER'S OWN CLAUDE SETTINGS ARE NOT AN INPUT OF THIS SUITE (3.2.0). Before a commit prompt the gates look for a
113
+ # PermissionRequest hook in the user's settings, skills, agents and plugins; on a machine that has one, every "the gate
114
+ # asks" case would read "the gate refuses". Cases that need a user directory set their own (HOME, CLAUDE_CONFIG_DIR).
115
+ _SMOKE_CCD="$(mktemp -d)"; export CLAUDE_CONFIG_DIR="$_SMOKE_CCD"
112
116
  # Trigger-phrases requirement: a GATE in the Crewforth repo, a note in an installed project (your skills, your call).
113
117
  need_trigger(){ if kit_owned "${2:-}"; then fail "$1"; else note "$1 (your own skill/agent; not gated in an install)"; fi; }
114
118
 
@@ -2328,7 +2332,7 @@ BUDGET_DISC=14975 # 3.1.0: 13986 → 14975 (+989): the task card (files, chan
2328
2332
  # and the wrong one winning silently. The only rule in this file that is about the OTHER
2329
2333
  # rules, so it cannot live in the README the way the compaction note does. Plus the Audit
2330
2334
  # row naming crew-performance-expert — an agent nothing routes to is an idle component.)
2331
- BUDGET_AGENTS=5596 # 5d.2: tightened to the measured sum (was 5800 with 204 B of slack). Before that: sum of agent frontmatter; currently 5582, measured 2026-09-23 (3.0: the backend and database
2335
+ BUDGET_AGENTS=5746 # 3.2.0: 5596 → 5746 (+150), the measured sum: crew-docs-agent is a 14th agent (195 B, its description cut to one line first; the other 13 sum to 5551). Raised on the user's decision, not to make room. 5d.2: tightened to the measured sum (was 5800 with 204 B of slack). Before that: sum of agent frontmatter; currently 5582, measured 2026-09-23 (3.0: the backend and database
2332
2336
  # agents' descriptions rewritten stack-agnostic, +55 B). Before that 5527, measured 2026-09-20 by reading this suite's
2333
2337
  # own printed line rather than a hand-rolled counter (a hand-rolled one answered 5503 and
2334
2338
  # was thrown away). Two corrections in one day: the note said 5765 against a measured 5407,
@@ -2521,20 +2525,34 @@ done
2521
2525
  # PROACTIVE-CUE GATE: Claude Code auto-delegates on the description field, and only fires reliably when it carries
2522
2526
  # an action cue ("use proactively" / "immediately after" / "use ... when"). A passive role description ("Senior X
2523
2527
  # expert. Handlers, endpoints.") rarely auto-invokes — the specialist stays dormant and Crewforth reads as inert.
2524
- # Every agent EXCEPT the two deliberately pull-only ones (invoked explicitly: a commit needs approval; session
2525
- # health is emitted by a hook) must carry a cue, or a future passive rewrite silently regresses delegation.
2526
- PULL_AGENTS=" crew-commit-agent crew-session-manager "
2528
+ # EVERY agent carries one. Two used to be exempt as "pull-only" (a commit needs approval; session health comes from
2529
+ # a hook), and nothing pulled them: the main thread wrote the commit message and the handover itself, and neither
2530
+ # agent was ever started. The exemption is gone; what pulls a chain-step agent is pinned just below.
2527
2531
  NO_CUE=""
2528
2532
  for f in $(agent_quality_files); do
2529
2533
  [ -e "$f" ] || continue
2530
2534
  a="$(basename "$f" .md)"
2531
- case "$PULL_AGENTS" in *" $a "*) continue ;; esac
2532
2535
  awk '/^---$/{c++; next} c==1' "$f" | grep -qiE "use proactively|immediately after|use [a-z ]*when" \
2533
2536
  || NO_CUE="$NO_CUE $a"
2534
2537
  done
2535
- if [ -z "$NO_CUE" ]; then pass "every non-pull agent carries an auto-delegation cue (proactive/immediately-after)"
2536
- elif [ "$IS_KIT" = 1 ]; then fail "agent(s) with a passive description — auto-delegation will rarely fire:$NO_CUE (add 'use proactively …', or add to PULL_AGENTS if pull-only)"
2538
+ if [ -z "$NO_CUE" ]; then pass "every agent carries an auto-delegation cue (proactive/immediately-after/use … when)"
2539
+ elif [ "$IS_KIT" = 1 ]; then fail "agent(s) with a passive description — auto-delegation will rarely fire:$NO_CUE (add 'use proactively …')"
2537
2540
  else pass "some agents lack a proactive cue:$NO_CUE (your project's own agents, not gated)"; fi
2541
+ # WHO PULLS A CHAIN-STEP AGENT. An agent whose work sits at a fixed step of the chain (metadata.stage close, handoff
2542
+ # or understand: the reviewer, the commit message, the handover, the plan) is not reached by a prompt's words; it is
2543
+ # reached because a command or the discipline CALLS it there. So each one is named in the call form, `@agent-<name>`
2544
+ # (or `subagent_type`), in a command skill or the discipline. Producers and auditors are pulled by route-hint.sh and
2545
+ # the cue above; the orphan check (3b) already holds that they are routed at all. Kit agents only.
2546
+ _cs=0; _csb=""; _cmdfiles="$(grep -l 'kind: command' "$SKILLS"/*/SKILL.md 2>/dev/null)"
2547
+ for f in "$AGENTS"/*.md; do
2548
+ [ -f "$f" ] || continue; a="$(basename "$f" .md)"; kit_owned "agents/$a.md" || continue
2549
+ case "$(awk '/^---$/{c++; next} c==1 && /^[[:space:]]*stage:/{print $2; exit}' "$f")" in close|handoff|understand) ;; *) continue ;; esac
2550
+ _cs=$((_cs+1))
2551
+ grep -qE "@agent-$a([^a-z0-9-]|\$)|subagent_type[^a-z]{0,6}$a([^a-z0-9-]|\$)" $_cmdfiles "$ROUTE_DOC" 2>/dev/null || _csb="$_csb $a"
2552
+ done
2553
+ if [ "$IS_KIT" = 1 ] && [ "$_cs" -lt 4 ]; then fail "FIXTURE: $_cs chain-step agents read (close/handoff/understand) — the stage field or the count broke, not the agents"
2554
+ elif [ -z "$_csb" ]; then pass "every chain-step agent ($_cs) is called as @agent-<name> by a command or the discipline"
2555
+ else fail "chain-step agent(s) nothing calls by name — the main thread does their work instead:$_csb"; fi
2538
2556
 
2539
2557
 
2540
2558
  # ---- gate UNIT cases: skipped under CREW_SMOKE_SCOPE=install ------------------------------------------------
@@ -2789,6 +2807,24 @@ r46rec "$R46_OID" "$R46_HEAD"
2789
2807
  o="$(gj default 'git commit -m x' | r46 2>/dev/null)"
2790
2808
  [ "$(gdec "$o")" = "ask" ] && pass "§4.6: a matching record lets the commit through to the §4.4 ask" \
2791
2809
  || fail "§4.6: a matching record did NOT pass the gate (out=$o)"
2810
+ # 2b. Who wrote the message (AJAN-1): the latest crew-review-agent / crew-commit-agent call in the transcript decides
2811
+ # one line in the approval. It never blocks, and it says nothing when it cannot know: a subagent's own call, or a
2812
+ # transcript it cannot read.
2813
+ _can_t="$R46/.t"; mkdir -p "$_can_t"
2814
+ _can_call(){ printf '{"type":"assistant","message":{"content":[{"type":"tool_use","name":"Agent","input":{"subagent_type":"%s","prompt":"x"}}]}}\n' "$1"; }
2815
+ { _can_call crew-review-agent; _can_call crew-commit-agent; } > "$_can_t/both.jsonl"
2816
+ _can_call crew-review-agent > "$_can_t/review.jsonl"
2817
+ { _can_call crew-commit-agent; _can_call crew-review-agent; } > "$_can_t/stale.jsonl"
2818
+ _canj(){ printf '{"cwd":"%s","permission_mode":"default","transcript_path":"%s",%s"tool_name":"Bash","tool_input":{"command":"git commit -m x"}}' "$R46" "$1" "${2:-}"; }
2819
+ _canb=""; _NOTE='crew-commit-agent has not run since the last review'
2820
+ o="$(_canj "$_can_t/both.jsonl" | r46 2>/dev/null)"; [ "$(gdec "$o")" = ask ] && [[ "$o" != *"$_NOTE"* ]] || _canb="$_canb agent-ran-but-noted"
2821
+ o="$(_canj "$_can_t/review.jsonl" | r46 2>/dev/null)"; [ "$(gdec "$o")" = ask ] && [[ "$o" == *"$_NOTE"* ]] || _canb="$_canb no-agent-not-noted"
2822
+ o="$(_canj "$_can_t/stale.jsonl" | r46 2>/dev/null)"; [[ "$o" == *"$_NOTE"* ]] || _canb="$_canb a-review-after-the-agent-not-noted"
2823
+ o="$(_canj "$_can_t/review.jsonl" '"agent_id":"a1",' | r46 2>/dev/null)"; [[ "$o" != *"$_NOTE"* ]] || _canb="$_canb noted-on-a-subagents-call"
2824
+ o="$(_canj "$_can_t/nope.jsonl" | r46 2>/dev/null)"; [ "$(gdec "$o")" = ask ] && [[ "$o" != *"$_NOTE"* ]] || _canb="$_canb noted-without-a-transcript"
2825
+ [ -z "$_canb" ] && pass "§4.4 approval names a commit message crew-commit-agent did not write (5 cases: ran, not run, review after it, subagent, no transcript); it never blocks" \
2826
+ || fail "commit-agent note:$_canb"
2827
+ rm -rf "$_can_t"
2792
2828
  # 3. Right diff, wrong base. This is the case a wall-clock TTL cannot see and the reason there is none.
2793
2829
  r46rec "$R46_OID" "0000000000000000000000000000000000000000"
2794
2830
  gj default 'git commit -m x' | r46 >/dev/null 2>&1; [ "$?" = 2 ] \
@@ -3476,6 +3512,27 @@ done
3476
3512
  # are now cut out and the rest goes to the old rule, so nothing unproven is skipped — all pinned above.
3477
3513
  [ -z "$_hp_bad" ] && pass "core.hooksPath: value-less reads pass, every write form stays blocked ($_hp_n of 48 shapes)" \
3478
3514
  || fail "core.hooksPath read/write split is wrong:$_hp_bad"
3515
+ # crewforth.hookschain IS JUDGED BY THE SAME READER. The key holds the path of a project hook chain that lives outside
3516
+ # the repository; the shim reads it on every commit. Reads pass, every write form is refused, exactly 0 or 2.
3517
+ _hc_bad=""; _hc_n=0
3518
+ for _c in 'git config crewforth.hookschain' 'git config --get crewforth.hookschain' 'git config --local crewforth.hookschain' \
3519
+ 'git -C /r config --get crewforth.hookschain' 'git config get crewforth.hookschain' 'git config --get crewforth.hookschain | cat' \
3520
+ 'git status; echo crewforth.hookschain' 'git config --remove-section crewforth.foo' 'git config crewforth.other x'; do
3521
+ gj auto "$_c" | bash "$HOOKS/guard-bash.sh" >/dev/null 2>&1; _r=$?; _hc_n=$((_hc_n+1)); [ "$_r" = 0 ] || _hc_bad="$_hc_bad [$_c -> $_r, want 0]"
3522
+ done
3523
+ for _c in 'git config crewforth.hookschain /tmp/x' 'git config --local crewforth.hookschain x' 'git config --unset crewforth.hookschain' \
3524
+ 'git config --unset-all crewforth.hookschain' 'git config --add crewforth.hookschain x' 'git config --replace-all crewforth.hookschain x' \
3525
+ 'git config set crewforth.hookschain x' 'git config unset crewforth.hookschain' 'git config crewforth.hookschain \"\"' \
3526
+ 'git config --get crewforth.hookschain && git config crewforth.hookschain x' 'git config crewforth.HooksChain /tmp/x' \
3527
+ 'git config crewforth.hooks\"c\"hain x' 'git config crewforth.hookschain \r' 'git -C /r config crewforth.hookschain /tmp/x' \
3528
+ 'git config --remove-section crewforth' 'git config --rename-section crewforth x' \
3529
+ 'git -c crewforth.hookschain=/tmp/x commit -m x' "git -c 'crewforth.hookschain=/tmp/x' commit -m x" \
3530
+ 'GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=crewforth.hookschain GIT_CONFIG_VALUE_0=/tmp/x git commit -m x'; do
3531
+ gj auto "$_c" | bash "$HOOKS/guard-bash.sh" >/dev/null 2>&1; _r=$?; _hc_n=$((_hc_n+1)); [ "$_r" = 2 ] || _hc_bad="$_hc_bad [$_c -> $_r, want 2]"
3532
+ done
3533
+ if [ "$_hc_n" != 28 ]; then fail "FIXTURE: the crewforth.hookschain table ran $_hc_n rows, not 28"
3534
+ elif [ -z "$_hc_bad" ]; then pass "crewforth.hookschain: 9 reads and neighbours pass, 19 write forms are refused — a value, unset, add, set, the section removed or renamed, -c, GIT_CONFIG_ ($_hc_n rows)"
3535
+ else fail "crewforth.hookschain read/write split is wrong:$_hc_bad"; fi
3479
3536
  # THE SAME SPLIT UNDER A WINDOWS PAYLOAD. A read is not proven when the payload holds an escape the reader drops
3480
3537
  # (`\r`, `\f`, `\b`, `\v`, `\u`). That was asked of the WHOLE payload, and a Windows `cwd` is full of them once
3481
3538
  # JSON-encoded: `C:\\repos\\app` holds a backslash and an r. So in such a directory `git config --get core.hooksPath`
@@ -4595,6 +4652,37 @@ DOC="$(mktemp -d)"
4595
4652
  chmod +x .claude/hooks/*.sh .claude/hooks/pre-commit .claude/hooks/commit-msg
4596
4653
  git config core.hooksPath .claude/hooks )
4597
4654
  bash "$ROOT/eval/doctor.sh" "$DOC" >/dev/null 2>&1 && pass "doctor: healthy install -> exit 0" || fail "doctor flagged a healthy install"
4655
+ # Two editions at once, and the advisor (doctor 9c). Driven through a stub `claude` that prints a plugin list, a
4656
+ # config dir of its own, and the provider and advisor variables cleared, so the machine running this decides
4657
+ # nothing. Advisory: every case keeps the healthy verdict (exit 0).
4658
+ _d9="$(mktemp -d)"; mkdir -p "$_d9/bin" "$_d9/cfg"
4659
+ _d9stub(){ printf '#!/bin/sh\ncase "$1" in --version) echo "2.1.299 (Claude Code)" ;; plugin) cat <<J\n%s\nJ\n;; esac\n' "$1" > "$_d9/bin/claude"; chmod +x "$_d9/bin/claude"; }
4660
+ _d9run(){ _d9o="$( cd "$DOC" && env -u CLAUDE_CODE_DISABLE_ADVISOR_TOOL -u CLAUDE_CODE_USE_BEDROCK -u CLAUDE_CODE_USE_VERTEX \
4661
+ CREW_LANG=en CLAUDE_CONFIG_DIR="$_d9/cfg" PATH="$_d9/bin:$PATH" "$@" bash "$ROOT/eval/doctor.sh" 2>&1 )"; _d9rc=$?; }
4662
+ _d9b=""
4663
+ _d9stub '[{"id":"crewforth@crewforth","enabled":true},{"id":"other@market","enabled":true}]'; _d9run
4664
+ case "$_d9o" in *"every hook runs twice"*) ;; *) _d9b="$_d9b both-on-not-seen" ;; esac; [ "$_d9rc" = 0 ] || _d9b="$_d9b both-on-changed-the-verdict($_d9rc)"
4665
+ # The 2.x plugin id, still enabled at user scope beside a 3.x install, wires the same hooks: measured in a real
4666
+ # project (the 2.13.0 plugin was claude-starter-kit@byerlikaya).
4667
+ _d9stub '[{"id":"claude-starter-kit@byerlikaya","enabled":true}]'; _d9run
4668
+ case "$_d9o" in *"claude-starter-kit@byerlikaya plugin is enabled"*"every hook runs twice"*) ;; *) _d9b="$_d9b legacy-plugin-not-seen" ;; esac
4669
+ _d9stub '[{"id": "crewforth@crewforth", "enabled": false}]'; _d9run
4670
+ case "$_d9o" in *"one edition: the Crewforth plugin is not enabled"*) ;; *) _d9b="$_d9b plugin-off-not-one-edition" ;; esac
4671
+ rm -f "$_d9/bin/claude"; _d9run env PATH="$_d9/bin:/usr/bin:/bin"
4672
+ case "$_d9o" in *"two editions at once: not measured (no claude CLI"*) ;; *) _d9b="$_d9b no-cli-not-said" ;; esac
4673
+ _d9stub '[]'
4674
+ _d9run; case "$_d9o" in *"advisor: off (no advisorModel set"*) ;; *) _d9b="$_d9b advisor-unset" ;; esac
4675
+ printf '{"advisorModel":"opus"}' > "$_d9/cfg/settings.json"; _d9run
4676
+ case "$_d9o" in *"advisor: on, opus"*) ;; *) _d9b="$_d9b advisor-opus" ;; esac; case "$_d9o" in *"below the critical tier"*) _d9b="$_d9b opus-called-below-critical" ;; esac
4677
+ printf '{"advisorModel":"sonnet"}' > "$_d9/cfg/settings.json"; _d9run
4678
+ case "$_d9o" in *"advisor (sonnet) is below the critical tier"*) ;; *) _d9b="$_d9b sonnet-not-below" ;; esac
4679
+ _d9run env CLAUDE_CODE_DISABLE_ADVISOR_TOOL=1
4680
+ case "$_d9o" in *"CLAUDE_CODE_DISABLE_ADVISOR_TOOL=1 turns the advisor off"*) ;; *) _d9b="$_d9b env-off-not-seen" ;; esac
4681
+ _d9run env CLAUDE_CODE_USE_BEDROCK=1
4682
+ case "$_d9o" in *"needs the Anthropic API"*) ;; *) _d9b="$_d9b bedrock-not-seen" ;; esac; [ "$_d9rc" = 0 ] || _d9b="$_d9b bedrock-changed-the-verdict($_d9rc)"
4683
+ rm -rf "$_d9"
4684
+ [ -z "$_d9b" ] && pass "doctor 9c: both editions on is named, one is ok, no CLI is not measured; the advisor off, on, below the critical tier, env-disabled and on Bedrock each read right; none changes the verdict" \
4685
+ || fail "doctor 9c:$_d9b"
4598
4686
  # THE MANIFEST'S LINE ENDINGS MUST NOT CHANGE WHO OWNS A SKILL. Measured before the fix: the same install with
4599
4687
  # one project skill counted 1 on an LF manifest and 2 on a CRLF one, because `grep -qxF` wants a whole line and
4600
4688
  # `skills/handoff\r` is not `skills/handoff` — so every KIT skill read as project-owned. A Windows checkout with
@@ -6610,8 +6698,10 @@ rm -rf "$_hsd"
6610
6698
  # A gate's timeout is not a comfort setting: a PreToolUse hook that reaches it does not block (Claude Code's hooks
6611
6699
  # reference: "doesn't block the tool call … don't count on a stalled hook to act as a gate"), and a field session on
6612
6700
  # 3.0.0 showed nine of them in one day — the commands ran with no gate. Crewforth had set 60 s where Claude Code's
6613
- # own default is 600, and the slowest machine measured needed 32-134 s for one guard-bash call. The seven PreToolUse
6614
- # gates (the four bash gates, the no-bash gate of 12e, guard-schedule.sh and guard-agent-model.sh) carry 600 now; every other hook keeps 60 — when one of those times out, nothing is left unguarded.
6701
+ # own default is 600, and the slowest machine measured needed 32-134 s for one guard-bash call. The eight PreToolUse
6702
+ # gates (the four bash gates, the no-bash gate of 12e, guard-schedule.sh, guard-agent-model.sh and prompt-approval.sh on
6703
+ # the approval question, whose `ask` is what keeps a hook from answering it) carry 600 now; every other hook keeps 60 —
6704
+ # when one of those times out, nothing is left unguarded.
6615
6705
  # Read per entry, in both editions; the twin lowers one gate back to 60 and must be seen.
6616
6706
  gate_timeouts(){ json_hooks "$1" | LC_ALL=C awk -F'\t' '$1 == "PreToolUse" { n++; t = 0
6617
6707
  if (match($3, /"timeout"[ \t]*:[ \t]*[0-9]+/)) { t = substr($3, RSTART, RLENGTH); sub(/.*:[ \t]*/, "", t) }
@@ -6620,13 +6710,13 @@ gate_timeouts(){ json_hooks "$1" | LC_ALL=C awk -F'\t' '$1 == "PreToolUse" { n++
6620
6710
  _gtd="$(mktemp -d)"
6621
6711
  tr -d '\n' < "$ROOT/settings.json" | sed 's/guard-bash\.sh\([^}]*\)"timeout": 600/guard-bash.sh\1"timeout": 60/' > "$_gtd/twin.json"
6622
6712
  _gtw="$(gate_timeouts "$_gtd/twin.json")"
6623
- if [ "$_gtw" != "7 1" ]; then fail "gate timeout pin: the twin with guard-bash.sh back at 60 s read '$_gtw', want '7 1' — the pin sees nothing"
6713
+ if [ "$_gtw" != "8 1" ]; then fail "gate timeout pin: the twin with guard-bash.sh back at 60 s read '$_gtw', want '8 1' — the pin sees nothing"
6624
6714
  else for _gf in $_gpw_f; do
6625
6715
  [ -f "$_gf" ] || continue
6626
6716
  set -- $(gate_timeouts "$_gf")
6627
- if [ "${1:-0}" != 7 ]; then fail "${_gf##*/}: $1 PreToolUse gate hooks read, want 7 — the pin did not read the file as written"
6628
- elif [ "${2:-9}" = 0 ]; then pass "${_gf##*/}: all 7 PreToolUse gates have a 600 s timeout (a gate that times out does not block)"
6629
- else fail "${_gf##*/}: $2 of 7 PreToolUse gates time out before 600 s — a timed-out gate does not block"; fi
6717
+ if [ "${1:-0}" != 8 ]; then fail "${_gf##*/}: $1 PreToolUse gate hooks read, want 8 — the pin did not read the file as written"
6718
+ elif [ "${2:-9}" = 0 ]; then pass "${_gf##*/}: all 8 PreToolUse gates have a 600 s timeout (a gate that times out does not block)"
6719
+ else fail "${_gf##*/}: $2 of 8 PreToolUse gates time out before 600 s — a timed-out gate does not block"; fi
6630
6720
  done; fi
6631
6721
  rm -rf "$_gtd"
6632
6722
 
@@ -7394,6 +7484,22 @@ PCT='0 @@ git commit -m x
7394
7484
  2 @@ git commit -m x
7395
7485
  2 @@ git commit -m x;touch
7396
7486
  2 @@ git commit -m #\x27\ntouch ../PWNED\n#\x27
7487
+ 2 @@ git commit -m x \\
7488
+ 2 @@ git commit -m a\\ b
7489
+ 2 @@ git commit -m $\x27a\x27
7490
+ 2 @@ git commit -m \"a
7491
+ 2 @@ git commit -m \x27a
7492
+ 2 @@ git commit -m \"a\\\\b\"
7493
+ 2 @@ git commit -m \"a!b\"
7494
+ 0 @@ git commit -q -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27 -m \x27p\x27
7495
+ 0 @@ \n git commit -m \x27a\x27 \t\n
7496
+ 0 @@ git commit -m x \\\n
7497
+ 0 @@ git commit -m x\n 2>&1
7498
+ 2 @@ git commit -m x\n2>&1 -a
7499
+ 2 @@ git commit -m \"$(cat <<\x27E-F\x27\nmsg\nE-F\n)\"
7500
+ 2 @@ git commit -m \"$(cat <<\x27EOF\x27\nmsg\nEOF\ntouch ../PWNED\nEOF\n)\"
7501
+ 2 @@ git commit -m a*b
7502
+ 2 @@ git commit -m x2>&1
7397
7503
  2 @@ git commit -m \\\x27a ; touch ../PWNED ; echo b\\\x27'
7398
7504
  _pa_say auto 'approve: commit' >/dev/null
7399
7505
  _pan=0; _pabad=""
@@ -7401,8 +7507,8 @@ while IFS= read -r _pl; do [ -z "$_pl" ] && continue
7401
7507
  _pw="${_pl%% @@ *}"; _pc="${_pl#* @@ }"; _pc="${_pc//\\x27/$_pq}"; _pan=$((_pan+1))
7402
7508
  _pa_run auto "$_pc"; [ "$_par" = "$_pw" ] || _pabad="$_pabad [$_pc → $_par, want $_pw]"
7403
7509
  done <<< "$PCT"
7404
- if [ "$_pan" != 50 ]; then fail "FIXTURE: the approved-commit table has $_pan rows, not 50"
7405
- elif [ -z "$_pabad" ]; then pass "an approved commit is 'git commit -m …' alone in its call: 7 spellings allowed (any single-quoted message, a here-document with a quoted delimiter), 43 refused — a cd or a variable in front, a second command however it is quoted, a substitution, a redirection, -a or a path past a redirection, -n, an abbreviated --no-verify or --amend, any other option (50 rows)"
7510
+ if [ "$_pan" != 66 ]; then fail "FIXTURE: the approved-commit table has $_pan rows, not 66"
7511
+ elif [ -z "$_pabad" ]; then pass "an approved commit is 'git commit -m …' alone in its call: 10 spellings allowed (any single-quoted message, a here-document with a quoted delimiter, forty messages in one call, blank lines around the call, a continued line with nothing after it, a 2>&1 on a line of its own), 56 refused — a cd or a variable in front, a second command however it is quoted, a substitution, a redirection, -a or a path past a redirection, -n, an abbreviated --no-verify or --amend, any other option, a backslash outside quotes (the last character of the call too), a quote never closed, a \$'…' text, a here-document whose delimiter is not a plain word or whose body holds the delimiter twice, a glob in the message (66 rows)"
7406
7512
  else fail "approved-commit table:$_pabad"; fi
7407
7513
 
7408
7514
  # What is staged, HEAD, the clock: each one moved on its own, with the others still matching.
@@ -7772,6 +7878,113 @@ _pa_say auto 'approve: commit' >/dev/null; _pa_gate auto 'git commit -m x'; _pav
7772
7878
  _pa_new; _pa_gate auto 'git commit -m x'; _pav2="$_par"
7773
7879
  [ "$_pav1/$_pav2" = 0/2 ] && pass "the wiring check moves no verdict: a recorded approval is allowed (rc 0) and its absence refused (rc 2) with no settings file" \
7774
7880
  || fail "the wiring check moved a verdict: approved $_pav1 (want 0), unapproved $_pav2 (want 2)"
7881
+ # ---- THE APPROVAL QUESTION (3.2.0): one click in auto, recorded as the typed approval is -------------------------
7882
+ # guard-question.sh on PreToolUse for AskUserQuestion answers `ask` to the fixed question (a hook's `ask` beats another
7883
+ # hook's `allow` with filled-in answers: measured on Claude Code 2.1.294, 34 runs and by hand), PostToolUse records
7884
+ # (prompt-approval.sh, on PostToolUse) the user's answer when THIS call was asked. Before either, and before guard-bash.sh raises its own prompt in
7885
+ # default / acceptEdits, a PermissionRequest hook is looked for: such a hook answers a prompt before the person does.
7886
+ # Every case runs the hooks against a real repository; what is asserted is a verdict or a record.
7887
+ _pa_new; mkdir -p "$_PA/ccd" "$_PA/home"
7888
+ _PAQ_ENV="CLAUDE_PROJECT_DIR=$_paw CLAUDE_CONFIG_DIR=$_PA/ccd HOME=$_PA/home CREW_GATE_LOG=/dev/null"
7889
+ _paq_canon="$(bash -c '. "$1"; printf "%s" "$_CREW_Q_JSON"' _ "$HOOKS/prompt-approval.sh")"
7890
+ _paq_text="$(bash -c '. "$1"; printf "%s" "$_CREW_Q_TEXT"' _ "$HOOKS/prompt-approval.sh")"
7891
+ # $1 = mode, $2 = the questions array's content, $3 = more tool_input (",..."), $4 = tool_use_id -> rc in _par, stdout _pao
7892
+ _paq_pre(){ printf '{"session_id":"s","transcript_path":"%s","cwd":"%s","permission_mode":"%s","hook_event_name":"PreToolUse","tool_name":"AskUserQuestion","tool_input":{"questions":[%s]%s},"tool_use_id":"%s"}' "$_patr" "$_paw" "$1" "$2" "${3:-}" "${4:-tu1}" > "$_PA/q.json"
7893
+ if [ -n "$JSONQ" ]; then json_ok < "$_PA/q.json" || _paqbad="$_paqbad [pre payload is not JSON]"; fi
7894
+ _pao="$( cd "$_paw" && env -u CLAUDE_CODE_SESSION_ATTENDED $_PAQ_ENV ${_PAQ_X:-} bash "$HOOKS/guard-question.sh" < "$_PA/q.json" 2>"$_PA/qerr" )"; _par=$?; }
7895
+ # $1 = mode, $2 = the answer, $3 = tool_use_id
7896
+ _paq_post(){ printf '{"session_id":"s","transcript_path":"%s","cwd":"%s","permission_mode":"%s","hook_event_name":"PostToolUse","tool_name":"AskUserQuestion","tool_input":{"questions":[%s],"answers":{"%s":"%s"}},"tool_response":{"questions":[%s],"answers":{"%s":"%s"}},"tool_use_id":"%s"}' "$_patr" "$_paw" "$1" "$_paq_canon" "$_paq_text" "$2" "$_paq_canon" "$_paq_text" "$2" "${3:-tu1}" > "$_PA/q.json"
7897
+ if [ -n "$JSONQ" ]; then json_ok < "$_PA/q.json" || _paqbad="$_paqbad [post payload is not JSON]"; fi
7898
+ _pao="$( cd "$_paw" && env -u CLAUDE_CODE_SESSION_ATTENDED $_PAQ_ENV ${_PAQ_X:-} bash "$HOOKS/prompt-approval.sh" < "$_PA/q.json" 2>"$_PA/qerr" )"; _par=$?; }
7899
+ _paq_gate(){ printf '{"session_id":"s","cwd":"%s","permission_mode":"%s","tool_name":"Bash","tool_input":{"command":"%s"}}' "$_paw" "$1" "$2" > "$_PA/pl.json"
7900
+ _pao="$( cd "$_paw" && env $_PAQ_ENV ${_PAQ_X:-} bash "$HOOKS/guard-bash.sh" < "$_PA/pl.json" 2>"$_PA/err" )"; _par=$?; _pae="$(cat "$_PA/err")"; }
7901
+ _paq_rec(){ [ -s "$_pa_rec" ] && _pa_op || echo none; }
7902
+ _paqbad=""; _paqn=0
7903
+ _paq_is(){ _paqn=$((_paqn+1)); [ "$2" = "$3" ] || _paqbad="$_paqbad [$1: got '$2', want '$3']"; }
7904
+ # the round trip, and what it opens
7905
+ : > "$_pa_rec"; _paq_pre auto "$_paq_canon"; _paq_is 'fixed question in auto is asked' "$_par/$(gdec "$_pao")" "0/ask"
7906
+ _paq_post auto 'Commit only'; _paq_is 'its answer is recorded' "$(_paq_rec)" commit
7907
+ _paq_gate auto 'git commit -m x'; _paq_is 'the recorded click allows the commit' "$_par" 0
7908
+ _pa_new; : > "$_pa_rec"; _paq_pre auto "$_paq_canon" '' tu2; _paq_post auto 'Commit + push' tu2; _paq_is 'commit + push' "$(_paq_rec)" commit+push
7909
+ # must-fail twins: each differs from the round trip in one thing
7910
+ _pa_new; : > "$_pa_rec"; _paq_post auto 'Commit only' tu3; _paq_is 'an answer no PreToolUse asked for' "$(_paq_rec)" none
7911
+ _paq_pre auto "$_paq_canon" '' tu4; _paq_post auto 'Commit only' tu5; _paq_is 'an answer to another call' "$(_paq_rec)" none
7912
+ _paq_pre auto "$_paq_canon" '' tu6; _paq_post auto 'Commit only' tu6; : > "$_pa_rec"; _paq_post auto 'Commit only' tu6
7913
+ _paq_is 'the same call answered twice' "$(_paq_rec)" none
7914
+ _paq_pre auto "$_paq_canon" '' tu7; _paq_post auto 'HOOK-CHOSE-Commit only' tu7; _paq_is 'an answer that is none of the four' "$(_paq_rec)" none
7915
+ _paq_pre auto "$_paq_canon" '' tu8; _paq_post auto 'No' tu8; _paq_is 'No' "$(_paq_rec)" none
7916
+ _paq_pre auto "$_paq_canon" '' tu9; _paq_post default 'Commit only' tu9; _paq_is 'an answer recorded outside auto' "$(_paq_rec)" none
7917
+ _paq_pre auto '{"question":"Crewforth approval: commit?","header":"Approval","options":[{"label":"Commit only","description":"x"}],"multiSelect":false}'
7918
+ _paq_is 'another wording is refused' "$_par" 2
7919
+ _paq_pre auto "$_paq_canon" ',"answers":{"x":"Commit only"}'; _paq_is 'a call with answers is refused' "$_par" 2
7920
+ _paq_pre auto "$_paq_canon,$_paq_canon"; _paq_is 'the question twice is refused' "$_par" 2
7921
+ _paq_pre dontAsk "$_paq_canon"; _paq_is 'dontAsk: refused' "$_par" 2
7922
+ _paq_pre default "$_paq_canon"; _paq_is 'default: refused' "$_par" 2
7923
+ _paq_pre bypassPermissions "$_paq_canon"; _paq_is 'bypassPermissions: refused' "$_par" 2
7924
+ _PAQ_X="CLAUDE_CODE_SESSION_ATTENDED=0"; _paq_pre auto "$_paq_canon"; unset _PAQ_X; _paq_is 'a headless session: refused' "$_par" 2
7925
+ _paq_pre auto '{"question":"Which colour?","header":"Colour","options":[{"label":"Red","description":"r"}],"multiSelect":false}'
7926
+ _paq_is 'any other question: no decision' "$_par/$_pao" "0/"
7927
+ if [ "$_paqn" != 18 ]; then fail "FIXTURE: the approval-question table ran $_paqn cases, not 18"
7928
+ elif [ -z "$_paqbad" ]; then pass "the approval question: asked (ask) only as the fixed text, in auto, attended, with no answers; its answer recorded only for the call that was asked, once, and only as one of the four; the record allows the commit (18 cases, 13 must-fail)"
7929
+ else fail "the approval question:$_paqbad"; fi
7930
+
7931
+ # A PermissionRequest HOOK, wherever this can read one, closes the question AND the gate's own prompt. Each source is
7932
+ # planted alone in an otherwise clean fixture; the clean fixture itself must answer "none" (calibration).
7933
+ _paq_scan(){ ( cd "$_paw" && env $_PAQ_ENV ${_PAQ_X:-} bash -c '. "$1"; if _crew_prh_scan; then printf "found %s" "$_PRH"; else printf none; fi' _ "$HOOKS/prompt-approval.sh" ) 2>/dev/null; }
7934
+ _paqbad=""; _paqn=0
7935
+ _paq_clean(){ rm -rf "$_PA/ccd" "$_PA/home" "$_paw/.claude/skills" "$_paw/.claude/agents" "$_paw/.claude/settings.local.json" "$_PA/mng.json"; mkdir -p "$_PA/ccd" "$_PA/home"; }
7936
+ _paq_found(){ _paqn=$((_paqn+1)); case "$(_paq_scan)" in "found "*"$2"*) ;; *) _paqbad="$_paqbad [$1: $(_paq_scan)]" ;; esac; _paq_clean; }
7937
+ _paq_none(){ _paqn=$((_paqn+1)); [ "$(_paq_scan)" = none ] || _paqbad="$_paqbad [$1 wrongly: $(_paq_scan)]"; _paq_clean; }
7938
+ _PRQ='{"hooks":{"PermissionRequest":[{"hooks":[{"type":"command","command":"x"}]}]}}'
7939
+ _paq_clean; _paq_none 'a clean fixture'
7940
+ printf '%s' "$_PRQ" > "$_paw/.claude/settings.local.json"; _paq_found 'project settings.local.json' settings.local.json
7941
+ printf '%s' "$_PRQ" > "$_PA/ccd/settings.json"; _paq_found 'user settings (CLAUDE_CONFIG_DIR)' ccd/settings.json
7942
+ printf '%s' "$_PRQ" > "$_PA/mng.json"; _PAQ_X="CREW_MANAGED_SETTINGS=$_PA/mng.json"; _paq_found 'a managed file' mng.json; unset _PAQ_X
7943
+ printf '%s' '{"hooks":{"Permission\u0052equest":[]}}' > "$_paw/.claude/settings.local.json"; _paq_found 'the name spelled with a \u escape' settings.local.json
7944
+ mkdir -p "$_paw/.claude/skills/s"; printf -- '---\nname: s\nhooks:\n PermissionRequest:\n - hooks: []\n---\nbody\n' > "$_paw/.claude/skills/s/SKILL.md"; _paq_found 'skill front matter' SKILL.md
7945
+ mkdir -p "$_paw/.claude/agents"; printf -- '---\nname: a\nhooks:\n "Permission\\x52equest": []\n---\n' > "$_paw/.claude/agents/a.md"; _paq_found 'agent front matter, escaped' a.md
7946
+ mkdir -p "$_PA/ccd/plugins/cache/m/p/1/hooks"; printf '%s' "$_PRQ" > "$_PA/ccd/plugins/cache/m/p/1/hooks/hooks.json"; _paq_found 'an installed plugin' hooks.json
7947
+ mkdir -p "$_paw/.claude/skills/s"; printf -- '---\nname: s\ndescription: about hooks\n---\nA PermissionRequest hook answers a prompt.\n' > "$_paw/.claude/skills/s/SKILL.md"; _paq_none 'the name in a skill body, not its front matter'
7948
+ printf '%s' '{"hooks":{"PreToolUse":[]},"x":"c:\\users\\me"}' > "$_paw/.claude/settings.local.json"; _paq_none 'an escaped backslash before u'
7949
+ if [ "$_paqn" != 10 ]; then fail "FIXTURE: the PermissionRequest scan table ran $_paqn cases, not 10"
7950
+ elif [ -z "$_paqbad" ]; then pass "a PermissionRequest hook is found in project, user and managed settings, an escaped spelling, skill and agent front matter and an installed plugin (7); a clean fixture, a skill body and an escaped backslash are not (3)"
7951
+ else fail "the PermissionRequest scan:$_paqbad"; fi
7952
+
7953
+ # What it closes: the question, the recording of an answer, and in default the gate's prompt. What it leaves: the typed
7954
+ # approval, in default too. Twin: the same fixture without the hook asks (default) and offers the question (auto).
7955
+ _paqbad=""
7956
+ _pa_new; _paq_clean
7957
+ printf '%s' '{"hooks":{"UserPromptSubmit":[{"hooks":[{"type":"command","command":"bash .claude/hooks/prompt-approval.sh"}]}],"PreToolUse":[{"matcher":"AskUserQuestion","hooks":[{"type":"command","command":"bash .claude/hooks/guard-question.sh"}]}],"PostToolUse":[{"matcher":"AskUserQuestion","hooks":[{"type":"command","command":"bash .claude/hooks/prompt-approval.sh"}]}]}}' > "$_paw/.claude/settings.json"
7958
+ _paq_gate default 'git commit -m x'; [ "$_par/$(gdec "$_pao")" = "0/ask" ] || _paqbad="$_paqbad [no hook, default: $_par/$(gdec "$_pao"), want 0/ask]"
7959
+ _paq_gate auto 'git commit -m x'; case "$_par/$_pae" in 2/*AskUserQuestion*"$_paq_text"*) ;; *) _paqbad="$_paqbad [no hook, auto: the refusal does not offer the question]" ;; esac
7960
+ printf '%s' "$_PRQ" > "$_paw/.claude/settings.local.json"
7961
+ _paq_gate default 'git commit -m x'; case "$_par/$_pae" in 2/*PermissionRequest*settings.local.json*/crew-approve*) ;; *) _paqbad="$_paqbad [hook, default: $_par, want 2 naming the file and /crew-approve]" ;; esac
7962
+ case "$_pae" in *'Shift+Tab to default/acceptEdits (this gate then asks'*) _paqbad="$_paqbad [hook, default: offers Shift+Tab]" ;; esac
7963
+ _paq_gate auto 'git commit -m x'; case "$_par/$_pae" in 2/*"approval question is closed"*) case "$_pae" in *AskUserQuestion*) _paqbad="$_paqbad [hook, auto: still offers the question]" ;; esac ;; *) _paqbad="$_paqbad [hook, auto: $_par, the question is not said to be closed]" ;; esac
7964
+ _paq_pre auto "$_paq_canon" '' tuh; [ "$_par" = 2 ] || _paqbad="$_paqbad [hook: the question was asked ($_par)]"
7965
+ rm -f "$_paw/.claude/settings.local.json"; _paq_pre auto "$_paq_canon" '' tuh2; printf '%s' "$_PRQ" > "$_paw/.claude/settings.local.json"
7966
+ : > "$_pa_rec"; _paq_post auto 'Commit only' tuh2; [ "$(_paq_rec)" = none ] || _paqbad="$_paqbad [a hook added after the question: its answer was recorded]"
7967
+ printf '{"session_id":"s","transcript_path":"%s","cwd":"%s","permission_mode":"default","hook_event_name":"UserPromptSubmit","prompt":"/crew-approve commit"}' "$_patr" "$_paw" \
7968
+ | ( cd "$_paw" && env -u CLAUDE_CODE_SESSION_ATTENDED $_PAQ_ENV bash "$HOOKS/prompt-approval.sh" ) >/dev/null 2>&1
7969
+ [ "$(_paq_rec)" = commit ] || _paqbad="$_paqbad [hook, default: /crew-approve commit was not recorded]"
7970
+ _paq_gate default 'git commit -m x'; [ "$_par" = 0 ] || _paqbad="$_paqbad [hook, default: the typed approval did not allow the commit ($_par)]"
7971
+ rm -f "$_paw/.claude/settings.local.json"; _pa_new
7972
+ printf '{"session_id":"s","transcript_path":"%s","cwd":"%s","permission_mode":"default","hook_event_name":"UserPromptSubmit","prompt":"/crew-approve commit"}' "$_patr" "$_paw" \
7973
+ | ( cd "$_paw" && env -u CLAUDE_CODE_SESSION_ATTENDED $_PAQ_ENV bash "$HOOKS/prompt-approval.sh" ) >/dev/null 2>&1
7974
+ [ "$(_paq_rec)" = none ] || _paqbad="$_paqbad [no hook, default: /crew-approve recorded although the gate asks there]"
7975
+ if [ -z "$_paqbad" ]; then pass "a PermissionRequest hook closes the question, the recording of its answer and the gate's own prompt in default, and leaves /crew-approve (which then allows the commit); without one, default asks, auto offers the question, and a typed approval in default records nothing (9 readings)"
7976
+ else fail "what a PermissionRequest hook closes:$_paqbad"; fi
7977
+
7978
+ # The record of the question is the gate's own: closed to the session like the pending note.
7979
+ _paqbad=""
7980
+ for _pqc in 'cat .claude/state/crew-approval-asked' 'printf x > .claude/state/crew-approval-asked' 'rm -f .claude/state/crew-approval-asked'; do
7981
+ _paq_gate auto "$_pqc"; [ "$_par" = 2 ] || _paqbad="$_paqbad [$_pqc: rc $_par]"
7982
+ done
7983
+ printf '{"cwd":"%s","permission_mode":"auto","tool_name":"Write","tool_input":{"file_path":"%s/.claude/state/crew-approval-asked","content":"x"}}' "$_paw" "$_paw" \
7984
+ | ( cd "$_paw" && env $_PAQ_ENV bash "$HOOKS/guard-write.sh" ) >/dev/null 2>&1; [ $? = 2 ] || _paqbad="$_paqbad [Write: not refused]"
7985
+ [ -z "$_paqbad" ] && pass "the question's own note (.claude/state/crew-approval-asked) is closed to the session: three shell forms and the Write tool refused" \
7986
+ || fail "the question's note is open:$_paqbad"
7987
+ rm -f "$_paw/.claude/settings.json"; _pa_new
7775
7988
  fi # prompt-approval.sh present
7776
7989
 
7777
7990
  # ---- the two definitions that live in two files, and the wiring -----------------------------------------------
@@ -7800,6 +8013,22 @@ if [ "$IS_KIT" = 1 ]; then
7800
8013
  elif [ -z "$_phm" ]; then pass "every script the plugin's hooks.json runs is in plugin/hooks ($_phn scripts)"
7801
8014
  else fail "the plugin's hooks.json runs a script the plugin does not carry:$_phm (add it to the list in packaging/build-plugin.sh)"; fi
7802
8015
  fi
8016
+ # ...and the approval question: guard-question.sh asks it (PreToolUse), prompt-approval.sh records its answer
8017
+ # (PostToolUse), each once on AskUserQuestion, in both editions.
8018
+ for _pf in $_pawf; do
8019
+ _pn="$(json_hooks "$_pf" | LC_ALL=C awk -F'\t' '$2 == "AskUserQuestion" { if ($1 == "PreToolUse" && $3 ~ /guard-question\.sh/) a++; if ($1 == "PostToolUse" && $3 ~ /prompt-approval\.sh/) b++ } END { printf "%d %d", a, b }')"
8020
+ [ "$_pn" = "1 1" ] && pass "${_pf##*/}: the approval question is wired on AskUserQuestion: guard-question.sh once on PreToolUse, prompt-approval.sh once on PostToolUse" \
8021
+ || fail "${_pf##*/}: the approval question is not wired once each (guard-question.sh on PreToolUse, prompt-approval.sh on PostToolUse; found: $_pn)"
8022
+ done
8023
+ # The managed settings files are one list: the ones model routing reads its rules from are the ones the approval
8024
+ # question looks for a PermissionRequest hook in. Compared as the lines that name a managed-settings.json.
8025
+ _pml(){ grep -oE '"[^"]*managed-settings\.json"|CREW_MANAGED_SETTINGS' "$1" 2>/dev/null | sort -u | tr '\n' ' '; }
8026
+ _pm1="$(_pml "$HOOKS/prompt-approval.sh")"; _pm2="$(_pml "$HOOKS/guard-agent-model.sh")"
8027
+ case "$_pm1" in *managed-settings.json*managed-settings.json*managed-settings.json*CREW_MANAGED_SETTINGS*)
8028
+ [ "$_pm1" = "$_pm2" ] && pass "the managed settings files are one list in prompt-approval.sh and guard-agent-model.sh ($(printf '%s' "$_pm1" | tr ' ' '\n' | grep -c .) entries)" \
8029
+ || fail "the managed settings lists differ: prompt-approval.sh [$_pm1] guard-agent-model.sh [$_pm2]" ;;
8030
+ *) fail "FIXTURE: the managed settings list could not be read from prompt-approval.sh ([$_pm1])" ;;
8031
+ esac
7803
8032
  # ...and on PreToolUse for the tools that schedule a prompt, in both editions, with one matcher.
7804
8033
  for _pf in $_pawf; do
7805
8034
  _pn="$(json_hooks "$_pf" | LC_ALL=C awk -F'\t' '$1 == "PreToolUse" && $3 ~ /guard-schedule\.sh/ { n++; m = $2 } END { printf "%d %s", n, m }')"
@@ -8022,6 +8251,19 @@ done <<'V2'
8022
8251
  2|crew-backend-expert|sonnet|prisma/schema.prisma|feature|none|
8023
8252
  2|crew-backend-expert|sonnet|config/SECRETS_local.env|text|none|
8024
8253
  0|crew-backend-expert|sonnet|docs/author.md, src/cryptography/hash.ts|feature|none|
8254
+ 2|crew-backend-expert|sonnet|legal/terms-of-service.md|text|none|
8255
+ 2|crew-backend-expert|sonnet|docs/privacy-policy.md|text|none|
8256
+ 2|crew-backend-expert|sonnet|src/PrivacyController.cs|feature|none|
8257
+ 2|crew-backend-expert|sonnet|src/consent/banner.ts|feature|none|
8258
+ 2|crew-backend-expert|sonnet|content/terms/index.md|text|none|
8259
+ 2|crew-backend-expert|sonnet|fastlane/metadata/en-US/description.txt|text|none|
8260
+ 2|crew-backend-expert|sonnet|store/listing.md|text|none|
8261
+ 2|crew-backend-expert|sonnet|metadata/android/en-US/full_description.txt|text|none|
8262
+ 0|crew-backend-expert|opus|legal/terms-of-service.md|text|none|
8263
+ 0|crew-backend-expert|sonnet|src/searchTerms.ts|feature|none|
8264
+ 0|crew-backend-expert|sonnet|src/store/index.ts|feature|none|
8265
+ 0|crew-backend-expert|sonnet|fastlane/metadata/en-US/images/icon.png|text|none|
8266
+ 0|crew-backend-expert|sonnet|docs/legalese.md|text|none|
8025
8267
  0|crew-backend-expert|sonnet|src/ui/a.ts|feature|none|
8026
8268
  2|crew-backend-expert|haiku|src/ui/a.ts|text|none|
8027
8269
  0|crew-backend-expert|sonnet|src/ui/a.ts|text|none|
@@ -8055,7 +8297,7 @@ done <<'V2'
8055
8297
  0|crew-backend-expert|sonnet|src/ui/a.ts|feature|git commit -m x|
8056
8298
  0|crew-backend-expert|sonnet|src/ui/a.ts|feature|rm -rf /|
8057
8299
  V2
8058
- if [ "$_v2n" != 47 ]; then fail "FIXTURE: the card table has $_v2n rows, not 47"
8300
+ if [ "$_v2n" != 60 ]; then fail "FIXTURE: the card table has $_v2n rows, not 60"
8059
8301
  elif [ -z "$_v2b" ]; then pass "the card decides the model: critical work (payments/, migrations, a .sql file, AuthController, userAuth, schema.prisma, and the four critical kinds of change) is refused below opus and passes on opus; verify none is refused on haiku; test-run passes on haiku, also on a critical path; test-write, audit and review are held to sonnet in normal work and to opus in critical work; critical work with a verify command is refused when the call says run_in_background true, and passes with false and with the field left out (a session whose Agent tool has no such field cannot send it); a card that is not one is refused; a verify command never refuses the call, whatever it is (the hook decides whether to run it) (47 rows)"
8060
8302
  else fail "card table:$_v2b"; fi
8061
8303
  # The refusal names the way forward that exists (the field was sent, so it can be sent as false), and a call that
@@ -8113,6 +8355,17 @@ _v2write "$_v2p/src/payments/p.ts" ',"agent_id":"ag-gp","agent_type":"general-pu
8113
8355
  _V2ENV="CREW_MODEL_ROUTING=off" _v2write "$_v2p/src/payments/p.ts" ',"agent_id":"ag-son","agent_type":"crew-backend-expert"'; [ "$_v2wrc" = 0 ] || _v2b="$_v2b routing-off-refused:$_v2wrc"
8114
8356
  [ -z "$_v2b" ] && pass "an agent on sonnet is refused a write to a critical path its card did not name, and told to report escalate; the same agent writes elsewhere; an agent on opus (by its call, or by its own transcript) writes there; an agent whose model cannot be read does not; the session's own write is not asked; routing off asks nothing" \
8115
8357
  || fail "write-time check:$_v2b"
8358
+ # B2 (K7): the session's own write to a critical path is not refused, and it is recorded: one NOTE line in the gate
8359
+ # log naming the path and the rule. A write elsewhere, one outside the project, and one with routing off add none.
8360
+ _v2b=""; _b2l="$_v2/b2.tsv"
8361
+ _b2(){ : > "$_b2l"; _V2ENV="CREW_GATE_LOG=$_b2l ${2:-}" _v2write "$1"; _b2n="$(grep -c '^NOTE' "$_b2l" 2>/dev/null)"; }
8362
+ _b2 "$_v2p/src/payments/p.ts"; [ "$_v2wrc/$_b2n" = 0/1 ] || _v2b="$_v2b [critical: rc $_v2wrc, $_b2n notes]"
8363
+ grep -q "^NOTE"$'\t'"§model"$'\t'"note: the session wrote a critical path itself, not through an agent: src/payments/p.ts (payments)" "$_b2l" || _v2b="$_v2b [line: $(head -1 "$_b2l")]"
8364
+ _b2 "$_v2p/src/ui/a.ts"; [ "$_v2wrc/$_b2n" = 0/0 ] || _v2b="$_v2b [plain: rc $_v2wrc, $_b2n notes]"
8365
+ _b2 "/tmp/elsewhere/payments/p.ts"; [ "$_v2wrc/$_b2n" = 0/0 ] || _v2b="$_v2b [outside: rc $_v2wrc, $_b2n notes]"
8366
+ _b2 "$_v2p/src/payments/p.ts" CREW_MODEL_ROUTING=off; [ "$_v2wrc/$_b2n" = 0/0 ] || _v2b="$_v2b [routing off: rc $_v2wrc, $_b2n notes]"
8367
+ [ -z "$_v2b" ] && pass "the session's own write to a critical path is allowed and recorded as a NOTE with the path and the rule; a plain write, one outside the project and one with routing off are not recorded" \
8368
+ || fail "the session's critical write (B2):$_v2b"
8116
8369
 
8117
8370
  # ---- 2. the critical paths of a project with no settings file: a Flutter app and a .NET service ---------------
8118
8371
  _v2new; _v2b=""
@@ -8170,7 +8423,7 @@ _v2call crew-backend-expert sonnet 'src/ui/tz.ts' feature none; _v2start tz1; _V
8170
8423
  _tzg="$(awk -F'\t' '$2 == "tz1" { print substr($1, 1, 13) }' "$_v2p/.claude/state/model-outcomes.tsv")"; _tzn="$(date -u +%Y-%m-%dT%H)"; _tzp="$(date -u -v-1H +%Y-%m-%dT%H 2>/dev/null || date -u -d '1 hour ago' +%Y-%m-%dT%H 2>/dev/null)"
8171
8424
  { [ -n "$_tzg" ] && { [ "$_tzg" = "$_tzn" ] || [ "$_tzg" = "$_tzp" ]; }; } || _v2b="$_v2b [the time is not UTC: wrote $_tzg, UTC is $_tzn]"
8172
8425
  IFS= read -r _h < "$_v2p/.claude/state/model-outcomes.tsv"
8173
- [ "$_h" = "ts"$'\t'"agent_id"$'\t'"agent"$'\t'"change"$'\t'"risk"$'\t'"card"$'\t'"model"$'\t'"verify"$'\t'"fixes"$'\t'"escalated_from"$'\t'"ran_on"$'\t'"confidence" ] || _v2b="$_v2b [header: $_h]"
8426
+ [ "$_h" = "ts"$'\t'"agent_id"$'\t'"agent"$'\t'"change"$'\t'"risk"$'\t'"card"$'\t'"model"$'\t'"verify"$'\t'"fixes"$'\t'"escalated_from"$'\t'"ran_on"$'\t'"confidence"$'\t'"risk_why" ] || _v2b="$_v2b [header: $_h]"
8174
8427
  [ -z "$_v2b" ] && pass "verify then escalate: red once keeps the agent running with the failing command; green after it is a pass with one fix; red twice ends the agent as a fail, recorded once; the session is told to repeat one model up; the same card is refused on the same model and allowed one up; red there too is the user's question and a third run is refused; a changed card is a new task; confidence: low is told the same way; a background launch and an agent with no record are left alone; the record's twelve columns are the ones published, and its time is UTC under a zone fourteen hours ahead" \
8175
8428
  || fail "verify-then-escalate:$_v2b"
8176
8429
 
@@ -8491,6 +8744,20 @@ mkdir -p "$_v2st/pending"; printf 'agent=crew-backend-expert\ntier=opus\nchange=
8491
8744
  _v2start o1; { [ ! -f "$_v2st/agents/o1" ] && [ ! -f "$_v2st/pending/1000000000-tuold" ]; } || _v2b="$_v2b a-stale-record-was-given-to-an-agent-or-kept"
8492
8745
  [ -z "$_v2b" ] && pass "which record is whose: with two models pending for one agent type the agent is recorded on the lower one; a record is taken by rename, so of two agents starting together one gets it; an agent whose transcript carries the other card is judged by that card's record (a call nobody has taken yet is looked at first), a task given as a list of blocks is read, a transcript with no card is noted in the gate log and the record used as matched, an agent whose card no record carries is not judged, and a record older than five minutes is dropped" \
8493
8746
  || fail "matching a call to its agent:$_v2b"
8747
+ # Why the work was critical is kept with it, in the gate's own words, so a reader shows the reason and does not work
8748
+ # it out again: a card on a critical path carries the path and the rule that matched; normal work carries "-".
8749
+ _v2new; _v2b=""; _v2st="$_v2p/.claude/state/crew-model"
8750
+ _v2call crew-backend-expert opus 'src/payments/p.ts' feature 'test -d src' ',"run_in_background":false'
8751
+ [ "$_v2rc" = 0 ] || _v2b="$_v2b FIXTURE:[the critical call was refused, rc=$_v2rc: $(head -c 300 "$_v2/err")]"
8752
+ grep -q '^why=src/payments/p.ts is on a critical path: ' "$_v2st"/pending/* 2>/dev/null || _v2b="$_v2b [pending record: $(grep -h '^why=' "$_v2st"/pending/* 2>/dev/null)]"
8753
+ _v2start k1; _v2tr k1 'src/payments/p.ts' feature 'test -d src'; _v2stopt k1 >/dev/null
8754
+ _kw="$(awk -F'\t' '$2 == "k1" { print $13 }' "$_v2st/../model-outcomes.tsv" 2>/dev/null)"
8755
+ case "$_kw" in 'src/payments/p.ts is on a critical path: '?*) ;; *) _v2b="$_v2b [critical row: risk_why='$_kw']" ;; esac
8756
+ _v2call crew-backend-expert sonnet 'src/ui/a.ts' feature 'test -d src'; _v2start k2; _v2tr k2 'src/ui/a.ts' feature 'test -d src'; _v2stopt k2 >/dev/null
8757
+ _kn="$(awk -F'\t' '$2 == "k2" { print $5 "/" $13 }' "$_v2st/../model-outcomes.tsv" 2>/dev/null)"
8758
+ [ "$_kn" = "normal/-" ] || _v2b="$_v2b [normal row: '$_kn']"
8759
+ [ -z "$_v2b" ] && pass "the gate's reason for critical work reaches the record: the pending record and the outcome line carry the path and the rule that matched; normal work carries -" \
8760
+ || fail "risk reason recorded:$_v2b"
8494
8761
  # The gate's and the write-time check's refusals are in the gate log; an agent id that cannot be read does not open
8495
8762
  # the write-time check; run_in_background named twice is refused.
8496
8763
  _v2new; _v2b=""; _V2ENV="CREW_GATE_LOG=$_v2/gl.tsv"; : > "$_v2/gl.tsv"
@@ -8523,7 +8790,7 @@ _v2call crew-backend-expert sonnet 'src/ui/m3.ts' feature none; _v2start no1; _v
8523
8790
  [ "$(_v2ran no1)" = "-" ] || _v2b="$_v2b [no model named: $(_v2ran no1)]"
8524
8791
  _v2call crew-backend-expert sonnet 'src/ui/m4.ts' feature none; _v2start od1; _v2stop od1 >/dev/null; _v2postm od1 completed ',"resolvedModel":"a b\tc"'
8525
8792
  [ "$(_v2ran od1)" = "-" ] || _v2b="$_v2b [a model that is not a name was written: $(_v2ran od1)]"
8526
- [ "$(_v2ran fg1)/$(awk 'END { print NR }' "$_v2p/.claude/state/model-outcomes.tsv")/$(awk -F'\t' 'NF != 12' "$_v2p/.claude/state/model-outcomes.tsv" | wc -l | tr -d ' ')" = "claude-sonnet-5-5/5/0" ] || _v2b="$_v2b [the other lines changed: $(_v2ran fg1), $(awk 'END { print NR }' "$_v2p/.claude/state/model-outcomes.tsv") lines]"
8793
+ [ "$(_v2ran fg1)/$(awk 'END { print NR }' "$_v2p/.claude/state/model-outcomes.tsv")/$(awk -F'\t' 'NF != 13' "$_v2p/.claude/state/model-outcomes.tsv" | wc -l | tr -d ' ')" = "claude-sonnet-5-5/5/0" ] || _v2b="$_v2b [the other lines changed: $(_v2ran fg1), $(awk 'END { print NR }' "$_v2p/.claude/state/model-outcomes.tsv") lines]"
8527
8794
  [ -d "$_v2p/.claude/state/.outcomes.lock" ] && _v2b="$_v2b the-lock-was-left-behind"
8528
8795
  [ -z "$_v2b" ] && pass "ran_on is the model the answer to the Agent call names: written into the agent's line when the answer follows the stop (a foreground call), there already when it came at the launch (a background call), '-' when the answer names none or names something that is not a model; a decoy of the field inside the task's text is not read, the other lines and the twelve columns stay as they were, and no lock is left behind" \
8529
8796
  || fail "ran_on:$_v2b"
@@ -8719,6 +8986,61 @@ rm -rf "$_v2"
8719
8986
  fi
8720
8987
  # Wired where it has to be, in both editions: the four events of agent-outcome.sh, and the gate on Agent.
8721
8988
  _pawf2="$ROOT/settings.json"; [ "$IS_KIT" = 1 ] && _pawf2="$_pawf2 $(cd "$ROOT/.." && pwd)/plugin/hooks/hooks.json"
8989
+ # ---- the refuter ledger: what crew-refuter concluded, written by the hook from the agent's own task and answer ----
8990
+ # findings.mjs --verified trusts this file, so what writes it is the gate: a line only when the TASK (the first record
8991
+ # of the agent's transcript) and the ANSWER (last_assistant_message) name the same finding and lens, only for a
8992
+ # crew-refuter (plugin-namespaced too), once per agent, whatever CREW_MODEL_ROUTING says, and never a refusal.
8993
+ _RL="$HOOKS/refuter-ledger.sh"
8994
+ if [ ! -f "$_RL" ]; then fail "hooks/refuter-ledger.sh is missing — no verdict of crew-refuter is ever recorded, so --verified can back nothing"
8995
+ else
8996
+ _rlt="$(mktemp -d)"; mkdir -p "$_rlt/p"
8997
+ printf '%s\n' '{"type":"user","content":"files: src/a.js\nchange: audit\nverify: none\nfinding: sec-idor-1\nlens: protection\ncite: src/a.js:3\nclaim: anyone reads any order"}' > "$_rlt/t.jsonl"
8998
+ _rl(){ # $1 agent id, $2 agent type, $3 answer (JSON-escaped), [$4 extra env] -> rows in the ledger after
8999
+ printf '{"hook_event_name":"SubagentStop","session_id":"s1","agent_id":"%s","agent_type":"%s","agent_transcript_path":"%s","last_assistant_message":"%s"}' \
9000
+ "$1" "$2" "$_rlt/t.jsonl" "$3" | env CLAUDE_PROJECT_DIR="$_rlt/p" ${4:-} bash "$_RL" >/dev/null 2>&1
9001
+ _rlrc=$?
9002
+ _rln=0; [ -f "$_rlt/p/.claude/state/crew-refuter.tsv" ] && _rln=$(($(wc -l < "$_rlt/p/.claude/state/crew-refuter.tsv") - 1))
9003
+ }
9004
+ _rlb=""
9005
+ _rl a1 crew-refuter 'checked\nFINDING: sec-idor-1\nLENS: protection\nVERDICT: FALSE_POSITIVE\nREASON: guard at src/a.js:2\nconfidence: high'
9006
+ [ "$_rlrc" = 0 ] && [ "$_rln" = 1 ] || _rlb="$_rlb match(rc=$_rlrc,rows=$_rln)"
9007
+ _rl a1 crew-refuter 'FINDING: sec-idor-1\nLENS: protection\nVERDICT: TRUE_POSITIVE'
9008
+ [ "$_rln" = 1 ] || _rlb="$_rlb resumed-agent-counted-twice"
9009
+ _rl a2 crew-refuter 'FINDING: sec-idor-1\nLENS: reachability\nVERDICT: TRUE_POSITIVE'
9010
+ [ "$_rln" = 1 ] || _rlb="$_rlb answer-on-another-lens-recorded"
9011
+ _rl a3 crew-refuter 'FINDING: sec-other\nLENS: protection\nVERDICT: TRUE_POSITIVE'
9012
+ [ "$_rln" = 1 ] || _rlb="$_rlb answer-on-another-finding-recorded"
9013
+ _rl a4 crew-refuter 'FINDING: sec-idor-1\nLENS: protection\nVERDICT: PROBABLY'
9014
+ [ "$_rln" = 1 ] || _rlb="$_rlb verdict-outside-the-three-recorded"
9015
+ _rl a5 crew-security-expert 'FINDING: sec-idor-1\nLENS: protection\nVERDICT: TRUE_POSITIVE'
9016
+ [ "$_rln" = 1 ] || _rlb="$_rlb another-agent-type-recorded"
9017
+ _rl a6 crewforth:crew-refuter 'FINDING: sec-idor-1\nLENS: protection\nVERDICT: CANNOT_VERIFY'
9018
+ [ "$_rln" = 2 ] || _rlb="$_rlb plugin-namespaced-type-not-recorded"
9019
+ _rl a7 crew-refuter 'FINDING: sec-idor-1\nLENS: protection\nVERDICT: TRUE_POSITIVE' CREW_MODEL_ROUTING=off
9020
+ [ "$_rln" = 3 ] || _rlb="$_rlb not-recorded-with-routing-off"
9021
+ _o="$(printf 'not json' | env CLAUDE_PROJECT_DIR="$_rlt/p" bash "$_RL" 2>/dev/null; echo "rc=$?")"
9022
+ [ "$_o" = rc=0 ] || _rlb="$_rlb unreadable-payload:$_o"
9023
+ _rlrow="$(sed -n 2p "$_rlt/p/.claude/state/crew-refuter.tsv" 2>/dev/null | cut -f3-6 | tr '\t' ' ')"
9024
+ [ "$_rlrow" = "a1 sec-idor-1 protection FALSE_POSITIVE" ] || _rlb="$_rlb row:[$_rlrow]"
9025
+ [ -z "$_rlb" ] && pass "refuter-ledger.sh: one line when task and answer agree (9 cases: resumed, other lens, other finding, bad verdict, other agent, plugin name, routing off, bad payload)" \
9026
+ || fail "refuter-ledger.sh:$_rlb"
9027
+ # Its guards: the ledger's file name is refused to the shell and to the file tools; the agent's name is not.
9028
+ _rlg(){ printf '{"hook_event_name":"PreToolUse","tool_name":"%s","permission_mode":"default","tool_input":%s}' "$1" "$2" \
9029
+ | env CLAUDE_PROJECT_DIR="$_rlt/p" bash "$HOOKS/$3" >/dev/null 2>&1; echo $?; }
9030
+ _g1="$(_rlg Bash '{"command":"echo x >> .claude/state/crew-refuter.tsv"}' guard-bash.sh)"
9031
+ _g2="$(_rlg Bash '{"command":"grep -rn crew-refuter agents"}' guard-bash.sh)"
9032
+ _g3="$(_rlg Write "{\"file_path\":\"$_rlt/p/.claude/state/crew-refuter.tsv\",\"content\":\"x\"}" guard-write.sh)"
9033
+ _g4="$(_rlg Write "{\"file_path\":\"$_rlt/p/notes.md\",\"content\":\"x\"}" guard-write.sh)"
9034
+ [ "$_g1" = 2 ] && [ "$_g2" = 0 ] && [ "$_g3" = 2 ] && [ "$_g4" = 0 ] \
9035
+ && pass "the refuter ledger is refused by name to the shell (rc 2) and the file tools (rc 2); a grep for the agent and a plain file are not (rc 0)" \
9036
+ || fail "refuter ledger guards: shell write $_g1 (want 2), grep $_g2 (want 0), Write $_g3 (want 2), plain Write $_g4 (want 0)"
9037
+ rm -rf "$_rlt"
9038
+ fi
9039
+ # Wired in both editions: SubagentStop, matched on the agent type.
9040
+ _rlw=""; for _pf in $_pawf2; do
9041
+ json_hooks "$_pf" | LC_ALL=C awk -F'\t' '$1 == "SubagentStop" && $2 ~ /crew-refuter/ && $3 ~ /refuter-ledger\.sh/ { f = 1 } END { exit !f }' || _rlw="$_rlw ${_pf##*/}"
9042
+ done
9043
+ [ -z "$_rlw" ] && pass "refuter-ledger.sh is wired to SubagentStop, matched on crew-refuter, in every edition read" || fail "refuter-ledger.sh is not wired to SubagentStop on crew-refuter in:$_rlw"
8722
9044
  for _pf in $_pawf2; do
8723
9045
  _wo=""; for _ev in SubagentStart SubagentStop PostToolUse SessionStart; do
8724
9046
  json_hooks "$_pf" | LC_ALL=C awk -F'\t' -v e="$_ev" '$1 == e && $3 ~ /agent-outcome\.sh/ { f = 1 } END { exit !f }' || _wo="$_wo $_ev"; done
@@ -8938,21 +9260,24 @@ CPT='0/ask 0/allow @@ git commit -m x
8938
9260
  0 0 @@ bash -c \x27git log --grep=commit\x27
8939
9261
  0 0 @@ grep -rn \"git commit -n\" docs/
8940
9262
  0/ask 0/allow @@ bash build.sh && git commit -m x
8941
- 0/ask 0/allow @@ cat > notes.md <<\x27EOF\x27\nrun: bash -c \x27git commit -am x\x27 and it\x27s gone\nEOF\ngit commit -m x'
9263
+ 0/ask 0/allow @@ cat > notes.md <<\x27EOF\x27\nrun: bash -c \x27git commit -am x\x27 and it\x27s gone\nEOF\ngit commit -m x
9264
+ 0/ask 0/allow @@ git commit -m x # trailing words -a'
8942
9265
  _cf_table "$CPT"
8943
- if [ "$_cfn" != 47 ]; then fail "FIXTURE: the everyday-commit table has $_cfn rows, not 47"
8944
- elif [ -z "$_cfbad" ]; then pass "47 everyday calls are judged as before (asked in default, allowed when pre-authorised): chained after git add, a message that holds flags and separators, a here-document message, -F, -S, -uno, redirections, a pipe, a comment, a cd into this same repository, GIT_AUTHOR_*, a script beside the commit"
9266
+ if [ "$_cfn" != 48 ]; then fail "FIXTURE: the everyday-commit table has $_cfn rows, not 48"
9267
+ elif [ -z "$_cfbad" ]; then pass "48 everyday calls are judged as before (asked in default, allowed when pre-authorised): chained after git add, a message that holds flags and separators, a here-document message, -F, -S, -uno, redirections, a pipe, a comment, a cd into this same repository, GIT_AUTHOR_*, a script beside the commit"
8945
9268
  else fail "everyday commit calls that changed verdict:$_cfbad"; fi
8946
9269
 
8947
- # Three everyday calls the OLDER scan refuses, and still does: it reads any a/o/i/p in a short token as a flag
8948
- # (`-uno`, a key id after -S) and reads past a comment sign. The new reading parses all three correctly; they are
8949
- # kept refused because this change only adds refusals — letting them through is a loosening, to be decided on its own.
9270
+ # Two everyday calls the OLDER scan refuses, and still does: it reads any a/o/i/p in a short token as a flag
9271
+ # (`-uno`, a key id after -S). The newer scan parses both correctly; they are kept refused because letting them
9272
+ # through is a loosening of that scan's option table, to be decided on its own. A third row stood here,
9273
+ # `git commit -m x # trailing words -a`: the older scan paired quotes and read on past the comment sign by itself.
9274
+ # It walks the one reader's text now, where a comment is left out, so that call is asked about like any commit
9275
+ # from the index (the row is in the table above).
8950
9276
  CKT='2 0/allow @@ git commit -Skeyid -qm x
8951
- 2 0/allow @@ git commit -uno -m x
8952
- 2 0/allow @@ git commit -m x # trailing words -a'
9277
+ 2 0/allow @@ git commit -uno -m x'
8953
9278
  _cf_table "$CKT"
8954
- if [ "$_cfn" != 3 ]; then fail "FIXTURE: the kept-over-blocks table has $_cfn rows, not 3"
8955
- elif [ -z "$_cfbad" ]; then pass "3 known over-blocks of the older scan are unchanged (-Skeyid, -uno, a flag after a comment sign): nothing was loosened"
9279
+ if [ "$_cfn" != 2 ]; then fail "FIXTURE: the kept-over-blocks table has $_cfn rows, not 2"
9280
+ elif [ -z "$_cfbad" ]; then pass "2 known over-blocks of the older scan are unchanged (-Skeyid, -uno)"
8956
9281
  else fail "the older scan's verdict changed on:$_cfbad"; fi
8957
9282
 
8958
9283
  # ---- the same commit, written for PowerShell --------------------------------------------------------------------
@@ -10312,7 +10637,9 @@ if [ -n "$SGR" ] && [ -f "$SGR/.gitattributes" ] && [ -d "$SGR/packaging" ] && [
10312
10637
  # An empty answer must mean "nothing unpinned", never "git listed nothing": two files every checkout has must
10313
10638
  # be in the listing first. Symlinks and submodules are not regular files; git leaves their i/ field empty.
10314
10639
  SLIST="$(git -C "$SGR" ls-files -- start.sh adopt.sh VERSION LICENSE README.md bin kit plugin 2>/dev/null)"
10315
- if ! printf '%s\n' "$SLIST" | grep -qx 'start.sh' || ! printf '%s\n' "$SLIST" | grep -qx 'kit/CLAUDE.md'; then
10640
+ # Here-strings, not a pipe: `grep -q` exits on its first match, a printf still writing gets SIGPIPE, and under
10641
+ # pipefail that read as "not listed" once the list grew long enough to outlast the match (Linux runner).
10642
+ if ! grep -qx 'start.sh' <<< "$SLIST" || ! grep -qx 'kit/CLAUDE.md' <<< "$SLIST"; then
10316
10643
  fail "git did not list Crewforth's shipped files (start.sh and kit/CLAUDE.md are missing), so the eol pin check measured nothing"
10317
10644
  else
10318
10645
  UNPIN="$(git -C "$SGR" ls-files --eol -- start.sh adopt.sh VERSION LICENSE README.md bin kit plugin 2>/dev/null \
@@ -10368,6 +10695,15 @@ if [ -n "$SGR" ] && [ -f "$SGR/.gitattributes" ] && [ -d "$SGR/packaging" ] && [
10368
10695
  # gate that only runs when someone remembers to run it, which is how the catalogue check went unnoticed.
10369
10696
  [ -z "$UNRUN" ] && pass "every gate verify.sh defines is wired into ci.yml" \
10370
10697
  || fail "verify.sh defines gates ci.yml never runs: $UNRUN — they hold only when run by hand"
10698
+ # The Windows e2e runs as shards of packaging/e2e.sh's map. A shard the matrix does not list is a third of the
10699
+ # rehearsals that runs nowhere while every listed job is green; e2e.sh checks its own map, not the matrix. So
10700
+ # the matrix lists exactly 1/N … N/N, N read from e2e.sh.
10701
+ _e2n="$(sed -n 's/^E2E_SHARDS=\([0-9][0-9]*\)$/\1/p' "$SGR/packaging/e2e.sh" 2>/dev/null)"
10702
+ _e2m="$(grep -oE "shard: [0-9]+/[0-9]+" "$SGR/.github/workflows/ci.yml" | awk '{print $2}' | LC_ALL=C sort -u | tr '\n' ' ')"
10703
+ _e2w=""; if [ -n "$_e2n" ]; then _i=1; while [ "$_i" -le "$_e2n" ]; do _e2w="$_e2w$_i/$_e2n "; _i=$((_i+1)); done; fi
10704
+ if [ -z "$_e2n" ]; then fail "FIXTURE: E2E_SHARDS was not read from packaging/e2e.sh — the shard pin cannot compare"
10705
+ elif [ "$_e2m" = "$_e2w" ]; then pass "ci.yml runs every e2e shard the map has ($_e2w)"
10706
+ else fail "ci.yml's e2e matrix lists shards [$_e2m], packaging/e2e.sh has [$_e2w] — a shard it does not list runs nowhere"; fi
10371
10707
  fi
10372
10708
 
10373
10709
  # EVERY JOB OF EVERY WORKFLOW HAS A TIME LIMIT. A job without one runs for GitHub's default of 360 minutes: a
@@ -10437,7 +10773,7 @@ if [ -n "$SGR" ] && [ -f "$SGR/.gitattributes" ] && [ -d "$SGR/packaging" ] && [
10437
10773
  # starts with a wildcard (which reaches every directory, kit/ included).
10438
10774
  cdo_unsafe(){ while IFS= read -r _p; do case "$_p" in *.sh*|kit*|\**) printf '%s\n' "$_p" ;; esac; done; }
10439
10775
  _cp="$(cdo_pats "$CDO" | tr '\n' ' ' | sed 's/ $//')"
10440
- _want='README*.md site/content/* evals/README.md evals/results/* CHANGELOG.md'
10776
+ _want='README*.md site/* evals/README.md evals/results/* CHANGELOG.md'
10441
10777
  [ "$_cp" = "$_want" ] && pass "the docs-only list is exactly: $_want" \
10442
10778
  || fail "the docs-only list changed — it reads '$_cp', pinned '$_want'. Widening it lets a change skip macOS and Windows; update this pin deliberately"
10443
10779
  _cu="$(cdo_pats "$CDO" | cdo_unsafe)"
@@ -10454,9 +10790,11 @@ if [ -n "$SGR" ] && [ -f "$SGR/.gitattributes" ] && [ -d "$SGR/packaging" ] && [
10454
10790
  [ "$(cdo evals/run.sh)" = code ] || _cv="$_cv evals/run.sh"
10455
10791
  [ "$(cdo kit/README.md)" = code ] || _cv="$_cv kit/README.md"
10456
10792
  [ "$(cdo .github/workflows/ci.yml)" = code ] || _cv="$_cv ci.yml"
10793
+ [ "$(cdo site/scripts/check.mjs site/package-lock.json)" = docs ] || _cv="$_cv site-source"
10794
+ [ "$(cdo site/scripts/build.sh)" = code ] || _cv="$_cv site-script"
10457
10795
  [ "$(printf '' | bash "$CDO")" = code ] || _cv="$_cv empty"
10458
10796
  [ "$(printf 'README.md\r\n' | bash "$CDO")" = docs ] || _cv="$_cv crlf"
10459
- [ -z "$_cv" ] && pass "ci-docs-only.sh: documentation reads docs; a hook, evals/run.sh, kit/README.md, ci.yml or an empty diff reads code" \
10797
+ [ -z "$_cv" ] && pass "ci-docs-only.sh: documentation and the site's sources read docs; a hook, a .sh under site/, evals/run.sh, kit/README.md, ci.yml or an empty diff reads code" \
10460
10798
  || fail "ci-docs-only.sh gave the wrong verdict for:$_cv"
10461
10799
  # The third answer, `text`: a pull request that changes only the text of skills, agents or commands skips the
10462
10800
  # macOS and Windows jobs as a documentation one does, and still runs the Linux verify job. That list is pinned
@@ -10482,10 +10820,13 @@ if [ -n "$SGR" ] && [ -f "$SGR/.gitattributes" ] && [ -d "$SGR/packaging" ] && [
10482
10820
  [ -z "$_cv" ] && pass "ci-docs-only.sh: skill, agent and command text reads text, with documentation too; with a hook, a skill's script, kit/CLAUDE.md or a blocklist it reads code" \
10483
10821
  || fail "ci-docs-only.sh gave the wrong text verdict for:$_cv"
10484
10822
  # The Linux verify job is gated on nothing: it holds the checks a text change can break.
10485
- _cyv="$(awk '/^ verify:$/{f=1;next} f && /^ [a-z-]+:$/{f=0} f' "$SGR/.github/workflows/ci.yml" | grep -cE '^ (if|needs):')"
10823
+ # One condition is allowed, and only this one: it skips the run a label other than full-ci starts, and says
10824
+ # nothing about what the pull request changed.
10825
+ _cyv="$(awk '/^ verify:$/{f=1;next} f && /^ [a-z-]+:$/{f=0} f' "$SGR/.github/workflows/ci.yml" | grep -E '^ (if|needs):' \
10826
+ | grep -vxF " if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'" | grep -c .)"
10486
10827
  _cyn="$(awk '/^ verify:$/{f=1;next} f && /^ [a-z-]+:$/{f=0} f' "$SGR/.github/workflows/ci.yml" | grep -c 'bash packaging/verify.sh')"
10487
10828
  [ "$_cyv" = 0 ] && [ "$_cyn" -ge 1 ] \
10488
- && pass "ci.yml runs the Linux verify job on every pull request, a text-only one included (no if:, no needs:)" \
10829
+ && pass "ci.yml runs the Linux verify job on every pull request, a text-only one included (no needs:, and no if: but the one that skips an unrelated label)" \
10489
10830
  || fail "ci.yml's verify job is conditional ($_cyv if:/needs: line(s)) or was not found ($_cyn verify.sh call(s)): a text-only pull request would skip the budget, pointer, routing and plugin checks"
10490
10831
  # ...and ci.yml really uses it: both cross-platform jobs are gated on its answer, nothing else is.
10491
10832
  _cy="$SGR/.github/workflows/ci.yml"
@@ -10604,6 +10945,63 @@ sec "== 14b) the star line (once, on a first install) and the front page it poin
10604
10945
  # One file owns the line — its URL, both languages, and when it stays quiet — so these checks drive THAT file,
10605
10946
  # with CI and CREW_NO_STAR set or cleared by each case itself: a runner exports CI=true, and a check that read it
10606
10947
  # from the environment would pass here and assert the opposite there.
10948
+ # ---- the status line: what it says, and where it is set ----------------------------------------------------------
10949
+ # eval/lib/statusline.sh reads Claude Code's stdin and the hooks' own records. What it must never do: show a gate
10950
+ # line or an agent from before the session (the gate log carries no time), or replace a status line of the user's.
10951
+ SLS="$ROOT/eval/lib/statusline.sh"
10952
+ if [ -f "$SLS" ]; then
10953
+ _sl="$(mktemp -d)"; mkdir -p "$_sl/p/.claude/state/crew-model/agents" "$_sl/p/.claude/state/crew-model/results" "$_sl/home"
10954
+ ( cd "$_sl/p" && git init -q . ) >/dev/null 2>&1
10955
+ printf 'ASK\t§4.4\tcommit\t\n' > "$_sl/p/.claude/gate-log.tsv"; : > "$_sl/p/.claude/state/crew-model/agents/before"
10956
+ _slj='{"session_id":"sl1","context_window":{"used_percentage":34.6},"cost":{"total_cost_usd":1.2034},"rate_limits":{"five_hour":{"used_percentage":90}},"workspace":{"project_dir":"'"$_sl/p"'"}}'
10957
+ sleep 1
10958
+ _o1="$(printf '%s' "$_slj" | (cd "$_sl" && bash "$SLS") 2>&1)"
10959
+ sleep 1
10960
+ printf 'BLOCK\t§4.2\tforce push\t\n' >> "$_sl/p/.claude/gate-log.tsv"
10961
+ : > "$_sl/p/.claude/state/crew-model/agents/run1"; : > "$_sl/p/.claude/state/crew-model/agents/done1"; : > "$_sl/p/.claude/state/crew-model/results/done1"
10962
+ if [ "${BASH_VERSINFO[0]}" -ge 5 ]; then printf -v _now '%(%s)T' -1; else _now="$(date +%s)"; fi
10963
+ # 330 s old: 24 minutes left for the next 30 s, so a slow machine does not read 23 (measured in an install: 23).
10964
+ printf 'v=1\nop=commit\nts=%s\n' "$((_now - 330))" > "$_sl/p/.git/crewforth-approval"
10965
+ _o2="$(printf '%s' "$_slj" | (cd "$_sl" && bash "$SLS") 2>&1)"
10966
+ _o3="$(printf '' | bash "$SLS" 2>&1)"
10967
+ [ "$_o1" = "🔋 34% · ~\$1.20" ] && [ "$_o2" = "🛡 BLOCK §4.2 · ✓ commit approved 24m · ⚙ 1 crew agent · 🔋 34% · ~\$1.20" ] && [ -z "$_o3" ] \
10968
+ && pass "status line: the session's own gate line, a standing approval and its running crew agents; nothing from before the session; the context fill, not a rate limit's; silent on no input" \
10969
+ || fail "status line said: first='$_o1' · later='$_o2' · no input='$_o3'"
10970
+ # --install: only where no status line is set, and never through a file it cannot read.
10971
+ # The project's settings carry a hook of the user's own beside Crewforth's: both must come through whole.
10972
+ # Built from Crewforth's hooks alone: in an installed project settings.json already carries the status line.
10973
+ if [ -f "$ROOT/settings.json" ]; then
10974
+ printf '{"hooks":%s}\n' "$(awk -v op=get -v path=hooks -f "$ROOT/eval/lib/settings-json.awk" "$ROOT/settings.json" 2>/dev/null)" > "$_sl/base.json"
10975
+ awk -v op=merge -v retired= -f "$ROOT/eval/lib/settings-json.awk" "$_sl/base.json" /dev/stdin > "$_sl/p/.claude/settings.json" 2>/dev/null <<'JSON'
10976
+ {"hooks":{"Stop":[{"hooks":[{"type":"command","command":"my-own-stop-hook"}]}]}}
10977
+ JSON
10978
+ fi
10979
+ [ -s "$_sl/p/.claude/settings.json" ] || printf '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"my-own-stop-hook"}]}]}}\n' > "$_sl/p/.claude/settings.json"
10980
+ _hb="$(awk -v op=get -v path=hooks -f "$ROOT/eval/lib/settings-json.awk" "$_sl/p/.claude/settings.json" 2>/dev/null | cksum)"
10981
+ _i(){ (cd "$_sl/p" && env CLAUDE_CONFIG_DIR="$_sl/home" bash "$SLS" --install 2>&1); }
10982
+ _hk0="$(awk -v op=len -v path=hooks -f "$ROOT/eval/lib/settings-json.awk" "$_sl/p/.claude/settings.json" 2>/dev/null)"
10983
+ _r1="$(_i)"; _c1="$(awk -v op=get -v path=statusLine.command -f "$ROOT/eval/lib/settings-json.awk" "$_sl/p/.claude/settings.json" 2>/dev/null)"
10984
+ _hk1="$(awk -v op=len -v path=hooks -f "$ROOT/eval/lib/settings-json.awk" "$_sl/p/.claude/settings.json" 2>/dev/null)"
10985
+ _ha="$(awk -v op=get -v path=hooks -f "$ROOT/eval/lib/settings-json.awk" "$_sl/p/.claude/settings.json" 2>/dev/null | cksum)"
10986
+ grep -q 'my-own-stop-hook' "$_sl/p/.claude/settings.json" || _ha="lost the user's own hook"
10987
+ _r2="$(_i)"
10988
+ cp "$_sl/base.json" "$_sl/p/.claude/settings.json" 2>/dev/null || printf '{"hooks":{}}\n' > "$_sl/p/.claude/settings.json"
10989
+ printf '{"statusLine":{"type":"command","command":"mine"}}\n' > "$_sl/home/settings.json"
10990
+ _sum0="$(cksum < "$_sl/p/.claude/settings.json")"; _r3="$(_i)"; _sum1="$(cksum < "$_sl/p/.claude/settings.json")"
10991
+ rm -f "$_sl/home/settings.json"; printf '{bad' > "$_sl/p/.claude/settings.json"; _r4="$(_i)"; _b4="$(cat "$_sl/p/.claude/settings.json")"
10992
+ case "$_c1" in *eval/lib/statusline.sh*) _c1=ok ;; esac
10993
+ [ "$_r1/$_c1/$_r2/$_r3/$_r4" = "installed/ok/kept/kept/failed" ] && [ "$_hk0" = "$_hk1" ] && [ -n "$_hk0" ] && [ "$_hb" = "$_ha" ] && [ "$_sum0" = "$_sum1" ] && [ "$_b4" = "{bad" ] \
10994
+ && pass "status line --install: set where none is, every hook kept byte for byte, Crewforth's and the user's own ($_hk1 events); kept when set; a user's own left untouched; a file it cannot read left as it was" \
10995
+ || fail "status line --install: $_r1/$_c1/$_r2/$_r3/$_r4 (want installed/ok/kept/kept/failed), hooks $_hk0 -> $_hk1 (content $([ "$_hb" = "$_ha" ] && echo same || echo "CHANGED: $_ha")), user's case changed the file: $([ "$_sum0" = "$_sum1" ] || echo yes), invalid left as '$_b4'"
10996
+ # The reader's gets: several values in one read, an absent one empty, a string with its quotes.
10997
+ _g="$(printf '{"a":{"b":1},"c":"x y"}' | awk -v op=gets -v 'path=a.b|nope|c' -f "$ROOT/eval/lib/settings-json.awk" - 2>&1)"
10998
+ [ "$_g" = "1"$'\t\t'"\"x y\"" ] && pass "settings-json.awk gets: several paths in one read, tab-separated, an absent one empty" \
10999
+ || fail "settings-json.awk gets printed '$_g'"
11000
+ rm -rf "$_sl"
11001
+ else
11002
+ skip scope "status line checks skipped (this project has no eval/lib/statusline.sh)" 3
11003
+ fi
11004
+
10607
11005
  STAR="$ROOT/eval/lib/star.sh"
10608
11006
  if [ -f "$STAR" ]; then
10609
11007
  _SURL="$(sed -n 's/^CREW_REPO_URL="\(.*\)"$/\1/p' "$STAR" | head -1)"
@@ -10643,6 +11041,26 @@ if [ -f "$STAR" ]; then
10643
11041
  && pass "--once: once per version (shown · same version silent · new version shown), marker holds the version; a silenced run writes nothing" \
10644
11042
  || fail "--once broken: v1='${_o1:+shown}' v1-again='${_o2:+shown}' v2='${_o3:+shown}' marker='$_mv' silenced='${_o4:+shown}' marker-after='$_mv4'"
10645
11043
  rm -rf "$_SP"
11044
+ # doctor keeps its own marker: the line an installer showed for a version does not silence doctor's, and doctor
11045
+ # shows it once per version too. Before 3.2.0 they shared one, so doctor almost never showed it.
11046
+ _SD="$(mktemp -d)"; mkdir -p "$_SD/.claude"; printf '9.9.0\n' > "$_SD/.claude/VERSION"
11047
+ _r(){ env -u CI -u CREW_NO_STAR -u CSK_NO_STAR bash "$STAR" --once "$_SD" "$@" 2>&1 | grep -c '⭐'; }
11048
+ _d="$(_r)$(_r)$(_r doctor)$(_r doctor)"
11049
+ _dn="$(env -u CI -u CSK_NO_STAR CREW_NO_STAR=1 bash "$STAR" --once "$_SD" doctor 2>&1)"
11050
+ [ "$_d" = 1010 ] && [ -z "$_dn" ] && [ -f "$_SD/.claude/star-shown-doctor" ] \
11051
+ && pass "--once doctor: its own marker (install shown, again silent, doctor shown, again silent); CREW_NO_STAR silences it" \
11052
+ || fail "--once doctor: install/install/doctor/doctor printed $_d (want 1010), silenced='${_dn:+shown}'"
11053
+ rm -rf "$_SD"
11054
+ # The plugin edition has no .claude/VERSION: the version is read from the manifest beside star.sh (../../).
11055
+ _SPL="$(mktemp -d)"; mkdir -p "$_SPL/plug/eval/lib" "$_SPL/plug/.claude-plugin" "$_SPL/proj"
11056
+ cp "$STAR" "$ROOT/eval/lib/settings-json.awk" "$_SPL/plug/eval/lib/" 2>/dev/null
11057
+ [ -f "$ROOT/eval/lib/crew-env.sh" ] && cp "$ROOT/eval/lib/crew-env.sh" "$_SPL/plug/eval/lib/"
11058
+ printf '{\n "name": "crewforth",\n "version": "9.8.7"\n}\n' > "$_SPL/plug/.claude-plugin/plugin.json"
11059
+ env -u CI -u CREW_NO_STAR -u CSK_NO_STAR bash "$_SPL/plug/eval/lib/star.sh" --once "$_SPL/proj" doctor >/dev/null 2>&1
11060
+ _pv="$(head -1 "$_SPL/proj/.claude/star-shown-doctor" 2>/dev/null)"
11061
+ [ "$_pv" = 9.8.7 ] && pass "a plugin install's star marker holds the plugin manifest's version (9.8.7)" \
11062
+ || fail "a plugin install's star marker holds '${_pv:-nothing}', not the manifest's 9.8.7"
11063
+ rm -rf "$_SPL"
10646
11064
  if command -v git >/dev/null 2>&1; then
10647
11065
  _SG="$(mktemp -d)"; ( cd "$_SG" && git init -q . ) >/dev/null 2>&1; mkdir -p "$_SG/.claude"; printf '9.9.0\n' > "$_SG/.claude/VERSION"
10648
11066
  env -u CI -u CREW_NO_STAR -u CSK_NO_STAR bash "$STAR" --once "$_SG" >/dev/null 2>&1
@@ -10666,7 +11084,7 @@ if [ -f "$STAR" ]; then
10666
11084
  [ -z "$_dup$_nocall" ] && pass "the repo URL lives only in lib/star.sh; $(printf '%s\n' $_callers | grep -c .) caller(s) call it" \
10667
11085
  || fail "star single source broken — URL copied into:${_dup:- none} · not calling star.sh:${_nocall:- none}"
10668
11086
  else
10669
- skip scope "star line checks skipped (this project has no eval/lib/star.sh)" 7
11087
+ skip scope "star line checks skipped (this project has no eval/lib/star.sh)" 9
10670
11088
  fi
10671
11089
  # The front page. Kit repo only: an installed project has no README of ours.
10672
11090
  if [ "$IS_KIT" = 1 ]; then
@@ -10742,12 +11160,12 @@ adopt.sh kit/legacy-blobs.tsv 347 migration: finds and moves 2.x names (componen
10742
11160
  bin/cli.js 4 migration: add accepts a typed <x>-csk and moves an add record written under the old names
10743
11161
  evals/run.sh 4 compat: reads the 2.x trusted eval parent when the 3.0 one is absent — removed in 4.0
10744
11162
  site/scripts/check.mjs 7 tests: the old-name pattern of the built-site gate, and its twins
10745
- */eval/doctor.sh 6 migration: PROOF-5 and the variable notice name what is still on the 2.x spelling
11163
+ */eval/doctor.sh 8 migration: PROOF-5 and the variable notice name what is still on the 2.x spelling; 9c names the 2.x plugin id
10746
11164
  */crew-env.* 18 compat layer (bash + Node): reads CSK_* when CREW_* is unset — removed in 4.0
10747
11165
  */hooks/board.sh 42 compat layer: reads the 2.x board ref and settings and folds them in — removed in 4.0
10748
11166
  */skills/automode-policy/scripts/check.sh 4 compat layer: counts auto-mode rules still named by 2.x — removed in 4.0
10749
11167
  */studio/web/storage-migrate.js 4 migration: moves the panel'"'"'s saved layout to the new keys — removed in 4.0
10750
- kit/eval/smoke-test.sh 36 tests: this gate'"'"'s own pattern, and that the 2.x names still work
11168
+ kit/eval/smoke-test.sh 42 tests: this gate'"'"'s own pattern, and that the 2.x names still work (doctor 9c: the 2.x plugin id; the star line'"'"'s doctor marker)
10751
11169
  packaging/legacy-npm/* 10 the 2.x package name'"'"'s 3.0.0: a forwarder to crewforth, published once by hand
10752
11170
  packaging/* 154 tests: the migration rehearsal on the real v2.13.0 tree, the legacy token and layout checks; the legacy blob list'"'"'s generator and its real-installer check'
10753
11171
  # A line may name several globs, separated by spaces, when one reason covers them all; its pin is their sum. Split
@@ -11170,7 +11588,7 @@ _EVR="$(cd "$(dirname "$0")/../.." && pwd)/evals/run.sh"
11170
11588
  _PY3OK=0
11171
11589
  printf '' | python3 -c 'import sys,json' >/dev/null 2>&1 && _PY3OK=1
11172
11590
  if [ -f "$_EVR" ] && [ "$_PY3OK" = 0 ]; then
11173
- skip tool "evals metric not calibrated (no working python3 — eval_trace_metrics is a python heredoc)" 6
11591
+ skip tool "evals metric not calibrated (no working python3 — eval_trace_metrics is a python heredoc)" 7
11174
11592
  elif [ -f "$_EVR" ]; then
11175
11593
  _EVD="$(mktemp -d)"
11176
11594
  # NOT IN A SUBSHELL, and that was a real defect in the first draft of this block: the five rows below ran
@@ -11219,6 +11637,15 @@ $_res")"
11219
11637
  [ "$(_f "$_p" 19)" = 2 ] \
11220
11638
  && pass "evals metric: two id-less messages stay two, not one" \
11221
11639
  || fail "evals metric: id-less messages collapsed [$_p] — parallel_msgs would undercount"
11640
+ # agents_by_type (column 21): WHICH agent the main thread started. A count of calls looked healthy while two agents
11641
+ # were never started; this names them. A plugin's namespace is dropped, a call with no type is general-purpose, and
11642
+ # a subagent's own call is not the main thread's.
11643
+ _p="$(_mk typed "$(printf '%s' '{"type":"assistant","message":{"id":"m1","content":[{"type":"tool_use","id":"x1","name":"Agent","input":{"subagent_type":"crew-commit-agent"}},{"type":"tool_use","id":"x2","name":"Agent","input":{"subagent_type":"crewforth:crew-review-agent"}},{"type":"tool_use","id":"x3","name":"Agent","input":{}}]}}')
11644
+ $(_msg s1 1 n1)
11645
+ $_res")"
11646
+ { [ "$(_f "$_p" 21)" = "crew-commit-agent:1,crew-review-agent:1,general-purpose:1" ] && [ "$(_f "$(_mk none_t "$_res")" 21)" = "-" ]; } \
11647
+ && pass "evals metric: agents_by_type names the main thread's agents (namespace dropped, untyped is general-purpose, nested not counted, none is -)" \
11648
+ || fail "evals metric: agents_by_type read [$(_f "$_p" 21)]"
11222
11649
  _p="$(_mk none "$_res")"
11223
11650
  { [ "$(_f "$_p" 19)" = 0 ] && [ "$(_f "$_p" 20)" = 0 ]; } \
11224
11651
  && pass "evals metric: a stream with no Agent call reports 0, not empty" \
@@ -11387,7 +11814,7 @@ if [ -s "$SECLOG" ]; then
11387
11814
  ' "$SECLOG"
11388
11815
  echo "---"
11389
11816
  fi
11390
- rm -f "$SECLOG"
11817
+ rm -f "$SECLOG"; rm -rf "$_SMOKE_CCD"
11391
11818
  if [ "$SKIPN" -gt 0 ]; then
11392
11819
  echo "SKIPPED (nothing was checked here):$SKIP_LIST"
11393
11820
  echo "---"