cclaw-cli 7.7.1 → 8.1.1

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 (284) hide show
  1. package/README.md +211 -134
  2. package/dist/artifact-frontmatter.d.ts +51 -0
  3. package/dist/artifact-frontmatter.js +131 -0
  4. package/dist/artifact-paths.d.ts +7 -27
  5. package/dist/artifact-paths.js +20 -249
  6. package/dist/cancel.d.ts +16 -0
  7. package/dist/cancel.js +66 -0
  8. package/dist/cli.d.ts +2 -27
  9. package/dist/cli.js +107 -511
  10. package/dist/compound.d.ts +26 -0
  11. package/dist/compound.js +96 -0
  12. package/dist/config.d.ts +14 -51
  13. package/dist/config.js +23 -359
  14. package/dist/constants.d.ts +11 -18
  15. package/dist/constants.js +19 -106
  16. package/dist/content/antipatterns.d.ts +1 -0
  17. package/dist/content/antipatterns.js +109 -0
  18. package/dist/content/artifact-templates.d.ts +10 -0
  19. package/dist/content/artifact-templates.js +550 -0
  20. package/dist/content/cancel-command.d.ts +2 -2
  21. package/dist/content/cancel-command.js +25 -17
  22. package/dist/content/core-agents.d.ts +9 -233
  23. package/dist/content/core-agents.js +39 -768
  24. package/dist/content/decision-protocol.d.ts +1 -12
  25. package/dist/content/decision-protocol.js +27 -20
  26. package/dist/content/examples.d.ts +8 -42
  27. package/dist/content/examples.js +293 -425
  28. package/dist/content/idea-command.d.ts +2 -0
  29. package/dist/content/idea-command.js +38 -0
  30. package/dist/content/iron-laws.d.ts +4 -138
  31. package/dist/content/iron-laws.js +18 -197
  32. package/dist/content/meta-skill.d.ts +1 -3
  33. package/dist/content/meta-skill.js +57 -134
  34. package/dist/content/node-hooks.d.ts +12 -8
  35. package/dist/content/node-hooks.js +188 -838
  36. package/dist/content/recovery.d.ts +8 -0
  37. package/dist/content/recovery.js +179 -0
  38. package/dist/content/reference-patterns.d.ts +4 -13
  39. package/dist/content/reference-patterns.js +260 -389
  40. package/dist/content/research-playbooks.d.ts +8 -8
  41. package/dist/content/research-playbooks.js +108 -121
  42. package/dist/content/review-loop.d.ts +6 -192
  43. package/dist/content/review-loop.js +29 -731
  44. package/dist/content/skills.d.ts +8 -38
  45. package/dist/content/skills.js +681 -732
  46. package/dist/content/specialist-prompts/architect.d.ts +1 -0
  47. package/dist/content/specialist-prompts/architect.js +225 -0
  48. package/dist/content/specialist-prompts/brainstormer.d.ts +1 -0
  49. package/dist/content/specialist-prompts/brainstormer.js +168 -0
  50. package/dist/content/specialist-prompts/index.d.ts +2 -0
  51. package/dist/content/specialist-prompts/index.js +14 -0
  52. package/dist/content/specialist-prompts/planner.d.ts +1 -0
  53. package/dist/content/specialist-prompts/planner.js +182 -0
  54. package/dist/content/specialist-prompts/reviewer.d.ts +1 -0
  55. package/dist/content/specialist-prompts/reviewer.js +193 -0
  56. package/dist/content/specialist-prompts/security-reviewer.d.ts +1 -0
  57. package/dist/content/specialist-prompts/security-reviewer.js +133 -0
  58. package/dist/content/specialist-prompts/slice-builder.d.ts +1 -0
  59. package/dist/content/specialist-prompts/slice-builder.js +232 -0
  60. package/dist/content/stage-playbooks.d.ts +8 -0
  61. package/dist/content/stage-playbooks.js +404 -0
  62. package/dist/content/start-command.d.ts +2 -12
  63. package/dist/content/start-command.js +221 -207
  64. package/dist/flow-state.d.ts +21 -178
  65. package/dist/flow-state.js +67 -170
  66. package/dist/fs-utils.d.ts +6 -26
  67. package/dist/fs-utils.js +29 -162
  68. package/dist/gitignore.d.ts +2 -1
  69. package/dist/gitignore.js +51 -34
  70. package/dist/harness-detect.d.ts +10 -0
  71. package/dist/harness-detect.js +29 -0
  72. package/dist/harness-prompt.d.ts +26 -0
  73. package/dist/harness-prompt.js +142 -0
  74. package/dist/install.d.ts +35 -15
  75. package/dist/install.js +238 -1347
  76. package/dist/knowledge-store.d.ts +19 -163
  77. package/dist/knowledge-store.js +56 -590
  78. package/dist/logger.d.ts +8 -3
  79. package/dist/logger.js +13 -4
  80. package/dist/orchestrator-routing.d.ts +29 -0
  81. package/dist/orchestrator-routing.js +156 -0
  82. package/dist/run-persistence.d.ts +7 -118
  83. package/dist/run-persistence.js +29 -845
  84. package/dist/runtime/run-hook.entry.d.ts +1 -3
  85. package/dist/runtime/run-hook.entry.js +19 -4
  86. package/dist/runtime/run-hook.mjs +13 -1024
  87. package/dist/types.d.ts +25 -261
  88. package/dist/types.js +8 -36
  89. package/package.json +6 -3
  90. package/dist/artifact-linter/brainstorm.d.ts +0 -2
  91. package/dist/artifact-linter/brainstorm.js +0 -353
  92. package/dist/artifact-linter/design.d.ts +0 -18
  93. package/dist/artifact-linter/design.js +0 -444
  94. package/dist/artifact-linter/findings-dedup.d.ts +0 -56
  95. package/dist/artifact-linter/findings-dedup.js +0 -232
  96. package/dist/artifact-linter/plan.d.ts +0 -2
  97. package/dist/artifact-linter/plan.js +0 -826
  98. package/dist/artifact-linter/review-army.d.ts +0 -49
  99. package/dist/artifact-linter/review-army.js +0 -520
  100. package/dist/artifact-linter/review.d.ts +0 -2
  101. package/dist/artifact-linter/review.js +0 -113
  102. package/dist/artifact-linter/scope.d.ts +0 -2
  103. package/dist/artifact-linter/scope.js +0 -158
  104. package/dist/artifact-linter/shared.d.ts +0 -637
  105. package/dist/artifact-linter/shared.js +0 -2163
  106. package/dist/artifact-linter/ship.d.ts +0 -2
  107. package/dist/artifact-linter/ship.js +0 -250
  108. package/dist/artifact-linter/spec.d.ts +0 -2
  109. package/dist/artifact-linter/spec.js +0 -176
  110. package/dist/artifact-linter/tdd.d.ts +0 -118
  111. package/dist/artifact-linter/tdd.js +0 -1404
  112. package/dist/artifact-linter.d.ts +0 -15
  113. package/dist/artifact-linter.js +0 -517
  114. package/dist/codex-feature-flag.d.ts +0 -58
  115. package/dist/codex-feature-flag.js +0 -193
  116. package/dist/content/closeout-guidance.d.ts +0 -14
  117. package/dist/content/closeout-guidance.js +0 -44
  118. package/dist/content/diff-command.d.ts +0 -1
  119. package/dist/content/diff-command.js +0 -43
  120. package/dist/content/harness-doc.d.ts +0 -1
  121. package/dist/content/harness-doc.js +0 -65
  122. package/dist/content/hook-events.d.ts +0 -9
  123. package/dist/content/hook-events.js +0 -23
  124. package/dist/content/hook-manifest.d.ts +0 -81
  125. package/dist/content/hook-manifest.js +0 -156
  126. package/dist/content/hooks.d.ts +0 -11
  127. package/dist/content/hooks.js +0 -1972
  128. package/dist/content/idea.d.ts +0 -60
  129. package/dist/content/idea.js +0 -416
  130. package/dist/content/language-policy.d.ts +0 -2
  131. package/dist/content/language-policy.js +0 -13
  132. package/dist/content/learnings.d.ts +0 -6
  133. package/dist/content/learnings.js +0 -141
  134. package/dist/content/observe.d.ts +0 -19
  135. package/dist/content/observe.js +0 -86
  136. package/dist/content/opencode-plugin.d.ts +0 -1
  137. package/dist/content/opencode-plugin.js +0 -635
  138. package/dist/content/review-prompts.d.ts +0 -1
  139. package/dist/content/review-prompts.js +0 -104
  140. package/dist/content/runtime-shared-snippets.d.ts +0 -8
  141. package/dist/content/runtime-shared-snippets.js +0 -80
  142. package/dist/content/session-hooks.d.ts +0 -7
  143. package/dist/content/session-hooks.js +0 -107
  144. package/dist/content/skills-elicitation.d.ts +0 -1
  145. package/dist/content/skills-elicitation.js +0 -167
  146. package/dist/content/stage-command.d.ts +0 -2
  147. package/dist/content/stage-command.js +0 -17
  148. package/dist/content/stage-schema.d.ts +0 -117
  149. package/dist/content/stage-schema.js +0 -955
  150. package/dist/content/stages/_lint-metadata/index.d.ts +0 -2
  151. package/dist/content/stages/_lint-metadata/index.js +0 -97
  152. package/dist/content/stages/brainstorm.d.ts +0 -2
  153. package/dist/content/stages/brainstorm.js +0 -184
  154. package/dist/content/stages/design.d.ts +0 -2
  155. package/dist/content/stages/design.js +0 -288
  156. package/dist/content/stages/index.d.ts +0 -8
  157. package/dist/content/stages/index.js +0 -11
  158. package/dist/content/stages/plan.d.ts +0 -2
  159. package/dist/content/stages/plan.js +0 -191
  160. package/dist/content/stages/review.d.ts +0 -2
  161. package/dist/content/stages/review.js +0 -240
  162. package/dist/content/stages/schema-types.d.ts +0 -203
  163. package/dist/content/stages/schema-types.js +0 -1
  164. package/dist/content/stages/scope.d.ts +0 -2
  165. package/dist/content/stages/scope.js +0 -254
  166. package/dist/content/stages/ship.d.ts +0 -2
  167. package/dist/content/stages/ship.js +0 -159
  168. package/dist/content/stages/spec.d.ts +0 -2
  169. package/dist/content/stages/spec.js +0 -170
  170. package/dist/content/stages/tdd.d.ts +0 -4
  171. package/dist/content/stages/tdd.js +0 -273
  172. package/dist/content/state-contracts.d.ts +0 -1
  173. package/dist/content/state-contracts.js +0 -63
  174. package/dist/content/status-command.d.ts +0 -4
  175. package/dist/content/status-command.js +0 -109
  176. package/dist/content/subagent-context-skills.d.ts +0 -4
  177. package/dist/content/subagent-context-skills.js +0 -279
  178. package/dist/content/subagents.d.ts +0 -3
  179. package/dist/content/subagents.js +0 -997
  180. package/dist/content/templates.d.ts +0 -26
  181. package/dist/content/templates.js +0 -1692
  182. package/dist/content/track-render-context.d.ts +0 -18
  183. package/dist/content/track-render-context.js +0 -53
  184. package/dist/content/tree-command.d.ts +0 -1
  185. package/dist/content/tree-command.js +0 -64
  186. package/dist/content/utility-skills.d.ts +0 -30
  187. package/dist/content/utility-skills.js +0 -160
  188. package/dist/content/view-command.d.ts +0 -2
  189. package/dist/content/view-command.js +0 -92
  190. package/dist/delegation.d.ts +0 -649
  191. package/dist/delegation.js +0 -1539
  192. package/dist/early-loop.d.ts +0 -70
  193. package/dist/early-loop.js +0 -302
  194. package/dist/execution-topology.d.ts +0 -44
  195. package/dist/execution-topology.js +0 -95
  196. package/dist/gate-evidence.d.ts +0 -85
  197. package/dist/gate-evidence.js +0 -631
  198. package/dist/harness-adapters.d.ts +0 -151
  199. package/dist/harness-adapters.js +0 -756
  200. package/dist/harness-selection.d.ts +0 -31
  201. package/dist/harness-selection.js +0 -214
  202. package/dist/hook-schema.d.ts +0 -6
  203. package/dist/hook-schema.js +0 -114
  204. package/dist/hook-schemas/claude-hooks.v1.json +0 -10
  205. package/dist/hook-schemas/codex-hooks.v1.json +0 -10
  206. package/dist/hook-schemas/cursor-hooks.v1.json +0 -13
  207. package/dist/init-detect.d.ts +0 -2
  208. package/dist/init-detect.js +0 -50
  209. package/dist/internal/advance-stage/advance.d.ts +0 -89
  210. package/dist/internal/advance-stage/advance.js +0 -655
  211. package/dist/internal/advance-stage/cancel-run.d.ts +0 -8
  212. package/dist/internal/advance-stage/cancel-run.js +0 -19
  213. package/dist/internal/advance-stage/flow-state-coercion.d.ts +0 -3
  214. package/dist/internal/advance-stage/flow-state-coercion.js +0 -81
  215. package/dist/internal/advance-stage/helpers.d.ts +0 -14
  216. package/dist/internal/advance-stage/helpers.js +0 -145
  217. package/dist/internal/advance-stage/hook.d.ts +0 -8
  218. package/dist/internal/advance-stage/hook.js +0 -40
  219. package/dist/internal/advance-stage/parsers.d.ts +0 -72
  220. package/dist/internal/advance-stage/parsers.js +0 -357
  221. package/dist/internal/advance-stage/proactive-delegation-trace.d.ts +0 -24
  222. package/dist/internal/advance-stage/proactive-delegation-trace.js +0 -56
  223. package/dist/internal/advance-stage/review-loop.d.ts +0 -16
  224. package/dist/internal/advance-stage/review-loop.js +0 -199
  225. package/dist/internal/advance-stage/rewind.d.ts +0 -14
  226. package/dist/internal/advance-stage/rewind.js +0 -108
  227. package/dist/internal/advance-stage/start-flow.d.ts +0 -13
  228. package/dist/internal/advance-stage/start-flow.js +0 -241
  229. package/dist/internal/advance-stage/verify.d.ts +0 -21
  230. package/dist/internal/advance-stage/verify.js +0 -185
  231. package/dist/internal/advance-stage.d.ts +0 -7
  232. package/dist/internal/advance-stage.js +0 -138
  233. package/dist/internal/cohesion-contract-stub.d.ts +0 -24
  234. package/dist/internal/cohesion-contract-stub.js +0 -148
  235. package/dist/internal/compound-readiness.d.ts +0 -23
  236. package/dist/internal/compound-readiness.js +0 -102
  237. package/dist/internal/detect-public-api-changes.d.ts +0 -5
  238. package/dist/internal/detect-public-api-changes.js +0 -45
  239. package/dist/internal/detect-supply-chain-changes.d.ts +0 -6
  240. package/dist/internal/detect-supply-chain-changes.js +0 -138
  241. package/dist/internal/early-loop-status.d.ts +0 -7
  242. package/dist/internal/early-loop-status.js +0 -93
  243. package/dist/internal/envelope-validate.d.ts +0 -7
  244. package/dist/internal/envelope-validate.js +0 -66
  245. package/dist/internal/flow-state-repair.d.ts +0 -20
  246. package/dist/internal/flow-state-repair.js +0 -104
  247. package/dist/internal/plan-split-waves.d.ts +0 -190
  248. package/dist/internal/plan-split-waves.js +0 -764
  249. package/dist/internal/runtime-integrity.d.ts +0 -7
  250. package/dist/internal/runtime-integrity.js +0 -268
  251. package/dist/internal/slice-commit.d.ts +0 -7
  252. package/dist/internal/slice-commit.js +0 -619
  253. package/dist/internal/tdd-loop-status.d.ts +0 -14
  254. package/dist/internal/tdd-loop-status.js +0 -68
  255. package/dist/internal/tdd-red-evidence.d.ts +0 -7
  256. package/dist/internal/tdd-red-evidence.js +0 -153
  257. package/dist/internal/waiver-grant.d.ts +0 -62
  258. package/dist/internal/waiver-grant.js +0 -294
  259. package/dist/internal/wave-status.d.ts +0 -74
  260. package/dist/internal/wave-status.js +0 -506
  261. package/dist/managed-resources.d.ts +0 -53
  262. package/dist/managed-resources.js +0 -313
  263. package/dist/policy.d.ts +0 -10
  264. package/dist/policy.js +0 -167
  265. package/dist/retro-gate.d.ts +0 -9
  266. package/dist/retro-gate.js +0 -47
  267. package/dist/run-archive.d.ts +0 -61
  268. package/dist/run-archive.js +0 -391
  269. package/dist/runs.d.ts +0 -2
  270. package/dist/runs.js +0 -2
  271. package/dist/stack-detection.d.ts +0 -116
  272. package/dist/stack-detection.js +0 -489
  273. package/dist/streaming/event-stream.d.ts +0 -31
  274. package/dist/streaming/event-stream.js +0 -114
  275. package/dist/tdd-cycle.d.ts +0 -107
  276. package/dist/tdd-cycle.js +0 -289
  277. package/dist/tdd-verification-evidence.d.ts +0 -17
  278. package/dist/tdd-verification-evidence.js +0 -122
  279. package/dist/track-heuristics.d.ts +0 -27
  280. package/dist/track-heuristics.js +0 -154
  281. package/dist/util/slice-id.d.ts +0 -58
  282. package/dist/util/slice-id.js +0 -89
  283. package/dist/worktree-manager.d.ts +0 -20
  284. package/dist/worktree-manager.js +0 -108
