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,7 +0,0 @@
1
- import type { Writable } from "node:stream";
2
- interface InternalIo {
3
- stdout: Writable;
4
- stderr: Writable;
5
- }
6
- export declare function runTddRedEvidenceCommand(projectRoot: string, tokens: string[], io: InternalIo): Promise<number>;
7
- export {};
@@ -1,153 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { RUNTIME_ROOT } from "../constants.js";
4
- import { readFlowState } from "../runs.js";
5
- import { hasFailingTestForPath, parseTddCycleLog, pathMatchesTarget } from "../tdd-cycle.js";
6
- // normalizePath and the path matcher live in src/tdd-cycle.ts so all
7
- // TDD-related guards (internal CLI, runtime hook, unit tests) agree on
8
- // what "path X matches recorded file Y" means.
9
- function parseArgs(tokens) {
10
- const args = { quiet: false };
11
- for (const token of tokens) {
12
- if (token === "--quiet") {
13
- args.quiet = true;
14
- continue;
15
- }
16
- if (token.startsWith("--path=")) {
17
- const value = token.slice("--path=".length).trim();
18
- if (!value) {
19
- throw new Error("--path must not be empty.");
20
- }
21
- args.targetPath = value;
22
- continue;
23
- }
24
- if (token.startsWith("--run-id=")) {
25
- const value = token.slice("--run-id=".length).trim();
26
- if (value) {
27
- args.runId = value;
28
- }
29
- continue;
30
- }
31
- throw new Error(`Unknown flag for tdd-red-evidence: ${token}`);
32
- }
33
- if (!args.targetPath) {
34
- throw new Error("Missing required flag: --path=<production-file-path>");
35
- }
36
- return args;
37
- }
38
- function parseAutoEvidence(text) {
39
- const out = [];
40
- for (const rawLine of text.split(/\r?\n/gu)) {
41
- const line = rawLine.trim();
42
- if (!line)
43
- continue;
44
- try {
45
- const parsed = JSON.parse(line);
46
- const exitCode = parsed.exitCode;
47
- if (typeof exitCode !== "number" || exitCode === 0)
48
- continue;
49
- const runId = typeof parsed.runId === "string" && parsed.runId.length > 0
50
- ? parsed.runId
51
- : "active";
52
- const rawPaths = Array.isArray(parsed.paths)
53
- ? parsed.paths
54
- : typeof parsed.path === "string"
55
- ? [parsed.path]
56
- : [];
57
- const paths = rawPaths
58
- .filter((value) => typeof value === "string")
59
- .map((value) => value.trim())
60
- .filter((value) => value.length > 0);
61
- if (paths.length === 0)
62
- continue;
63
- out.push({
64
- runId,
65
- exitCode,
66
- paths
67
- });
68
- }
69
- catch {
70
- // ignore malformed lines
71
- }
72
- }
73
- return out;
74
- }
75
- function hasFailingAutoEvidenceForPath(entries, targetPath, options = {}) {
76
- for (const entry of entries) {
77
- if (options.runId && entry.runId !== options.runId)
78
- continue;
79
- for (const filePath of entry.paths) {
80
- if (pathMatchesTarget(filePath, targetPath))
81
- return true;
82
- }
83
- }
84
- return false;
85
- }
86
- export async function runTddRedEvidenceCommand(projectRoot, tokens, io) {
87
- const args = parseArgs(tokens);
88
- const flowState = await readFlowState(projectRoot).catch(() => null);
89
- // Strict runId scoping: a previous implementation fell back to no
90
- // filter when both `--runId` and `flowState.activeRunId` were missing,
91
- // which let evidence rows from past runs satisfy the current check
92
- // (false positive). Now: require an explicit or inferred runId or
93
- // fail loud so the caller cannot silently inherit cross-run state.
94
- const effectiveRunId = args.runId ?? flowState?.activeRunId;
95
- if (!effectiveRunId || effectiveRunId.trim().length === 0) {
96
- const reason = "tdd-red-evidence: cannot scope check — no --runId provided and " +
97
- "flow-state.json has no activeRunId. Pass --runId=<id> explicitly " +
98
- "or run `npx cclaw-cli sync` to reconcile state.";
99
- if (!args.quiet) {
100
- io.stdout.write(`${JSON.stringify({
101
- ok: false,
102
- path: args.targetPath,
103
- runId: null,
104
- error: reason,
105
- sources: { tddCycleLog: false, autoEvidence: false }
106
- }, null, 2)}\n`);
107
- }
108
- else {
109
- io.stderr.write(`${reason}\n`);
110
- }
111
- return 2;
112
- }
113
- const tddLogPath = path.join(projectRoot, RUNTIME_ROOT, "state", "tdd-cycle-log.jsonl");
114
- const autoEvidencePath = path.join(projectRoot, RUNTIME_ROOT, "state", "tdd-red-evidence.jsonl");
115
- let cycleLogHasRed = false;
116
- let autoEvidenceHasRed = false;
117
- try {
118
- const raw = await fs.readFile(tddLogPath, "utf8");
119
- // Strict parse: drop malformed/underspecified rows rather than
120
- // backfilling runId=active / stage=tdd defaults, which used to
121
- // silently glue foreign entries to the current run.
122
- const entries = parseTddCycleLog(raw, { strict: true });
123
- cycleLogHasRed = hasFailingTestForPath(entries, args.targetPath, {
124
- runId: effectiveRunId
125
- });
126
- }
127
- catch {
128
- cycleLogHasRed = false;
129
- }
130
- try {
131
- const raw = await fs.readFile(autoEvidencePath, "utf8");
132
- const entries = parseAutoEvidence(raw);
133
- autoEvidenceHasRed = hasFailingAutoEvidenceForPath(entries, args.targetPath, {
134
- runId: effectiveRunId
135
- });
136
- }
137
- catch {
138
- autoEvidenceHasRed = false;
139
- }
140
- const hasRed = cycleLogHasRed || autoEvidenceHasRed;
141
- if (!args.quiet) {
142
- io.stdout.write(`${JSON.stringify({
143
- ok: hasRed,
144
- path: args.targetPath,
145
- runId: effectiveRunId,
146
- sources: {
147
- tddCycleLog: cycleLogHasRed,
148
- autoEvidence: autoEvidenceHasRed
149
- }
150
- }, null, 2)}\n`);
151
- }
152
- return hasRed ? 0 : 2;
153
- }
@@ -1,62 +0,0 @@
1
- import { type FlowStage } from "../types.js";
2
- import type { Writable } from "node:stream";
3
- interface InternalIo {
4
- stdout: Writable;
5
- stderr: Writable;
6
- }
7
- export declare const WAIVER_TOKEN_DEFAULT_TTL_MINUTES = 30;
8
- export declare const WAIVER_TOKEN_MAX_TTL_MINUTES = 120;
9
- export declare const WAIVER_REASON_PATTERN: RegExp;
10
- export interface WaiverRecord {
11
- token: string;
12
- stage: FlowStage;
13
- reason: string;
14
- issuedAt: string;
15
- expiresAt: string;
16
- consumedAt: string | null;
17
- issuerSubsystem: string;
18
- consumedBy?: string;
19
- }
20
- export interface WaiverLedger {
21
- schemaVersion: number;
22
- pending: WaiverRecord[];
23
- consumed: WaiverRecord[];
24
- }
25
- export interface IssueWaiverTokenOptions {
26
- stage: FlowStage;
27
- reason: string;
28
- expiresInMinutes?: number;
29
- issuerSubsystem?: string;
30
- now?: Date;
31
- }
32
- export interface ConsumeWaiverOptions {
33
- stage: FlowStage;
34
- token: string;
35
- consumedBy?: string;
36
- now?: Date;
37
- }
38
- export declare function formatWaiverToken(stage: FlowStage, fingerprint: string, expiresAt: Date): string;
39
- export declare function issueWaiverToken(projectRoot: string, options: IssueWaiverTokenOptions): Promise<WaiverRecord>;
40
- export type ConsumeWaiverFailureReason = "not-found" | "wrong-stage" | "expired" | "already-consumed";
41
- export interface ConsumeWaiverSuccess {
42
- ok: true;
43
- record: WaiverRecord;
44
- }
45
- export interface ConsumeWaiverFailure {
46
- ok: false;
47
- reason: ConsumeWaiverFailureReason;
48
- record?: WaiverRecord;
49
- detail: string;
50
- }
51
- export type ConsumeWaiverResult = ConsumeWaiverSuccess | ConsumeWaiverFailure;
52
- export declare function consumeWaiverToken(projectRoot: string, options: ConsumeWaiverOptions): Promise<ConsumeWaiverResult>;
53
- export interface WaiverGrantArgs {
54
- stage: FlowStage;
55
- reason: string;
56
- ttlMinutes: number;
57
- json: boolean;
58
- quiet: boolean;
59
- }
60
- export declare function parseWaiverGrantArgs(tokens: string[]): WaiverGrantArgs;
61
- export declare function runWaiverGrant(projectRoot: string, args: WaiverGrantArgs, io: InternalIo): Promise<number>;
62
- export {};
@@ -1,294 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import fs from "node:fs/promises";
3
- import path from "node:path";
4
- import { RUNTIME_ROOT } from "../constants.js";
5
- import { ensureDir, exists, withDirectoryLock, writeFileSafe } from "../fs-utils.js";
6
- import { FLOW_STAGES } from "../types.js";
7
- /**
8
- * Tokens issued by `cclaw internal waiver-grant` live under the runtime
9
- * root. The ledger also tracks `consumed[]` entries so consumption is
10
- * traceable and one-shot.
11
- */
12
- const WAIVER_LEDGER_REL_PATH = `${RUNTIME_ROOT}/.waivers.json`;
13
- const WAIVER_LEDGER_LOCK_REL_PATH = `${RUNTIME_ROOT}/.waivers.json.lock`;
14
- export const WAIVER_TOKEN_DEFAULT_TTL_MINUTES = 30;
15
- export const WAIVER_TOKEN_MAX_TTL_MINUTES = 120;
16
- export const WAIVER_REASON_PATTERN = /^[a-z][a-z0-9_-]{2,}$/u;
17
- const WAIVER_TOKEN_PREFIX = "WV";
18
- const WAIVER_LEDGER_SCHEMA_VERSION = 1;
19
- function waiverLedgerPath(projectRoot) {
20
- return path.join(projectRoot, WAIVER_LEDGER_REL_PATH);
21
- }
22
- function waiverLedgerLockPath(projectRoot) {
23
- return path.join(projectRoot, WAIVER_LEDGER_LOCK_REL_PATH);
24
- }
25
- function sanitizeWaiverRecord(value) {
26
- if (!value || typeof value !== "object" || Array.isArray(value))
27
- return null;
28
- const row = value;
29
- const token = typeof row.token === "string" ? row.token : "";
30
- const stage = row.stage;
31
- const reason = typeof row.reason === "string" ? row.reason : "";
32
- const issuedAt = typeof row.issuedAt === "string" ? row.issuedAt : "";
33
- const expiresAt = typeof row.expiresAt === "string" ? row.expiresAt : "";
34
- const consumedAt = typeof row.consumedAt === "string" ? row.consumedAt : null;
35
- const issuerSubsystem = typeof row.issuerSubsystem === "string" ? row.issuerSubsystem : "";
36
- const consumedBy = typeof row.consumedBy === "string" ? row.consumedBy : undefined;
37
- if (token.length === 0 ||
38
- typeof stage !== "string" ||
39
- !FLOW_STAGES.includes(stage) ||
40
- reason.length === 0 ||
41
- issuedAt.length === 0 ||
42
- expiresAt.length === 0 ||
43
- issuerSubsystem.length === 0) {
44
- return null;
45
- }
46
- return {
47
- token,
48
- stage: stage,
49
- reason,
50
- issuedAt,
51
- expiresAt,
52
- consumedAt,
53
- issuerSubsystem,
54
- ...(consumedBy ? { consumedBy } : {})
55
- };
56
- }
57
- async function readWaiverLedger(projectRoot) {
58
- const statePath = waiverLedgerPath(projectRoot);
59
- if (!(await exists(statePath))) {
60
- return { schemaVersion: WAIVER_LEDGER_SCHEMA_VERSION, pending: [], consumed: [] };
61
- }
62
- let raw;
63
- try {
64
- raw = await fs.readFile(statePath, "utf8");
65
- }
66
- catch {
67
- return { schemaVersion: WAIVER_LEDGER_SCHEMA_VERSION, pending: [], consumed: [] };
68
- }
69
- let parsed;
70
- try {
71
- parsed = JSON.parse(raw);
72
- }
73
- catch {
74
- return { schemaVersion: WAIVER_LEDGER_SCHEMA_VERSION, pending: [], consumed: [] };
75
- }
76
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
77
- return { schemaVersion: WAIVER_LEDGER_SCHEMA_VERSION, pending: [], consumed: [] };
78
- }
79
- const typed = parsed;
80
- const pending = Array.isArray(typed.pending)
81
- ? typed.pending
82
- .map((item) => sanitizeWaiverRecord(item))
83
- .filter((item) => item !== null)
84
- : [];
85
- const consumed = Array.isArray(typed.consumed)
86
- ? typed.consumed
87
- .map((item) => sanitizeWaiverRecord(item))
88
- .filter((item) => item !== null)
89
- : [];
90
- return { schemaVersion: WAIVER_LEDGER_SCHEMA_VERSION, pending, consumed };
91
- }
92
- async function writeWaiverLedger(projectRoot, ledger) {
93
- const next = {
94
- schemaVersion: WAIVER_LEDGER_SCHEMA_VERSION,
95
- pending: ledger.pending,
96
- consumed: ledger.consumed
97
- };
98
- await writeFileSafe(waiverLedgerPath(projectRoot), `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
99
- }
100
- function formatExpiresSlug(expiresAt) {
101
- // Minute-precision slug for the token: e.g. `20260502T220500Z`
102
- return expiresAt.toISOString().replace(/[-:]/gu, "").replace(/\..+$/u, "").concat("Z");
103
- }
104
- function minuteFingerprint(stage, reason, issuedAt) {
105
- const payload = `${stage}|${reason}|${issuedAt.toISOString()}|${Math.random().toString(16).slice(2, 12)}`;
106
- return createHash("sha256").update(payload, "utf8").digest("hex").slice(0, 8);
107
- }
108
- export function formatWaiverToken(stage, fingerprint, expiresAt) {
109
- return `${WAIVER_TOKEN_PREFIX}-${stage}-${fingerprint}-${formatExpiresSlug(expiresAt)}`;
110
- }
111
- export async function issueWaiverToken(projectRoot, options) {
112
- if (!FLOW_STAGES.includes(options.stage)) {
113
- throw new Error(`waiver-grant: --stage must be one of ${FLOW_STAGES.join(", ")}.`);
114
- }
115
- const reason = options.reason.trim();
116
- if (reason.length === 0) {
117
- throw new Error("waiver-grant: --reason is required.");
118
- }
119
- if (!WAIVER_REASON_PATTERN.test(reason)) {
120
- throw new Error("waiver-grant: --reason must match /^[a-z][a-z0-9_-]{2,}$/ (short lowercase slug, e.g. architect_unavailable).");
121
- }
122
- const ttlRaw = typeof options.expiresInMinutes === "number" && Number.isFinite(options.expiresInMinutes)
123
- ? Math.floor(options.expiresInMinutes)
124
- : WAIVER_TOKEN_DEFAULT_TTL_MINUTES;
125
- if (ttlRaw < 1) {
126
- throw new Error("waiver-grant: --ttl must be >= 1 minute.");
127
- }
128
- if (ttlRaw > WAIVER_TOKEN_MAX_TTL_MINUTES) {
129
- throw new Error(`waiver-grant: --ttl must be <= ${WAIVER_TOKEN_MAX_TTL_MINUTES} minutes.`);
130
- }
131
- const issuedAtDate = options.now ?? new Date();
132
- const expiresAtDate = new Date(issuedAtDate.getTime() + ttlRaw * 60 * 1000);
133
- const fingerprint = minuteFingerprint(options.stage, reason, issuedAtDate);
134
- const token = formatWaiverToken(options.stage, fingerprint, expiresAtDate);
135
- const record = {
136
- token,
137
- stage: options.stage,
138
- reason,
139
- issuedAt: issuedAtDate.toISOString(),
140
- expiresAt: expiresAtDate.toISOString(),
141
- consumedAt: null,
142
- issuerSubsystem: options.issuerSubsystem?.trim() || "cli"
143
- };
144
- await ensureDir(path.dirname(waiverLedgerPath(projectRoot)));
145
- await withDirectoryLock(waiverLedgerLockPath(projectRoot), async () => {
146
- const ledger = await readWaiverLedger(projectRoot);
147
- ledger.pending.push(record);
148
- await writeWaiverLedger(projectRoot, ledger);
149
- });
150
- return record;
151
- }
152
- export async function consumeWaiverToken(projectRoot, options) {
153
- const token = options.token.trim();
154
- if (token.length === 0) {
155
- return {
156
- ok: false,
157
- reason: "not-found",
158
- detail: "waiver token is required"
159
- };
160
- }
161
- const now = (options.now ?? new Date()).getTime();
162
- return withDirectoryLock(waiverLedgerLockPath(projectRoot), async () => {
163
- const ledger = await readWaiverLedger(projectRoot);
164
- const pendingIdx = ledger.pending.findIndex((entry) => entry.token === token);
165
- const consumedMatch = ledger.consumed.find((entry) => entry.token === token);
166
- if (pendingIdx < 0) {
167
- if (consumedMatch) {
168
- return {
169
- ok: false,
170
- reason: "already-consumed",
171
- record: consumedMatch,
172
- detail: `waiver token ${token} was already consumed at ${consumedMatch.consumedAt ?? "unknown time"}`
173
- };
174
- }
175
- return {
176
- ok: false,
177
- reason: "not-found",
178
- detail: `no pending waiver token "${token}" found in ${WAIVER_LEDGER_REL_PATH}`
179
- };
180
- }
181
- const record = ledger.pending[pendingIdx];
182
- if (record.stage !== options.stage) {
183
- return {
184
- ok: false,
185
- reason: "wrong-stage",
186
- record,
187
- detail: `waiver token ${token} was issued for stage "${record.stage}", not "${options.stage}"`
188
- };
189
- }
190
- const expiresAt = Date.parse(record.expiresAt);
191
- if (Number.isFinite(expiresAt) && expiresAt < now) {
192
- return {
193
- ok: false,
194
- reason: "expired",
195
- record,
196
- detail: `waiver token ${token} expired at ${record.expiresAt}`
197
- };
198
- }
199
- const consumedAtIso = (options.now ?? new Date()).toISOString();
200
- const consumedRecord = {
201
- ...record,
202
- consumedAt: consumedAtIso,
203
- ...(options.consumedBy ? { consumedBy: options.consumedBy } : {})
204
- };
205
- ledger.pending.splice(pendingIdx, 1);
206
- ledger.consumed.push(consumedRecord);
207
- await writeWaiverLedger(projectRoot, ledger);
208
- return { ok: true, record: consumedRecord };
209
- });
210
- }
211
- export function parseWaiverGrantArgs(tokens) {
212
- let stage;
213
- let reason;
214
- let ttlMinutes = WAIVER_TOKEN_DEFAULT_TTL_MINUTES;
215
- let json = false;
216
- let quiet = false;
217
- for (let i = 0; i < tokens.length; i += 1) {
218
- const token = tokens[i];
219
- const nextToken = tokens[i + 1];
220
- const readValue = (flag) => {
221
- if (token.startsWith(`${flag}=`))
222
- return token.slice(flag.length + 1);
223
- if (token === flag && nextToken && !nextToken.startsWith("--")) {
224
- i += 1;
225
- return nextToken;
226
- }
227
- throw new Error(`${flag} requires a value.`);
228
- };
229
- if (token === "--json") {
230
- json = true;
231
- continue;
232
- }
233
- if (token === "--quiet") {
234
- quiet = true;
235
- continue;
236
- }
237
- if (token === "--stage" || token.startsWith("--stage=")) {
238
- const raw = readValue("--stage").trim();
239
- if (!FLOW_STAGES.includes(raw)) {
240
- throw new Error(`waiver-grant: --stage must be one of ${FLOW_STAGES.join(", ")}.`);
241
- }
242
- stage = raw;
243
- continue;
244
- }
245
- if (token === "--reason" || token.startsWith("--reason=")) {
246
- reason = readValue("--reason").trim();
247
- continue;
248
- }
249
- if (token === "--ttl" || token.startsWith("--ttl=")) {
250
- const raw = readValue("--ttl").trim();
251
- if (!/^[0-9]+$/u.test(raw)) {
252
- throw new Error("waiver-grant: --ttl must be an integer number of minutes.");
253
- }
254
- ttlMinutes = Number(raw);
255
- continue;
256
- }
257
- throw new Error(`Unknown flag for internal waiver-grant: ${token}`);
258
- }
259
- if (!stage) {
260
- throw new Error(`internal waiver-grant requires --stage=<${FLOW_STAGES.join("|")}>.`);
261
- }
262
- if (!reason) {
263
- throw new Error(`internal waiver-grant requires --reason=<short-slug> (e.g. architect_unavailable).`);
264
- }
265
- return { stage, reason, ttlMinutes, json, quiet };
266
- }
267
- export async function runWaiverGrant(projectRoot, args, io) {
268
- const record = await issueWaiverToken(projectRoot, {
269
- stage: args.stage,
270
- reason: args.reason,
271
- expiresInMinutes: args.ttlMinutes,
272
- issuerSubsystem: "cli"
273
- });
274
- if (args.json) {
275
- io.stdout.write(`${JSON.stringify({
276
- ok: true,
277
- command: "waiver-grant",
278
- token: record.token,
279
- stage: record.stage,
280
- reason: record.reason,
281
- issuedAt: record.issuedAt,
282
- expiresAt: record.expiresAt,
283
- ttlMinutes: args.ttlMinutes,
284
- consumption: `cclaw-cli internal advance-stage ${record.stage} --accept-proactive-waiver=${record.token} --accept-proactive-waiver-reason="${record.reason}"`
285
- })}\n`);
286
- return 0;
287
- }
288
- io.stdout.write(`${record.token}\n`);
289
- if (!args.quiet) {
290
- io.stdout.write(`Waiver token issued for stage="${record.stage}" reason="${record.reason}" expires=${record.expiresAt}.\n`);
291
- io.stdout.write(`Consume with: node ${RUNTIME_ROOT}/hooks/stage-complete.mjs ${record.stage} --accept-proactive-waiver=${record.token} --accept-proactive-waiver-reason="${record.reason}"\n`);
292
- }
293
- return 0;
294
- }
@@ -1,74 +0,0 @@
1
- import type { Writable } from "node:stream";
2
- import type { ExecutionTopology } from "../types.js";
3
- interface InternalIo {
4
- stdout: Writable;
5
- stderr: Writable;
6
- }
7
- export interface WaveStatusWaveSummary {
8
- waveId: string;
9
- members: string[];
10
- closedMembers: string[];
11
- openMembers: string[];
12
- readyMembers: string[];
13
- blockedMembers: string[];
14
- status: "closed" | "open" | "partial" | "empty";
15
- }
16
- /**
17
- * 7.7.1 — `controller-inline` is added so the controller knows it must
18
- * fulfil the ready slices in this turn (no slice-builder dispatch). The
19
- * remaining values (`single-slice`, `wave-fanout`, `blocked`, `none`) keep
20
- * their pre-7.7.1 contract.
21
- */
22
- export interface WaveStatusNextDispatch {
23
- waveId: string | null;
24
- readyToDispatch: string[];
25
- pathConflicts: string[];
26
- mode: "single-slice" | "wave-fanout" | "blocked" | "none" | "controller-inline";
27
- topology: Exclude<ExecutionTopology, "auto"> | "none";
28
- topologyReason: string;
29
- maxBuilders: number;
30
- /**
31
- * Optional natural-language hint for the controller, populated when the
32
- * router selects a non-default mode (currently only `inline`).
33
- */
34
- controllerHint?: string;
35
- }
36
- export interface WaveStatusReport {
37
- activeRunId: string;
38
- currentStage: string;
39
- waves: WaveStatusWaveSummary[];
40
- nextDispatch: WaveStatusNextDispatch;
41
- warnings: string[];
42
- }
43
- export interface RunWaveStatusOptions {
44
- /**
45
- * Override the artifacts directory; useful for fixture tests that
46
- * place an `05-plan.md` outside `.cclaw/artifacts`. Defaults to
47
- * `<projectRoot>/.cclaw/artifacts`.
48
- */
49
- artifactsDir?: string;
50
- /**
51
- * Event ingestion mode:
52
- * - auto: prefer live stream file; fallback to delegation-events.jsonl.
53
- * - live: force live stream first; fallback to delegation-events.jsonl with warning.
54
- * - file: skip stream file and use delegation-events.jsonl only.
55
- */
56
- streamMode?: "auto" | "live" | "file";
57
- /**
58
- * Optional absolute stream path override (tests).
59
- */
60
- streamPath?: string;
61
- }
62
- /**
63
- * Deterministic helper for the TDD controller. Reads the managed
64
- * `<!-- parallel-exec-managed-start -->` block from
65
- * `<artifacts-dir>/05-plan.md` plus the `wave-plans/` directory and
66
- * reports waves + the next dispatchable members so the controller does
67
- * NOT have to page through a long plan to find the active wave.
68
- *
69
- * Always exits 0 unless the plan is malformed (no managed block AND no
70
- * wave-plans directory), in which case exit 2 with a structured error.
71
- */
72
- export declare function runWaveStatus(projectRoot: string, options?: RunWaveStatusOptions): Promise<WaveStatusReport>;
73
- export declare function runWaveStatusCommand(projectRoot: string, argv: string[], io: InternalIo): Promise<number>;
74
- export {};