@paths.design/caws-cli 10.2.0 → 11.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 (493) hide show
  1. package/README.md +125 -374
  2. package/dist/index.js +45 -787
  3. package/dist/init/harness-detect.d.ts +18 -0
  4. package/dist/init/harness-detect.d.ts.map +1 -0
  5. package/dist/init/harness-detect.js +90 -0
  6. package/dist/init/harness-detect.js.map +1 -0
  7. package/dist/init/hook-install.d.ts +53 -0
  8. package/dist/init/hook-install.d.ts.map +1 -0
  9. package/dist/init/hook-install.js +421 -0
  10. package/dist/init/hook-install.js.map +1 -0
  11. package/dist/init/hook-packs/manifest-claude-code.d.ts +4 -0
  12. package/dist/init/hook-packs/manifest-claude-code.d.ts.map +1 -0
  13. package/dist/init/hook-packs/manifest-claude-code.js +190 -0
  14. package/dist/init/hook-packs/manifest-claude-code.js.map +1 -0
  15. package/dist/init/hook-packs/register.d.ts +19 -0
  16. package/dist/init/hook-packs/register.d.ts.map +1 -0
  17. package/dist/init/hook-packs/register.js +37 -0
  18. package/dist/init/hook-packs/register.js.map +1 -0
  19. package/dist/init/hook-packs/types.d.ts +123 -0
  20. package/dist/init/hook-packs/types.d.ts.map +1 -0
  21. package/dist/init/hook-packs/types.js +29 -0
  22. package/dist/init/hook-packs/types.js.map +1 -0
  23. package/dist/shell/binding/resolve-binding.d.ts +4 -0
  24. package/dist/shell/binding/resolve-binding.d.ts.map +1 -0
  25. package/dist/shell/binding/resolve-binding.js +228 -0
  26. package/dist/shell/binding/resolve-binding.js.map +1 -0
  27. package/dist/shell/binding/types.d.ts +42 -0
  28. package/dist/shell/binding/types.d.ts.map +1 -0
  29. package/dist/shell/binding/types.js +21 -0
  30. package/dist/shell/binding/types.js.map +1 -0
  31. package/dist/shell/commands/claim.d.ts +14 -0
  32. package/dist/shell/commands/claim.d.ts.map +1 -0
  33. package/dist/shell/commands/claim.js +197 -0
  34. package/dist/shell/commands/claim.js.map +1 -0
  35. package/dist/shell/commands/doctor.d.ts +13 -0
  36. package/dist/shell/commands/doctor.d.ts.map +1 -0
  37. package/dist/shell/commands/doctor.js +97 -0
  38. package/dist/shell/commands/doctor.js.map +1 -0
  39. package/dist/shell/commands/evidence.d.ts +28 -0
  40. package/dist/shell/commands/evidence.d.ts.map +1 -0
  41. package/dist/shell/commands/evidence.js +166 -0
  42. package/dist/shell/commands/evidence.js.map +1 -0
  43. package/dist/shell/commands/gates.d.ts +19 -0
  44. package/dist/shell/commands/gates.d.ts.map +1 -0
  45. package/dist/shell/commands/gates.js +208 -0
  46. package/dist/shell/commands/gates.js.map +1 -0
  47. package/dist/shell/commands/init.d.ts +17 -0
  48. package/dist/shell/commands/init.d.ts.map +1 -0
  49. package/dist/shell/commands/init.js +168 -0
  50. package/dist/shell/commands/init.js.map +1 -0
  51. package/dist/shell/commands/scope.d.ts +11 -0
  52. package/dist/shell/commands/scope.d.ts.map +1 -0
  53. package/dist/shell/commands/scope.js +92 -0
  54. package/dist/shell/commands/scope.js.map +1 -0
  55. package/dist/shell/commands/specs.d.ts +41 -0
  56. package/dist/shell/commands/specs.d.ts.map +1 -0
  57. package/dist/shell/commands/specs.js +264 -0
  58. package/dist/shell/commands/specs.js.map +1 -0
  59. package/dist/shell/commands/status.d.ts +15 -0
  60. package/dist/shell/commands/status.d.ts.map +1 -0
  61. package/dist/shell/commands/status.js +106 -0
  62. package/dist/shell/commands/status.js.map +1 -0
  63. package/dist/shell/commands/waiver.d.ts +38 -0
  64. package/dist/shell/commands/waiver.d.ts.map +1 -0
  65. package/dist/shell/commands/waiver.js +240 -0
  66. package/dist/shell/commands/waiver.js.map +1 -0
  67. package/dist/shell/commands/worktree.d.ts +38 -0
  68. package/dist/shell/commands/worktree.d.ts.map +1 -0
  69. package/dist/shell/commands/worktree.js +286 -0
  70. package/dist/shell/commands/worktree.js.map +1 -0
  71. package/dist/shell/gates/disposition.d.ts +23 -0
  72. package/dist/shell/gates/disposition.d.ts.map +1 -0
  73. package/dist/shell/gates/disposition.js +117 -0
  74. package/dist/shell/gates/disposition.js.map +1 -0
  75. package/dist/shell/gates/gate-result-contract.d.ts +39 -0
  76. package/dist/shell/gates/gate-result-contract.d.ts.map +1 -0
  77. package/dist/shell/gates/gate-result-contract.js +150 -0
  78. package/dist/shell/gates/gate-result-contract.js.map +1 -0
  79. package/dist/shell/gates/local-evaluators/budget-limit.d.ts +24 -0
  80. package/dist/shell/gates/local-evaluators/budget-limit.d.ts.map +1 -0
  81. package/dist/shell/gates/local-evaluators/budget-limit.js +67 -0
  82. package/dist/shell/gates/local-evaluators/budget-limit.js.map +1 -0
  83. package/dist/shell/gates/local-evaluators/diff-helpers.d.ts +25 -0
  84. package/dist/shell/gates/local-evaluators/diff-helpers.d.ts.map +1 -0
  85. package/dist/shell/gates/local-evaluators/diff-helpers.js +74 -0
  86. package/dist/shell/gates/local-evaluators/diff-helpers.js.map +1 -0
  87. package/dist/shell/gates/local-evaluators/index.d.ts +28 -0
  88. package/dist/shell/gates/local-evaluators/index.d.ts.map +1 -0
  89. package/dist/shell/gates/local-evaluators/index.js +67 -0
  90. package/dist/shell/gates/local-evaluators/index.js.map +1 -0
  91. package/dist/shell/gates/local-evaluators/scope-boundary.d.ts +23 -0
  92. package/dist/shell/gates/local-evaluators/scope-boundary.d.ts.map +1 -0
  93. package/dist/shell/gates/local-evaluators/scope-boundary.js +67 -0
  94. package/dist/shell/gates/local-evaluators/scope-boundary.js.map +1 -0
  95. package/dist/shell/gates/local-evaluators/spec-completeness.d.ts +12 -0
  96. package/dist/shell/gates/local-evaluators/spec-completeness.d.ts.map +1 -0
  97. package/dist/shell/gates/local-evaluators/spec-completeness.js +73 -0
  98. package/dist/shell/gates/local-evaluators/spec-completeness.js.map +1 -0
  99. package/dist/shell/gates/quality-gates-adapter.d.ts +55 -0
  100. package/dist/shell/gates/quality-gates-adapter.d.ts.map +1 -0
  101. package/dist/shell/gates/quality-gates-adapter.js +161 -0
  102. package/dist/shell/gates/quality-gates-adapter.js.map +1 -0
  103. package/dist/shell/gates/waiver-filter.d.ts +58 -0
  104. package/dist/shell/gates/waiver-filter.d.ts.map +1 -0
  105. package/dist/shell/gates/waiver-filter.js +119 -0
  106. package/dist/shell/gates/waiver-filter.js.map +1 -0
  107. package/dist/shell/index.d.ts +54 -0
  108. package/dist/shell/index.d.ts.map +1 -0
  109. package/dist/shell/index.js +85 -0
  110. package/dist/shell/index.js.map +1 -0
  111. package/dist/shell/register.d.ts +11 -0
  112. package/dist/shell/register.d.ts.map +1 -0
  113. package/dist/shell/register.js +464 -0
  114. package/dist/shell/register.js.map +1 -0
  115. package/dist/shell/render/claim.d.ts +22 -0
  116. package/dist/shell/render/claim.d.ts.map +1 -0
  117. package/dist/shell/render/claim.js +75 -0
  118. package/dist/shell/render/claim.js.map +1 -0
  119. package/dist/shell/render/decision.d.ts +15 -0
  120. package/dist/shell/render/decision.d.ts.map +1 -0
  121. package/dist/shell/render/decision.js +66 -0
  122. package/dist/shell/render/decision.js.map +1 -0
  123. package/dist/shell/render/diagnostic.d.ts +19 -0
  124. package/dist/shell/render/diagnostic.d.ts.map +1 -0
  125. package/dist/shell/render/diagnostic.js +76 -0
  126. package/dist/shell/render/diagnostic.js.map +1 -0
  127. package/dist/shell/render/finding.d.ts +15 -0
  128. package/dist/shell/render/finding.d.ts.map +1 -0
  129. package/dist/shell/render/finding.js +57 -0
  130. package/dist/shell/render/finding.js.map +1 -0
  131. package/dist/shell/render/gates.d.ts +3 -0
  132. package/dist/shell/render/gates.d.ts.map +1 -0
  133. package/dist/shell/render/gates.js +56 -0
  134. package/dist/shell/render/gates.js.map +1 -0
  135. package/dist/shell/render/init-hook-pack.d.ts +16 -0
  136. package/dist/shell/render/init-hook-pack.d.ts.map +1 -0
  137. package/dist/shell/render/init-hook-pack.js +206 -0
  138. package/dist/shell/render/init-hook-pack.js.map +1 -0
  139. package/dist/shell/render/init.d.ts +11 -0
  140. package/dist/shell/render/init.d.ts.map +1 -0
  141. package/dist/shell/render/init.js +32 -0
  142. package/dist/shell/render/init.js.map +1 -0
  143. package/dist/shell/render/status.d.ts +26 -0
  144. package/dist/shell/render/status.d.ts.map +1 -0
  145. package/dist/shell/render/status.js +143 -0
  146. package/dist/shell/render/status.js.map +1 -0
  147. package/dist/shell/render/waiver.d.ts +21 -0
  148. package/dist/shell/render/waiver.d.ts.map +1 -0
  149. package/dist/shell/render/waiver.js +94 -0
  150. package/dist/shell/render/waiver.js.map +1 -0
  151. package/dist/shell/rules.d.ts +37 -0
  152. package/dist/shell/rules.d.ts.map +1 -0
  153. package/dist/shell/rules.js +51 -0
  154. package/dist/shell/rules.js.map +1 -0
  155. package/dist/shell/session/actor.d.ts +14 -0
  156. package/dist/shell/session/actor.d.ts.map +1 -0
  157. package/dist/shell/session/actor.js +34 -0
  158. package/dist/shell/session/actor.js.map +1 -0
  159. package/dist/shell/session/resolve-session.d.ts +5 -0
  160. package/dist/shell/session/resolve-session.d.ts.map +1 -0
  161. package/dist/shell/session/resolve-session.js +239 -0
  162. package/dist/shell/session/resolve-session.js.map +1 -0
  163. package/dist/shell/session/types.d.ts +56 -0
  164. package/dist/shell/session/types.d.ts.map +1 -0
  165. package/dist/shell/session/types.js +15 -0
  166. package/dist/shell/session/types.js.map +1 -0
  167. package/dist/store/agents-store.d.ts +3 -0
  168. package/dist/store/agents-store.d.ts.map +1 -0
  169. package/dist/store/agents-store.js +63 -0
  170. package/dist/store/agents-store.js.map +1 -0
  171. package/dist/store/apply-patch.d.ts +16 -0
  172. package/dist/store/apply-patch.d.ts.map +1 -0
  173. package/dist/store/apply-patch.js +191 -0
  174. package/dist/store/apply-patch.js.map +1 -0
  175. package/dist/store/atomic-write.d.ts +34 -0
  176. package/dist/store/atomic-write.d.ts.map +1 -0
  177. package/dist/store/atomic-write.js +174 -0
  178. package/dist/store/atomic-write.js.map +1 -0
  179. package/dist/store/doctor-snapshot.d.ts +20 -0
  180. package/dist/store/doctor-snapshot.d.ts.map +1 -0
  181. package/dist/store/doctor-snapshot.js +176 -0
  182. package/dist/store/doctor-snapshot.js.map +1 -0
  183. package/dist/store/events-store.d.ts +33 -0
  184. package/dist/store/events-store.d.ts.map +1 -0
  185. package/dist/store/events-store.js +297 -0
  186. package/dist/store/events-store.js.map +1 -0
  187. package/dist/store/index.d.ts +21 -0
  188. package/dist/store/index.d.ts.map +1 -0
  189. package/dist/store/index.js +47 -0
  190. package/dist/store/index.js.map +1 -0
  191. package/dist/store/init-store.d.ts +21 -0
  192. package/dist/store/init-store.d.ts.map +1 -0
  193. package/dist/store/init-store.js +295 -0
  194. package/dist/store/init-store.js.map +1 -0
  195. package/dist/store/json-store.d.ts +3 -0
  196. package/dist/store/json-store.d.ts.map +1 -0
  197. package/dist/store/json-store.js +65 -0
  198. package/dist/store/json-store.js.map +1 -0
  199. package/dist/store/lifecycle-lock.d.ts +34 -0
  200. package/dist/store/lifecycle-lock.d.ts.map +1 -0
  201. package/dist/store/lifecycle-lock.js +168 -0
  202. package/dist/store/lifecycle-lock.js.map +1 -0
  203. package/dist/store/lifecycle-transaction.d.ts +79 -0
  204. package/dist/store/lifecycle-transaction.d.ts.map +1 -0
  205. package/dist/store/lifecycle-transaction.js +319 -0
  206. package/dist/store/lifecycle-transaction.js.map +1 -0
  207. package/dist/store/policy-store.d.ts +3 -0
  208. package/dist/store/policy-store.d.ts.map +1 -0
  209. package/dist/store/policy-store.js +65 -0
  210. package/dist/store/policy-store.js.map +1 -0
  211. package/dist/store/repo-root.d.ts +46 -0
  212. package/dist/store/repo-root.d.ts.map +1 -0
  213. package/dist/store/repo-root.js +145 -0
  214. package/dist/store/repo-root.js.map +1 -0
  215. package/dist/store/rules.d.ts +69 -0
  216. package/dist/store/rules.d.ts.map +1 -0
  217. package/dist/store/rules.js +95 -0
  218. package/dist/store/rules.js.map +1 -0
  219. package/dist/store/specs-store.d.ts +3 -0
  220. package/dist/store/specs-store.d.ts.map +1 -0
  221. package/dist/store/specs-store.js +131 -0
  222. package/dist/store/specs-store.js.map +1 -0
  223. package/dist/store/specs-writer.d.ts +61 -0
  224. package/dist/store/specs-writer.d.ts.map +1 -0
  225. package/dist/store/specs-writer.js +506 -0
  226. package/dist/store/specs-writer.js.map +1 -0
  227. package/dist/store/types.d.ts +84 -0
  228. package/dist/store/types.d.ts.map +1 -0
  229. package/dist/store/types.js +14 -0
  230. package/dist/store/types.js.map +1 -0
  231. package/dist/store/waivers-store.d.ts +25 -0
  232. package/dist/store/waivers-store.d.ts.map +1 -0
  233. package/dist/store/waivers-store.js +232 -0
  234. package/dist/store/waivers-store.js.map +1 -0
  235. package/dist/store/worktrees-store.d.ts +3 -0
  236. package/dist/store/worktrees-store.d.ts.map +1 -0
  237. package/dist/store/worktrees-store.js +62 -0
  238. package/dist/store/worktrees-store.js.map +1 -0
  239. package/dist/store/worktrees-writer.d.ts +77 -0
  240. package/dist/store/worktrees-writer.d.ts.map +1 -0
  241. package/dist/store/worktrees-writer.js +674 -0
  242. package/dist/store/worktrees-writer.js.map +1 -0
  243. package/dist/store/yaml-patch.d.ts +7 -0
  244. package/dist/store/yaml-patch.d.ts.map +1 -0
  245. package/dist/store/yaml-patch.js +250 -0
  246. package/dist/store/yaml-patch.js.map +1 -0
  247. package/dist/store/yaml-store.d.ts +9 -0
  248. package/dist/store/yaml-store.d.ts.map +1 -0
  249. package/dist/store/yaml-store.js +121 -0
  250. package/dist/store/yaml-store.js.map +1 -0
  251. package/package.json +15 -13
  252. package/dist/budget-derivation.js +0 -751
  253. package/dist/cicd-optimizer.js +0 -504
  254. package/dist/commands/agents.js +0 -124
  255. package/dist/commands/archive.js +0 -500
  256. package/dist/commands/burnup.js +0 -198
  257. package/dist/commands/diagnose.js +0 -525
  258. package/dist/commands/evaluate.js +0 -314
  259. package/dist/commands/gates.js +0 -149
  260. package/dist/commands/init.js +0 -857
  261. package/dist/commands/iterate.js +0 -417
  262. package/dist/commands/mode.js +0 -269
  263. package/dist/commands/parallel.js +0 -242
  264. package/dist/commands/plan.js +0 -438
  265. package/dist/commands/provenance.js +0 -1143
  266. package/dist/commands/quality-monitor.js +0 -284
  267. package/dist/commands/scope.js +0 -264
  268. package/dist/commands/session.js +0 -312
  269. package/dist/commands/sidecar.js +0 -74
  270. package/dist/commands/specs.js +0 -1656
  271. package/dist/commands/status.js +0 -1172
  272. package/dist/commands/templates.js +0 -237
  273. package/dist/commands/tool.js +0 -136
  274. package/dist/commands/tutorial.js +0 -480
  275. package/dist/commands/validate.js +0 -357
  276. package/dist/commands/verify-acs.js +0 -443
  277. package/dist/commands/waivers.js +0 -599
  278. package/dist/commands/workflow.js +0 -243
  279. package/dist/commands/worktree.js +0 -502
  280. package/dist/config/lite-scope.js +0 -158
  281. package/dist/config/modes.js +0 -347
  282. package/dist/constants/spec-types.js +0 -65
  283. package/dist/gates/budget-limit.js +0 -121
  284. package/dist/gates/feedback.js +0 -260
  285. package/dist/gates/format.js +0 -179
  286. package/dist/gates/god-object.js +0 -117
  287. package/dist/gates/pipeline.js +0 -167
  288. package/dist/gates/scope-boundary.js +0 -112
  289. package/dist/gates/spec-completeness.js +0 -109
  290. package/dist/gates/todo-detection.js +0 -205
  291. package/dist/generators/jest-config-generator.js +0 -242
  292. package/dist/generators/working-spec.js +0 -237
  293. package/dist/minimal-cli.js +0 -88
  294. package/dist/parallel/parallel-manager.js +0 -433
  295. package/dist/policy/PolicyManager.js +0 -470
  296. package/dist/scaffold/claude-hooks.js +0 -443
  297. package/dist/scaffold/cursor-hooks.js +0 -177
  298. package/dist/scaffold/git-hooks.js +0 -928
  299. package/dist/scaffold/index.js +0 -794
  300. package/dist/session/session-manager.js +0 -653
  301. package/dist/sidecars/index.js +0 -33
  302. package/dist/sidecars/listeners.js +0 -40
  303. package/dist/sidecars/provenance-summary.js +0 -238
  304. package/dist/sidecars/quality-gaps.js +0 -258
  305. package/dist/sidecars/schema.js +0 -149
  306. package/dist/sidecars/spec-drift.js +0 -151
  307. package/dist/sidecars/waiver-draft.js +0 -176
  308. package/dist/spec/SpecFileManager.js +0 -419
  309. package/dist/templates/.caws/schemas/policy.schema.json +0 -117
  310. package/dist/templates/.caws/schemas/scope.schema.json +0 -52
  311. package/dist/templates/.caws/schemas/waivers.schema.json +0 -106
  312. package/dist/templates/.caws/schemas/working-spec.schema.json +0 -340
  313. package/dist/templates/.caws/schemas/worktrees.schema.json +0 -38
  314. package/dist/templates/.caws/templates/working-spec.template.yml +0 -80
  315. package/dist/templates/.caws/tools/README.md +0 -18
  316. package/dist/templates/.caws/tools/scope-guard.js +0 -203
  317. package/dist/templates/.caws/tools-allow.json +0 -331
  318. package/dist/templates/.caws/waivers.yml +0 -19
  319. package/dist/templates/.claude/README.md +0 -190
  320. package/dist/templates/.claude/hooks/audit.sh +0 -121
  321. package/dist/templates/.claude/hooks/block-dangerous.sh +0 -203
  322. package/dist/templates/.claude/hooks/classify_command.py +0 -592
  323. package/dist/templates/.claude/hooks/doc-frontmatter-check.sh +0 -173
  324. package/dist/templates/.claude/hooks/lite-sprawl-check.sh +0 -145
  325. package/dist/templates/.claude/hooks/naming-check.sh +0 -100
  326. package/dist/templates/.claude/hooks/protected-paths.sh +0 -39
  327. package/dist/templates/.claude/hooks/quality-check.sh +0 -81
  328. package/dist/templates/.claude/hooks/scan-secrets.sh +0 -85
  329. package/dist/templates/.claude/hooks/scope-guard.sh +0 -381
  330. package/dist/templates/.claude/hooks/session-caws-status.sh +0 -117
  331. package/dist/templates/.claude/hooks/session-log.sh +0 -634
  332. package/dist/templates/.claude/hooks/simplification-guard.sh +0 -92
  333. package/dist/templates/.claude/hooks/stop-worktree-check.sh +0 -46
  334. package/dist/templates/.claude/hooks/test_classify_command.py +0 -370
  335. package/dist/templates/.claude/hooks/test_wrapper_smoke.sh +0 -96
  336. package/dist/templates/.claude/hooks/validate-spec.sh +0 -76
  337. package/dist/templates/.claude/hooks/worktree-guard.sh +0 -220
  338. package/dist/templates/.claude/hooks/worktree-write-guard.sh +0 -190
  339. package/dist/templates/.claude/rules/git-safety.md +0 -26
  340. package/dist/templates/.claude/rules/worktree-isolation.md +0 -101
  341. package/dist/templates/.claude/settings.json +0 -141
  342. package/dist/templates/.cursor/README.md +0 -299
  343. package/dist/templates/.cursor/hooks/audit.sh +0 -55
  344. package/dist/templates/.cursor/hooks/block-dangerous.sh +0 -84
  345. package/dist/templates/.cursor/hooks/caws-quality-check.sh +0 -52
  346. package/dist/templates/.cursor/hooks/caws-scope-guard.sh +0 -130
  347. package/dist/templates/.cursor/hooks/format.sh +0 -38
  348. package/dist/templates/.cursor/hooks/naming-check.sh +0 -64
  349. package/dist/templates/.cursor/hooks/scan-secrets.sh +0 -51
  350. package/dist/templates/.cursor/hooks/scope-guard.sh +0 -52
  351. package/dist/templates/.cursor/hooks/session-log.sh +0 -924
  352. package/dist/templates/.cursor/hooks/validate-spec.sh +0 -83
  353. package/dist/templates/.cursor/hooks.json +0 -76
  354. package/dist/templates/.cursor/rules/00-claims-verification.mdc +0 -144
  355. package/dist/templates/.cursor/rules/01-working-style.mdc +0 -50
  356. package/dist/templates/.cursor/rules/02-quality-gates.mdc +0 -368
  357. package/dist/templates/.cursor/rules/03-naming-and-refactor.mdc +0 -33
  358. package/dist/templates/.cursor/rules/04-logging-language-style.mdc +0 -23
  359. package/dist/templates/.cursor/rules/05-safe-defaults-guards.mdc +0 -23
  360. package/dist/templates/.cursor/rules/06-typescript-conventions.mdc +0 -36
  361. package/dist/templates/.cursor/rules/07-process-ops.mdc +0 -20
  362. package/dist/templates/.cursor/rules/08-solid-and-architecture.mdc +0 -16
  363. package/dist/templates/.cursor/rules/09-docstrings.mdc +0 -89
  364. package/dist/templates/.cursor/rules/10-documentation-quality-standards.mdc +0 -385
  365. package/dist/templates/.cursor/rules/11-scope-management-waivers.mdc +0 -381
  366. package/dist/templates/.cursor/rules/12-implementation-completeness.mdc +0 -516
  367. package/dist/templates/.cursor/rules/13-language-agnostic-standards.mdc +0 -578
  368. package/dist/templates/.cursor/rules/README.md +0 -148
  369. package/dist/templates/.github/copilot-instructions.md +0 -82
  370. package/dist/templates/.idea/runConfigurations/CAWS_Evaluate.xml +0 -5
  371. package/dist/templates/.idea/runConfigurations/CAWS_Validate.xml +0 -5
  372. package/dist/templates/.junie/guidelines.md +0 -73
  373. package/dist/templates/.vscode/launch.json +0 -17
  374. package/dist/templates/.vscode/settings.json +0 -95
  375. package/dist/templates/.windsurf/rules/caws-quality-standards.md +0 -54
  376. package/dist/templates/.windsurf/workflows/caws-guided-development.md +0 -92
  377. package/dist/templates/CLAUDE.md +0 -196
  378. package/dist/templates/COMMIT_CONVENTIONS.md +0 -86
  379. package/dist/templates/OIDC_SETUP.md +0 -300
  380. package/dist/templates/agents.md +0 -171
  381. package/dist/templates/codemod/README.md +0 -1
  382. package/dist/templates/codemod/test.js +0 -93
  383. package/dist/templates/docs/README.md +0 -151
  384. package/dist/templates/scripts/new_feature.sh +0 -80
  385. package/dist/templates/scripts/quality-gates/check-god-objects.js +0 -146
  386. package/dist/templates/scripts/quality-gates/run-quality-gates.js +0 -50
  387. package/dist/templates/scripts/v3/analysis/todo_analyzer.py +0 -1997
  388. package/dist/test-analysis.js +0 -786
  389. package/dist/tool-interface.js +0 -314
  390. package/dist/tool-loader.js +0 -303
  391. package/dist/tool-validator.js +0 -393
  392. package/dist/utils/agent-display.js +0 -210
  393. package/dist/utils/agent-session.js +0 -344
  394. package/dist/utils/async-utils.js +0 -188
  395. package/dist/utils/command-wrapper.js +0 -200
  396. package/dist/utils/event-log.js +0 -584
  397. package/dist/utils/event-renderer.js +0 -521
  398. package/dist/utils/finalization.js +0 -230
  399. package/dist/utils/git-lock.js +0 -119
  400. package/dist/utils/gitignore-updater.js +0 -158
  401. package/dist/utils/ide-detection.js +0 -133
  402. package/dist/utils/lifecycle-events.js +0 -94
  403. package/dist/utils/project-analysis.js +0 -367
  404. package/dist/utils/promise-utils.js +0 -72
  405. package/dist/utils/quality-gates-errors.js +0 -520
  406. package/dist/utils/quality-gates-utils.js +0 -387
  407. package/dist/utils/schema-validator.js +0 -50
  408. package/dist/utils/spec-resolver.js +0 -711
  409. package/dist/utils/typescript-detector.js +0 -369
  410. package/dist/utils/working-state.js +0 -530
  411. package/dist/utils/yaml-validation.js +0 -156
  412. package/dist/validation/spec-validation.js +0 -924
  413. package/dist/waivers-manager.js +0 -732
  414. package/dist/worktree/worktree-manager.js +0 -1735
  415. package/templates/.caws/schemas/policy.schema.json +0 -117
  416. package/templates/.caws/schemas/scope.schema.json +0 -52
  417. package/templates/.caws/schemas/waivers.schema.json +0 -106
  418. package/templates/.caws/schemas/working-spec.schema.json +0 -340
  419. package/templates/.caws/schemas/worktrees.schema.json +0 -38
  420. package/templates/.caws/templates/working-spec.template.yml +0 -80
  421. package/templates/.caws/tools/README.md +0 -18
  422. package/templates/.caws/tools/scope-guard.js +0 -203
  423. package/templates/.caws/tools-allow.json +0 -331
  424. package/templates/.caws/waivers.yml +0 -19
  425. package/templates/.claude/README.md +0 -190
  426. package/templates/.claude/hooks/audit.sh +0 -121
  427. package/templates/.claude/hooks/block-dangerous.sh +0 -203
  428. package/templates/.claude/hooks/classify_command.py +0 -592
  429. package/templates/.claude/hooks/doc-frontmatter-check.sh +0 -173
  430. package/templates/.claude/hooks/lite-sprawl-check.sh +0 -145
  431. package/templates/.claude/hooks/naming-check.sh +0 -100
  432. package/templates/.claude/hooks/protected-paths.sh +0 -39
  433. package/templates/.claude/hooks/quality-check.sh +0 -81
  434. package/templates/.claude/hooks/scan-secrets.sh +0 -85
  435. package/templates/.claude/hooks/scope-guard.sh +0 -381
  436. package/templates/.claude/hooks/session-caws-status.sh +0 -117
  437. package/templates/.claude/hooks/session-log.sh +0 -634
  438. package/templates/.claude/hooks/simplification-guard.sh +0 -92
  439. package/templates/.claude/hooks/stop-worktree-check.sh +0 -46
  440. package/templates/.claude/hooks/test_classify_command.py +0 -370
  441. package/templates/.claude/hooks/test_wrapper_smoke.sh +0 -96
  442. package/templates/.claude/hooks/validate-spec.sh +0 -76
  443. package/templates/.claude/hooks/worktree-guard.sh +0 -220
  444. package/templates/.claude/hooks/worktree-write-guard.sh +0 -190
  445. package/templates/.claude/rules/git-safety.md +0 -26
  446. package/templates/.claude/rules/worktree-isolation.md +0 -101
  447. package/templates/.claude/settings.json +0 -141
  448. package/templates/.cursor/README.md +0 -299
  449. package/templates/.cursor/hooks/audit.sh +0 -55
  450. package/templates/.cursor/hooks/block-dangerous.sh +0 -84
  451. package/templates/.cursor/hooks/caws-quality-check.sh +0 -52
  452. package/templates/.cursor/hooks/caws-scope-guard.sh +0 -130
  453. package/templates/.cursor/hooks/format.sh +0 -38
  454. package/templates/.cursor/hooks/naming-check.sh +0 -64
  455. package/templates/.cursor/hooks/scan-secrets.sh +0 -51
  456. package/templates/.cursor/hooks/scope-guard.sh +0 -52
  457. package/templates/.cursor/hooks/session-log.sh +0 -924
  458. package/templates/.cursor/hooks/validate-spec.sh +0 -83
  459. package/templates/.cursor/hooks.json +0 -76
  460. package/templates/.cursor/rules/00-claims-verification.mdc +0 -144
  461. package/templates/.cursor/rules/01-working-style.mdc +0 -50
  462. package/templates/.cursor/rules/02-quality-gates.mdc +0 -368
  463. package/templates/.cursor/rules/03-naming-and-refactor.mdc +0 -33
  464. package/templates/.cursor/rules/04-logging-language-style.mdc +0 -23
  465. package/templates/.cursor/rules/05-safe-defaults-guards.mdc +0 -23
  466. package/templates/.cursor/rules/06-typescript-conventions.mdc +0 -36
  467. package/templates/.cursor/rules/07-process-ops.mdc +0 -20
  468. package/templates/.cursor/rules/08-solid-and-architecture.mdc +0 -16
  469. package/templates/.cursor/rules/09-docstrings.mdc +0 -89
  470. package/templates/.cursor/rules/10-documentation-quality-standards.mdc +0 -385
  471. package/templates/.cursor/rules/11-scope-management-waivers.mdc +0 -381
  472. package/templates/.cursor/rules/12-implementation-completeness.mdc +0 -516
  473. package/templates/.cursor/rules/13-language-agnostic-standards.mdc +0 -578
  474. package/templates/.cursor/rules/README.md +0 -148
  475. package/templates/.github/copilot-instructions.md +0 -82
  476. package/templates/.idea/runConfigurations/CAWS_Evaluate.xml +0 -5
  477. package/templates/.idea/runConfigurations/CAWS_Validate.xml +0 -5
  478. package/templates/.junie/guidelines.md +0 -73
  479. package/templates/.vscode/launch.json +0 -17
  480. package/templates/.vscode/settings.json +0 -95
  481. package/templates/.windsurf/rules/caws-quality-standards.md +0 -54
  482. package/templates/.windsurf/workflows/caws-guided-development.md +0 -92
  483. package/templates/CLAUDE.md +0 -196
  484. package/templates/COMMIT_CONVENTIONS.md +0 -86
  485. package/templates/OIDC_SETUP.md +0 -300
  486. package/templates/agents.md +0 -171
  487. package/templates/codemod/README.md +0 -1
  488. package/templates/codemod/test.js +0 -93
  489. package/templates/docs/README.md +0 -151
  490. package/templates/scripts/new_feature.sh +0 -80
  491. package/templates/scripts/quality-gates/check-god-objects.js +0 -146
  492. package/templates/scripts/quality-gates/run-quality-gates.js +0 -50
  493. package/templates/scripts/v3/analysis/todo_analyzer.py +0 -1997
