architecture-harness 0.18.2 → 0.19.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 (36) hide show
  1. package/package.json +1 -1
  2. package/src/cli/bash-command-guard.mjs +60 -11
  3. package/src/cli/bash-command-guard.test.mjs +66 -0
  4. package/src/cli/check-input.mjs +24 -0
  5. package/src/cli/check.mjs +2 -2
  6. package/src/cli/cli.test.mjs +50 -1
  7. package/src/cli/dispatch-guard.test.mjs +6 -23
  8. package/src/cli/dispatch-reminder.mjs +3 -3
  9. package/src/cli/dispatch-reminder.test.mjs +15 -10
  10. package/src/cli/dispatch.mjs +4 -3
  11. package/src/cli/dispatch.test.mjs +25 -17
  12. package/src/cli/explore-guard.mjs +11 -87
  13. package/src/cli/explore-guard.test.mjs +34 -97
  14. package/src/cli/explore-hint.mjs +3 -3
  15. package/src/cli/explore-hint.test.mjs +14 -5
  16. package/src/cli/init.mjs +12 -0
  17. package/src/cli/merge-guard.mjs +4 -0
  18. package/src/cli/merge-guard.test.mjs +21 -2
  19. package/src/cli/plugin-agents.test.mjs +4 -4
  20. package/src/cli/powershell-command.mjs +1 -1
  21. package/src/cli/qc.mjs +9 -4
  22. package/src/cli/workflow-hooks.test.mjs +1 -0
  23. package/src/cli/worktree-gate.mjs +117 -0
  24. package/src/cli/worktree-gate.test.mjs +152 -0
  25. package/src/cli/worktree-settings.mjs +27 -0
  26. package/src/cli/worktree.mjs +60 -21
  27. package/src/cli/worktree.test.mjs +106 -7
  28. package/src/config.mjs +19 -13
  29. package/src/eslint/preset.mjs +2 -2
  30. package/src/eslint/preset.test.mjs +4 -2
  31. package/src/gates/sql-identifiers.mjs +11 -3
  32. package/src/gates/sql-identifiers.test.mjs +39 -0
  33. package/templates/.jscpd.json +1 -0
  34. package/templates/docs/decisions.md +1 -0
  35. package/templates/docs/enforcement.md +10 -0
  36. package/templates/githooks/pre-commit +8 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "architecture-harness",
3
- "version": "0.18.2",
3
+ "version": "0.19.1",
4
4
  "type": "module",
5
5
  "description": "Architecture gates, lint rules and scaffolding for the bounded-vertical-slice architecture",
6
6
  "license": "MIT",
@@ -1,18 +1,22 @@
1
1
  #!/usr/bin/env node
2
- // The PreToolUse trigger that refuses a Bash or PowerShell command which skips the git hooks, or
3
- // which runs a hook script by hand. It reads the command through the shell parsers and never runs it.
2
+ // The PreToolUse trigger that refuses a Bash or PowerShell command which skips the git hooks, runs a hook script
3
+ // by hand, or adds a worktree outside the worktree folder (QC-015). It reads the command and never runs it.
4
4
 
5
5
  import { existsSync } from "node:fs";
6
+ import os from "node:os";
6
7
  import path from "node:path";
7
8
  import { fileURLToPath } from "node:url";
8
9
  import { CONFIG_FILE } from "../config.mjs";
9
10
  import { checkoutRootOf } from "./checkout-root.mjs";
10
- import { powershellSegments } from "./powershell-command.mjs";
11
- import { commandWords, gitCall, segmentsOf } from "./shell-command.mjs";
11
+ import { locationTarget, powershellSegments } from "./powershell-command.mjs";
12
+ import { cdTarget, commandWords, gitCall, segmentsOf } from "./shell-command.mjs";
13
+ import { nativePath } from "./workflow-place.mjs";
14
+ import { keyOf } from "./worktree.mjs";
15
+ import { worktreeRuleAt } from "./worktree-settings.mjs";
12
16
 
13
17
  const HOOK_SCRIPTS = [
14
18
  "work-order-guard.mjs", "budget-guard.mjs", "bash-edit-guard.mjs", "worktree-isolation.mjs", "pre-edit-guard.sh",
15
- "report-stop.mjs", "plan-stop.mjs", "merge-guard.mjs", "issue-gate.mjs", "controller-guard.mjs",
19
+ "report-stop.mjs", "plan-stop.mjs", "merge-guard.mjs", "issue-gate.mjs", "controller-guard.mjs", "worktree-gate.mjs",
16
20
  ];
17
21
  const NO_VERIFY = "--no-verify";
18
22
  // The shortest prefix git could still expand to `--no-verify`.
@@ -28,6 +32,10 @@ const COMMIT_VALUE_FLAGS = new Set(["m", "F", "C", "c", "t"]);
28
32
 
29
33
  /** The parser for each guarded tool. */
30
34
  export const PARSERS = { Bash: segmentsOf, PowerShell: powershellSegments };
35
+ /** The directory a segment moves to, read the way each parser's shell reads it. */
36
+ const MOVES = new Map([[segmentsOf, cdTarget], [powershellSegments, locationTarget]]);
37
+ /** The options of `git worktree add` whose value is the next word. */
38
+ const WORKTREE_VALUE_OPTIONS = new Set(["-b", "-B", "--reason"]);
31
39
  /** A POSIX shell reads a command line from `-c`, alone or in a cluster of short flags: `-lc`, `-ic`, `-lic`, `-cl`. */
