cclaw-cli 7.7.1 → 8.1.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 (282) hide show
  1. package/README.md +210 -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 +90 -508
  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/install.d.ts +27 -15
  73. package/dist/install.js +230 -1342
  74. package/dist/knowledge-store.d.ts +19 -163
  75. package/dist/knowledge-store.js +56 -590
  76. package/dist/logger.d.ts +8 -3
  77. package/dist/logger.js +13 -4
  78. package/dist/orchestrator-routing.d.ts +29 -0
  79. package/dist/orchestrator-routing.js +156 -0
  80. package/dist/run-persistence.d.ts +7 -118
  81. package/dist/run-persistence.js +29 -845
  82. package/dist/runtime/run-hook.entry.d.ts +1 -3
  83. package/dist/runtime/run-hook.entry.js +19 -4
  84. package/dist/runtime/run-hook.mjs +13 -1024
  85. package/dist/types.d.ts +25 -261
  86. package/dist/types.js +8 -36
  87. package/package.json +6 -3
  88. package/dist/artifact-linter/brainstorm.d.ts +0 -2
  89. package/dist/artifact-linter/brainstorm.js +0 -353
  90. package/dist/artifact-linter/design.d.ts +0 -18
  91. package/dist/artifact-linter/design.js +0 -444
  92. package/dist/artifact-linter/findings-dedup.d.ts +0 -56
  93. package/dist/artifact-linter/findings-dedup.js +0 -232
  94. package/dist/artifact-linter/plan.d.ts +0 -2
  95. package/dist/artifact-linter/plan.js +0 -826
  96. package/dist/artifact-linter/review-army.d.ts +0 -49
  97. package/dist/artifact-linter/review-army.js +0 -520
  98. package/dist/artifact-linter/review.d.ts +0 -2
  99. package/dist/artifact-linter/review.js +0 -113
  100. package/dist/artifact-linter/scope.d.ts +0 -2
  101. package/dist/artifact-linter/scope.js +0 -158
  102. package/dist/artifact-linter/shared.d.ts +0 -637
  103. package/dist/artifact-linter/shared.js +0 -2163
  104. package/dist/artifact-linter/ship.d.ts +0 -2
  105. package/dist/artifact-linter/ship.js +0 -250
  106. package/dist/artifact-linter/spec.d.ts +0 -2
  107. package/dist/artifact-linter/spec.js +0 -176
  108. package/dist/artifact-linter/tdd.d.ts +0 -118
  109. package/dist/artifact-linter/tdd.js +0 -1404
  110. package/dist/artifact-linter.d.ts +0 -15
  111. package/dist/artifact-linter.js +0 -517
  112. package/dist/codex-feature-flag.d.ts +0 -58
  113. package/dist/codex-feature-flag.js +0 -193
  114. package/dist/content/closeout-guidance.d.ts +0 -14
  115. package/dist/content/closeout-guidance.js +0 -44
  116. package/dist/content/diff-command.d.ts +0 -1
  117. package/dist/content/diff-command.js +0 -43
  118. package/dist/content/harness-doc.d.ts +0 -1
  119. package/dist/content/harness-doc.js +0 -65
  120. package/dist/content/hook-events.d.ts +0 -9
  121. package/dist/content/hook-events.js +0 -23
  122. package/dist/content/hook-manifest.d.ts +0 -81
  123. package/dist/content/hook-manifest.js +0 -156
  124. package/dist/content/hooks.d.ts +0 -11
  125. package/dist/content/hooks.js +0 -1972
  126. package/dist/content/idea.d.ts +0 -60
  127. package/dist/content/idea.js +0 -416
  128. package/dist/content/language-policy.d.ts +0 -2
  129. package/dist/content/language-policy.js +0 -13
  130. package/dist/content/learnings.d.ts +0 -6
  131. package/dist/content/learnings.js +0 -141
  132. package/dist/content/observe.d.ts +0 -19
  133. package/dist/content/observe.js +0 -86
  134. package/dist/content/opencode-plugin.d.ts +0 -1
  135. package/dist/content/opencode-plugin.js +0 -635
  136. package/dist/content/review-prompts.d.ts +0 -1
  137. package/dist/content/review-prompts.js +0 -104
  138. package/dist/content/runtime-shared-snippets.d.ts +0 -8
  139. package/dist/content/runtime-shared-snippets.js +0 -80
  140. package/dist/content/session-hooks.d.ts +0 -7
  141. package/dist/content/session-hooks.js +0 -107
  142. package/dist/content/skills-elicitation.d.ts +0 -1
  143. package/dist/content/skills-elicitation.js +0 -167
  144. package/dist/content/stage-command.d.ts +0 -2
  145. package/dist/content/stage-command.js +0 -17
  146. package/dist/content/stage-schema.d.ts +0 -117
  147. package/dist/content/stage-schema.js +0 -955
  148. package/dist/content/stages/_lint-metadata/index.d.ts +0 -2
  149. package/dist/content/stages/_lint-metadata/index.js +0 -97
  150. package/dist/content/stages/brainstorm.d.ts +0 -2
  151. package/dist/content/stages/brainstorm.js +0 -184
  152. package/dist/content/stages/design.d.ts +0 -2
  153. package/dist/content/stages/design.js +0 -288
  154. package/dist/content/stages/index.d.ts +0 -8
  155. package/dist/content/stages/index.js +0 -11
  156. package/dist/content/stages/plan.d.ts +0 -2
  157. package/dist/content/stages/plan.js +0 -191
  158. package/dist/content/stages/review.d.ts +0 -2
  159. package/dist/content/stages/review.js +0 -240
  160. package/dist/content/stages/schema-types.d.ts +0 -203
  161. package/dist/content/stages/schema-types.js +0 -1
  162. package/dist/content/stages/scope.d.ts +0 -2
  163. package/dist/content/stages/scope.js +0 -254
  164. package/dist/content/stages/ship.d.ts +0 -2
  165. package/dist/content/stages/ship.js +0 -159
  166. package/dist/content/stages/spec.d.ts +0 -2
  167. package/dist/content/stages/spec.js +0 -170
  168. package/dist/content/stages/tdd.d.ts +0 -4
  169. package/dist/content/stages/tdd.js +0 -273
  170. package/dist/content/state-contracts.d.ts +0 -1
  171. package/dist/content/state-contracts.js +0 -63
  172. package/dist/content/status-command.d.ts +0 -4
  173. package/dist/content/status-command.js +0 -109
  174. package/dist/content/subagent-context-skills.d.ts +0 -4
  175. package/dist/content/subagent-context-skills.js +0 -279
  176. package/dist/content/subagents.d.ts +0 -3
  177. package/dist/content/subagents.js +0 -997
  178. package/dist/content/templates.d.ts +0 -26
  179. package/dist/content/templates.js +0 -1692
  180. package/dist/content/track-render-context.d.ts +0 -18
  181. package/dist/content/track-render-context.js +0 -53
  182. package/dist/content/tree-command.d.ts +0 -1
  183. package/dist/content/tree-command.js +0 -64
  184. package/dist/content/utility-skills.d.ts +0 -30
  185. package/dist/content/utility-skills.js +0 -160
  186. package/dist/content/view-command.d.ts +0 -2
  187. package/dist/content/view-command.js +0 -92
  188. package/dist/delegation.d.ts +0 -649
  189. package/dist/delegation.js +0 -1539
  190. package/dist/early-loop.d.ts +0 -70
  191. package/dist/early-loop.js +0 -302
  192. package/dist/execution-topology.d.ts +0 -44
  193. package/dist/execution-topology.js +0 -95
  194. package/dist/gate-evidence.d.ts +0 -85
  195. package/dist/gate-evidence.js +0 -631
  196. package/dist/harness-adapters.d.ts +0 -151
  197. package/dist/harness-adapters.js +0 -756
  198. package/dist/harness-selection.d.ts +0 -31
  199. package/dist/harness-selection.js +0 -214
  200. package/dist/hook-schema.d.ts +0 -6
  201. package/dist/hook-schema.js +0 -114
  202. package/dist/hook-schemas/claude-hooks.v1.json +0 -10
  203. package/dist/hook-schemas/codex-hooks.v1.json +0 -10
  204. package/dist/hook-schemas/cursor-hooks.v1.json +0 -13
  205. package/dist/init-detect.d.ts +0 -2
  206. package/dist/init-detect.js +0 -50
  207. package/dist/internal/advance-stage/advance.d.ts +0 -89
  208. package/dist/internal/advance-stage/advance.js +0 -655
  209. package/dist/internal/advance-stage/cancel-run.d.ts +0 -8
  210. package/dist/internal/advance-stage/cancel-run.js +0 -19
  211. package/dist/internal/advance-stage/flow-state-coercion.d.ts +0 -3
  212. package/dist/internal/advance-stage/flow-state-coercion.js +0 -81
  213. package/dist/internal/advance-stage/helpers.d.ts +0 -14
  214. package/dist/internal/advance-stage/helpers.js +0 -145
  215. package/dist/internal/advance-stage/hook.d.ts +0 -8
  216. package/dist/internal/advance-stage/hook.js +0 -40
  217. package/dist/internal/advance-stage/parsers.d.ts +0 -72
  218. package/dist/internal/advance-stage/parsers.js +0 -357
  219. package/dist/internal/advance-stage/proactive-delegation-trace.d.ts +0 -24
  220. package/dist/internal/advance-stage/proactive-delegation-trace.js +0 -56
  221. package/dist/internal/advance-stage/review-loop.d.ts +0 -16
  222. package/dist/internal/advance-stage/review-loop.js +0 -199
  223. package/dist/internal/advance-stage/rewind.d.ts +0 -14
  224. package/dist/internal/advance-stage/rewind.js +0 -108
  225. package/dist/internal/advance-stage/start-flow.d.ts +0 -13
  226. package/dist/internal/advance-stage/start-flow.js +0 -241
  227. package/dist/internal/advance-stage/verify.d.ts +0 -21
  228. package/dist/internal/advance-stage/verify.js +0 -185
  229. package/dist/internal/advance-stage.d.ts +0 -7
  230. package/dist/internal/advance-stage.js +0 -138
  231. package/dist/internal/cohesion-contract-stub.d.ts +0 -24
  232. package/dist/internal/cohesion-contract-stub.js +0 -148
  233. package/dist/internal/compound-readiness.d.ts +0 -23
  234. package/dist/internal/compound-readiness.js +0 -102
  235. package/dist/internal/detect-public-api-changes.d.ts +0 -5
  236. package/dist/internal/detect-public-api-changes.js +0 -45
  237. package/dist/internal/detect-supply-chain-changes.d.ts +0 -6
  238. package/dist/internal/detect-supply-chain-changes.js +0 -138
  239. package/dist/internal/early-loop-status.d.ts +0 -7
  240. package/dist/internal/early-loop-status.js +0 -93
  241. package/dist/internal/envelope-validate.d.ts +0 -7
  242. package/dist/internal/envelope-validate.js +0 -66
  243. package/dist/internal/flow-state-repair.d.ts +0 -20
  244. package/dist/internal/flow-state-repair.js +0 -104
  245. package/dist/internal/plan-split-waves.d.ts +0 -190
  246. package/dist/internal/plan-split-waves.js +0 -764
  247. package/dist/internal/runtime-integrity.d.ts +0 -7
  248. package/dist/internal/runtime-integrity.js +0 -268
  249. package/dist/internal/slice-commit.d.ts +0 -7
  250. package/dist/internal/slice-commit.js +0 -619
  251. package/dist/internal/tdd-loop-status.d.ts +0 -14
  252. package/dist/internal/tdd-loop-status.js +0 -68
  253. package/dist/internal/tdd-red-evidence.d.ts +0 -7
  254. package/dist/internal/tdd-red-evidence.js +0 -153
  255. package/dist/internal/waiver-grant.d.ts +0 -62
  256. package/dist/internal/waiver-grant.js +0 -294
  257. package/dist/internal/wave-status.d.ts +0 -74
  258. package/dist/internal/wave-status.js +0 -506
  259. package/dist/managed-resources.d.ts +0 -53
  260. package/dist/managed-resources.js +0 -313
  261. package/dist/policy.d.ts +0 -10
  262. package/dist/policy.js +0 -167
  263. package/dist/retro-gate.d.ts +0 -9
  264. package/dist/retro-gate.js +0 -47
  265. package/dist/run-archive.d.ts +0 -61
  266. package/dist/run-archive.js +0 -391
  267. package/dist/runs.d.ts +0 -2
  268. package/dist/runs.js +0 -2
  269. package/dist/stack-detection.d.ts +0 -116
  270. package/dist/stack-detection.js +0 -489
  271. package/dist/streaming/event-stream.d.ts +0 -31
  272. package/dist/streaming/event-stream.js +0 -114
  273. package/dist/tdd-cycle.d.ts +0 -107
  274. package/dist/tdd-cycle.js +0 -289
  275. package/dist/tdd-verification-evidence.d.ts +0 -17
  276. package/dist/tdd-verification-evidence.js +0 -122
  277. package/dist/track-heuristics.d.ts +0 -27
  278. package/dist/track-heuristics.js +0 -154
  279. package/dist/util/slice-id.d.ts +0 -58
  280. package/dist/util/slice-id.js +0 -89
  281. package/dist/worktree-manager.d.ts +0 -20
  282. package/dist/worktree-manager.js +0 -108
