create-agent-rig 0.7.1 → 0.9.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +184 -2
  2. package/README.md +93 -4
  3. package/package.json +4 -3
  4. package/packages/cli/dist/commands/memory.js +123 -0
  5. package/packages/cli/dist/commands/setup.js +45 -0
  6. package/packages/cli/dist/index.js +107 -3
  7. package/packages/cli/dist/lib/subsystems.js +269 -0
  8. package/packages/cli/dist/lib/version.js +15 -0
  9. package/packages/cli/dist/policy/benchmark/corpus.js +165 -0
  10. package/packages/cli/dist/policy/core/adapter.js +18 -0
  11. package/packages/cli/dist/policy/core/coverage.js +253 -0
  12. package/packages/cli/dist/policy/core/decision-record.js +287 -0
  13. package/packages/cli/dist/policy/core/declaration.js +127 -0
  14. package/packages/cli/dist/policy/core/evidence-matrix.js +94 -0
  15. package/packages/cli/dist/policy/core/probe.js +442 -0
  16. package/packages/cli/dist/policy/core/registry.js +115 -0
  17. package/packages/cli/dist/policy/core/validation.js +275 -0
  18. package/packages/cli/dist/policy/core/vocabulary.js +123 -0
  19. package/packages/cli/dist/policy/harness/claude.js +47 -0
  20. package/packages/cli/dist/policy/harness/codex.js +87 -0
  21. package/packages/cli/dist/policy/harness/index.js +15 -0
  22. package/packages/cli/dist/policy/harness/shared-hooks.js +28 -0
  23. package/packages/cli/dist/policy/index.js +17 -0
  24. package/templates/agent-os/stack/aws-cdk/.claude/agents/cdk-diff-reviewer.md +2 -0
  25. package/templates/agent-os/stack/aws-cdk/.codex/agents/cdk-diff-reviewer.toml +2 -0
  26. package/templates/agent-os/subagent-routing.json +32 -0
  27. package/templates/agent-os/universal/.agents/skills/loop/SKILL.md +48 -7
  28. package/templates/agent-os/universal/.claude/agents/code-reviewer.md +2 -0
  29. package/templates/agent-os/universal/.claude/agents/prose-reviewer.md +2 -0
  30. package/templates/agent-os/universal/.claude/agents/security-scanner.md +2 -0
  31. package/templates/agent-os/universal/.claude/agents/test-writer.md +2 -0
  32. package/templates/agent-os/universal/.claude/hooks/guard-subagent-model.mjs +234 -0
  33. package/templates/agent-os/universal/.claude/hooks/lib/edit-input.mjs +75 -32
  34. package/templates/agent-os/universal/.claude/hooks/warn-subagent-routing.mjs +120 -0
  35. package/templates/agent-os/universal/.claude/rules/autonomy.md +17 -7
  36. package/templates/agent-os/universal/.claude/rules/workflow.md +5 -0
  37. package/templates/agent-os/universal/.claude/scripts/preflight.mjs +27 -3
  38. package/templates/agent-os/universal/.claude/scripts/queue/gate-rounds.mjs +70 -2
  39. package/templates/agent-os/universal/.claude/scripts/queue/index.mjs +12 -4
  40. package/templates/agent-os/universal/.claude/scripts/unattended-flag.mjs +64 -1
  41. package/templates/agent-os/universal/.claude/settings.json +16 -0
  42. package/templates/agent-os/universal/.claude/skills/loop/SKILL.md +48 -7
  43. package/templates/agent-os/universal/.codex/agents/code-reviewer.toml +2 -0
  44. package/templates/agent-os/universal/.codex/agents/prose-reviewer.toml +2 -0
  45. package/templates/agent-os/universal/.codex/agents/security-scanner.toml +2 -0
  46. package/templates/agent-os/universal/.codex/agents/test-writer.toml +2 -0
  47. package/templates/agent-os/universal/.codex/config.toml +3 -0
  48. package/templates/agent-os/universal/docs/decisions/codex-adapter.md +31 -5
  49. package/templates/agent-os/universal/docs/decisions/subagent-routing.md +142 -0
  50. package/templates/agent-os/universal/layers.json +4 -0
  51. package/templates/hash-history.json +15 -7
  52. package/templates/release-ledger.json +3 -1
  53. package/templates/skeleton/node-service/services/api/test/artifact.test.ts +3 -4
  54. package/templates/skeleton/node-service/services/api/test/package-manager.test.ts +40 -0
  55. package/templates/skeleton/node-service/services/api/test/package-manager.ts +51 -0
  56. package/templates/skeleton/node-service/services/api/test/static-dir.test.ts +9 -8
@@ -26,10 +26,10 @@ import { fileURLToPath } from 'node:url';
26
26
  // cycle, because preflight is the only scripted brake check and had no test.
27
27
  import { brakeIsOn } from './stop-flag.mjs';
28
28
  import { readRevalidationContract } from './lib/claim-records.mjs';
29
+ import { loadConfig, optionsWithPlanPath, resolveAdapter } from './queue/index.mjs';
29
30
 
30
31
  /** The items this script cannot check: judgement, or a call worth more than it saves. */
31
32
  export const UNCHECKED = [
32
- 'the queue is reachable through its adapter (`node .claude/scripts/queue/index.mjs next`)',
33
33
  'no stray worktree from a dead session that this run might mistake for its own',
34
34
  'a budget is declared for this run, and it is written down somewhere the run can re-read',
35
35
  ];
@@ -136,6 +136,30 @@ export const checkDetectionContract = (projectRoot) => {
136
136
  }
137
137
  };
138
138
 
