architecture-harness 0.25.0 → 0.26.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 (244) hide show
  1. package/package.json +3 -22
  2. package/src/cli/ask.mjs +42 -0
  3. package/src/cli/ask.test.mjs +40 -0
  4. package/src/cli/branch-sync.mjs +126 -0
  5. package/src/cli/branch-sync.test.mjs +428 -0
  6. package/src/cli/budget-guard.mjs +74 -5
  7. package/src/cli/budget-guard.test.mjs +185 -2
  8. package/src/cli/budget-report.mjs +85 -0
  9. package/src/cli/budget-report.test.mjs +173 -0
  10. package/src/cli/budget.mjs +8 -5
  11. package/src/cli/check-commands.mjs +123 -11
  12. package/src/cli/check-commands.test.mjs +360 -6
  13. package/src/cli/check-feature-switches.test.mjs +110 -0
  14. package/src/cli/check-full.test.mjs +152 -0
  15. package/src/cli/check-verdict.mjs +46 -0
  16. package/src/cli/check-verdict.test.mjs +32 -0
  17. package/src/cli/check.mjs +137 -4
  18. package/src/cli/check.test.mjs +45 -0
  19. package/src/cli/checkpoint.mjs +143 -0
  20. package/src/cli/checkpoint.test.mjs +146 -0
  21. package/src/cli/child-run.mjs +7 -2
  22. package/src/cli/child-run.test.mjs +17 -2
  23. package/src/cli/ci-failures.mjs +304 -0
  24. package/src/cli/ci-failures.test.mjs +615 -0
  25. package/src/cli/ci-preview.mjs +62 -0
  26. package/src/cli/ci-preview.test.mjs +85 -0
  27. package/src/cli/ci-state.mjs +25 -29
  28. package/src/cli/ci-state.test.mjs +174 -2
  29. package/src/cli/ci-template.test.mjs +86 -0
  30. package/src/cli/claude-core.test.mjs +37 -0
  31. package/src/cli/codex-implement.mjs +580 -47
  32. package/src/cli/codex-implement.test.mjs +1946 -29
  33. package/src/cli/codex-limit.mjs +85 -0
  34. package/src/cli/codex-limit.test.mjs +179 -0
  35. package/src/cli/codex-reset.mjs +78 -0
  36. package/src/cli/codex-reset.test.mjs +192 -0
  37. package/src/cli/codex-verify.mjs +230 -0
  38. package/src/cli/codex-verify.test.mjs +402 -0
  39. package/src/cli/comment-watch.mjs +391 -0
  40. package/src/cli/comment-watch.test.mjs +392 -0
  41. package/src/cli/commit-guard.mjs +219 -0
  42. package/src/cli/commit-guard.test.mjs +809 -0
  43. package/src/cli/context-budgets.mjs +47 -0
  44. package/src/cli/context-budgets.test.mjs +96 -0
  45. package/src/cli/context-watch.mjs +116 -0
  46. package/src/cli/context-watch.test.mjs +395 -0
  47. package/src/cli/contract-history.mjs +1 -1
  48. package/src/cli/controller-guard.mjs +38 -0
  49. package/src/cli/controller-guard.test.mjs +66 -2
  50. package/src/cli/cost-stop.mjs +5 -1
  51. package/src/cli/cost-stop.test.mjs +26 -0
  52. package/src/cli/diff-shape.mjs +162 -0
  53. package/src/cli/diff-shape.test.mjs +200 -0
  54. package/src/cli/direct-lane.mjs +32 -19
  55. package/src/cli/direct-lane.test.mjs +21 -3
  56. package/src/cli/dispatch-guard.mjs +11 -0
  57. package/src/cli/dispatch-guard.test.mjs +145 -10
  58. package/src/cli/dispatch-reminder.mjs +23 -10
  59. package/src/cli/dispatch-reminder.test.mjs +63 -11
  60. package/src/cli/dispatch-route.mjs +54 -0
  61. package/src/cli/dispatch-route.test.mjs +101 -0
  62. package/src/cli/dispatch-slot.mjs +2 -2
  63. package/src/cli/dispatch-slot.test.mjs +18 -19
  64. package/src/cli/dispatch.test.mjs +3 -3
  65. package/src/cli/e2e-affected.mjs +15 -0
  66. package/src/cli/e2e-affected.test.mjs +73 -0
  67. package/src/cli/fleet.mjs +180 -0
  68. package/src/cli/fleet.test.mjs +213 -0
  69. package/src/cli/gate-slot.mjs +2 -1
  70. package/src/cli/gh-merge-command.mjs +96 -31
  71. package/src/cli/gh-merge-command.test.mjs +74 -0
  72. package/src/cli/gh-run.mjs +64 -3
  73. package/src/cli/gh-run.test.mjs +66 -1
  74. package/src/cli/git-hooks.test.mjs +25 -3
  75. package/src/cli/git-read.mjs +2 -1
  76. package/src/cli/integrate-tree.mjs +47 -0
  77. package/src/cli/integrate.mjs +143 -40
  78. package/src/cli/integrate.test.mjs +347 -1
  79. package/src/cli/integration-lane.mjs +62 -0
  80. package/src/cli/integration-lane.test.mjs +213 -0
  81. package/src/cli/ledger.mjs +4 -2
  82. package/src/cli/ledger.test.mjs +12 -3
  83. package/src/cli/legs.mjs +53 -0
  84. package/src/cli/legs.test.mjs +70 -0
  85. package/src/cli/lint-changed.mjs +59 -10
  86. package/src/cli/lint-changed.test.mjs +112 -1
  87. package/src/cli/locked-tests.mjs +134 -0
  88. package/src/cli/locked-tests.test.mjs +188 -0
  89. package/src/cli/merge-guard.mjs +234 -62
  90. package/src/cli/merge-guard.test.mjs +768 -39
  91. package/src/cli/metrics.mjs +53 -0
  92. package/src/cli/metrics.test.mjs +73 -0
  93. package/src/cli/milestone.mjs +297 -0
  94. package/src/cli/milestone.test.mjs +294 -0
  95. package/src/cli/mutate.mjs +203 -0
  96. package/src/cli/mutate.test.mjs +134 -0
  97. package/src/cli/output-redaction.mjs +26 -0
  98. package/src/cli/output-redaction.test.mjs +117 -0
  99. package/src/cli/overview.mjs +131 -0
  100. package/src/cli/overview.test.mjs +137 -0
  101. package/src/cli/pause.mjs +93 -0
  102. package/src/cli/pause.test.mjs +109 -0
  103. package/src/cli/plan-check.mjs +84 -12
  104. package/src/cli/plan-check.test.mjs +152 -2
  105. package/src/cli/plan-stop.mjs +7 -4
  106. package/src/cli/plan-stop.test.mjs +87 -0
  107. package/src/cli/platform-risk.mjs +46 -0
  108. package/src/cli/platform-risk.test.mjs +38 -0
  109. package/src/cli/plugin-skills.test.mjs +25 -0
  110. package/src/cli/pr-guard.mjs +128 -0
  111. package/src/cli/pr-guard.test.mjs +154 -0
  112. package/src/cli/promotion-branch.mjs +2 -0
  113. package/src/cli/qc.mjs +160 -27
  114. package/src/cli/qc.test.mjs +93 -0
  115. package/src/cli/report-stop.mjs +5 -0
  116. package/src/cli/report-stop.test.mjs +23 -1
  117. package/src/cli/retry-failed.mjs +3 -1
  118. package/src/cli/review-gate.mjs +24 -6
  119. package/src/cli/review-gate.test.mjs +116 -0
  120. package/src/cli/review-promotion.mjs +107 -0
  121. package/src/cli/review-promotion.test.mjs +251 -0
  122. package/src/cli/role-budget.mjs +50 -0
  123. package/src/cli/role-budget.test.mjs +91 -0
  124. package/src/cli/run-log.mjs +73 -0
  125. package/src/cli/run-log.test.mjs +121 -0
  126. package/src/cli/secret-patterns.mjs +16 -0
  127. package/src/cli/secret-patterns.test.mjs +73 -0
  128. package/src/cli/setup-block.mjs +24 -0
  129. package/src/cli/setup-block.test.mjs +96 -0
  130. package/src/cli/setup-checks.mjs +65 -0
  131. package/src/cli/setup-checks.test.mjs +158 -0
  132. package/src/cli/setup-compaction.mjs +55 -0
  133. package/src/cli/setup-compaction.test.mjs +115 -0
  134. package/src/cli/setup-skills.mjs +65 -0
  135. package/src/cli/setup-skills.test.mjs +171 -0
  136. package/src/cli/setup.mjs +107 -0
  137. package/src/cli/setup.test.mjs +275 -0
  138. package/src/cli/skill-length.test.mjs +8 -0
  139. package/src/cli/spawn-command.mjs +47 -0
  140. package/src/cli/spawn-command.test.mjs +64 -0
  141. package/src/cli/task-gate-review.test.mjs +21 -2
  142. package/src/cli/task-gate.mjs +25 -12
  143. package/src/cli/task-gate.test.mjs +43 -5
  144. package/src/cli/tokens.mjs +46 -3
  145. package/src/cli/tokens.test.mjs +103 -3
  146. package/src/cli/tools.mjs +49 -0
  147. package/src/cli/tools.test.mjs +89 -0
  148. package/src/cli/transcript-usage.mjs +27 -0
  149. package/src/cli/transcript-usage.test.mjs +34 -0
  150. package/src/cli/user-config-package.mjs +1 -1
  151. package/src/cli/user-config-toml.mjs +63 -7
  152. package/src/cli/user-config.mjs +39 -7
  153. package/src/cli/user-config.test.mjs +238 -5
  154. package/src/cli/watch-arm.mjs +39 -0
  155. package/src/cli/watch-arm.test.mjs +87 -0
  156. package/src/cli/watch.mjs +80 -35
  157. package/src/cli/watch.test.mjs +233 -27
  158. package/src/cli/work-order-guard.mjs +2 -1
  159. package/src/cli/workflow-hooks.test.mjs +18 -4
  160. package/src/cli/workflow-settings.mjs +44 -8
  161. package/src/cli/workflow-settings.test.mjs +124 -1
  162. package/src/cli/worktree.mjs +14 -1
  163. package/src/cli/worktree.test.mjs +20 -1
  164. package/src/config.mjs +174 -7
  165. package/src/config.test.mjs +327 -5
  166. package/src/consumer-package.mjs +31 -0
  167. package/src/consumer-package.test.mjs +54 -0
  168. package/src/descriptions.mjs +2 -0
  169. package/src/eslint/index.mjs +12 -0
  170. package/src/eslint/jsx.mjs +20 -0
  171. package/src/eslint/preset.mjs +26 -2
  172. package/src/eslint/preset.test.mjs +104 -2
  173. package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
  174. package/src/eslint/rules/no-literal-color.mjs +94 -0
  175. package/src/eslint/rules/no-static-inline-style.mjs +41 -0
  176. package/src/eslint/rules/one-component-per-file.mjs +70 -0
  177. package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
  178. package/src/eslint/rules/timeless-comment.mjs +92 -0
  179. package/src/eslint/rules.test.mjs +189 -0
  180. package/src/eslint/ui-regressions.test.mjs +39 -0
  181. package/src/gates/contract-operations.mjs +3 -3
  182. package/src/gates/contract-operations.test.mjs +28 -0
  183. package/src/gates/feature-switches.mjs +19 -0
  184. package/src/gates/feature-switches.test.mjs +55 -0
  185. package/src/gates/plain-language.mjs +396 -0
  186. package/src/gates/plain-language.test.mjs +210 -0
  187. package/src/gates/runtime-imports.test.mjs +114 -0
  188. package/src/gates/saga-key.test.mjs +1 -1
  189. package/src/global-skills.mjs +9 -0
  190. package/src/global-skills.test.mjs +53 -0
  191. package/src/plugin.test.mjs +3 -2
  192. package/src/ui/class-sites.mjs +38 -6
  193. package/src/ui/codemod.mjs +4 -1
  194. package/src/ui/codemod.test.mjs +52 -0
  195. package/src/ui/components.mjs +5 -3
  196. package/src/ui/components.test.mjs +8 -0
  197. package/src/ui/dupes.test.mjs +18 -0
  198. package/templates/docs/enforcement.md +12 -2
  199. package/templates/docs/ui.md +33 -0
  200. package/templates/githooks/pre-commit +1 -0
  201. package/templates/githooks/pre-push +11 -2
  202. package/templates/github/workflows/ci.yml +57 -3
  203. package/user-config/claude/CLAUDE.core.md +28 -0
  204. package/user-config/claude/settings.shared.json +41 -1
  205. package/src/cli/screens-discovery.mjs +0 -60
  206. package/src/cli/screens.mjs +0 -84
  207. package/src/cli/stack.mjs +0 -14
  208. package/src/cli/throwaway-db.mjs +0 -127
  209. package/src/cli/throwaway-db.test.mjs +0 -83
  210. package/src/screens/auth-context.test.mjs +0 -41
  211. package/src/screens/auth-run.test.mjs +0 -147
  212. package/src/screens/auth.mjs +0 -223
  213. package/src/screens/auth.test.mjs +0 -76
  214. package/src/screens/capture-idle.test.mjs +0 -27
  215. package/src/screens/capture.browser-test.mjs +0 -73
  216. package/src/screens/capture.mjs +0 -175
  217. package/src/screens/capture.test.mjs +0 -28
  218. package/src/screens/catalog.browser-test.mjs +0 -32
  219. package/src/screens/catalog.mjs +0 -72
  220. package/src/screens/catalog.test.mjs +0 -36
  221. package/src/screens/chrome.mjs +0 -21
  222. package/src/screens/compare.mjs +0 -40
  223. package/src/screens/compare.test.mjs +0 -30
  224. package/src/screens/discovery.browser-test.mjs +0 -29
  225. package/src/screens/discovery.mjs +0 -158
  226. package/src/screens/discovery.test.mjs +0 -27
  227. package/src/screens/inventory.mjs +0 -69
  228. package/src/screens/inventory.test.mjs +0 -10
  229. package/src/screens/map.mjs +0 -63
  230. package/src/screens/map.test.mjs +0 -35
  231. package/src/screens/open.browser-test.mjs +0 -50
  232. package/src/screens/regions.mjs +0 -137
  233. package/src/screens/regions.test.mjs +0 -38
  234. package/src/screens/session-files.mjs +0 -39
  235. package/src/screens/session-files.test.mjs +0 -39
  236. package/src/screens/setup.browser-test.mjs +0 -49
  237. package/src/screens/setup.mjs +0 -78
  238. package/src/screens/stack-auth.browser-test.mjs +0 -30
  239. package/src/screens/stack-auth.mjs +0 -106
  240. package/src/screens/stack-auth.test.mjs +0 -65
  241. package/src/screens/write-guard.mjs +0 -26
  242. package/src/stack/stack.mjs +0 -131
  243. package/src/stack/stack.test.mjs +0 -40
  244. package/src/stack/supervisor.mjs +0 -30
