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,391 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import { RUNTIME_ROOT } from "./constants.js";
4
- import { createInitialFlowState } from "./flow-state.js";
5
- import { ensureDir, exists, withDirectoryLock, writeFileSafe } from "./fs-utils.js";
6
- import { readKnowledgeSafely } from "./knowledge-store.js";
7
- import { evaluateRetroGate } from "./retro-gate.js";
8
- import { ensureRunSystem, flowStateLockPathFor, readFlowState, writeFlowState } from "./run-persistence.js";
9
- export const ARCHIVE_DISPOSITIONS = ["completed", "cancelled", "abandoned"];
10
- const ARCHIVE_DIR_REL_PATH = `${RUNTIME_ROOT}/archive`;
11
- const ACTIVE_ARTIFACTS_REL_PATH = `${RUNTIME_ROOT}/artifacts`;
12
- const STATE_DIR_REL_PATH = `${RUNTIME_ROOT}/state`;
13
- /** State filenames explicitly excluded from the archive snapshot. */
14
- const STATE_SNAPSHOT_EXCLUDE = new Set([
15
- ".flow-state.lock",
16
- ".delegation.lock"
17
- ]);
18
- const DELEGATION_LOG_FILE = "delegation-log.json";
19
- const TDD_CYCLE_LOG_FILE = "tdd-cycle-log.jsonl";
20
- const CRITICAL_STATE_SNAPSHOT_FILES = new Set([
21
- "flow-state.json",
22
- DELEGATION_LOG_FILE,
23
- TDD_CYCLE_LOG_FILE
24
- ]);
25
- function archiveRoot(projectRoot) {
26
- return path.join(projectRoot, ARCHIVE_DIR_REL_PATH);
27
- }
28
- function activeArtifactsPath(projectRoot) {
29
- return path.join(projectRoot, ACTIVE_ARTIFACTS_REL_PATH);
30
- }
31
- function stateDirPath(projectRoot) {
32
- return path.join(projectRoot, STATE_DIR_REL_PATH);
33
- }
34
- function archiveLockPath(projectRoot) {
35
- return path.join(projectRoot, RUNTIME_ROOT, "state", ".archive.lock");
36
- }
37
- function compoundCloseoutComplete(state) {
38
- return (state.closeout.compoundCompletedAt !== undefined ||
39
- state.closeout.compoundPromoted > 0 ||
40
- (state.closeout.compoundSkipped === true &&
41
- typeof state.closeout.compoundSkipReason === "string" &&
42
- state.closeout.compoundSkipReason.trim().length > 0));
43
- }
44
- async function snapshotStateDirectory(projectRoot, destinationRoot) {
45
- const sourceDir = stateDirPath(projectRoot);
46
- if (!(await exists(sourceDir))) {
47
- return [];
48
- }
49
- await ensureDir(destinationRoot);
50
- const copied = [];
51
- let entries;
52
- try {
53
- entries = await fs.readdir(sourceDir, { withFileTypes: true });
54
- }
55
- catch {
56
- return [];
57
- }
58
- for (const entry of entries) {
59
- if (STATE_SNAPSHOT_EXCLUDE.has(entry.name))
60
- continue;
61
- if (entry.name.startsWith(".") && !entry.name.endsWith(".json"))
62
- continue;
63
- const from = path.join(sourceDir, entry.name);
64
- const to = path.join(destinationRoot, entry.name);
65
- try {
66
- if (entry.isDirectory()) {
67
- await fs.cp(from, to, { recursive: true });
68
- copied.push(`${entry.name}/`);
69
- }
70
- else if (entry.isFile()) {
71
- await fs.copyFile(from, to);
72
- copied.push(entry.name);
73
- }
74
- }
75
- catch (error) {
76
- if (CRITICAL_STATE_SNAPSHOT_FILES.has(entry.name)) {
77
- const details = error instanceof Error ? error.message : String(error);
78
- throw new Error(`Archive snapshot failed for critical state file "${entry.name}" (${details}).`);
79
- }
80
- // Non-critical snapshot files are best-effort and may be skipped.
81
- }
82
- }
83
- return copied.sort((a, b) => a.localeCompare(b));
84
- }
85
- async function resetCarryoverStateFiles(projectRoot, activeRunId) {
86
- const stateDir = stateDirPath(projectRoot);
87
- await ensureDir(stateDir);
88
- await writeFileSafe(path.join(stateDir, DELEGATION_LOG_FILE), `${JSON.stringify({ runId: activeRunId, entries: [] }, null, 2)}\n`, { mode: 0o600 });
89
- await writeFileSafe(path.join(stateDir, TDD_CYCLE_LOG_FILE), "", { mode: 0o600 });
90
- }
91
- async function restoreStateSnapshot(projectRoot, archiveStatePath) {
92
- if (!(await exists(archiveStatePath)))
93
- return;
94
- const stateDir = stateDirPath(projectRoot);
95
- await ensureDir(stateDir);
96
- const entries = await fs.readdir(archiveStatePath, { withFileTypes: true });
97
- for (const entry of entries) {
98
- const from = path.join(archiveStatePath, entry.name);
99
- const to = path.join(stateDir, entry.name);
100
- if (entry.isDirectory()) {
101
- await fs.rm(to, { recursive: true, force: true });
102
- await fs.cp(from, to, { recursive: true });
103
- }
104
- else if (entry.isFile()) {
105
- await fs.copyFile(from, to);
106
- }
107
- }
108
- }
109
- function toArchiveDate(date = new Date()) {
110
- const yyyy = date.getFullYear().toString();
111
- const mm = (date.getMonth() + 1).toString().padStart(2, "0");
112
- const dd = date.getDate().toString().padStart(2, "0");
113
- return `${yyyy}-${mm}-${dd}`;
114
- }
115
- function slugifyRunName(value) {
116
- const slug = value
117
- .toLowerCase()
118
- .trim()
119
- .replace(/[^a-z0-9]+/gu, "-")
120
- .replace(/^-+/u, "")
121
- .replace(/-+$/u, "");
122
- if (slug.length === 0) {
123
- return "run";
124
- }
125
- return slug.slice(0, 64);
126
- }
127
- async function inferRunNameFromArtifacts(projectRoot) {
128
- const ideaPath = path.join(projectRoot, ACTIVE_ARTIFACTS_REL_PATH, "00-idea.md");
129
- if (!(await exists(ideaPath))) {
130
- return "run";
131
- }
132
- try {
133
- const raw = await fs.readFile(ideaPath, "utf8");
134
- const firstMeaningful = raw
135
- .split(/\r?\n/gu)
136
- .map((line) => line.trim())
137
- .find((line) => line.length > 0);
138
- if (!firstMeaningful) {
139
- return "run";
140
- }
141
- return firstMeaningful.replace(/^[-#*\s]+/u, "").trim() || "run";
142
- }
143
- catch {
144
- return "run";
145
- }
146
- }
147
- async function uniqueArchiveId(projectRoot, baseId) {
148
- let index = 1;
149
- let candidate = baseId;
150
- while (await exists(path.join(archiveRoot(projectRoot), candidate))) {
151
- index += 1;
152
- candidate = `${baseId}-${index}`;
153
- }
154
- return candidate;
155
- }
156
- export async function listRuns(projectRoot) {
157
- const root = archiveRoot(projectRoot);
158
- if (!(await exists(root))) {
159
- return [];
160
- }
161
- const entries = await fs.readdir(root, { withFileTypes: true });
162
- const runs = [];
163
- for (const entry of entries) {
164
- if (!entry.isDirectory()) {
165
- continue;
166
- }
167
- const runPath = path.join(root, entry.name);
168
- let createdAt = new Date().toISOString();
169
- try {
170
- const stat = await fs.stat(runPath);
171
- createdAt = stat.birthtime?.toISOString?.() ?? stat.mtime.toISOString();
172
- }
173
- catch {
174
- // keep fallback timestamp
175
- }
176
- runs.push({
177
- id: entry.name,
178
- title: entry.name,
179
- createdAt
180
- });
181
- }
182
- return runs.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
183
- }
184
- export async function archiveRun(projectRoot, runName, options = {}) {
185
- await ensureRunSystem(projectRoot);
186
- // Hold BOTH archive.lock and flow-state.lock for the entire archive:
187
- // the outer archive lock serializes two concurrent archives; the
188
- // inner flow-state lock prevents CLI / hook paths from mutating
189
- // flow-state between the archive snapshot and the subsequent reset,
190
- // which used to cause lost-update races.
191
- return withDirectoryLock(archiveLockPath(projectRoot), async () => {
192
- return withDirectoryLock(flowStateLockPathFor(projectRoot), async () => {
193
- const artifactsDir = activeArtifactsPath(projectRoot);
194
- const archiveDir = archiveRoot(projectRoot);
195
- await ensureDir(archiveDir);
196
- await ensureDir(artifactsDir);
197
- const archiveRunName = (runName?.trim() && runName.trim().length > 0)
198
- ? runName.trim()
199
- : await inferRunNameFromArtifacts(projectRoot);
200
- const archiveBaseId = `${toArchiveDate()}-${slugifyRunName(archiveRunName)}`;
201
- const archiveId = await uniqueArchiveId(projectRoot, archiveBaseId);
202
- const archivePath = path.join(archiveDir, archiveId);
203
- const archiveArtifactsPath = path.join(archivePath, "artifacts");
204
- let sourceState = await readFlowState(projectRoot);
205
- const retroGate = await evaluateRetroGate(projectRoot, sourceState);
206
- const disposition = options.disposition ?? "completed";
207
- const dispositionReason = options.dispositionReason?.trim();
208
- const nonCompletedDisposition = disposition !== "completed";
209
- if (nonCompletedDisposition && (!dispositionReason || dispositionReason.length === 0)) {
210
- throw new Error("archive --disposition=cancelled|abandoned requires --reason=<text>.");
211
- }
212
- const shipCompleted = sourceState.completedStages.includes("ship");
213
- const skipRetro = options.skipRetro === true;
214
- const skipRetroReason = options.skipRetroReason?.trim();
215
- if (skipRetro && (!skipRetroReason || skipRetroReason.length === 0)) {
216
- throw new Error("archive --skip-retro requires --retro-reason=<text>.");
217
- }
218
- if (nonCompletedDisposition && skipRetro) {
219
- throw new Error("archive --skip-retro is only valid for completed archives; use --reason with cancelled/abandoned.");
220
- }
221
- const retroSkippedInCloseout = sourceState.closeout.retroSkipped === true &&
222
- typeof sourceState.closeout.retroSkipReason === "string" &&
223
- sourceState.closeout.retroSkipReason.trim().length > 0;
224
- const readyForArchive = sourceState.closeout.shipSubstate === "ready_to_archive";
225
- const inShipCloseout = sourceState.currentStage === "ship";
226
- if (!nonCompletedDisposition && readyForArchive && !compoundCloseoutComplete(sourceState)) {
227
- throw new Error("Archive blocked: compound closeout is incomplete. " +
228
- "Promote compound guidance or skip compound review with an explicit reason before archiving.");
229
- }
230
- if (!nonCompletedDisposition && inShipCloseout && skipRetro) {
231
- throw new Error("Archive blocked: --skip-retro is not allowed while current stage is ship. " +
232
- "Complete closeout to ready_to_archive via /cc.");
233
- }
234
- if (!nonCompletedDisposition && inShipCloseout && !readyForArchive) {
235
- throw new Error("Archive blocked: closeout is not ready_to_archive. " +
236
- "Resume /cc until closeout reaches ready_to_archive.");
237
- }
238
- if (!nonCompletedDisposition && shipCompleted && !readyForArchive && !skipRetro) {
239
- throw new Error("Archive blocked: closeout is not ready_to_archive. " +
240
- "Resume /cc until closeout reaches ready_to_archive, " +
241
- "or run `cclaw archive --skip-retro --retro-reason=<text>` for CLI-only flows.");
242
- }
243
- if (!nonCompletedDisposition && retroGate.required && !retroGate.completed && !skipRetro && !retroSkippedInCloseout) {
244
- throw new Error("Archive blocked: retro gate is required after ship completion. " +
245
- "Run /cc (auto-runs retro) or, for CLI-only flows, re-run `cclaw archive --skip-retro --retro-reason=<text>`.");
246
- }
247
- if (retroGate.completed) {
248
- const completedAt = sourceState.retro.completedAt ?? new Date().toISOString();
249
- sourceState = {
250
- ...sourceState,
251
- retro: {
252
- required: retroGate.required,
253
- completedAt,
254
- compoundEntries: retroGate.compoundEntries
255
- }
256
- };
257
- await writeFlowState(projectRoot, sourceState, { allowReset: true, skipLock: true });
258
- }
259
- const retroSummary = {
260
- required: retroGate.required,
261
- completed: retroGate.completed,
262
- skipped: skipRetro || retroSkippedInCloseout,
263
- skipReason: skipRetro
264
- ? skipRetroReason
265
- : retroSkippedInCloseout
266
- ? sourceState.closeout.retroSkipReason
267
- : undefined,
268
- compoundEntries: retroGate.compoundEntries
269
- };
270
- await ensureDir(archivePath);
271
- // Drop an `.archive-in-progress` sentinel immediately so that a crash
272
- // between the artifact rename and the final manifest write leaves a
273
- // recoverable marker (sync reports these; re-running archive on an
274
- // orphan attempts to complete or roll back). The sentinel is removed
275
- // only after the manifest lands successfully.
276
- const sentinelPath = path.join(archivePath, ".archive-in-progress");
277
- const archivedAt = new Date().toISOString();
278
- await writeFileSafe(sentinelPath, `${JSON.stringify({ archiveId, startedAt: archivedAt, sourceRunId: sourceState.activeRunId }, null, 2)}\n`);
279
- const stateBeforeReset = sourceState;
280
- let artifactsMoved = false;
281
- let stateReset = false;
282
- try {
283
- await fs.rename(artifactsDir, archiveArtifactsPath);
284
- artifactsMoved = true;
285
- await ensureDir(artifactsDir);
286
- const archiveStatePath = path.join(archivePath, "state");
287
- const snapshottedStateFiles = await snapshotStateDirectory(projectRoot, archiveStatePath);
288
- const resetState = createInitialFlowState();
289
- await writeFlowState(projectRoot, resetState, { allowReset: true, skipLock: true });
290
- stateReset = true;
291
- await resetCarryoverStateFiles(projectRoot, resetState.activeRunId);
292
- const manifest = {
293
- version: 2,
294
- archiveId,
295
- archivedAt,
296
- runName: archiveRunName,
297
- sourceRunId: sourceState.activeRunId,
298
- sourceCurrentStage: sourceState.currentStage,
299
- sourceCompletedStages: sourceState.completedStages,
300
- snapshottedStateFiles,
301
- disposition,
302
- ...(dispositionReason ? { dispositionReason } : {}),
303
- retro: retroSummary
304
- };
305
- await writeFileSafe(path.join(archivePath, "archive-manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`);
306
- // Manifest landed — sentinel is no longer needed.
307
- await fs.unlink(sentinelPath).catch(() => undefined);
308
- const knowledgeStats = await readKnowledgeStats(projectRoot);
309
- return {
310
- archiveId,
311
- archivePath,
312
- archivedAt,
313
- runName: archiveRunName,
314
- resetState,
315
- snapshottedStateFiles,
316
- disposition,
317
- ...(dispositionReason ? { dispositionReason } : {}),
318
- knowledge: knowledgeStats,
319
- retro: retroSummary
320
- };
321
- }
322
- catch (err) {
323
- // Best-effort rollback: if artifacts were moved but the subsequent
324
- // steps failed, put artifacts back so the user is not left without
325
- // a working run. The sentinel is intentionally left behind for
326
- // inspection; sync reports it.
327
- if (artifactsMoved) {
328
- try {
329
- await fs.rm(artifactsDir, { recursive: true, force: true });
330
- await fs.rename(archiveArtifactsPath, artifactsDir);
331
- }
332
- catch {
333
- // Rollback failed — sentinel + orphaned archive dir will be
334
- // surfaced by sync and can be reconciled manually.
335
- }
336
- }
337
- if (stateReset) {
338
- try {
339
- await restoreStateSnapshot(projectRoot, path.join(archivePath, "state"));
340
- await writeFlowState(projectRoot, stateBeforeReset, { allowReset: true, skipLock: true });
341
- }
342
- catch {
343
- // If rollback of state fails, keep sentinel + archive remnants for
344
- // manual reconciliation.
345
- }
346
- }
347
- throw err;
348
- }
349
- });
350
- }, {
351
- retries: 400,
352
- retryDelayMs: 25,
353
- staleAfterMs: 120_000
354
- });
355
- }
356
- const KNOWLEDGE_SOFT_THRESHOLD = 50;
357
- async function readKnowledgeStats(projectRoot) {
358
- const { entries } = await readKnowledgeSafely(projectRoot);
359
- const activeEntryCount = entries.length;
360
- return {
361
- activeEntryCount,
362
- softThreshold: KNOWLEDGE_SOFT_THRESHOLD,
363
- overThreshold: activeEntryCount > KNOWLEDGE_SOFT_THRESHOLD,
364
- knowledgePath: `${RUNTIME_ROOT}/knowledge.jsonl`
365
- };
366
- }
367
- /**
368
- * Counts entries in the canonical JSONL knowledge store. An "active" entry is one
369
- * non-empty line that parses as JSON with the required `type` field belonging to the
370
- * allowed set. Malformed lines are ignored (not counted) but do not throw so that a
371
- * hand-edited file cannot break sync/archive flows.
372
- */
373
- export function countActiveKnowledgeEntries(text) {
374
- const allowed = new Set(["rule", "pattern", "lesson", "compound"]);
375
- let count = 0;
376
- for (const raw of text.split(/\r?\n/)) {
377
- const line = raw.trim();
378
- if (line.length === 0)
379
- continue;
380
- try {
381
- const parsed = JSON.parse(line);
382
- if (typeof parsed.type === "string" && allowed.has(parsed.type)) {
383
- count += 1;
384
- }
385
- }
386
- catch {
387
- // Skip malformed lines silently; curation surfaces them separately.
388
- }
389
- }
390
- return count;
391
- }
package/dist/runs.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { CorruptFlowStateError, FlowStateGuardMismatchError, InvalidStageTransitionError, type FlowStateGuardSidecar, type FlowStateRepairResult, type WriteFlowStateOptions, ensureRunSystem, flowStateGuardSidecarPathFor, flowStateRepairLogPathFor, readFlowState, readFlowStateGuarded, repairFlowStateGuard, verifyFlowStateGuard, writeFlowState, writeFlowStateGuarded } from "./run-persistence.js";
2
- export { ARCHIVE_DISPOSITIONS, archiveRun, countActiveKnowledgeEntries, listRuns, type ArchiveDisposition, type ArchiveManifest, type ArchiveRunOptions, type ArchiveRunResult, type CclawRunMeta } from "./run-archive.js";
package/dist/runs.js DELETED
@@ -1,2 +0,0 @@
1
- export { CorruptFlowStateError, FlowStateGuardMismatchError, InvalidStageTransitionError, ensureRunSystem, flowStateGuardSidecarPathFor, flowStateRepairLogPathFor, readFlowState, readFlowStateGuarded, repairFlowStateGuard, verifyFlowStateGuard, writeFlowState, writeFlowStateGuarded } from "./run-persistence.js";
2
- export { ARCHIVE_DISPOSITIONS, archiveRun, countActiveKnowledgeEntries, listRuns } from "./run-archive.js";
@@ -1,116 +0,0 @@
1
- export interface StackReviewRouteProfile {
2
- stack: string;
3
- /**
4
- * Signals shown in review routing documentation/skills.
5
- * These are human-facing pointers, not strict parsers.
6
- */
7
- reviewSignals: string[];
8
- /** Root-level markers used by start-flow context discovery. */
9
- discoveryMarkers: string[];
10
- focus: string;
11
- }
12
- export declare const STACK_REVIEW_ROUTE_PROFILES: readonly StackReviewRouteProfile[];
13
- /**
14
- * Unified root-marker list used by start-flow context discovery.
15
- * Keep this in one place so stage skill routing and start-flow scanning
16
- * evolve together.
17
- */
18
- export declare const STACK_DISCOVERY_MARKERS: readonly string[];
19
- /**
20
- * Directory markers (checked with pathExists) for stack discovery.
21
- */
22
- export declare const STACK_DISCOVERY_DIR_MARKERS: readonly string[];
23
- export type StackAdapterId = "rust" | "node" | "python" | "go" | "ruby" | "php" | "swift" | "dotnet" | "elixir" | "java" | "unknown";
24
- /** Twin describing manifest → lockfile coupling for a stack. */
25
- export interface ManifestLockfileTwin {
26
- /** Manifest glob (path relative to repo root). */
27
- manifestGlob: string;
28
- /** Lockfile glob that the manifest's package manager regenerates. */
29
- lockfileGlob: string;
30
- }
31
- /**
32
- * Wiring-aggregator contract — describes whether a new file in a stack
33
- * needs an explicit aggregator/parent module update for the new module to
34
- * be reachable from the rest of the project.
35
- *
36
- * - `aggregatorPattern` is a human-facing description; consumers should
37
- * call `resolveAggregatorFor(filePath, repoState?)` to compute the
38
- * concrete aggregator path.
39
- * - `resolveAggregatorFor` returns the concrete repo-relative path of
40
- * the aggregator file required to wire `filePath`, or `null` when no
41
- * aggregator is required (e.g. file IS the aggregator, or the stack
42
- * layout makes wiring implicit).
43
- * - `repoState.headFiles` lets the resolver check whether sibling
44
- * aggregators already exist (so e.g. node-ts only requires
45
- * `index.ts` updates when an `index.ts` already exists in that
46
- * directory).
47
- */
48
- export interface WiringAggregatorContract {
49
- aggregatorPattern: string;
50
- /**
51
- * Resolve the aggregator path required to wire `filePath` into its
52
- * parent module, given a snapshot of repo state. Return `null` when
53
- * no aggregator update is required.
54
- */
55
- resolveAggregatorFor(filePath: string, repoState?: {
56
- headFiles?: ReadonlySet<string>;
57
- }): string | null;
58
- }
59
- /**
60
- * Universal stack-adapter contract used by hooks (slice-commit lockfile
61
- * twins), linters (`plan_module_introducing_slice_wires_root`), and
62
- * future stack-specific evidence validators.
63
- *
64
- * Each stack returns:
65
- * - `id` — short stable identifier; routes used elsewhere should match.
66
- * - `displayName` — used in user-facing prose so error messages stay
67
- * stack-agnostic at the surface ("Rust workspace" vs "Node project"
68
- * are forbidden in generic code; use `adapter.displayName` instead).
69
- * - `manifestGlobs` — repo-relative manifest paths the stack uses.
70
- * - `lockfileTwins` — manifest→lockfile twin entries; auto-detected
71
- * from disk at adapter init so node projects with yarn.lock get
72
- * `yarn.lock`, pnpm gets `pnpm-lock.yaml`, etc.
73
- * - `testCommandHints` — example test command lines for prompts and
74
- * evidence validators (advisory; not authoritative).
75
- * - `wiringAggregator` — see contract above. `undefined` when the
76
- * stack has no aggregator pattern (Go, Java, Ruby, Swift, .NET,
77
- * Elixir use implicit/automatic wiring).
78
- */
79
- export interface StackAdapter {
80
- id: StackAdapterId;
81
- displayName: string;
82
- manifestGlobs: string[];
83
- lockfileTwins: ManifestLockfileTwin[];
84
- testCommandHints: string[];
85
- wiringAggregator?: WiringAggregatorContract;
86
- }
87
- interface LoadStackAdapterOptions {
88
- /**
89
- * Override the project root for tests. Defaults to the supplied
90
- * argument; primarily here so callers can inject a synthesized
91
- * directory in fixtures.
92
- */
93
- projectRoot?: string;
94
- }
95
- /**
96
- * Load the stack-adapter for a project. Walks the registered factories
97
- * in order; the first detector that returns true wins. Returns the
98
- * `unknown` adapter (no-op) when no detector matches.
99
- *
100
- * Adapter init reads the filesystem to auto-detect lockfile twins
101
- * (e.g. yarn.lock vs package-lock.json). Callers should cache the
102
- * adapter for the lifetime of the operation rather than calling this
103
- * per-row.
104
- */
105
- export declare function loadStackAdapter(projectRoot: string, options?: LoadStackAdapterOptions): Promise<StackAdapter>;
106
- /**
107
- * Synthesize a stack adapter from explicit lockfile-twin overrides.
108
- * Useful in tests that want to pin twins without a real filesystem
109
- * scan, and for the linter test suite.
110
- */
111
- export declare function buildStackAdapterForTests(partial: Partial<StackAdapter> & {
112
- id: StackAdapterId;
113
- displayName: string;
114
- }): StackAdapter;
115
- export declare const UNKNOWN_STACK: StackAdapter;
116
- export {};