@paths.design/caws-cli 10.2.0 → 11.0.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 (421) hide show
  1. package/README.md +125 -374
  2. package/dist/index.js +43 -785
  3. package/dist/shell/binding/resolve-binding.d.ts +4 -0
  4. package/dist/shell/binding/resolve-binding.d.ts.map +1 -0
  5. package/dist/shell/binding/resolve-binding.js +228 -0
  6. package/dist/shell/binding/resolve-binding.js.map +1 -0
  7. package/dist/shell/binding/types.d.ts +42 -0
  8. package/dist/shell/binding/types.d.ts.map +1 -0
  9. package/dist/shell/binding/types.js +21 -0
  10. package/dist/shell/binding/types.js.map +1 -0
  11. package/dist/shell/commands/claim.d.ts +14 -0
  12. package/dist/shell/commands/claim.d.ts.map +1 -0
  13. package/dist/shell/commands/claim.js +197 -0
  14. package/dist/shell/commands/claim.js.map +1 -0
  15. package/dist/shell/commands/doctor.d.ts +13 -0
  16. package/dist/shell/commands/doctor.d.ts.map +1 -0
  17. package/dist/shell/commands/doctor.js +97 -0
  18. package/dist/shell/commands/doctor.js.map +1 -0
  19. package/dist/shell/commands/evidence.d.ts +28 -0
  20. package/dist/shell/commands/evidence.d.ts.map +1 -0
  21. package/dist/shell/commands/evidence.js +166 -0
  22. package/dist/shell/commands/evidence.js.map +1 -0
  23. package/dist/shell/commands/gates.d.ts +19 -0
  24. package/dist/shell/commands/gates.d.ts.map +1 -0
  25. package/dist/shell/commands/gates.js +181 -0
  26. package/dist/shell/commands/gates.js.map +1 -0
  27. package/dist/shell/commands/init.d.ts +8 -0
  28. package/dist/shell/commands/init.d.ts.map +1 -0
  29. package/dist/shell/commands/init.js +64 -0
  30. package/dist/shell/commands/init.js.map +1 -0
  31. package/dist/shell/commands/scope.d.ts +11 -0
  32. package/dist/shell/commands/scope.d.ts.map +1 -0
  33. package/dist/shell/commands/scope.js +92 -0
  34. package/dist/shell/commands/scope.js.map +1 -0
  35. package/dist/shell/commands/status.d.ts +15 -0
  36. package/dist/shell/commands/status.d.ts.map +1 -0
  37. package/dist/shell/commands/status.js +106 -0
  38. package/dist/shell/commands/status.js.map +1 -0
  39. package/dist/shell/commands/waiver.d.ts +38 -0
  40. package/dist/shell/commands/waiver.d.ts.map +1 -0
  41. package/dist/shell/commands/waiver.js +240 -0
  42. package/dist/shell/commands/waiver.js.map +1 -0
  43. package/dist/shell/gates/disposition.d.ts +23 -0
  44. package/dist/shell/gates/disposition.d.ts.map +1 -0
  45. package/dist/shell/gates/disposition.js +87 -0
  46. package/dist/shell/gates/disposition.js.map +1 -0
  47. package/dist/shell/gates/gate-result-contract.d.ts +39 -0
  48. package/dist/shell/gates/gate-result-contract.d.ts.map +1 -0
  49. package/dist/shell/gates/gate-result-contract.js +150 -0
  50. package/dist/shell/gates/gate-result-contract.js.map +1 -0
  51. package/dist/shell/gates/quality-gates-adapter.d.ts +55 -0
  52. package/dist/shell/gates/quality-gates-adapter.d.ts.map +1 -0
  53. package/dist/shell/gates/quality-gates-adapter.js +161 -0
  54. package/dist/shell/gates/quality-gates-adapter.js.map +1 -0
  55. package/dist/shell/gates/waiver-filter.d.ts +58 -0
  56. package/dist/shell/gates/waiver-filter.d.ts.map +1 -0
  57. package/dist/shell/gates/waiver-filter.js +119 -0
  58. package/dist/shell/gates/waiver-filter.js.map +1 -0
  59. package/dist/shell/index.d.ts +50 -0
  60. package/dist/shell/index.d.ts.map +1 -0
  61. package/dist/shell/index.js +73 -0
  62. package/dist/shell/index.js.map +1 -0
  63. package/dist/shell/register.d.ts +11 -0
  64. package/dist/shell/register.d.ts.map +1 -0
  65. package/dist/shell/register.js +274 -0
  66. package/dist/shell/register.js.map +1 -0
  67. package/dist/shell/render/claim.d.ts +22 -0
  68. package/dist/shell/render/claim.d.ts.map +1 -0
  69. package/dist/shell/render/claim.js +75 -0
  70. package/dist/shell/render/claim.js.map +1 -0
  71. package/dist/shell/render/decision.d.ts +15 -0
  72. package/dist/shell/render/decision.d.ts.map +1 -0
  73. package/dist/shell/render/decision.js +66 -0
  74. package/dist/shell/render/decision.js.map +1 -0
  75. package/dist/shell/render/diagnostic.d.ts +19 -0
  76. package/dist/shell/render/diagnostic.d.ts.map +1 -0
  77. package/dist/shell/render/diagnostic.js +76 -0
  78. package/dist/shell/render/diagnostic.js.map +1 -0
  79. package/dist/shell/render/finding.d.ts +15 -0
  80. package/dist/shell/render/finding.d.ts.map +1 -0
  81. package/dist/shell/render/finding.js +57 -0
  82. package/dist/shell/render/finding.js.map +1 -0
  83. package/dist/shell/render/gates.d.ts +3 -0
  84. package/dist/shell/render/gates.d.ts.map +1 -0
  85. package/dist/shell/render/gates.js +56 -0
  86. package/dist/shell/render/gates.js.map +1 -0
  87. package/dist/shell/render/init.d.ts +11 -0
  88. package/dist/shell/render/init.d.ts.map +1 -0
  89. package/dist/shell/render/init.js +32 -0
  90. package/dist/shell/render/init.js.map +1 -0
  91. package/dist/shell/render/status.d.ts +26 -0
  92. package/dist/shell/render/status.d.ts.map +1 -0
  93. package/dist/shell/render/status.js +143 -0
  94. package/dist/shell/render/status.js.map +1 -0
  95. package/dist/shell/render/waiver.d.ts +21 -0
  96. package/dist/shell/render/waiver.d.ts.map +1 -0
  97. package/dist/shell/render/waiver.js +94 -0
  98. package/dist/shell/render/waiver.js.map +1 -0
  99. package/dist/shell/rules.d.ts +37 -0
  100. package/dist/shell/rules.d.ts.map +1 -0
  101. package/dist/shell/rules.js +51 -0
  102. package/dist/shell/rules.js.map +1 -0
  103. package/dist/shell/session/actor.d.ts +14 -0
  104. package/dist/shell/session/actor.d.ts.map +1 -0
  105. package/dist/shell/session/actor.js +34 -0
  106. package/dist/shell/session/actor.js.map +1 -0
  107. package/dist/shell/session/resolve-session.d.ts +5 -0
  108. package/dist/shell/session/resolve-session.d.ts.map +1 -0
  109. package/dist/shell/session/resolve-session.js +239 -0
  110. package/dist/shell/session/resolve-session.js.map +1 -0
  111. package/dist/shell/session/types.d.ts +56 -0
  112. package/dist/shell/session/types.d.ts.map +1 -0
  113. package/dist/shell/session/types.js +15 -0
  114. package/dist/shell/session/types.js.map +1 -0
  115. package/dist/store/agents-store.d.ts +3 -0
  116. package/dist/store/agents-store.d.ts.map +1 -0
  117. package/dist/store/agents-store.js +63 -0
  118. package/dist/store/agents-store.js.map +1 -0
  119. package/dist/store/apply-patch.d.ts +16 -0
  120. package/dist/store/apply-patch.d.ts.map +1 -0
  121. package/dist/store/apply-patch.js +191 -0
  122. package/dist/store/apply-patch.js.map +1 -0
  123. package/dist/store/atomic-write.d.ts +16 -0
  124. package/dist/store/atomic-write.d.ts.map +1 -0
  125. package/dist/store/atomic-write.js +132 -0
  126. package/dist/store/atomic-write.js.map +1 -0
  127. package/dist/store/doctor-snapshot.d.ts +20 -0
  128. package/dist/store/doctor-snapshot.d.ts.map +1 -0
  129. package/dist/store/doctor-snapshot.js +176 -0
  130. package/dist/store/doctor-snapshot.js.map +1 -0
  131. package/dist/store/events-store.d.ts +33 -0
  132. package/dist/store/events-store.d.ts.map +1 -0
  133. package/dist/store/events-store.js +297 -0
  134. package/dist/store/events-store.js.map +1 -0
  135. package/dist/store/index.d.ts +21 -0
  136. package/dist/store/index.d.ts.map +1 -0
  137. package/dist/store/index.js +47 -0
  138. package/dist/store/index.js.map +1 -0
  139. package/dist/store/init-store.d.ts +21 -0
  140. package/dist/store/init-store.d.ts.map +1 -0
  141. package/dist/store/init-store.js +295 -0
  142. package/dist/store/init-store.js.map +1 -0
  143. package/dist/store/json-store.d.ts +3 -0
  144. package/dist/store/json-store.d.ts.map +1 -0
  145. package/dist/store/json-store.js +65 -0
  146. package/dist/store/json-store.js.map +1 -0
  147. package/dist/store/policy-store.d.ts +3 -0
  148. package/dist/store/policy-store.d.ts.map +1 -0
  149. package/dist/store/policy-store.js +65 -0
  150. package/dist/store/policy-store.js.map +1 -0
  151. package/dist/store/repo-root.d.ts +46 -0
  152. package/dist/store/repo-root.d.ts.map +1 -0
  153. package/dist/store/repo-root.js +145 -0
  154. package/dist/store/repo-root.js.map +1 -0
  155. package/dist/store/rules.d.ts +53 -0
  156. package/dist/store/rules.d.ts.map +1 -0
  157. package/dist/store/rules.js +78 -0
  158. package/dist/store/rules.js.map +1 -0
  159. package/dist/store/specs-store.d.ts +3 -0
  160. package/dist/store/specs-store.d.ts.map +1 -0
  161. package/dist/store/specs-store.js +131 -0
  162. package/dist/store/specs-store.js.map +1 -0
  163. package/dist/store/types.d.ts +84 -0
  164. package/dist/store/types.d.ts.map +1 -0
  165. package/dist/store/types.js +14 -0
  166. package/dist/store/types.js.map +1 -0
  167. package/dist/store/waivers-store.d.ts +25 -0
  168. package/dist/store/waivers-store.d.ts.map +1 -0
  169. package/dist/store/waivers-store.js +232 -0
  170. package/dist/store/waivers-store.js.map +1 -0
  171. package/dist/store/worktrees-store.d.ts +3 -0
  172. package/dist/store/worktrees-store.d.ts.map +1 -0
  173. package/dist/store/worktrees-store.js +62 -0
  174. package/dist/store/worktrees-store.js.map +1 -0
  175. package/dist/store/yaml-store.d.ts +9 -0
  176. package/dist/store/yaml-store.d.ts.map +1 -0
  177. package/dist/store/yaml-store.js +121 -0
  178. package/dist/store/yaml-store.js.map +1 -0
  179. package/package.json +15 -13
  180. package/dist/budget-derivation.js +0 -751
  181. package/dist/cicd-optimizer.js +0 -504
  182. package/dist/commands/agents.js +0 -124
  183. package/dist/commands/archive.js +0 -500
  184. package/dist/commands/burnup.js +0 -198
  185. package/dist/commands/diagnose.js +0 -525
  186. package/dist/commands/evaluate.js +0 -314
  187. package/dist/commands/gates.js +0 -149
  188. package/dist/commands/init.js +0 -857
  189. package/dist/commands/iterate.js +0 -417
  190. package/dist/commands/mode.js +0 -269
  191. package/dist/commands/parallel.js +0 -242
  192. package/dist/commands/plan.js +0 -438
  193. package/dist/commands/provenance.js +0 -1143
  194. package/dist/commands/quality-monitor.js +0 -284
  195. package/dist/commands/scope.js +0 -264
  196. package/dist/commands/session.js +0 -312
  197. package/dist/commands/sidecar.js +0 -74
  198. package/dist/commands/specs.js +0 -1656
  199. package/dist/commands/status.js +0 -1172
  200. package/dist/commands/templates.js +0 -237
  201. package/dist/commands/tool.js +0 -136
  202. package/dist/commands/tutorial.js +0 -480
  203. package/dist/commands/validate.js +0 -357
  204. package/dist/commands/verify-acs.js +0 -443
  205. package/dist/commands/waivers.js +0 -599
  206. package/dist/commands/workflow.js +0 -243
  207. package/dist/commands/worktree.js +0 -502
  208. package/dist/config/lite-scope.js +0 -158
  209. package/dist/config/modes.js +0 -347
  210. package/dist/constants/spec-types.js +0 -65
  211. package/dist/gates/budget-limit.js +0 -121
  212. package/dist/gates/feedback.js +0 -260
  213. package/dist/gates/format.js +0 -179
  214. package/dist/gates/god-object.js +0 -117
  215. package/dist/gates/pipeline.js +0 -167
  216. package/dist/gates/scope-boundary.js +0 -112
  217. package/dist/gates/spec-completeness.js +0 -109
  218. package/dist/gates/todo-detection.js +0 -205
  219. package/dist/generators/jest-config-generator.js +0 -242
  220. package/dist/generators/working-spec.js +0 -237
  221. package/dist/minimal-cli.js +0 -88
  222. package/dist/parallel/parallel-manager.js +0 -433
  223. package/dist/policy/PolicyManager.js +0 -470
  224. package/dist/scaffold/claude-hooks.js +0 -443
  225. package/dist/scaffold/cursor-hooks.js +0 -177
  226. package/dist/scaffold/git-hooks.js +0 -928
  227. package/dist/scaffold/index.js +0 -794
  228. package/dist/session/session-manager.js +0 -653
  229. package/dist/sidecars/index.js +0 -33
  230. package/dist/sidecars/listeners.js +0 -40
  231. package/dist/sidecars/provenance-summary.js +0 -238
  232. package/dist/sidecars/quality-gaps.js +0 -258
  233. package/dist/sidecars/schema.js +0 -149
  234. package/dist/sidecars/spec-drift.js +0 -151
  235. package/dist/sidecars/waiver-draft.js +0 -176
  236. package/dist/spec/SpecFileManager.js +0 -419
  237. package/dist/templates/.caws/schemas/policy.schema.json +0 -117
  238. package/dist/templates/.caws/schemas/scope.schema.json +0 -52
  239. package/dist/templates/.caws/schemas/waivers.schema.json +0 -106
  240. package/dist/templates/.caws/schemas/working-spec.schema.json +0 -340
  241. package/dist/templates/.caws/schemas/worktrees.schema.json +0 -38
  242. package/dist/templates/.caws/templates/working-spec.template.yml +0 -80
  243. package/dist/templates/.caws/tools/README.md +0 -18
  244. package/dist/templates/.caws/tools/scope-guard.js +0 -203
  245. package/dist/templates/.caws/tools-allow.json +0 -331
  246. package/dist/templates/.caws/waivers.yml +0 -19
  247. package/dist/templates/.claude/README.md +0 -190
  248. package/dist/templates/.claude/hooks/audit.sh +0 -121
  249. package/dist/templates/.claude/hooks/block-dangerous.sh +0 -203
  250. package/dist/templates/.claude/hooks/classify_command.py +0 -592
  251. package/dist/templates/.claude/hooks/doc-frontmatter-check.sh +0 -173
  252. package/dist/templates/.claude/hooks/lite-sprawl-check.sh +0 -145
  253. package/dist/templates/.claude/hooks/naming-check.sh +0 -100
  254. package/dist/templates/.claude/hooks/protected-paths.sh +0 -39
  255. package/dist/templates/.claude/hooks/quality-check.sh +0 -81
  256. package/dist/templates/.claude/hooks/scan-secrets.sh +0 -85
  257. package/dist/templates/.claude/hooks/scope-guard.sh +0 -381
  258. package/dist/templates/.claude/hooks/session-caws-status.sh +0 -117
  259. package/dist/templates/.claude/hooks/session-log.sh +0 -634
  260. package/dist/templates/.claude/hooks/simplification-guard.sh +0 -92
  261. package/dist/templates/.claude/hooks/stop-worktree-check.sh +0 -46
  262. package/dist/templates/.claude/hooks/test_classify_command.py +0 -370
  263. package/dist/templates/.claude/hooks/test_wrapper_smoke.sh +0 -96
  264. package/dist/templates/.claude/hooks/validate-spec.sh +0 -76
  265. package/dist/templates/.claude/hooks/worktree-guard.sh +0 -220
  266. package/dist/templates/.claude/hooks/worktree-write-guard.sh +0 -190
  267. package/dist/templates/.claude/rules/git-safety.md +0 -26
  268. package/dist/templates/.claude/rules/worktree-isolation.md +0 -101
  269. package/dist/templates/.claude/settings.json +0 -141
  270. package/dist/templates/.cursor/README.md +0 -299
  271. package/dist/templates/.cursor/hooks/audit.sh +0 -55
  272. package/dist/templates/.cursor/hooks/block-dangerous.sh +0 -84
  273. package/dist/templates/.cursor/hooks/caws-quality-check.sh +0 -52
  274. package/dist/templates/.cursor/hooks/caws-scope-guard.sh +0 -130
  275. package/dist/templates/.cursor/hooks/format.sh +0 -38
  276. package/dist/templates/.cursor/hooks/naming-check.sh +0 -64
  277. package/dist/templates/.cursor/hooks/scan-secrets.sh +0 -51
  278. package/dist/templates/.cursor/hooks/scope-guard.sh +0 -52
  279. package/dist/templates/.cursor/hooks/session-log.sh +0 -924
  280. package/dist/templates/.cursor/hooks/validate-spec.sh +0 -83
  281. package/dist/templates/.cursor/hooks.json +0 -76
  282. package/dist/templates/.cursor/rules/00-claims-verification.mdc +0 -144
  283. package/dist/templates/.cursor/rules/01-working-style.mdc +0 -50
  284. package/dist/templates/.cursor/rules/02-quality-gates.mdc +0 -368
  285. package/dist/templates/.cursor/rules/03-naming-and-refactor.mdc +0 -33
  286. package/dist/templates/.cursor/rules/04-logging-language-style.mdc +0 -23
  287. package/dist/templates/.cursor/rules/05-safe-defaults-guards.mdc +0 -23
  288. package/dist/templates/.cursor/rules/06-typescript-conventions.mdc +0 -36
  289. package/dist/templates/.cursor/rules/07-process-ops.mdc +0 -20
  290. package/dist/templates/.cursor/rules/08-solid-and-architecture.mdc +0 -16
  291. package/dist/templates/.cursor/rules/09-docstrings.mdc +0 -89
  292. package/dist/templates/.cursor/rules/10-documentation-quality-standards.mdc +0 -385
  293. package/dist/templates/.cursor/rules/11-scope-management-waivers.mdc +0 -381
  294. package/dist/templates/.cursor/rules/12-implementation-completeness.mdc +0 -516
  295. package/dist/templates/.cursor/rules/13-language-agnostic-standards.mdc +0 -578
  296. package/dist/templates/.cursor/rules/README.md +0 -148
  297. package/dist/templates/.github/copilot-instructions.md +0 -82
  298. package/dist/templates/.idea/runConfigurations/CAWS_Evaluate.xml +0 -5
  299. package/dist/templates/.idea/runConfigurations/CAWS_Validate.xml +0 -5
  300. package/dist/templates/.junie/guidelines.md +0 -73
  301. package/dist/templates/.vscode/launch.json +0 -17
  302. package/dist/templates/.vscode/settings.json +0 -95
  303. package/dist/templates/.windsurf/rules/caws-quality-standards.md +0 -54
  304. package/dist/templates/.windsurf/workflows/caws-guided-development.md +0 -92
  305. package/dist/templates/CLAUDE.md +0 -196
  306. package/dist/templates/COMMIT_CONVENTIONS.md +0 -86
  307. package/dist/templates/OIDC_SETUP.md +0 -300
  308. package/dist/templates/agents.md +0 -171
  309. package/dist/templates/codemod/README.md +0 -1
  310. package/dist/templates/codemod/test.js +0 -93
  311. package/dist/templates/docs/README.md +0 -151
  312. package/dist/templates/scripts/new_feature.sh +0 -80
  313. package/dist/templates/scripts/quality-gates/check-god-objects.js +0 -146
  314. package/dist/templates/scripts/quality-gates/run-quality-gates.js +0 -50
  315. package/dist/templates/scripts/v3/analysis/todo_analyzer.py +0 -1997
  316. package/dist/test-analysis.js +0 -786
  317. package/dist/tool-interface.js +0 -314
  318. package/dist/tool-loader.js +0 -303
  319. package/dist/tool-validator.js +0 -393
  320. package/dist/utils/agent-display.js +0 -210
  321. package/dist/utils/agent-session.js +0 -344
  322. package/dist/utils/async-utils.js +0 -188
  323. package/dist/utils/command-wrapper.js +0 -200
  324. package/dist/utils/event-log.js +0 -584
  325. package/dist/utils/event-renderer.js +0 -521
  326. package/dist/utils/finalization.js +0 -230
  327. package/dist/utils/git-lock.js +0 -119
  328. package/dist/utils/gitignore-updater.js +0 -158
  329. package/dist/utils/ide-detection.js +0 -133
  330. package/dist/utils/lifecycle-events.js +0 -94
  331. package/dist/utils/project-analysis.js +0 -367
  332. package/dist/utils/promise-utils.js +0 -72
  333. package/dist/utils/quality-gates-errors.js +0 -520
  334. package/dist/utils/quality-gates-utils.js +0 -387
  335. package/dist/utils/schema-validator.js +0 -50
  336. package/dist/utils/spec-resolver.js +0 -711
  337. package/dist/utils/typescript-detector.js +0 -369
  338. package/dist/utils/working-state.js +0 -530
  339. package/dist/utils/yaml-validation.js +0 -156
  340. package/dist/validation/spec-validation.js +0 -924
  341. package/dist/waivers-manager.js +0 -732
  342. package/dist/worktree/worktree-manager.js +0 -1735
  343. package/templates/.caws/schemas/policy.schema.json +0 -117
  344. package/templates/.caws/schemas/scope.schema.json +0 -52
  345. package/templates/.caws/schemas/waivers.schema.json +0 -106
  346. package/templates/.caws/schemas/working-spec.schema.json +0 -340
  347. package/templates/.caws/schemas/worktrees.schema.json +0 -38
  348. package/templates/.caws/templates/working-spec.template.yml +0 -80
  349. package/templates/.caws/tools/README.md +0 -18
  350. package/templates/.caws/tools/scope-guard.js +0 -203
  351. package/templates/.caws/tools-allow.json +0 -331
  352. package/templates/.caws/waivers.yml +0 -19
  353. package/templates/.claude/README.md +0 -190
  354. package/templates/.claude/hooks/audit.sh +0 -121
  355. package/templates/.claude/hooks/block-dangerous.sh +0 -203
  356. package/templates/.claude/hooks/classify_command.py +0 -592
  357. package/templates/.claude/hooks/doc-frontmatter-check.sh +0 -173
  358. package/templates/.claude/hooks/lite-sprawl-check.sh +0 -145
  359. package/templates/.claude/hooks/naming-check.sh +0 -100
  360. package/templates/.claude/hooks/protected-paths.sh +0 -39
  361. package/templates/.claude/hooks/quality-check.sh +0 -81
  362. package/templates/.claude/hooks/scan-secrets.sh +0 -85
  363. package/templates/.claude/hooks/scope-guard.sh +0 -381
  364. package/templates/.claude/hooks/session-caws-status.sh +0 -117
  365. package/templates/.claude/hooks/session-log.sh +0 -634
  366. package/templates/.claude/hooks/simplification-guard.sh +0 -92
  367. package/templates/.claude/hooks/stop-worktree-check.sh +0 -46
  368. package/templates/.claude/hooks/test_classify_command.py +0 -370
  369. package/templates/.claude/hooks/test_wrapper_smoke.sh +0 -96
  370. package/templates/.claude/hooks/validate-spec.sh +0 -76
  371. package/templates/.claude/hooks/worktree-guard.sh +0 -220
  372. package/templates/.claude/hooks/worktree-write-guard.sh +0 -190
  373. package/templates/.claude/rules/git-safety.md +0 -26
  374. package/templates/.claude/rules/worktree-isolation.md +0 -101
  375. package/templates/.claude/settings.json +0 -141
  376. package/templates/.cursor/README.md +0 -299
  377. package/templates/.cursor/hooks/audit.sh +0 -55
  378. package/templates/.cursor/hooks/block-dangerous.sh +0 -84
  379. package/templates/.cursor/hooks/caws-quality-check.sh +0 -52
  380. package/templates/.cursor/hooks/caws-scope-guard.sh +0 -130
  381. package/templates/.cursor/hooks/format.sh +0 -38
  382. package/templates/.cursor/hooks/naming-check.sh +0 -64
  383. package/templates/.cursor/hooks/scan-secrets.sh +0 -51
  384. package/templates/.cursor/hooks/scope-guard.sh +0 -52
  385. package/templates/.cursor/hooks/session-log.sh +0 -924
  386. package/templates/.cursor/hooks/validate-spec.sh +0 -83
  387. package/templates/.cursor/hooks.json +0 -76
  388. package/templates/.cursor/rules/00-claims-verification.mdc +0 -144
  389. package/templates/.cursor/rules/01-working-style.mdc +0 -50
  390. package/templates/.cursor/rules/02-quality-gates.mdc +0 -368
  391. package/templates/.cursor/rules/03-naming-and-refactor.mdc +0 -33
  392. package/templates/.cursor/rules/04-logging-language-style.mdc +0 -23
  393. package/templates/.cursor/rules/05-safe-defaults-guards.mdc +0 -23
  394. package/templates/.cursor/rules/06-typescript-conventions.mdc +0 -36
  395. package/templates/.cursor/rules/07-process-ops.mdc +0 -20
  396. package/templates/.cursor/rules/08-solid-and-architecture.mdc +0 -16
  397. package/templates/.cursor/rules/09-docstrings.mdc +0 -89
  398. package/templates/.cursor/rules/10-documentation-quality-standards.mdc +0 -385
  399. package/templates/.cursor/rules/11-scope-management-waivers.mdc +0 -381
  400. package/templates/.cursor/rules/12-implementation-completeness.mdc +0 -516
  401. package/templates/.cursor/rules/13-language-agnostic-standards.mdc +0 -578
  402. package/templates/.cursor/rules/README.md +0 -148
  403. package/templates/.github/copilot-instructions.md +0 -82
  404. package/templates/.idea/runConfigurations/CAWS_Evaluate.xml +0 -5
  405. package/templates/.idea/runConfigurations/CAWS_Validate.xml +0 -5
  406. package/templates/.junie/guidelines.md +0 -73
  407. package/templates/.vscode/launch.json +0 -17
  408. package/templates/.vscode/settings.json +0 -95
  409. package/templates/.windsurf/rules/caws-quality-standards.md +0 -54
  410. package/templates/.windsurf/workflows/caws-guided-development.md +0 -92
  411. package/templates/CLAUDE.md +0 -196
  412. package/templates/COMMIT_CONVENTIONS.md +0 -86
  413. package/templates/OIDC_SETUP.md +0 -300
  414. package/templates/agents.md +0 -171
  415. package/templates/codemod/README.md +0 -1
  416. package/templates/codemod/test.js +0 -93
  417. package/templates/docs/README.md +0 -151
  418. package/templates/scripts/new_feature.sh +0 -80
  419. package/templates/scripts/quality-gates/check-god-objects.js +0 -146
  420. package/templates/scripts/quality-gates/run-quality-gates.js +0 -50
  421. package/templates/scripts/v3/analysis/todo_analyzer.py +0 -1997
