architecture-harness 0.21.1 → 0.21.2

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.21.1",
3
+ "version": "0.21.2",
4
4
  "type": "module",
5
5
  "description": "Architecture gates, lint rules and scaffolding for the bounded-vertical-slice architecture",
6
6
  "license": "MIT",
@@ -40,13 +40,29 @@ export function parseArgs(argv) {
40
40
 
41
41
  const isDone = (progress) => existsSync(progress) && readFileSync(progress, "utf8").includes(DONE_MARKER);
42
42
 
43
+ const LEAN_RULES = [
44
+ "Lean rules for every session. They cut repeated reading and helper agents. Never drop a security, tenant, data, or correctness check that this brief asks for.",
45
+ "- At session start, rewrite the progress file to at most 40 lines: the pushed head, the done items one line each, the first unfinished item, and the open questions. Delete the history.",
46
+ "- Never re-verify a finished item, and never repeat a probe that already failed.",
47
+ "- Read only the line ranges that the current item needs.",
48
+ "- Start no helper agents. Run no broad audit, no Playwright, and no full gate. Run the tests of the touched files, and the local check once before the push.",
49
+ "- One item per session: code, test, commit, push, update the progress file, stop.",
50
+ "- Keep the report under 15 lines.",
51
+ ].join("\n");
52
+
43
53
  function continuationNote(progress) {
44
54
  return (
45
55
  `\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.`
56
+ `in the worktree, and the progress file ${progress}. Continue from the first unfinished task.\n\n${LEAN_RULES}`
47
57
  );
48
58
  }
49
59
 
60
+ /** The Codex features that start helper agents. Each run turns them off. */
61
+ const HELPER_AGENT_FEATURES = ["features.multi_agent=false", "features.multi_agent_v2=false"];
62
+
63
+ /** The brief is read again for each run, so an edit reaches the next session. */
64
+ const promptFor = (settings) => readFileSync(settings.brief, "utf8") + continuationNote(settings.progress);
65
+
50
66
  /** 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
67
  function spawnRun({ command, args, env, log }, codexCommand) {
52
68
  const [bin, ...prefix] = codexCommand;
@@ -80,10 +96,16 @@ export async function runCodexImplement(argv, { run, codexCommand = ["codex"], e
80
96
  return 1;
81
97
  }
82
98
  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
99
  for (let count = 1; count <= settings.maxRuns; count += 1) {
86
100
  if (isDone(settings.progress)) return finish(say, `done after ${count - 1} run(s)`, 0);
101
+ let prompt;
102
+ try {
103
+ prompt = promptFor(settings);
104
+ } catch (error) {
105
+ return finish(say, `cannot read the brief: ${error.message}`, 1);
106
+ }
107
+ const helperOff = HELPER_AGENT_FEATURES.flatMap((feature) => ["-c", feature]);
108
+ const args = ["exec", "-s", "danger-full-access", "-C", settings.worktree, ...helperOff, prompt];
87
109
  let result;
88
110
  try {
89
111
  result = await execute({ command: codexCommand[0], args, env: { ...env, QC_ROLE: "implementer" }, log: settings.log });
@@ -42,16 +42,67 @@ test("a run passes exec, the sandbox, the worktree and one prompt, with QC_ROLE=
42
42
  const [call] = seen;
43
43
  assert.equal(call.command, "codex");
44
44
  assert.deepEqual(call.args.slice(0, 5), ["exec", "-s", "danger-full-access", "-C", worktree]);
45
- assert.equal(call.args.length, 6);
45
+ const prompt = call.args.at(-1);
46
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));
47
+ assert.ok(prompt.startsWith(readFileSync(brief, "utf8")));
48
+ assert.match(prompt, /git log --oneline/);
49
+ assert.match(prompt, /git status --short/);
50
+ assert.match(prompt, /first unfinished task/);
51
+ assert.ok(prompt.includes(progress));
52
52
  assert.equal(call.log, `${progress}.log`);
53
53
  });
54
54
 
55
+ test("the brief is read again before each run, so an edit reaches the next session", async (t) => {
56
+ const { argv, brief, progress } = setup(t);
57
+ const prompts = [];
58
+ const run = async (call) => {
59
+ prompts.push(call.args.at(-1));
60
+ if (prompts.length === 1) writeFileSync(brief, "# Brief\n\nDo task one.\nDecision: use the new column name.\n");
61
+ else appendFileSync(progress, `${DONE_MARKER}\n`);
62
+ return { status: 0, tail: "ok" };
63
+ };
64
+ assert.equal(await runCodexImplement(argv, { run, say: quiet }), 0);
65
+ assert.equal(prompts.length, 2);
66
+ assert.ok(!prompts[0].includes("new column name"));
67
+ assert.ok(prompts[1].includes("Decision: use the new column name."));
68
+ });
69
+
70
+ test("every run prompt carries the lean rules after the brief", async (t) => {
71
+ const { argv, brief, progress } = setup(t);
72
+ const seen = [];
73
+ const run = async (call) => {
74
+ seen.push(call.args.at(-1));
75
+ if (seen.length === 2) appendFileSync(progress, `${DONE_MARKER}\n`);
76
+ return { status: 0, tail: "ok" };
77
+ };
78
+ assert.equal(await runCodexImplement(argv, { run, say: quiet }), 0);
79
+ assert.equal(seen.length, 2);
80
+ for (const prompt of seen) {
81
+ assert.ok(prompt.startsWith(readFileSync(brief, "utf8")));
82
+ assert.match(prompt, /at most 40 lines/);
83
+ assert.match(prompt, /re-verify/);
84
+ assert.match(prompt, /line ranges/);
85
+ assert.match(prompt, /helper agents/);
86
+ assert.match(prompt, /one item per session/i);
87
+ assert.match(prompt, /under 15 lines/);
88
+ assert.match(prompt, /never drop a security, tenant, data, or correctness check/i);
89
+ }
90
+ });
91
+
92
+ test("a run turns off the Codex helper agents with -c, before the prompt", async (t) => {
93
+ const { argv, progress } = setup(t);
94
+ let args;
95
+ const run = async (call) => {
96
+ args = call.args;
97
+ appendFileSync(progress, `${DONE_MARKER}\n`);
98
+ return { status: 0, tail: "ok" };
99
+ };
100
+ assert.equal(await runCodexImplement(argv, { run, say: quiet }), 0);
101
+ const index = args.indexOf("features.multi_agent=false");
102
+ assert.ok(index > 0 && args[index - 1] === "-c");
103
+ assert.ok(index < args.length - 1, "the prompt stays the last argument");
104
+ });
105
+
55
106
  test("a fresh session starts after a stop with the progress file not done", async (t) => {
56
107
  const { argv, progress } = setup(t);
57
108
  let calls = 0;
@@ -146,7 +197,7 @@ test("the default runner spawns without a shell, closes stdin, and appends outpu
146
197
  assert.equal(line.role, "implementer");
147
198
  assert.equal(line.input, "");
148
199
  assert.deepEqual(line.args.slice(0, 3), ["exec", "-s", "danger-full-access"]);
149
- assert.ok(line.args[5].startsWith(readFileSync(brief, "utf8")));
200
+ assert.ok(line.args.at(-1).startsWith(readFileSync(brief, "utf8")));
150
201
 
151
202
  writeFileSync(progress, "");
152
203
  process.env.FAKE_MODE = "limit";
@@ -19,10 +19,11 @@ 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. */
22
+ /** Two sentences name Codex first, its controller skill, and the Claude fallback on a Codex limit. */
23
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).";
24
+ " Implementer work runs on Codex first through `qc codex-implement --brief <file> --worktree <path> --progress <file>`; " +
25
+ "load the `architecture:codex` skill before the first dispatch. " +
26
+ "On exit 2 (a Codex limit), dispatch the same brief to an architecture:sdd-implementer (sonnet).";
26
27
 