@@ -0,0 +1,295 @@
1
+ "use strict";
2
+ // `caws init` — store-side bootstrap of the canonical vNext .caws/ shape.
3
+ //
4
+ // What this adapter creates (when absent):
5
+ //
6
+ // .caws/
7
+ // .caws/specs/ empty dir, multi-spec lives here
8
+ // .caws/waivers/ empty dir, slice-7a authority surface
9
+ // .caws/policy.yaml kernel-validated default policy
10
+ // .caws/worktrees.json {}
11
+ // .caws/agents.json {}
12
+ //
13
+ // What this adapter intentionally does NOT create:
14
+ //
15
+ // .caws/working-spec.yaml legacy single-spec entry point — the
16
+ // vNext model is multi-spec under
17
+ // .caws/specs/<id>.yaml. Seeding
18
+ // working-spec.yaml would silently
19
+ // reintroduce the legacy authority.
20
+ // .caws/working-spec.schema.json same reason.
21
+ // .caws/events.jsonl evidence is append-only and
22
+ // created by the first event under
23
+ // lock. Manufacturing an empty file
24
+ // would either be a zero-event chain
25
+ // (no genesis) or require a synthetic
26
+ // init event that doesn't represent
27
+ // any real state transition. The
28
+ // store treats a missing file as
29
+ // `events: []`, so doctor / status /
30
+ // waiver list all work without it.
31
+ //
32
+ // Idempotence and refusal:
33
+ // - missing .caws → create canonical state.
34
+ // - all canonical files exist → no-op, return AlreadyInitialized.
35
+ // - any LEGACY residue → refuse with INIT_LEGACY_RESIDUE
36
+ // naming each offending path. Do NOT
37
+ // touch anything. Repair belongs to a
38
+ // later doctor/repair surface.
39
+ //
40
+ // Authority discipline:
41
+ // - The seeded policy MUST pass `parseAndValidatePolicy` before
42
+ // hitting disk. If it doesn't, init refuses (this is a programmer
43
+ // error in our default, not a user-recoverable condition).
44
+ // - All writes go through `writeFileAtomic`. Concurrent invocations
45
+ // either both see "already initialized" or one wins and the other
46
+ // observes the same canonical state.
47
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
48
+ if (k2 === undefined) k2 = k;
49
+ var desc = Object.getOwnPropertyDescriptor(m, k);
50
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
51
+ desc = { enumerable: true, get: function() { return m[k]; } };
52
+ }
53
+ Object.defineProperty(o, k2, desc);
54
+ }) : (function(o, m, k, k2) {
55
+ if (k2 === undefined) k2 = k;
56
+ o[k2] = m[k];
57
+ }));
58
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
59
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
60
+ }) : function(o, v) {
61
+ o["default"] = v;
62
+ });
63
+ var __importStar = (this && this.__importStar) || (function () {
64
+ var ownKeys = function(o) {
65
+ ownKeys = Object.getOwnPropertyNames || function (o) {
66
+ var ar = [];
67
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
68
+ return ar;
69
+ };
70
+ return ownKeys(o);
71
+ };
72
+ return function (mod) {
73
+ if (mod && mod.__esModule) return mod;
74
+ var result = {};
75
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
76
+ __setModuleDefault(result, mod);
77
+ return result;
78
+ };
79
+ })();
80
+ Object.defineProperty(exports, "__esModule", { value: true });
81
+ exports.DEFAULT_POLICY_YAML = void 0;
82
+ exports.initProject = initProject;
83
+ const fs = __importStar(require("fs"));
84
+ const path = __importStar(require("path"));
85
+ const caws_kernel_1 = require("@paths.design/caws-kernel");
86
+ const caws_kernel_2 = require("@paths.design/caws-kernel");
87
+ const atomic_write_1 = require("./atomic-write");
88
+ const repo_root_1 = require("./repo-root");
89
+ const rules_1 = require("./rules");
90
+ // ---------------------------------------------------------------------------
91
+ // Canonical layout
92
+ // ---------------------------------------------------------------------------
93
+ /** Canonical files/dirs init creates (or expects to be present already). */
94
+ const CANONICAL_PATHS = {
95
+ cawsDir: '.caws',
96
+ specsDir: '.caws/specs',
97
+ waiversDir: '.caws/waivers',
98
+ policyFile: '.caws/policy.yaml',
99
+ worktreesFile: '.caws/worktrees.json',
100
+ agentsFile: '.caws/agents.json',
101
+ };
102
+ /**
103
+ * Files whose presence inside `.caws/` indicates legacy single-spec /
104
+ * pre-vNext state. init refuses to touch these — repair belongs to a
105
+ * later doctor/repair surface. Adding more entries here is the
106
+ * sanctioned way to extend the legacy-residue check.
107
+ */
108
+ const LEGACY_PATHS = [
109
+ '.caws/working-spec.yaml',
110
+ '.caws/working-spec.schema.json',
111
+ ];
112
+ // ---------------------------------------------------------------------------
113
+ // Default policy
114
+ //
115
+ // The seed below mirrors the gate set the vNext gates command knows
116
+ // about. Block-mode for the structural gates (budget_limit,
117
+ // spec_completeness, scope_boundary), warn for the heuristic gates
118
+ // (god_object, todo_detection). edit_rules is set to the conservative
119
+ // "policy and code may live in the same PR" default; teams can tighten.
120
+ // ---------------------------------------------------------------------------
121
+ exports.DEFAULT_POLICY_YAML = `version: 1
122
+ risk_tiers:
123
+ '1':
124
+ max_files: 5
125
+ max_loc: 200
126
+ '2':
127
+ max_files: 15
128
+ max_loc: 600
129
+ '3':
130
+ max_files: 30
131
+ max_loc: 1500
132
+ gates:
133
+ budget_limit:
134
+ enabled: true
135
+ mode: block
136
+ spec_completeness:
137
+ enabled: true
138
+ mode: block
139
+ scope_boundary:
140
+ enabled: true
141
+ mode: block
142
+ god_object:
143
+ enabled: true
144
+ mode: warn
145
+ todo_detection:
146
+ enabled: true
147
+ mode: warn
148
+ edit_rules:
149
+ policy_and_code_same_pr: true
150
+ require_signed_commits: false
151
+ require_dual_control_for_governance: false
152
+ `;
153
+ // ---------------------------------------------------------------------------
154
+ // Implementation
155
+ // ---------------------------------------------------------------------------
156
+ function abs(repoRoot, rel) {
157
+ return path.join(repoRoot, rel);
158
+ }
159
+ function existsCanonical(repoRoot) {
160
+ const isFile = (p) => fs.existsSync(p) && fs.statSync(p).isFile();
161
+ const isDir = (p) => fs.existsSync(p) && fs.statSync(p).isDirectory();
162
+ return {
163
+ cawsDir: isDir(abs(repoRoot, CANONICAL_PATHS.cawsDir)),
164
+ specsDir: isDir(abs(repoRoot, CANONICAL_PATHS.specsDir)),
165
+ waiversDir: isDir(abs(repoRoot, CANONICAL_PATHS.waiversDir)),
166
+ policyFile: isFile(abs(repoRoot, CANONICAL_PATHS.policyFile)),
167
+ worktreesFile: isFile(abs(repoRoot, CANONICAL_PATHS.worktreesFile)),
168
+ agentsFile: isFile(abs(repoRoot, CANONICAL_PATHS.agentsFile)),
169
+ };
170
+ }
171
+ function findLegacyResidue(repoRoot) {
172
+ // Use isFile semantics — must match observeInitResidue in
173
+ // doctor-snapshot.ts. A *file* at one of the legacy paths is
174
+ // residue; a *directory* at the same path is a different problem
175
+ // (not yet a separately-modeled rule) and must not be conflated
176
+ // with file-residue. Otherwise init refuses while doctor stays
177
+ // silent on the same project state.
178
+ const found = [];
179
+ for (const rel of LEGACY_PATHS) {
180
+ const p = abs(repoRoot, rel);
181
+ try {
182
+ if (fs.statSync(p).isFile())
183
+ found.push(p);
184
+ }
185
+ catch {
186
+ // ENOENT or similar — not residue.
187
+ }
188
+ }
189
+ return found;
190
+ }
191
+ function legacyDiag(found) {
192
+ return (0, repo_root_1.storeDiagnostic)(rules_1.STORE_RULES.INIT_LEGACY_RESIDUE, `caws init refuses to overwrite legacy state: ${found.join(', ')}.`, {
193
+ narrowRepair: 'Move or remove the listed files manually, then re-run `caws init`. Repair tooling belongs to a later doctor/repair surface; init is intentionally non-destructive.',
194
+ data: { legacy_paths: found.slice() },
195
+ });
196
+ }
197
+ function mkdirRecursive(target) {
198
+ try {
199
+ fs.mkdirSync(target, { recursive: true });
200
+ return (0, caws_kernel_2.ok)(true);
201
+ }
202
+ catch (e) {
203
+ return (0, caws_kernel_2.err)((0, repo_root_1.storeDiagnostic)(rules_1.STORE_RULES.WRITE_IO_FAILED, `Failed to create ${target}: ${e.message}.`, { subject: target }));
204
+ }
205
+ }
206
+ /**
207
+ * Idempotent vNext init. Returns:
208
+ *
209
+ * Ok({ outcome: 'created', created: [...], policy })
210
+ * Ok({ outcome: 'already_initialized', created: [], policy })
211
+ * Err on legacy residue (INIT_LEGACY_RESIDUE) or write failure
212
+ * (WRITE_IO_FAILED) or a default-policy that fails kernel
213
+ * validation (INIT_DEFAULT_POLICY_INVALID).
214
+ */
215
+ function initProject(repoRoot) {
216
+ if (typeof repoRoot !== 'string' || repoRoot.length === 0) {
217
+ throw new TypeError('initProject: repoRoot must be a non-empty string.');
218
+ }
219
+ // 1. Refuse if any legacy residue exists. Do this BEFORE any write so
220
+ // the caller's repo is not mutated when we say "no".
221
+ const residue = findLegacyResidue(repoRoot);
222
+ if (residue.length > 0) {
223
+ return (0, caws_kernel_2.err)(legacyDiag(residue));
224
+ }
225
+ // 2. Validate the default policy through the kernel. If our seed is
226
+ // bad, surface that as INIT_DEFAULT_POLICY_INVALID — do NOT write
227
+ // a known-invalid policy to disk just to keep init succeeding.
228
+ const validatedPolicy = (0, caws_kernel_1.parseAndValidatePolicy)(exports.DEFAULT_POLICY_YAML);
229
+ if (!(0, caws_kernel_1.isOk)(validatedPolicy)) {
230
+ return (0, caws_kernel_2.err)((0, repo_root_1.storeDiagnostic)(rules_1.STORE_RULES.INIT_DEFAULT_POLICY_INVALID, `Default policy failed kernel validation: ${validatedPolicy.errors.map((d) => d.rule).join(', ')}.`, { data: { kernel_diagnostics: validatedPolicy.errors.slice() } }));
231
+ }
232
+ const policy = validatedPolicy.value;
233
+ // 3. Decide outcome. If every canonical file/dir is present, do nothing.
234
+ const present = existsCanonical(repoRoot);
235
+ const allPresent = present.cawsDir &&
236
+ present.specsDir &&
237
+ present.waiversDir &&
238
+ present.policyFile &&
239
+ present.worktreesFile &&
240
+ present.agentsFile;
241
+ if (allPresent) {
242
+ return (0, caws_kernel_2.ok)({
243
+ outcome: 'already_initialized',
244
+ created: [],
245
+ policy,
246
+ });
247
+ }
248
+ // 4. Create the missing pieces. We track what we actually wrote so the
249
+ // shell can report "what changed" precisely. Each step is its own
250
+ // Ok-or-Err — we abort on the first error rather than continue and
251
+ // partially populate.
252
+ const created = [];
253
+ if (!present.cawsDir) {
254
+ const r = mkdirRecursive(abs(repoRoot, CANONICAL_PATHS.cawsDir));
255
+ if (!(0, caws_kernel_1.isOk)(r))
256
+ return r;
257
+ created.push(abs(repoRoot, CANONICAL_PATHS.cawsDir));
258
+ }
259
+ if (!present.specsDir) {
260
+ const r = mkdirRecursive(abs(repoRoot, CANONICAL_PATHS.specsDir));
261
+ if (!(0, caws_kernel_1.isOk)(r))
262
+ return r;
263
+ created.push(abs(repoRoot, CANONICAL_PATHS.specsDir));
264
+ }
265
+ if (!present.waiversDir) {
266
+ const r = mkdirRecursive(abs(repoRoot, CANONICAL_PATHS.waiversDir));
267
+ if (!(0, caws_kernel_1.isOk)(r))
268
+ return r;
269
+ created.push(abs(repoRoot, CANONICAL_PATHS.waiversDir));
270
+ }
271
+ if (!present.policyFile) {
272
+ const r = (0, atomic_write_1.writeFileAtomic)(abs(repoRoot, CANONICAL_PATHS.policyFile), exports.DEFAULT_POLICY_YAML);
273
+ if (!(0, caws_kernel_1.isOk)(r))
274
+ return r;
275
+ created.push(abs(repoRoot, CANONICAL_PATHS.policyFile));
276
+ }
277
+ if (!present.worktreesFile) {
278
+ const r = (0, atomic_write_1.writeFileAtomic)(abs(repoRoot, CANONICAL_PATHS.worktreesFile), '{}\n');
279
+ if (!(0, caws_kernel_1.isOk)(r))
280
+ return r;
281
+ created.push(abs(repoRoot, CANONICAL_PATHS.worktreesFile));
282
+ }
283
+ if (!present.agentsFile) {
284
+ const r = (0, atomic_write_1.writeFileAtomic)(abs(repoRoot, CANONICAL_PATHS.agentsFile), '{}\n');
285
+ if (!(0, caws_kernel_1.isOk)(r))
286
+ return r;
287
+ created.push(abs(repoRoot, CANONICAL_PATHS.agentsFile));
288
+ }
289
+ return (0, caws_kernel_2.ok)({
290
+ outcome: 'created',
291
+ created,
292
+ policy,
293
+ });
294
+ }
295
+ //# sourceMappingURL=init-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-store.js","sourceRoot":"","sources":["../../src/store/init-store.ts"],"names":[],"mappings":";AAAA,0EAA0E;AAC1E,EAAE;AACF,2CAA2C;AAC3C,EAAE;AACF,WAAW;AACX,mEAAmE;AACnE,wEAAwE;AACxE,kEAAkE;AAClE,qCAAqC;AACrC,qCAAqC;AACrC,EAAE;AACF,mDAAmD;AACnD,EAAE;AACF,uEAAuE;AACvE,kEAAkE;AAClE,iEAAiE;AACjE,mEAAmE;AACnE,oEAAoE;AACpE,iDAAiD;AACjD,8DAA8D;AAC9D,mEAAmE;AACnE,oEAAoE;AACpE,qEAAqE;AACrE,sEAAsE;AACtE,oEAAoE;AACpE,iEAAiE;AACjE,iEAAiE;AACjE,qEAAqE;AACrE,mEAAmE;AACnE,EAAE;AACF,2BAA2B;AAC3B,yDAAyD;AACzD,oEAAoE;AACpE,iEAAiE;AACjE,oEAAoE;AACpE,qEAAqE;AACrE,8DAA8D;AAC9D,EAAE;AACF,wBAAwB;AACxB,kEAAkE;AAClE,sEAAsE;AACtE,+DAA+D;AAC/D,sEAAsE;AACtE,sEAAsE;AACtE,yCAAyC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuLzC,kCAiGC;AAtRD,uCAAyB;AACzB,2CAA6B;AAE7B,2DAMmC;A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AA,kBAAI,EAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,IAAA,gBAAE,EAAC;QACR,OAAO,EAAE,SAAS;QAClB,OAAO;QACP,MAAM;KACP,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type Result } from '@paths.design/caws-kernel';
2
+ export declare function readJsonFile(filePath: string): Result<unknown>;
3
+ //# sourceMappingURL=json-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-store.d.ts","sourceRoot":"","sources":["../../src/store/json-store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAIjE,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAkC9D"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ // JSON read helper. Same shape and discipline as yaml-store: report
3
+ // missing/malformed via discrete rule ids.
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
17
+ }) : function(o, v) {
18
+ o["default"] = v;
19
+ });
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.readJsonFile = readJsonFile;
39
+ const fs = __importStar(require("fs"));
40
+ const caws_kernel_1 = require("@paths.design/caws-kernel");
41
+ const repo_root_1 = require("./repo-root");
42
+ const rules_1 = require("./rules");
43
+ function readJsonFile(filePath) {
44
+ let raw;
45
+ try {
46
+ raw = fs.readFileSync(filePath, 'utf8');
47
+ }
48
+ catch (e) {
49
+ const cause = e;
50
+ if (cause.code === 'ENOENT') {
51
+ return (0, caws_kernel_1.err)((0, repo_root_1.storeDiagnostic)(rules_1.STORE_RULES.READ_MISSING_FILE, `File not found: ${filePath}.`, {
52
+ subject: filePath,
53
+ }));
54
+ }
55
+ return (0, caws_kernel_1.err)((0, repo_root_1.storeDiagnostic)(rules_1.STORE_RULES.READ_IO_FAILED, `Failed to read ${filePath}: ${cause.message ?? 'unknown error'}.`, { subject: filePath, data: { code: cause.code } }));
56
+ }
57
+ try {
58
+ return (0, caws_kernel_1.ok)(JSON.parse(raw));
59
+ }
60
+ catch (e) {
61
+ const cause = e;
62
+ return (0, caws_kernel_1.err)((0, repo_root_1.storeDiagnostic)(rules_1.STORE_RULES.READ_JSON_INVALID, `JSON parse failed in ${filePath}: ${cause.message ?? 'unknown error'}.`, { subject: filePath }));
63
+ }
64
+ }
65
+ //# sourceMappingURL=json-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-store.js","sourceRoot":"","sources":["../../src/store/json-store.ts"],"names":[],"mappings":";AAAA,oEAAo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@@ -0,0 +1,34 @@
1
+ import { type Result } from '@paths.design/caws-kernel';
2
+ export interface LifecycleLockHandle {
3
+ readonly fd: number;
4
+ readonly lockPath: string;
5
+ }
6
+ export interface AcquireLifecycleLockOptions {
7
+ /** Override the global lock path. Used by tests; production callers
8
+ * pass cawsDir and get the canonical `<cawsDir>/state.lock`. */
9
+ readonly lockPath?: string;
10
+ /** Override stale-lock threshold. Defaults to 30s. Tests can lower it
11
+ * to validate recovery without sleeping. */
12
+ readonly staleThresholdMs?: number;
13
+ /** Override max attempts. Defaults to 3. */
14
+ readonly maxAttempts?: number;
15
+ /** Override retry delay. Defaults to 50ms. */
16
+ readonly retryDelayMs?: number;
17
+ }
18
+ /**
19
+ * Acquire the global lifecycle mutation lock. Returns a `LifecycleLockHandle`
20
+ * the caller MUST release via `releaseLifecycleLock` in a `finally` block.
21
+ *
22
+ * The lock is held by the existence of `<cawsDir>/state.lock`. Concurrent
23
+ * callers retry up to `maxAttempts` with `retryDelayMs` between attempts.
24
+ * Stale locks (older than `staleThresholdMs`) are reclaimed.
25
+ */
26
+ export declare function acquireLifecycleLock(cawsDir: string, options?: AcquireLifecycleLockOptions): Result<LifecycleLockHandle>;
27
+ /** Release the lifecycle lock. Always safe to call; errors are swallowed
28
+ * because lock-release is best-effort (the lockfile is the contract, not
29
+ * the fd state). */
30
+ export declare function releaseLifecycleLock(handle: LifecycleLockHandle): void;
31
+ /** Convenience wrapper: acquire, run the body, release in a `finally`.
32
+ * Returns the body's `Result` or the acquire-failure `Result`. */
33
+ export declare function withLifecycleLock<T>(cawsDir: string, body: () => Result<T>, options?: AcquireLifecycleLockOptions): Result<T>;
34
+ //# sourceMappingURL=lifecycle-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle-lock.d.ts","sourceRoot":"","sources":["../../src/store/lifecycle-lock.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAUjE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,2BAA2B;IAC1C;qEACiE;IACjE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;iDAC6C;IAC7C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,4CAA4C;IAC5C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,8CAA8C;IAC9C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AA6BD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,2BAAgC,GACxC,MAAM,CAAC,mBAAmB,CAAC,CAmD7B;AAED;;qBAEqB;AACrB,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAWtE;AAED;mEACmE;AACnE,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,MAAM,CAAC,CAAC,CAAC,EACrB,OAAO,GAAE,2BAAgC,GACxC,MAAM,CAAC,CAAC,CAAC,CAUX"}
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ // Lifecycle mutation lock.
3
+ //
4
+ // LIFECYCLE-MUTATION-001 invariant: multi-file lifecycle mutations
5
+ // serialize through a single global `.caws/state.lock`. This lock is
6
+ // distinct from `.caws/events.jsonl.lock` (held by appendEvent only)
7
+ // because lifecycle mutations cross file boundaries — spec YAML +
8
+ // registry + event append — and need a wider critical section than
9
+ // the per-file event lock provides.
10
+ //
11
+ // Per-resource locks (per-spec, per-worktree) are deferred. The plan
12
+ // is: get the lifecycle mutation graph stable on a single conservative
13
+ // lock first; introduce finer-grained locking only when the mutation
14
+ // surface is well understood. Premature optimization here recreates
15
+ // exactly the cross-file split-brain hazard the substrate exists to
16
+ // prevent.
17
+ //
18
+ // Implementation parity with events-store.ts:
19
+ // - existence-based lockfile (`openSync(path, 'wx')`)
20
+ // - bounded retry with stale-lock recovery
21
+ // - same constants: 30s stale threshold, 3 attempts, 50ms retry
22
+ // - release in `finally` of caller's wrapper (transaction layer)
23
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
35
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
36
+ }) : function(o, v) {
37
+ o["default"] = v;
38
+ });
39
+ var __importStar = (this && this.__importStar) || (function () {
40
+ var ownKeys = function(o) {
41
+ ownKeys = Object.getOwnPropertyNames || function (o) {
42
+ var ar = [];
43
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
44
+ return ar;
45
+ };
46
+ return ownKeys(o);
47
+ };
48
+ return function (mod) {
49
+ if (mod && mod.__esModule) return mod;
50
+ var result = {};
51
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
52
+ __setModuleDefault(result, mod);
53
+ return result;
54
+ };
55
+ })();
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.acquireLifecycleLock = acquireLifecycleLock;
58
+ exports.releaseLifecycleLock = releaseLifecycleLock;
59
+ exports.withLifecycleLock = withLifecycleLock;
60
+ const fs = __importStar(require("fs"));
61
+ const path = __importStar(require("path"));
62
+ const caws_kernel_1 = require("@paths.design/caws-kernel");
63
+ const repo_root_1 = require("./repo-root");
64
+ const rules_1 = require("./rules");
65
+ const LOCK_FILE_NAME = 'state.lock';
66
+ const LOCK_MAX_ATTEMPTS = 3;
67
+ const LOCK_RETRY_DELAY_MS = 50;
68
+ const LOCK_STALE_MS = 30_000;
69
+ function sleepSyncMs(ms) {
70
+ // Busy-wait short sleep. Matches events-store.ts pattern.
71
+ const end = Date.now() + ms;
72
+ while (Date.now() < end) {
73
+ // intentional spin
74
+ }
75
+ }
76
+ function tryRecoverStaleLock(lockPath, staleThresholdMs) {
77
+ try {
78
+ const stat = fs.statSync(lockPath);
79
+ const ageMs = Date.now() - stat.mtimeMs;
80
+ if (ageMs > staleThresholdMs) {
81
+ fs.unlinkSync(lockPath);
82
+ return true;
83
+ }
84
+ }
85
+ catch {
86
+ // Race: lock was released between EEXIST and statSync. Treat as
87
+ // recoverable so the next attempt can take it.
88
+ return true;
89
+ }
90
+ return false;
91
+ }
92
+ /**
93
+ * Acquire the global lifecycle mutation lock. Returns a `LifecycleLockHandle`
94
+ * the caller MUST release via `releaseLifecycleLock` in a `finally` block.
95
+ *
96
+ * The lock is held by the existence of `<cawsDir>/state.lock`. Concurrent
97
+ * callers retry up to `maxAttempts` with `retryDelayMs` between attempts.
98
+ * Stale locks (older than `staleThresholdMs`) are reclaimed.
99
+ */
100
+ function acquireLifecycleLock(cawsDir, options = {}) {
101
+ const lockPath = options.lockPath ?? path.join(cawsDir, LOCK_FILE_NAME);
102
+ const staleThresholdMs = options.staleThresholdMs ?? LOCK_STALE_MS;
103
+ const maxAttempts = options.maxAttempts ?? LOCK_MAX_ATTEMPTS;
104
+ const retryDelayMs = options.retryDelayMs ?? LOCK_RETRY_DELAY_MS;
105
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
106
+ try {
107
+ const fd = fs.openSync(lockPath, 'wx');
108
+ // Best-effort metadata so a future doctor or operator can see who
109
+ // is holding the lock.
110
+ try {
111
+ fs.writeFileSync(fd, JSON.stringify({
112
+ pid: process.pid,
113
+ at: new Date().toISOString(),
114
+ purpose: 'lifecycle-mutation',
115
+ }));
116
+ fs.fsyncSync(fd);
117
+ }
118
+ catch {
119
+ // Lock content is best-effort; the lock itself is the file's
120
+ // existence.
121
+ }
122
+ return (0, caws_kernel_1.ok)({ fd, lockPath });
123
+ }
124
+ catch (e) {
125
+ const cause = e;
126
+ if (cause.code !== 'EEXIST') {
127
+ return (0, caws_kernel_1.err)((0, repo_root_1.storeDiagnostic)(rules_1.STORE_RULES.LIFECYCLE_LOCK_CONTENTION, `Unexpected error acquiring lifecycle lock: ${cause.message ?? 'unknown error'}.`, { subject: lockPath, data: { code: cause.code ?? null } }));
128
+ }
129
+ const recovered = tryRecoverStaleLock(lockPath, staleThresholdMs);
130
+ if (!recovered) {
131
+ sleepSyncMs(retryDelayMs);
132
+ }
133
+ }
134
+ }
135
+ return (0, caws_kernel_1.err)((0, repo_root_1.storeDiagnostic)(rules_1.STORE_RULES.LIFECYCLE_LOCK_CONTENTION, `Could not acquire lifecycle lock after ${maxAttempts} attempts.`, { subject: lockPath }));
136
+ }
137
+ /** Release the lifecycle lock. Always safe to call; errors are swallowed
138
+ * because lock-release is best-effort (the lockfile is the contract, not
139
+ * the fd state). */
140
+ function releaseLifecycleLock(handle) {
141
+ try {
142
+ fs.closeSync(handle.fd);
143
+ }
144
+ catch {
145
+ /* ignore */
146
+ }
147
+ try {
148
+ fs.unlinkSync(handle.lockPath);
149
+ }
150
+ catch {
151
+ /* ignore */
152
+ }
153
+ }
154
+ /** Convenience wrapper: acquire, run the body, release in a `finally`.
155
+ * Returns the body's `Result` or the acquire-failure `Result`. */
156
+ function withLifecycleLock(cawsDir, body, options = {}) {
157
+ const acquired = acquireLifecycleLock(cawsDir, options);
158
+ if (!acquired.ok) {
159
+ return acquired;
160
+ }
161
+ try {
162
+ return body();
163
+ }
164
+ finally {
165
+ releaseLifecycleLock(acquired.value);
166
+ }
167
+ }
168
+ //# sourceMappingURL=lifecycle-lock.js.map
@@ -0,0 +1 @@
1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