@@ -1,924 +0,0 @@
1
- #!/bin/bash
2
- # Session Logger for Cursor IDE
3
- #
4
- # Dual-mode session logging:
5
- # 1. Incremental: accumulates events from Cursor hook invocations during session
6
- # 2. Workspace DB: on stop, reads Cursor's state.vscdb to enrich with metadata
7
- # (composer name, model, mode, prompts, generation history)
8
- # 3. Global DB: on stop, reads cursorDiskKV bubbleId entries to reconstruct
9
- # full conversation including assistant responses, code blocks, file actions
10
- #
11
- # Generates:
12
- # session.txt — lightweight index (header + turn list + exploration + audit)
13
- # turn-001.txt — per-turn narrative (user + assistant exchange + tool calls)
14
- # turn-001.json — per-turn structured data (tools + edits + results + responses)
15
- #
16
- # Cursor stores data across:
17
- # - globalStorage/state.vscdb → cursorDiskKV composerData:<id> (bubble headers)
18
- # - globalStorage/state.vscdb → cursorDiskKV bubbleId:<conv_id>:<bubble_id> (message content)
19
- # - workspaceStorage/*/state.vscdb → ItemTable composer.composerData (session metadata)
20
- # - workspaceStorage/*/state.vscdb → ItemTable aiService.prompts / aiService.generations
21
- # - ~/.cursor/ai-tracking/ai-code-tracking.db → conversation_summaries (tldr, overview)
22
- #
23
- # Output: ./tmp/<conversation-id>/
24
- #
25
- # Wired into: beforeSubmitPrompt, afterFileEdit, beforeShellExecution,
26
- # beforeReadFile, afterAgentResponse, afterAgentThought, stop
27
- #
28
- # @author @darianrosebrook
29
-
30
- set -euo pipefail
31
-
32
- INPUT=$(cat)
33
-
34
- # --- Parse common fields ---
35
- CONVERSATION_ID=$(echo "$INPUT" | jq -r '.conversation_id // "unknown"')
36
- GENERATION_ID=$(echo "$INPUT" | jq -r '.generation_id // "none"')
37
- HOOK_EVENT=$(echo "$INPUT" | jq -r '.hook_event_name // "unknown"')
38
- TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
39
- CWD=$(pwd)
40
-
41
- # --- Log directory ---
42
- LOG_DIR="${CWD}/tmp/${CONVERSATION_ID}"
43
- mkdir -p "$LOG_DIR"
44
-
45
- EVENTS_FILE="$LOG_DIR/.events.jsonl"
46
- META_FILE="$LOG_DIR/.meta.json"
47
- SESSION_MD="$LOG_DIR/session.txt"
48
-
49
- # ============================================================
50
- # Helper: append an event to the accumulator
51
- # ============================================================
52
- append_event() {
53
- local event_json="$1"
54
- echo "$event_json" >> "$EVENTS_FILE"
55
- }
56
-
57
- # ============================================================
58
- # Helper: resolve Cursor workspace state.vscdb path
59
- # ============================================================
60
- resolve_workspace_db() {
61
- local cursor_data=""
62
-
63
- if [ -d "$HOME/Library/Application Support/Cursor/User/workspaceStorage" ]; then
64
- cursor_data="$HOME/Library/Application Support/Cursor/User/workspaceStorage"
65
- elif [ -d "$HOME/.config/Cursor/User/workspaceStorage" ]; then
66
- cursor_data="$HOME/.config/Cursor/User/workspaceStorage"
67
- elif [ -d "${APPDATA:-}/Cursor/User/workspaceStorage" ] 2>/dev/null; then
68
- cursor_data="${APPDATA}/Cursor/User/workspaceStorage"
69
- fi
70
-
71
- if [ -z "$cursor_data" ]; then
72
- echo ""
73
- return
74
- fi
75
-
76
- for ws_dir in "$cursor_data"/*/; do
77
- local ws_json="${ws_dir}workspace.json"
78
- if [ -f "$ws_json" ]; then
79
- local folder
80
- folder=$(python3 -c "
81
- import json, sys
82
- try:
83
- d = json.load(open(sys.argv[1]))
84
- print(d.get('folder', ''))
85
- except: pass
86
- " "$ws_json" 2>/dev/null)
87
-
88
- local expected="file://${CWD}"
89
- if [ "$folder" = "$expected" ]; then
90
- local db="${ws_dir}state.vscdb"
91
- if [ -f "$db" ]; then
92
- echo "$db"
93
- return
94
- fi
95
- fi
96
- fi
97
- done
98
-
99
- echo ""
100
- }
101
-
102
- # ============================================================
103
- # Helper: resolve Cursor global state.vscdb path
104
- # ============================================================
105
- resolve_global_db() {
106
- local candidates=(
107
- "$HOME/Library/Application Support/Cursor/User/globalStorage/state.vscdb"
108
- "$HOME/.config/Cursor/User/globalStorage/state.vscdb"
109
- )
110
- for db in "${candidates[@]}"; do
111
- if [ -f "$db" ]; then
112
- echo "$db"
113
- return
114
- fi
115
- done
116
- echo ""
117
- }
118
-
119
- # ============================================================
120
- # Helper: resolve Cursor ai-tracking database
121
- # ============================================================
122
- resolve_tracking_db() {
123
- local candidates=(
124
- "$HOME/.cursor/ai-tracking/ai-code-tracking.db"
125
- "$HOME/.config/Cursor/ai-tracking/ai-code-tracking.db"
126
- )
127
- for db in "${candidates[@]}"; do
128
- if [ -f "$db" ]; then
129
- echo "$db"
130
- return
131
- fi
132
- done
133
- echo ""
134
- }
135
-
136
- # ============================================================
137
- # EVENT: beforeSubmitPrompt — capture user prompts (turn boundaries)
138
- # ============================================================
139
- handle_before_submit_prompt() {
140
- local prompt
141
- prompt=$(echo "$INPUT" | jq -r '.prompt // ""')
142
-
143
- if [ -z "$prompt" ] || [ "$prompt" = "null" ]; then
144
- return
145
- fi
146
-
147
- append_event "$(jq -cn \
148
- --arg ev "user_text" \
149
- --arg text "$prompt" \
150
- --arg ts "$TIMESTAMP" \
151
- --arg gen "$GENERATION_ID" \
152
- '{ev: $ev, text: $text, ts: $ts, generation_id: $gen}')"
153
- }
154
-
155
- # ============================================================
156
- # EVENT: afterFileEdit — capture file edits
157
- # ============================================================
158
- handle_after_file_edit() {
159
- local file_path action_type
160
- file_path=$(echo "$INPUT" | jq -r '.file_path // ""')
161
- action_type=$(echo "$INPUT" | jq -r '.action // "edit"')
162
-
163
- file_path=$(echo "$file_path" | sed "s|${CWD}/||")
164
-
165
- append_event "$(jq -cn \
166
- --arg ev "file_edit" \
167
- --arg file "$file_path" \
168
- --arg action "$action_type" \
169
- --arg ts "$TIMESTAMP" \
170
- --arg gen "$GENERATION_ID" \
171
- '{ev: $ev, file: $file, action: $action, ts: $ts, generation_id: $gen}')"
172
- }
173
-
174
- # ============================================================
175
- # EVENT: afterAgentResponse — capture assistant response text at turn end
176
- # ============================================================
177
- handle_after_agent_response() {
178
- local response
179
- response=$(echo "$INPUT" | jq -r '.response // ""')
180
-
181
- if [ -z "$response" ] || [ "$response" = "null" ]; then
182
- return
183
- fi
184
-
185
- append_event "$(jq -cn \
186
- --arg ev "agent_response" \
187
- --arg text "$response" \
188
- --arg ts "$TIMESTAMP" \
189
- --arg gen "$GENERATION_ID" \
190
- '{ev: $ev, text: $text, ts: $ts, generation_id: $gen}')"
191
- }
192
-
193
- # ============================================================
194
- # EVENT: afterAgentThought — capture agent reasoning steps
195
- # ============================================================
196
- handle_after_agent_thought() {
197
- local thought
198
- thought=$(echo "$INPUT" | jq -r '.thought // ""')
199
-
200
- if [ -z "$thought" ] || [ "$thought" = "null" ]; then
201
- return
202
- fi
203
-
204
- append_event "$(jq -cn \
205
- --arg ev "agent_thought" \
206
- --arg text "$thought" \
207
- --arg ts "$TIMESTAMP" \
208
- --arg gen "$GENERATION_ID" \
209
- '{ev: $ev, text: $text, ts: $ts, generation_id: $gen}')"
210
- }
211
-
212
- # ============================================================
213
- # EVENT: beforeShellExecution — capture shell commands
214
- # ============================================================
215
- handle_before_shell_execution() {
216
- local command
217
- command=$(echo "$INPUT" | jq -r '.command // ""')
218
-
219
- if [ -z "$command" ] || [ "$command" = "null" ]; then
220
- return
221
- fi
222
-
223
- append_event "$(jq -cn \
224
- --arg ev "shell_command" \
225
- --arg cmd "$command" \
226
- --arg ts "$TIMESTAMP" \
227
- --arg gen "$GENERATION_ID" \
228
- '{ev: $ev, command: $cmd, ts: $ts, generation_id: $gen}')"
229
- }
230
-
231
- # ============================================================
232
- # EVENT: beforeReadFile — capture file reads
233
- # ============================================================
234
- handle_before_read_file() {
235
- local file_path
236
- file_path=$(echo "$INPUT" | jq -r '.file_path // ""')
237
-
238
- file_path=$(echo "$file_path" | sed "s|${CWD}/||")
239
-
240
- append_event "$(jq -cn \
241
- --arg ev "file_read" \
242
- --arg file "$file_path" \
243
- --arg ts "$TIMESTAMP" \
244
- --arg gen "$GENERATION_ID" \
245
- '{ev: $ev, file: $file, ts: $ts, generation_id: $gen}')"
246
- }
247
-
248
- # ============================================================
249
- # EVENT: stop — generate session output
250
- # ============================================================
251
- handle_stop() {
252
- local branch head_sha dirty_count
253
- branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
254
- head_sha=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
255
- dirty_count=$(git status --porcelain 2>/dev/null | wc -l | tr -d ' ' || echo "0")
256
-
257
- local started_at model
258
- if [ -f "$META_FILE" ]; then
259
- started_at=$(jq -r '.local_time // "unknown"' "$META_FILE")
260
- model=$(jq -r '.model // "cursor-agent"' "$META_FILE")
261
- else
262
- started_at="(unknown)"
263
- model="cursor-agent"
264
- fi
265
-
266
- local workspace_db tracking_db global_db
267
- workspace_db=$(resolve_workspace_db)
268
- tracking_db=$(resolve_tracking_db)
269
- global_db=$(resolve_global_db)
270
-
271
- if [ ! -f "$EVENTS_FILE" ] || [ ! -s "$EVENTS_FILE" ]; then
272
- cat > "$SESSION_MD" << MDEOF
273
- # Session Log: $(basename "$CWD")
274
-
275
- | Field | Value |
276
- |-------|-------|
277
- | Conversation ID | \`${CONVERSATION_ID}\` |
278
- | Started | ${started_at} |
279
- | Model | ${model} |
280
- | Branch | \`${branch}\` @ \`${head_sha}\` |
281
-
282
- ---
283
-
284
- _No events captured. Session log unavailable._
285
- MDEOF
286
- return
287
- fi
288
-
289
- local pyscript
290
- pyscript=$(mktemp "${TMPDIR:-/tmp}/cursor-session-log-XXXX.py")
291
- trap "rm -f '$pyscript'" RETURN
292
- cat > "$pyscript" << 'PYEOF'
293
- import json, sys, os, sqlite3, base64
294
- from datetime import datetime
295
-
296
- log_dir = sys.argv[1]
297
- cwd = sys.argv[2]
298
- conversation_id = sys.argv[3]
299
- started_at = sys.argv[4]
300
- model = sys.argv[5]
301
- branch = sys.argv[6]
302
- head_sha = sys.argv[7]
303
- dirty_count = sys.argv[8]
304
- workspace_db = sys.argv[9] if len(sys.argv) > 9 else ""
305
- tracking_db = sys.argv[10] if len(sys.argv) > 10 else ""
306
- global_db = sys.argv[11] if len(sys.argv) > 11 else ""
307
-
308
- def rel(path):
309
- if path and path.startswith(cwd + "/"):
310
- return path[len(cwd) + 1:]
311
- return path or ""
312
-
313
- def open_ro(path):
314
- return sqlite3.connect(f"file:{path}?mode=ro", uri=True)
315
-
316
- def decode_value(value):
317
- """Decode a DB value: JSON string, bytes, or base64-encoded JSON."""
318
- if value is None:
319
- return None
320
- if isinstance(value, bytes):
321
- try:
322
- return json.loads(value.decode("utf-8"))
323
- except Exception:
324
- pass
325
- try:
326
- return json.loads(base64.b64decode(value))
327
- except Exception:
328
- return None
329
- if isinstance(value, str):
330
- try:
331
- return json.loads(value)
332
- except Exception:
333
- pass
334
- try:
335
- return json.loads(base64.b64decode(value))
336
- except Exception:
337
- return None
338
- return value
339
-
340
- # ---- Enrich from workspace state.vscdb (session metadata) ----
341
- composer_meta = {}
342
- if workspace_db and os.path.isfile(workspace_db):
343
- try:
344
- conn = open_ro(workspace_db)
345
- cur = conn.cursor()
346
- cur.execute("SELECT value FROM ItemTable WHERE key = 'composer.composerData'")
347
- row = cur.fetchone()
348
- if row:
349
- data = decode_value(row[0])
350
- if data:
351
- for c in data.get("allComposers", []):
352
- if c.get("composerId") == conversation_id:
353
- composer_meta = c
354
- break
355
- conn.close()
356
- except Exception:
357
- pass
358
-
359
- # ---- Enrich from ai-tracking DB (tldr, overview, model) ----
360
- conversation_summary = {}
361
- if tracking_db and os.path.isfile(tracking_db):
362
- try:
363
- conn = open_ro(tracking_db)
364
- cur = conn.cursor()
365
- cur.execute(
366
- "SELECT title, tldr, overview, model, mode FROM conversation_summaries WHERE conversationId = ?",
367
- (conversation_id,)
368
- )
369
- row = cur.fetchone()
370
- if row:
371
- conversation_summary = {
372
- "title": row[0], "tldr": row[1], "overview": row[2],
373
- "model": row[3], "mode": row[4],
374
- }
375
- conn.close()
376
- except Exception:
377
- pass
378
-
379
- # ---- Pull full bubble conversation from global cursorDiskKV ----
380
- # Structure:
381
- # composerData:<conv_id> → { fullConversationHeadersOnly: [{bubbleId, type}, ...], ... }
382
- # bubbleId:<conv_id>:<bubble_id> → { type, text, codeBlocks, fileActions, timingInfo, ... }
383
- #
384
- # type == 1 → User message
385
- # type != 1 → Assistant message
386
- bubbles = []
387
- if global_db and os.path.isfile(global_db):
388
- try:
389
- conn = open_ro(global_db)
390
- cur = conn.cursor()
391
-
392
- # Get ordered bubble headers
393
- cur.execute(
394
- "SELECT value FROM cursorDiskKV WHERE key = ?",
395
- (f"composerData:{conversation_id}",)
396
- )
397
- row = cur.fetchone()
398
- headers = []
399
- if row:
400
- data = decode_value(row[0])
401
- if data:
402
- headers = data.get("fullConversationHeadersOnly", [])
403
-
404
- # Fetch each bubble's content
405
- for header in headers:
406
- bubble_id = header.get("bubbleId", "")
407
- bubble_type = header.get("type")
408
- if not bubble_id:
409
- continue
410
- cur.execute(
411
- "SELECT value FROM cursorDiskKV WHERE key = ?",
412
- (f"bubbleId:{conversation_id}:{bubble_id}",)
413
- )
414
- brow = cur.fetchone()
415
- if not brow:
416
- continue
417
- bdata = decode_value(brow[0])
418
- if not bdata:
419
- continue
420
-
421
- role = "user" if bubble_type == 1 else "assistant"
422
- text = bdata.get("text", "")
423
-
424
- # Extract code blocks
425
- code_blocks = []
426
- for cb in bdata.get("codeBlocks", []):
427
- lang = cb.get("language", "")
428
- code = cb.get("code", "")
429
- if code:
430
- code_blocks.append({"language": lang, "code": code})
431
-
432
- # Extract file actions
433
- file_actions = []
434
- for fa in bdata.get("fileActions", []):
435
- fa_type = fa.get("type", "")
436
- fa_path = fa.get("path", "")
437
- if fa_path:
438
- file_actions.append({"type": fa_type, "path": fa_path})
439
-
440
- # Timing
441
- timing = bdata.get("timingInfo", {})
442
- ts_ms = timing.get("clientStartTime") or timing.get("clientEndTime")
443
- ts_str = ""
444
- if ts_ms and isinstance(ts_ms, (int, float)):
445
- ts_str = datetime.fromtimestamp(ts_ms / 1000).strftime("%Y-%m-%dT%H:%M:%SZ")
446
-
447
- bubbles.append({
448
- "bubble_id": bubble_id,
449
- "role": role,
450
- "text": text,
451
- "code_blocks": code_blocks,
452
- "file_actions": file_actions,
453
- "ts": ts_str,
454
- })
455
-
456
- conn.close()
457
- except Exception:
458
- pass
459
-
460
- # Index bubbles by role sequence for turn correlation
461
- user_bubbles = [b for b in bubbles if b["role"] == "user"]
462
- assistant_bubbles = [b for b in bubbles if b["role"] == "assistant"]
463
-
464
- # ---- Override metadata from DB ----
465
- conv_name = (
466
- composer_meta.get("name")
467
- or conversation_summary.get("title")
468
- or ""
469
- )
470
- conv_model = (
471
- conversation_summary.get("model")
472
- or model
473
- )
474
- conv_mode = (
475
- composer_meta.get("unifiedMode")
476
- or conversation_summary.get("mode")
477
- or ""
478
- )
479
- conv_created = composer_meta.get("createdAt")
480
- if conv_created and isinstance(conv_created, (int, float)):
481
- started_at = datetime.fromtimestamp(conv_created / 1000).strftime("%Y-%m-%d %H:%M:%S")
482
- context_pct = composer_meta.get("contextUsagePercent")
483
- lines_added = composer_meta.get("totalLinesAdded", 0)
484
- lines_removed = composer_meta.get("totalLinesRemoved", 0)
485
- files_changed = composer_meta.get("filesChangedCount", 0)
486
- conv_branch = composer_meta.get("createdOnBranch", "")
487
-
488
- # ---- Accumulate turns from .events.jsonl ----
489
- turns = []
490
-
491
- def new_turn(user_text, generation_id=None):
492
- return {
493
- "user": user_text,
494
- "generation_id": generation_id,
495
- "agent_response": "",
496
- "agent_thoughts": [],
497
- "edits": [],
498
- "reads": [],
499
- "commands": [],
500
- "events": [],
501
- }
502
-
503
- current = new_turn(None)
504
-
505
- for line in sys.stdin:
506
- try:
507
- entry = json.loads(line)
508
- except json.JSONDecodeError:
509
- continue
510
-
511
- ev = entry.get("ev")
512
- ts = entry.get("ts", "")
513
-
514
- if ev == "user_text":
515
- text = entry.get("text", "")
516
- if not text.strip():
517
- continue
518
- if current["user"] or current["events"]:
519
- turns.append(current)
520
- current = new_turn(text, entry.get("generation_id"))
521
- current["events"].append({"kind": "user_prompt", "text": text, "ts": ts})
522
-
523
- elif ev == "file_edit":
524
- f = rel(entry.get("file", ""))
525
- action = entry.get("action", "edit")
526
- if f and f not in current["edits"]:
527
- current["edits"].append(f)
528
- current["events"].append({"kind": "file_edit", "file": f, "action": action, "ts": ts})
529
-
530
- elif ev == "file_read":
531
- f = rel(entry.get("file", ""))
532
- if f and f not in current["reads"]:
533
- current["reads"].append(f)
534
- current["events"].append({"kind": "file_read", "file": f, "ts": ts})
535
-
536
- elif ev == "shell_command":
537
- cmd = entry.get("command", "")
538
- if cmd:
539
- current["commands"].append(cmd)
540
- current["events"].append({"kind": "shell_command", "command": cmd, "ts": ts})
541
-
542
- elif ev == "agent_response":
543
- text = entry.get("text", "")
544
- if text:
545
- current["agent_response"] = text
546
- current["events"].append({"kind": "agent_response", "text": text, "ts": ts})
547
-
548
- elif ev == "agent_thought":
549
- text = entry.get("text", "")
550
- if text:
551
- current.setdefault("agent_thoughts", []).append(text)
552
- current["events"].append({"kind": "agent_thought", "text": text, "ts": ts})
553
-
554
- if current["user"] or current["events"]:
555
- turns.append(current)
556
-
557
- # ---- Correlate bubble content into turns ----
558
- # Match user bubbles to turns by text similarity, then pair with the
559
- # following assistant bubble(s). Falls back gracefully if DB unavailable.
560
- def bubble_for_turn(turn_idx):
561
- """Return (user_bubble, [assistant_bubbles]) for a turn index."""
562
- if turn_idx < len(user_bubbles):
563
- ub = user_bubbles[turn_idx]
564
- # Collect all assistant bubbles that follow this user bubble
565
- ub_pos = bubbles.index(ub)
566
- ab_list = []
567
- for b in bubbles[ub_pos + 1:]:
568
- if b["role"] == "assistant":
569
- ab_list.append(b)
570
- elif b["role"] == "user":
571
- break
572
- return ub, ab_list
573
- return None, []
574
-
575
- # ---- Write per-turn files ----
576
- turn_index = []
577
-
578
- def group_by_ext(paths):
579
- groups = {}
580
- for p in paths:
581
- ext = os.path.splitext(p)[1] or "(no ext)"
582
- groups.setdefault(ext, []).append(p)
583
- return groups
584
-
585
- for i, turn in enumerate(turns):
586
- num = i + 1
587
- padded = f"{num:03d}"
588
-
589
- user_bubble, asst_bubbles = bubble_for_turn(i)
590
-
591
- # Prefer bubble text (richer) over hook-captured prompt when available
592
- user_text = (
593
- (user_bubble["text"] if user_bubble and user_bubble["text"] else None)
594
- or turn["user"]
595
- or ""
596
- )
597
-
598
- # Prefer hook-captured response (afterAgentResponse) — available mid-session.
599
- # Fall back to DB bubble extraction used at stop time.
600
- hook_response = turn.get("agent_response", "")
601
- asst_text = (
602
- hook_response
603
- or "\n\n".join(b["text"] for b in asst_bubbles if b["text"])
604
- )
605
- asst_code_blocks = [cb for b in asst_bubbles for cb in b["code_blocks"]]
606
- asst_file_actions = [fa for b in asst_bubbles for fa in b["file_actions"]]
607
- asst_thoughts = turn.get("agent_thoughts", [])
608
-
609
- # ---- turn-NNN.txt ----
610
- md_lines = [f"# Turn {num}", ""]
611
-
612
- # User block
613
- if user_text:
614
- md_lines.append("> **User**")
615
- md_lines.append(">")
616
- for line in user_text.splitlines():
617
- md_lines.append(f"> {line}" if line else ">")
618
- md_lines.append("")
619
-
620
- # Tool activity (from hook events)
621
- tool_lines = []
622
- for event in turn["events"]:
623
- kind = event["kind"]
624
- if kind == "user_prompt":
625
- pass
626
- elif kind == "file_edit":
627
- f = event.get("file", "")
628
- action = event.get("action", "edit")
629
- tool_lines.append(f"`{action.title()}` {f}")
630
- elif kind == "file_read":
631
- f = event.get("file", "")
632
- tool_lines.append(f"`Read` {f}")
633
- elif kind == "shell_command":
634
- cmd = event.get("command", "")
635
- if len(cmd) > 120:
636
- tool_lines.extend(["`Bash`", "```", cmd, "```"])
637
- else:
638
- tool_lines.append(f"`Bash` `{cmd}`")
639
-
640
- if tool_lines:
641
- md_lines.append("**Tool activity**")
642
- md_lines.append("")
643
- md_lines.extend(tool_lines)
644
- md_lines.append("")
645
-
646
- # Agent thoughts (reasoning steps, if captured)
647
- if asst_thoughts:
648
- md_lines.append("**Thoughts**")
649
- md_lines.append("")
650
- for thought in asst_thoughts:
651
- md_lines.append(f"_{thought}_")
652
- md_lines.append("")
653
-
654
- # Assistant response block
655
- if asst_text:
656
- md_lines.append("> **Assistant**")
657
- md_lines.append(">")
658
- for line in asst_text.splitlines():
659
- md_lines.append(f"> {line}" if line else ">")
660
- md_lines.append("")
661
-
662
- if asst_code_blocks:
663
- md_lines.append("**Code blocks**")
664
- md_lines.append("")
665
- for cb in asst_code_blocks:
666
- lang = cb.get("language", "")
667
- md_lines.append(f"```{lang}")
668
- md_lines.append(cb.get("code", ""))
669
- md_lines.append("```")
670
- md_lines.append("")
671
-
672
- if asst_file_actions:
673
- md_lines.append("**File actions**")
674
- md_lines.append("")
675
- for fa in asst_file_actions:
676
- md_lines.append(f"- `{fa['type']}` {fa['path']}")
677
- md_lines.append("")
678
-
679
- with open(os.path.join(log_dir, f"turn-{padded}.txt"), "w") as fh:
680
- fh.write("\n".join(md_lines))
681
-
682
- # ---- turn-NNN.json ----
683
- turn_json = {
684
- "turn": num,
685
- "user": user_text,
686
- "generation_id": turn["generation_id"],
687
- "assistant": {
688
- "text": asst_text,
689
- "thoughts": asst_thoughts,
690
- "code_blocks": asst_code_blocks,
691
- "file_actions": asst_file_actions,
692
- "source": "hook" if hook_response else "db",
693
- },
694
- "events": turn["events"],
695
- "files_edited": group_by_ext(turn["edits"]),
696
- "files_read": group_by_ext(turn["reads"]),
697
- "commands": turn["commands"],
698
- }
699
-
700
- with open(os.path.join(log_dir, f"turn-{padded}.json"), "w") as fh:
701
- json.dump(turn_json, fh, indent=2)
702
-
703
- user_preview = (user_text or "(no user message)")[:120]
704
- event_count = len(turn["events"])
705
- turn_index.append({
706
- "num": num,
707
- "padded": padded,
708
- "user_preview": user_preview,
709
- "event_count": event_count,
710
- "edits": turn["edits"],
711
- "has_response": bool(asst_text),
712
- })
713
-
714
- # ---- Write session.txt index ----
715
- with open(os.path.join(log_dir, "session.txt"), "w") as fh:
716
- fh.write(f"# Session Log: {os.path.basename(cwd)}\n\n")
717
- fh.write("| Field | Value |\n")
718
- fh.write("|-------|-------|\n")
719
- fh.write(f"| Conversation ID | `{conversation_id}` |\n")
720
- if conv_name:
721
- fh.write(f"| Name | {conv_name} |\n")
722
- fh.write(f"| Started | {started_at} |\n")
723
- fh.write(f"| Model | {conv_model} |\n")
724
- if conv_mode:
725
- fh.write(f"| Mode | {conv_mode} |\n")
726
- fh.write(f"| Branch | `{conv_branch or branch}` @ `{head_sha}` |\n")
727
- fh.write(f"| Turns | {len(turn_index)} |\n")
728
- if files_changed:
729
- fh.write(f"| Files changed | {files_changed} |\n")
730
- if lines_added or lines_removed:
731
- fh.write(f"| Lines | +{lines_added} / -{lines_removed} |\n")
732
- if context_pct is not None:
733
- fh.write(f"| Context usage | {context_pct:.1f}% |\n")
734
-
735
- tldr = conversation_summary.get("tldr", "")
736
- if tldr:
737
- fh.write(f"\n> {tldr}\n")
738
-
739
- fh.write("\n---\n\n")
740
- fh.write("## Turns\n\n")
741
-
742
- for t in turn_index:
743
- edits_str = ", ".join(f"`{e}`" for e in t["edits"][:3])
744
- if len(t["edits"]) > 3:
745
- edits_str += f" +{len(t['edits'])-3} more"
746
- summary = f"{t['event_count']} events"
747
- if edits_str:
748
- summary += f" | {edits_str}"
749
- if t["has_response"]:
750
- summary += " | response captured"
751
- fh.write(f"- **[Turn {t['num']}](turn-{t['padded']}.txt)** — {t['user_preview']}\n")
752
- fh.write(f" _{summary}_\n")
753
-
754
- fh.write("\n---\n\n")
755
-
756
- all_reads = []
757
- all_edits = []
758
- all_commands = []
759
- for turn in turns:
760
- all_reads.extend(turn["reads"])
761
- all_edits.extend(turn["edits"])
762
- all_commands.extend(turn["commands"])
763
-
764
- fh.write("## Exploration\n")
765
- fh.write("_Files read and commands executed (deduplicated)._\n\n")
766
- for r in sorted(set(all_reads)):
767
- fh.write(f"- READ `{r}`\n")
768
- fh.write("\n")
769
-
770
- fh.write("## Audit\n")
771
- fh.write("_Edits, commands, git activity._\n\n")
772
- for e in sorted(set(all_edits)):
773
- fh.write(f"- EDIT `{e}`\n")
774
- for cmd in all_commands:
775
- short = cmd[:120]
776
- meaningful = any(kw in short for kw in [
777
- "pytest", "cargo test", "ruff", "mypy", "npm test",
778
- "git log", "git diff", "git status", "git add", "git commit",
779
- "git merge", "caws ", "pip install", "make", "cargo build"
780
- ])
781
- if meaningful:
782
- fh.write(f"- BASH `{short}`\n")
783
- fh.write("\n")
784
-
785
- fh.write("## Session Snapshot\n\n")
786
- fh.write("| Field | Value |\n")
787
- fh.write("|-------|-------|\n")
788
- fh.write(f"| Branch | `{branch}` @ `{head_sha}` |\n")
789
- fh.write(f"| Dirty files | {dirty_count} |\n")
790
- fh.write(f"| Total turns | {len(turn_index)} |\n")
791
- fh.write(f"| Bubbles fetched | {len(bubbles)} |\n")
792
-
793
- overview = conversation_summary.get("overview", "")
794
- if overview:
795
- fh.write(f"\n## Overview\n\n{overview}\n")
796
-
797
- PYEOF
798
-
799
- python3 "$pyscript" "$LOG_DIR" "$CWD" "$CONVERSATION_ID" "$started_at" "$model" \
800
- "$branch" "$head_sha" "$dirty_count" "$workspace_db" "$tracking_db" "$global_db" \
801
- < "$EVENTS_FILE"
802
- }
803
-
804
- # ============================================================
805
- # Metadata capture (first invocation creates meta)
806
- # ============================================================
807
- ensure_meta() {
808
- if [ ! -f "$META_FILE" ]; then
809
- local full_time
810
- full_time=$(date +"%Y-%m-%d %H:%M:%S %Z")
811
- jq -cn \
812
- --arg cid "$CONVERSATION_ID" \
813
- --arg ts "$TIMESTAMP" \
814
- --arg lt "$full_time" \
815
- --arg model "cursor-agent" \
816
- --arg project "$(basename "$CWD")" \
817
- '{conversation_id: $cid, started_at: $ts, local_time: $lt, model: $model, project: $project}' \
818
- > "$META_FILE"
819
- fi
820
- }
821
-
822
- # ============================================================
823
- # Agent registry heartbeat — register this agent with CAWS
824
- # ============================================================
825
- AGENTS_REGISTRY="${CWD}/.caws/agents.json"
826
-
827
- heartbeat_agent() {
828
- [ "$CONVERSATION_ID" = "unknown" ] && return
829
-
830
- mkdir -p "$(dirname "$AGENTS_REGISTRY")"
831
-
832
- # Read existing registry or start fresh
833
- local registry
834
- if [ -f "$AGENTS_REGISTRY" ]; then
835
- registry=$(cat "$AGENTS_REGISTRY" 2>/dev/null || echo '{"version":1,"agents":{}}')
836
- else
837
- registry='{"version":1,"agents":{}}'
838
- fi
839
-
840
- # Prune stale entries (older than 30 minutes) and upsert this agent
841
- registry=$(echo "$registry" | python3 -c "
842
- import json, sys
843
- from datetime import datetime, timedelta, timezone
844
-
845
- TTL = timedelta(minutes=30)
846
- now = datetime.now(timezone.utc)
847
- conv_id = '$CONVERSATION_ID'
848
-
849
- data = json.load(sys.stdin)
850
- agents = data.get('agents', {})
851
-
852
- # Prune stale
853
- pruned = {}
854
- for sid, entry in agents.items():
855
- try:
856
- last = datetime.fromisoformat(entry['lastSeen'].replace('Z', '+00:00'))
857
- if now - last < TTL:
858
- pruned[sid] = entry
859
- except (KeyError, ValueError):
860
- pass
861
-
862
- # Upsert current agent
863
- existing = pruned.get(conv_id, {})
864
- pruned[conv_id] = {
865
- 'sessionId': conv_id,
866
- 'platform': 'cursor',
867
- 'model': existing.get('model'),
868
- 'specId': existing.get('specId'),
869
- 'ttl': 1800000,
870
- 'firstSeen': existing.get('firstSeen', now.strftime('%Y-%m-%dT%H:%M:%SZ')),
871
- 'lastSeen': now.strftime('%Y-%m-%dT%H:%M:%SZ'),
872
- }
873
-
874
- data['agents'] = pruned
875
- json.dump(data, sys.stdout, indent=2)
876
- " 2>/dev/null)
877
-
878
- [ -n "$registry" ] && echo "$registry" > "$AGENTS_REGISTRY"
879
- }
880
-
881
- remove_agent() {
882
- [ "$CONVERSATION_ID" = "unknown" ] && return
883
- [ ! -f "$AGENTS_REGISTRY" ] && return
884
-
885
- # Remove this agent from registry
886
- python3 -c "
887
- import json, sys
888
-
889
- conv_id = '$CONVERSATION_ID'
890
- with open('$AGENTS_REGISTRY', 'r') as f:
891
- data = json.load(f)
892
-
893
- agents = data.get('agents', {})
894
- agents.pop(conv_id, None)
895
- data['agents'] = agents
896
-
897
- with open('$AGENTS_REGISTRY', 'w') as f:
898
- json.dump(data, f, indent=2)
899
- " 2>/dev/null || true
900
- }
901
-
902
- # ============================================================
903
- # DISPATCH
904
- # ============================================================
905
- ensure_meta
906
-
907
- case "$HOOK_EVENT" in
908
- beforeSubmitPrompt) handle_before_submit_prompt ;;
909
- afterFileEdit) handle_after_file_edit ;;
910
- beforeShellExecution) handle_before_shell_execution ;;
911
- beforeReadFile) handle_before_read_file ;;
912
- afterAgentResponse) handle_after_agent_response ;;
913
- afterAgentThought) handle_after_agent_thought ;;
914
- stop) handle_stop; remove_agent ;;
915
- *) ;;
916
- esac
917
-
918
- # Heartbeat on every event (keeps TTL fresh while agent is active)
919
- heartbeat_agent
920
-
921
- # Always allow — this is observation only
922
- echo '{"permission":"allow"}' 2>/dev/null || true
923
- exit 0
924
-