@paths.design/caws-cli 7.0.2 → 8.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 (217) hide show
  1. package/dist/budget-derivation.js +5 -4
  2. package/dist/commands/diagnose.js +24 -19
  3. package/dist/commands/init.js +51 -4
  4. package/dist/commands/quality-gates.js +147 -9
  5. package/dist/commands/specs.js +148 -14
  6. package/dist/commands/status.js +2 -2
  7. package/dist/commands/tool.js +2 -4
  8. package/dist/config/index.js +17 -8
  9. package/dist/generators/working-spec.js +19 -6
  10. package/dist/scaffold/git-hooks.js +245 -46
  11. package/dist/scaffold/index.js +53 -7
  12. package/dist/templates/.caws/tools/README.md +21 -0
  13. package/dist/templates/.cursor/README.md +311 -0
  14. package/dist/templates/.cursor/hooks/audit.sh +55 -0
  15. package/dist/templates/.cursor/hooks/block-dangerous.sh +83 -0
  16. package/dist/templates/.cursor/hooks/caws-quality-check.sh +52 -0
  17. package/dist/templates/.cursor/hooks/caws-scope-guard.sh +130 -0
  18. package/dist/templates/.cursor/hooks/caws-tool-validation.sh +121 -0
  19. package/dist/templates/.cursor/hooks/format.sh +38 -0
  20. package/dist/templates/.cursor/hooks/naming-check.sh +64 -0
  21. package/dist/templates/.cursor/hooks/scan-secrets.sh +46 -0
  22. package/dist/templates/.cursor/hooks/scope-guard.sh +52 -0
  23. package/dist/templates/.cursor/hooks/validate-spec.sh +83 -0
  24. package/dist/templates/.cursor/hooks.json +59 -0
  25. package/dist/templates/.cursor/rules/00-claims-verification.mdc +144 -0
  26. package/dist/templates/.cursor/rules/01-working-style.mdc +50 -0
  27. package/dist/templates/.cursor/rules/02-quality-gates.mdc +370 -0
  28. package/dist/templates/.cursor/rules/03-naming-and-refactor.mdc +33 -0
  29. package/dist/templates/.cursor/rules/04-logging-language-style.mdc +23 -0
  30. package/dist/templates/.cursor/rules/05-safe-defaults-guards.mdc +23 -0
  31. package/dist/templates/.cursor/rules/06-typescript-conventions.mdc +36 -0
  32. package/dist/templates/.cursor/rules/07-process-ops.mdc +20 -0
  33. package/dist/templates/.cursor/rules/08-solid-and-architecture.mdc +16 -0
  34. package/dist/templates/.cursor/rules/09-docstrings.mdc +89 -0
  35. package/dist/templates/.cursor/rules/10-documentation-quality-standards.mdc +390 -0
  36. package/dist/templates/.cursor/rules/11-scope-management-waivers.mdc +385 -0
  37. package/dist/templates/.cursor/rules/12-implementation-completeness.mdc +516 -0
  38. package/dist/templates/.cursor/rules/13-language-agnostic-standards.mdc +588 -0
  39. package/dist/templates/.cursor/rules/README.md +148 -0
  40. package/dist/templates/.github/copilot/instructions.md +311 -0
  41. package/dist/templates/.idea/runConfigurations/CAWS_Evaluate.xml +5 -0
  42. package/dist/templates/.idea/runConfigurations/CAWS_Validate.xml +5 -0
  43. package/dist/templates/.vscode/launch.json +56 -0
  44. package/dist/templates/.vscode/settings.json +93 -0
  45. package/dist/templates/.windsurf/workflows/caws-guided-development.md +92 -0
  46. package/dist/templates/COMMIT_CONVENTIONS.md +86 -0
  47. package/dist/templates/OIDC_SETUP.md +300 -0
  48. package/dist/templates/agents.md +1047 -0
  49. package/dist/templates/codemod/README.md +1 -0
  50. package/dist/templates/codemod/test.js +93 -0
  51. package/dist/templates/docs/README.md +150 -0
  52. package/dist/templates/scripts/quality-gates/check-god-objects.js +146 -0
  53. package/dist/templates/scripts/quality-gates/run-quality-gates.js +50 -0
  54. package/dist/templates/scripts/v3/analysis/todo_analyzer.py +1997 -0
  55. package/dist/tool-loader.js +6 -1
  56. package/dist/tool-validator.js +8 -2
  57. package/dist/utils/detection.js +4 -3
  58. package/dist/utils/git-lock.js +119 -0
  59. package/dist/utils/gitignore-updater.js +148 -0
  60. package/dist/utils/project-analysis.js +176 -16
  61. package/dist/utils/quality-gates.js +48 -7
  62. package/dist/utils/spec-resolver.js +27 -3
  63. package/dist/utils/yaml-validation.js +156 -0
  64. package/dist/validation/spec-validation.js +81 -2
  65. package/package.json +2 -2
  66. package/templates/.caws/schemas/waivers.schema.json +30 -0
  67. package/templates/.caws/schemas/working-spec.schema.json +133 -0
  68. package/templates/.caws/templates/working-spec.template.yml +74 -0
  69. package/templates/.caws/tools/README.md +21 -0
  70. package/templates/.caws/tools/scope-guard.js +208 -0
  71. package/templates/.caws/tools-allow.json +331 -0
  72. package/templates/.caws/waivers.yml +19 -0
  73. package/templates/.cursor/hooks/scope-guard.sh +2 -2
  74. package/templates/.cursor/hooks/validate-spec.sh +42 -7
  75. package/dist/budget-derivation.d.ts +0 -74
  76. package/dist/budget-derivation.d.ts.map +0 -1
  77. package/dist/cicd-optimizer.d.ts +0 -142
  78. package/dist/cicd-optimizer.d.ts.map +0 -1
  79. package/dist/commands/archive.d.ts +0 -50
  80. package/dist/commands/archive.d.ts.map +0 -1
  81. package/dist/commands/burnup.d.ts +0 -6
  82. package/dist/commands/burnup.d.ts.map +0 -1
  83. package/dist/commands/diagnose.d.ts +0 -52
  84. package/dist/commands/diagnose.d.ts.map +0 -1
  85. package/dist/commands/evaluate.d.ts +0 -8
  86. package/dist/commands/evaluate.d.ts.map +0 -1
  87. package/dist/commands/init.d.ts +0 -5
  88. package/dist/commands/init.d.ts.map +0 -1
  89. package/dist/commands/iterate.d.ts +0 -8
  90. package/dist/commands/iterate.d.ts.map +0 -1
  91. package/dist/commands/mode.d.ts +0 -24
  92. package/dist/commands/mode.d.ts.map +0 -1
  93. package/dist/commands/plan.d.ts +0 -49
  94. package/dist/commands/plan.d.ts.map +0 -1
  95. package/dist/commands/provenance.d.ts +0 -32
  96. package/dist/commands/provenance.d.ts.map +0 -1
  97. package/dist/commands/quality-gates.d.ts +0 -52
  98. package/dist/commands/quality-gates.d.ts.map +0 -1
  99. package/dist/commands/quality-monitor.d.ts +0 -17
  100. package/dist/commands/quality-monitor.d.ts.map +0 -1
  101. package/dist/commands/specs.d.ts +0 -71
  102. package/dist/commands/specs.d.ts.map +0 -1
  103. package/dist/commands/status.d.ts +0 -44
  104. package/dist/commands/status.d.ts.map +0 -1
  105. package/dist/commands/templates.d.ts +0 -74
  106. package/dist/commands/templates.d.ts.map +0 -1
  107. package/dist/commands/tool.d.ts +0 -13
  108. package/dist/commands/tool.d.ts.map +0 -1
  109. package/dist/commands/troubleshoot.d.ts +0 -8
  110. package/dist/commands/troubleshoot.d.ts.map +0 -1
  111. package/dist/commands/tutorial.d.ts +0 -55
  112. package/dist/commands/tutorial.d.ts.map +0 -1
  113. package/dist/commands/validate.d.ts +0 -15
  114. package/dist/commands/validate.d.ts.map +0 -1
  115. package/dist/commands/waivers.d.ts +0 -8
  116. package/dist/commands/waivers.d.ts.map +0 -1
  117. package/dist/commands/workflow.d.ts +0 -85
  118. package/dist/commands/workflow.d.ts.map +0 -1
  119. package/dist/config/index.d.ts +0 -29
  120. package/dist/config/index.d.ts.map +0 -1
  121. package/dist/config/modes.d.ts +0 -225
  122. package/dist/config/modes.d.ts.map +0 -1
  123. package/dist/constants/spec-types.d.ts +0 -41
  124. package/dist/constants/spec-types.d.ts.map +0 -1
  125. package/dist/error-handler.d.ts +0 -164
  126. package/dist/error-handler.d.ts.map +0 -1
  127. package/dist/generators/jest-config.d.ts +0 -32
  128. package/dist/generators/jest-config.d.ts.map +0 -1
  129. package/dist/generators/working-spec.d.ts +0 -13
  130. package/dist/generators/working-spec.d.ts.map +0 -1
  131. package/dist/index-new.d.ts +0 -5
  132. package/dist/index-new.d.ts.map +0 -1
  133. package/dist/index-new.js +0 -317
  134. package/dist/index.d.ts +0 -5
  135. package/dist/index.d.ts.map +0 -1
  136. package/dist/index.js.backup +0 -4711
  137. package/dist/minimal-cli.d.ts +0 -3
  138. package/dist/minimal-cli.d.ts.map +0 -1
  139. package/dist/policy/PolicyManager.d.ts +0 -104
  140. package/dist/policy/PolicyManager.d.ts.map +0 -1
  141. package/dist/scaffold/cursor-hooks.d.ts +0 -7
  142. package/dist/scaffold/cursor-hooks.d.ts.map +0 -1
  143. package/dist/scaffold/git-hooks.d.ts +0 -20
  144. package/dist/scaffold/git-hooks.d.ts.map +0 -1
  145. package/dist/scaffold/index.d.ts +0 -20
  146. package/dist/scaffold/index.d.ts.map +0 -1
  147. package/dist/spec/SpecFileManager.d.ts +0 -146
  148. package/dist/spec/SpecFileManager.d.ts.map +0 -1
  149. package/dist/test-analysis.d.ts +0 -182
  150. package/dist/test-analysis.d.ts.map +0 -1
  151. package/dist/tool-interface.d.ts +0 -236
  152. package/dist/tool-interface.d.ts.map +0 -1
  153. package/dist/tool-loader.d.ts +0 -77
  154. package/dist/tool-loader.d.ts.map +0 -1
  155. package/dist/tool-validator.d.ts +0 -72
  156. package/dist/tool-validator.d.ts.map +0 -1
  157. package/dist/utils/detection.d.ts +0 -7
  158. package/dist/utils/detection.d.ts.map +0 -1
  159. package/dist/utils/finalization.d.ts +0 -17
  160. package/dist/utils/finalization.d.ts.map +0 -1
  161. package/dist/utils/project-analysis.d.ts +0 -14
  162. package/dist/utils/project-analysis.d.ts.map +0 -1
  163. package/dist/utils/quality-gates.d.ts +0 -49
  164. package/dist/utils/quality-gates.d.ts.map +0 -1
  165. package/dist/utils/spec-resolver.d.ts +0 -88
  166. package/dist/utils/spec-resolver.d.ts.map +0 -1
  167. package/dist/utils/typescript-detector.d.ts +0 -63
  168. package/dist/utils/typescript-detector.d.ts.map +0 -1
  169. package/dist/validation/spec-validation.d.ts +0 -43
  170. package/dist/validation/spec-validation.d.ts.map +0 -1
  171. package/dist/waivers-manager.d.ts +0 -167
  172. package/dist/waivers-manager.d.ts.map +0 -1
  173. package/templates/apps/tools/caws/COMPLETION_REPORT.md +0 -331
  174. package/templates/apps/tools/caws/MIGRATION_SUMMARY.md +0 -360
  175. package/templates/apps/tools/caws/README.md +0 -463
  176. package/templates/apps/tools/caws/TEST_STATUS.md +0 -365
  177. package/templates/apps/tools/caws/attest.js +0 -357
  178. package/templates/apps/tools/caws/ci-optimizer.js +0 -642
  179. package/templates/apps/tools/caws/config.ts +0 -245
  180. package/templates/apps/tools/caws/cross-functional.js +0 -876
  181. package/templates/apps/tools/caws/dashboard.js +0 -1112
  182. package/templates/apps/tools/caws/flake-detector.ts +0 -362
  183. package/templates/apps/tools/caws/gates.js +0 -198
  184. package/templates/apps/tools/caws/gates.ts +0 -271
  185. package/templates/apps/tools/caws/language-adapters.ts +0 -381
  186. package/templates/apps/tools/caws/language-support.d.ts +0 -367
  187. package/templates/apps/tools/caws/language-support.d.ts.map +0 -1
  188. package/templates/apps/tools/caws/language-support.js +0 -585
  189. package/templates/apps/tools/caws/legacy-assessment.ts +0 -408
  190. package/templates/apps/tools/caws/legacy-assessor.js +0 -764
  191. package/templates/apps/tools/caws/mutant-analyzer.js +0 -734
  192. package/templates/apps/tools/caws/perf-budgets.ts +0 -349
  193. package/templates/apps/tools/caws/prompt-lint.js.backup +0 -274
  194. package/templates/apps/tools/caws/property-testing.js +0 -707
  195. package/templates/apps/tools/caws/provenance.d.ts +0 -14
  196. package/templates/apps/tools/caws/provenance.d.ts.map +0 -1
  197. package/templates/apps/tools/caws/provenance.js +0 -132
  198. package/templates/apps/tools/caws/provenance.js.backup +0 -73
  199. package/templates/apps/tools/caws/provenance.ts +0 -211
  200. package/templates/apps/tools/caws/security-provenance.ts +0 -483
  201. package/templates/apps/tools/caws/shared/base-tool.ts +0 -281
  202. package/templates/apps/tools/caws/shared/config-manager.ts +0 -366
  203. package/templates/apps/tools/caws/shared/gate-checker.ts +0 -849
  204. package/templates/apps/tools/caws/shared/types.ts +0 -444
  205. package/templates/apps/tools/caws/shared/validator.ts +0 -305
  206. package/templates/apps/tools/caws/shared/waivers-manager.ts +0 -174
  207. package/templates/apps/tools/caws/spec-test-mapper.ts +0 -391
  208. package/templates/apps/tools/caws/test-quality.js +0 -578
  209. package/templates/apps/tools/caws/validate.js +0 -76
  210. package/templates/apps/tools/caws/validate.ts +0 -228
  211. package/templates/apps/tools/caws/waivers.js +0 -344
  212. /package/{templates/apps/tools/caws → dist/templates/.caws}/schemas/waivers.schema.json +0 -0
  213. /package/{templates/apps/tools/caws → dist/templates/.caws}/schemas/working-spec.schema.json +0 -0
  214. /package/{templates/apps/tools/caws → dist/templates/.caws}/templates/working-spec.template.yml +0 -0
  215. /package/{templates/apps/tools/caws → dist/templates/.caws/tools}/scope-guard.js +0 -0
  216. /package/{templates/apps/tools/caws → dist/templates/.caws}/tools-allow.json +0 -0
  217. /package/{templates/apps/tools/caws → dist/templates/.caws}/waivers.yml +0 -0
