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,73 @@
1
+ import { strict as assert } from "node:assert";
2
+ import { test } from "node:test";
3
+ import { findSecrets } from "./secret-patterns.mjs";
4
+ import { redactOutput } from "./output-redaction.mjs";
5
+
6
+ const samples = [
7
+ ["aws-access-key", `AKIA${"A".repeat(16)}`],
8
+ ["aws-access-key", `ASIA${"B".repeat(16)}`],
9
+ ["aws-secret-key", `AWS_SECRET_ACCESS_KEY=${"a".repeat(40)}`],
10
+ ...[
11
+ ["TF_VAR_aws_secret_access_key=", "TF_VAR_[REDACTED]"],
12
+ ["PROD_AWS_SECRET_ACCESS_KEY=", "PROD_[REDACTED]"],
13
+ ["aws configure set aws_secret_access_key ", "aws configure set [REDACTED]"],
14
+ ['"aws_secret_access_key" => "', '"[REDACTED]'],
15
+ ].map(([prefix, redacted]) => ["aws-secret-key", `${prefix}wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY`, redacted]),
16
+ ...["p", "o", "u", "s", "r"].map((kind) => ["github-token", `gh${kind}_${"a".repeat(36)}`]),
17
+ ["github-pat", `github_pat_${"a".repeat(40)}`],
18
+ ["private-key", "-----BEGIN RSA PRIVATE KEY-----"], // qc-allow-secret
19
+ ["private-key", "-----BEGIN PRIVATE KEY-----"], // qc-allow-secret
20
+ ["anthropic-key", `sk-ant-${"a".repeat(20)}`],
21
+ ...["a", "b", "p", "r", "s"].map((kind) => ["slack-token", `xox${kind}-${"a".repeat(10)}`]),
22
+ ["npm-token", `npm_${"a".repeat(36)}`],
23
+ ];
24
+
25
+ for (const [rule, sample, redacted = "[REDACTED]"] of samples) {
26
+ test(`detects ${rule}: ${sample.slice(0, 8)}`, () => {
27
+ assert.ok(findSecrets(`token=${sample}`).includes(rule));
28
+ assert.deepEqual(findSecrets(`token=${sample} # qc-allow-secret`), []);
29
+ assert.equal(redactOutput(sample), redacted, rule);
30
+ const complete = rule === "private-key" ? `${sample}\nmaterial\n${sample.replace("BEGIN", "END")}` : sample;
31
+ assert.equal(redactOutput(`${complete}\n${complete} qc-allow-secret`), `${redacted}\n${redacted} qc-allow-secret`, rule);
32
+ });
33
+ }
34
+
35
+ test("ordinary text and short token prefixes pass", () => {
36
+ assert.deepEqual(findSecrets("const token = 'ghp_short'; // AWS_ACCESS_KEY_ID"), []);
37
+ });
38
+
39
+ test("AWS operator assignments cover the review probes and compact values", () => {
40
+ const value = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
41
+ for (const separator of [":=", "?=", "+=", "!=", "-->", "=:=", "<-"]) {
42
+ for (const spacing of ["", " ", "\t"]) {
43
+ const line = `aws_secret_access_key${spacing}${separator}${spacing}${value}`;
44
+ assert.deepEqual(findSecrets(line), ["aws-secret-key"], line);
45
+ assert.deepEqual(findSecrets(`${line} # qc-allow-secret`), []);
46
+ assert.equal(redactOutput(line), "[REDACTED]");
47
+ }
48
+ }
49
+ });
50
+
51
+ test("AWS names and workflow references pass without a literal 40-character value", () => {
52
+ for (const line of [
53
+ "AWS_SECRET_ACCESS_KEY",
54
+ 'AWS_SECRET_ACCESS_KEY: "aws-secret"',
55
+ 'aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}',
56
+ 'AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}',
57
+ `AWS_SECRET_ACCESS_KEY=${"a".repeat(39)}`,
58
+ `AWS_SECRET_ACCESS_KEY=${"a".repeat(41)}`,
59
+ ]) assert.deepEqual(findSecrets(line), [], line);
60
+ });
61
+
62
+ test("AWS literal assignments cover the value, quotes, both separators, and case", () => {
63
+ for (const name of ["AWS_SECRET_ACCESS_KEY", "aws_secret_access_key", "aws-secret-access-key"]) {
64
+ for (const separator of ["=", ":", "=>", " ", "\t"]) {
65
+ for (const quote of ["", "'", '"']) {
66
+ const line = `${quote}${name}${quote} ${separator} ${quote}${"aB0/+=".repeat(6)}abcd${quote}`;
67
+ assert.deepEqual(findSecrets(line), ["aws-secret-key"]);
68
+ assert.deepEqual(findSecrets(`${line} # qc-allow-secret`), []);
69
+ assert.ok(!redactOutput(line).includes("aB0/+=".repeat(6) + "abcd"));
70
+ }
71
+ }
72
+ }
73
+ });
@@ -0,0 +1,24 @@
1
+ export const CORE_BEGIN = "<!-- architecture-kit:begin core -->";
2
+ export const CORE_END = "<!-- architecture-kit:end core -->";
3
+
4
+ /** Fragment: replace or append the core block while preserving the surrounding text. */
5
+ export function applyBlock(text, block) {
6
+ const begins = [...text.matchAll(new RegExp(`^[ \t]*${CORE_BEGIN}[ \t]*$`, "gm"))];
7
+ const ends = [...text.matchAll(new RegExp(`^[ \t]*${CORE_END}[ \t]*$`, "gm"))];
8
+ const absent = begins.length === 0 && ends.length === 0;
9
+ if (!absent && (begins.length !== 1 || ends.length !== 1 || begins[0].index >= ends[0].index)) {
10
+ throw new Error(`CLAUDE.md has ${begins.length} begin and ${ends.length} end markers; fix them by hand`);
11
+ }
12
+
13
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
14
+ const body = block.replace(/\r\n?|\n/g, eol).trimEnd();
15
+ const region = `${CORE_BEGIN}${eol}${body}${eol}${CORE_END}`;
16
+ let result;
17
+ if (absent) {
18
+ const prefix = text === "" ? "" : `${text}${text.endsWith("\n") ? "" : eol}${eol}`;
19
+ result = `${prefix}${region}${eol}`;
20
+ } else {
21
+ result = text.slice(0, begins[0].index) + region + text.slice(ends[0].index + ends[0][0].length);
22
+ }
23
+ return { text: result, changed: result !== text };
24
+ }
@@ -0,0 +1,96 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { CORE_BEGIN, CORE_END, applyBlock } from "./setup-block.mjs";
4
+
5
+ test("exports the core marker lines", () => {
6
+ assert.equal(CORE_BEGIN, "<!-- architecture-kit:begin core -->");
7
+ assert.equal(CORE_END, "<!-- architecture-kit:end core -->");
8
+ });
9
+
10
+ test("writes the block into empty text", () => {
11
+ assert.deepEqual(applyBlock("", "body"), {
12
+ text: `${CORE_BEGIN}\nbody\n${CORE_END}\n`,
13
+ changed: true,
14
+ });
15
+ });
16
+
17
+ test("appends the block after a blank line", () => {
18
+ assert.deepEqual(applyBlock("mine\n", "body"), {
19
+ text: `mine\n\n${CORE_BEGIN}\nbody\n${CORE_END}\n`,
20
+ changed: true,
21
+ });
22
+ });
23
+
24
+ test("adds the missing final newline before the blank line", () => {
25
+ assert.equal(applyBlock("mine", "body").text,
26
+ `mine\n\n${CORE_BEGIN}\nbody\n${CORE_END}\n`);
27
+ });
28
+
29
+ test("replaces the block and preserves every character outside the marker lines", () => {
30
+ const before = " mine \t\n\n";
31
+ const after = "\n\tmy footer \n\n";
32
+ const text = `${before}${CORE_BEGIN}\nold body\n${CORE_END}${after}`;
33
+ assert.deepEqual(applyBlock(text, "new body"), {
34
+ text: `${before}${CORE_BEGIN}\nnew body\n${CORE_END}${after}`,
35
+ changed: true,
36
+ });
37
+ });
38
+
39
+ test("leaves the second call unchanged", () => {
40
+ const first = applyBlock("mine\n", "body");
41
+ assert.deepEqual(applyBlock(first.text, "body"), {
42
+ text: first.text,
43
+ changed: false,
44
+ });
45
+ });
46
+
47
+ test("uses CRLF inside and around the appended block", () => {
48
+ const result = applyBlock("mine\r\n", "first\nsecond\r\nthird \n\t");
49
+ assert.equal(result.text,
50
+ `mine\r\n\r\n${CORE_BEGIN}\r\nfirst\r\nsecond\r\nthird\r\n${CORE_END}\r\n`);
51
+ assert.equal(result.changed, true);
52
+ assert.doesNotMatch(result.text, /(?<!\r)\n/);
53
+ });
54
+
55
+ test("replaces CRLF marker lines and preserves the surrounding text", () => {
56
+ const before = "mine \t\r\n";
57
+ const after = "\r\nfooter ";
58
+ const result = applyBlock(`${before}${CORE_BEGIN}\r\nold\r\n${CORE_END}${after}`, "first\nsecond");
59
+ assert.equal(result.text, `${before}${CORE_BEGIN}\r\nfirst\r\nsecond\r\n${CORE_END}${after}`);
60
+ assert.doesNotMatch(result.text, /(?<!\r)\n/);
61
+ });
62
+
63
+ test("ignores markers inside longer lines", () => {
64
+ const text = `see ${CORE_BEGIN} here\nsee ${CORE_END} here\n`;
65
+ assert.equal(applyBlock(text, "body").text,
66
+ `${text}\n${CORE_BEGIN}\nbody\n${CORE_END}\n`);
67
+ });
68
+
69
+ test("accepts horizontal whitespace around whole-line markers", () => {
70
+ const result = applyBlock(`mine\n \t${CORE_BEGIN}\t \nold\n\t${CORE_END} \t\nfooter`, "body");
71
+ assert.equal(result.text, `mine\n${CORE_BEGIN}\nbody\n${CORE_END}\nfooter`);
72
+ });
73
+
74
+ test("keeps an absent final newline after an existing end marker", () => {
75
+ assert.equal(applyBlock(`${CORE_BEGIN}\nold\n${CORE_END}`, "body").text,
76
+ `${CORE_BEGIN}\nbody\n${CORE_END}`);
77
+ });
78
+
79
+ test("normalizes body line endings and trims only trailing whitespace", () => {
80
+ assert.equal(applyBlock("", " first \r\nsecond\rthird \n\t").text,
81
+ `${CORE_BEGIN}\n first \nsecond\nthird\n${CORE_END}\n`);
82
+ });
83
+
84
+ for (const [name, text, begins, ends] of [
85
+ ["a begin without an end", `${CORE_BEGIN}\nbody\n`, 1, 0],
86
+ ["an end without a begin", `${CORE_END}\n`, 0, 1],
87
+ ["two begins", `${CORE_BEGIN}\n${CORE_BEGIN}\n${CORE_END}\n`, 2, 1],
88
+ ["two ends", `${CORE_BEGIN}\n${CORE_END}\n${CORE_END}\n`, 1, 2],
89
+ ["an end above its begin", `${CORE_END}\n${CORE_BEGIN}\n`, 1, 1],
90
+ ]) {
91
+ test(`rejects ${name}`, () => {
92
+ assert.throws(() => applyBlock(text, "body"), {
93
+ message: `CLAUDE.md has ${begins} begin and ${ends} end markers; fix them by hand`,
94
+ });
95
+ });
96
+ }
@@ -0,0 +1,65 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+
5
+ const installSteps = {
6
+ node: "Install node 22 or later",
7
+ pnpm: "Install pnpm 10 (run corepack enable)",
8
+ gh: "Install the GitHub CLI (gh)",
9
+ codex: "Install the Codex CLI",
10
+ };
11
+
12
+ /** Resource: run a tool with a bounded wait and no visible Windows console. */
13
+ export function runTool(tool, args) {
14
+ const options = {
15
+ encoding: "utf8",
16
+ shell: process.platform === "win32",
17
+ windowsHide: true,
18
+ timeout: 15000,
19
+ };
20
+ const { status, stdout } = process.platform === "win32"
21
+ ? spawnSync(`${tool} ${args.join(" ")}`, options)
22
+ : spawnSync(tool, args, options);
23
+ return { status, stdout: stdout ?? "" };
24
+ }
25
+
26
+ /** Pipeline: collect the installed tools and their first version lines. */
27
+ export function checkTools(run = runTool) {
28
+ return Object.keys(installSteps).map((tool) => {
29
+ const { status, stdout } = run(tool, ["--version"]);
30
+ const found = status === 0;
31
+ return { tool, found, version: found ? stdout.split("\n")[0].trim() : null };
32
+ });
33
+ }
34
+
35
+ /** Resource: read an optional configuration file as text. */
36
+ function readOptionalText(path) {
37
+ try {
38
+ return readFileSync(path, "utf8");
39
+ } catch {
40
+ return null;
41
+ }
42
+ }
43
+
44
+ /** Pipeline: list the setup steps that require a person. */
45
+ export function personSteps({ tools, home, codexDir, run = runTool, exists = existsSync, readText = readOptionalText }) {
46
+ const steps = [];
47
+ for (const [tool, step] of Object.entries(installSteps)) {
48
+ const check = tools.find((entry) => entry.tool === tool);
49
+ if (!check?.found || (tool === "node" && Number.parseInt(check.version?.replace(/^v/, ""), 10) < 22)) {
50
+ steps.push(step);
51
+ }
52
+ }
53
+
54
+ if (tools.some(({ tool, found }) => tool === "gh" && found) && run("gh", ["auth", "status"]).status !== 0) {
55
+ steps.push("Run `gh auth login`");
56
+ }
57
+ if (tools.some(({ tool, found }) => tool === "codex" && found) && !exists(join(codexDir, "auth.json"))) {
58
+ steps.push("Run `codex login`");
59
+ }
60
+ const awsConfig = readText(join(home, ".aws", "config"));
61
+ if (awsConfig === null || !/^\s*sso_(session|start_url)\s*=/m.test(awsConfig)) {
62
+ steps.push("Set up the AWS SSO profile: run `aws configure sso`");
63
+ }
64
+ return steps;
65
+ }
@@ -0,0 +1,158 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawnSync } from "node:child_process";
3
+ import { EOL } from "node:os";
4
+ import { join } from "node:path";
5
+ import test from "node:test";
6
+ import { checkTools, personSteps, runTool } from "./setup-checks.mjs";
7
+
8
+ const toolNames = ["node", "pnpm", "gh", "codex"];
9
+ const installSteps = [
10
+ "Install node 22 or later",
11
+ "Install pnpm 10 (run corepack enable)",
12
+ "Install the GitHub CLI (gh)",
13
+ "Install the Codex CLI",
14
+ ];
15
+ const awsStep = "Set up the AWS SSO profile: run `aws configure sso`";
16
+
17
+ /** Fragment: supply a finished machine through fake checks. */
18
+ function machine(overrides = {}) {
19
+ const home = join("test-home");
20
+ const codexDir = join(home, "custom-codex");
21
+ return {
22
+ home,
23
+ codexDir,
24
+ tools: toolNames.map((tool) => ({ tool, found: true, version: "v22.0.0" })),
25
+ run(tool, args) {
26
+ assert.equal(tool, "gh");
27
+ assert.deepEqual(args, ["auth", "status"]);
28
+ return { status: 0, stdout: "" };
29
+ },
30
+ exists(path) {
31
+ assert.equal(path, join(codexDir, "auth.json"));
32
+ return true;
33
+ },
34
+ readText(path) {
35
+ assert.equal(path, join(home, ".aws", "config"));
36
+ return "[profile work]\nsso_session = x\n";
37
+ },
38
+ ...overrides,
39
+ };
40
+ }
41
+
42
+ test("checks tools in order with --version and trims the first stdout line", () => {
43
+ const calls = [];
44
+ const tools = checkTools((tool, args) => {
45
+ calls.push([tool, args]);
46
+ return { status: 0, stdout: " v22.1.0 \nmore" };
47
+ });
48
+ assert.deepEqual(calls, toolNames.map((tool) => [tool, ["--version"]]));
49
+ assert.deepEqual(tools, toolNames.map((tool) => ({ tool, found: true, version: "v22.1.0" })));
50
+ });
51
+
52
+ for (const status of [null, 1, 127]) {
53
+ test(`treats tool status ${status} as missing despite stdout`, () => {
54
+ assert.deepEqual(
55
+ checkTools(() => ({ status, stdout: "v22.1.0\nmore" })),
56
+ toolNames.map((tool) => ({ tool, found: false, version: null })),
57
+ );
58
+ });
59
+ }
60
+
61
+ test("runs a tool and returns its status and stdout", () => {
62
+ assert.deepEqual(runTool("node", ["--version"]), {
63
+ status: 0,
64
+ stdout: `${process.version}${EOL}`,
65
+ });
66
+ });
67
+
68
+ test("tool checks emit no shell argument deprecation warning", () => {
69
+ const source = `import { runTool } from ${JSON.stringify(new URL("./setup-checks.mjs", import.meta.url).href)}; process.exitCode = runTool("node", ["--version"]).status;`;
70
+ const result = spawnSync(process.execPath, ["--throw-deprecation", "--input-type=module", "-e", source], { encoding: "utf8" });
71
+ assert.equal(result.status, 0, result.stderr);
72
+ assert.doesNotMatch(result.stderr, /DEP0190/);
73
+ });
74
+
75
+ test("normalizes missing stdout when a tool cannot start", () => {
76
+ const result = runTool("qc-nonexistent-setup-tool", ["--version"]);
77
+ assert.notEqual(result.status, 0);
78
+ assert.equal(result.stdout, "");
79
+ });
80
+
81
+ test("a finished machine needs no steps and reads only the AWS config", () => {
82
+ assert.deepEqual(personSteps(machine()), []);
83
+ });
84
+
85
+ for (const [index, tool] of toolNames.entries()) {
86
+ test(`a missing ${tool} needs its install step`, () => {
87
+ const options = machine();
88
+ options.tools[index] = { tool, found: false, version: null };
89
+ if (tool === "gh") options.run = () => assert.fail("a missing gh cannot check authentication");
90
+ if (tool === "codex") options.exists = () => assert.fail("a missing codex cannot check auth.json");
91
+ assert.deepEqual(personSteps(options), [installSteps[index]]);
92
+ });
93
+ }
94
+
95
+ test("lists missing tools in order before the AWS step", () => {
96
+ assert.deepEqual(personSteps(machine({
97
+ tools: toolNames.map((tool) => ({ tool, found: false, version: null })),
98
+ run: () => assert.fail("missing tools cannot run"),
99
+ exists: () => assert.fail("missing codex cannot check auth.json"),
100
+ readText: () => null,
101
+ })), [...installSteps, awsStep]);
102
+ });
103
+
104
+ for (const version of ["v20.19.0", "v21.7.3", "21.7.3"]) {
105
+ test(`node ${version} needs node 22 or later`, () => {
106
+ const options = machine();
107
+ options.tools[0].version = version;
108
+ assert.deepEqual(personSteps(options), [installSteps[0]]);
109
+ });
110
+ }
111
+
112
+ test("node newer than 22 needs no install step", () => {
113
+ const options = machine();
114
+ options.tools[0].version = "v24.0.0";
115
+ assert.deepEqual(personSteps(options), []);
116
+ });
117
+
118
+ for (const status of [null, 1]) {
119
+ test(`gh auth status ${status} needs a login`, () => {
120
+ const options = machine();
121
+ const run = options.run;
122
+ options.run = (tool, args) => ({ ...run(tool, args), status });
123
+ assert.deepEqual(personSteps(options), ["Run `gh auth login`"]);
124
+ });
125
+ }
126
+
127
+ test("a missing Codex auth file needs a login without reading credentials", () => {
128
+ const options = machine();
129
+ const exists = options.exists;
130
+ options.exists = (path) => { exists(path); return false; };
131
+ assert.deepEqual(personSteps(options), ["Run `codex login`"]);
132
+ });
133
+
134
+ for (const text of [null, "", "[profile work]\nregion = us-east-1\n",
135
+ "# sso_session = x\n", "prefix_sso_start_url = x\n"]) {
136
+ test(`AWS config ${JSON.stringify(text)} needs SSO setup`, () => {
137
+ assert.deepEqual(personSteps(machine({ readText: () => text })), [awsStep]);
138
+ });
139
+ }
140
+
141
+ for (const text of ["[profile work]\nsso_session = x\n", " sso_start_url = https://example.test/start\n"]) {
142
+ test(`AWS config accepts ${JSON.stringify(text)}`, () => {
143
+ assert.deepEqual(personSteps(machine({ readText: () => text })), []);
144
+ });
145
+ }
146
+
147
+ test("lists install steps, GitHub login, Codex login, and AWS setup in order", () => {
148
+ const options = machine({
149
+ run: () => ({ status: 1, stdout: "" }),
150
+ exists: () => false,
151
+ readText: () => null,
152
+ });
153
+ options.tools[0].version = "v20.0.0";
154
+ options.tools[1] = { tool: "pnpm", found: false, version: null };
155
+ assert.deepEqual(personSteps(options), [
156
+ installSteps[0], installSteps[1], "Run `gh auth login`", "Run `codex login`", awsStep,
157
+ ]);
158
+ });
@@ -0,0 +1,55 @@
1
+ import { mergeCodexConfig } from "./user-config-toml.mjs";
2
+
3
+ /** Fragment: read optional compaction budgets from the project config. */
4
+ export function budgetsOf(configText) {
5
+ let config;
6
+ try {
7
+ config = configText === null ? {} : JSON.parse(configText);
8
+ } catch (cause) {
9
+ throw new Error("qc.config.json must contain valid JSON", { cause });
10
+ }
11
+ const budgets = {};
12
+ for (const agent of ["orchestrator", "codex"]) {
13
+ const value = config?.budgets?.[agent]?.compactAt;
14
+ if (value !== undefined && (!Number.isInteger(value) || value <= 0)) {
15
+ throw new Error(`budgets.${agent}.compactAt must be a positive whole number`);
16
+ }
17
+ budgets[agent] = value ?? null;
18
+ }
19
+ return budgets;
20
+ }
21
+
22
+ /** Fragment: enable Claude compaction and merge the selected model windows. */
23
+ export function compactClaude(configText, { models, window }) {
24
+ let settings;
25
+ try {
26
+ settings = JSON.parse(configText || "{}");
27
+ } catch (cause) {
28
+ throw new Error("Claude settings must be a JSON settings object", { cause });
29
+ }
30
+ if (settings === null || typeof settings !== "object" || Array.isArray(settings)) {
31
+ throw new Error("Claude settings must be a JSON settings object");
32
+ }
33
+
34
+ const changed = [];
35
+ if (settings.autoCompactEnabled !== true) {
36
+ settings.autoCompactEnabled = true;
37
+ changed.push("autoCompactEnabled");
38
+ }
39
+ if (window !== null) {
40
+ for (const name of models) {
41
+ const modelSettings = settings.modelSettings ??= {};
42
+ const model = modelSettings[name] ??= {};
43
+ if (model.autoCompactWindow === window) continue;
44
+ model.autoCompactWindow = window;
45
+ changed.push(`modelSettings.${name}.autoCompactWindow`);
46
+ }
47
+ }
48
+ return { text: changed.length ? JSON.stringify(settings, null, 2) + "\n" : configText, changed };
49
+ }
50
+
51
+ /** Fragment: merge the Codex compaction limit while preserving other TOML settings. */
52
+ export function compactCodex(configText, limit) {
53
+ if (limit === null) return { text: configText, changed: [] };
54
+ return mergeCodexConfig(configText, `model_auto_compact_token_limit = ${limit}\n`);
55
+ }
@@ -0,0 +1,115 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { budgetsOf, compactClaude, compactCodex } from "./setup-compaction.mjs";
4
+
5
+ test("absent budgets leave both compaction limits unset", () => {
6
+ for (const text of [null, "{}"]) {
7
+ assert.deepEqual(budgetsOf(text), { orchestrator: null, codex: null });
8
+ }
9
+ assert.deepEqual(budgetsOf('{"budgets":{"codex":{"compactAt":300000}}}'), {
10
+ orchestrator: null, codex: 300000,
11
+ });
12
+ });
13
+
14
+ test("reads the orchestrator and Codex compaction budgets", () => {
15
+ assert.deepEqual(budgetsOf('{"budgets":{"orchestrator":{"compactAt":200000},"codex":{"compactAt":300000}}}'), {
16
+ orchestrator: 200000, codex: 300000,
17
+ });
18
+ });
19
+
20
+ test("invalid compaction budgets name the key and the required number", () => {
21
+ for (const agent of ["orchestrator", "codex"]) {
22
+ for (const compactAt of [0, 1.5, "x", -1]) {
23
+ const text = JSON.stringify({ budgets: { [agent]: { compactAt } } });
24
+ assert.throws(() => budgetsOf(text), (error) => {
25
+ assert.ok(error.message.includes(`budgets.${agent}.compactAt`));
26
+ assert.match(error.message, /positive whole number/);
27
+ return true;
28
+ });
29
+ }
30
+ }
31
+ });
32
+
33
+ test("invalid budget JSON names qc.config.json", () => {
34
+ assert.throws(() => budgetsOf("not JSON"), /qc\.config\.json/);
35
+ });
36
+
37
+ test("enables Claude compaction in empty settings without a budget", () => {
38
+ for (const text of ["", "{}"]) {
39
+ assert.deepEqual(compactClaude(text, { models: [], window: null }), {
40
+ text: '{\n "autoCompactEnabled": true\n}\n',
41
+ changed: ["autoCompactEnabled"],
42
+ });
43
+ }
44
+ });
45
+
46
+ test("preserves Claude settings text when compaction is already enabled", () => {
47
+ const text = ' { "autoCompactEnabled": true, "theme": "dark" }\r\n';
48
+ assert.deepEqual(compactClaude(text, { models: ["claude-opus-5-5"], window: null }), {
49
+ text, changed: [],
50
+ });
51
+ });
52
+
53
+ test("sets Claude model windows while preserving other settings", () => {
54
+ const settings = {
55
+ autoCompactEnabled: true,
56
+ modelSettings: { "claude-opus-5-5": { effortLevel: "high" } },
57
+ theme: "dark",
58
+ };
59
+ const options = { models: ["claude-opus-5-5"], window: 200000 };
60
+ const result = compactClaude(JSON.stringify(settings), options);
61
+ const expected = {
62
+ ...settings,
63
+ modelSettings: { "claude-opus-5-5": { effortLevel: "high", autoCompactWindow: 200000 } },
64
+ };
65
+ assert.deepEqual(JSON.parse(result.text), expected);
66
+ assert.equal(result.text, JSON.stringify(expected, null, 2) + "\n");
67
+ assert.deepEqual(result.changed, ["modelSettings.claude-opus-5-5.autoCompactWindow"]);
68
+ assert.deepEqual(compactClaude(result.text, options), { text: result.text, changed: [] });
69
+ });
70
+
71
+ test("creates Claude model settings and enables disabled compaction", () => {
72
+ const options = { models: ["claude-opus-5-5", "claude-sonnet-4-6"], window: 200000 };
73
+ const result = compactClaude('{"autoCompactEnabled":false}', options);
74
+ assert.deepEqual(JSON.parse(result.text), {
75
+ autoCompactEnabled: true,
76
+ modelSettings: {
77
+ "claude-opus-5-5": { autoCompactWindow: 200000 },
78
+ "claude-sonnet-4-6": { autoCompactWindow: 200000 },
79
+ },
80
+ });
81
+ assert.deepEqual(result.changed, [
82
+ "autoCompactEnabled",
83
+ "modelSettings.claude-opus-5-5.autoCompactWindow",
84
+ "modelSettings.claude-sonnet-4-6.autoCompactWindow",
85
+ ]);
86
+ });
87
+
88
+ test("rejects Claude settings that are not a JSON object", () => {
89
+ for (const text of ["[]", "not JSON", "null", "true", '"settings"', "1"]) {
90
+ assert.throws(() => compactClaude(text, { models: [], window: null }), /JSON settings object/);
91
+ }
92
+ });
93
+
94
+ test("a missing Codex budget preserves the input", () => {
95
+ const text = 'model = "x"\n# keep\n';
96
+ assert.deepEqual(compactCodex(text, null), { text, changed: [] });
97
+ });
98
+
99
+ test("adds the Codex limit while preserving the model and comments", () => {
100
+ const text = 'model = "x"\n# keep\n';
101
+ const result = compactCodex(text, 300000);
102
+ assert.ok(result.text.includes("model_auto_compact_token_limit = 300000\n"));
103
+ assert.ok(result.text.includes('model = "x"\n'));
104
+ assert.ok(result.text.includes("# keep\n"));
105
+ assert.deepEqual(result.changed, ["model_auto_compact_token_limit"]);
106
+ assert.deepEqual(compactCodex(result.text, 300000), { text: result.text, changed: [] });
107
+ });
108
+
109
+ test("replaces the Codex limit while preserving its comment and other tables", () => {
110
+ const text = 'model_auto_compact_token_limit = 100000 # keep\n[profile]\nmodel = "x"\n';
111
+ const result = compactCodex(text, 300000);
112
+ assert.equal(result.text, text.replace("100000", "300000"));
113
+ assert.deepEqual(result.changed, ["model_auto_compact_token_limit"]);
114
+ assert.deepEqual(compactCodex(result.text, 300000), { text: result.text, changed: [] });
115
+ });
@@ -0,0 +1,65 @@
1
+ import { existsSync, readFileSync, readdirSync, rmSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { GLOBAL_SKILLS } from "../global-skills.mjs";
4
+
5
+ const pluginKey = "architecture@architecture-kit";
6
+
7
+ /** Fragment: read whether Claude enables the architecture plugin. */
8
+ function pluginEnabled(settingsText) {
9
+ try {
10
+ return JSON.parse(settingsText)?.enabledPlugins?.[pluginKey] === true;
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
15
+
16
+ /** Fragment: read installation paths from the optional plugin registry. */
17
+ function pluginInstallPaths(claudeDir) {
18
+ try {
19
+ const registry = JSON.parse(readFileSync(join(claudeDir, "plugins", "installed_plugins.json"), "utf8"));
20
+ const entries = registry?.plugins?.[pluginKey];
21
+ if (!Array.isArray(entries)) return [];
22
+ return entries.map((entry) => entry?.installPath).filter((path) => typeof path === "string");
23
+ } catch {
24
+ return [];
25
+ }
26
+ }
27
+
28
+ /** Pipeline: remove personal skills only after their identical plugin copies load. */
29
+ export function dropPersonalSkills({ claudeDir, settingsText, names = GLOBAL_SKILLS, dryRun = false }) {
30
+ const removed = [];
31
+ const kept = [];
32
+ const enabled = pluginEnabled(settingsText);
33
+ const installPaths = enabled ? pluginInstallPaths(claudeDir) : [];
34
+
35
+ for (const name of names) {
36
+ const folder = join(claudeDir, "skills", name);
37
+ const personalFile = join(folder, "SKILL.md");
38
+ if (!existsSync(personalFile)) continue;
39
+ if (!enabled) {
40
+ kept.push({ name, reason: "the plugin is not enabled" });
41
+ continue;
42
+ }
43
+
44
+ const pluginFile = installPaths
45
+ .map((path) => join(path, "skills", name, "SKILL.md"))
46
+ .find((path) => existsSync(path));
47
+ if (!pluginFile) {
48
+ kept.push({ name, reason: "the plugin copy is not installed" });
49
+ continue;
50
+ }
51
+ if (!readFileSync(personalFile).equals(readFileSync(pluginFile))) {
52
+ kept.push({ name, reason: "it differs from the plugin copy" });
53
+ continue;
54
+ }
55
+ if (readdirSync(folder).some((entry) => entry !== "SKILL.md")) {
56
+ kept.push({ name, reason: "it holds files besides SKILL.md" });
57
+ continue;
58
+ }
59
+
60
+ if (!dryRun) rmSync(folder, { recursive: true });
61
+ removed.push(folder);
62
+ }
63
+
64
+ return { removed, kept };
65
+ }