@@ -1,93 +0,0 @@
1
- import path from "node:path";
2
- import { RUNTIME_ROOT } from "../constants.js";
3
- import { clampEarlyLoopStatusForWrite, computeEarlyLoopStatus, formatEarlyLoopStatusLine, isEarlyLoopStage } from "../early-loop.js";
4
- import { writeFileSafe } from "../fs-utils.js";
5
- import { readFlowState } from "../runs.js";
6
- function parseArgs(tokens) {
7
- const args = { json: false, quiet: false, write: true };
8
- for (let index = 0; index < tokens.length; index += 1) {
9
- const token = tokens[index];
10
- const nextToken = tokens[index + 1];
11
- if (token === "--json") {
12
- args.json = true;
13
- continue;
14
- }
15
- if (token === "--quiet") {
16
- args.quiet = true;
17
- continue;
18
- }
19
- if (token === "--write") {
20
- args.write = true;
21
- continue;
22
- }
23
- if (token === "--no-write") {
24
- args.write = false;
25
- continue;
26
- }
27
- if (token === "--stage") {
28
- if (!nextToken || nextToken.startsWith("--")) {
29
- throw new Error("--stage requires a value: brainstorm | scope | design");
30
- }
31
- if (!isEarlyLoopStage(nextToken)) {
32
- throw new Error("--stage must be one of: brainstorm, scope, design");
33
- }
34
- args.stage = nextToken;
35
- index += 1;
36
- continue;
37
- }
38
- if (token.startsWith("--stage=")) {
39
- const stageRaw = token.slice("--stage=".length);
40
- if (!isEarlyLoopStage(stageRaw)) {
41
- throw new Error("--stage must be one of: brainstorm, scope, design");
42
- }
43
- args.stage = stageRaw;
44
- continue;
45
- }
46
- if (token === "--run-id") {
47
- if (!nextToken || nextToken.startsWith("--")) {
48
- throw new Error("--run-id requires a value.");
49
- }
50
- args.runId = nextToken.trim();
51
- index += 1;
52
- continue;
53
- }
54
- if (token.startsWith("--run-id=")) {
55
- args.runId = token.slice("--run-id=".length).trim();
56
- continue;
57
- }
58
- throw new Error(`Unknown early-loop-status flag: ${token}`);
59
- }
60
- return args;
61
- }
62
- function stateDir(projectRoot) {
63
- return path.join(projectRoot, RUNTIME_ROOT, "state");
64
- }
65
- export async function runEarlyLoopStatusCommand(projectRoot, argv, io) {
66
- const args = parseArgs(argv);
67
- const flow = await readFlowState(projectRoot).catch(() => null);
68
- const stage = args.stage ?? flow?.currentStage;
69
- if (!isEarlyLoopStage(stage)) {
70
- io.stderr.write("cclaw internal early-loop-status: current stage is not an early-loop stage. Pass --stage=brainstorm|scope|design.\n");
71
- return 1;
72
- }
73
- const runId = (args.runId ?? flow?.activeRunId ?? "active").trim() || "active";
74
- let status = await computeEarlyLoopStatus(stage, runId, path.join(stateDir(projectRoot), "early-loop-log.jsonl"));
75
- const persisted = clampEarlyLoopStatusForWrite(status);
76
- if (persisted.clampedFrom !== null) {
77
- io.stderr.write(`cclaw internal early-loop-status: early-loop iteration ${persisted.clampedFrom} exceeds maxIterations ${status.maxIterations}; clamping before write.\n`);
78
- status = persisted.status;
79
- }
80
- if (args.write) {
81
- const target = path.join(stateDir(projectRoot), "early-loop.json");
82
- await writeFileSafe(target, `${JSON.stringify(status, null, 2)}\n`);
83
- }
84
- if (!args.quiet) {
85
- if (args.json) {
86
- io.stdout.write(`${JSON.stringify(status, null, 2)}\n`);
87
- }
88
- else {
89
- io.stdout.write(`${formatEarlyLoopStatusLine(status)}\n`);
90
- }
91
- }
92
- return 0;
93
- }
@@ -1,7 +0,0 @@
1
- import type { Writable } from "node:stream";
2
- interface InternalIo {
3
- stdout: Writable;
4
- stderr: Writable;
5
- }
6
- export declare function runEnvelopeValidateCommand(_projectRoot: string, tokens: string[], io: InternalIo): Promise<number>;
7
- export {};
@@ -1,66 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import { parseSkillEnvelope, validateSkillEnvelope } from "../content/stage-schema.js";
3
- function parseArgs(tokens) {
4
- const args = { stdin: false, quiet: false };
5
- for (const token of tokens) {
6
- if (token === "--stdin") {
7
- args.stdin = true;
8
- continue;
9
- }
10
- if (token === "--quiet") {
11
- args.quiet = true;
12
- continue;
13
- }
14
- if (token.startsWith("--json=")) {
15
- args.json = token.replace("--json=", "");
16
- continue;
17
- }
18
- if (token.startsWith("--file=")) {
19
- args.file = token.replace("--file=", "");
20
- continue;
21
- }
22
- throw new Error(`Unknown flag for envelope-validate: ${token}`);
23
- }
24
- return args;
25
- }
26
- async function readStdin() {
27
- const chunks = [];
28
- for await (const chunk of process.stdin) {
29
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
30
- }
31
- return Buffer.concat(chunks).toString("utf8");
32
- }
33
- export async function runEnvelopeValidateCommand(_projectRoot, tokens, io) {
34
- const args = parseArgs(tokens);
35
- let raw = "";
36
- if (args.json !== undefined) {
37
- raw = args.json;
38
- }
39
- else if (args.file !== undefined) {
40
- raw = await fs.readFile(args.file, "utf8");
41
- }
42
- else if (args.stdin) {
43
- raw = await readStdin();
44
- }
45
- else {
46
- throw new Error("Provide one source: --json=<payload> | --file=<path> | --stdin");
47
- }
48
- const parsed = parseSkillEnvelope(raw);
49
- if (parsed) {
50
- if (!args.quiet) {
51
- io.stdout.write(`${JSON.stringify(parsed, null, 2)}\n`);
52
- }
53
- return 0;
54
- }
55
- let candidate;
56
- try {
57
- candidate = JSON.parse(raw);
58
- }
59
- catch (error) {
60
- io.stderr.write(`Invalid JSON: ${error instanceof Error ? error.message : String(error)}\n`);
61
- return 1;
62
- }
63
- const validation = validateSkillEnvelope(candidate);
64
- io.stderr.write(`Invalid envelope: ${validation.errors.join(" ")}\n`);
65
- return 1;
66
- }
@@ -1,20 +0,0 @@
1
- import type { Writable } from "node:stream";
2
- interface InternalIo {
3
- stdout: Writable;
4
- stderr: Writable;
5
- }
6
- export interface FlowStateRepairArgs {
7
- reason: string;
8
- json: boolean;
9
- quiet: boolean;
10
- /**
11
- * when true, normalize `state/early-loop.json` to the canonical
12
- * shape derived from `early-loop-log.jsonl`. Lets operators recover from
13
- * legacy hand-written `early-loop.json` files that drifted from the
14
- * source-of-truth log.
15
- */
16
- earlyLoop: boolean;
17
- }
18
- export declare function parseFlowStateRepairArgs(tokens: string[]): FlowStateRepairArgs;
19
- export declare function runFlowStateRepair(projectRoot: string, args: FlowStateRepairArgs, io: InternalIo): Promise<number>;
20
- export {};
@@ -1,104 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { RUNTIME_ROOT } from "../constants.js";
4
- import { clampEarlyLoopStatusForWrite, computeEarlyLoopStatus, isEarlyLoopStage } from "../early-loop.js";
5
- import { writeFileSafe } from "../fs-utils.js";
6
- import { repairFlowStateGuard } from "../run-persistence.js";
7
- import { readFlowState } from "../runs.js";
8
- export function parseFlowStateRepairArgs(tokens) {
9
- let reason;
10
- let json = false;
11
- let quiet = false;
12
- let earlyLoop = false;
13
- for (let i = 0; i < tokens.length; i += 1) {
14
- const token = tokens[i];
15
- const nextToken = tokens[i + 1];
16
- if (token === "--json") {
17
- json = true;
18
- continue;
19
- }
20
- if (token === "--quiet") {
21
- quiet = true;
22
- continue;
23
- }
24
- if (token === "--early-loop") {
25
- earlyLoop = true;
26
- continue;
27
- }
28
- if (token === "--reason") {
29
- if (!nextToken || nextToken.startsWith("--")) {
30
- throw new Error("--reason requires a short slug value.");
31
- }
32
- reason = nextToken.trim();
33
- i += 1;
34
- continue;
35
- }
36
- if (token.startsWith("--reason=")) {
37
- reason = token.slice("--reason=".length).trim();
38
- continue;
39
- }
40
- throw new Error(`Unknown flag for internal flow-state-repair: ${token}`);
41
- }
42
- if (!reason || reason.length === 0) {
43
- throw new Error("internal flow-state-repair requires --reason=<slug> (e.g. --reason=manual_edit_recovery).");
44
- }
45
- return { reason, json, quiet, earlyLoop };
46
- }
47
- async function repairEarlyLoopFile(projectRoot, io) {
48
- const flow = await readFlowState(projectRoot).catch(() => null);
49
- if (!flow) {
50
- return { performed: false, skipped: "flow-state-unreadable" };
51
- }
52
- const stage = flow.currentStage;
53
- if (!isEarlyLoopStage(stage)) {
54
- return { performed: false, skipped: `current-stage-${stage}-not-early-loop` };
55
- }
56
- const runId = flow.activeRunId.trim();
57
- if (runId.length === 0) {
58
- io.stderr.write("cclaw internal flow-state-repair --early-loop: active run has no runId; cannot derive canonical early-loop.json.\n");
59
- return { performed: false, skipped: "missing-active-runId" };
60
- }
61
- const stateDir = path.join(projectRoot, RUNTIME_ROOT, "state");
62
- const logPath = path.join(stateDir, "early-loop-log.jsonl");
63
- const status = await computeEarlyLoopStatus(stage, runId, logPath);
64
- const persisted = clampEarlyLoopStatusForWrite(status);
65
- const finalStatus = persisted.status;
66
- const target = path.join(stateDir, "early-loop.json");
67
- await writeFileSafe(target, `${JSON.stringify(finalStatus, null, 2)}\n`);
68
- return {
69
- performed: true,
70
- stage,
71
- runId,
72
- iteration: finalStatus.iteration,
73
- openConcernCount: finalStatus.openConcerns.length
74
- };
75
- }
76
- export async function runFlowStateRepair(projectRoot, args, io) {
77
- const result = await repairFlowStateGuard(projectRoot, args.reason);
78
- const logRel = path.relative(projectRoot, result.repairLogPath).replace(/\\/gu, "/");
79
- const guardRel = path.relative(projectRoot, result.guardPath).replace(/\\/gu, "/");
80
- let earlyLoopOutcome = null;
81
- if (args.earlyLoop) {
82
- earlyLoopOutcome = await repairEarlyLoopFile(projectRoot, io);
83
- }
84
- void fs;
85
- const payload = {
86
- ok: true,
87
- command: "flow-state-repair",
88
- reason: args.reason,
89
- sidecar: result.sidecar,
90
- guardPath: guardRel,
91
- repairLogPath: logRel,
92
- completedStageMetaBackfilled: result.completedStageMetaBackfilled,
93
- earlyLoop: earlyLoopOutcome,
94
- runtimeRoot: RUNTIME_ROOT
95
- };
96
- if (args.json) {
97
- io.stdout.write(`${JSON.stringify(payload)}\n`);
98
- return 0;
99
- }
100
- if (!args.quiet) {
101
- io.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
102
- }
103
- return 0;
104
- }
@@ -1,190 +0,0 @@
1
- import type { Writable } from "node:stream";
2
- interface InternalIo {
3
- stdout: Writable;
4
- stderr: Writable;
5
- }
6
- /**
7
- * split a large `05-plan.md` Implementation Units section
8
- * into wave-NN.md sub-files so an executor can carry one wave at a time
9
- * without re-reading the whole plan.
10
- *
11
- * Threshold contract:
12
- * - total units < SMALL_PLAN_THRESHOLD → no-op, exit 0.
13
- * - total units >= SMALL_PLAN_THRESHOLD → split into waves of `--wave-size`
14
- * (default 25).
15
- *
16
- * Files written:
17
- * - `<artifacts-dir>/wave-plans/wave-NN.md` per wave (1-indexed).
18
- * - In-place update to `05-plan.md` adding (or refreshing) a
19
- * `## Wave Plans` section between
20
- * `<!-- wave-split-managed-start -->` and `<!-- wave-split-managed-end -->`
21
- * markers. Outside-marker content is preserved verbatim.
22
- *
23
- * `--dry-run` prints the plan but does not write. `--force` overwrites
24
- * existing wave files; without it, the command refuses to clobber.
25
- */
26
- export interface PlanSplitWavesArgs {
27
- waveSize: number;
28
- dryRun: boolean;
29
- force: boolean;
30
- json: boolean;
31
- }
32
- export declare const PLAN_SPLIT_DEFAULT_WAVE_SIZE = 5;
33
- export declare const PLAN_SPLIT_SMALL_PLAN_THRESHOLD = 50;
34
- /** Member line in Parallel Execution Plan or wave-NN.md */
35
- export interface ParsedParallelWaveMember {
36
- sliceId: string;
37
- unitId: string;
38
- }
39
- export interface ParsedParallelWave {
40
- waveId: string;
41
- members: ParsedParallelWaveMember[];
42
- }
43
- export declare class WavePlanDuplicateSliceError extends Error {
44
- constructor(message: string);
45
- }
46
- export declare class WavePlanMergeConflictError extends Error {
47
- constructor(message: string);
48
- }
49
- /**
50
- * Raw body between parallel execution managed markers (no markers included).
51
- */
52
- export declare function extractParallelExecutionManagedBody(planMarkdown: string): string | null;
53
- /**
54
- * Members list after `Members:` in Parallel Execution Plan / wave-NN headers.
55
- * Supports markdown bold `**Members:**` (colon between Members and closing `**`)
56
- * and plain `Members:`.
57
- */
58
- export declare function extractMembersListFromLine(trimmedLine: string): string | null;
59
- /**
60
- * Extract a `(sliceId, unitId)` pair from a markdown table data row
61
- * whose first column is an `S-NN` token. Used by the wave parser to
62
- * recognize the table-format Parallel Execution Plan alongside (or
63
- * instead of) the `**Members:**` bullet line.
64
- *
65
- * Rules:
66
- * - The line must start with `|` (after trimming).
67
- * - Column 1 (after stripping markdown noise) may be either a slice id
68
- * (`S-N`) or an implementation-unit id (`U-N`). Unit ids derive their
69
- * execution slice as `S-N`, which lets 7.7+ plans schedule feature-atomic
70
- * units without inventing a tiny `T-NNN` row per dispatch lane. Header rows
71
- * (`| sliceId | …`, `| unit | …`) and separator rows (`|---|---|…`) are
72
- * silently skipped.
73
- * - Column 2, when present and non-empty, becomes the `unitId`
74
- * verbatim (after stripping whitespace + backticks/quotes/brackets).
75
- * This lets authors record task ids (`T-010`, `T-008a`, …) in the
76
- * `unit` column without forcing a `U-NN` derivation.
77
- * - When column 2 is absent or empty, fall back to the
78
- * `S-NN → U-NN` derivation so the `**Members:**` parser path stays
79
- * bit-identical for non-table plans.
80
- */
81
- export declare function parseTableRowMember(trimmedLine: string): ParsedParallelWaveMember | null;
82
- /**
83
- * Parse `## Parallel Execution Plan` managed block for wave headings and
84
- * member declarations. Recognizes BOTH the `**Members:**` / `Members:`
85
- * line shape AND the markdown-table shape
86
- * (`| sliceId | unit | dependsOn | …`).
87
- *
88
- * Wave headings accepted (case-insensitive, trailing text allowed):
89
- * - `### Wave 04`
90
- * - `### Wave W-04`
91
- * - `### Wave W-04 — after fan-in W-03 (5 lanes …)`
92
- *
93
- * Within a single wave the parser dedupes by `sliceId`: if the same
94
- * slice appears in both `**Members:**` and a table row, the first
95
- * occurrence wins (line-order). Cross-wave duplicates still throw
96
- * `WavePlanDuplicateSliceError`.
97
- *
98
- * Malformed member tokens are skipped. Empty waves (heading present
99
- * but neither a Members line nor any matching `| S-NN |` row found
100
- * before the next heading) are RETURNED with `members: []` so callers
101
- * can surface the boundary; classification is up to the caller.
102
- */
103
- export declare function parseParallelExecutionPlanWaves(planMarkdown: string): ParsedParallelWave[];
104
- /**
105
- * Parse a single wave-NN.md: prefer a `Members:` line in the header; otherwise
106
- * collect distinct S-N tokens in the first lines (legacy).
107
- */
108
- export declare function parseWavePlanFileBody(body: string, waveId: string): ParsedParallelWave;
109
- export declare function parseWavePlanDirectory(artifactsDir: string): Promise<ParsedParallelWave[]>;
110
- /**
111
- * Merge wave definitions: managed Parallel Execution Plan first, then wave-NN.md.
112
- * Same slice must map to the same wave id and unit id in both sources or a
113
- * `WavePlanMergeConflictError` is thrown.
114
- */
115
- export declare function mergeParallelWaveDefinitions(primary: ParsedParallelWave[], secondary: ParsedParallelWave[]): ParsedParallelWave[];
116
- /**
117
- * One-line operator hint after sync when a multi-member wave exists.
118
- */
119
- export declare function formatNextParallelWaveSyncHint(merged: ParsedParallelWave[]): string | null;
120
- export interface ParsedImplementationUnit {
121
- id: string;
122
- /**
123
- * The full markdown body of this unit, starting at the
124
- * `### Implementation Unit U-N` heading and ending right before the
125
- * next unit heading (or the next `## ` H2, or end of file).
126
- */
127
- body: string;
128
- /** Repo-relative path declarations from the optional `Files:` line. */
129
- paths: string[];
130
- }
131
- export interface ImplementationUnitParallelFields {
132
- unitId: string;
133
- dependsOn: string[];
134
- claimedPaths: string[];
135
- parallelizable: boolean;
136
- riskTier: "low" | "standard" | "high";
137
- lane?: string;
138
- }
139
- export interface ParseImplementationUnitParallelOptions {
140
- /**
141
- * Continuation: when the plan predates explicit parallel
142
- * bullets, units without a `parallelizable:` line default to serial eligibility
143
- * in the scheduler (`parallelizable: false`).
144
- */
145
- legacyParallelDefaultSerial?: boolean;
146
- }
147
- /**
148
- * Parse parallel-metadata bullets from an implementation unit body.
149
- * Missing keys use conservative defaults (`dependsOn: []`, `parallelizable: true`
150
- * unless `legacyParallelDefaultSerial` is set).
151
- */
152
- export declare function parseImplementationUnitParallelFields(unit: ParsedImplementationUnit, options?: ParseImplementationUnitParallelOptions): ImplementationUnitParallelFields;
153
- /**
154
- * True when the plan has implementation units but any unit is missing
155
- * `dependsOn` / `claimedPaths` / `parallelizable` / `riskTier` bullets.
156
- */
157
- export declare function planArtifactLacksV613ParallelMetadata(planMarkdown: string): boolean;
158
- export declare function compareCanonicalUnitIds(a: string, b: string): number;
159
- /**
160
- * Group implementation units into waves: topological order, then greedy
161
- * placement with disjoint `claimedPaths` and `cap` members per wave.
162
- */
163
- export declare function buildConflictAwareWavesFromUnits(units: ParsedImplementationUnit[], cap: number): ParsedImplementationUnit[][];
164
- export declare function buildParallelExecutionPlanSection(waves: ParsedImplementationUnit[][], cap: number): string;
165
- /**
166
- * Replace or append the managed Parallel Execution Plan block.
167
- */
168
- export declare function upsertParallelExecutionPlanSection(planMarkdown: string, managedBlock: string): string;
169
- /**
170
- * Parse `## Implementation Units` section into individual unit blocks.
171
- * Recognizes the canonical heading shape in the TDD-velocity plan template
172
- * (`### Implementation Unit U-<n>`). Tolerant of `Files:` listed either
173
- * inline or as a `- **Files (...):**` bullet block.
174
- */
175
- export declare function parseImplementationUnits(planMarkdown: string): ParsedImplementationUnit[];
176
- /**
177
- * Pull repo-relative paths from a `Files:` line or the `Files (...)` bullet
178
- * block. Both shapes appear in the wild; the parser extracts after the colon
179
- * and splits on commas. Empty/whitespace items are dropped.
180
- */
181
- export declare function extractPathsLine(unitBody: string): string[];
182
- export declare function parsePlanSplitWavesArgs(tokens: string[]): PlanSplitWavesArgs;
183
- /**
184
- * Replace any existing managed Wave Plans block with the new one, or append
185
- * it at the end of the file when no markers are present yet. The helper
186
- * never touches text outside the markers.
187
- */
188
- export declare function upsertWavePlansSection(planMarkdown: string, managedBlock: string): string;
189
- export declare function runPlanSplitWaves(projectRoot: string, args: PlanSplitWavesArgs, io: InternalIo): Promise<number>;
190
- export {};