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,357 +0,0 @@
1
- import { FLOW_STAGES } from "../../types.js";
2
- import { isDiscoveryMode, isFlowTrack } from "../../flow-state.js";
3
- import { isFlowStageValue, parseCsv, parseEvidenceByGate, unique } from "./helpers.js";
4
- export function parseAdvanceStageArgs(tokens) {
5
- const [stageRaw, ...flagTokens] = tokens;
6
- if (!isFlowStageValue(stageRaw)) {
7
- throw new Error(`internal advance-stage requires a stage positional argument (${FLOW_STAGES.join(", ")}).`);
8
- }
9
- let evidenceJson;
10
- let passed = [];
11
- let waiveDelegations = [];
12
- let waiverReason;
13
- let acceptProactiveWaiver = false;
14
- let acceptProactiveWaiverReason;
15
- let acceptProactiveWaiverToken;
16
- let skipQuestions = false;
17
- let quiet = false;
18
- let json = false;
19
- for (let i = 0; i < flagTokens.length; i += 1) {
20
- const token = flagTokens[i];
21
- const nextToken = flagTokens[i + 1];
22
- if (token === "--json") {
23
- json = true;
24
- continue;
25
- }
26
- if (token === "--quiet") {
27
- quiet = true;
28
- continue;
29
- }
30
- if (token === "--evidence-json") {
31
- if (!nextToken || nextToken.startsWith("--")) {
32
- throw new Error("--evidence-json requires a JSON object value.");
33
- }
34
- evidenceJson = nextToken;
35
- i += 1;
36
- continue;
37
- }
38
- if (token.startsWith("--evidence-json=")) {
39
- evidenceJson = token.slice("--evidence-json=".length);
40
- continue;
41
- }
42
- if (token === "--passed") {
43
- if (!nextToken || nextToken.startsWith("--")) {
44
- throw new Error("--passed requires a comma-separated gate list.");
45
- }
46
- passed = [...passed, ...parseCsv(nextToken)];
47
- i += 1;
48
- continue;
49
- }
50
- if (token.startsWith("--passed=")) {
51
- passed = [...passed, ...parseCsv(token.slice("--passed=".length))];
52
- continue;
53
- }
54
- if (token === "--waive-delegation") {
55
- if (!nextToken || nextToken.startsWith("--")) {
56
- throw new Error("--waive-delegation requires a comma-separated agent list.");
57
- }
58
- waiveDelegations = [...waiveDelegations, ...parseCsv(nextToken)];
59
- i += 1;
60
- continue;
61
- }
62
- if (token.startsWith("--waive-delegation=")) {
63
- waiveDelegations = [
64
- ...waiveDelegations,
65
- ...parseCsv(token.slice("--waive-delegation=".length))
66
- ];
67
- continue;
68
- }
69
- if (token === "--waiver-reason") {
70
- if (!nextToken || nextToken.startsWith("--")) {
71
- throw new Error("--waiver-reason requires a text value.");
72
- }
73
- waiverReason = nextToken.trim();
74
- i += 1;
75
- continue;
76
- }
77
- if (token.startsWith("--waiver-reason=")) {
78
- waiverReason = token.slice("--waiver-reason=".length).trim();
79
- continue;
80
- }
81
- if (token === "--accept-proactive-waiver") {
82
- acceptProactiveWaiver = true;
83
- continue;
84
- }
85
- if (token.startsWith("--accept-proactive-waiver=")) {
86
- acceptProactiveWaiver = true;
87
- acceptProactiveWaiverToken = token.slice("--accept-proactive-waiver=".length).trim();
88
- continue;
89
- }
90
- if (token === "--skip-questions") {
91
- skipQuestions = true;
92
- continue;
93
- }
94
- if (token === "--accept-proactive-waiver-reason") {
95
- if (!nextToken || nextToken.startsWith("--")) {
96
- throw new Error("--accept-proactive-waiver-reason requires a text value.");
97
- }
98
- acceptProactiveWaiverReason = nextToken.trim();
99
- i += 1;
100
- continue;
101
- }
102
- if (token.startsWith("--accept-proactive-waiver-reason=")) {
103
- acceptProactiveWaiverReason = token.slice("--accept-proactive-waiver-reason=".length).trim();
104
- continue;
105
- }
106
- throw new Error(`Unknown flag for internal advance-stage: ${token}`);
107
- }
108
- return {
109
- stage: stageRaw,
110
- passedGateIds: unique(passed),
111
- evidenceByGate: parseEvidenceByGate(evidenceJson),
112
- waiveDelegations: unique(waiveDelegations),
113
- waiverReason,
114
- acceptProactiveWaiver,
115
- acceptProactiveWaiverReason,
116
- acceptProactiveWaiverToken,
117
- skipQuestions,
118
- quiet,
119
- json
120
- };
121
- }
122
- export function parseVerifyFlowStateDiffArgs(tokens) {
123
- let afterJson;
124
- let afterFile;
125
- let quiet = false;
126
- for (const token of tokens) {
127
- if (token === "--quiet") {
128
- quiet = true;
129
- continue;
130
- }
131
- if (token.startsWith("--after-json=")) {
132
- afterJson = token.replace("--after-json=", "");
133
- continue;
134
- }
135
- if (token.startsWith("--after-file=")) {
136
- afterFile = token.replace("--after-file=", "");
137
- continue;
138
- }
139
- throw new Error(`Unknown flag for internal verify-flow-state-diff: ${token}`);
140
- }
141
- if (!afterJson && !afterFile) {
142
- throw new Error("internal verify-flow-state-diff requires --after-json=<json> or --after-file=<path>.");
143
- }
144
- return { afterJson, afterFile, quiet };
145
- }
146
- export function parseVerifyCurrentStateArgs(tokens) {
147
- let quiet = false;
148
- for (const token of tokens) {
149
- if (token === "--quiet") {
150
- quiet = true;
151
- continue;
152
- }
153
- throw new Error(`Unknown flag for internal verify-current-state: ${token}`);
154
- }
155
- return { quiet };
156
- }
157
- export function parseRewindArgs(tokens) {
158
- let quiet = false;
159
- let json = false;
160
- const positional = [];
161
- for (let i = 0; i < tokens.length; i += 1) {
162
- const token = tokens[i];
163
- const nextToken = tokens[i + 1];
164
- if (token === "--quiet") {
165
- quiet = true;
166
- continue;
167
- }
168
- if (token === "--json") {
169
- json = true;
170
- continue;
171
- }
172
- if (token === "--ack") {
173
- if (!nextToken || nextToken.startsWith("--")) {
174
- throw new Error("--ack requires a stage value.");
175
- }
176
- if (!isFlowStageValue(nextToken)) {
177
- throw new Error(`--ack stage must be one of: ${FLOW_STAGES.join(", ")}.`);
178
- }
179
- i += 1;
180
- return { mode: "ack", targetStage: nextToken, quiet, json };
181
- }
182
- if (token.startsWith("--ack=")) {
183
- const stage = token.slice("--ack=".length);
184
- if (!isFlowStageValue(stage)) {
185
- throw new Error(`--ack stage must be one of: ${FLOW_STAGES.join(", ")}.`);
186
- }
187
- return { mode: "ack", targetStage: stage, quiet, json };
188
- }
189
- positional.push(token);
190
- }
191
- const [targetStage, ...reasonParts] = positional;
192
- if (!isFlowStageValue(targetStage)) {
193
- throw new Error(`internal rewind requires a target stage (${FLOW_STAGES.join(", ")}) or --ack <stage>.`);
194
- }
195
- const reason = reasonParts.join(" ").trim();
196
- if (reason.length === 0) {
197
- throw new Error('internal rewind requires a reason, for example: cclaw internal rewind tdd "review_blocked_by_critical".');
198
- }
199
- return { mode: "rewind", targetStage, reason, quiet, json };
200
- }
201
- export function parseHookArgs(tokens) {
202
- const [hookName, ...rest] = tokens;
203
- const normalizedHook = typeof hookName === "string" ? hookName.trim() : "";
204
- if (normalizedHook.length === 0) {
205
- throw new Error("internal hook requires a hook name: cclaw internal hook <name>.");
206
- }
207
- if (rest.length > 0) {
208
- throw new Error(`Unknown arguments for internal hook: ${rest.join(" ")}`);
209
- }
210
- return { hookName: normalizedHook };
211
- }
212
- export function parseStartFlowArgs(tokens) {
213
- let track;
214
- let discoveryMode = "guided";
215
- let className;
216
- let prompt;
217
- let reason;
218
- let stack;
219
- let forceReset = false;
220
- let reclassify = false;
221
- let quiet = false;
222
- let fromIdeaArtifact;
223
- let fromIdeaCandidateId;
224
- for (let i = 0; i < tokens.length; i += 1) {
225
- const token = tokens[i];
226
- const nextToken = tokens[i + 1];
227
- const readValue = (flag) => {
228
- if (token.startsWith(`${flag}=`))
229
- return token.slice(flag.length + 1);
230
- if (token === flag && nextToken && !nextToken.startsWith("--")) {
231
- i += 1;
232
- return nextToken;
233
- }
234
- throw new Error(`${flag} requires a value.`);
235
- };
236
- if (token === "--quiet") {
237
- quiet = true;
238
- continue;
239
- }
240
- if (token === "--force-reset") {
241
- forceReset = true;
242
- continue;
243
- }
244
- if (token === "--reclassify") {
245
- reclassify = true;
246
- continue;
247
- }
248
- if (token === "--track" || token.startsWith("--track=")) {
249
- const raw = readValue("--track").trim();
250
- if (!isFlowTrack(raw)) {
251
- throw new Error(`--track must be one of: standard, medium, quick.`);
252
- }
253
- track = raw;
254
- continue;
255
- }
256
- if (token === "--discovery-mode" || token.startsWith("--discovery-mode=")) {
257
- const raw = readValue("--discovery-mode").trim();
258
- const normalized = raw.toLowerCase();
259
- if (!isDiscoveryMode(normalized)) {
260
- throw new Error(`--discovery-mode must be one of: lean, guided, deep.`);
261
- }
262
- discoveryMode = normalized;
263
- continue;
264
- }
265
- if (token === "--class" || token.startsWith("--class=")) {
266
- className = readValue("--class").trim();
267
- continue;
268
- }
269
- if (token === "--prompt" || token.startsWith("--prompt=")) {
270
- prompt = readValue("--prompt").trim();
271
- continue;
272
- }
273
- if (token === "--reason" || token.startsWith("--reason=")) {
274
- reason = readValue("--reason").trim();
275
- continue;
276
- }
277
- if (token === "--stack" || token.startsWith("--stack=")) {
278
- stack = readValue("--stack").trim();
279
- continue;
280
- }
281
- if (token === "--from-idea-artifact" || token.startsWith("--from-idea-artifact=")) {
282
- const raw = readValue("--from-idea-artifact").trim();
283
- fromIdeaArtifact = raw.length > 0 ? raw : undefined;
284
- continue;
285
- }
286
- if (token === "--from-idea-candidate" || token.startsWith("--from-idea-candidate=")) {
287
- const raw = readValue("--from-idea-candidate").trim();
288
- fromIdeaCandidateId = raw.length > 0 ? raw : undefined;
289
- continue;
290
- }
291
- throw new Error(`Unknown flag for internal start-flow: ${token}`);
292
- }
293
- if (!track) {
294
- throw new Error("internal start-flow requires --track=<standard|medium|quick>.");
295
- }
296
- if (fromIdeaCandidateId && !fromIdeaArtifact) {
297
- throw new Error("--from-idea-candidate requires --from-idea-artifact=<path> to be set as well.");
298
- }
299
- return {
300
- track,
301
- discoveryMode,
302
- className,
303
- prompt,
304
- reason,
305
- stack,
306
- forceReset,
307
- reclassify,
308
- quiet,
309
- fromIdeaArtifact,
310
- fromIdeaCandidateId
311
- };
312
- }
313
- export function parseCancelRunArgs(tokens) {
314
- let reason;
315
- let disposition = "cancelled";
316
- let name;
317
- let quiet = false;
318
- for (let i = 0; i < tokens.length; i += 1) {
319
- const token = tokens[i];
320
- const nextToken = tokens[i + 1];
321
- const readValue = (flag) => {
322
- if (token.startsWith(`${flag}=`))
323
- return token.slice(flag.length + 1);
324
- if (token === flag && nextToken && !nextToken.startsWith("--")) {
325
- i += 1;
326
- return nextToken;
327
- }
328
- throw new Error(`${flag} requires a value.`);
329
- };
330
- if (token === "--quiet") {
331
- quiet = true;
332
- continue;
333
- }
334
- if (token === "--reason" || token.startsWith("--reason=")) {
335
- reason = readValue("--reason").trim();
336
- continue;
337
- }
338
- if (token === "--name" || token.startsWith("--name=")) {
339
- const raw = readValue("--name").trim();
340
- name = raw.length > 0 ? raw : undefined;
341
- continue;
342
- }
343
- if (token === "--disposition" || token.startsWith("--disposition=")) {
344
- const raw = readValue("--disposition").trim();
345
- if (raw !== "cancelled" && raw !== "abandoned") {
346
- throw new Error("--disposition must be cancelled or abandoned.");
347
- }
348
- disposition = raw;
349
- continue;
350
- }
351
- throw new Error(`Unknown flag for internal cancel-run: ${token}`);
352
- }
353
- if (!reason || reason.length === 0) {
354
- throw new Error("internal cancel-run requires --reason=<text>.");
355
- }
356
- return { reason, disposition, name, quiet };
357
- }
@@ -1,24 +0,0 @@
1
- import { type StageAutoSubagentDispatch } from "../../content/stage-schema.js";
2
- import type { DiscoveryMode, FlowStage } from "../../types.js";
3
- import type { RepoSignals } from "../../flow-state.js";
4
- export interface ProactiveDelegationTraceResult {
5
- missingRules: StageAutoSubagentDispatch[];
6
- }
7
- /**
8
- * Ensure every proactive dispatch rule for the stage has a ledger row for the
9
- * active run, or an explicit user-flag waiver.
10
- *
11
- * Lean/guided discovery on brainstorm/scope/design keeps only proactive rules
12
- * marked `essentialAcrossModes` (researcher today) so external research stays
13
- * auditable without requiring every discretionary proactive lens. Deep
14
- * discovery evaluates the full proactive matrix.
15
- */
16
- export declare function ensureProactiveDelegationTrace(projectRoot: string, stage: FlowStage, options: {
17
- acceptWaiver: boolean;
18
- waiverReason?: string;
19
- approvalToken?: string;
20
- approvalReason?: string;
21
- approvalIssuedAt?: string;
22
- discoveryMode: DiscoveryMode;
23
- repoSignals?: RepoSignals;
24
- }): Promise<ProactiveDelegationTraceResult>;
@@ -1,56 +0,0 @@
1
- import { appendDelegation, readDelegationLedger } from "../../delegation.js";
2
- import { stageAutoSubagentDispatch } from "../../content/stage-schema.js";
3
- function isEarlyElicitationStage(stage) {
4
- return stage === "brainstorm" || stage === "scope" || stage === "design";
5
- }
6
- function proactiveRulesForDiscoveryMode(stage, discoveryMode) {
7
- const proactiveRules = stageAutoSubagentDispatch(stage).filter((rule) => rule.mode === "proactive");
8
- if (isEarlyElicitationStage(stage) && (discoveryMode === "lean" || discoveryMode === "guided")) {
9
- return proactiveRules.filter((rule) => rule.essentialAcrossModes === true);
10
- }
11
- return proactiveRules;
12
- }
13
- /**
14
- * Ensure every proactive dispatch rule for the stage has a ledger row for the
15
- * active run, or an explicit user-flag waiver.
16
- *
17
- * Lean/guided discovery on brainstorm/scope/design keeps only proactive rules
18
- * marked `essentialAcrossModes` (researcher today) so external research stays
19
- * auditable without requiring every discretionary proactive lens. Deep
20
- * discovery evaluates the full proactive matrix.
21
- */
22
- export async function ensureProactiveDelegationTrace(projectRoot, stage, options) {
23
- void options.repoSignals;
24
- const proactiveRules = proactiveRulesForDiscoveryMode(stage, options.discoveryMode);
25
- if (proactiveRules.length === 0)
26
- return { missingRules: [] };
27
- const ledger = await readDelegationLedger(projectRoot);
28
- const currentRunEntries = ledger.entries.filter((entry) => entry.runId === ledger.runId);
29
- const missingRules = proactiveRules.filter((rule) => !currentRunEntries.some((entry) => entry.stage === stage && entry.agent === rule.agent && entry.mode === "proactive"));
30
- if (missingRules.length === 0)
31
- return { missingRules: [] };
32
- if (!options.acceptWaiver)
33
- return { missingRules };
34
- const approvalToken = options.approvalToken?.trim();
35
- const approvalReason = options.approvalReason?.trim();
36
- const waiverReason = options.waiverReason?.trim() ||
37
- approvalReason ||
38
- "accepted via --accept-proactive-waiver";
39
- for (const rule of missingRules) {
40
- await appendDelegation(projectRoot, {
41
- stage,
42
- agent: rule.agent,
43
- mode: "proactive",
44
- status: "waived",
45
- waiverReason,
46
- acceptedBy: "user-flag",
47
- conditionTrigger: rule.when,
48
- skill: rule.skill,
49
- ...(approvalToken ? { approvalToken } : {}),
50
- ...(approvalReason ? { approvalReason } : {}),
51
- ...(options.approvalIssuedAt ? { approvalIssuedAt: options.approvalIssuedAt } : {}),
52
- ts: new Date().toISOString()
53
- });
54
- }
55
- return { missingRules: [] };
56
- }
@@ -1,16 +0,0 @@
1
- import type { FlowStage } from "../../types.js";
2
- export declare const AUTO_REVIEW_LOOP_GATE_BY_STAGE: Partial<Record<FlowStage, string>>;
3
- /**
4
- * exact JSON shape that gate-evidence validators
5
- * accept for a review-loop envelope. The error messages emitted by
6
- * `validateReviewLoopGateEvidence` always include this example so the
7
- * agent never has to guess where `stage` lives (top-level of the
8
- * envelope, NOT inside `payload`). Keep `stage`/`targetScore`/etc. in
9
- * the order shown so a copy-paste from the error survives.
10
- */
11
- export declare function reviewLoopEnvelopeExample(stage: "scope" | "design"): string;
12
- export declare function pickReviewLoopEnvelope(value: unknown): Record<string, unknown> | null;
13
- export declare function validateReviewLoopGateEvidence(stage: "scope" | "design", evidence: string): string | null;
14
- export declare function validateUserApprovalEvidence(evidence: string): string | null;
15
- export declare function validateGateEvidenceShape(projectRoot: string, stage: FlowStage, gateId: string, evidence: string): Promise<string | null>;
16
- export declare function reviewLoopArtifactFixHint(stage: FlowStage, gateId: string): string;
@@ -1,199 +0,0 @@
1
- import { SHIP_FINALIZATION_MODES } from "../../constants.js";
2
- import { validateTddVerificationEvidence } from "../../tdd-verification-evidence.js";
3
- import { asRecord } from "./helpers.js";
4
- export const AUTO_REVIEW_LOOP_GATE_BY_STAGE = {
5
- design: "design_architecture_locked"
6
- };
7
- const SHIP_FINALIZATION_MODE_PATTERN = new RegExp(`\\b(?:${SHIP_FINALIZATION_MODES.join("|")})\\b`, "u");
8
- const SHIP_FINALIZATION_MODE_HINT = SHIP_FINALIZATION_MODES.join(", ");
9
- const REVIEW_LOOP_STOP_REASONS = new Set([
10
- "quality_threshold_met",
11
- "max_iterations_reached",
12
- "user_opt_out"
13
- ]);
14
- /**
15
- * exact JSON shape that gate-evidence validators
16
- * accept for a review-loop envelope. The error messages emitted by
17
- * `validateReviewLoopGateEvidence` always include this example so the
18
- * agent never has to guess where `stage` lives (top-level of the
19
- * envelope, NOT inside `payload`). Keep `stage`/`targetScore`/etc. in
20
- * the order shown so a copy-paste from the error survives.
21
- */
22
- export function reviewLoopEnvelopeExample(stage) {
23
- return JSON.stringify({
24
- type: "review-loop",
25
- stage,
26
- targetScore: 0.8,
27
- maxIterations: 3,
28
- stopReason: "quality_threshold_met",
29
- iterations: [{ iteration: 1, qualityScore: 0.8, findingsCount: 0 }]
30
- });
31
- }
32
- function reviewLoopEnvelopeShapeHint(stage) {
33
- return (`Expected envelope: ${reviewLoopEnvelopeExample(stage)}` +
34
- " (top-level keys: type, stage, targetScore, maxIterations, stopReason, iterations[]). " +
35
- "Stage MUST be at the top level — not inside payload.");
36
- }
37
- export function pickReviewLoopEnvelope(value) {
38
- const direct = asRecord(value);
39
- if (!direct)
40
- return null;
41
- if (direct.type === "review-loop")
42
- return direct;
43
- const payload = asRecord(direct.payload);
44
- if (payload?.type === "review-loop")
45
- return payload;
46
- const nested = asRecord(direct.reviewLoop);
47
- if (nested?.type === "review-loop")
48
- return nested;
49
- return null;
50
- }
51
- export function validateReviewLoopGateEvidence(stage, evidence) {
52
- let parsed;
53
- try {
54
- parsed = JSON.parse(evidence);
55
- }
56
- catch {
57
- return ("must be JSON containing a review-loop envelope (`type: \"review-loop\"`) in top-level, `payload`, or `reviewLoop`. " +
58
- reviewLoopEnvelopeShapeHint(stage));
59
- }
60
- const envelope = pickReviewLoopEnvelope(parsed);
61
- if (!envelope) {
62
- return ("must include a review-loop envelope (`type: \"review-loop\"`) in top-level, `payload`, or `reviewLoop`. " +
63
- reviewLoopEnvelopeShapeHint(stage));
64
- }
65
- if (envelope.stage !== stage) {
66
- return (`review-loop envelope stage must be "${stage}" at the top level of the envelope, not inside payload. ` +
67
- reviewLoopEnvelopeShapeHint(stage));
68
- }
69
- const targetScore = envelope.targetScore;
70
- if (typeof targetScore !== "number" || Number.isNaN(targetScore) || targetScore < 0 || targetScore > 1) {
71
- return "review-loop targetScore must be a number between 0 and 1.";
72
- }
73
- const maxIterations = envelope.maxIterations;
74
- if (typeof maxIterations !== "number" ||
75
- Number.isNaN(maxIterations) ||
76
- !Number.isInteger(maxIterations) ||
77
- maxIterations < 1) {
78
- return "review-loop maxIterations must be an integer >= 1.";
79
- }
80
- if (typeof envelope.stopReason !== "string" || !REVIEW_LOOP_STOP_REASONS.has(envelope.stopReason)) {
81
- return "review-loop stopReason must be one of quality_threshold_met, max_iterations_reached, user_opt_out.";
82
- }
83
- const rows = envelope.iterations;
84
- if (!Array.isArray(rows) || rows.length === 0) {
85
- return "review-loop iterations must be a non-empty array.";
86
- }
87
- if (rows.length > maxIterations) {
88
- return "review-loop iterations count cannot exceed maxIterations.";
89
- }
90
- let prevScore = -Infinity;
91
- let reachedTarget = false;
92
- for (let index = 0; index < rows.length; index++) {
93
- const row = asRecord(rows[index]);
94
- if (!row) {
95
- return `review-loop iterations[${index}] must be an object.`;
96
- }
97
- const iteration = row.iteration;
98
- const qualityScore = row.qualityScore;
99
- const findingsCount = row.findingsCount;
100
- if (typeof iteration !== "number" ||
101
- Number.isNaN(iteration) ||
102
- !Number.isInteger(iteration) ||
103
- iteration < 1) {
104
- return `review-loop iterations[${index}].iteration must be an integer >= 1.`;
105
- }
106
- if (typeof qualityScore !== "number" ||
107
- Number.isNaN(qualityScore) ||
108
- qualityScore < 0 ||
109
- qualityScore > 1) {
110
- return `review-loop iterations[${index}].qualityScore must be between 0 and 1.`;
111
- }
112
- if (typeof findingsCount !== "number" ||
113
- Number.isNaN(findingsCount) ||
114
- !Number.isInteger(findingsCount) ||
115
- findingsCount < 0) {
116
- return `review-loop iterations[${index}].findingsCount must be an integer >= 0.`;
117
- }
118
- if (qualityScore + Number.EPSILON < prevScore) {
119
- return "review-loop qualityScore must be monotonic non-decreasing across iterations.";
120
- }
121
- if (qualityScore >= targetScore) {
122
- reachedTarget = true;
123
- }
124
- prevScore = qualityScore;
125
- }
126
- if (envelope.stopReason === "quality_threshold_met" && !reachedTarget) {
127
- return "review-loop stopReason is quality_threshold_met but no iteration reached targetScore.";
128
- }
129
- if (envelope.stopReason === "max_iterations_reached" && rows.length < maxIterations) {
130
- return "review-loop stopReason is max_iterations_reached but iterations are below maxIterations.";
131
- }
132
- return null;
133
- }
134
- export function validateUserApprovalEvidence(evidence) {
135
- const normalized = evidence.trim();
136
- if (normalized.length === 0) {
137
- return "must cite explicit user approval.";
138
- }
139
- const reviewLoopEnvelope = (() => {
140
- try {
141
- return pickReviewLoopEnvelope(JSON.parse(normalized));
142
- }
143
- catch {
144
- return null;
145
- }
146
- })();
147
- if (reviewLoopEnvelope) {
148
- return "must cite explicit user approval; review-loop evidence is outside-voice evidence, not user approval.";
149
- }
150
- if (/\b(?:approved|approval|user approved|confirmed|accepted|yes|ok)\b/iu.test(normalized)) {
151
- return null;
152
- }
153
- if (/\b(?:утвержд(?:аю|ено|ен|ена)|подтвержд(?:аю|ено|ен|ена)|соглас(?:ен|на|овано)|да|ок|принято)\b/iu.test(normalized)) {
154
- return null;
155
- }
156
- return "must cite explicit user approval (for example `user approved the scope contract` or `пользователь утвердил scope`).";
157
- }
158
- // Per-gate validators keyed by `${stage}:${gateId}`. Returning a non-null
159
- // string surfaces the reason as an `advance-stage` failure so evidence is
160
- // guaranteed to carry the structural breadcrumbs downstream tooling
161
- // expects. Previously only `tdd:tdd_verified_before_complete` was checked.
162
- const GATE_EVIDENCE_VALIDATORS = {
163
- "ship:ship_finalization_executed": (evidence) => {
164
- if (!SHIP_FINALIZATION_MODE_PATTERN.test(evidence)) {
165
- return `must name the finalization mode that ran (for example ${SHIP_FINALIZATION_MODE_HINT}).`;
166
- }
167
- return null;
168
- },
169
- "scope:scope_user_approved": (evidence) => validateUserApprovalEvidence(evidence),
170
- "design:design_architecture_locked": (evidence) => validateReviewLoopGateEvidence("design", evidence)
171
- };
172
- export async function validateGateEvidenceShape(projectRoot, stage, gateId, evidence) {
173
- const normalized = evidence.trim();
174
- if (stage === "tdd" && gateId === "tdd_verified_before_complete") {
175
- const result = await validateTddVerificationEvidence(projectRoot, normalized);
176
- return result.ok ? null : result.issues.join(" ");
177
- }
178
- const validator = GATE_EVIDENCE_VALIDATORS[`${stage}:${gateId}`];
179
- if (!validator)
180
- return null;
181
- return validator(normalized);
182
- }
183
- export function reviewLoopArtifactFixHint(stage, gateId) {
184
- if (AUTO_REVIEW_LOOP_GATE_BY_STAGE[stage] !== gateId)
185
- return "";
186
- // the consistent flow is "include the gate in
187
- // --passed AND let stage-complete auto-hydrate evidence from the
188
- // artifact". An older hint told agents to omit the gate from
189
- // --evidence-json, but they then hit
190
- // `missing --evidence-json entries for passed gates: <gateId>`
191
- // because hydration only runs when --evidence-json is also present
192
- // OR when an artifact section yields a parseable envelope. The new
193
- // hint tells the agent to:
194
- // 1. Add the artifact section (so hydration succeeds), AND
195
- // 2. Include the gate in --passed.
196
- // No --evidence-json entry is required in that case.
197
- const stageReviewSection = stage === "scope" ? "Scope Outside Voice Loop" : "Design Outside Voice Loop";
198
- return (` Fix in two steps: (1) Add a \`## ${stageReviewSection}\` table to the artifact with rows like \`| 1 | 0.80 | 0 |\` plus \`- Stop reason: quality_threshold_met\`, \`- Target score: 0.80\`, and \`- Max iterations: 3\`. (2) Re-run \`stage-complete ${stage} --passed=...,${gateId},...\` — stage-complete will auto-hydrate the envelope from the artifact, so you do NOT need to pass --evidence-json for ${gateId}.`);
199
- }
@@ -1,14 +0,0 @@
1
- import { type FlowState } from "../../flow-state.js";
2
- import { type FlowStage } from "../../types.js";
3
- import type { RewindArgs } from "./parsers.js";
4
- import type { Writable } from "node:stream";
5
- interface InternalIo {
6
- stdout: Writable;
7
- stderr: Writable;
8
- }
9
- export declare function rewindLogPath(projectRoot: string): string;
10
- export declare function rewindId(date?: Date): string;
11
- export declare function stagesInvalidatedByRewind(current: FlowState, targetStage: FlowStage): FlowStage[];
12
- export declare function appendRewindLog(projectRoot: string, payload: Record<string, unknown>): Promise<void>;
13
- export declare function runRewind(projectRoot: string, args: RewindArgs, io: InternalIo): Promise<number>;
14
- export {};