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
@@ -18,6 +18,7 @@ import { existsSync, realpathSync } from "node:fs";
18
18
  import path from "node:path";
19
19
  import { fileURLToPath } from "node:url";
20
20
  import { promisify } from "node:util";
21
+ import { MILESTONE_PATTERN } from "./milestone.mjs";
21
22
  import { load } from "../config.mjs";
22
23
  import { globMatcher, globToRegExp } from "../glob.mjs";
23
24
  import { ignoredPaths } from "./ignored-paths.mjs";
@@ -213,7 +214,7 @@ async function warnOnBranchMismatch(root, manifest) {
213
214
  /** The pre-commit git hook's own check — refuses the commit itself, not just an edit. */
214
215
  /** @returns why a branch name breaks `branches.pattern`, or null. A detached HEAD and an allowed branch pass. */
215
216
  export function branchNameRefusal(branch, { pattern, allow = [] }) {
216
- if (!branch || !pattern || globMatcher(allow)(branch) || new RegExp(pattern).test(branch)) return null;
217
+ if (!branch || !pattern || MILESTONE_PATTERN.test(branch) || globMatcher(allow)(branch) || (!branch.startsWith("milestone/") && new RegExp(pattern).test(branch))) return null;
217
218
  return (
218
219
  `Branch "${branch}" names no issue: it must match branches.pattern ${pattern}, as in feat/340-roles. ` +
219
220
  "Open the issue first, then rename the branch: git branch -m <type>/<issue>-<slug>."
@@ -49,14 +49,13 @@ test("every hook script in src/cli is registered, in hooks.json or in a shell ho
49
49
  assert.deepEqual(unregistered, [], "each hook entry point must be registered, or it never runs");
50
50
  });
51
51
 
52
- test("each workflow script is silent in a checkout without swarm.dispatch", (t) => {
52
+ test("workflow scripts stay silent without swarm.dispatch, and the merge guard denies an unreadable base", (t) => {
53
53
  const base = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-workflow-hooks-")));
54
- t.after(() => rmSync(base, { recursive: true, force: true }));
54
+ t.after(() => rmSync(base, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 }));
55
55
  execFileSync("git", ["init", "-q"], { cwd: base, stdio: "pipe" });
56
- writeFileSync(path.join(base, "qc.config.json"), JSON.stringify({ swarm: {} }));
56
+ writeFileSync(path.join(base, "qc.config.json"), JSON.stringify({ swarm: {}, commentWatch: false }));
57
57
  const events = {
58
58
  "controller-guard.mjs": { hook_event_name: "PreToolUse", tool_name: "Write", tool_input: { file_path: path.join(base, "src", "a.ts") } },
59
- "merge-guard.mjs": { hook_event_name: "PreToolUse", tool_name: "Bash", tool_input: { command: "gh pr merge 1" } },
60
59
  "report-stop.mjs": { hook_event_name: "SubagentStop", agent_id: "a", agent_type: "sdd-reviewer", last_assistant_message: "x" },
61
60
  "plan-stop.mjs": { hook_event_name: "SubagentStop", agent_id: "a", agent_type: "sdd-planner", last_assistant_message: "x" },
62
61
  "issue-gate.mjs": { hook_event_name: "Stop" },
@@ -70,6 +69,21 @@ test("each workflow script is silent in a checkout without swarm.dispatch", (t)
70
69
  assert.equal(result.status, 0, `${script}: ${result.stderr}`);
71
70
  assert.equal(result.stdout, "", script);
72
71
  }
72
+ const callerEnv = { ...process.env, GH_REPO: "inherited/project", GH_HOST: "inherited.invalid" };
73
+ const childEnv = { ...callerEnv, TEMP: base, TMP: base, TMPDIR: base };
74
+ delete childEnv.GH_REPO;
75
+ delete childEnv.GH_HOST;
76
+ assert.equal(childEnv.GH_REPO, undefined);
77
+ assert.equal(childEnv.GH_HOST, undefined);
78
+ const merge = spawnSync(process.execPath, [path.join(CLI, "merge-guard.mjs")], {
79
+ input: JSON.stringify({ session_id: "s", cwd: base, hook_event_name: "PreToolUse", tool_name: "Bash", tool_input: { command: "gh pr merge 1" } }),
80
+ env: childEnv,
81
+ encoding: "utf8",
82
+ });
83
+ assert.equal(merge.status, 0, merge.stderr);
84
+ const output = JSON.parse(merge.stdout).hookSpecificOutput;
85
+ assert.equal(output.permissionDecision, "deny");
86
+ assert.match(output.permissionDecisionReason, /gh cannot read the base branch of the PR/);
73
87
  });
74
88
 
75
89
  test("hooks.json runs the skill guard on the Skill tool, and gives the dispatch guard time for its git and gh reads", () => {
@@ -3,18 +3,19 @@
3
3
 
4
4
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import path from "node:path";
6
- import { CONFIG_FILE, load, merge, reviewDefaults } from "../config.mjs";
6
+ import { CONFIG_FILE, defaults, load, merge, promotionDefaults, reviewDefaults } from "../config.mjs";
7
7
  import { checkoutRootOf } from "./checkout-root.mjs";
8
- import { directSettings } from "./direct-lane.mjs";
8
+ import { configAtBase, directSettings } from "./direct-lane.mjs";
9
9
  import { dispatchSettings } from "./dispatch.mjs";
10
10
  import { fileSafe } from "./edit-batch-state.mjs";
11
11
  import { ledgerFileOf } from "./ledger.mjs";
12
+ import { promotionBranchName } from "./promotion-branch.mjs";
12
13
 
13
14
  const KEY = "swarm.review";
14
15
  const MERGE_KINDS = ["branch", "task"];
15
16
  const SWITCH_KEYS = ["oneBranchReview", "requireGreen", "requireBase", "productDecisions"];
16
17
  const LIMIT_KEYS = ["roundFindings", "roundFiles"];
17
- const REVIEW_KEYS = ["merge", "maxTaskCalls", "controllerPaths", "reviewerTypes", "plannerTypes", "codeReviewSkills", ...SWITCH_KEYS, ...LIMIT_KEYS];
18
+ const REVIEW_KEYS = ["runtime", "merge", "maxTaskCalls", "riskPaths", "cases", "controllerPaths", "reviewerTypes", "plannerTypes", "codeReviewSkills", "promotion", ...SWITCH_KEYS, ...LIMIT_KEYS];
18
19
  const STATE_FILE = "state.json";
19
20
 
20
21
  const isNameList = (value) => Array.isArray(value) && value.every((name) => typeof name === "string" && name !== "");
@@ -31,30 +32,63 @@ export function reviewSettings(swarm = {}) {
31
32
  const unknown = Object.keys(raw).find((key) => !REVIEW_KEYS.includes(key));
32
33
  if (unknown !== undefined) throw new Error(`${KEY}.${unknown} in qc.config.json is not a review setting; the keys are ${REVIEW_KEYS.join(", ")}`);
33
34
  const merged = merge(reviewDefaults, raw);
35
+ if (!["claude", "codex"].includes(merged.runtime)) throw wrong("runtime", merged.runtime, "claude or codex");
36
+ let promotion = merged.promotion;
37
+ if (promotion !== null) {
38
+ if (typeof promotion !== "object" || Array.isArray(promotion)) throw wrong("promotion", promotion, "an object or null");
39
+ const unknown = Object.keys(promotion).find((key) => !["integration", "release", "surfaces"].includes(key));
40
+ if (unknown !== undefined) throw wrong(`promotion.${unknown}`, promotion[unknown], "absent; the keys are integration, release, surfaces");
41
+ promotion = { ...promotionDefaults, ...promotion };
42
+ for (const key of ["integration", "release"]) {
43
+ if (typeof promotion[key] !== "string" || !promotion[key].trim()) throw wrong(`promotion.${key}`, promotion[key], "a non-empty branch name");
44
+ }
45
+ if (promotionBranchName(promotion.integration) === promotionBranchName(promotion.release)) throw wrong("promotion.release", promotion.release, "different from swarm.review.promotion.integration");
46
+ if (!isNameList(promotion.surfaces) || promotion.surfaces.length === 0 || promotion.surfaces.some((glob) => !glob.trim())) {
47
+ throw wrong("promotion.surfaces", promotion.surfaces, "a non-empty list of non-empty globs");
48
+ }
49
+ }
34
50
  const { merge: mergeKind, maxTaskCalls, controllerPaths, reviewerTypes, plannerTypes, codeReviewSkills } = merged;
35
51
  if (!MERGE_KINDS.includes(mergeKind)) throw wrong("merge", mergeKind, `one of ${MERGE_KINDS.join(", ")}`);
36
52
  if (!Number.isInteger(maxTaskCalls) || maxTaskCalls < 1) throw wrong("maxTaskCalls", maxTaskCalls, "a positive whole number");
37
53
  if (!isNameList(controllerPaths)) throw wrong("controllerPaths", controllerPaths, "a list of globs");
54
+ if (!isNameList(merged.riskPaths)) throw wrong("riskPaths", merged.riskPaths, "a list of globs");
55
+ if (merged.cases === null || typeof merged.cases !== "object" || Array.isArray(merged.cases)) throw wrong("cases", merged.cases, "a map of globs to case-word lists");
56
+ for (const [glob, words] of Object.entries(merged.cases)) {
57
+ if (!glob.trim() || !isNameList(words) || words.some((word) => !word.trim())) throw wrong("cases", merged.cases, "a map of non-empty globs to non-empty case words");
58
+ }
38
59
  for (const kind of MERGE_KINDS) {
39
60
  if (!isNameList(reviewerTypes?.[kind])) throw wrong(`reviewerTypes.${kind}`, reviewerTypes?.[kind], "a list of agent types");
40
61
  }
41
62
  if (!isNameList(plannerTypes)) throw wrong("plannerTypes", plannerTypes, "a list of agent types");
42
63
  if (!isNameList(codeReviewSkills)) throw wrong("codeReviewSkills", codeReviewSkills, "a list of skill names");
43
64
  for (const key of SWITCH_KEYS) {
65
+ if (key === "requireGreen") {
66
+ if (![true, false, "not-red"].includes(merged[key])) throw wrong(key, merged[key], 'true, false, or "not-red"');
67
+ continue;
68
+ }
44
69
  if (typeof merged[key] !== "boolean") throw wrong(key, merged[key], "true or false");
45
70
  }
46
71
  for (const key of LIMIT_KEYS) {
47
72
  if (!Number.isInteger(merged[key]) || merged[key] < 0) throw wrong(key, merged[key], "a whole number, 0 or more");
48
73
  }
49
74
  const enforcement = Object.fromEntries([...SWITCH_KEYS, ...LIMIT_KEYS].map((key) => [key, merged[key]]));
50
- return { merge: mergeKind, maxTaskCalls, controllerPaths, reviewerTypes, plannerTypes, codeReviewSkills, ...enforcement, implementerTypes: dispatch.implementerTypes };
75
+ return { runtime: merged.runtime, merge: mergeKind, maxTaskCalls, riskPaths: merged.riskPaths, cases: merged.cases, controllerPaths, reviewerTypes, plannerTypes, codeReviewSkills, promotion, ...enforcement, implementerTypes: dispatch.implementerTypes };
51
76
  }
52
77
 
53
- /** @returns the workflow of the checkout that holds `cwd`, or null when it has no config or the checks are off. */
54
- export function workflowAt(cwd) {
78
+ /** The workflow branch reads the PR base through `git`, or the checkout when `git` is absent; null while dispatch is off. */
79
+ export function workflowAt(cwd, { baseOid, git } = {}) {
55
80
  const root = checkoutRootOf(cwd);
56
- if (!root || !existsSync(path.join(root, CONFIG_FILE))) return null;
57
- const config = load(root);
81
+ if (!root) return null;
82
+ let config;
83
+ if (git) {
84
+ const settings = configAtBase(root, baseOid, git, "the PR base");
85
+ if (settings.problem) throw new Error(settings.problem);
86
+ if (settings.config === null) return null;
87
+ config = merge(defaults, settings.config);
88
+ } else {
89
+ if (!existsSync(path.join(root, CONFIG_FILE))) return null;
90
+ config = load(root);
91
+ }
58
92
  const review = reviewSettings(config.swarm);
59
93
  const ledger = review ? ledgerFileOf(root) : null;
60
94
  if (!review || !ledger) return null;
@@ -63,7 +97,9 @@ export function workflowAt(cwd) {
63
97
  let directProblem = null;
64
98
  try {
65
99
  direct = directSettings(config.swarm);
100
+ if (git && existsSync(path.join(root, CONFIG_FILE)) && !directSettings(load(root).swarm)) direct = null;
66
101
  } catch (error) {
102
+ direct = null;
67
103
  directProblem = error.message;
68
104
  }
69
105
  return {
@@ -10,7 +10,7 @@ import { rememberSession, reviewSettings, sessionDirOf, workflowAt, workflowOf }
10
10
  /** One git checkout per config; `null` writes no config. The last folder is outside any checkout. */
11
11
  function folders(t, configs) {
12
12
  const base = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-workflow-")));
13
- t.after(() => rmSync(base, { recursive: true, force: true }));
13
+ t.after(() => rmSync(base, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
14
14
  const dirs = configs.map((config, index) => {
15
15
  const dir = path.join(base, String(index));
16
16
  mkdirSync(dir);
@@ -32,10 +32,123 @@ test("with swarm.dispatch off, the checks are off", (t) => {
32
32
  for (const dir of dirs) assert.equal(workflowAt(dir), null);
33
33
  });
34
34
 
35
+ test("workflowAt reads the policy at the PR commit even when the checkout has no config", (t) => {
36
+ const { dirs } = folders(t, [null]);
37
+ const baseOid = "a".repeat(40);
38
+ const calls = [];
39
+ const git = (root, ...args) => {
40
+ calls.push({ root, args });
41
+ if (args[0] === "ls-tree") return "100644 blob config\tqc.config.json";
42
+ return args[0] === "show" ? JSON.stringify({ swarm: { dispatch: {}, direct: false } }) : "";
43
+ };
44
+ const workflow = workflowAt(dirs[0], { baseOid, git });
45
+ assert.equal(workflow.review.merge, "branch");
46
+ assert.equal(workflow.direct, null);
47
+ assert.deepEqual(calls.map(({ args }) => args), [["cat-file", "-e", `${baseOid}^{commit}`], ["ls-tree", baseOid, "--", "qc.config.json"], ["show", `${baseOid}:qc.config.json`]]);
48
+ assert.throws(() => workflowAt(dirs[0], { baseOid: "main", git }), /no base commit/);
49
+ assert.equal(calls.length, 3);
50
+ });
51
+
52
+ test("a failed or late config listing keeps the base policy closed", (t) => {
53
+ const { dirs } = folders(t, [{ swarm: { dispatch: {} } }]);
54
+ for (const late of [false, true]) {
55
+ const git = (root, ...args) => args[0] === "ls-tree" && !late ? null : "";
56
+ git.late = () => late;
57
+ assert.throws(() => workflowAt(dirs[0], { baseOid: "a".repeat(40), git }), late ? /ran past.*budget/ : /git cannot read qc\.config\.json/);
58
+ }
59
+ });
60
+
61
+ test("a config content read that finishes late keeps the base policy closed", (t) => {
62
+ const { dirs } = folders(t, [{ swarm: { dispatch: {} } }]);
63
+ let late = false;
64
+ const git = (root, ...args) => {
65
+ if (args[0] === "ls-tree") return "100644 blob config\tqc.config.json";
66
+ if (args[0] === "show") {
67
+ late = true;
68
+ return JSON.stringify({ swarm: {} });
69
+ }
70
+ return "";
71
+ };
72
+ git.late = () => late;
73
+ assert.throws(() => workflowAt(dirs[0], { baseOid: "a".repeat(40), git }), /ran past.*budget/);
74
+ });
75
+
76
+ test("the checkout can close the direct lane while the PR base keeps its review policy", (t) => {
77
+ const { dirs } = folders(t, [{ swarm: { direct: false } }, { swarm: { direct: { maxLines: 0 } } }]);
78
+ const git = (root, ...args) => args[0] === "show" ? JSON.stringify({ swarm: { dispatch: {} } }) : args[0] === "ls-tree" ? "100644 blob config\tqc.config.json" : "";
79
+ for (const dir of dirs) {
80
+ const workflow = workflowAt(dir, { baseOid: "a".repeat(40), git });
81
+ assert.equal(workflow.review.merge, "branch");
82
+ assert.equal(workflow.direct, null);
83
+ }
84
+ });
85
+
35
86
  test("an empty dispatch section takes every review default", () => {
36
87
  assert.deepEqual(reviewSettings({ dispatch: {} }), { ...reviewDefaults, implementerTypes: dispatchDefaults.implementerTypes });
37
88
  });
38
89
 
90
+ test("requireGreen accepts booleans and not-red", () => {
91
+ for (const requireGreen of [true, false, "not-red"]) {
92
+ assert.equal(reviewSettings({ dispatch: {}, review: { requireGreen } }).requireGreen, requireGreen);
93
+ }
94
+ });
95
+
96
+ test("requireGreen rejects other strings and names every allowed value", () => {
97
+ for (const requireGreen of ["", "true", "false", "green", "not_red"]) {
98
+ assert.throws(
99
+ () => reviewSettings({ dispatch: {}, review: { requireGreen } }),
100
+ /swarm\.review\.requireGreen.*true, false, or "not-red"/,
101
+ );
102
+ }
103
+ });
104
+
105
+ test("promotion review is off by default", () => {
106
+ assert.equal(reviewSettings({ dispatch: {} }).promotion, null);
107
+ });
108
+
109
+ test("promotion review fills the default surfaces", () => {
110
+ const promotion = { integration: "dev", release: "main" };
111
+ assert.deepEqual(reviewSettings({ dispatch: {}, review: { promotion } }).promotion, {
112
+ ...promotion,
113
+ surfaces: ["infra/**", "**/migrations/**", ".github/workflows/**"],
114
+ });
115
+ });
116
+
117
+ test("promotion review accepts custom surfaces", () => {
118
+ const promotion = { integration: "dev", release: "main", surfaces: ["deploy/**"] };
119
+ assert.deepEqual(reviewSettings({ dispatch: {}, review: { promotion } }).promotion, promotion);
120
+ });
121
+
122
+ for (const [name, promotion, key] of [
123
+ ["a string", "on", "promotion"],
124
+ ["an array", [], "promotion"],
125
+ ["a boolean", false, "promotion"],
126
+ ["a number", 1, "promotion"],
127
+ ["missing integration", { release: "main" }, "promotion.integration"],
128
+ ["empty integration", { integration: "", release: "main" }, "promotion.integration"],
129
+ ["blank integration", { integration: " ", release: "main" }, "promotion.integration"],
130
+ ["missing release", { integration: "dev" }, "promotion.release"],
131
+ ["empty release", { integration: "dev", release: "" }, "promotion.release"],
132
+ ["blank release", { integration: "dev", release: " " }, "promotion.release"],
133
+ ["equal branches", { integration: "dev", release: "dev" }, "promotion.release"],
134
+ ["equal normalized integration", { integration: "origin/main", release: "main" }, "promotion.release"],
135
+ ["equal normalized release", { integration: "main", release: "origin/main" }, "promotion.release"],
136
+ ["a string for surfaces", { integration: "dev", release: "main", surfaces: "infra/**" }, "promotion.surfaces"],
137
+ ["empty surfaces", { integration: "dev", release: "main", surfaces: [] }, "promotion.surfaces"],
138
+ ["an empty glob", { integration: "dev", release: "main", surfaces: [""] }, "promotion.surfaces"],
139
+ ["a blank glob", { integration: "dev", release: "main", surfaces: [" "] }, "promotion.surfaces"],
140
+ ["a non-string glob", { integration: "dev", release: "main", surfaces: [1] }, "promotion.surfaces"],
141
+ ["an unknown key", { integration: "dev", release: "main", typo: true }, "promotion.typo"],
142
+ ]) {
143
+ test(`promotion review rejects ${name} and names its key`, () => {
144
+ assert.throws(() => reviewSettings({ dispatch: {}, review: { promotion } }), (error) => {
145
+ assert.ok(error.message.startsWith(`swarm.review.${key} in qc.config.json must be `), error.message);
146
+ assert.match(error.message, /, got /);
147
+ return true;
148
+ });
149
+ });
150
+ }
151
+
39
152
  test("a repository overrides one reviewer kind and keeps the other", () => {
40
153
  const settings = reviewSettings({ dispatch: {}, review: { merge: "task", reviewerTypes: { task: ["my-reviewer"] } } });
41
154
  assert.equal(settings.merge, "task");
@@ -101,3 +214,13 @@ test("the enforcement keys default on, and a repository switches each one off",
101
214
  [false, [], false, false, false, 0, 0],
102
215
  );
103
216
  });
217
+
218
+ test("review runtime defaults to Claude and accepts Codex without changing reviewer types", () => {
219
+ assert.equal(reviewSettings({ dispatch: {} }).runtime, "claude");
220
+ const policy = reviewSettings({ dispatch: {}, review: { runtime: "codex" } });
221
+ assert.equal(policy.runtime, "codex");
222
+ assert.deepEqual(policy.reviewerTypes, reviewDefaults.reviewerTypes);
223
+ for (const runtime of [null, "", "other", 1]) {
224
+ assert.throws(() => reviewSettings({ dispatch: {}, review: { runtime } }), /swarm\.review\.runtime/);
225
+ }
226
+ });
@@ -6,6 +6,7 @@ import { appendFileSync, existsSync, mkdirSync, readFileSync, realpathSync } fro
6
6
  import { rm } from "node:fs/promises";
7
7
  import path from "node:path";
8
8
  import { runGh } from "./gh-run.mjs";
9
+ import { pauseRefusal } from "./pause.mjs";
9
10
 
10
11
  export const USAGE = `qc worktree — a linked worktree under .worktree/ in the main checkout
11
12
 
@@ -14,7 +15,9 @@ export const USAGE = `qc worktree — a linked worktree under .worktree/ in the
14
15
 
15
16
  --from the ref a new branch starts at, and the ref remove checks a merge against.
16
17
  The default is worktree.base in qc.config.json. The install is worktree.install.
17
- The folder is worktree.dir. remove also finds a worktree at ../<name>, beside the main checkout.`;
18
+ The folder is worktree.dir. remove also finds a worktree at ../<name>, beside the main checkout.
19
+
20
+ exit 5 remove refused because the operator pause exists or cannot be read.`;
18
21
 
19
22
  /** The install of the package manager whose lockfile `root` holds, or null for a folder with no package.json. */
20
23
  export function installCommand(root) {
@@ -139,6 +142,16 @@ function settleBranch(main, branch, from, gh) {
139
142
  }
140
143
 
141
144
  async function remove(main, targets, from, gh) {
145
+ try {
146
+ const refusal = pauseRefusal(main);
147
+ if (refusal) {
148
+ console.error(refusal);
149
+ return 5;
150
+ }
151
+ } catch (error) {
152
+ console.error(`cannot read the operator pause (${error.message}). Wait for the operator to run \`qc resume\`.`);
153
+ return 5;
154
+ }
142
155
  const listed = worktrees(main);
143
156
  const found = targets.map((target) => listed.find((entry) => keyOf(entry.path) === keyOf(target))).find(Boolean);
144
157
  const target = found?.path ?? targets[0];
@@ -6,7 +6,11 @@ import { tmpdir } from "node:os";
6
6
  import path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { load } from "../config.mjs";
9
- import { installCommand, runWorktree } from "./worktree.mjs";
9
+ import { installCommand, runWorktree, USAGE } from "./worktree.mjs";
10
+
11
+ test("worktree usage lists exit 5 for an operator pause", () => {
12
+ assert.match(USAGE, /exit 5.*pause/);
13
+ });
10
14
 
11
15
  const QC = fileURLToPath(new URL("./qc.mjs", import.meta.url));
12
16
  const git = (cwd, ...args) => execFileSync("git", args, { cwd, stdio: "pipe", encoding: "utf8" }).trim();
@@ -212,6 +216,21 @@ test("remove deletes the remote branch of a merged PR that gh pr merge could not
212
216
  rmSync(top, { recursive: true, force: true });
213
217
  });
214
218
 
219
+ test("a pause refuses worktree removal before deleting a remote branch", async (t) => {
220
+ const { top, main } = fixture();
221
+ t.after(() => rmSync(top, { recursive: true, force: true }));
222
+ const { tip, where } = squashed(main, "wt-paused", "feat/paused");
223
+ mkdirSync(path.join(main, ".git", "qc"), { recursive: true });
224
+ writeFileSync(path.join(main, ".git", "qc", "pause"), "operator investigation\n");
225
+ const messages = [];
226
+ t.mock.method(console, "error", (line) => messages.push(line));
227
+ assert.equal(await removeIn(main, "wt-paused", fakeGh([{ number: 7, headRefOid: tip }]).gh), 5);
228
+ assert.deepEqual(messages, ["An operator paused the kit: operator investigation. Wait for the operator to run `qc resume`."]);
229
+ assert.match(git(main, "ls-remote", "--heads", "origin", "feat/paused"), new RegExp(`^${tip}\\s`));
230
+ assert.ok(existsSync(where));
231
+ assert.equal(git(main, "rev-parse", "feat/paused"), tip);
232
+ });
233
+
215
234
  test("remove keeps a branch with unpushed commits when no merged PR has it as its head", async () => {
216
235
  const { top, main } = fixture();
217
236
  const where = added(main, "wt-k", "feat/k");