32
40
  const POSIX_COMMAND_FLAG = /^-[A-Za-z]*c[A-Za-z]*$/;
33
41
  const POWERSHELL_COMMAND_FLAG = /^-(c|command)$/i;
@@ -98,6 +106,29 @@ export function nestedCommand(segment) {
98
106
  return command === undefined ? null : { command, parse: shell.parse };
99
107
  }
100
108
 
109
+ /** @returns the path that `git worktree add` names after its options, or null for another worktree command. */
110
+ function worktreeAddPath(args) {
111
+ if (args[0] !== "add") return null;
112
+ for (let i = 1; i < args.length; i++) {
113
+ if (args[i] === "--") return args[i + 1] ?? null;
114
+ if (WORKTREE_VALUE_OPTIONS.has(args[i])) i++;
115
+ else if (!args[i].startsWith("-")) return args[i];
116
+ }
117
+ return null;
118
+ }
119
+
120
+ /** A path as a shell resolves it from `cwd`. PowerShell also reads a backslash as a separator on Linux and macOS. */
121
+ function resolveFrom(cwd, spelled, parse) {
122
+ const word = parse === powershellSegments ? spelled.replace(/\\/g, "/") : spelled;
123
+ return path.resolve(cwd, nativePath(word.replace(/^~(?=$|[\\/])/, os.homedir())));
124
+ }
125
+
126
+ /** True when `target` is one folder directly under `folder`, as `qc worktree add` makes it. */
127
+ function inFolder(folder, target) {
128
+ const parts = path.relative(keyOf(folder), keyOf(target)).split(path.sep);
129
+ return parts.length === 1 && parts[0] !== "" && parts[0] !== ".." && !path.isAbsolute(parts[0]);
130
+ }
131
+
101
132
  const REASONS = {
102
133
  hooks:
103
134
  "the command skips the git hooks. The pre-commit and pre-push hooks are the gates: run the command " +
@@ -107,18 +138,32 @@ const REASONS = {
107
138
  script:
108
139
  "a hand run of a hook script writes a lease or a ledger record under a made-up session id, and that lease blocks later " +
109
140
  "edits in the worktree for hours. Test a hook only through its own suite (`node --test`), in temporary folders.",
141
+ worktree:
142
+ "a worktree lives in the worktree folder of the main checkout, so git ignores it and `qc worktree remove` finds it. " +
143
+ "Run `npx qc worktree add <name> <branch>` from the repository, or give `git worktree add` a path one level under that folder.",
110
144
  };
111
145
 
112
- /** @returns the reasons the command breaks a rule, in a stable order. */
113
- export function violations(command, parse = segmentsOf) {
146
+ /**
147
+ * @param {{cwd: string, folder: string} | null} [place] the working directory and the worktree folder; null skips the worktree rule
148
+ * @returns the reasons the command breaks a rule, in a stable order.
149
+ */
150
+ export function violations(command, parse = segmentsOf, place = null) {
114
151
  const segments = parse(command);
115
152
  const found = new Set();
153
+ let cwd = place?.cwd;
116
154
  for (const segment of segments) {
155
+ const moved = place ? MOVES.get(parse)?.(segment) : null;
156
+ if (moved != null) cwd = resolveFrom(cwd, moved, parse);
117
157
  const git = gitCall(segment);
118
158
  if (git && skipsHooks(git)) found.add("hooks");
119
159
  if (git && setsHooksPath(git)) found.add("hooksPath");
160
+ const added = place && git?.sub === "worktree" ? worktreeAddPath(git.args) : null;
161
+ if (added !== null) {
162
+ const from = git.dirs.filter(Boolean).reduce((dir, next) => resolveFrom(dir, next, parse), cwd);
163
+ if (!inFolder(place.folder, resolveFrom(from, added, parse))) found.add("worktree");
164
+ }
120
165
  const nested = nestedCommand(segment);
121
- if (nested) for (const key of violations(nested.command, nested.parse)) found.add(key);
166
+ if (nested) for (const key of violations(nested.command, nested.parse, place && { ...place, cwd })) found.add(key);
122
167
  }
123
168
  if (!segments.some(runsTests) && segments.some(runsHookScript)) found.add("script");
124
169
  return Object.keys(REASONS).filter((key) => found.has(key));
@@ -129,15 +174,19 @@ export function decide(call) {
129
174
  const command = call.tool_input?.command;
130
175
  const parse = PARSERS[call.tool_name];
131
176
  if (!parse || typeof command !== "string") return null;
132
- const root = checkoutRootOf(call.cwd ?? process.cwd());
177
+ const cwd = call.cwd ?? process.cwd();
178
+ const root = checkoutRootOf(cwd);
133
179
  if (!root || !existsSync(path.join(root, CONFIG_FILE))) return null;
134
- const found = violations(command, parse);
180
+ // The config is read only for a command that can add a worktree, so every other call stays cheap.
181
+ const rule = /\bworktree\b/i.test(command) ? worktreeRuleAt(cwd) : null;
182
+ const found = violations(command, parse, rule && { cwd: path.resolve(cwd), folder: rule.folder });
135
183
  if (found.length === 0) return null;
184
+ const reasonOf = (key) => (key === "worktree" ? `${REASONS.worktree} The folder is ${rule.folder}.` : REASONS[key]);
136
185
  return {
137
186
  hookSpecificOutput: {
138
187
  hookEventName: "PreToolUse",
139
188
  permissionDecision: "deny",
140
- permissionDecisionReason: `${call.tool_name} command guard: ${found.map((key) => REASONS[key]).join(" Also, ")}`,
189
+ permissionDecisionReason: `${call.tool_name} command guard: ${found.map(reasonOf).join(" Also, ")}`,
141
190
  },
142
191
  };
143
192
  }
@@ -88,6 +88,7 @@ test("a hand run of a hook script is denied, and the reason names the lease", (t
88
88
  "node src/cli/issue-gate.mjs",
89
89
  "node src/cli/plan-stop.mjs",
90
90
  "node src/cli/controller-guard.mjs",
91
+ "node src/cli/worktree-gate.mjs",
91
92
  ]) {
92
93
  assert.match(reasonOf(decide(bash(ws.adopted, command))) ?? "", /writes a lease/, command);
93
94
  }
@@ -168,3 +169,68 @@ test("the deny names the tool it guarded", (t) => {
168
169
  const ws = workspace(t);
169
170
  assert.match(reasonOf(decide(powershell(ws.adopted, "git push --no-verify"))), /^PowerShell command guard:/);
170
171
  });
172
+
173
+ const outsideFolder = (output) => /npx qc worktree add <name> <branch>/.test(reasonOf(output) ?? "");
174
+
175
+ test("git worktree add to a path outside .worktree/ of the main checkout is refused, and names qc worktree add", (t) => {
176
+ const ws = workspace(t);
177
+ for (const command of [
178
+ "git worktree add ../x",
179
+ "git worktree add -b b ../x origin/main",
180
+ "git worktree add -B b --lock --reason why ../x",
181
+ "git -C .. worktree add x",
182
+ "cd .. && git worktree add x",
183
+ "git worktree add .worktree/a/b",
184
+ "git worktree add x",
185
+ `bash -c 'git worktree add ../x'`,
186
+ "git worktree add -- ../x",
187
+ ]) {
188
+ assert.ok(outsideFolder(decide(bash(ws.adopted, command))), command);
189
+ }
190
+ });
191
+
192
+ test("git worktree add under .worktree/, qc worktree add, and other worktree commands pass", (t) => {
193
+ const ws = workspace(t);
194
+ for (const command of [
195
+ "git worktree add .worktree/x",
196
+ "git worktree add -b feat/1-x .worktree/x origin/main",
197
+ "git worktree add --detach -f .worktree/x HEAD",
198
+ "cd .worktree && git worktree add x",
199
+ "cd .. && git worktree add adopted/.worktree/x",
200
+ `git -C .. worktree add "${path.join(ws.adopted, ".worktree", "x")}"`,
201
+ "npx qc worktree add x feat/1-x",
202
+ "git worktree list",
203
+ "git worktree remove ../x",
204
+ ]) {
205
+ assert.equal(decide(bash(ws.adopted, command)), null, command);
206
+ }
207
+ });
208
+
209
+ test("a PowerShell git worktree add is held to the same folder", (t) => {
210
+ const ws = workspace(t);
211
+ for (const command of [String.raw`git worktree add ..\x`, String.raw`git worktree add -B b ..\x origin/main`, "Set-Location ..; git worktree add x"]) {
212
+ assert.ok(outsideFolder(decide(powershell(ws.adopted, command))), command);
213
+ }
214
+ for (const command of [String.raw`git worktree add .worktree\x`, String.raw`Set-Location .worktree; git worktree add x`]) {
215
+ assert.equal(decide(powershell(ws.adopted, command)), null, command);
216
+ }
217
+ });
218
+
219
+ test("worktree.dir moves the folder, and worktree.enforce false turns the rule off", (t) => {
220
+ const ws = workspace(t);
221
+ writeFileSync(path.join(ws.adopted, "qc.config.json"), JSON.stringify({ worktree: { dir: "trees" } }));
222
+ assert.ok(outsideFolder(decide(bash(ws.adopted, "git worktree add .worktree/x"))));
223
+ assert.equal(decide(bash(ws.adopted, "git worktree add trees/x")), null);
224
+ writeFileSync(path.join(ws.adopted, "qc.config.json"), JSON.stringify({ worktree: { enforce: false } }));
225
+ assert.equal(decide(bash(ws.adopted, "git worktree add ../x")), null);
226
+ });
227
+
228
+ test("inside a linked worktree, the folder is the main checkout's", (t) => {
229
+ const ws = workspace(t);
230
+ execFileSync("git", ["-c", "user.name=qc", "-c", "user.email=qc@example.com", "commit", "-q", "--allow-empty", "-m", "init"], { cwd: ws.adopted, stdio: "pipe" });
231
+ const linked = path.join(ws.adopted, ".worktree", "wt");
232
+ execFileSync("git", ["worktree", "add", "-q", linked], { cwd: ws.adopted, stdio: "pipe" });
233
+ writeFileSync(path.join(linked, "qc.config.json"), "{}");
234
+ assert.equal(decide(bash(linked, "git worktree add ../x")), null);
235
+ assert.ok(outsideFolder(decide(bash(linked, "git worktree add x"))), "a worktree nested in a worktree is refused");
236
+ });
@@ -0,0 +1,24 @@
1
+ // The file list for `qc check`, from arguments and from `--files-from <path|->` (NUL-separated).
2
+ // A list read from a stream has no length limit, unlike the command line of `npx.cmd`.
3
+
4
+ import { readFile } from "node:fs/promises";
5
+ import process from "node:process";
6
+
7
+ /** @returns {Promise<{ files: string[], listed: boolean }>} `listed` is true when `--files-from` was given. */
8
+ export async function checkFiles(args) {
9
+ const files = [];
10
+ let source;
11
+ for (let i = 0; i < args.length; i++) {
12
+ if (args[i] === "--files-from") source = args[++i] ?? "-";
13
+ else files.push(args[i]);
14
+ }
15
+ if (source === undefined) return { files, listed: false };
16
+ const text = source === "-" ? await readStdin() : await readFile(source, "utf8");
17
+ return { files: [...files, ...text.split("\0").filter(Boolean)], listed: true };
18
+ }
19
+
20
+ async function readStdin() {
21
+ const chunks = [];
22
+ for await (const chunk of process.stdin) chunks.push(chunk);
23
+ return Buffer.concat(chunks).toString("utf8");
24
+ }
package/src/cli/check.mjs CHANGED
@@ -42,7 +42,7 @@ import { checkAdrFormat } from "../gates/adr-format.mjs";
42
42
  import { checkConfigFloor } from "../gates/config-floor.mjs";
43
43
  import { defaults } from "../config.mjs";
44
44
  import { rules as lintRules } from "../eslint/index.mjs";
45
- import { adrLog, enabled, readerEntries, requiredHooks, thresholds } from "../config.mjs";
45
+ import { adrLog, enabled, ignoresOf, readerEntries, requiredHooks, thresholds } from "../config.mjs";
46
46
  import { checkRegistryReaders } from "../gates/registry-readers.mjs";
47
47
  import { checkMigrationNumbers } from "../gates/migration-numbers.mjs";
48
48
  import { checkRegistryLiteral } from "../gates/registry-literal.mjs";
@@ -569,7 +569,7 @@ export async function runCheck(config, only = [], { lister = repoFiles } = {}) {
569
569
  .map((file) => relativeTo(config.root)(path.resolve(config.root, file)))
570
570
  .filter((rel) => !rel.startsWith("../") && !path.isAbsolute(rel));
571
571
  const pathspecs = perFile ? scopeOf(config, given) : undefined;
572
- const tree = treeOf(await lister(config.root, { ignores: config.ignores, pathspecs }));
572
+ const tree = treeOf(await lister(config.root, { ignores: ignoresOf(config), pathspecs }));
573
573
 
574
574
  const roots = config.featureRoots.map((root) => path.join(config.root, root));
575
575
  const { features, contents } = await collect(config, tree, perFile ? given : undefined);
@@ -1,9 +1,10 @@
1
1
  import test from "node:test";
2
2
  import assert from "node:assert/strict";
3
- import { execFileSync } from "node:child_process";
3
+ import { execFileSync, spawnSync } from "node:child_process";
4
4
  import { mkdtempSync, readFileSync, rmSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
5
5
  import { tmpdir } from "node:os";
6
6
  import path from "node:path";
7
+ import { fileURLToPath } from "node:url";
7
8
  import { load, requiredHooks } from "../config.mjs";
8
9
  import { hookDrift } from "./git-hooks.mjs";
9
10
  import { runInit } from "./init.mjs";
@@ -235,6 +236,29 @@ test("check with several files reports every problem from each, and judges only
235
236
  rmSync(dir, { recursive: true, force: true });
236
237
  });
237
238
 
239
+ // A Windows command line holds about 8,000 characters through `npx.cmd`, so a hook sends the list on stdin.
240
+ test("check --files-from - reads 300 long paths from stdin and reports a failure in each of two files", async () => {
241
+ const dir = repo();
242
+ await quiet(() => runInit(load(dir)));
243
+ const orders = "backend/src/features/orders";
244
+ const invoices = "backend/src/features/invoices";
245
+ write(dir, {
246
+ "qc.config.json": ENGLISH_ON,
247
+ [`${orders}/index.ts`]: "export {};\n",
248
+ [`${orders}/junk/a.ts`]: "// 注文の補助\nexport {};\n",
249
+ [`${invoices}/index.ts`]: "export {};\n",
250
+ [`${invoices}/junk/b.ts`]: "// 請求の補助\nexport {};\n",
251
+ });
252
+ const filler = Array.from({ length: 300 }, (_, i) => `docs/${"long-segment-".repeat(6)}${i}.md`);
253
+ const input = [...filler, `${orders}/junk/a.ts`, `${invoices}/junk/b.ts`].join("\0") + "\0";
254
+ const qc = fileURLToPath(new URL("./qc.mjs", import.meta.url));
255
+ const run = spawnSync(process.execPath, [qc, "check", "--files-from", "-"], { cwd: dir, input, encoding: "utf8" });
256
+ assert.equal(run.status, 1, run.stderr);
257
+ assert.match(run.stderr, /orders\/junk\/a\.ts/);
258
+ assert.match(run.stderr, /invoices\/junk\/b\.ts/);
259
+ rmSync(dir, { recursive: true, force: true });
260
+ });
261
+
238
262
  test("a clean mirror run names every root it judged", async () => {
239
263
  const dir = await mirrored(["backend/src/orders/ship.ts", "backend/tests/orders/ship.test.ts"]);
240
264
  const { lines } = await runCheck(load(dir));
@@ -454,3 +478,28 @@ test("check follows an export const alias, and fails a file that aliases the hel
454
478
  );
455
479
  rmSync(dir, { recursive: true, force: true });
456
480
  });
481
+
482
+ test("init adds the worktree folder to an existing .gitignore once, and writes it to a new one", async () => {
483
+ const dir = repo();
484
+ writeFileSync(path.join(dir, ".gitignore"), "node_modules/");
485
+ await quiet(() => runInit(load(dir)));
486
+ await quiet(() => runInit(load(dir)));
487
+ assert.equal(readFileSync(path.join(dir, ".gitignore"), "utf8"), "node_modules/\n.worktree/\n");
488
+ const spelled = repo();
489
+ writeFileSync(path.join(spelled, ".gitignore"), "/.worktree\n");
490
+ await quiet(() => runInit(load(spelled)));
491
+ assert.equal(readFileSync(path.join(spelled, ".gitignore"), "utf8"), "/.worktree\n");
492
+ const fresh = repo();
493
+ await quiet(() => runInit(load(fresh)));
494
+ assert.equal(readFileSync(path.join(fresh, ".gitignore"), "utf8"), ".worktree/\n");
495
+ for (const root of [dir, spelled, fresh]) rmSync(root, { recursive: true, force: true });
496
+ });
497
+
498
+ test("check skips the worktree folder, even where git does not ignore it", async () => {
499
+ const dir = repo();
500
+ await quiet(() => runInit(load(dir)));
501
+ write(dir, { "qc.config.json": ENGLISH_ON, ".gitignore": "", ".worktree/wt/docs/draft.md": "下書き\n", "docs/draft.md": "下書き\n" });
502
+ const { problems } = await runCheck(load(dir));
503
+ assert.deepEqual(englishPaths(problems), ["docs/draft.md"]);
504
+ rmSync(dir, { recursive: true, force: true });
505
+ });
@@ -66,7 +66,7 @@ test("a checkout with no config, or a swarm section with no dispatch key, sees n
66
66
  test("the main session's dispatch with no model is refused, and one with a model passes", (t) => {
67
67
  const ws = workspace(t);
68
68
  assert.match(reasonOf(decide(agentCall(ws.on, { prompt: "p" }), ws.tmp)) ?? "", /names no model/);
69
- assert.equal(decide(agentCall(ws.on, { prompt: "p", model: "sonnet" }), ws.tmp), null);
69
+ assert.equal(decide(agentCall(ws.on, { prompt: "p", model: "gpt-6.1-sol" }), ws.tmp), null);
70
70
  });
71
71
 
72
72
  test("a subagent's dispatch is left to its own definition", (t) => {
@@ -125,29 +125,12 @@ test("the tier guard refuses a type on the wrong family, naming the type, the mo
125
125
  assert.match(refused({ model: "opus", prompt: "p" }), /general-purpose/);
126
126
  });
127
127
 
128
- test("each allowed pair passes, including a full model id and a branch reviewer on opus", (t) => {
128
+ test("every shipped role accepts GPT 6.1 Sol without a cache note", (t) => {
129
129
  const ws = workspace(t);
130
- assert.equal(decide(agentCall(ws.on, { subagent_type: "architecture:sdd-planner", model: "opus", prompt: "p" }), ws.tmp), null);
131
- assert.equal(
132
- decide(agentCall(ws.on, { subagent_type: "architecture:sdd-branch-reviewer", model: "opus", prompt: "p" }), ws.tmp),
133
- null,
134
- );
135
- assert.equal(
136
- decide(agentCall(ws.on, { subagent_type: "architecture:sdd-reviewer", model: "sonnet", prompt: "p" }), ws.tmp),
137
- null,
138
- );
139
- assert.equal(decide(agentCall(ws.on, { model: "haiku", prompt: "p" }), ws.tmp), null);
140
- assert.equal(
141
- decide(agentCall(ws.on, { subagent_type: "architecture:sdd-implementer", model: "sonnet", prompt: "p" }), ws.tmp),
142
- null,
143
- );
144
- decide(subagentEvent(ws.on, "architecture:sdd-implementer"), ws.tmp);
145
- const pinned = decide(
146
- agentCall(ws.on, { subagent_type: "architecture:sdd-implementer", model: "claude-sonnet-5", prompt: "p" }),
147
- ws.tmp,
148
- );
149
- assert.equal(pinned.hookSpecificOutput.permissionDecision, undefined);
150
- assert.match(pinned.hookSpecificOutput.additionalContext, /share no prompt cache/);
130
+ for (const subagent_type of ["architecture:sdd-planner", "architecture:sdd-branch-reviewer", "architecture:sdd-reviewer", "architecture:sdd-implementer"]) {
131
+ assert.equal(decide(agentCall(ws.on, { subagent_type, model: "gpt-6.1-sol", prompt: "p" }), ws.tmp), null, subagent_type);
132
+ }
133
+ assert.equal(decide(agentCall(ws.on, { model: "gpt-6.1-sol", prompt: "p" }), ws.tmp), null);
151
134
  });
152
135
 
153
136
  test("a repository's models override replaces one type's families and leaves the rest at default", (t) => {
@@ -9,7 +9,7 @@ export const REMINDER =
9
9
  "Subagent workflow (swarm.dispatch in qc.config.json): run a plan with superpowers:subagent-driven-development. " +
10
10
  "Dispatch architecture:sdd-planner to write a plan, architecture:sdd-implementer for one task, and " +
11
11
  "architecture:sdd-reviewer to review it; before merge, dispatch architecture:sdd-branch-reviewer to review the " +
12
- "whole branch. The planner and the branch reviewer run on opus, the implementer and the task reviewer on sonnet. " +
12
+ "whole branch. All four roles default to gpt-6.1-sol with high reasoning effort. " +
13
13
  "Run one implementer at a time: a hook refuses a second while one runs. Name a model on any other dispatch, and " +
14
14
  "pass each brief as a file path. Name the worktree on a prompt line `Worktree: <path>`. A reviewer starts with " +
15
15
  "`VERDICT: <APPROVED|CHANGES_REQUIRED> <sha>`, and a merge passes `--match-head-commit <sha>`.";
@@ -37,14 +37,14 @@ function exploreToolsAt(cwd) {
37
37
  /** One added line naming `swarm.explore`'s tools, or "" when there are none. */
38
38
  function exploreLine(cwd) {
39
39
  const tools = exploreToolsAt(cwd);
40
- return tools ? ` The repository's own explore tools: ${tools.map((tool) => tool.name).join(", ")}.` : "";
40
+ return tools ? ` Optional explore tools: ${tools.map((tool) => tool.name).join(", ")}. Read, Grep, and shell searches remain available.` : "";
41
41
  }
42
42
 
43
43
  /** A subagent may carry no MCP tool, so its note gives each tool's command, not only its name. */
44
44
  function decideSubagentStart(cwd) {
45
45
  const tools = exploreToolsAt(cwd);
46
46
  if (!tools) return null;
47
- const lines = ["The repository's own explore tools, and how to run each:", ...exploreToolLines(tools)];
47
+ const lines = ["Optional explore tools, and how to run each. Read, Grep, and shell searches remain available:", ...exploreToolLines(tools)];
48
48
  return context("SubagentStart", lines.join("\n"));
49
49
  }
50
50
 
@@ -49,6 +49,8 @@ test("the note names the workflow, the four types, the model tiers, and the one-
49
49
  "architecture:sdd-reviewer",
50
50
  "architecture:sdd-branch-reviewer",
51
51
  "one implementer at a time",
52
+ "gpt-6.1-sol",
53
+ "high reasoning effort",
52
54
  "Worktree: <path>",
53
55
  "VERDICT: <APPROVED|CHANGES_REQUIRED> <sha>",
54
56
  "--match-head-commit <sha>",
@@ -60,11 +62,12 @@ test("the note names the workflow, the four types, the model tiers, and the one-
60
62
 
61
63
  test("with swarm.explore also on, the note names its tools", (t) => {
62
64
  const [on] = checkouts(t, [
63
- { swarm: { dispatch: {}, explore: { tools: [{ name: "slm-rerank", use: "u", how: "h" }, { name: "GitNexus", use: "u", how: "h" }] } } },
65
+ { swarm: { dispatch: {}, explore: { tools: [{ name: "CocoIndex", use: "u", how: "h" }, { name: "GitNexus", use: "u", how: "h" }] } } },
64
66
  ]);
65
67
  const text = decide(start(on, "startup")).hookSpecificOutput.additionalContext;
66
68
  assert.ok(text.startsWith(REMINDER));
67
- assert.match(text, /slm-rerank, GitNexus/);
69
+ assert.match(text, /CocoIndex, GitNexus/);
70
+ assert.match(text, /optional/i);
68
71
  });
69
72
 
70
73
  test("with swarm.explore off, or naming no tools, the note is exactly REMINDER", (t) => {
@@ -77,18 +80,20 @@ test("with swarm.explore off, or naming no tools, the note is exactly REMINDER",
77
80
  });
78
81
 
79
82
  test("with swarm.explore on and swarm.dispatch off, the SessionStart note still names the tools", (t) => {
80
- const [on] = checkouts(t, [{ swarm: { explore: { tools: [{ name: "slm-rerank", use: "u", how: "h" }] } } }]);
83
+ const [on] = checkouts(t, [{ swarm: { explore: { tools: [{ name: "CocoIndex", use: "u", how: "h" }] } } }]);
81
84
  const output = decide(start(on, "startup"));
82
85
  assert.equal(output.hookSpecificOutput.hookEventName, "SessionStart");
83
- assert.match(output.hookSpecificOutput.additionalContext, /slm-rerank/);
86
+ assert.match(output.hookSpecificOutput.additionalContext, /CocoIndex/);
87
+ assert.match(output.hookSpecificOutput.additionalContext, /optional/i);
84
88
  assert.ok(!output.hookSpecificOutput.additionalContext.startsWith(" "));
85
89
  });
86
90
 
87
91
  test("SubagentStart names the tools when swarm.explore is on, independent of swarm.dispatch", (t) => {
88
- const [on] = checkouts(t, [{ swarm: { explore: { tools: [{ name: "slm-rerank", use: "u", how: "h" }] } } }]);
92
+ const [on] = checkouts(t, [{ swarm: { explore: { tools: [{ name: "CocoIndex", use: "u", how: "h" }] } } }]);
89
93
  const output = decide(subagentStart(on));
90
94
  assert.equal(output.hookSpecificOutput.hookEventName, "SubagentStart");
91
- assert.match(output.hookSpecificOutput.additionalContext, /slm-rerank/);
95
+ assert.match(output.hookSpecificOutput.additionalContext, /CocoIndex/);
96
+ assert.match(output.hookSpecificOutput.additionalContext, /optional/i);
92
97
  });
93
98
 
94
99
  test("SubagentStart with no swarm.explore section, or none naming tools, is a no-op", (t) => {
@@ -150,7 +155,7 @@ test("SubagentStart gives each tool's use and command, in config order, since a
150
155
  swarm: {
151
156
  explore: {
152
157
  tools: [
153
- { name: "slm-rerank", use: "find the files for a concept", how: 'slm-rerank -q "<question>" --stub -k 5' },
158
+ { name: "CocoIndex", use: "find the files for a concept", how: 'ccc search "<question>"' },
154
159
  { name: "GitNexus", use: "callers and callees", how: "gitnexus context <symbol> -r repo" },
155
160
  ],
156
161
  },
@@ -160,15 +165,15 @@ test("SubagentStart gives each tool's use and command, in config order, since a
160
165
  assert.equal(
161
166
  decide(subagentStart(on)).hookSpecificOutput.additionalContext,
162
167
  [
163
- "The repository's own explore tools, and how to run each:",
164
- '- slm-rerank: find the files for a concept (slm-rerank -q "<question>" --stub -k 5)',
168
+ "Optional explore tools, and how to run each. Read, Grep, and shell searches remain available:",
169
+ '- CocoIndex: find the files for a concept (ccc search "<question>")',
165
170
  "- GitNexus: callers and callees (gitnexus context <symbol> -r repo)",
166
171
  ].join("\n"),
167
172
  );
168
173
  });
169
174
 
170
175
  test("a swarm.explore section that does not parse leaves SubagentStart silent and the session note as REMINDER", (t) => {
171
- const [bad] = checkouts(t, [{ swarm: { dispatch: {}, explore: { tools: "slm-rerank" } } }]);
176
+ const [bad] = checkouts(t, [{ swarm: { dispatch: {}, explore: { tools: "CocoIndex" } } }]);
172
177
  assert.equal(decide(subagentStart(bad)), null);
173
178
  assert.equal(decide(start(bad, "startup")).hookSpecificOutput.additionalContext, REMINDER);
174
179
  });
@@ -27,10 +27,11 @@ function checkModels(models) {
27
27
  }
28
28
  }
29
29
 
30
- /** The first family name a model string contains, lower-cased. Null when it names none the guard knows. */
30
+ /** An exact GPT model id or the first Claude family a model string contains, lower-cased. */
31
31
  export function familyOf(model) {
32
32
  const lower = model.toLowerCase();
33
- return MODEL_FAMILIES.find((family) => lower.includes(family)) ?? null;
33
+ if (lower.startsWith("gpt-")) return MODEL_FAMILIES.includes(lower) ? lower : null;
34
+ return MODEL_FAMILIES.find((family) => !family.startsWith("gpt-") && lower.includes(family)) ?? null;
34
35
  }
35
36
 
36
37
  /** @returns the dispatch settings, or null when the section is absent; throws naming the key a repository got wrong. */
@@ -126,7 +127,7 @@ function modelRefusal(type, settings) {
126
127
  }
127
128
  return (
128
129
  `Dispatch guard: the dispatch names no model, so the ${type} agent runs on the session's model. ` +
129
- `Pass \`model\` with the cheapest tier that fits the task, or dispatch one of: ${allowed}. ` +
130
+ `Pass \`model\` with the configured model, or dispatch one of: ${allowed}. ` +
130
131
  `To allow another type with no model, add it to ${KEY}.allowedTypes in qc.config.json.`
131
132
  );
132
133
  }
@@ -54,6 +54,16 @@ test("familyOf finds the first known family a model string contains, lower-cased
54
54
  assert.equal(familyOf("opus[1m]"), "opus");
55
55
  assert.equal(familyOf("OPUS"), "opus");
56
56
  assert.equal(familyOf("gpt-4"), null);
57
+ assert.equal(familyOf("GPT-6.1-SOL"), "gpt-6.1-sol");
58
+ assert.equal(familyOf("gpt-6.1-sol-other"), null);
59
+ });
60
+
61
+ test("every SDD role and the wildcard accept GPT 6.1 Sol by default and refuse another GPT model", () => {
62
+ const settings = dispatchSettings({ dispatch: {} });
63
+ for (const type of [...settings.allowedTypes, "general-purpose", "Explore"]) {
64
+ assert.equal(dispatchRefusal({ subagent_type: type, model: "gpt-6.1-sol" }, settings), null, type);
65
+ assert.match(dispatchRefusal({ subagent_type: type, model: "gpt-6-sol" }, settings) ?? "", /gpt-6\.1-sol/, type);
66
+ }
57
67
  });
58
68
 
59
69
  const on = dispatchSettings({ dispatch: { maxPromptChars: 20 } });
@@ -68,8 +78,8 @@ test("a dispatch with neither a model nor an allowed type is refused, and the re
68
78
  });
69
79
 
70
80
  test("a named model or an allowed type passes", () => {
71
- assert.equal(dispatchRefusal({ subagent_type: "general-purpose", model: "sonnet", prompt: "p" }, on), null);
72
- assert.equal(dispatchRefusal({ model: "haiku" }, on), null);
81
+ assert.equal(dispatchRefusal({ subagent_type: "general-purpose", model: "gpt-6.1-sol", prompt: "p" }, on), null);
82
+ assert.equal(dispatchRefusal({ model: "gpt-6.1-sol" }, on), null);
73
83
  assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-reviewer" }, on), null);
74
84
  });
75
85
 
@@ -80,11 +90,11 @@ test("a fork passes only as an allowed type, since it ignores the model", () =>
80
90
  });
81
91
 
82
92
  test("a prompt over the limit is refused, and a prompt at the limit passes", () => {
83
- const reason = dispatchRefusal({ model: "haiku", prompt: "x".repeat(21) }, on) ?? "";
93
+ const reason = dispatchRefusal({ model: "gpt-6.1-sol", prompt: "x".repeat(21) }, on) ?? "";
84
94
  assert.match(reason, /21 characters/);
85
95
  assert.match(reason, /swarm\.dispatch\.maxPromptChars \(20\)/);
86
96
  assert.match(reason, /Write the brief to a file/);
87
- assert.equal(dispatchRefusal({ model: "haiku", prompt: "x".repeat(20) }, on), null);
97
+ assert.equal(dispatchRefusal({ model: "gpt-6.1-sol", prompt: "x".repeat(20) }, on), null);
88
98
  });
89
99
 
90
100
  test("the model rule comes before the length rule", () => {
@@ -95,30 +105,28 @@ test("a planner on sonnet is refused, and an implementer on opus is refused", ()
95
105
  const planner = dispatchRefusal({ subagent_type: "architecture:sdd-planner", model: "sonnet" }, on) ?? "";
96
106
  assert.match(planner, /architecture:sdd-planner/);
97
107
  assert.match(planner, /"sonnet"/);
98
- assert.match(planner, /opus/);
108
+ assert.match(planner, /gpt-6\.1-sol/);
99
109
  const implementer = dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "opus" }, on) ?? "";
100
110
  assert.match(implementer, /architecture:sdd-implementer/);
101
111
  assert.match(implementer, /"opus"/);
102
- assert.match(implementer, /sonnet/);
112
+ assert.match(implementer, /gpt-6\.1-sol/);
103
113
  });
104
114
 
105
115
  test("a general-purpose dispatch on opus is refused, naming the wildcard's families", () => {
106
116
  const reason = dispatchRefusal({ model: "opus" }, on) ?? "";
107
117
  assert.match(reason, /general-purpose/);
108
- assert.match(reason, /sonnet, haiku/);
118
+ assert.match(reason, /gpt-6\.1-sol/);
109
119
  });
110
120
 
111
121
  test("a model string with no known family is refused", () => {
112
122
  assert.match(dispatchRefusal({ model: "gpt-4" }, on) ?? "", /general-purpose/);
113
123
  });
114
124
 
115
- test("each allowed pair passes, including a full model id that resolves to its family", () => {
116
- assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-planner", model: "opus" }, on), null);
117
- assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-branch-reviewer", model: "opus" }, on), null);
118
- assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "sonnet" }, on), null);
119
- assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-reviewer", model: "sonnet" }, on), null);
120
- assert.equal(dispatchRefusal({ model: "haiku" }, on), null);
121
- assert.equal(dispatchRefusal({ subagent_type: "architecture:sdd-implementer", model: "claude-sonnet-5" }, on), null);
125
+ test("each shipped role accepts its configured model, bare and scoped", () => {
126
+ for (const type of on.allowedTypes) {
127
+ assert.equal(dispatchRefusal({ subagent_type: type, model: "gpt-6.1-sol" }, on), null, type);
128
+ }
129
+ assert.equal(dispatchRefusal({ model: "gpt-6.1-sol" }, on), null);
122
130
  });
123
131
 
124
132
  test("a fork keeps its current rule and never reaches the tier check", () => {
@@ -196,11 +204,11 @@ test("a refusal over a limit above 1 names the limit and each holder, and one at
196
204
  test("exploreToolLines gives one `- name: use (how)` line per tool, in config order", () => {
197
205
  assert.deepEqual(
198
206
  exploreToolLines([
199
- { name: "slm-rerank", use: "find the files for a concept", how: 'slm-rerank -q "<question>" --stub -k 5' },
207
+ { name: "CocoIndex", use: "find the files for a concept", how: 'ccc search "<question>"' },
200
208
  { name: "GitNexus", use: "callers and callees", how: "gitnexus context <symbol> -r repo" },
201
209
  ]),
202
210
  [
203
- '- slm-rerank: find the files for a concept (slm-rerank -q "<question>" --stub -k 5)',
211
+ '- CocoIndex: find the files for a concept (ccc search "<question>")',
204
212
  "- GitNexus: callers and callees (gitnexus context <symbol> -r repo)",
205
213
  ],
206
214
  );
@@ -211,7 +219,7 @@ test("a shipped type that names a full model id gets a cache note, never a refus
211
219
  const settings = { ...dispatchDefaults };
212
220
  const note = dispatchNote({ subagent_type: "architecture:sdd-implementer", model: "claude-sonnet-5", prompt: "x" }, settings);
213
221
  assert.match(note, /share no prompt cache/);
214
- assert.equal(dispatchNote({ subagent_type: "architecture:sdd-implementer", model: "sonnet", prompt: "x" }, settings), null);
222
+ assert.equal(dispatchNote({ subagent_type: "architecture:sdd-implementer", model: "gpt-6.1-sol", prompt: "x" }, settings), null);
215
223
  assert.equal(dispatchNote({ subagent_type: "architecture:sdd-implementer", prompt: "x" }, settings), null);
216
224
  assert.equal(dispatchNote({ subagent_type: "general-purpose", model: "claude-sonnet-5", prompt: "x" }, settings), null);
217
225
  });