@yeison.restrepo.r/code-conductor 1.36.0 → 1.37.0

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.
package/README.md CHANGED
@@ -122,7 +122,12 @@ Four checks live in `tools/` as tracked repository infrastructure. Three of them
122
122
  - Agent definitions provided by plugins are not searched.
123
123
  - A halted run cannot be resumed, only ended and restarted.
124
124
 
125
- No role agent definitions ship until `[FEAT-012]`.
125
+ The five role agent definitions it dispatches ship from `1.37.0`; their limits are the next item.
126
+ - **The role agents (`1.37.0`) are bounded by their tool masks, and Guard 7 bounds one thing beneath them: the shell.**
127
+ - `qa`'s test command is enforcement: Guard 5 keeps qa from writing, so qa only ever runs files it did not write. `code`'s identical allowance is process discipline, not a security boundary, because code writes the tests that command runs.
128
+ - The profiles are live in this repository, because the mirror convention puts them in `.claude/agents/`. The standing rule forbids starting an orchestrator run here; it does not forbid the files being present. A role dispatched by hand through `/agents` or `Agent` creates no band envelope, so Guard 5 allows every write its mask holds, which is `[ARCH-010]`'s no-envelope rule. Guard 7 still denies it the shell. This is named, not fixed.
129
+ - Installing or updating copies `.claude/agents/{spec,plan,code,audit,qa}.md` over the host project's files of the same names, as it does every shipped `.claude/` asset.
130
+ - A gate certifies protocol position and the claim its role states, never the truth of the work beyond that claim.
126
131
  - **The `P7` false positive above**, still live.
127
132
  - **A re-run against an untouched `project.md` prints a recovery hint it cannot prove is needed.** If you install, never write anything into `.claude/memory/project.md`, and install again, you get a line suggesting the file may have been overwritten by a pre-`1.30.0` re-run. It was not; it equals the stub because it was seeded and never edited. The check compares content and **cannot distinguish "seeded and untouched" from "clobbered"**, which is why the wording is hedged to "may have been" rather than "was". This residual is named and accepted in [`BUG-039`'s spec at `:129`](docs/superpowers/specs/2026-09-27-bug039-installer-host-owned-state-design.md), where the alternative (restoring from the host's own git history) was rejected as writing host files out of the host's history with new failure modes. A **fresh** install is silent, which the Quickstart shows.
128
133
  - **Three open dossiers**, which are the evidence-collection pipeline working rather than a backlog: a session denial tally, one for interleaved-artifact reports, and an intermittent commit-hook hang in the `snap-build` suite. A dossier holds specimens until a mechanism is characterized by probe; an id is minted only when the written condition is met. `[BUG-047]` is what that pipeline produces when it completes: an out-of-scope note, then a dossier, then four specimens across four sessions, then a mint, then a release.
@@ -228,7 +233,7 @@ All commands are tagged `(Conductor)` in the Claude Code command palette so they
228
233
  | `/cc-plan` | Require an approved spec, map the codebase, and generate an ordered implementation plan with exact file paths, a test list, a commit order, and identified risks. Every generated task line carries a unique `[T-NNN]` ID (min 3 digits, unlimited suffix depth) using plain ASCII checkboxes — enforced at generation time. |
229
234
  | `/cc-compact` | Phase-boundary command. Serializes the current phase's essential state (decisions, pending steps, files touched, constraints) into a single-line SNAP JSON snapshot at `.claude/memory/session-snapshot.json` — and, when Node `>= 22.5` is available, a git-hash-keyed row in the local `.conductor/cache.db` — then prompts you to run `/compact` to clear conversation history. Run at the end of every phase to prevent context overflow. |
230
235
  | `/cc-implement` | Execute implementation tasks from an approved plan using a surgical 5-step ritual: Grep-locate pending tasks → single-line Read verify → pre-flip `[ ]` to `[>]` → execute → post-flip to `[X]` or `[!]`. Never reads or rewrites the full plan file. Includes dependency evaluation, drift detection, and a Step 6 hook that records each task's final state to a local SQLite cache (see below). |