27
28
  /** The note a Codex implementer gets in place of the controller note, with `QC_ROLE=implementer`. */
28
29
  export const WORKER_NOTE =
@@ -265,9 +265,11 @@ test("the models line names each role's models for the runtime, and how to dispa
265
265
  assert.match(modelsLine({ models: {}, runtime: null }), /unknown runtime \(set QC_RUNTIME to claude or codex\): sdd-planner the session's model/);
266
266
  });
267
267
 
268
- test("the controller note says an implementer may run on Codex, and to fall back to a Claude sonnet on exit 2", () => {
268
+ test("the controller note makes Codex the first choice, names its skill, and falls back to Claude sonnet on exit 2", () => {
269
269
  for (const phrase of [
270
+ /Implementer work runs on Codex first/,
270
271
  /qc codex-implement --brief <file> --worktree <path> --progress <file>/,
272
+ /load the `architecture:codex` skill before the first dispatch/,
271
273
  /exit 2 \(a Codex limit\)/,
272
274
  /architecture:sdd-implementer \(sonnet\)/,
273
275
  /same brief/,
@@ -355,3 +355,121 @@ test("a failing typecheck with no error line does not retry, and a passing one r
355
355
  assert.equal(green.run().status, 0);
356
356
  assert.equal(green.count(), 1);
357
357
  });
358
+
359
+ test("a root typecheck script replaces tsc -b, keeps the TS2307 retry, and the lint call carries a cache", (t) => {
360
+ const ws = workspace(t, { codes: {}, withDoctor: false });
361
+ const base = path.dirname(ws.tmpDir);
362
+ const repo = path.join(base, "repo");
363
+ mkdirSync(path.join(repo, "node_modules", ".bin"), { recursive: true });
364
+ writeFileSync(path.join(repo, "node_modules", ".bin", "eslint"), "");
365
+ writeFileSync(path.join(repo, "package.json"), JSON.stringify({ scripts: { typecheck: "tsgo" } }));
366
+ writeFileSync(path.join(repo, "pnpm-lock.yaml"), "");
367
+ const stubDir = path.join(base, "stub");
368
+ mkdirSync(stubDir, { recursive: true });
369
+ const calls = path.join(stubDir, "calls");
370
+ const counter = path.join(stubDir, "count");
371
+ writeFileSync(
372
+ path.join(stubDir, "pnpm"),
373
+ [
374
+ "#!/usr/bin/env bash",
375
+ `echo "pnpm $*" >> "${calls}"`,
376
+ `n=$(cat "${counter}" 2>/dev/null || echo 0); n=$((n + 1)); echo $n > "${counter}"`,
377
+ `if [ $n -eq 1 ]; then printf '%s' "${TS2307.trim()}"; exit 2; fi`,
378
+ "exit 0",
379
+ ].join("\n") + "\n",
380
+ { mode: 0o755 },
381
+ );
382
+ writeFileSync(path.join(stubDir, "npx"), ["#!/usr/bin/env bash", `echo "npx $*" >> "${calls}"`, "exit 0"].join("\n") + "\n", { mode: 0o755 });
383
+ const result = ws.run({}, { PATH: `${stubDir}${path.delimiter}${process.env.PATH}` });
384
+ assert.equal(result.status, 0, result.stderr);
385
+ const lines = readFileSync(calls, "utf8").trim().split("\n");
386
+ assert.deepEqual(lines.slice(0, 2), ["pnpm run -s typecheck", "pnpm run -s typecheck"]);
387
+ assert.ok(!lines.some((l) => l.startsWith("npx tsc")));
388
+ assert.ok(lines.includes("npx eslint . --max-warnings 0 --cache --cache-location node_modules/.cache/eslint-stop-gate"));
389
+ });
390
+
391
+ /** A workspace whose repository is a git repository with one commit, so the gate can fingerprint it. */
392
+ function gitWorkspace(t, installed = { codes: {}, withDoctor: false }) {
393
+ const ws = workspace(t, installed);
394
+ const repo = path.join(path.dirname(ws.tmpDir), "repo");
395
+ const git = (...args) => {
396
+ const r = spawnSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.com", ...args], { cwd: repo, encoding: "utf8" });
397
+ assert.equal(r.status, 0, r.stderr);
398
+ };
399
+ writeFileSync(path.join(repo, ".gitignore"), "node_modules\n");
400
+ writeFileSync(path.join(repo, "a.txt"), "one\n");
401
+ git("init", "-q");
402
+ git("add", "-A");
403
+ git("commit", "-q", "-m", "first");
404
+ return { ...ws, repo, git };
405
+ }
406
+
407
+ test("a second stop on an unchanged checkout skips the gate", (t) => {
408
+ const ws = gitWorkspace(t);
409
+ assert.equal(ws.run().status, 0);
410
+ assert.deepEqual(ws.ran(), ["installed check"]);
411
+ assert.equal(ws.run().status, 0);
412
+ assert.deepEqual(ws.ran(), ["installed check"]);
413
+ });
414
+
415
+ test("an edited tracked file makes the next stop run the full gate", (t) => {
416
+ const ws = gitWorkspace(t);
417
+ ws.run();
418
+ writeFileSync(path.join(ws.repo, "a.txt"), "two\n");
419
+ ws.run();
420
+ assert.equal(ws.ran().length, 2);
421
+ writeFileSync(path.join(ws.repo, "a.txt"), "three\n");
422
+ ws.run();
423
+ assert.equal(ws.ran().length, 3);
424
+ });
425
+
426
+ test("a new untracked file makes the next stop run the full gate", (t) => {
427
+ const ws = gitWorkspace(t);
428
+ ws.run();
429
+ writeFileSync(path.join(ws.repo, "b.txt"), "new\n");
430
+ ws.run();
431
+ assert.equal(ws.ran().length, 2);
432
+ ws.run();
433
+ assert.equal(ws.ran().length, 2);
434
+ });
435
+
436
+ test("a new commit makes the next stop run the full gate", (t) => {
437
+ const ws = gitWorkspace(t);
438
+ ws.run();
439
+ ws.git("commit", "-q", "--allow-empty", "-m", "second");
440
+ ws.run();
441
+ assert.equal(ws.ran().length, 2);
442
+ });
443
+
444
+ test("a red first run stores nothing, so the next stop runs the full gate again", (t) => {
445
+ const ws = gitWorkspace(t, { codes: { check: 1 }, withDoctor: false });
446
+ assert.equal(ws.run().status, 2);
447
+ assert.equal(ws.run().status, 2);
448
+ assert.equal(ws.ran().length, 2);
449
+ });
450
+
451
+ test("a repository that is no git checkout always runs the full gate", (t) => {
452
+ const ws = workspace(t, { codes: {}, withDoctor: false });
453
+ ws.run();
454
+ ws.run();
455
+ assert.equal(ws.ran().length, 2);
456
+ });
457
+
458
+ test("two checkout roots do not share a fingerprint", (t) => {
459
+ const a = gitWorkspace(t);
460
+ const b = gitWorkspace(t);
461
+ // Same temp folder, same content, same commit shape: only the root path differs.
462
+ const shared = { TMPDIR: a.tmpDir, TEMP: a.tmpDir, TMP: a.tmpDir };
463
+ const runIn = (ws) =>
464
+ spawnSync("bash", [HOOK], {
465
+ input: JSON.stringify({ hook_event_name: "Stop" }),
466
+ env: { ...process.env, CLAUDE_PROJECT_DIR: ws.repo, CLAUDE_PLUGIN_ROOT: path.join(path.dirname(ws.tmpDir), "plugin"), QC_STOP_EXTRA: "", ...shared },
467
+ encoding: "utf8",
468
+ });
469
+ runIn(a);
470
+ runIn(b);
471
+ assert.equal(a.ran().length, 1);
472
+ assert.equal(b.ran().length, 1);
473
+ runIn(a);
474
+ assert.equal(a.ran().length, 1);
475
+ });