@@ -0,0 +1,311 @@
1
+ # CAWS Cursor IDE Integration
2
+
3
+ This directory contains Cursor IDE hooks that provide real-time CAWS quality assurance integration during development.
4
+
5
+ ## Overview
6
+
7
+ Cursor hooks enable seamless integration between CAWS and the Cursor IDE, providing:
8
+
9
+ - **Real-time quality validation** as you code
10
+ - **Automatic spec validation** when editing working specs
11
+ - **Scope enforcement** preventing out-of-scope file access
12
+ - **Tool validation** for safe MCP execution
13
+ - **Quality monitoring** after file edits
14
+
15
+ ## Hook Configuration
16
+
17
+ The `hooks.json` file defines when each hook runs:
18
+
19
+ ```json
20
+ {
21
+ "beforeShellExecution": ["block-dangerous.sh", "audit.sh"],
22
+ "beforeMCPExecution": ["audit.sh", "caws-tool-validation.sh"],
23
+ "beforeReadFile": ["scan-secrets.sh", "caws-scope-guard.sh"],
24
+ "afterFileEdit": ["format.sh", "naming-check.sh", "validate-spec.sh", "caws-quality-check.sh", "audit.sh"],
25
+ "beforeSubmitPrompt": ["caws-scope-guard.sh", "audit.sh"],
26
+ "stop": ["audit.sh"]
27
+ }
28
+ ```
29
+
30
+ ## Available Hooks
31
+
32
+ ### CAWS-Specific Hooks
33
+
34
+ #### `caws-quality-check.sh`
35
+ - **Trigger**: `afterFileEdit`
36
+ - **Purpose**: Runs CAWS quality evaluation after code changes
37
+ - **Blocks**: No (provides warnings and suggestions)
38
+ - **Fallback**: Graceful degradation if CAWS CLI unavailable
39
+
40
+ #### `caws-scope-guard.sh`
41
+ - **Trigger**: `beforeReadFile`, `beforeSubmitPrompt`
42
+ - **Purpose**: Prevents access to files outside CAWS-defined scope
43
+ - **Blocks**: Yes (for out-of-scope file access)
44
+ - **Requires**: `.caws/working-spec.yaml`
45
+
46
+ #### `caws-tool-validation.sh`
47
+ - **Trigger**: `beforeMCPExecution`
48
+ - **Purpose**: Validates CAWS MCP tool calls for security
49
+ - **Blocks**: Yes (for dangerous operations or invalid waivers)
50
+ - **Validates**: Waiver creation, tool permissions, command safety
51
+
52
+ ### General Security Hooks
53
+
54
+ #### `block-dangerous.sh`
55
+ - **Trigger**: `beforeShellExecution`
56
+ - **Purpose**: Prevents execution of dangerous shell commands
57
+ - **Blocks**: `rm -rf /`, `sudo`, destructive operations
58
+
59
+ #### `scan-secrets.sh`
60
+ - **Trigger**: `beforeReadFile`
61
+ - **Purpose**: Scans for potential secrets before file access
62
+ - **Blocks**: Files containing password/token patterns
63
+
64
+ ### Code Quality Hooks
65
+
66
+ #### `format.sh`
67
+ - **Trigger**: `afterFileEdit`
68
+ - **Purpose**: Auto-formats code using Prettier/ESLint
69
+ - **Blocks**: No (formats in background)
70
+
71
+ #### `naming-check.sh`
72
+ - **Trigger**: `afterFileEdit`
73
+ - **Purpose**: Enforces CAWS naming conventions
74
+ - **Blocks**: No (provides warnings)
75
+
76
+ #### `validate-spec.sh`
77
+ - **Trigger**: `afterFileEdit`
78
+ - **Purpose**: Validates CAWS working specs in real-time
79
+ - **Blocks**: No (shows validation errors)
80
+
81
+ ### Audit Hooks
82
+
83
+ #### `audit.sh`
84
+ - **Trigger**: Multiple events
85
+ - **Purpose**: Logs all hook executions for debugging
86
+ - **Blocks**: No (passive logging)
87
+
88
+ ## Installation
89
+
90
+ ### Automatic Setup
91
+
92
+ ```bash
93
+ # CAWS init automatically sets up Cursor hooks
94
+ caws init my-project --interactive
95
+
96
+ # Or manually scaffold hooks
97
+ caws scaffold
98
+ ```
99
+
100
+ ### Manual Setup
101
+
102
+ 1. Copy `.cursor/` directory to your project root
103
+ 2. Ensure hook scripts are executable: `chmod +x .cursor/hooks/*.sh`
104
+ 3. Restart Cursor IDE
105
+ 4. Verify hooks are active in Cursor settings
106
+
107
+ ## Configuration
108
+
109
+ ### Environment Variables
110
+
111
+ ```bash
112
+ # Enable debug logging
113
+ export CURSOR_HOOKS_DEBUG=1
114
+
115
+ # CAWS CLI path override
116
+ export CAWS_CLI_PATH=/custom/path/to/caws
117
+
118
+ # Disable specific hooks
119
+ export CURSOR_DISABLE_HOOKS=audit.sh,format.sh
120
+ ```
121
+
122
+ ### Hook Customization
123
+
124
+ Modify `hooks.json` to customize hook behavior:
125
+
126
+ ```json
127
+ {
128
+ "afterFileEdit": [
129
+ {
130
+ "command": "./.cursor/hooks/caws-quality-check.sh",
131
+ "timeout": 5000,
132
+ "background": true
133
+ }
134
+ ]
135
+ }
136
+ ```
137
+
138
+ ## Troubleshooting
139
+
140
+ ### Hooks Not Running
141
+
142
+ ```bash
143
+ # Check hook permissions
144
+ ls -la .cursor/hooks/
145
+
146
+ # Verify Cursor hooks are enabled
147
+ # Cursor Settings → Hooks → Enable hooks
148
+
149
+ # Check Cursor logs
150
+ # Help → Toggle Developer Tools → Console
151
+ ```
152
+
153
+ ### CAWS CLI Not Found
154
+
155
+ ```bash
156
+ # Install CAWS CLI
157
+ npm install -g @caws/cli
158
+
159
+ # Or use bundled version (VS Code extension)
160
+ code --install-extension caws.caws-vscode-extension
161
+
162
+ # Verify PATH
163
+ which caws
164
+ ```
165
+
166
+ ### False Positives
167
+
168
+ ```bash
169
+ # Temporarily disable hooks
170
+ export CURSOR_DISABLE_HOOKS=caws-scope-guard.sh
171
+
172
+ # Or modify hook logic
173
+ vim .cursor/hooks/caws-scope-guard.sh
174
+ ```
175
+
176
+ ### Performance Issues
177
+
178
+ ```bash
179
+ # Run hooks in background
180
+ # Edit hooks.json to add "background": true
181
+
182
+ # Increase timeouts
183
+ # Edit hooks.json to add "timeout": 10000
184
+
185
+ # Disable slow hooks
186
+ export CURSOR_DISABLE_HOOKS=format.sh,naming-check.sh
187
+ ```
188
+
189
+ ## Development
190
+
191
+ ### Creating New Hooks
192
+
193
+ 1. **Create script** in `.cursor/hooks/`
194
+ 2. **Make executable**: `chmod +x .cursor/hooks/your-hook.sh`
195
+ 3. **Add to configuration** in `hooks.json`
196
+ 4. **Test manually**: `echo '{}' | ./cursor/hooks/your-hook.sh`
197
+
198
+ ### Hook Script Template
199
+
200
+ ```bash
201
+ #!/bin/bash
202
+ # CAWS Hook: Description
203
+ # @author @darianrosebrook
204
+
205
+ set -e
206
+
207
+ # Read Cursor input
208
+ INPUT=$(cat)
209
+ DATA=$(echo "$INPUT" | jq -r '.data // ""')
210
+
211
+ # Your hook logic here
212
+ if [[ -n "$DATA" ]]; then
213
+ # Process data
214
+ echo '{"userMessage": "Hook executed", "agentMessage": "Details"}'
215
+ fi
216
+
217
+ exit 0
218
+ ```
219
+
220
+ ### Testing Hooks
221
+
222
+ ```bash
223
+ # Test with sample input
224
+ echo '{"action": "edit_file", "file_path": "test.js"}' | ./cursor/hooks/caws-quality-check.sh
225
+
226
+ # Test error conditions
227
+ echo '{}' | ./cursor/hooks/caws-scope-guard.sh
228
+
229
+ # Debug with verbose output
230
+ export CURSOR_HOOKS_DEBUG=1
231
+ ```
232
+
233
+ ## Integration with CAWS Ecosystem
234
+
235
+ ### Relationship to Other Tools
236
+
237
+ ```
238
+ Cursor Hooks ←→ CAWS CLI ←→ VS Code Extension
239
+ ↓ ↓ ↓
240
+ Real-time Command-line Rich IDE
241
+ Validation Interface Integration
242
+ ```
243
+
244
+ ### Complementary Tools
245
+
246
+ - **Git Hooks**: `.git/hooks/` for commit/push validation
247
+ - **VS Code Extension**: Rich UI for CAWS operations
248
+ - **MCP Server**: Agent tool integration
249
+ - **CAWS CLI**: Core functionality
250
+
251
+ ### Data Flow
252
+
253
+ ```
254
+ File Edit → Cursor Hook → CAWS CLI → Quality Check → User Feedback
255
+
256
+ Audit Log → Provenance Tracking
257
+ ```
258
+
259
+ ## Security Considerations
260
+
261
+ ### Safe Execution
262
+
263
+ - Hooks run in isolated processes
264
+ - No access to sensitive Cursor data
265
+ - Input validation on all hook data
266
+ - Timeout protection against hanging hooks
267
+
268
+ ### Privacy Protection
269
+
270
+ - File contents not sent to external services
271
+ - Local CAWS CLI execution only
272
+ - No telemetry or data collection
273
+ - User-controlled hook execution
274
+
275
+ ## Performance Optimization
276
+
277
+ ### Hook Design Principles
278
+
279
+ 1. **Fast Execution**: < 2 seconds for real-time feedback
280
+ 2. **Background Processing**: Non-blocking operations
281
+ 3. **Selective Running**: Only run relevant hooks
282
+ 4. **Caching**: Avoid redundant operations
283
+
284
+ ### Optimization Strategies
285
+
286
+ - **Debounced execution** for file edit hooks
287
+ - **Incremental validation** for large codebases
288
+ - **Parallel processing** for independent checks
289
+ - **Result caching** for repeated operations
290
+
291
+ ## Contributing
292
+
293
+ ### Hook Development Guidelines
294
+
295
+ - **Clear naming**: `caws-*` prefix for CAWS-specific hooks
296
+ - **Comprehensive logging**: Debug-friendly output
297
+ - **Error handling**: Graceful failure modes
298
+ - **Documentation**: Inline comments and README updates
299
+ - **Testing**: Manual and automated test coverage
300
+
301
+ ### Pull Request Process
302
+
303
+ 1. **Test locally** in Cursor IDE
304
+ 2. **Update documentation** in this README
305
+ 3. **Add configuration examples** if needed
306
+ 4. **Consider performance impact** on large codebases
307
+ 5. **Test with different project types** (CAWS/non-CAWS)
308
+
309
+ ## License
310
+
311
+ MIT License - see main project LICENSE file.
@@ -0,0 +1,55 @@
1
+ #!/bin/bash
2
+ # Cursor Hook: Audit Trail
3
+ #
4
+ # Purpose: Log all Cursor AI events for provenance tracking
5
+ # Event: All (beforeShellExecution, beforeMCPExecution, beforeReadFile,
6
+ # afterFileEdit, beforeSubmitPrompt, stop)
7
+ #
8
+ # @author @darianrosebrook
9
+
10
+ set -euo pipefail
11
+
12
+ # Read input from Cursor
13
+ INPUT=$(cat)
14
+
15
+ # Create log directory if it doesn't exist
16
+ LOG_DIR=".cursor/logs"
17
+ mkdir -p "$LOG_DIR"
18
+
19
+ # Log file with date rotation
20
+ LOG_FILE="$LOG_DIR/audit-$(date +%Y-%m-%d).log"
21
+
22
+ # Extract key information
23
+ TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
24
+ HOOK_EVENT=$(echo "$INPUT" | jq -r '.hook_event_name // "unknown"')
25
+ CONVERSATION_ID=$(echo "$INPUT" | jq -r '.conversation_id // "none"')
26
+ GENERATION_ID=$(echo "$INPUT" | jq -r '.generation_id // "none"')
27
+
28
+ # Create audit entry
29
+ AUDIT_ENTRY=$(cat <<EOF
30
+ {
31
+ "timestamp": "$TIMESTAMP",
32
+ "event": "$HOOK_EVENT",
33
+ "conversation_id": "$CONVERSATION_ID",
34
+ "generation_id": "$GENERATION_ID",
35
+ "details": $INPUT
36
+ }
37
+ EOF
38
+ )
39
+
40
+ # Append to audit log
41
+ echo "$AUDIT_ENTRY" >> "$LOG_FILE"
42
+
43
+ # Try to update CAWS provenance if available
44
+ if [ -f "apps/tools/caws/provenance.js" ]; then
45
+ node apps/tools/caws/provenance.js log-event \
46
+ --event="$HOOK_EVENT" \
47
+ --conversation="$CONVERSATION_ID" \
48
+ --generation="$GENERATION_ID" \
49
+ 2>/dev/null || true
50
+ fi
51
+
52
+ # Always allow - this is observation only
53
+ echo '{"permission":"allow"}' 2>/dev/null || true
54
+ exit 0
55
+
@@ -0,0 +1,83 @@
1
+ #!/bin/bash
2
+ # Cursor Hook: Dangerous Command Blocker
3
+ #
4
+ # Purpose: Block or ask permission for risky shell commands
5
+ # Event: beforeShellExecution
6
+ #
7
+ # @author @darianrosebrook
8
+
9
+ set -euo pipefail
10
+
11
+ # Read input from Cursor
12
+ INPUT=$(cat)
13
+
14
+ # Extract command and cwd
15
+ COMMAND=$(echo "$INPUT" | jq -r '.command // ""')
16
+ CWD=$(echo "$INPUT" | jq -r '.cwd // ""')
17
+
18
+ # Hard blocks - never allow these
19
+ # CRITICAL: These commands can cause catastrophic data loss
20
+ # git init, git reset --hard, and git push --force were added after an incident
21
+ # where an agent panicked at quality gates and wiped thousands of lines of work
22
+ HARD_BLOCKS=(
23
+ "rm -rf /"
24
+ "rm -rf /*"
25
+ "rm -rf ~"
26
+ "rm -rf $HOME"
27
+ "> /dev/sda"
28
+ "git init" # Can wipe entire git history and stashed changes
29
+ "git commit --amend --no-edit" # Can rewrite commit history destructively
30
+ "git reset --hard" # Can lose uncommitted work and stashed changes
31
+ "git push --force" # Can overwrite remote repository history
32
+ "dd if="
33
+ "mkfs"
34
+ "format c:"
35
+ "del /f /s /q"
36
+ "DROP DATABASE"
37
+ "TRUNCATE TABLE"
38
+ )
39
+
40
+ for blocked in "${HARD_BLOCKS[@]}"; do
41
+ if [[ "$COMMAND" == *"$blocked"* ]]; then
42
+ echo '{"permission":"deny","userMessage":"⚠️ BLOCKED: Dangerous command detected. This operation could cause data loss.","agentMessage":"This command is blocked for safety. If you need to perform this operation, run it manually."}' 2>/dev/null
43
+ exit 0
44
+ fi
45
+ done
46
+
47
+ # Ask permission for risky operations
48
+ # Note: git commands moved to HARD_BLOCKS after catastrophic data loss incident
49
+ ASK_PERMISSION=(
50
+ "rm -rf"
51
+ "npm publish"
52
+ "docker rmi"
53
+ "docker system prune"
54
+ "kubectl delete"
55
+ "terraform destroy"
56
+ "DROP TABLE"
57
+ "DELETE FROM"
58
+ "UPDATE.*SET"
59
+ )
60
+
61
+ for risky in "${ASK_PERMISSION[@]}"; do
62
+ if echo "$COMMAND" | grep -qiE "$risky"; then
63
+ echo '{"permission":"ask","userMessage":"⚠️ Risky operation: '"$COMMAND"'. Approve to continue.","agentMessage":"This is a potentially destructive operation. User approval required."}' 2>/dev/null
64
+ exit 0
65
+ fi
66
+ done
67
+
68
+ # Block git operations that skip hooks
69
+ if echo "$COMMAND" | grep -qE "(--no-verify|--no-gpg-sign)"; then
70
+ echo '{"permission":"ask","userMessage":"⚠️ This command skips git hooks. Approve to continue.","agentMessage":"Skipping hooks bypasses quality gates. Use with caution."}' 2>/dev/null
71
+ exit 0
72
+ fi
73
+
74
+ # Block force push to main/master
75
+ if echo "$COMMAND" | grep -qE "git push.*(--force|-f).*\s+(origin\s+)?(main|master)"; then
76
+ echo '{"permission":"deny","userMessage":"⚠️ BLOCKED: Force push to main/master is not allowed.","agentMessage":"Force pushing to main/master can cause data loss for other developers."}' 2>/dev/null
77
+ exit 0
78
+ fi
79
+
80
+ # Allow by default
81
+ echo '{"permission":"allow"}' 2>/dev/null
82
+ exit 0
83
+
@@ -0,0 +1,52 @@
1
+ #!/bin/bash
2
+ # CAWS Quality Check Hook
3
+ # Runs CAWS quality validation after file edits
4
+ # @author @darianrosebrook
5
+
6
+ set -e
7
+
8
+ # Read input from Cursor
9
+ INPUT=$(cat)
10
+ FILE_PATH=$(echo "$INPUT" | jq -r '.file_path // ""')
11
+
12
+ # Only run on source files
13
+ if [[ "$FILE_PATH" =~ \.(js|ts|jsx|tsx|py|go|rs|java)$ ]] && [[ ! "$FILE_PATH" =~ node_modules ]] && [[ ! "$FILE_PATH" =~ dist ]]; then
14
+
15
+ # Check if CAWS is available
16
+ if command -v caws &> /dev/null; then
17
+
18
+ # Check if we're in a CAWS project
19
+ if [[ -f ".caws/working-spec.yaml" ]]; then
20
+
21
+ echo "🔍 Running CAWS quality check..." >&2
22
+
23
+ # Run CAWS evaluation in quiet mode for fast feedback
24
+ if caws agent evaluate .caws/working-spec.yaml --quiet 2>/dev/null; then
25
+ echo '{"userMessage": "✅ CAWS quality check passed", "agentMessage": "Quality standards maintained"}'
26
+ else
27
+ # Get detailed feedback
28
+ EVALUATION=$(caws agent evaluate .caws/working-spec.yaml --json 2>/dev/null || echo '{"success": false, "error": "Evaluation failed"}')
29
+
30
+ # Parse the evaluation result
31
+ SUCCESS=$(echo "$EVALUATION" | jq -r '.success // false')
32
+ SCORE=$(echo "$EVALUATION" | jq -r '.evaluation.quality_score // 0')
33
+
34
+ if [[ "$SUCCESS" == "true" ]] && (( $(echo "$SCORE > 0.75" | bc -l) )); then
35
+ echo '{"userMessage": "✅ CAWS quality standards met", "agentMessage": "Code meets quality requirements"}'
36
+ else
37
+ FAILED_GATES=$(echo "$EVALUATION" | jq -r '.evaluation.criteria[] | select(.status == "failed") | .name' | tr '\n' ', ' | sed 's/, $//')
38
+
39
+ echo '{
40
+ "userMessage": "⚠️ CAWS quality issues detected. Run: caws agent evaluate",
41
+ "agentMessage": "Quality gates failed: '"$FAILED_GATES"'",
42
+ "suggestions": [
43
+ "Run caws agent evaluate for detailed feedback",
44
+ "Consider creating a waiver if justified: caws waivers create",
45
+ "Address failing quality gates before proceeding"
46
+ ]
47
+ }'
48
+ fi
49
+ fi
50
+ fi
51
+ fi
52
+ fi
@@ -0,0 +1,130 @@
1
+ #!/bin/bash
2
+ # CAWS Scope Guard Hook
3
+ # Prevents agents from accessing files outside CAWS-defined scope
4
+ # @author @darianrosebrook
5
+
6
+ set -e
7
+
8
+ # Read input from Cursor
9
+ INPUT=$(cat)
10
+ ACTION=$(echo "$INPUT" | jq -r '.action // ""')
11
+ FILE_PATH=$(echo "$INPUT" | jq -r '.file_path // ""')
12
+
13
+ # Check if CAWS is available and we have a working spec
14
+ if command -v caws &> /dev/null && [[ -f ".caws/working-spec.yaml" ]]; then
15
+
16
+ # AGENT GUARDRAILS - Prevent policy bypass attempts
17
+ if [[ "$ACTION" == "edit_file" ]] || [[ "$ACTION" == "create_file" ]]; then
18
+ if [[ "$FILE_PATH" == ".caws/policy.yaml" ]]; then
19
+ echo '{
20
+ "userMessage": "🚫 Policy file editing blocked by agent guardrails",
21
+ "agentMessage": "Agents cannot edit .caws/policy.yaml - requires human dual control",
22
+ "block": true,
23
+ "suggestions": [
24
+ "Policy changes must be approved by humans with Gatekeeper role",
25
+ "Create a separate PR for policy changes",
26
+ "For budget exceptions: caws waivers create --title=\"Budget exception\" --reason=architectural_refactor --gates=budget_limit",
27
+ "Contact @gatekeepers for policy modifications"
28
+ ]
29
+ }'
30
+ exit 1
31
+ fi
32
+
33
+ if [[ "$FILE_PATH" == "CODEOWNERS" ]]; then
34
+ echo '{
35
+ "userMessage": "🚫 CODEOWNERS editing blocked by agent guardrails",
36
+ "agentMessage": "Agents cannot modify CODEOWNERS - governance changes require approval",
37
+ "block": true,
38
+ "suggestions": [
39
+ "CODEOWNERS changes require governance review",
40
+ "Contact repository maintainers for ownership changes",
41
+ "For approval workflows: caws waivers create --reason=governance_change"
42
+ ]
43
+ }'
44
+ exit 1
45
+ fi
46
+
47
+ if [[ "$FILE_PATH" == ".caws/working-spec.yaml" ]]; then
48
+ # Check if trying to add change_budget
49
+ FILE_CONTENT=$(echo "$INPUT" | jq -r '.content // ""')
50
+ if echo "$FILE_CONTENT" | grep -q "change_budget"; then
51
+ echo '{
52
+ "userMessage": "🚫 Budget editing blocked by agent guardrails",
53
+ "agentMessage": "Agents cannot introduce change_budget fields - budgets are derived automatically",
54
+ "block": true,
55
+ "suggestions": [
56
+ "Check current budget status: caws burnup",
57
+ "For budget exceptions: caws waivers create --title=\"Scope expansion\" --reason=architectural_refactor --gates=budget_limit --expires-at=\"2025-12-31T23:59:59Z\"",
58
+ "Add waiver_ids to working spec instead: [\"WV-XXXX\"]",
59
+ "Validate waiver: caws validate .caws/working-spec.yaml"
60
+ ]
61
+ }'
62
+ exit 1
63
+ fi
64
+ fi
65
+ fi
66
+
67
+ # For file access actions, check scope
68
+ if [[ "$ACTION" == "read_file" ]] || [[ "$ACTION" == "edit_file" ]] || [[ -n "$FILE_PATH" ]]; then
69
+
70
+ # Get scope information from CAWS spec
71
+ SCOPE_CHECK=$(caws validate .caws/working-spec.yaml --scope-check "$FILE_PATH" 2>/dev/null || echo "unknown")
72
+
73
+ if [[ "$SCOPE_CHECK" == "out_of_scope" ]]; then
74
+ echo '{
75
+ "userMessage": "🚫 File access blocked by CAWS scope guard",
76
+ "agentMessage": "Cannot access '"$FILE_PATH"' - outside CAWS defined scope",
77
+ "block": true,
78
+ "suggestions": [
79
+ "Check current scope: caws validate .caws/working-spec.yaml",
80
+ "Update scope in working spec: edit .caws/working-spec.yaml scope.in array",
81
+ "For scope exceptions: caws waivers create --title=\"Scope expansion\" --reason=architectural_refactor --gates=scope_boundary --description=\"Need access to '"$FILE_PATH"' for implementation\"",
82
+ "Validate changes: caws validate .caws/working-spec.yaml"
83
+ ]
84
+ }'
85
+ exit 1
86
+ elif [[ "$SCOPE_CHECK" == "scope_warning" ]]; then
87
+ echo '{
88
+ "userMessage": "⚠️ File access outside primary scope",
89
+ "agentMessage": "File '"$FILE_PATH"' is outside primary scope but allowed",
90
+ "suggestions": [
91
+ "Check if needed in primary scope: edit .caws/working-spec.yaml scope.in",
92
+ "Consider scope implications: caws agent evaluate",
93
+ "Document scope decision in working spec invariants",
94
+ "Validate scope changes: caws validate .caws/working-spec.yaml"
95
+ ]
96
+ }'
97
+ fi
98
+ fi
99
+
100
+ # For prompt submissions, check working spec compliance
101
+ if [[ "$ACTION" == "submit_prompt" ]]; then
102
+ PROMPT_CONTENT=$(echo "$INPUT" | jq -r '.prompt // ""')
103
+
104
+ # Check if prompt mentions files outside scope
105
+ if [[ -n "$PROMPT_CONTENT" ]]; then
106
+ MENTIONED_FILES=$(echo "$PROMPT_CONTENT" | grep -oE '\b[a-zA-Z0-9_/.-]+\.(js|ts|jsx|tsx|py|go|rs|java|yaml|json|md)\b' | sort | uniq || true)
107
+
108
+ OUT_OF_SCOPE=""
109
+ for file in $MENTIONED_FILES; do
110
+ if [[ -f "$file" ]] && ! caws validate .caws/working-spec.yaml --scope-check "$file" 2>/dev/null | grep -q "in_scope"; then
111
+ OUT_OF_SCOPE="$OUT_OF_SCOPE $file"
112
+ fi
113
+ done
114
+
115
+ if [[ -n "$OUT_OF_SCOPE" ]]; then
116
+ echo '{
117
+ "userMessage": "⚠️ Prompt references files outside CAWS scope",
118
+ "agentMessage": "Prompt mentions out-of-scope files: '"$OUT_OF_SCOPE"'",
119
+ "suggestions": [
120
+ "Check current scope definition: caws validate .caws/working-spec.yaml",
121
+ "Update working spec scope: edit .caws/working-spec.yaml scope.in array",
122
+ "For scope exceptions: caws waivers create --title=\"Scope expansion\" --reason=architectural_refactor --gates=scope_boundary",
123
+ "Refocus prompt on in-scope files or request scope update approval",
124
+ "Validate scope changes: caws validate .caws/working-spec.yaml"
125
+ ]
126
+ }'
127
+ fi
128
+ fi
129
+ fi
130
+ fi