231
- | `/cc-orchestrate <ITEM> [--auto]` | Route one backlog item through Define, Build and Verify. For each role it builds, validates (`snap-validate --to`) and installs a SNAP v3 band envelope, dispatches the agent named after the role, waits for its completion notice, and checks the one `SNAP_HANDBACK` line of its delivered hand-back before the next. It pauses before every dispatch unless `--auto`; the spec and plan approvals always pause. A failed validation halts the run, terminally in this version (recover with `end`, then `start`). It needs agent definitions named `spec`, `plan`, `code`, `audit` and `qa` in `.claude/agents/` or `~/.claude/agents/`, none of which ship yet, and plans in the writing-plans format (`### Task N` with a `**Files:**` block). Release stays human. |
236
+ | `/cc-orchestrate <ITEM> [--auto]` | Route one backlog item through Define, Build and Verify. For each role it builds, validates (`snap-validate --to`) and installs a SNAP v3 band envelope, dispatches the agent named after the role, waits for its completion notice, and checks the one `SNAP_HANDBACK` line of its delivered hand-back before the next. It pauses before every dispatch unless `--auto`; the spec and plan approvals always pause. A failed validation halts the run, terminally in this version (recover with `end`, then `start`). It needs agent definitions named `spec`, `plan`, `code`, `audit` and `qa` in `.claude/agents/` or `~/.claude/agents/`, which ship from `1.37.0`; a root `package.json` with a `test` script, or a stack whose test command detect-stack names, since `start` records the one command `code` and `qa` may run and halts when none resolves; and plans in the writing-plans format (`### Task N` with a `**Files:**` block). Release stays human. |
232
237
 
