architecture-harness 0.20.4 → 0.21.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "architecture-harness",
3
- "version": "0.20.4",
3
+ "version": "0.21.0",
4
4
  "type": "module",
5
5
  "description": "Architecture gates, lint rules and scaffolding for the bounded-vertical-slice architecture",
6
6
  "license": "MIT",
@@ -0,0 +1,109 @@
1
+ // `qc codex-implement`: run one brief through `codex exec` as an implementer, and start a fresh session
2
+ // after each stop until the progress file says it is done. It never calls Claude; exit 2 hands the brief back.
3
+
4
+ import { spawn } from "node:child_process";
5
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, statSync } from "node:fs";
6
+ import path from "node:path";
7
+
8
+ export const DONE_MARKER = "ALL TASKS DONE";
9
+ const DEFAULT_MAX_RUNS = 12;
10
+ const TAIL_CHARS = 4000;
11
+ const LIMIT = /usage limit|spend cap|rate limit|hit your limit/i;
12
+
13
+ const USAGE =
14
+ "usage: qc codex-implement --brief <file> --worktree <path> --progress <file> [--log <file>] [--max-runs <n>]\n" +
15
+ "exit 0 every task done, 1 bad input or no codex, 2 a Codex usage or spend limit, 3 out of runs";
16
+
17
+ const FLAGS = { "--brief": "brief", "--worktree": "worktree", "--progress": "progress", "--log": "log", "--max-runs": "maxRuns" };
18
+
19
+ /** @returns the settings with resolved paths; throws an Error naming the bad or missing flag. */
20
+ export function parseArgs(argv) {
21
+ const found = {};
22
+ for (let index = 0; index < argv.length; index += 2) {
23
+ const key = FLAGS[argv[index]];
24
+ if (!key) throw new Error(`unknown argument ${argv[index]}`);
25
+ if (argv[index + 1] === undefined) throw new Error(`${argv[index]} needs a value`);
26
+ found[key] = argv[index + 1];
27
+ }
28
+ for (const flag of ["--brief", "--worktree", "--progress"]) if (!found[FLAGS[flag]]) throw new Error(`${flag} is required`);
29
+ const maxRuns = found.maxRuns === undefined ? DEFAULT_MAX_RUNS : Number(found.maxRuns);
30
+ if (!Number.isInteger(maxRuns) || maxRuns < 1) throw new Error(`--max-runs must be a positive integer, got ${found.maxRuns}`);
31
+ const progress = path.resolve(found.progress);
32
+ return {
33
+ brief: path.resolve(found.brief),
34
+ worktree: path.resolve(found.worktree),
35
+ progress,
36
+ log: path.resolve(found.log ?? `${progress}.log`),
37
+ maxRuns,
38
+ };
39
+ }
40
+
41
+ const isDone = (progress) => existsSync(progress) && readFileSync(progress, "utf8").includes(DONE_MARKER);
42
+
43
+ function continuationNote(progress) {
44
+ return (
45
+ `\n\n---\nThis may be a fresh session that continues earlier work. Read \`git log --oneline\` and \`git status --short\` ` +
46
+ `in the worktree, and the progress file ${progress}. Continue from the first unfinished task.`
47
+ );
48
+ }
49
+
50
+ /** Runs one codex process with no shell and a closed stdin, appends its output to the log, and resolves with the exit status and the output tail. */
51
+ function spawnRun({ command, args, env, log }, codexCommand) {
52
+ const [bin, ...prefix] = codexCommand;
53
+ mkdirSync(path.dirname(log), { recursive: true });
54
+ const start = existsSync(log) ? statSync(log).size : 0;
55
+ const fd = openSync(log, "a");
56
+ return new Promise((resolve, reject) => {
57
+ const child = spawn(bin, [...prefix, ...args], { env, stdio: ["ignore", fd, fd], windowsHide: true });
58
+ child.on("error", (error) => {
59
+ closeSync(fd);
60
+ reject(error);
61
+ });
62
+ child.on("close", (status) => {
63
+ closeSync(fd);
64
+ const text = readFileSync(log, "utf8");
65
+ resolve({ status, tail: Buffer.from(text).subarray(Math.max(start, Buffer.byteLength(text) - TAIL_CHARS)).toString("utf8") });
66
+ });
67
+ });
68
+ }
69
+
70
+ /**
71
+ * @param run `({ command, args, env, log }) => Promise<{ status, tail }>`; the default spawns `codexCommand`.
72
+ * @returns the exit code: 0 done, 1 bad input or no codex, 2 a limit, 3 out of runs.
73
+ */
74
+ export async function runCodexImplement(argv, { run, codexCommand = ["codex"], env = process.env, say = (line) => console.error(line) } = {}) {
75
+ let settings;
76
+ try {
77
+ settings = parseArgs(argv);
78
+ } catch (error) {
79
+ say(`qc codex-implement: ${error.message}\n${USAGE}`);
80
+ return 1;
81
+ }
82
+ const execute = run ?? ((call) => spawnRun(call, codexCommand));
83
+ const prompt = readFileSync(settings.brief, "utf8") + continuationNote(settings.progress);
84
+ const args = ["exec", "-s", "danger-full-access", "-C", settings.worktree, prompt];
85
+ for (let count = 1; count <= settings.maxRuns; count += 1) {
86
+ if (isDone(settings.progress)) return finish(say, `done after ${count - 1} run(s)`, 0);
87
+ let result;
88
+ try {
89
+ result = await execute({ command: codexCommand[0], args, env: { ...env, QC_ROLE: "implementer" }, log: settings.log });
90
+ } catch (error) {
91
+ return finish(say, `codex did not run: ${error.message}`, 1);
92
+ }
93
+ say(`qc codex-implement: run ${count} ended with status ${result.status}`);
94
+ if (isDone(settings.progress)) return finish(say, `done after ${count} run(s)`, 0);
95
+ if (reportsLimit(result.tail ?? "", prompt)) return finish(say, "Codex reports a usage or spend limit: dispatch the same brief to a Claude sdd-implementer", 2);
96
+ }
97
+ return finish(say, `out of runs: ${settings.maxRuns} runs and the progress file is not done`, 3);
98
+ }
99
+
100
+ /** A limit line counts only when Codex wrote it, not when the log echoes a line of the prompt. */
101
+ function reportsLimit(tail, prompt) {
102
+ const echoed = new Set(prompt.split(/\r?\n/).map((line) => line.trim()).filter(Boolean));
103
+ return tail.split(/\r?\n/).some((line) => LIMIT.test(line) && !echoed.has(line.trim()));
104
+ }
105
+
106
+ function finish(say, message, code) {
107
+ say(`qc codex-implement: ${message}`);
108
+ return code;
109
+ }
@@ -0,0 +1,175 @@
1
+ import { strict as assert } from "node:assert";
2
+ import { spawnSync } from "node:child_process";
3
+ import { appendFileSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { test } from "node:test";
7
+ import { fileURLToPath } from "node:url";
8
+ import { DONE_MARKER, parseArgs, runCodexImplement } from "./codex-implement.mjs";
9
+
10
+ const QC = fileURLToPath(new URL("./qc.mjs", import.meta.url));
11
+
12
+ function setup(t, { progress = "" } = {}) {
13
+ const dir = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-codex-implement-")));
14
+ t.after(() => rmSync(dir, { recursive: true, force: true }));
15
+ const files = { dir, brief: path.join(dir, "brief.md"), progress: path.join(dir, "progress.md"), worktree: path.join(dir, "wt") };
16
+ writeFileSync(files.brief, "# Brief\n\nDo task one.\n");
17
+ writeFileSync(files.progress, progress);
18
+ const argv = ["--brief", files.brief, "--worktree", files.worktree, "--progress", files.progress];
19
+ return { ...files, argv };
20
+ }
21
+
22
+ const quiet = () => {};
23
+
24
+ test("a progress file that already says ALL TASKS DONE exits 0 with no run", async (t) => {
25
+ const { argv } = setup(t, { progress: `task 1 committed\n${DONE_MARKER}\n` });
26
+ let calls = 0;
27
+ const code = await runCodexImplement(argv, { run: async () => (calls += 1), say: quiet });
28
+ assert.equal(code, 0);
29
+ assert.equal(calls, 0);
30
+ });
31
+
32
+ test("a run passes exec, the sandbox, the worktree and one prompt, with QC_ROLE=implementer", async (t) => {
33
+ const { argv, brief, progress, worktree } = setup(t);
34
+ const seen = [];
35
+ const run = async (call) => {
36
+ seen.push(call);
37
+ appendFileSync(progress, `${DONE_MARKER}\n`);
38
+ return { status: 0, tail: "ok" };
39
+ };
40
+ assert.equal(await runCodexImplement(argv, { run, say: quiet }), 0);
41
+ assert.equal(seen.length, 1);
42
+ const [call] = seen;
43
+ assert.equal(call.command, "codex");
44
+ assert.deepEqual(call.args.slice(0, 5), ["exec", "-s", "danger-full-access", "-C", worktree]);
45
+ assert.equal(call.args.length, 6);
46
+ assert.equal(call.env.QC_ROLE, "implementer");
47
+ assert.ok(call.args[5].startsWith(readFileSync(brief, "utf8")));
48
+ assert.match(call.args[5], /git log --oneline/);
49
+ assert.match(call.args[5], /git status --short/);
50
+ assert.match(call.args[5], /first unfinished task/);
51
+ assert.ok(call.args[5].includes(progress));
52
+ assert.equal(call.log, `${progress}.log`);
53
+ });
54
+
55
+ test("a fresh session starts after a stop with the progress file not done", async (t) => {
56
+ const { argv, progress } = setup(t);
57
+ let calls = 0;
58
+ const run = async () => {
59
+ calls += 1;
60
+ if (calls === 2) appendFileSync(progress, `${DONE_MARKER}\n`);
61
+ return { status: 0, tail: "context large, notes written" };
62
+ };
63
+ assert.equal(await runCodexImplement(argv, { run, say: quiet }), 0);
64
+ assert.equal(calls, 2);
65
+ });
66
+
67
+ test("a usage or spend limit in the output tail exits 2 and stops restarting", async (t) => {
68
+ const { argv } = setup(t);
69
+ for (const message of ["You've hit your usage limit.", "Spend cap reached", "429 Rate Limit exceeded", "you HIT YOUR LIMIT"]) {
70
+ let calls = 0;
71
+ const run = async () => {
72
+ calls += 1;
73
+ return { status: 1, tail: `stack\n${message}\n` };
74
+ };
75
+ assert.equal(await runCodexImplement(argv, { run, say: quiet }), 2, message);
76
+ assert.equal(calls, 1, message);
77
+ }
78
+ });
79
+
80
+ test("--max-runs bounds the restarts and exits 3, with a default of 12", async (t) => {
81
+ const { argv } = setup(t);
82
+ let calls = 0;
83
+ const run = async () => ((calls += 1), { status: 0, tail: "stopped" });
84
+ assert.equal(await runCodexImplement([...argv, "--max-runs", "3"], { run, say: quiet }), 3);
85
+ assert.equal(calls, 3);
86
+ calls = 0;
87
+ assert.equal(await runCodexImplement(argv, { run, say: quiet }), 3);
88
+ assert.equal(calls, 12);
89
+ });
90
+
91
+ test("a run that finishes the brief on its last allowed run exits 0, not 3", async (t) => {
92
+ const { argv, progress } = setup(t);
93
+ const run = async () => (appendFileSync(progress, DONE_MARKER), { status: 0, tail: "" });
94
+ assert.equal(await runCodexImplement([...argv, "--max-runs", "1"], { run, say: quiet }), 0);
95
+ });
96
+
97
+ test("a codex binary that does not start exits 1 with the reason", async (t) => {
98
+ const { argv } = setup(t);
99
+ const said = [];
100
+ const run = async () => {
101
+ throw new Error("spawn codex ENOENT");
102
+ };
103
+ assert.equal(await runCodexImplement(argv, { run, say: (line) => said.push(line) }), 1);
104
+ assert.match(said.join("\n"), /ENOENT/);
105
+ });
106
+
107
+ test("a missing or malformed argument exits 1 and names it", async (t) => {
108
+ const { argv } = setup(t);
109
+ const said = [];
110
+ const run = async () => assert.fail("no run");
111
+ for (const bad of [[], argv.slice(2), [...argv, "--max-runs", "0"], [...argv, "--max-runs", "x"], [...argv, "--nope", "1"]]) {
112
+ assert.equal(await runCodexImplement(bad, { run, say: (line) => said.push(line) }), 1, bad.join(" "));
113
+ }
114
+ assert.match(said.join("\n"), /--brief/);
115
+ assert.match(said.join("\n"), /--max-runs/);
116
+ assert.match(said.join("\n"), /--nope/);
117
+ });
118
+
119
+ test("parseArgs reads the flags, resolves the paths, and puts the log beside the progress file", () => {
120
+ const parsed = parseArgs(["--brief", "b.md", "--worktree", "w", "--progress", "p/progress.md", "--log", "x.log", "--max-runs", "5"]);
121
+ assert.equal(parsed.maxRuns, 5);
122
+ assert.equal(parsed.log, path.resolve("x.log"));
123
+ assert.equal(parsed.brief, path.resolve("b.md"));
124
+ assert.equal(parseArgs(["--brief", "b", "--worktree", "w", "--progress", "p/q.md"]).log, `${path.resolve("p/q.md")}.log`);
125
+ });
126
+
127
+ test("the default runner spawns without a shell, closes stdin, and appends output to the log", async (t) => {
128
+ const { dir, argv, progress, brief } = setup(t);
129
+ const fake = path.join(dir, "fake-codex.mjs");
130
+ writeFileSync(
131
+ fake,
132
+ [
133
+ 'import { appendFileSync } from "node:fs";',
134
+ "let input = '';",
135
+ "for await (const chunk of process.stdin) input += chunk;",
136
+ "console.log(JSON.stringify({ args: process.argv.slice(2), role: process.env.QC_ROLE, input }));",
137
+ `if (process.env.FAKE_MODE === "limit") console.error("You have hit your usage limit");`,
138
+ `else appendFileSync(${JSON.stringify(progress)}, ${JSON.stringify(`${DONE_MARKER}
139
+ `)});`,
140
+ ].join("\n"),
141
+ );
142
+ const log = path.join(dir, "run.log");
143
+ const done = await runCodexImplement([...argv, "--log", log], { codexCommand: [process.execPath, fake], say: quiet });
144
+ assert.equal(done, 0);
145
+ const line = JSON.parse(readFileSync(log, "utf8").trim().split("\n")[0]);
146
+ assert.equal(line.role, "implementer");
147
+ assert.equal(line.input, "");
148
+ assert.deepEqual(line.args.slice(0, 3), ["exec", "-s", "danger-full-access"]);
149
+ assert.ok(line.args[5].startsWith(readFileSync(brief, "utf8")));
150
+
151
+ writeFileSync(progress, "");
152
+ process.env.FAKE_MODE = "limit";
153
+ t.after(() => delete process.env.FAKE_MODE);
154
+ assert.equal(await runCodexImplement([...argv, "--log", log], { codexCommand: [process.execPath, fake], say: quiet }), 2);
155
+ assert.ok(readFileSync(log, "utf8").split("\n").filter((entry) => entry.startsWith("{")).length >= 2, "the log is appended, not replaced");
156
+ });
157
+
158
+ test("qc codex-implement is wired, and prints usage errors with exit 1", () => {
159
+ const result = spawnSync(process.execPath, [QC, "codex-implement"], { encoding: "utf8" });
160
+ assert.equal(result.status, 1);
161
+ assert.match(result.stderr, /--brief/);
162
+ assert.match(spawnSync(process.execPath, [QC], { encoding: "utf8" }).stdout, /qc codex-implement/);
163
+ });
164
+
165
+ test("a limit word that only echoes the brief is not a limit", async (t) => {
166
+ const { argv, brief } = setup(t);
167
+ writeFileSync(brief, "# Brief\n\nIf you hit a usage limit, stop and write notes.\n");
168
+ let calls = 0;
169
+ const run = async () => {
170
+ calls += 1;
171
+ return { status: 1, tail: "user\nIf you hit a usage limit, stop and write notes.\nexec failed\n" };
172
+ };
173
+ assert.equal(await runCodexImplement([...argv, "--max-runs", "2"], { run, say: quiet }), 3);
174
+ assert.equal(calls, 2);
175
+ });
@@ -19,6 +19,21 @@ export const REMINDER =
19
19
  "Review a head only once CI on it is green, with the base merged in: fix a CI failure first, and merge `origin/<base>` at Step 0 of a fix round. " +
20
20
  "A PR gets one branch review. After it, review each fix round once, by its increment: add `Reviewed: <sha>`, the last head a branch review named.";
21
21
 
22
+ /** One added sentence: a Codex implementer through the runner, and the Claude fallback on a Codex limit. */
23
+ export const CODEX_LINE =
24
+ " An implementer may run on Codex through `qc codex-implement --brief <file> --worktree <path> --progress <file>`; " +
25
+ "on exit 2 (a Codex limit), dispatch the same brief to an architecture:sdd-implementer (sonnet).";
26
+
27
+ /** The note a Codex implementer gets in place of the controller note, with `QC_ROLE=implementer`. */
28
+ export const WORKER_NOTE =
29
+ "Implementer worker mode (QC_ROLE=implementer): you are an implementer under a controller. Work inline. " +
30
+ "Never use superpowers:subagent-driven-development, helper agents, task reviews, or fix-review rounds. " +
31
+ "For each task in your brief: write the failing test, run only that test file, make it pass, " +
32
+ "run typecheck and lint on what you touched, and commit that task at once. " +
33
+ "Do not run the full local gate or e2e; CI runs them. " +
34
+ "When every task in the brief is committed, append `ALL TASKS DONE` to the progress file the brief names. " +
35
+ "If your context gets large, write notes to the progress file and end the turn: a fresh session continues.";
36
+
22
37
  const ROLES = ["sdd-planner", "sdd-implementer", "sdd-reviewer", "sdd-branch-reviewer"];
23
38
 
24
39
  /** One added line naming each role's models for the session's runtime, so a dispatch names the right one. */
@@ -85,7 +100,7 @@ function decideSubagentStart(cwd) {
85
100
  }
86
101
 
87
102
  /** @returns the hook output, or null when the checkout turns on neither `swarm.dispatch` nor `swarm.explore`. */
88
- function decideSessionStart(call) {
103
+ function decideSessionStart(call, env) {
89
104
  const cwd = call.cwd ?? process.cwd();
90
105
  let dispatch;
91
106
  try {
@@ -95,13 +110,14 @@ function decideSessionStart(call) {
95
110
  }
96
111
  const explore = exploreLine(cwd);
97
112
  if (!dispatch) return explore === "" ? null : context("SessionStart", explore.trim());
98
- return context("SessionStart", `${REMINDER}${modelsLine(dispatch)}${slotsLine(dispatch)}${directLine(cwd)}${explore}`);
113
+ if (env.QC_ROLE === "implementer") return context("SessionStart", `${WORKER_NOTE}${explore}`);
114
+ return context("SessionStart", `${REMINDER}${modelsLine(dispatch)}${CODEX_LINE}${slotsLine(dispatch)}${directLine(cwd)}${explore}`);
99
115
  }
100
116
 
101
117
  /** @returns the hook output, or null when there is nothing to add for this event. */
102
- export function decide(call) {
118
+ export function decide(call, env = process.env) {
103
119
  if (call.hook_event_name === "SubagentStart") return decideSubagentStart(call.cwd ?? process.cwd());
104
- return decideSessionStart(call);
120
+ return decideSessionStart(call, env);
105
121
  }
106
122
 
107
123
  async function readStdin() {
@@ -6,11 +6,12 @@ import path from "node:path";
6
6
  import { test } from "node:test";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { runtimeModels } from "../config.mjs";
9
- import { REMINDER, decide, modelsLine } from "./dispatch-reminder.mjs";
9
+ import { CODEX_LINE, REMINDER, WORKER_NOTE, decide, modelsLine } from "./dispatch-reminder.mjs";
10
10
 
11
11
  // The checkouts below run under Codex, whatever runtime runs the test.
12
12
  process.env.QC_RUNTIME = "codex";
13
- const BASE = `${REMINDER}${modelsLine({ models: runtimeModels.codex, runtime: "codex" })}`;
13
+ delete process.env.QC_ROLE;
14
+ const BASE = `${REMINDER}${modelsLine({ models: runtimeModels.codex, runtime: "codex" })}${CODEX_LINE}`;
14
15
 
15
16
  const NOTE = fileURLToPath(new URL("./dispatch-reminder.mjs", import.meta.url));
16
17
  const HOOKS = fileURLToPath(new URL("../../../../hooks/hooks.json", import.meta.url));
@@ -263,3 +264,64 @@ test("the models line names each role's models for the runtime, and how to dispa
263
264
  assert.match(codex, /the codex runtime: sdd-planner gpt-6\.1-sol, sdd-implementer gpt-6\.1-sol/);
264
265
  assert.match(modelsLine({ models: {}, runtime: null }), /unknown runtime \(set QC_RUNTIME to claude or codex\): sdd-planner the session's model/);
265
266
  });
267
+
268
+ test("the controller note says an implementer may run on Codex, and to fall back to a Claude sonnet on exit 2", () => {
269
+ for (const phrase of [
270
+ /qc codex-implement --brief <file> --worktree <path> --progress <file>/,
271
+ /exit 2 \(a Codex limit\)/,
272
+ /architecture:sdd-implementer \(sonnet\)/,
273
+ /same brief/,
274
+ ]) {
275
+ assert.match(CODEX_LINE, phrase);
276
+ }
277
+ assert.ok(!REMINDER.includes("codex-implement"));
278
+ });
279
+
280
+ test("QC_ROLE=implementer replaces the controller note with the worker note", (t) => {
281
+ const [on] = checkouts(t, [{ swarm: { dispatch: {} } }]);
282
+ const text = decide(start(on, "startup"), { QC_ROLE: "implementer" }).hookSpecificOutput.additionalContext;
283
+ assert.equal(text, WORKER_NOTE);
284
+ assert.ok(!text.includes("Run one implementer at a time"));
285
+ assert.ok(!text.includes("sdd-planner"));
286
+ });
287
+
288
+ test("the worker note says to work inline, run one test file, commit each task, and write ALL TASKS DONE", () => {
289
+ for (const phrase of [
290
+ /implementer under a controller/,
291
+ /Work inline/,
292
+ /Never use superpowers:subagent-driven-development, helper agents, task reviews, or fix-review rounds/,
293
+ /failing test, run only that test file, make it pass/,
294
+ /typecheck and lint on what you touched/,
295
+ /commit that task at once/,
296
+ /Do not run the full local gate or e2e; CI runs them/,
297
+ /append `ALL TASKS DONE` to the progress file the brief names/,
298
+ /context gets large.*end the turn.*fresh session continues/,
299
+ ]) {
300
+ assert.match(WORKER_NOTE, phrase);
301
+ }
302
+ assert.ok(WORKER_NOTE.length < 1000, `${WORKER_NOTE.length} characters`);
303
+ });
304
+
305
+ test("another QC_ROLE, or none, keeps the controller note", (t) => {
306
+ const [on] = checkouts(t, [{ swarm: { direct: false, dispatch: {} } }]);
307
+ for (const env of [{}, { QC_ROLE: "" }, { QC_ROLE: "controller" }]) {
308
+ assert.equal(decide(start(on, "startup"), env).hookSpecificOutput.additionalContext, BASE, JSON.stringify(env));
309
+ }
310
+ });
311
+
312
+ test("the worker note keeps the explore line, stays silent with dispatch off, and leaves SubagentStart alone", (t) => {
313
+ const [explore, off] = checkouts(t, [{ swarm: { dispatch: {}, explore: { tools: [{ name: "CocoIndex", use: "u", how: "h" }] } } }, null]);
314
+ const env = { QC_ROLE: "implementer" };
315
+ const text = decide(start(explore, "startup"), env).hookSpecificOutput.additionalContext;
316
+ assert.ok(text.startsWith(WORKER_NOTE));
317
+ assert.match(text, /CocoIndex/);
318
+ assert.equal(decide(start(off, "startup"), env), null);
319
+ assert.equal(decide(subagentStart(explore), env).hookSpecificOutput.hookEventName, "SubagentStart");
320
+ });
321
+
322
+ test("the hook process reads QC_ROLE from its environment", (t) => {
323
+ const [on] = checkouts(t, [{ swarm: { direct: false, dispatch: {} } }]);
324
+ const run = (env) => spawnSync(process.execPath, [NOTE], { input: JSON.stringify(start(on, "startup")), encoding: "utf8", env: { ...process.env, ...env } });
325
+ assert.equal(JSON.parse(run({ QC_ROLE: "implementer" }).stdout).hookSpecificOutput.additionalContext, WORKER_NOTE);
326
+ assert.equal(JSON.parse(run({}).stdout).hookSpecificOutput.additionalContext, BASE);
327
+ });
package/src/cli/qc.mjs CHANGED
@@ -23,6 +23,8 @@ const USAGE = `qc — architecture gates
23
23
  qc commit-msg <file> conventional (commitlint), English, and the trailer when attribution is on
24
24
  qc decisions [id] where decisions are cited; --squash closes the gaps
25
25
  qc ledger [--cost] [branch] the workflow ledger: dispatches, stops, verdicts, merges, issue updates; --cost totals tokens and tool calls
26
+ qc codex-implement --brief <file> --worktree <path> --progress <file> [--log <file>] [--max-runs <n>]
27
+ run a brief through codex exec as an implementer, restarting until the progress file says ALL TASKS DONE; exit 2 on a Codex limit
26
28
  qc plan-check <plan.md> each task names files, a test step and a commit step, within the tool-call budget
27
29
  qc tokens [--session <id>] [--project <dir>] [--claude-dir <dir>] [--json]
28
30
  one session's tokens and cache hit rate per agent type, from its transcripts
@@ -43,6 +45,11 @@ async function main() {
43
45
  const { runLease } = await import("./lease.mjs");
44
46
  process.exit(await runLease(rest));
45
47
  }
48
+ // The runner reads no configuration, so it runs from any folder.
49
+ if (command === "codex-implement") {
50
+ const { runCodexImplement } = await import("./codex-implement.mjs");
51
+ process.exit(await runCodexImplement(rest));
52
+ }
46
53
  const config = load(process.cwd());
47
54
 
48
55
  switch (command) {