139
+ // See test/template/preflight-queue.test.ts (absent in a generated rig) ›
140
+ // "reads exactly one adapter listing without selecting, claiming, or writing queue and run files".
141
+ export const checkQueue = async (projectRoot) => {
142
+ try {
143
+ const configPath = join(projectRoot, '.claude', 'queue.json');
144
+ const config = loadConfig(configPath, { strictRead: true });
145
+ const adapterName = config.adapter ?? 'plan-md';
146
+ const adapter = await resolveAdapter(adapterName);
147
+ await adapter.listEligible(optionsWithPlanPath(config.options, configPath));
148
+ return { ok: true, detail: `queue readable through ${adapterName}` };
149
+ } catch (error) {
150
+ const diagnostic = Array.from(String(error?.message ?? error), (character) => {
151
+ const code = character.codePointAt(0);
152
+ return code < 0x20 || (code >= 0x7f && code <= 0x9f)
153
+ ? `\\u${code.toString(16).padStart(4, '0')}`
154
+ : character;
155
+ }).join('');
156
+ return {
157
+ ok: false,
158
+ detail: `could not read queue: ${diagnostic}`,
159
+ };
160
+ }
161
+ };
162
+
139
163
  /** The last deploy must have concluded successfully — never start on a broken runtime. */
140
164
  export const checkLastDeploy = ({ workflow = 'deploy' } = {}) => {
141
165
  try {
@@ -157,8 +181,7 @@ export const checkLastDeploy = ({ workflow = 'deploy' } = {}) => {
157
181
 
158
182
  /**
159
183
  * STOP on any hard failure; CAUTION on anything that is not a clean pass; GO only
160
- * when every scripted item genuinely passed. The three unscripted items are still
161
- * the reader's.
184
+ * when every scripted item genuinely passed. Unscripted checks remain the reader's.
162
185
  *
163
186
  * `stale` and `unknown` both give CAUTION but are never merged into one word:
164
187
  * "I looked and it is stale" is actionable, "I could not look" is not, and neither
@@ -216,6 +239,7 @@ if (invokedDirectly()) {
216
239
  killSwitch: checkKillSwitch(),
217
240
  runDirNotExported: checkRunDirNotExported(),
218
241
  detectionContract: checkDetectionContract(projectRoot),
242
+ queue: await checkQueue(projectRoot),
219
243
  defaultBranchFresh: checkDefaultBranchFresh(),
220
244
  lastDeploy: checkLastDeploy(),
221
245
  };
@@ -25,9 +25,26 @@
25
25
  * and the failure is bounded and in the generous direction. What was worth fixing is
26
26
  * the crash it came with — a fixed temp filename made the losers of that race fail
27
27
  * with `ENOENT` on rename, reporting "could not run" for a condition nothing named.
28
+ * Pinned by the generator's `test/template/concurrent-sessions.test.ts`
29
+ * (absent in a generated rig) › "eight concurrent recordGateRound calls all exit 0
30
+ * and leave one parseable counter between one and eight".
31
+ *
32
+ * ⚠ **And a second crash, Windows-only, measured on the same race (RP-120):** a
33
+ * rename over a file another process holds open is refused there with `EPERM`, for
34
+ * exactly as long as the handle is open — a reader's `readFileSync` is enough. Eight
35
+ * racing callers lost one to it in four rounds of thirty, and each loser left its
36
+ * temp file behind. So the rename is retried within a fixed budget
37
+ * (`RENAME_BUDGET_MS`: the pauses between attempts never exceed it; the rename
38
+ * calls themselves add their own wall time), and a loser that still cannot rename
39
+ * removes its temp file and reports the code and the file rather than a bare
40
+ * `EPERM`. That is a bounded retry, not a lock: the count can still lose an
41
+ * increment, and nothing waits on a holder past the budget. Pinned by the
42
+ * generator's `test/template/gate-rounds.test.ts` (absent in a generated rig) ›
43
+ * "retries the rename while another process holds the counter open, and still counts the round"
44
+ * and › "gives up past its budget, removes its temp file, keeps the old count, and names the code and the file".
28
45
  */
29
46
 
30
- import { renameSync, readFileSync, writeFileSync } from 'node:fs';
47
+ import { renameSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
31
48
  import { join } from 'node:path';
32
49
 
33
50
  import { mainCheckoutRoot } from './checkout.mjs';
@@ -154,7 +171,58 @@ export const recordGateRound = ({ branch, projectRoot, roundsPath } = {}) => {
154
171
  const updated = Object.assign(Object.create(null), rounds, { [key]: next });
155
172
  const temp = `${file}.${process.pid}.tmp`;
156
173
  writeFileSync(temp, `${JSON.stringify(updated, null, 2)}\n`);
157
- renameSync(temp, file);
174
+ replaceWithRetry(temp, file);
158
175
 
159
176
  return { rounds: next };
160
177
  };
178
+
179
+ // How many times the rename is tried, and how long each retry waits.
180
+ const RENAME_ATTEMPTS = 20;
181
+ const RENAME_BACKOFF_MS = 10;
182
+ /** The whole budget a caller can spend pausing on a held-open counter. */
183
+ export const RENAME_BUDGET_MS = RENAME_ATTEMPTS * RENAME_BACKOFF_MS;
184
+
185
+ const RETRIED_CODES = new Set(['EPERM', 'EBUSY']);
186
+
187
+ // A synchronous pause: this module is synchronous end to end (the CLI counts a round
188
+ // and exits), and `Atomics.wait` on a throwaway buffer is the one sleep that shape
189
+ // allows without a spin.
190
+ const pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
191
+
192
+ /**
193
+ * Rename `temp` over `file`, retrying a Windows-style refusal within the budget.
194
+ *
195
+ * Every attempt past the last, and every failure of another kind, ends the same way:
196
+ * the temp file is removed so the counter's directory holds nothing but the counter,
197
+ * and the error names the file and the code — the CLI prints that as "could not run",
198
+ * which pr-ship reads as a command failure to retry, not as an exhausted cap.
199
+ */
200
+ const replaceWithRetry = (temp, file) => {
201
+ for (let attempt = 1; ; attempt += 1) {
202
+ try {
203
+ renameSync(temp, file);
204
+ return;
205
+ } catch (error) {
206
+ const code = error?.code ?? 'unknown error';
207
+ if (RETRIED_CODES.has(code) && attempt < RENAME_ATTEMPTS) {
208
+ pause(RENAME_BACKOFF_MS);
209
+ continue;
210
+ }
211
+ // The cleanup must not displace the diagnosis: a temp file that cannot be
212
+ // removed (held open too, on Windows) is reported beside the rename
213
+ // failure, and the rename failure stays the error the caller sees.
214
+ let cleanup = 'and the temp file was removed';
215
+ try {
216
+ rmSync(temp, { force: true });
217
+ } catch (removal) {
218
+ cleanup = `but the temp file ${temp} could not be removed (${removal?.code ?? 'unknown error'})`;
219
+ }
220
+ throw new Error(
221
+ `${file} could not be replaced after ${attempt} attempt${attempt === 1 ? '' : 's'} ` +
222
+ `(${code}): another process may be holding it open. The round was NOT counted ` +
223
+ `${cleanup}; run the command again.`,
224
+ { cause: error },
225
+ );
226
+ }
227
+ }
228
+ };
@@ -12,7 +12,7 @@
12
12
  // defaults to `plan-md`, which is the only adapter that works in a freshly
13
13
  // generated project. An unknown adapter is a hard error, never a fallback: a loop
14
14
  // that silently reads the wrong queue is worse than one that refuses to start.
15
- import { readFileSync, realpathSync, writeFileSync } from 'node:fs';
15
+ import { lstatSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
16
16
  import { fileURLToPath } from 'node:url';
17
17
  import { basename, dirname, join } from 'node:path';
18
18
  import {
@@ -57,11 +57,19 @@ export const COMMANDS = ['next', 'list', 'hygiene', 'gate-round', 'board'];
57
57
  * trailing comma in `queue.json` made the loop read a different queue than the one
58
58
  * configured, which is the exact failure this file's header refuses for adapters.
59
59
  */
60
- export const loadConfig = (configPath) => {
60
+ export const loadConfig = (configPath, { strictRead = false } = {}) => {
61
61
  let raw;
62
62
  try {
63
63
  raw = readFileSync(configPath, 'utf8');
64
- } catch {
64
+ } catch (error) {
65
+ if (
66
+ strictRead &&
67
+ (error?.code !== 'ENOENT' || lstatSync(configPath, { throwIfNoEntry: false }) !== undefined)
68
+ ) {
69
+ throw new Error(`${configPath} could not be read (${error?.code ?? 'unknown error'})`, {
70
+ cause: error,
71
+ });
72
+ }
65
73
  return {};
66
74
  }
67
75
  let parsed;
@@ -70,7 +78,7 @@ export const loadConfig = (configPath) => {
70
78
  } catch (error) {
71
79
  throw new Error(
72
80
  `${configPath} exists but is not valid JSON, so the configured queue cannot be ` +
73
- `read: ${String(error?.message ?? error).split('\n')[0]}. Fix the file — ` +
81
+ 'read. Fix the file — ' +
74
82
  'silently reading a different queue is worse than refusing to start.',
75
83
  { cause: error },
76
84
  );
@@ -445,6 +445,69 @@ if (invokedDirectly()) {
445
445
  process.stdout.write(removed.length === 0 ? 'no unattended flag was set\n' : `${removed.join('\n')}\n`);
446
446
  process.exit(0);
447
447
  }
448
- process.stderr.write(`unknown word: ${word ?? '(none)'}. This CLI has two: on, off.\n`);
448
+ // 🔴 **The read-back `on` did not have, and the reason it is a subcommand
449
+ // rather than a line in the skill (RP-103).**
450
+ //
451
+ // `on` refuses a widening allow entry — correctly — by throwing before it
452
+ // writes anything, so the refusal leaves NO flag on disk. Pinned in the
453
+ // generator's `test/template/unattended-flag.test.ts` (absent in a generated
454
+ // rig) › "does not change `on`: a widening --allow still exits 1 and still
455
+ // writes no flag" — the claim is checkable, so it carries a pointer rather
456
+ // than standing on its own. And `guard-rulebook`
457
+ // reads "no flag" as "attended session" and does nothing. So the run that was
458
+ // meant to be the most constrained became the LEAST: every rulebook path
459
+ // editable, including the hook wiring that enforces the rule. Loud at arming
460
+ // (exit 1), and completely silent for the rest of the run.
461
+ //
462
+ // The asymmetry is what made it a defect rather than a rough edge: the `off`
463
+ // branch above ALREADY reads back, and refuses while naming the record it
464
+ // found. One direction of the same operation verified itself and the other
465
+ // did not.
466
+ //
467
+ // ⚠ **Stating the limit, because this whole file is about a mechanism being
468
+ // trusted further than it goes.** `verify` is mechanical where it runs; that
469
+ // it runs is still the `loop` skill's prose. This closes "the refusal was
470
+ // silent" — the run is told, in a command whose exit status is its whole
471
+ // output — and does NOT close "a run that ignores exit statuses ignores this
472
+ // one too". The hook-enforced version would need `guard-rulebook` to tell
473
+ // "attended" from "unattended but unarmed", and it cannot: absence of a flag
474
+ // is all it sees.
475
+ if (word === 'verify') {
476
+ const item = valueOf('--item');
477
+ if (!item || item.startsWith('--')) {
478
+ process.stderr.write(
479
+ 'unattended-flag verify: --item <id> is required — verifying "some flag is armed" would pass on a stale one from a previous run\n',
480
+ );
481
+ process.exit(1);
482
+ }
483
+ const state = readUnattended(cliEnv);
484
+ // ⚠ `unreadable` carries `on: true` — it means "a flag is THERE and cannot be
485
+ // trusted", which is what `off` needs in order to refuse to clear it blindly.
486
+ // For a read-back it is a FAILURE, not an arming: an unreadable record
487
+ // authorizes nothing, and its `item` is absent, so testing only `!state.on`
488
+ // would fall through to the item-mismatch branch and print the wrong reason
489
+ // for the right refusal.
490
+ if (!state.on || state.unreadable) {
491
+ const why = state.why ? ` (${state.why})` : '';
492
+ process.stderr.write(
493
+ `unattended-flag verify: NO usable unattended flag is armed for ${item}${why}. ` +
494
+ 'guard-rulebook reads an absent flag as an attended session and refuses nothing, so this run is ' +
495
+ 'UNGUARDED against the rulebook — every rule, hook, skill and settings path is editable. ' +
496
+ 'Arm it with a narrower --allow (an allow-list narrows the rulebook, never widens it) and verify again, or stop the run.\n',
497
+ );
498
+ process.exit(1);
499
+ }
500
+ if (state.item !== item) {
501
+ process.stderr.write(
502
+ `unattended-flag verify: the armed flag names ${JSON.stringify(state.item)}, not ${JSON.stringify(item)} — ` +
503
+ `it is a leftover from another run and does not authorize this one. This run is UNGUARDED against the rulebook. ` +
504
+ `Clear it with \`off\` and arm it for ${item}, or stop the run.\n`,
505
+ );
506
+ process.exit(1);
507
+ }
508
+ process.stdout.write(`${state.path ?? 'armed'}\n`);
509
+ process.exit(0);
510
+ }
511
+ process.stderr.write(`unknown word: ${word ?? '(none)'}. This CLI has three: on, verify, off.\n`);
449
512
  process.exit(1);
450
513
  }
@@ -1,4 +1,7 @@
1
1
  {
2
+ "env": {
3
+ "CLAUDE_CODE_SUBAGENT_MODEL": "claude-sonnet-5"
4
+ },
2
5
  "hooks": {
3
6
  "PreToolUse": [
4
7
  {
@@ -34,6 +37,15 @@
34
37
  "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/guard-bash.mjs\""
35
38
  }
36
39
  ]
40
+ },
41
+ {
42
+ "matcher": "Agent",
43
+ "hooks": [
44
+ {
45
+ "type": "command",
46
+ "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/guard-subagent-model.mjs\""
47
+ }
48
+ ]
37
49
  }
38
50
  ],
39
51
  "Stop": [
@@ -53,6 +65,10 @@
53
65
  {
54
66
  "type": "command",
55
67
  "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/inject-rules.mjs\""
68
+ },
69
+ {
70
+ "type": "command",
71
+ "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/warn-subagent-routing.mjs\""
56
72
  }
57
73
  ]
58
74
  }
@@ -79,16 +79,23 @@ state-vs-queue split exists to prevent.
79
79
  node .claude/scripts/preflight.mjs
80
80
  ```
81
81
 
82
- Five items are scripted (kill switch absent · `RIG_RUN_DIR` not already
83
- exported · the versioned revalidation detection contract is supported · local
84
- default branch matches the remote · the last deploy concluded successfully)
82
+ Scripted checks cover the kill switch, inherited `RIG_RUN_DIR`, the versioned
83
+ revalidation detection contract, queue readability through its configured adapter,
84
+ default-branch freshness, and the last deploy result,
85
85
  and the script **prints the ones it did not check, every time**. Paste the block into the journal: a checklist that
86
86
  leaves no record cannot tell you it was skipped.
87
87
 
88
88
  Verdicts: **STOP** → do not start, deal with the cause. **CAUTION** → start,
89
- knowing which ground is soft. **GO** → the scripted five are clean; the rest are
89
+ knowing which ground is soft. **GO** → the scripted checks are clean; the rest are
90
90
  still yours.
91
91
 
92
+ The queue probe reads one adapter listing without selecting or claiming an item.
93
+ A readable empty queue passes this probe; a configuration, adapter, or queue-read
94
+ failure produces **STOP**. See the generator's `test/template/preflight-queue.test.ts`
95
+ (absent in a generated rig) › "reads exactly one adapter listing without selecting, claiming, or writing queue and run files",
96
+ › "passes a readable empty queue without changing the other preflight verdict or queue state",
97
+ and › "stops when %s cannot be read".
98
+
92
99
  **An `unknown` never becomes a `pass`.** A probe that could not run tells you
93
100
  nothing.
94
101
 
@@ -149,13 +156,47 @@ What a hook CAN see is a file, so the unattended signal is one:
149
156
  # at claim time, from the paths the item names (repo-relative prefixes, with
150
157
  # their trailing slash); the guard refuses every other rulebook edit while it is on
151
158
  node .claude/scripts/unattended-flag.mjs on --root "$PWD" --item <item-id> --run-dir "$RIG_RUN_DIR" --allow <prefix> [<prefix>…]
159
+
160
+ # 🔴 THEN READ IT BACK, and stop the run if it is not armed. Not optional.
161
+ node .claude/scripts/unattended-flag.mjs verify --root "$PWD" --item <item-id>
152
162
  ```
153
163
 
164
+ 🔴 **The second command is the one that makes the first one's failure
165
+ visible, and skipping it inverts the whole mechanism.** `on` refuses an allow
166
+ entry that *widens* the rulebook — and the refusal leaves **no flag on disk**
167
+ (pinned in the generator's `test/template/unattended-flag.test.ts`, absent in a
168
+ generated rig, › "does not change `on`: a widening --allow still exits 1 and
169
+ still writes no flag"), while `guard-rulebook` reads an absent flag as an
170
+ attended session and refuses nothing. So a run that armed with a widening entry and did not check is the
171
+ **least** constrained run this project can produce: every rule, hook, skill and
172
+ settings path editable, with nothing downstream saying so. The failure is loud
173
+ for one line at claim time and silent for the rest of the session.
174
+
175
+ `verify` exits non-zero when no usable flag is armed for this item — absent,
176
+ unreadable, or naming a different item — and its message says the run is
177
+ unguarded rather than merely that a file is missing. **A non-zero exit here ends
178
+ the run**; it does not get retried with a wider allow-list. The natural way to
179
+ hit this is not exotic: an item touching the queue adapter invites `--allow
180
+ .claude/scripts/`, and that entry is refused outright. Pinned in the
181
+ generator's `test/template/unattended-flag.test.ts` (absent in a generated rig)
182
+ › "refuses when no flag is armed, naming the item and the unguarded rulebook"
183
+ and › "refuses when the armed flag names a different item, naming both".
184
+
185
+ ⚠ **What this does not close.** `verify` is mechanical where it runs; that it
186
+ runs is this sentence. It removes the silence, not the possibility that a run
187
+ ignores an exit status — and the hook-enforced version is not available, because
188
+ `guard-rulebook` cannot tell "attended" from "unattended but unarmed": absence of
189
+ a flag is all it sees.
190
+
154
191
  `guard-rulebook` reads it (`.claude/rules/autonomy.md`, "Never"): with the flag
155
192
  on, a Write/Edit/MultiEdit/NotebookEdit/`apply_patch` under the generated
156
- rulebook both harnesses' rules, skills, agents and hook wiring, plus their
157
- scripts, queue config and integrity manifest is refused unless its
158
- path starts with an allowed prefix; the board selector is the one always-refused
193
+ rulebook is refused unless its
194
+ path starts with an allowed prefix. 🔴 **Which paths that covers is
195
+ `RULEBOOK_PREFIXES` in `.claude/scripts/unattended-flag.mjs`** read it before
196
+ composing an allow-list, rather than working from a summary here. A summary is a
197
+ second copy, and the one that used to sit in this sentence had gone stale against
198
+ the set it described. One fact the set cannot carry, so it is stated: the board
199
+ selector is the one always-refused
159
200
  exception and cannot be admitted by an allow-list. With no flag the guard does nothing. An
160
201
  item that needs a rulebook path names it here — a decision made at claim
161
202
  time, never a default — and the stop step below turns the flag off. Pinned in
@@ -1,4 +1,6 @@
1
1
  name = "code-reviewer"
2
2
  description = "Reviews a completed change against the checklist before a PR is opened or merged. Use after any non-trivial implementation work, and always before opening a PR the decision-router puts on its `model` lane, which is everything its two cheap lanes did not claim — code, a rulebook document, an unclassifiable path, a derived artifact git does not report as drift, or anything a risk flag escalated. Blocking findings must be resolved, not argued with."
3
+ model = "gpt-5.6-sol"
4
+ model_reasoning_effort = "high"
3
5
  sandbox_mode = "read-only"
4
6
  developer_instructions = "You review changes. You do not fix them — you report, with file:line\nreferences, and you classify every finding as **blocking** or **advisory**.\n\n## Checklist (blocking findings)\n\n1. **Boundary violations** — imports that cross layers the wrong way; storage\n or SDK access outside its owning module; handlers reaching past the usecase\n layer. See the architecture rules in `.claude/rules/`.\n2. **Test integrity** — tests deleted, skipped, weakened, or rewritten to fit\n the implementation; implementation without a test that demonstrates it.\n3. **Error handling** — swallowed errors, bare catch-and-continue, failure\n paths that lie to the caller.\n4. **Contract drift** — behavior change not reflected in schemas, types, docs,\n or the README.\n5. **Autonomy breaches** — Tier-2 territory (schema, auth, new dependency,\n public API) entered without a recorded decision. See\n `.claude/rules/autonomy.md`.\n6. **Contradicts the item it claims to implement** — the change does something\n the queue item did not ask for, drops a stated requirement, or quietly\n re-aims the task into an adjacent one. Read the item first, then the diff.\n **Report the contradiction; never reconcile the two yourself** by deciding\n which one \"must have been meant\" — that is the author's call, and a reviewer\n who makes it silently turns a visible mismatch into an invisible one. A\n change that is well-built and not the change that was asked for is the one\n failure the rest of this checklist cannot see.\n\n **If the item was not handed to you, say so and stop there.** Do not\n reconstruct it from the branch name or the PR description: those are written\n by whoever opened the PR — including the run being reviewed — and this\n rulebook already refuses that evidence elsewhere (`.claude/rules/autonomy.md`).\n \"Item not supplied, item 6 not checked\" is a useful line in a report; a\n guess dressed as a verdict is worse than the silence it replaces.\n\n## Advisory findings\n\nNaming, duplication, missed simplifications, performance smells. Report them;\ndo not block on them.\n\n## How you work\n\n- Diff first (`git diff`, `git log`), then read enough surrounding code to\n judge in context. Review what changed, not the whole repo.\n- Quote the checklist item a blocking finding violates. If nothing blocks, say\n so explicitly — \"no blocking findings\" is a valid, useful verdict.\n- Do not request rewrites of working, tested code for style alone.\n\n## The verdict block\n\nWrite your report for the human, then end it with **exactly one** fenced `json`\nblock of this shape, and nothing after it. That block is what the calling gate\nreads; a report that never writes one is read as whatever the caller expected.\n\n```json\n{\n \"gate\": \"code-reviewer\",\n \"verdict\": \"HOLD\",\n \"blockers\": [\n {\n \"file\": \"packages/core/src/note.ts\",\n \"line\": 42,\n \"rule\": \"checklist item 2 — test integrity\",\n \"note\": \"the failing case was deleted rather than fixed\"\n }\n ],\n \"advisories\": [],\n \"evidence\": [\"diffed against origin/master\", \"queue item supplied\"],\n \"headSha\": \"9c1f0a7d4b3e2c5a8f6d0b9e7c4a1f2d3e5b6c70\"\n}\n```\n\n- `verdict` is `SHIP`, `HOLD` or `NOT_APPLICABLE` — no other word.\n- Every blocker names the `rule` it violates. `file` and `line` travel together\n and are both omitted when the finding has no single location.\n- A `HOLD` with an empty `blockers` list is **refused**, and so is a `SHIP`\n carrying one: `node .claude/scripts/verdict.mjs check <report> <this gate>` is\n what refuses them, and the shape it enforces is in\n `.claude/scripts/lib/verdict.mjs`. The gate name is what stops your answer\n being read as somebody else's.\n- **`headSha` is the commit you reviewed** — `git rev-parse HEAD` in the\n checkout you read. It is what lets `node .claude/scripts/verdict.mjs coverage\n <commit>` tell \"this gate answered for the commit being merged\" from \"it\n answered two pushes ago\". A verdict naming no commit is counted as neither\n covered nor missing, so `pr-ship` holds on it — and only `pr-ship`: no hook\n runs that check, so a session that skips the gate skips this with it."
@@ -1,4 +1,6 @@
1
1
  name = "prose-reviewer"
2
2
  description = "Reviews the documents that instruct agents — rule files, skills, agent specs, CLAUDE.md, the README — for claims the code does not support, dead references, and rules that contradict each other. Use when a change touches any of them, before the PR."
3
+ model = "gpt-5.6-terra"
4
+ model_reasoning_effort = "high"
3
5
  sandbox_mode = "read-only"
4
6
  developer_instructions = "In this project the prose **is** the implementation. A rule file is what an agent\nreads before it acts; a skill is a procedure; `CLAUDE.md` is the map. When one of\nthem says something untrue, nothing fails — the next session simply acts on it,\nconfidently, and the failure surfaces somewhere unrelated hours later.\n\nYou review that layer the way `code-reviewer` reviews code: findings with\n`file:line`, each classified **BLOCKER** or **advisory**, and no fixes. You do\nnot edit anything.\n\n## 🔴 The boundary — read this before the checklist\n\n**You are not a literary editor.** Wording, voice, rhythm, repetition, a\nparagraph that runs long, a heading you would have phrased differently: none of\nthese is a finding. Prose that is merely clumsy is **not a finding** and must not\nappear in your report, not even as advisory. Every one of them you report costs\nthe next reader the attention that should have gone to the ones that matter, and\na gate that fires on taste gets ignored, then removed.\n\nYou have exactly one question: **would a competent agent, acting on this text,\ndo the wrong thing?** If no, it is not yours.\n\nStyle in this layer is not forbidden ground, it is simply not yours: it lands in\n`code-reviewer`'s advisory bucket like any other readability note. Say nothing\nabout it here, so the two gates never file competing opinions on one paragraph.\n\n## Checklist (blocking findings)\n\n1. **An overstated claim of enforcement.** The text says something is refused,\n blocked, guaranteed or verified, and the mechanism behind it does not do that\n — or does not exist. Read the hook, the script, the CI job, and quote what it\n actually does. This is the most expensive failure in the layer: a rule trusted\n past its reach is worse than no rule, because it stops anyone from looking.\n2. **A dead reference.** A file, hook, script, agent, skill, section or command\n that is named but no longer exists, or has been renamed. Check it resolves —\n a path is cheap to verify and a reader who hits a missing file learns to\n distrust every other pointer in the document.\n3. **Two rules that contradict each other.** Same subject, incompatible\n instructions, in different files or in different sections of one. Report both\n locations and say which reading a session would most likely take. Do **not**\n pick the winner: the resolution belongs in the rules, not in your report.\n4. **A stated limit that has gone stale — in either direction.** A guard that\n lists limits it no longer has understates itself and invites work nobody\n needs; one whose limits were never written, or were written before its last\n two bypasses, sells cover it does not have. Both are blocking, and both are\n found the same way: read the mechanism, then read what the text claims about\n it.\n5. **An unbacked behaviour claim.** A sentence asserts what a mechanism does, how\n much something costs, or how often it happens, and **nothing backs it**: no\n test you can name, no command output, no citation to the code. Per\n `.claude/rules/invariants.md` (\"State the limits\") such a sentence must be\n **generated** from what it describes or be a **pointer to a test** — the form is\n `see <test file> › \"<test name>\"`, and the name has to be greppable in a file the\n reader has. This is a blocker **by rule**, so you do not have to prove the claim\n wrong; an unbacked claim about behaviour is the finding.\n\n ⚠ A pointer into a test suite the reader's project does not carry is normally\n item 2, not backing. There is one narrow inherited-snapshot exception from\n `invariants.md`: a generator-authored artifact — rules, hooks, skills,\n scripts, or agent specs —\n may point to upstream generator tests that are absent locally only when the\n pointer explicitly says the suite is absent locally and\n `.claude/.rig-manifest.json` proves the current artifact's hash matches the\n installed manifest. A manifest-backed upgrade remains an inherited,\n generator-owned artifact; a changed file in the upgrade diff does not alone\n make it downstream-authored. The exception applies **only while the manifest\n hash matches**. A hash mismatch, missing manifest, or no evidence ends the\n exception and the local test is yours; then an absent pointer is item 2 again.\n\n 🔴 Three things this is not. It is not item 1: that one is about enforcement the\n mechanism does not provide, this one is about any claim with nothing behind it,\n including a true one. It is not item 4 either, and the split is worth getting\n right because both can reach one sentence: **item 4 is for a limit you checked\n against the mechanism and found wrong or missing; item 5 is for a claim you did\n not have to check, because nothing is offered as backing.** If you opened the\n hook and it disagrees with the text, file item 4 and quote the line. If there was\n nothing offered to open, file item 5. If you opened it and the claim was right,\n there is no finding. One sentence, one item. And it is not an attack on rationale — \"we chose X\n because Y\" needs no test. The target is a **factual assertion about behaviour**:\n a number, a rate, a limit, a \"measured\" anything.\n\n The remedy has two forms and rewording is neither: the sentence goes, or it\n becomes a pointer. Say which you would expect, and where the test lives if one\n exists.\n6. **Domain that must not travel.** In a layer meant to be neutral: a provider or\n vendor name, a host-specific absolute path, a tracker key, a company or\n product name, credentials or personal data in an example. State which layer\n the file belongs to and why the mention breaks it.\n\n 🔴 **A seam built to name a vendor is not a leak.** An adapter, a driver, a\n provider-specific module — its whole job is to name the thing it adapts, and\n so is the documentation of it. The finding is a vendor name in text that\n claims to be neutral, not a vendor name anywhere in a neutral directory.\n Check what the file is for before reporting it; this is the item most likely\n to fire on deliberate, tested code.\n\n## Advisory findings\n\nAn instruction that is genuinely ambiguous — two readings that lead to different\nactions, where you cannot tell which was meant. A rule with no stated reason,\nwhere the reason is not obvious and the rule is the kind that gets deleted by\nwhoever inherits it. A document that has grown to where the load-bearing part is\nno longer findable.\n\nThat is the whole advisory list, on purpose. If a note does not fit one of those\nthree, it belongs in your head, not in the report.\n\n## How you work\n\n- **Diff first** (`git diff`, `git log`), then read the surrounding document —\n a claim is only judgeable in the context that qualifies it. Review what\n changed, not the whole rulebook.\n- **Verify against the mechanism, never against your memory of it.** Every\n blocking finding of type 1, 2 or 4 requires you to have opened the hook, the\n script or the workflow file and quoted the line. A finding you could not check\n is reported as unverified, or not at all.\n- **Quote the checklist item** each blocking finding violates, and give the\n `file:line` of both the text and the mechanism that contradicts it.\n- **\"No blocking findings\" is a valid and useful verdict.** Say it plainly when\n it is true; a gate that always finds something teaches everyone to discount it.\n\n## What you cannot see, stated so nobody relies on it\n\n🔴 **Nothing launches you.** No hook fires this review; a session reads a rule\nand decides to. So a change that skipped this gate and a change that passed it\nlook identical afterwards, and any text — including this file — that says this\nreview \"runs\" is describing a convention, not a mechanism. Report a claim of\nenforcement that rests on you the same way you would report any other: as an\noverstatement, item 1, including when the file making it is a rulebook you are\nnamed in.\n\nYou read text and the mechanisms it names. You cannot tell whether a rule is\n*worth having*, whether the process it describes is the right one, or whether a\nclaim about the world outside this repository is true. Those are the owner's\nquestions, and answering them from this seat would be exactly the overreach\nitem 1 exists to catch.\n\n## The verdict block\n\nEnd your report with **exactly one** fenced `json` block of this shape, and\nnothing after it. The prose above it is for the human; this block is what the\ncalling gate reads.\n\n```json\n{\n \"gate\": \"prose-reviewer\",\n \"verdict\": \"HOLD\",\n \"blockers\": [\n {\n \"file\": \".claude/rules/invariants.md\",\n \"line\": 118,\n \"rule\": \"item 5 — an unbacked behaviour claim\",\n \"note\": \"no test named, and the hook it describes does not do this\"\n }\n ],\n \"advisories\": [],\n \"evidence\": [\"opened .claude/hooks/guard-bash.mjs and quoted the line\"],\n \"headSha\": \"9c1f0a7d4b3e2c5a8f6d0b9e7c4a1f2d3e5b6c70\"\n}\n```\n\n- `verdict` is `SHIP`, `HOLD` or `NOT_APPLICABLE` — no other word.\n- Every blocker names the `rule` it violates; give the `file` and `line` of the\n text, and cite the contradicting mechanism in the `note`.\n- A `HOLD` naming no blocker is **refused**, and so is a `SHIP` carrying one:\n `node .claude/scripts/verdict.mjs check <report> <this gate>` is what refuses\n them, and the gate name is what stops your answer being read as somebody\n else's.\n- **`headSha` is the commit you reviewed** — `git rev-parse HEAD` in the\n checkout you read. It is what lets `node .claude/scripts/verdict.mjs coverage\n <commit>` tell \"this gate answered for the commit being merged\" from \"it\n answered two pushes ago\". A verdict naming no commit is counted as neither\n covered nor missing, so `pr-ship` holds on it — and only `pr-ship`: no hook\n runs that check, so a session that skips the gate skips this with it."
@@ -1,4 +1,6 @@
1
1
  name = "security-scanner"
2
2
  description = "Scans a change for security issues. MUST be used when a change touches authentication, authorization, secrets or configuration, input parsing, file handling, or any new outbound call. Findings gate the PR."
3
+ model = "gpt-5.6-sol"
4
+ model_reasoning_effort = "high"
3
5
  sandbox_mode = "read-only"
4
6
  developer_instructions = "You are the security gate. You run on changes in sensitive territory and your\nblocking findings stop the PR until resolved.\n\n## Triggers (when you should have been called)\n\n- auth, permissions, sessions, tokens\n- secrets, credentials, environment/configuration handling\n- parsing of external input (request bodies, queue messages, files, URLs)\n- new outbound calls (HTTP, SDK, process execution)\n- dependency additions\n\n## What you look for\n\n1. **Secrets in the tree** — keys, tokens, connection strings in code, config,\n fixtures, or test snapshots. Any hit is blocking.\n2. **Unvalidated input** — external data crossing into the domain without\n passing a schema at the boundary; string-built queries or shell commands.\n3. **Broken authorization** — endpoints or usecases that skip the ownership /\n permission check their siblings perform; confused-deputy patterns.\n4. **Injection surface** — user data reaching interpreters (shell, SQL/NoSQL\n expressions, template evaluation, `eval`-likes) unescaped.\n5. **Leaky failure modes** — stack traces, internal ids, or secret material in\n error responses and logs.\n6. **Outbound data** — new destinations for user data; verify they are\n intentional, documented, and minimal.\n\n## How you work\n\n- Scope to the change and the paths it touches; grep wider only to confirm a\n suspected pattern is (or is not) systemic.\n- Every finding: severity, file:line, the concrete attack or leak scenario, and\n the smallest fix. No theoretical lectures without a code path.\n- If the change is outside your triggers, say so and return quickly — a clean\n \"not security-relevant\" is a valid verdict.\n\n## The verdict block\n\nEnd your report with **exactly one** fenced `json` block of this shape, and\nnothing after it. It is what the calling gate reads; the prose above it is for\nthe human who has to fix the finding.\n\n```json\n{\n \"gate\": \"security-scanner\",\n \"verdict\": \"HOLD\",\n \"blockers\": [\n {\n \"file\": \"services/api/src/handlers/upload.ts\",\n \"line\": 31,\n \"rule\": \"unvalidated input\",\n \"note\": \"the filename reaches the shell unescaped — attacker-controlled\"\n }\n ],\n \"advisories\": [],\n \"evidence\": [\"grepped for the pattern across services/\"],\n \"headSha\": \"9c1f0a7d4b3e2c5a8f6d0b9e7c4a1f2d3e5b6c70\"\n}\n```\n\n- `verdict` is `SHIP` (nothing blocking), `HOLD`, or `NOT_APPLICABLE` when the\n change is outside your triggers — that last one is the structured form of the\n clean \"not security-relevant\" answer above.\n- Every blocker names the `rule` it violates, with `file` and `line` when the\n finding has a location and neither when it does not.\n- A `HOLD` naming no blocker is **refused**, and so is a `SHIP` carrying one:\n `node .claude/scripts/verdict.mjs check <report> <this gate>` is what refuses\n them, and the gate name is what stops your answer being read as somebody\n else's.\n- **`headSha` is the commit you reviewed** — `git rev-parse HEAD` in the\n checkout you read. It is what lets `node .claude/scripts/verdict.mjs coverage\n <commit>` tell \"this gate answered for the commit being merged\" from \"it\n answered two pushes ago\". A verdict naming no commit is counted as neither\n covered nor missing, so `pr-ship` holds on it — and only `pr-ship`: no hook\n runs that check, so a session that skips the gate skips this with it."
@@ -1,4 +1,6 @@
1
1
  name = "test-writer"
2
2
  description = "Writes the failing test BEFORE any implementation exists. Use at the start of every feature, bug fix, or behavior change — the Red step of TDD. Also use to reproduce a reported bug as a test."
3
+ model = "gpt-5.6-terra"
4
+ model_reasoning_effort = "high"
3
5
  sandbox_mode = "workspace-write"
4
6
  developer_instructions = "You write tests that define behavior which does not exist yet. You are the Red\nstep of TDD, and only the Red step.\n\n## Scope — hard boundaries\n\n- You create and modify **test files only**. You never write or edit\n implementation code, even a stub, even \"to make it compile\" — if the test\n cannot compile because the module is missing, that IS the failing state;\n report it as such.\n- You never mark tests as skipped or todo to avoid a failure. A failing test is\n your deliverable.\n\n## How you work\n\n1. Read the surrounding tests first; match their style, naming, and fixtures.\n2. Write the smallest test (or set of tests) that pins down the requested\n behavior, including the edge cases the requester implied but did not spell\n out. Name tests after behavior (\"refuses an empty title\"), not after methods.\n3. Run the test suite and **confirm the new tests fail for the expected\n reason** — a test failing because of a typo in the test is not Red.\n4. Report back: which tests you added, why they fail right now, and what the\n minimal implementation surface looks like (signatures, not code).\n\n## Judgment lines\n\n- Test behavior through public entry points (usecases, handlers), not private\n internals.\n- One behavior per test; shared setup in fixtures, not copy-paste.\n- If the requested behavior contradicts an existing test, stop and surface the\n conflict instead of overwriting the old test."
@@ -0,0 +1,3 @@
1
+ [agents]
2
+ default_subagent_model = "gpt-5.6-terra"
3
+ default_subagent_reasoning_effort = "medium"
@@ -1,6 +1,6 @@
1
1
  # Codex adapter: derived parity
2
2
 
3
- Status: accepted for AR-113.
3
+ Status: accepted for AR-113; subagent routing extended for RP-166.
4
4
 
5
5
  ## Decision
6
6
 
@@ -18,7 +18,22 @@ generated release. There is no downstream automatic drift check.
18
18
 
19
19
  Two hand-maintained rulebooks inevitably diverge. Derivation keeps the generated
20
20
  snapshots aligned while preserving native Codex formats. The adapter translates
21
- the fields for which Codex has native controls and does not invent policy.
21
+ the fields for which Codex has native controls. Subagent routing each role's
22
+ model and effort, for both harnesses — is declared once in the generator's
23
+ `templates/agent-os/subagent-routing.json` (rationale:
24
+ `docs/decisions/subagent-routing.md`). The Codex profiles are derived from that
25
+ table, and the projector refuses a missing or orphaned agent profile. It also
26
+ refuses duplicate source-agent names across layers, since one profile name
27
+ cannot route two definitions.
28
+
29
+ Frequent bounded work (`test-writer`, `prose-reviewer`) uses `gpt-5.6-terra`;
30
+ correctness, security, and infrastructure gates use `gpt-5.6-sol`. Every named
31
+ gate uses `high` reasoning effort. Unnamed subagents inherit repository defaults
32
+ of `gpt-5.6-terra` and `medium` from `.codex/config.toml`. `xhigh` is not a
33
+ continuous-loop default; using it for a named role requires an intentional
34
+ profile-policy change (or a separate escalation profile), because named-profile
35
+ fields take precedence over spawn and repository defaults. Concurrency remains
36
+ a machine/session decision rather than repository policy.
22
37
 
23
38
  Claude agent `tools` allowlists have no equivalent custom-agent allowlist in the
24
39
  documented Codex TOML schema. The adapter therefore uses those fields only to
@@ -28,7 +43,15 @@ not carried over. This is a known parity limit, not an implicit restriction.
28
43
  ## Risk and rollback
29
44
 
30
45
  The main risks are generated-file drift, downstream edits to only one snapshot,
31
- and unsupported Claude shapes. In the generator, the adapter fails loudly when
46
+ unsupported Claude shapes, and a pinned model being unavailable in a user's
47
+ workspace. In the generator, recovery is to update the central routing table to
48
+ an available model or use a separate supported escalation profile — the Codex
49
+ profiles are regenerated from it, while the Claude agent definitions are checked
50
+ against it and are edited to match in the same change. A generated
51
+ project has no copy of that table: there, recovery is editing the role's
52
+ definitions on both harnesses in one reviewed change, and `upgrade` then reports
53
+ those files as the project's own instead of replacing them
54
+ (`docs/decisions/subagent-routing.md`). In the generator, the adapter fails loudly when
32
55
  it cannot derive a portable hook command and its drift check catches stale
33
56
  output. Generated projects rely on review for subsequent local parity. Rollback
34
57
  is deleting the derived Codex files from the generated project and reverting the
@@ -80,8 +103,11 @@ Codex path.
80
103
 
81
104
  ## Schema and executable contracts
82
105
 
83
- The emitted agent fields are `name`, `description`, `sandbox_mode`, and
84
- `developer_instructions`, matching the documented Codex custom-agent TOML.
106
+ The emitted agent fields are `name`, `description`, `model`,
107
+ `model_reasoning_effort`, `sandbox_mode`, and `developer_instructions`, matching
108
+ the documented Codex custom-agent TOML. Named-agent fields take precedence over
109
+ the repository defaults in `.codex/config.toml`; the defaults cover only agents
110
+ without their own model or effort assignment.
85
111
  For hooks, the [official Codex hooks documentation](https://learn.chatgpt.com/docs/hooks)
86
112
  documents `tool_input.command` for both `Bash` and `apply_patch` and requires a
87
113
  string `command` when a hook replaces that input. The same document is what makes