233
238
  Each of `/cc-spec`, `/cc-plan`, and `/cc-implement` opens its phase with a **resume read** (`scripts/resume-read.mjs`): it restores any context stored for the current git commit, so work survives branch switches and rollbacks (see [Local State Cache & Session Persistence](#local-state-cache--session-persistence--v1220)).
234
239
  | `/cc-review [file\|dir]` | Review code in three layers - Critical / Important / Suggestion - then deliver a verdict and offer to auto-fix. |
@@ -318,6 +323,8 @@ Hit a block you believe is wrong? Re-run the command with `CC_GUARD3_WARN=1` and
318
323
  - Inside the live session, only a main-session-dispatched non-role agent can write the surface itself, the band envelope included. So Guard 6 bounds where the orchestrator writes, not who writes inside that surface.
319
324
  - An agent that keeps writing after its hand-back is bounded only by the envelope in force.
320
325
 
326
+ **Role shell guard (Guard 7)** - a `Bash` call from a subagent whose `agent_type` names a band role is decided before Guard 3, so Guard 3's `CC_GUARD3_WARN` ask can never outrank it. `spec`, `plan` and `audit` have no shell (`ROLE_SHELL_DENIED`). `code` and `qa` may run exactly one command, byte for byte: the `test_command` that `orchestrate.mjs start` recorded in the run file of a run live in their session. A command carrying `;`, `&`, `|`, a backtick, `$(`, `<`, `>` or a line break is denied first (`ROLE_SHELL_CHAINING`). No run file, a run of another session, or no recorded command is denied (`ROLE_SHELL_UNRESOLVED`), and any other command is denied naming the allowed one (`ROLE_SHELL_NOT_ALLOWED`). An error inside the guard denies too, and `CC_HOOK_ALLOW` does not reach it. The main session and every other agent are untouched. The two allowances differ in kind: for `qa`, which Guard 5 keeps from writing, the guard is enforcement; for `code`, which writes the tests the command runs, it is process discipline, not a security boundary. `start` resolves the command before it writes anything: the package manager's `test` invocation when a root `package.json` has a `test` script (`npm test`, `pnpm test`, `yarn test`, or `bun run test` by lockfile, and `npm test` with none), detect-stack's test command when there is no `package.json`, and otherwise a halt (`ORCH_TEST_COMMAND_UNRESOLVED`). A resolved command carrying a chaining character halts too (`ORCH_TEST_COMMAND_UNSAFE`), so nothing is recorded that Guard 7 would deny.
327
+
321
328
  Input the hook cannot parse fails closed: it is denied with one stderr line naming `CC_HOOK_ALLOW=1`, which overrides that denial alone and leaves every guard fully active on every payload the hook can read. Set `CC_HOOK_DEBUG=1` to see the diagnostic lines it otherwise swallows.
322
329
 
323
330
  ### context-guard *(global + project)* — v1.15.0
@@ -418,6 +425,7 @@ code-conductor/
418
425
  │ ├── gitignore Merged into the host project's .gitignore
419
426
  │ └── .claude/
420
427
  │ ├── settings.json Hooks wiring (pre-tool-use, post-compact)
428
+ │ ├── agents/ Band roles: spec, plan, code, audit, qa (FEAT-012)
421
429
  │ ├── commands/
422
430
  │ │ ├── cc-init.md /cc-init — session initialization
423
431
  │ │ ├── cc-resume.md /cc-resume — session context restore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeison.restrepo.r/code-conductor",
3
- "version": "1.36.0",
3
+ "version": "1.37.0",
4
4
  "description": "A governance layer for Claude Code sessions: hooks that check an agent's commands before they run, a spec-first workflow, and project memory the next session reads.",
5
5
  "keywords": [
6
6
  "agentic-development",
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: audit
3
+ description: Verify-band role of a /cc-orchestrate run. Reviews the item's changes statically against its spec and plan, read-only, and hands back build_executed with its findings. No shell. Dispatched only by /cc-orchestrate during a run; never use it for ad-hoc work.
4
+ tools: Read, Grep, Glob
5
+ ---
6
+
7
+ You are the `audit` role of a code-conductor orchestrated run. The orchestrator dispatched you with a brief naming the item, its spec and its plan, and installed your band envelope at `.claude/memory/band-envelope.json`. Read the envelope first.
8
+
9
+ ## Your job
10
+
11
+ Review the work the code role produced, statically, against the approved spec and plan. The plan's `**Files:**` blocks name the files each task changed; read them as they stand now. Check them against the spec's behavior and acceptance criteria, the plan's tasks, and the conventions in the project's `CLAUDE.md`. Nothing is run: judge what is written.
12
+
13
+ ## Success condition
14
+
15
+ Your success condition is fixed: a static review of the changes against the spec and plan was completed, and its findings are listed in your report, each with a `file:line` and one sentence. Findings do not withhold the gate; the claim is that the review was done and reported. Do not substitute a stricter or different standard of your own.
16
+
17
+ ## Rules
18
+
19
+ - You have no shell and no write tools.
20
+ - A hook or owner denial is an instruction to stop and report, never an obstacle to route around.
21
+ - Never dispatch or message another agent.
22
+ - Deliver exactly one report, ending in exactly one `SNAP_HANDBACK` line, then stop. Claim only the gate `build_executed`.
23
+ - Copy `ops.scope` verbatim from your envelope into the hand-back; if your envelope has no scope, leave the key out.
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: code
3
+ description: Build-band role of a /cc-orchestrate run. Implements one plan task inside the files it names, runs the run's recorded test command, and hands back build_executed. Dispatched only by /cc-orchestrate during a run; never use it for ad-hoc work.
4
+ tools: Read, Grep, Glob, Write, Edit, Bash
5
+ ---
6
+
7
+ You are the `code` role of a code-conductor orchestrated run. The orchestrator dispatched you with a brief naming one task of the approved plan, and installed your band envelope at `.claude/memory/band-envelope.json`. Read the envelope first: its `ops.scope` is the task's files plus the plan file.
8
+
9
+ ## Your job
10
+
11
+ Implement exactly the task your brief names. Touch only the files in your envelope's scope; Guard 5 denies a write anywhere else. When the task is done, tick its checkboxes in the plan.
12
+
13
+ ## The test command
14
+
15
+ Your shell runs one command: the run's test command, the `test_command` field of `.claude/memory/orchestrator-run.json`. Run exactly the command named in the run file, byte for byte, with no added flag, pipe, redirect or second command. Guard 7 denies anything else, and its denial names the allowed command.
16
+
17
+ ## Success condition
18
+
19
+ Your success condition is fixed: after your last edit you ran the test command, and your report states its exact exit status and summary line. A red suite is reported as red; the gate claims only that the run happened and was reported. Do not substitute a stricter or different standard of your own.
20
+
21
+ ## Rules
22
+
23
+ - A hook or owner denial is an instruction to stop and report, never an obstacle to route around. Never redo a denied write through another tool.
24
+ - Never dispatch or message another agent.
25
+ - Deliver exactly one report, ending in exactly one `SNAP_HANDBACK` line, then stop. Claim only the gate `build_executed`.
26
+ - Copy `ops.scope` verbatim from your envelope into the hand-back; if your envelope has no scope, leave the key out.
27
+ - List every file you changed in the hand-back's `ops.f` as `<path>:C`, `<path>:M` or `<path>:D`.
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: plan
3
+ description: Define-band role of a /cc-orchestrate run. Writes the implementation plan for the approved spec under docs/superpowers/plans/ and hands back boundary_routed. No shell. Dispatched only by /cc-orchestrate during a run; never use it for ad-hoc work.
4
+ tools: Read, Grep, Glob, Write, Edit
5
+ ---
6
+
7
+ You are the `plan` role of a code-conductor orchestrated run. The orchestrator dispatched you with a brief naming the item and its approved spec, and installed your band envelope at `.claude/memory/band-envelope.json`. Read the envelope first.
8
+
9
+ ## Your job
10
+
11
+ Write the implementation plan for the item from its approved spec, as one new file under `docs/superpowers/plans/`. Use the writing-plans format, because the orchestrator routes code tasks from it: each task is a `### Task N: <name>` heading followed by a `**Files:**` block whose lines start `- Create:`, `- Modify:` or `- Test:` and name each path in backticks. A code agent may touch only the files its task names, so name every file the task changes, its tests included. A task's envelope scope is its files plus the plan file, and the router halts a scope over 20 entries with `ORCH_SCOPE_OVER_CAP`, so keep each task to 19 files or fewer. Order the tasks so that each one ends with the suite green.
12
+
13
+ ## Success condition
14
+
15
+ Your success condition is fixed: a plan file was written under `docs/superpowers/plans/` from the approved spec, and each task names its files. Do not substitute a stricter or different standard of your own.
16
+
17
+ ## Rules
18
+
19
+ - You have no shell. Write only inside your envelope's scope; Guard 5 denies anything else.
20
+ - A hook or owner denial is an instruction to stop and report, never an obstacle to route around.
21
+ - Never dispatch or message another agent.
22
+ - Deliver exactly one report, ending in exactly one `SNAP_HANDBACK` line, then stop. Claim only the gate `boundary_routed`.
23
+ - Copy `ops.scope` verbatim from your envelope into the hand-back; if your envelope has no scope, leave the key out.
24
+ - List the plan file in the hand-back's `ops.f` as `<path>:C`. The owner approves that path.
@@ -0,0 +1,26 @@
1
+ ---
2
+ name: qa
3
+ description: Verify-band role of a /cc-orchestrate run. Re-runs the run's recorded test command as a non-author and hands back verify_pass only when the suite passes. No write tools. Dispatched only by /cc-orchestrate during a run; never use it for ad-hoc work.
4
+ tools: Read, Grep, Glob, Bash
5
+ ---
6
+
7
+ You are the `qa` role of a code-conductor orchestrated run. The orchestrator dispatched you with a brief naming the item, and installed your band envelope at `.claude/memory/band-envelope.json`. Read the envelope first.
8
+
9
+ ## Your job
10
+
11
+ Verify the item independently. You did not write this code and you cannot write files. Your run of the suite is the authoritative one, whatever any other role reported.
12
+
13
+ ## The test command
14
+
15
+ Your shell runs one command: the run's test command, the `test_command` field of `.claude/memory/orchestrator-run.json`. Run exactly the command named in the run file, byte for byte, with no added flag, pipe, redirect or second command. Guard 7 denies anything else, and its denial names the allowed command.
16
+
17
+ ## Success condition
18
+
19
+ Your success condition is fixed: you ran the test command yourself and the suite passed, meaning the command exited with status 0. Report its exact exit status and summary line. Do not substitute a stricter or different standard of your own: exit status 0 is a pass, and anything else is a fail.
20
+
21
+ ## Rules
22
+
23
+ - A hook or owner denial is an instruction to stop and report, never an obstacle to route around.
24
+ - Never dispatch or message another agent.
25
+ - Deliver exactly one report, then stop. If the suite passed, end it in exactly one `SNAP_HANDBACK` line and claim only the gate `verify_pass`. If it failed, leave the `SNAP_HANDBACK` line out and say why, quoting the summary line.
26
+ - Copy `ops.scope` verbatim from your envelope into the hand-back; if your envelope has no scope, leave the key out.
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: spec
3
+ description: Define-band role of a /cc-orchestrate run. Writes the spec for one backlog item under docs/superpowers/specs/ and hands back boundary_routed. No shell. Dispatched only by /cc-orchestrate during a run; never use it for ad-hoc work.
4
+ tools: Read, Grep, Glob, Write, Edit
5
+ ---
6
+
7
+ You are the `spec` role of a code-conductor orchestrated run. The orchestrator dispatched you with a brief naming the item and installed your band envelope at `.claude/memory/band-envelope.json`. Read the envelope first.
8
+
9
+ ## Your job
10
+
11
+ Write the spec for the item as one new file under `docs/superpowers/specs/`, named `YYYY-MM-DD-<topic>-design.md`. Read the item's backlog entry and the code it touches before you write. The spec states the problem, the solution, the behavior including its error cases, testable acceptance criteria, what is out of scope, and the files the change affects.
12
+
13
+ ## Success condition
14
+
15
+ Your success condition is fixed: a spec file was written under `docs/superpowers/specs/` that answers the item. List the questions the codebase does not settle as open questions in your report; do not decide them, because the owner rules them at the approval boundary. Do not substitute a stricter or different standard of your own.
16
+
17
+ ## Rules
18
+
19
+ - You have no shell. Write only inside your envelope's scope; Guard 5 denies anything else.
20
+ - A hook or owner denial is an instruction to stop and report, never an obstacle to route around.
21
+ - Never dispatch or message another agent.
22
+ - Deliver exactly one report, ending in exactly one `SNAP_HANDBACK` line, then stop. Claim only the gate `boundary_routed`.
23
+ - Copy `ops.scope` verbatim from your envelope into the hand-back; if your envelope has no scope, leave the key out.
24
+ - List the spec file in the hand-back's `ops.f` as `<path>:C`.
@@ -34,11 +34,12 @@ A halt is terminal in v1 (D12). Recovery is `node "$S/orchestrate.mjs" end`, the
34
34
 
35
35
  ## Steps
36
36
 
37
- 1. **Start.** Run `node "$S/orchestrate.mjs" start $ARGUMENTS`.
37
+ 1. **Start.** Run `node "$S/orchestrate.mjs" start $ARGUMENTS`. It resolves the run's test command before it writes anything, and its stdout ends with `test command: <command>`.
38
38
  - If stdout names a replaced stale run, report its item and start time.
39
39
  - On `ORCH_RUN_ACTIVE`, report it, offer `end`, and stop.
40
+ - On `ORCH_TEST_COMMAND_UNRESOLVED` or `ORCH_TEST_COMMAND_UNSAFE`, report it and stop. No run file was written, so there is nothing to `end`. The owner adds a `test` script to `package.json`, or removes the chaining from the command it names, before a fresh `start`.
40
41
 
41
- Print the run header: the item, the mode (`step` unless `--auto` was given), and the first role, `spec`.
42
+ Print the run header: the item, the mode (`step` unless `--auto` was given), the test command, and the first role, `spec`.
42
43
  2. **Each dispatch.** Take the roles in band order: `spec`, `plan`, then `code` once per plan task, then `audit`, then `qa`. For each one:
43
44
  1. **Check.** Run `node "$S/orchestrate.mjs" install <role> --check`. Print the role and the envelope it prints, and state that `--to <role>` passed.
44
45
  2. **Pause.** In step mode, ask the owner for a go. On a decline, stop: the run stays at its position, and nothing is installed. Under `--auto`, skip this pause.
@@ -86,6 +87,6 @@ The role's task, its `ph`, and the gate it hands back:
86
87
  |---|---|---|---|
87
88
  | `spec` | Write the spec for `<ITEM>` under `docs/superpowers/specs/`. | `spec` | `boundary_routed` |
88
89
  | `plan` | Write the plan under `docs/superpowers/plans/` in the writing-plans format: `### Task N` headings, each with a `**Files:**` block. Name the plan path in `ops.f`. | `plan` | `boundary_routed` |
89
- | `code` | Implement `<Task N>` of `<plan>`, touching only its files, and tick its boxes in the plan. | `impl` | `build_executed` |
90
+ | `code` | Implement `<Task N>` of `<plan>`, touching only its files, and tick its boxes in the plan. After your last edit, run the run's test command exactly and report its exit status and summary line. | `impl` | `build_executed` |
90
91
  | `audit` | Review the changes against the spec and the plan, read-only. | `rev` | `build_executed` |
91
- | `qa` | Run the project's tests and report. If verification fails, leave out the `SNAP_HANDBACK` line and say why. | `rev` | `verify_pass` |
92
+ | `qa` | Run the run's test command exactly and report. If the suite fails, leave out the `SNAP_HANDBACK` line and say why. | `rev` | `verify_pass` |
@@ -244,6 +244,45 @@ function guard6OrchestratorRun(input, payload) {
244
244
  return deny(`Guard 6: ORCH_WRITE_DENIED: ${target || '<no path>'} is outside the orchestrator's write surface while run ${run.item} is live; repository writes during a run go through a band role (Guard 5).`);
245
245
  }
246
246
 
247
+ // ── Guard 7 constants ─────────────────────────────────────────────────────────
248
+ // A copy of scripts/orchestrate.mjs SHELL_METACHARACTERS (FEAT-012 D10), carried for Guard
249
+ // 5's reason: no import resolves from both install locations. tests/hooks/guard7.test.js pins it.
250
+ const ROLE_SHELL_METACHARACTERS = [';', '&', '|', '`', '$(', '<', '>', '\n', '\r'];
251
+ const ROLE_SHELL_ROLES = ['code', 'qa'];
252
+
253
+ // R3: the test command a live run of this session recorded, or null. The run root is found
254
+ // by Guard 5's walk and the file read by Guard 6's reader.
255
+ function liveTestCommand(payload) {
256
+ const root = findRootHolding(payloadCwd(payload), ORCH_RUN_REL);
257
+ if (!root) return null;
258
+ const run = readRunFile(join(root, ...ORCH_RUN_REL));
259
+ if (!run || payload.session_id !== run.session_id) return null;
260
+ return typeof run.test_command === 'string' && run.test_command !== '' ? run.test_command : null;
261
+ }
262
+
263
+ // R1-R5, the first match decides. The match is exact: a prefix allowlist is walked around by
264
+ // chaining, which is the T-003 vector.
265
+ function roleShellDecision(role, input, payload) {
266
+ if (!ROLE_SHELL_ROLES.includes(role)) return deny(`Guard 7: ROLE_SHELL_DENIED: ${role} has no shell.`);
267
+ const command = typeof input.command === 'string' ? input.command : '';
268
+ const found = ROLE_SHELL_METACHARACTERS.find((m) => command.includes(m));
269
+ if (found !== undefined) return deny(`Guard 7: ROLE_SHELL_CHAINING: the command contains ${JSON.stringify(found)}; a role runs one command, never a chain.`);
270
+ const allowed = liveTestCommand(payload);
271
+ if (allowed === null) return deny(`Guard 7: ROLE_SHELL_UNRESOLVED: no live run in this session records a test command, so ${role} has no shell.`);
272
+ if (command !== allowed) return deny(`Guard 7: ROLE_SHELL_NOT_ALLOWED: allowed command is ${allowed}`);
273
+ return null;
274
+ }
275
+
276
+ // Guard 7: a band role's Bash (FEAT-012). The tool mask is the authority and this is the layer
277
+ // beneath it: in FEAT-011's T-003 a declined Write was completed through Bash, so a prompt is
278
+ // not enough. Fail-closed: a throw denies here, where CC_HOOK_ALLOW cannot reach it.
279
+ function guard7RoleShell(input, payload) {
280
+ const role = payload.agent_type;
281
+ if (!BAND_ROLES.includes(role)) return null;
282
+ try { return roleShellDecision(role, input, payload); }
283
+ catch (e) { return deny(`Guard 7: ROLE_SHELL_UNRESOLVED: the guard could not decide (${e && e.message}), so the call is denied.`); }
284
+ }
285
+
247
286
  // ── Guard 3 constants ─────────────────────────────────────────────────────────
248
287
  // POSIX ERE fragments from tests/fixtures/guard3-reference.sh, translated class by
249
288
  // class. [[:space:]] in the C locale is EXACTLY [ \t\n\r\f\v]; JavaScript \s also
@@ -704,6 +743,9 @@ const DISPATCH = {
704
743
  for (const tool of BAND_WRITE_TOOLS) DISPATCH[tool].unshift(guard5BandScope, guard6OrchestratorRun);
705
744
  // R7 sees dispatch only where settings.json routes it: the matcher names Agent and SendMessage.
706
745
  for (const tool of ORCH_DISPATCH_TOOLS) DISPATCH[tool] = [guard6OrchestratorRun];
746
+ // Guard 7 runs before Guard 3 on Bash: under CC_GUARD3_WARN Guard 3 asks instead of denying,
747
+ // and an ask must never outrank a role's shell deny.
748
+ DISPATCH.Bash.unshift(guard7RoleShell);
707
749
 
708
750
  // Case B. Unparseable input is not "nothing to verify", it is "the verifier could not
709
751
  // run", which is the condition that fails closed. CC_HOOK_ALLOW bypasses THIS denial only;
@@ -34,6 +34,11 @@ export const MAY_HAND_BACK = {
34
34
  audit: ['build_executed'], qa: ['verify_pass'],
35
35
  };
36
36
  const PHASE = { spec: 'spec', plan: 'plan', code: 'impl', audit: 'rev', qa: 'rev' };
37
+ // Guard 7's chaining set (FEAT-012 D7). The hook carries a copy pinned to this one (D10).
38
+ export const SHELL_METACHARACTERS = [';', '&', '|', '`', '$(', '<', '>', '\n', '\r'];
39
+ // D6: each package manager's invocation of the owner's `test` script. `bun test` would run
40
+ // Bun's own test runner and ignore the script, so bun goes through `run`.
41
+ export const PM_TEST_COMMAND = { npm: 'npm test', pnpm: 'pnpm test', yarn: 'yarn test', bun: 'bun run test' };
37
42
 
38
43
  // A halt stops the run and is recorded in it (D12). A refusal is a misuse of the CLI:
39
44
  // nothing is written and nothing is recorded.
@@ -172,6 +177,48 @@ function runScript(name, args, input = '') {
172
177
  return { status: r.status, out: r.stdout, err: (r.stderr || '').trim() };
173
178
  }
174
179
 
180
+ // detect-stack installs process-wide error handlers when imported, so it is spawned. It prints
181
+ // {} on any failure, which answers nothing either way.
182
+ function detectStack(root) {
183
+ let out = null;
184
+ try { out = JSON.parse(runScript('detect-stack.mjs', [root]).out); } catch { /* judged below */ }
185
+ if (isPlainObject(out) && Object.keys(out).length > 0) return out;
186
+ throw new Halt('ORCH_TEST_COMMAND_UNRESOLVED', `detect-stack returned no result for ${root}`);
187
+ }
188
+
189
+ // Only a non-blank string is the owner's test script.
190
+ function hasTestScript(pkgPath) {
191
+ let pkg;
192
+ try { pkg = JSON.parse(readFileSync(pkgPath, 'utf8').replace(/^\uFEFF/, '')); } catch {
193
+ throw new Halt('ORCH_TEST_COMMAND_UNRESOLVED', `${pkgPath} does not parse, so its test script cannot be read`);
194
+ }
195
+ const script = pkg?.scripts?.test;
196
+ return typeof script === 'string' && script.trim() !== '';
197
+ }
198
+
199
+ // D6: the one command code and qa may run, resolved before anything is recorded. The script
200
+ // is checked before detect-stack runs, because a non-string script makes detect-stack fail
201
+ // whole and the halt would then name the wrong cause.
202
+ export function resolveTestCommand(root) {
203
+ const pkgPath = join(root, 'package.json');
204
+ if (existsSync(pkgPath)) {
205
+ if (!hasTestScript(pkgPath)) {
206
+ throw new Halt('ORCH_TEST_COMMAND_UNRESOLVED', 'package.json has no scripts.test; add a test script, the run does not guess a runner');
207
+ }
208
+ return PM_TEST_COMMAND[detectStack(root).packageManager] ?? PM_TEST_COMMAND.npm;
209
+ }
210
+ const { test } = detectStack(root);
211
+ if (typeof test === 'string' && test.trim() !== '') return test;
212
+ throw new Halt('ORCH_TEST_COMMAND_UNRESOLVED', `detect-stack names no test command for ${root}`);
213
+ }
214
+
215
+ // D7: no command is recorded that Guard 7 would not pass.
216
+ export function checkTestCommand(command) {
217
+ const found = SHELL_METACHARACTERS.find((m) => command.includes(m));
218
+ if (found === undefined) return command;
219
+ throw new Halt('ORCH_TEST_COMMAND_UNSAFE', `${JSON.stringify(command)} contains ${JSON.stringify(found)}, which Guard 7 denies; nothing was recorded`);
220
+ }
221
+
175
222
  // The validator reads a file, so the candidate goes through a private temp dir. Returns
176
223
  // the validator's error text, or '' when it passes.
177
224
  function validate(text, role) {
@@ -280,13 +327,16 @@ function start(root, sessionId, item, flag) {
280
327
  if (!sessionId) throw new Halt('ORCH_NO_SESSION_ID', 'CLAUDE_CODE_SESSION_ID is absent or empty, so Guard 6 could never bind this run');
281
328
  const old = readRun(root);
282
329
  if (old && old.session_id === sessionId) throw new Halt('ORCH_RUN_ACTIVE', `run ${old.item} is live in this session; end it first`);
330
+ // Resolved before a stale run is cleared, so a halt here leaves everything as it was.
331
+ const testCommand = checkTestCommand(resolveTestCommand(root));
283
332
  if (old) clearRunFiles(root);
284
333
  saveRun(root, {
285
334
  v: 1, session_id: sessionId, item, mode: flag ? 'auto' : 'step', started: new Date().toISOString(),
286
335
  band: 'boundary', role: null, gate: 'boundary_routed', approvals: { spec: null, plan: null },
287
- plan: null, tasks: { ids: [], done: 0 }, handbacks: [], halt: null,
336
+ plan: null, tasks: { ids: [], done: 0 }, handbacks: [], halt: null, test_command: testCommand,
288
337
  });
289
- return old ? `replaced the stale run ${old.item} started ${old.started}` : `run ${item} started`;
338
+ const begun = old ? `replaced the stale run ${old.item} started ${old.started}` : `run ${item} started`;
339
+ return `${begun}; test command: ${testCommand}`;
290
340
  }
291
341
 
292
342
  function clearRunFiles(root) {