@@ -0,0 +1,54 @@
1
+ // This branch keeps the panel's runtime and model consistent with the dispatch.
2
+ import { readFileSync } from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { familyOf, isImplementer, typeOf } from "./dispatch.mjs";
6
+
7
+ export const isCodexType = (type) => type === "codex" || type === "architecture:codex";
8
+ export const RUNTIME_LINE = /^[\t ]*Runtime:[\t ]*claude[\t ]+(\S[^\r\n]*?)[\t ]*$/im;
9
+
10
+ export function routeRefusal(input, settings, limit) {
11
+ const type = typeOf(input);
12
+ const prompt = typeof input.prompt === "string" ? input.prompt : "";
13
+ if (isCodexType(type)) {
14
+ if (!limit) return null;
15
+ const preferred = "architecture:sdd-implementer";
16
+ const fallback = settings.implementerTypes.includes(preferred) ? preferred :
17
+ settings.implementerTypes.find((name) => name.endsWith("sdd-implementer")) ?? preferred;
18
+ const brief = prompt.match(/^[\t ]*Brief:[^\r\n]*$/m)?.[0] ?? "Brief: <path>";
19
+ return `Dispatch guard: Codex is limited until ${limit.until.toISOString()}; run \`qc codex status\` to check the limit. ` +
20
+ `Dispatch \`${fallback}\` with model \`sonnet\` and the same brief:\n${brief}`;
21
+ }
22
+ if (!limit && isImplementer(type, settings) && !RUNTIME_LINE.test(prompt)) {
23
+ return "Dispatch guard: an implementer dispatch while Codex is free needs a prompt line `Runtime: claude <reason>` with a reason.";
24
+ }
25
+ return null;
26
+ }
27
+
28
+ export function codexModelOf(env = process.env) {
29
+ const home = env.CODEX_HOME || path.join(os.homedir(), ".codex");
30
+ let config;
31
+ try {
32
+ config = readFileSync(path.join(home, "config.toml"), "utf8");
33
+ } catch {
34
+ return null;
35
+ }
36
+ for (const line of config.split(/\r?\n/)) {
37
+ if (/^\s*\[/.test(line)) break;
38
+ const match = line.match(/^\s*model\s*=\s*(["'])(.*?)\1\s*(?:#.*)?$/);
39
+ if (match) return match[2];
40
+ }
41
+ return null;
42
+ }
43
+
44
+ export function runtimeTagOf(input, { codexModel } = {}) {
45
+ if (isCodexType(typeOf(input))) return `Codex ${codexModel || "default"} \u00b7 `;
46
+ const model = typeof input.model === "string" && input.model !== "" ? input.model : null;
47
+ return `Claude ${(model && (familyOf(model) || model)) || "default"} \u00b7 `;
48
+ }
49
+
50
+ export function tagRefusal(input, options) {
51
+ const tag = runtimeTagOf(input, options);
52
+ if (typeof input.description === "string" && input.description.trimStart().startsWith(tag)) return null;
53
+ return `Dispatch guard: the description of a ${typeOf(input)} dispatch must start with "${tag}" so the agent panel shows the runtime and the model. Write "${tag}<what the agent does>".`;
54
+ }
@@ -0,0 +1,101 @@
1
+ import { strict as assert } from "node:assert";
2
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { test } from "node:test";
6
+ import { codexModelOf, isCodexType, routeRefusal, runtimeTagOf, tagRefusal } from "./dispatch-route.mjs";
7
+
8
+ function configHome(t, content) {
9
+ const home = mkdtempSync(path.join(os.tmpdir(), "qc-route-"));
10
+ t.after(() => rmSync(home, { recursive: true, force: true }));
11
+ if (content !== undefined) writeFileSync(path.join(home, "config.toml"), content);
12
+ return { CODEX_HOME: home };
13
+ }
14
+
15
+ test("codexModelOf reads a top-level model in double or single quotes", (t) => {
16
+ for (const quote of ['"', "'"]) {
17
+ const env = configHome(t, `# model = "ignored"\nmodel = ${quote}gpt-6.1-sol${quote} # runtime\n[profiles.work]\nmodel = "other"\n`);
18
+ assert.equal(codexModelOf(env), "gpt-6.1-sol");
19
+ }
20
+ });
21
+
22
+ test("codexModelOf returns null for a missing file or key and stops at the first table", (t) => {
23
+ for (const content of [undefined, 'model_provider = "openai"\n', '[profiles.work]\nmodel = "other"\n', ' [profiles.work]\nmodel = "other"\n']) {
24
+ assert.equal(codexModelOf(configHome(t, content)), null);
25
+ }
26
+ });
27
+
28
+ test("only codex and architecture:codex use the Codex runtime", () => {
29
+ for (const type of ["codex", "architecture:codex"]) assert.equal(isCodexType(type), true);
30
+ for (const type of ["general-purpose", "architecture:sdd-implementer", "other:codex"]) assert.equal(isCodexType(type), false);
31
+ });
32
+
33
+ test("runtimeTagOf uses the configured Codex model instead of the Agent model", () => {
34
+ for (const subagent_type of ["codex", "architecture:codex"]) {
35
+ const input = { subagent_type, model: "haiku" };
36
+ assert.equal(runtimeTagOf(input, { codexModel: "gpt-6.1-sol" }), "Codex gpt-6.1-sol \u00b7 ");
37
+ assert.equal(runtimeTagOf(input, { codexModel: null }), "Codex default \u00b7 ");
38
+ }
39
+ });
40
+
41
+ test("runtimeTagOf uses the Claude family, model string, or default", () => {
42
+ for (const [model, label] of [["sonnet", "sonnet"], ["claude-opus-4-5", "opus"], ["custom", "custom"], [undefined, "default"]]) {
43
+ assert.equal(runtimeTagOf({ subagent_type: "architecture:sdd-implementer", model }, { codexModel: null }), `Claude ${label} \u00b7 `);
44
+ }
45
+ });
46
+
47
+ test("tagRefusal accepts the exact prefix with optional leading spaces", () => {
48
+ const input = { subagent_type: "architecture:codex", model: "haiku" };
49
+ for (const leading of ["", " "]) {
50
+ assert.equal(tagRefusal({ ...input, description: `${leading}Codex gpt-6.1-sol \u00b7 work` }, { codexModel: "gpt-6.1-sol" }), null);
51
+ }
52
+ });
53
+
54
+ test("tagRefusal quotes the exact tag for a missing description, wrong runtime, or wrong model", () => {
55
+ const tag = "Codex gpt-6.1-sol \u00b7 ";
56
+ for (const description of [undefined, "work", "Claude gpt-6.1-sol \u00b7 work", "Codex default \u00b7 work"]) {
57
+ assert.equal(
58
+ tagRefusal({ subagent_type: "architecture:codex", description }, { codexModel: "gpt-6.1-sol" }),
59
+ `Dispatch guard: the description of a architecture:codex dispatch must start with "${tag}" so the agent panel shows the runtime and the model. Write "${tag}<what the agent does>".`,
60
+ );
61
+ }
62
+ });
63
+
64
+ const settings = { implementerTypes: ["codex", "architecture:codex", "architecture:sdd-implementer"] };
65
+ const limit = { until: new Date("2026-10-26T15:00:00Z"), source: "codex" };
66
+
67
+ test("routeRefusal refuses Codex while limited and names the Sonnet implementer with the same brief", () => {
68
+ for (const subagent_type of ["codex", "architecture:codex"]) {
69
+ const refusal = routeRefusal({ subagent_type, prompt: "Read the brief.\nBrief: brief.md\nReport: report.md" }, settings, limit);
70
+ for (const text of ["2026-10-26T15:00:00.000Z", "qc codex status", "architecture:sdd-implementer", "sonnet", "Brief: brief.md"]) {
71
+ assert.ok(refusal.includes(text), text);
72
+ }
73
+ }
74
+ });
75
+
76
+ test("routeRefusal allows an implementer while Codex is limited and Codex while free", () => {
77
+ assert.equal(routeRefusal({ subagent_type: "architecture:sdd-implementer", prompt: "Brief: brief.md" }, settings, limit), null);
78
+ for (const subagent_type of ["codex", "architecture:codex"]) {
79
+ assert.equal(routeRefusal({ subagent_type, prompt: "Brief: brief.md" }, settings, null), null);
80
+ }
81
+ });
82
+
83
+ test("routeRefusal requires a Claude Runtime line with a reason for an implementer while Codex is free", () => {
84
+ for (const runtime of ["", "Runtime: claude", "Runtime: codex x", "Runtime: claude ", "Runtime: claude\nother text"]) {
85
+ const refusal = routeRefusal({ subagent_type: "architecture:sdd-implementer", prompt: `Brief: brief.md\n${runtime}` }, settings, null);
86
+ assert.ok(refusal.includes("Runtime: claude <reason>"), runtime);
87
+ }
88
+ assert.equal(routeRefusal({ subagent_type: "architecture:sdd-implementer", prompt: "Brief: brief.md\nRuntime: claude codex is down" }, settings, null), null);
89
+ });
90
+
91
+ test("routeRefusal uses the configured sdd-implementer fallback and leaves other roles alone", () => {
92
+ const custom = { implementerTypes: ["codex", "custom:sdd-implementer"] };
93
+ assert.ok(routeRefusal({ subagent_type: "codex", prompt: "Brief: brief.md" }, custom, limit).includes("custom:sdd-implementer"));
94
+ assert.equal(routeRefusal({ subagent_type: "general-purpose" }, settings, null), null);
95
+ });
96
+
97
+ test("routeRefusal accepts case variants and zero or more horizontal spaces after Runtime:", () => {
98
+ for (const runtime of ["Runtime:claude reason", "Runtime: Claude reason", "rUnTiMe:\tClAuDe\treason", " RUNTIME: CLAUDE reason "]) {
99
+ assert.equal(routeRefusal({ subagent_type: "architecture:sdd-implementer", prompt: `Brief: brief.md\n${runtime}` }, settings, null), null, runtime);
100
+ }
101
+ });
@@ -24,7 +24,7 @@ const slotFileOf = (dir, index) => path.join(dir, `slot-${index}.claim`);
24
24
 
25
25
  function recordedSettings(dir) {
26
26
  try {
27
- const { implementerTypes, slotMinutes, implementerSlots = 1 } = JSON.parse(
27
+ const { implementerTypes, slotMinutes, implementerSlots = 3 } = JSON.parse(
28
28
  readFileSync(path.join(dir, SETTINGS_FILE), "utf8"),
29
29
  );
30
30
  const valid = Array.isArray(implementerTypes) && slotMinutes > 0 && Number.isInteger(implementerSlots) && implementerSlots > 0;
@@ -132,7 +132,7 @@ function refusalOf(slots, ttlMs, limit) {
132
132
  */
133
133
  export function claimSlot(dir, settings, now, holderId = randomUUID()) {
134
134
  const ttlMs = settings.slotMinutes * MINUTE_MS;
135
- const limit = settings.implementerSlots ?? 1;
135
+ const limit = settings.implementerSlots ?? 3;
136
136
  const held = `${PENDING}${holderId}`;
137
137
  expireSlots(dir, ttlMs, now);
138
138
  if (slotsOf(dir).some((slot) => slot.held === held)) return null;
@@ -12,7 +12,7 @@ function sessionDir(t, session = "s") {
12
12
  return slotDirOf(session, tmp);
13
13
  }
14
14
 
15
- const settings = { ...dispatchDefaults, slotMinutes: 1 };
15
+ const settings = { ...dispatchDefaults, slotMinutes: 1, implementerSlots: 1 };
16
16
  const withSlots = (implementerSlots) => ({ ...settings, implementerSlots });
17
17
  const IMPLEMENTER = "sdd-implementer";
18
18
 
@@ -91,23 +91,19 @@ test("a claim whose settings cannot be written is released, and the error reache
91
91
  assert.deepEqual(claimFiles(dir), []);
92
92
  });
93
93
 
94
- test("the default limit is 1, and a second holder is refused with the limit and the first holder", (t) => {
95
- const dir = sessionDir(t);
96
- assert.equal(dispatchDefaults.implementerSlots, 1);
97
- assert.equal(claimSlot(dir, settings, Date.now(), "use-1"), null);
98
- const refused = claimSlot(dir, settings, Date.now(), "use-2");
99
- assert.equal(refused.limit, 1);
100
- assert.deepEqual(refused.holders.map((holder) => holder.id), ["use-1"]);
101
- assert.deepEqual(claimFiles(dir).length, 1);
102
- });
103
-
104
- test("a limit of 3 holds three claims and refuses the fourth, naming the three holders", (t) => {
105
- const dir = sessionDir(t);
106
- for (const id of ["use-1", "use-2", "use-3"]) assert.equal(claimSlot(dir, withSlots(3), Date.now(), id), null);
107
- const refused = claimSlot(dir, withSlots(3), Date.now(), "use-4");
108
- assert.equal(refused.limit, 3);
109
- assert.deepEqual(refused.holders.map((holder) => holder.id).sort(), ["use-1", "use-2", "use-3"]);
110
- assert.equal(claimFiles(dir).length, 3);
94
+ test("the default and omitted limits hold three claims and refuse the fourth", (t) => {
95
+ assert.equal(dispatchDefaults.implementerSlots, 3);
96
+ for (const implementerSlots of [dispatchDefaults.implementerSlots, undefined]) {
97
+ const dir = sessionDir(t);
98
+ const defaults = { ...settings, implementerSlots };
99
+ for (const id of ["use-1", "use-2", "use-3"]) assert.equal(claimSlot(dir, defaults, Date.now(), id), null);
100
+ const refused = claimSlot(dir, defaults, Date.now(), "use-4");
101
+ assert.equal(refused.limit, 3);
102
+ assert.deepEqual(refused.holders.map((holder) => holder.id).sort(), ["use-1", "use-2", "use-3"]);
103
+ assert.equal(claimFiles(dir).length, 3);
104
+ const recorded = JSON.parse(readFileSync(path.join(dir, "settings.json"), "utf8"));
105
+ assert.equal(recorded.implementerSlots, 3);
106
+ }
111
107
  });
112
108
 
113
109
  test("a stop frees its own holder's claim only, so one slot opens and the others stay", (t) => {
@@ -216,7 +212,7 @@ test("a repeat of one holder's claim leaves its slot alone and takes no second s
216
212
  assert.deepEqual(claimFiles(dir), ["slot-0.claim"]);
217
213
  });
218
214
 
219
- test("the stop and the start read the limit recorded at the claim, and a record with no limit means 1", (t) => {
215
+ test("the stop and the start read the limit recorded at the claim, and a record with no limit means 3", (t) => {
220
216
  const dir = sessionDir(t);
221
217
  claimSlot(dir, withSlots(2), Date.now(), "use-1");
222
218
  reclaimSlot(dir, IMPLEMENTER, Date.now(), "agent-1");
@@ -225,5 +221,8 @@ test("the stop and the start read the limit recorded at the claim, and a record
225
221
  const { implementerTypes, slotMinutes } = settings;
226
222
  writeFileSync(path.join(dir, "settings.json"), JSON.stringify({ implementerTypes, slotMinutes }));
227
223
  reclaimSlot(dir, IMPLEMENTER, Date.now(), "agent-3");
224
+ reclaimSlot(dir, IMPLEMENTER, Date.now(), "agent-4");
225
+ assert.equal(claimFiles(dir).length, 3);
226
+ assert.equal(releaseSlot(dir, IMPLEMENTER, "agent-3"), true);
228
227
  assert.equal(claimFiles(dir).length, 2);
229
228
  });
@@ -170,9 +170,9 @@ test("the slot refusal names the expiry and the file that frees the slot", () =>
170
170
  assert.match(reason, /delete \/tmp\/slot\.claim/);
171
171
  });
172
172
 
173
- test("implementerSlots defaults to 1, and a repository sets a whole number", () => {
174
- assert.equal(dispatchSettings({ dispatch: {} }).implementerSlots, 1);
175
- assert.equal(dispatchSettings({ dispatch: { implementerSlots: 3 } }).implementerSlots, 3);
173
+ test("implementerSlots defaults to 3, and a repository sets a whole number", () => {
174
+ assert.equal(dispatchSettings({ dispatch: {} }).implementerSlots, 3);
175
+ assert.equal(dispatchSettings({ dispatch: { implementerSlots: 1 } }).implementerSlots, 1);
176
176
  });
177
177
 
178
178
  test("a refusal over a limit above 1 names the limit and each holder, and one at 1 keeps its text", () => {
@@ -0,0 +1,15 @@
1
+ // A branch that selects the configured e2e command for the changed files.
2
+ import { changedFiles, runCommand } from "./check-commands.mjs";
3
+
4
+ export async function runE2e(config) {
5
+ if (config.check.e2e === null) {
6
+ console.log("SKIP check.e2e is null; no e2e command to run");
7
+ return 0;
8
+ }
9
+ const files = changedFiles(config.root, config.check.base);
10
+ if (files?.length === 0) {
11
+ console.log("SKIP no changed file; no e2e spec to pick");
12
+ return 0;
13
+ }
14
+ return runCommand(config.root, config.check.e2e, files ?? []);
15
+ }
@@ -0,0 +1,73 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { execFileSync, spawnSync } from "node:child_process";
4
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
6
+ import path from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+ import { defaults } from "../config.mjs";
9
+
10
+ const qc = fileURLToPath(new URL("./qc.mjs", import.meta.url));
11
+ const node = (source) => `"${process.execPath}" -e '${source}'`;
12
+ const record = node('require("node:fs").writeFileSync("args.json", JSON.stringify(process.argv.slice(1)))');
13
+ const git = (root, ...args) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: "pipe" });
14
+
15
+ function fixture(t, check = {}) {
16
+ const root = mkdtempSync(path.join(tmpdir(), "qc-e2e-affected-"));
17
+ t.after(() => rmSync(root, { recursive: true, force: true }));
18
+ git(root, "init", "-q", "-b", "main");
19
+ git(root, "config", "user.name", "QC test");
20
+ git(root, "config", "user.email", "qc@example.test");
21
+ const config = {
22
+ featureRoots: [],
23
+ gates: Object.fromEntries(Object.keys(defaults.gates).map((key) => [key, false])),
24
+ check: { base: "main", ...check },
25
+ };
26
+ writeFileSync(path.join(root, "qc.config.json"), JSON.stringify(config));
27
+ writeFileSync(path.join(root, "committed.mjs"), "export const value = 1;\n");
28
+ git(root, "add", ".");
29
+ git(root, "commit", "-q", "-m", "test(qc): seed fixture");
30
+ git(root, "checkout", "-q", "-b", "feat/156-e2e");
31
+ return root;
32
+ }
33
+
34
+ function e2e(root) {
35
+ return spawnSync(process.execPath, [qc, "e2e"], { cwd: root, encoding: "utf8" });
36
+ }
37
+
38
+ test("e2e skips a null command", (t) => {
39
+ const root = fixture(t, { e2e: null });
40
+ const run = e2e(root);
41
+ assert.equal(run.status, 0, run.stderr);
42
+ assert.match(run.stdout, /SKIP check\.e2e/);
43
+ });
44
+
45
+ test("e2e receives committed and staged files", (t) => {
46
+ const root = fixture(t, { e2e: record });
47
+ writeFileSync(path.join(root, "committed.mjs"), "export const value = 2;\n");
48
+ git(root, "add", "committed.mjs");
49
+ git(root, "commit", "-q", "-m", "test(qc): change shared module");
50
+ writeFileSync(path.join(root, "staged.mjs"), "export {};\n");
51
+ git(root, "add", "staged.mjs");
52
+ const run = e2e(root);
53
+ assert.equal(run.status, 0, run.stderr);
54
+ assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"), "utf8")), ["committed.mjs", "staged.mjs"]);
55
+ });
56
+
57
+ test("a failing e2e command streams output and preserves its exit code", (t) => {
58
+ const root = fixture(t, { e2e: node('console.log("e2e output"); console.error("e2e error"); process.exit(7)') });
59
+ writeFileSync(path.join(root, "changed.mjs"), "export {};\n");
60
+ git(root, "add", "changed.mjs");
61
+ const run = e2e(root);
62
+ assert.equal(run.status, 7, run.stderr);
63
+ assert.match(run.stdout, /e2e output/);
64
+ assert.match(run.stderr, /e2e error/);
65
+ });
66
+
67
+ test("e2e skips an empty diff without running the command", (t) => {
68
+ const root = fixture(t, { e2e: record });
69
+ const run = e2e(root);
70
+ assert.equal(run.status, 0, run.stderr);
71
+ assert.match(run.stdout, /SKIP no changed file/);
72
+ assert.equal(existsSync(path.join(root, "args.json")), false);
73
+ });
@@ -0,0 +1,180 @@
1
+ // A static fleet shares node settings across PCs; only the local self id differs.
2
+ import { createHash } from "node:crypto";
3
+ import { closeSync, fchmodSync, mkdirSync, openSync, readFileSync, writeFileSync } from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { load } from "../config.mjs";
7
+ import { checkoutRootOf } from "./checkout-root.mjs";
8
+ import { runGh } from "./gh-run.mjs";
9
+ import { gitOut, originOf } from "./git-read.mjs";
10
+
11
+ const SIZES = ["S", "M", "L"];
12
+ const USAGE = "usage: qc fleet init --self <id> --nodes <id:weight:size,...> [--force] | next [--repo <o/r>] [--all] | status [--repo <o/r>]";
13
+
14
+ /** The fleet settings live on this PC, outside the repository. */
15
+ export function fleetPath(env = process.env, platform = process.platform, home = os.homedir()) {
16
+ if (env.QC_FLEET_FILE) return env.QC_FLEET_FILE;
17
+ const base = platform === "win32" && env.APPDATA ? env.APPDATA : env.XDG_CONFIG_HOME || path.join(home, ".config");
18
+ return path.join(base, "qc", "fleet.json");
19
+ }
20
+
21
+ /** Return validated settings with defaults, naming the field for each error. */
22
+ export function validateFleet(value) {
23
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("fleet must be an object");
24
+ if (!Array.isArray(value.nodes)) throw new Error("nodes must be an array");
25
+ const seen = new Set();
26
+ const nodes = value.nodes.map((node, index) => {
27
+ const field = `nodes[${index}]`;
28
+ if (!node || typeof node !== "object" || Array.isArray(node)) throw new Error(`${field} must be an object`);
29
+ if (typeof node.id !== "string" || !/^[a-z0-9-]{1,32}$/.test(node.id)) throw new Error(`${field}.id must match ^[a-z0-9-]{1,32}$`);
30
+ if (seen.has(node.id)) throw new Error(`${field}.id is duplicated: ${node.id}`);
31
+ seen.add(node.id);
32
+ if (!Number.isFinite(node.weight) || node.weight <= 0 || node.weight > 100) throw new Error(`${field}.weight must be a number above 0 and at most 100`);
33
+ const maxSize = node.maxSize === undefined ? "L" : node.maxSize;
34
+ if (!SIZES.includes(maxSize)) throw new Error(`${field}.maxSize must be S, M or L`);
35
+ const active = node.active === undefined ? true : node.active;
36
+ if (typeof active !== "boolean") throw new Error(`${field}.active must be a boolean`);
37
+ return { id: node.id, weight: node.weight, maxSize, active };
38
+ });
39
+ if (typeof value.self !== "string" || !seen.has(value.self)) throw new Error("self must name a node");
40
+ return { self: value.self, nodes };
41
+ }
42
+
43
+ /** Weighted rendezvous hashing keeps other owners stable when a PC goes inactive. */
44
+ export function ownerOf(repo, number, size, nodes) {
45
+ let owner = null;
46
+ let highest = -Infinity;
47
+ for (const node of nodes) {
48
+ if (node.active === false || SIZES.indexOf(node.maxSize ?? "L") < SIZES.indexOf(size)) continue;
49
+ const hash = createHash("sha256").update(`${repo.toLowerCase()}#${number}:${node.id}`).digest().readBigUInt64BE();
50
+ // Keep u below one even when the integer rounds up during conversion to a double.
51
+ const u = Math.min(1 - Number.EPSILON / 2, Number(hash + 1n) / Number(2n ** 64n + 2n));
52
+ const score = -node.weight / Math.log(u);
53
+ if (score > highest || (score === highest && node.id < owner)) {
54
+ highest = score;
55
+ owner = node.id;
56
+ }
57
+ }
58
+ return owner;
59
+ }
60
+
61
+ function readList(gh, args, cwd, valid) {
62
+ const text = gh(args, { cwd });
63
+ let list;
64
+ try { list = JSON.parse(text); } catch { /* The error below names the failed read. */ }
65
+ if (!Array.isArray(list) || !list.every(valid)) throw new Error(`gh ${args[0]} list returned no readable list`);
66
+ return list;
67
+ }
68
+
69
+ /** Read free open issues and count those already taken by a PR or an origin branch. */
70
+ export function freeIssues(repo, cwd, { gh = runGh, git = gitOut, holdLabel = "hold", remote = "origin" } = {}) {
71
+ const issues = readList(gh, ["issue", "list", "--state", "open", "--limit", "500", "--json", "number,labels,createdAt", "--repo", repo], cwd,
72
+ row => Number.isSafeInteger(row?.number) && row.number > 0 && Array.isArray(row.labels) && row.labels.every(label => typeof label?.name === "string") && Number.isFinite(Date.parse(row.createdAt)));
73
+ const prs = readList(gh, ["pr", "list", "--state", "open", "--limit", "200", "--json", "number,headRefName,body", "--repo", repo], cwd,
74
+ row => Number.isSafeInteger(row?.number) && typeof row.headRefName === "string" && typeof row.body === "string");
75
+ const branches = git(cwd, "ls-remote", "--heads", remote);
76
+ if (branches === null) throw new Error(`git ls-remote --heads ${remote} failed`);
77
+ const taken = new Set();
78
+ const takeBranch = branch => {
79
+ const match = /^[^/]+\/([0-9]+)-/.exec(branch);
80
+ if (match) taken.add(Number(match[1]));
81
+ };
82
+ for (const pr of prs) {
83
+ takeBranch(pr.headRefName);
84
+ for (const match of pr.body.matchAll(/(?<![\w#])#([0-9]+)(?!\w)/g)) taken.add(Number(match[1]));
85
+ }
86
+ for (const line of branches.split(/\r?\n/)) {
87
+ const match = /^\S+\s+refs\/heads\/(.+)$/.exec(line);
88
+ if (match) takeBranch(match[1]);
89
+ }
90
+ const skip = new Set(["hold", holdLabel.toLowerCase(), "fleet-skip"]);
91
+ const eligible = issues.filter(row => !row.labels.some(label => skip.has(label.name.toLowerCase())));
92
+ const free = eligible.filter(row => !taken.has(row.number)).map(row => ({
93
+ ...row,
94
+ size: row.labels.map(label => /^size:([SML])$/i.exec(label.name)?.[1].toUpperCase()).find(Boolean) ?? "M",
95
+ })).sort((a, b) => Date.parse(a.createdAt) - Date.parse(b.createdAt) || a.number - b.number);
96
+ return { free, taken: eligible.filter(row => taken.has(row.number)).length };
97
+ }
98
+
99
+ function parseArgs(argv) {
100
+ const [verb, ...rest] = argv;
101
+ const allowed = verb === "init" ? ["--self", "--nodes", "--force"] : verb === "next" ? ["--repo", "--all"] : verb === "status" ? ["--repo"] : [];
102
+ if (!allowed.length) throw new Error(USAGE);
103
+ const options = { verb };
104
+ for (let i = 0; i < rest.length; i++) {
105
+ const flag = rest[i];
106
+ if (!allowed.includes(flag)) throw new Error(`unknown argument ${flag}`);
107
+ if (Object.hasOwn(options, flag)) throw new Error(`duplicate argument ${flag}`);
108
+ if (flag === "--force" || flag === "--all") options[flag] = true;
109
+ else {
110
+ if (!rest[i + 1] || rest[i + 1].startsWith("--")) throw new Error(`${flag} needs a value`);
111
+ options[flag] = rest[++i];
112
+ }
113
+ }
114
+ if (options["--repo"] && !/^[a-z0-9][a-z0-9-]*\/[a-z0-9_.-]+$/i.test(options["--repo"])) throw new Error("--repo needs owner/repository");
115
+ return options;
116
+ }
117
+
118
+ function initialize(options, file, say) {
119
+ if (!options["--self"] || !options["--nodes"]) throw new Error("init needs --self and --nodes");
120
+ const nodes = options["--nodes"].split(",").map(entry => {
121
+ const [id, weight, maxSize, ...extra] = entry.split(":");
122
+ if (extra.length) throw new Error("--nodes needs id:weight:size entries");
123
+ return { id, weight: Number(weight), maxSize };
124
+ });
125
+ const fleet = validateFleet({ self: options["--self"], nodes });
126
+ mkdirSync(path.dirname(file), { recursive: true });
127
+ let fd;
128
+ try {
129
+ fd = openSync(file, options["--force"] ? "w" : "wx", 0o600);
130
+ if (process.platform !== "win32") fchmodSync(fd, 0o600);
131
+ writeFileSync(fd, `${JSON.stringify(fleet, null, 2)}\n`);
132
+ } catch (error) {
133
+ if (error.code === "EEXIST") throw new Error(`fleet file exists: ${file}; use --force`);
134
+ throw error;
135
+ } finally {
136
+ if (fd !== undefined) closeSync(fd);
137
+ }
138
+ say(`fleet initialized: ${file}`);
139
+ return 0;
140
+ }
141
+
142
+ /** The three fleet verbs return exit codes; injected readers keep tests off the network. */
143
+ export function runFleet(argv, { cwd = process.cwd(), env = process.env, gh = runGh, git, origin = originOf, say = console.log, warn = console.error } = {}) {
144
+ try {
145
+ const options = parseArgs(argv);
146
+ const file = fleetPath(env);
147
+ if (options.verb === "init") return initialize(options, file, say);
148
+ let text;
149
+ try { text = readFileSync(file, "utf8"); } catch (error) {
150
+ if (error.code === "ENOENT") throw new Error(`fleet is off: no ${file}`);
151
+ throw error;
152
+ }
153
+ let value;
154
+ try { value = JSON.parse(text); } catch { throw new Error(`fleet file has invalid JSON: ${file}`); }
155
+ const fleet = validateFleet(value);
156
+ const localRepo = origin(cwd);
157
+ const repo = (options["--repo"] ?? localRepo)?.toLowerCase();
158
+ if (!repo) throw new Error("--repo is required when origin has no repository");
159
+ const remote = localRepo?.toLowerCase() === repo ? "origin" : `https://github.com/${repo}.git`;
160
+ const config = load(checkoutRootOf(cwd) ?? cwd);
161
+ const { free, taken } = freeIssues(repo, cwd, { gh, git, remote, holdLabel: config.merge.holdLabel });
162
+ const owned = free.map(row => ({ ...row, owner: ownerOf(repo, row.number, row.size, fleet.nodes) }));
163
+ if (options.verb === "next") {
164
+ const mine = owned.filter(row => row.owner === fleet.self);
165
+ if (!mine.length) { warn(`no free issue for ${fleet.self}`); return 3; }
166
+ for (const row of options["--all"] ? mine : mine.slice(0, 5)) say(String(row.number));
167
+ return 0;
168
+ }
169
+ for (const node of fleet.nodes.slice(0, 14)) {
170
+ const rows = owned.filter(row => row.owner === node.id);
171
+ say(`${node.id} weight=${node.weight} maxSize=${node.maxSize} active=${node.active} free=${rows.length} ${rows.slice(0, 10).map(row => row.number).join(",")}`.trimEnd());
172
+ }
173
+ const omitted = fleet.nodes.length > 14 ? `; ${fleet.nodes.length - 14} more nodes` : "";
174
+ say(`taken=${taken} unassigned=${owned.filter(row => row.owner === null).length}${omitted}`);
175
+ return 0;
176
+ } catch (error) {
177
+ warn(error.message);
178
+ return 1;
179
+ }
180
+ }