@@ -1,631 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { checkReviewSecurityNoChangeAttestation, checkReviewVerdictConsistency, extractMarkdownSectionBody, lintArtifact, validateReviewArmy } from "./artifact-linter.js";
4
- import { ELICITATION_STAGES, evaluateQaLogFloor } from "./artifact-linter/shared.js";
5
- import { resolveArtifactPath } from "./artifact-paths.js";
6
- import { RUNTIME_ROOT } from "./constants.js";
7
- import { stageSchema } from "./content/stage-schema.js";
8
- import { readDelegationLedger } from "./delegation.js";
9
- import { exists } from "./fs-utils.js";
10
- import { computeEarlyLoopStatus, isEarlyLoopStage, normalizeEarlyLoopMaxIterations } from "./early-loop.js";
11
- import { detectPublicApiChanges } from "./internal/detect-public-api-changes.js";
12
- import { detectSupplyChainChanges } from "./internal/detect-supply-chain-changes.js";
13
- import { readFlowState, writeFlowState } from "./runs.js";
14
- import { loadStackAdapter } from "./stack-detection.js";
15
- import { validateTddVerificationEvidence } from "./tdd-verification-evidence.js";
16
- async function currentStageArtifactExists(projectRoot, stage, track) {
17
- const resolved = await resolveArtifactPath(stage, {
18
- projectRoot,
19
- track,
20
- intent: "read"
21
- });
22
- return exists(resolved.absPath);
23
- }
24
- async function readArtifactMarkdown(projectRoot, artifactFile) {
25
- const candidates = [
26
- path.join(projectRoot, RUNTIME_ROOT, "artifacts", artifactFile),
27
- path.join(projectRoot, artifactFile)
28
- ];
29
- for (const candidate of candidates) {
30
- if (!(await exists(candidate)))
31
- continue;
32
- try {
33
- return await fs.readFile(candidate, "utf8");
34
- }
35
- catch {
36
- // Try next location.
37
- }
38
- }
39
- return null;
40
- }
41
- async function readStageArtifactMarkdown(projectRoot, stage, track) {
42
- const resolved = await resolveArtifactPath(stage, {
43
- projectRoot,
44
- track,
45
- intent: "read"
46
- });
47
- if (!(await exists(resolved.absPath))) {
48
- return null;
49
- }
50
- try {
51
- return await fs.readFile(resolved.absPath, "utf8");
52
- }
53
- catch {
54
- return null;
55
- }
56
- }
57
- function unique(values) {
58
- return [...new Set(values)];
59
- }
60
- function sameStringArray(a, b) {
61
- if (a.length !== b.length)
62
- return false;
63
- return a.every((value, index) => value === b[index]);
64
- }
65
- async function readJsonFile(filePath) {
66
- try {
67
- const parsed = JSON.parse(await fs.readFile(filePath, "utf8"));
68
- return parsed && typeof parsed === "object" && !Array.isArray(parsed)
69
- ? parsed
70
- : null;
71
- }
72
- catch {
73
- return null;
74
- }
75
- }
76
- async function discoverRealTestCommands(projectRoot) {
77
- const commands = [];
78
- const packageJson = await readJsonFile(path.join(projectRoot, "package.json"));
79
- const scripts = packageJson?.scripts;
80
- if (scripts && typeof scripts === "object" && !Array.isArray(scripts)) {
81
- const scriptNames = Object.keys(scripts).filter((name) => {
82
- const value = scripts[name];
83
- return typeof value === "string" && (name === "test" || name.startsWith("test:"));
84
- });
85
- for (const name of scriptNames.sort()) {
86
- commands.push(name === "test" ? "npm test" : `npm run ${name}`);
87
- commands.push(name === "test" ? "pnpm test" : `pnpm ${name}`);
88
- commands.push(name === "test" ? "yarn test" : `yarn ${name}`);
89
- commands.push(name === "test" ? "bun test" : `bun run ${name}`);
90
- }
91
- }
92
- // 7.6.0 — pull additional commands from the stack-adapter's
93
- // testCommandHints rather than hardcoding pytest/go test/cargo
94
- // test/mvn/gradle here. Adapters that don't apply to the project
95
- // contribute no commands; pytest.ini support is kept as an
96
- // explicit fallback because pyproject.toml-less projects exist.
97
- const stackAdapter = await loadStackAdapter(projectRoot);
98
- for (const hint of stackAdapter.testCommandHints) {
99
- commands.push(hint);
100
- }
101
- if (await exists(path.join(projectRoot, "pytest.ini")))
102
- commands.push("pytest");
103
- return unique(commands);
104
- }
105
- async function verifyDiscoveredCommandEvidence(projectRoot, stage, gateId, flowState) {
106
- if (!(stage === "tdd" && gateId === "tdd_verified_before_complete")) {
107
- return null;
108
- }
109
- const commands = await discoverRealTestCommands(projectRoot);
110
- if (commands.length === 0)
111
- return null;
112
- const evidence = flowState.guardEvidence[gateId];
113
- const normalizedEvidence = typeof evidence === "string" ? evidence.toLowerCase() : "";
114
- const matched = commands.some((command) => normalizedEvidence.includes(command.toLowerCase()));
115
- if (matched)
116
- return null;
117
- return `${stage} verification gate blocked (${gateId}): guard evidence must cite one discovered real test command: ${commands.join(", ")}.`;
118
- }
119
- function toEarlyLoopGateSnapshot(value) {
120
- if (!value || typeof value !== "object" || Array.isArray(value))
121
- return null;
122
- const typed = value;
123
- const stage = typeof typed.stage === "string" ? typed.stage : "";
124
- const runId = typeof typed.runId === "string" ? typed.runId : "active";
125
- const iteration = typeof typed.iteration === "number" && Number.isInteger(typed.iteration) && typed.iteration >= 0
126
- ? typed.iteration
127
- : 0;
128
- const maxIterations = normalizeEarlyLoopMaxIterations(typeof typed.maxIterations === "number" ? typed.maxIterations : undefined);
129
- const openConcernIds = Array.isArray(typed.openConcerns)
130
- ? typed.openConcerns
131
- .flatMap((concern) => {
132
- if (!concern || typeof concern !== "object" || Array.isArray(concern))
133
- return [];
134
- const id = concern.id;
135
- return typeof id === "string" && id.trim().length > 0 ? [id.trim()] : [];
136
- })
137
- .sort((a, b) => a.localeCompare(b, "en"))
138
- : [];
139
- if (stage.length === 0)
140
- return null;
141
- return {
142
- stage,
143
- runId,
144
- iteration,
145
- maxIterations,
146
- openConcernIds,
147
- openConcernCount: openConcernIds.length,
148
- convergenceTripped: typed.convergenceTripped === true,
149
- escalationReason: typeof typed.escalationReason === "string" && typed.escalationReason.trim().length > 0
150
- ? typed.escalationReason.trim()
151
- : undefined
152
- };
153
- }
154
- async function readEarlyLoopGateSnapshot(projectRoot, flowState) {
155
- if (!isEarlyLoopStage(flowState.currentStage)) {
156
- return { snapshot: null };
157
- }
158
- const stateDir = path.join(projectRoot, RUNTIME_ROOT, "state");
159
- const statusPath = path.join(stateDir, "early-loop.json");
160
- let onDisk = null;
161
- if (await exists(statusPath)) {
162
- try {
163
- onDisk = toEarlyLoopGateSnapshot(JSON.parse(await fs.readFile(statusPath, "utf8")));
164
- }
165
- catch (error) {
166
- const reason = error instanceof Error ? error.message : String(error);
167
- return {
168
- snapshot: null,
169
- issue: `early loop gate blocked (early_loop_open_concerns): unable to parse ${statusPath} (${reason}). ` +
170
- "Rebuild status with `cclaw internal early-loop-status --write`."
171
- };
172
- }
173
- }
174
- if (onDisk &&
175
- onDisk.stage === flowState.currentStage &&
176
- onDisk.runId === flowState.activeRunId) {
177
- return { snapshot: onDisk };
178
- }
179
- try {
180
- const computed = await computeEarlyLoopStatus(flowState.currentStage, flowState.activeRunId, path.join(stateDir, "early-loop-log.jsonl"));
181
- return {
182
- snapshot: {
183
- stage: computed.stage,
184
- runId: computed.runId,
185
- iteration: computed.iteration,
186
- maxIterations: computed.maxIterations,
187
- openConcernIds: computed.openConcerns.map((concern) => concern.id),
188
- openConcernCount: computed.openConcerns.length,
189
- convergenceTripped: computed.convergenceTripped,
190
- escalationReason: computed.escalationReason
191
- }
192
- };
193
- }
194
- catch (error) {
195
- const reason = error instanceof Error ? error.message : String(error);
196
- return {
197
- snapshot: null,
198
- issue: `early loop gate blocked (early_loop_open_concerns): unable to compute status from early-loop-log.jsonl (${reason}).`
199
- };
200
- }
201
- }
202
- const DESIGN_RESEARCH_REQUIRED_SECTIONS = [
203
- "Stack Analysis",
204
- "Features & Patterns",
205
- "Architecture Options",
206
- "Pitfalls & Risks",
207
- "Synthesis"
208
- ];
209
- export async function verifyCurrentStageGateEvidence(projectRoot, flowState, options = {}) {
210
- const stage = flowState.currentStage;
211
- const schema = stageSchema(stage, flowState.track, flowState.discoveryMode, flowState.taskClass ?? null);
212
- const catalog = flowState.stageGateCatalog[stage];
213
- const required = schema.requiredGates
214
- .filter((gate) => gate.tier === "required")
215
- .map((gate) => gate.id);
216
- const recommended = schema.requiredGates
217
- .filter((gate) => gate.tier === "recommended")
218
- .map((gate) => gate.id);
219
- const conditional = [];
220
- const requiredSet = new Set(required);
221
- const recommendedSet = new Set(recommended);
222
- const allowedSet = new Set([...required, ...recommended]);
223
- const issues = [];
224
- const softNotices = [];
225
- const catalogRequired = unique(catalog.required);
226
- const catalogRecommended = unique(catalog.recommended ?? []);
227
- const catalogConditional = unique(catalog.conditional ?? []);
228
- const catalogTriggered = unique(catalog.triggered ?? []);
229
- const missingInCatalog = required.filter((gateId) => !catalogRequired.includes(gateId));
230
- const unexpectedInCatalog = catalogRequired.filter((gateId) => !requiredSet.has(gateId));
231
- const missingRecommendedInCatalog = recommended.filter((gateId) => !catalogRecommended.includes(gateId));
232
- const unexpectedRecommendedInCatalog = catalogRecommended.filter((gateId) => !recommendedSet.has(gateId));
233
- for (const gateId of missingInCatalog) {
234
- issues.push(`gate "${gateId}" missing from stageGateCatalog.required for stage "${stage}".`);
235
- }
236
- for (const gateId of unexpectedInCatalog) {
237
- issues.push(`unexpected gate "${gateId}" found in stageGateCatalog.required for stage "${stage}".`);
238
- }
239
- for (const gateId of missingRecommendedInCatalog) {
240
- issues.push(`gate "${gateId}" missing from stageGateCatalog.recommended for stage "${stage}".`);
241
- }
242
- for (const gateId of unexpectedRecommendedInCatalog) {
243
- issues.push(`unexpected gate "${gateId}" found in stageGateCatalog.recommended for stage "${stage}".`);
244
- }
245
- for (const gateId of catalogConditional) {
246
- issues.push(`stale conditional gate "${gateId}" found in stageGateCatalog.conditional for stage "${stage}" (conditional gate DSL removed).`);
247
- }
248
- for (const gateId of catalogTriggered) {
249
- issues.push(`stale triggered conditional gate "${gateId}" found in stageGateCatalog.triggered for stage "${stage}" (conditional gate DSL removed).`);
250
- }
251
- const blockedSet = new Set(catalog.blocked);
252
- const passedSet = new Set(catalog.passed);
253
- for (const gateId of catalog.passed) {
254
- if (!allowedSet.has(gateId)) {
255
- issues.push(`passed gate "${gateId}" is not defined for stage "${stage}".`);
256
- continue;
257
- }
258
- if (blockedSet.has(gateId)) {
259
- issues.push(`gate "${gateId}" cannot be both passed and blocked.`);
260
- }
261
- const evidence = flowState.guardEvidence[gateId];
262
- if (typeof evidence !== "string" || evidence.trim().length === 0) {
263
- issues.push(`passed gate "${gateId}" is missing guardEvidence entry.`);
264
- continue;
265
- }
266
- if (stage === "tdd" && gateId === "tdd_verified_before_complete") {
267
- const verification = await validateTddVerificationEvidence(projectRoot, evidence);
268
- if (!verification.ok) {
269
- issues.push(`tdd verification gate blocked (${gateId}): ${verification.issues.join(" ")}`);
270
- }
271
- }
272
- const discoveredCommandIssue = await verifyDiscoveredCommandEvidence(projectRoot, stage, gateId, flowState);
273
- if (discoveredCommandIssue) {
274
- issues.push(discoveredCommandIssue);
275
- }
276
- }
277
- for (const gateId of catalog.blocked) {
278
- if (!allowedSet.has(gateId)) {
279
- issues.push(`blocked gate "${gateId}" is not defined for stage "${stage}".`);
280
- }
281
- }
282
- const artifactPresent = await currentStageArtifactExists(projectRoot, stage, flowState.track);
283
- const shouldValidateArtifact = artifactPresent || catalog.passed.length > 0 || flowState.completedStages.includes(stage);
284
- if (shouldValidateArtifact) {
285
- const lint = await lintArtifact(projectRoot, stage, flowState.track, {
286
- extraStageFlags: options.extraStageFlags
287
- });
288
- if (!lint.passed) {
289
- const failedRequiredFindings = lint.findings
290
- .filter((finding) => finding.required && !finding.found);
291
- const failedRequired = failedRequiredFindings.map((finding) => finding.section);
292
- if (failedRequired.length > 0) {
293
- const failureDetails = failedRequiredFindings
294
- .map((finding) => {
295
- const details = finding.details?.trim();
296
- const rule = finding.rule?.trim();
297
- const explanation = details && details.length > 0 ? details : rule;
298
- return explanation && explanation.length > 0
299
- ? `${finding.section}: ${explanation}`
300
- : finding.section;
301
- })
302
- .join("; ");
303
- issues.push(`artifact validation failed for required sections: ${failedRequired.join(", ")}. ${failureDetails}`);
304
- }
305
- }
306
- if (stage === "review") {
307
- const reviewArmy = await validateReviewArmy(projectRoot);
308
- if (!reviewArmy.valid) {
309
- issues.push(`review-army validation failed: ${reviewArmy.errors.join("; ")}`);
310
- }
311
- const verdictConsistency = await checkReviewVerdictConsistency(projectRoot);
312
- if (!verdictConsistency.ok) {
313
- issues.push(`review verdict inconsistency: ${verdictConsistency.errors.join("; ")}`);
314
- }
315
- const reviewCriticalsClaimedResolved = passedSet.has("review_criticals_resolved") || flowState.completedStages.includes("review");
316
- const unresolvedCriticals = verdictConsistency.openCriticalCount > 0 || verdictConsistency.shipBlockerCount > 0;
317
- if (reviewCriticalsClaimedResolved && unresolvedCriticals) {
318
- issues.push(`review criticals gate blocked (review_criticals_resolved): review-army still reports ` +
319
- `${verdictConsistency.openCriticalCount} open critical(s) and ` +
320
- `${verdictConsistency.shipBlockerCount} ship blocker(s).`);
321
- }
322
- const securityAttestation = await checkReviewSecurityNoChangeAttestation(projectRoot);
323
- if (!securityAttestation.ok) {
324
- issues.push(`review security attestation failed: ${securityAttestation.errors.join("; ")}`);
325
- }
326
- }
327
- if (stage === "design") {
328
- const researchGateRequired = schema.requiredGates.some((gate) => gate.id === "design_research_complete" && gate.tier === "required");
329
- if (researchGateRequired) {
330
- const designMarkdown = await readStageArtifactMarkdown(projectRoot, "design", flowState.track);
331
- const inlineResearchBody = designMarkdown
332
- ? extractMarkdownSectionBody(designMarkdown, "Research Fleet Synthesis")
333
- : null;
334
- const inlineResearchLines = inlineResearchBody
335
- ? inlineResearchBody
336
- .split(/\r?\n/gu)
337
- .map((line) => line.trim())
338
- .filter((line) => line.length > 0)
339
- .filter((line) => !/^\|?(?:[-:\s|])+$/u.test(line))
340
- .filter((line) => !/\b(?:TODO|TBD|FIXME|pending)\b/iu.test(line) &&
341
- !/<fill-in>/iu.test(line) &&
342
- !/^>\s*Default path:/iu.test(line) &&
343
- !/^\|\s*compact inline synthesis\s*\|\s*\|\s*\|\s*\|?\s*$/iu.test(line))
344
- : [];
345
- const inlineResearchComplete = inlineResearchLines.length > 0;
346
- const researchMarkdown = await readArtifactMarkdown(projectRoot, "02a-research.md");
347
- if (!inlineResearchComplete && !researchMarkdown) {
348
- issues.push("design research gate blocked (design_research_complete): fill `Research Fleet Synthesis` in the active design artifact, or write `.cclaw/artifacts/02a-research.md` for deep/high-risk research.");
349
- }
350
- else if (researchMarkdown) {
351
- const missingSections = [];
352
- for (const section of DESIGN_RESEARCH_REQUIRED_SECTIONS) {
353
- const body = extractMarkdownSectionBody(researchMarkdown, section);
354
- if (body === null) {
355
- missingSections.push(section);
356
- continue;
357
- }
358
- const meaningfulLines = body
359
- .split(/\r?\n/gu)
360
- .map((line) => line.trim())
361
- .filter((line) => line.length > 0)
362
- .filter((line) => !/^\|?(?:[-:\s|])+$/u.test(line));
363
- const nonPlaceholder = meaningfulLines.filter((line) => !/\b(?:TODO|TBD|FIXME|pending)\b/iu.test(line) &&
364
- !/<fill-in>/iu.test(line));
365
- if (nonPlaceholder.length === 0) {
366
- missingSections.push(`${section} (empty or placeholder)`);
367
- }
368
- }
369
- if (missingSections.length > 0) {
370
- issues.push(`design research gate blocked (design_research_complete): ${missingSections.join(", ")}.`);
371
- }
372
- }
373
- }
374
- }
375
- if (stage === "tdd") {
376
- const docsDriftDetection = await detectPublicApiChanges(projectRoot);
377
- const supplyChainDetection = await detectSupplyChainChanges(projectRoot);
378
- if (docsDriftDetection.triggered || supplyChainDetection.triggered) {
379
- const ledger = await readDelegationLedger(projectRoot);
380
- const hasDocUpdaterCompletion = ledger.entries.some((entry) => entry.runId === flowState.activeRunId &&
381
- entry.stage === "tdd" &&
382
- entry.agent === "doc-updater" &&
383
- entry.status === "completed");
384
- if (!hasDocUpdaterCompletion) {
385
- if (docsDriftDetection.triggered) {
386
- issues.push(`tdd docs drift gate blocked (tdd_docs_drift_check): public surface changes detected (${docsDriftDetection.changedFiles.join(", ")}) but no completed doc-updater delegation exists for the active run.`);
387
- }
388
- if (supplyChainDetection.triggered) {
389
- issues.push(`tdd docs drift gate blocked (tdd_docs_drift_check): supply-chain changes detected (${supplyChainDetection.changedFiles.join(", ")}) but no completed doc-updater delegation exists for the active run.`);
390
- }
391
- }
392
- }
393
- }
394
- }
395
- if (isEarlyLoopStage(stage)) {
396
- const { snapshot, issue } = await readEarlyLoopGateSnapshot(projectRoot, flowState);
397
- if (issue) {
398
- issues.push(issue);
399
- }
400
- else if (snapshot && snapshot.openConcernCount > 0) {
401
- const concernTail = snapshot.openConcernIds.length > 3
402
- ? `, +${snapshot.openConcernIds.length - 3} more`
403
- : "";
404
- const concernSample = snapshot.openConcernIds.slice(0, 3).join(", ");
405
- if (snapshot.convergenceTripped) {
406
- const reason = snapshot.escalationReason ?? "convergence guard tripped";
407
- softNotices.push(`early loop escalation notice (early_loop_open_concerns): ${reason}; ` +
408
- `open concerns remain (${concernSample}${concernTail}). Request explicit human override before advancing.`);
409
- }
410
- else {
411
- issues.push(`early loop gate blocked (early_loop_open_concerns): ` +
412
- `${snapshot.openConcernCount} open concern(s) remain after iteration ` +
413
- `${snapshot.iteration}/${snapshot.maxIterations} (${concernSample}${concernTail}).`);
414
- }
415
- }
416
- }
417
- const missingRequired = required.filter((gateId) => !passedSet.has(gateId));
418
- const missingRecommended = [
419
- ...recommended.filter((gateId) => !passedSet.has(gateId)),
420
- ...softNotices
421
- ];
422
- const missingTriggeredConditional = [];
423
- const blockingBlocked = catalog.blocked.filter((gateId) => requiredSet.has(gateId));
424
- const complete = missingRequired.length === 0 && blockingBlocked.length === 0;
425
- if (flowState.completedStages.includes(stage) && !complete) {
426
- if (missingRequired.length > 0) {
427
- issues.push(`stage "${stage}" is marked completed but required gates are not passed: ${missingRequired.join(", ")}.`);
428
- }
429
- if (blockingBlocked.length > 0) {
430
- issues.push(`stage "${stage}" is marked completed but has blocking blocked gates: ${blockingBlocked.join(", ")}.`);
431
- }
432
- }
433
- let qaLogFloor = null;
434
- if (ELICITATION_STAGES.has(stage)) {
435
- let qaLogBody = null;
436
- try {
437
- const stageMd = await readStageArtifactMarkdown(projectRoot, stage, flowState.track);
438
- qaLogBody = stageMd
439
- ? extractMarkdownSectionBody(stageMd, "Q&A Log")
440
- : null;
441
- }
442
- catch {
443
- qaLogBody = null;
444
- }
445
- const skipQuestionsHint = flowState.interactionHints?.[stage]?.skipQuestions === true ||
446
- (options.extraStageFlags ?? []).includes("--skip-questions");
447
- const floor = evaluateQaLogFloor(qaLogBody, flowState.track, stage, {
448
- discoveryMode: flowState.discoveryMode,
449
- skipQuestions: skipQuestionsHint
450
- });
451
- qaLogFloor = {
452
- ok: floor.ok,
453
- count: floor.count,
454
- min: floor.min,
455
- hasStopSignal: floor.hasStopSignal,
456
- liteShortCircuit: floor.liteShortCircuit,
457
- skipQuestionsAdvisory: floor.skipQuestionsAdvisory,
458
- blocking: !floor.ok && !floor.skipQuestionsAdvisory,
459
- forcingCovered: floor.forcingCovered,
460
- forcingPending: floor.forcingPending,
461
- noNewDecisions: floor.noNewDecisions
462
- };
463
- // when the QA log floor is blocking, mirror that decision into
464
- // `gates.issues` so the harness has a single structured source of truth
465
- // for "this stage is blocked". The `qa_log_unconverged` linter rule
466
- // remains the verbose detail/fallback channel.
467
- if (qaLogFloor.blocking) {
468
- issues.push(`qa log floor blocked (qa_log_unconverged): ${qaLogFloor.count}/${qaLogFloor.min} entries on stage "${stage}" (track=${flowState.track}, discoveryMode=${flowState.discoveryMode ?? "default"}). Continue elicitation or pass --skip-questions to record the stop.`);
469
- }
470
- }
471
- return {
472
- ok: issues.length === 0,
473
- stage,
474
- issues,
475
- requiredCount: required.length,
476
- recommendedCount: recommended.length,
477
- conditionalCount: conditional.length,
478
- triggeredConditionalCount: 0,
479
- passedCount: catalog.passed.length,
480
- blockedCount: catalog.blocked.length,
481
- complete,
482
- missingRequired,
483
- missingRecommended,
484
- missingTriggeredConditional,
485
- qaLogFloor
486
- };
487
- }
488
- export function verifyCompletedStagesGateClosure(flowState) {
489
- const issues = [];
490
- const openStages = [];
491
- for (const stage of flowState.completedStages) {
492
- const schema = stageSchema(stage, flowState.track, flowState.discoveryMode, flowState.taskClass ?? null);
493
- const catalog = flowState.stageGateCatalog[stage];
494
- const required = schema.requiredGates
495
- .filter((gate) => gate.tier === "required")
496
- .map((gate) => gate.id);
497
- const passedSet = new Set(catalog.passed);
498
- const missingRequired = required.filter((gateId) => !passedSet.has(gateId));
499
- const missingTriggeredConditional = [];
500
- const blockingBlocked = catalog.blocked.filter((gateId) => required.includes(gateId));
501
- if (missingRequired.length > 0 || missingTriggeredConditional.length > 0 || blockingBlocked.length > 0) {
502
- openStages.push({
503
- stage,
504
- missingRequired,
505
- missingTriggeredConditional,
506
- blocked: [...blockingBlocked]
507
- });
508
- if (missingRequired.length > 0) {
509
- issues.push(`completed stage "${stage}" has unpassed required gates: ${missingRequired.join(", ")}.`);
510
- }
511
- if (blockingBlocked.length > 0) {
512
- issues.push(`completed stage "${stage}" still has blocking blocked gates: ${blockingBlocked.join(", ")}.`);
513
- }
514
- }
515
- }
516
- return { ok: openStages.length === 0, issues, openStages };
517
- }
518
- export function reconcileCurrentStageGateCatalog(flowState) {
519
- const stage = flowState.currentStage;
520
- const schema = stageSchema(stage, flowState.track, flowState.discoveryMode, flowState.taskClass ?? null);
521
- const required = schema.requiredGates
522
- .filter((gate) => gate.tier === "required")
523
- .map((gate) => gate.id);
524
- const recommended = schema.requiredGates
525
- .filter((gate) => gate.tier === "recommended")
526
- .map((gate) => gate.id);
527
- const conditional = [];
528
- const requiredSet = new Set(required);
529
- const recommendedSet = new Set(recommended);
530
- const allowedSet = new Set([...required, ...recommended]);
531
- const catalog = flowState.stageGateCatalog[stage];
532
- const notes = [];
533
- const demotedGateIds = new Set();
534
- const before = {
535
- required: [...catalog.required],
536
- recommended: [...catalog.recommended],
537
- conditional: [...catalog.conditional],
538
- triggered: [...catalog.triggered],
539
- passed: [...catalog.passed],
540
- blocked: [...catalog.blocked]
541
- };
542
- const passedSet = new Set(unique(catalog.passed).filter((gateId) => {
543
- const keep = allowedSet.has(gateId);
544
- if (!keep) {
545
- notes.push(`removed unknown passed gate "${gateId}"`);
546
- }
547
- return keep;
548
- }));
549
- const blockedSet = new Set(unique(catalog.blocked).filter((gateId) => {
550
- const keep = allowedSet.has(gateId);
551
- if (!keep) {
552
- notes.push(`removed unknown blocked gate "${gateId}"`);
553
- }
554
- return keep;
555
- }));
556
- const staleConditional = unique(catalog.conditional).filter((gateId) => !allowedSet.has(gateId));
557
- for (const gateId of staleConditional) {
558
- notes.push(`removed stale conditional gate "${gateId}" (conditional gate DSL removed)`);
559
- }
560
- const staleTriggered = unique(catalog.triggered);
561
- for (const gateId of staleTriggered) {
562
- notes.push(`removed stale triggered gate "${gateId}" (conditional gate DSL removed)`);
563
- }
564
- for (const gateId of [...passedSet]) {
565
- if (!blockedSet.has(gateId))
566
- continue;
567
- const evidence = flowState.guardEvidence[gateId];
568
- if (typeof evidence === "string" && evidence.trim().length > 0) {
569
- blockedSet.delete(gateId);
570
- notes.push(`resolved overlap for "${gateId}" in favor of passed (evidence present)`);
571
- continue;
572
- }
573
- passedSet.delete(gateId);
574
- demotedGateIds.add(gateId);
575
- notes.push(`resolved overlap for "${gateId}" in favor of blocked (missing evidence)`);
576
- }
577
- for (const gateId of [...passedSet]) {
578
- const evidence = flowState.guardEvidence[gateId];
579
- if (typeof evidence === "string" && evidence.trim().length > 0)
580
- continue;
581
- passedSet.delete(gateId);
582
- blockedSet.add(gateId);
583
- demotedGateIds.add(gateId);
584
- notes.push(`moved "${gateId}" from passed to blocked (missing evidence)`);
585
- }
586
- const after = {
587
- required: [...required],
588
- recommended: [...recommended],
589
- conditional: [...conditional],
590
- triggered: [],
591
- passed: [...required, ...recommended].filter((gateId) => passedSet.has(gateId)),
592
- blocked: [...required, ...recommended].filter((gateId) => blockedSet.has(gateId) && !passedSet.has(gateId))
593
- };
594
- const changed = !sameStringArray(before.required, after.required) ||
595
- !sameStringArray(before.recommended, after.recommended) ||
596
- !sameStringArray(before.conditional, after.conditional) ||
597
- !sameStringArray(before.triggered, after.triggered) ||
598
- !sameStringArray(before.passed, after.passed) ||
599
- !sameStringArray(before.blocked, after.blocked);
600
- const nextState = changed
601
- ? {
602
- ...flowState,
603
- stageGateCatalog: {
604
- ...flowState.stageGateCatalog,
605
- [stage]: after
606
- }
607
- }
608
- : flowState;
609
- return {
610
- nextState,
611
- reconciliation: {
612
- stage,
613
- changed,
614
- before,
615
- after,
616
- demotedGateIds: [...required, ...recommended].filter((gateId) => demotedGateIds.has(gateId)),
617
- notes
618
- }
619
- };
620
- }
621
- export async function reconcileAndWriteCurrentStageGateCatalog(projectRoot) {
622
- const state = await readFlowState(projectRoot);
623
- const { nextState, reconciliation } = reconcileCurrentStageGateCatalog(state);
624
- if (reconciliation.changed) {
625
- await writeFlowState(projectRoot, nextState);
626
- }
627
- return {
628
- ...reconciliation,
629
- wrote: reconciliation.changed
630
- };
631
- }