@paths.design/caws-cli 8.1.0 → 8.2.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 (78) hide show
  1. package/README.md +5 -6
  2. package/dist/commands/archive.d.ts +1 -1
  3. package/dist/commands/archive.d.ts.map +1 -1
  4. package/dist/commands/init.d.ts.map +1 -1
  5. package/dist/commands/init.js +185 -39
  6. package/dist/commands/mode.d.ts +2 -1
  7. package/dist/commands/mode.d.ts.map +1 -1
  8. package/dist/commands/provenance.d.ts.map +1 -1
  9. package/dist/commands/specs.d.ts.map +1 -1
  10. package/dist/commands/worktree.d.ts +7 -0
  11. package/dist/commands/worktree.d.ts.map +1 -0
  12. package/dist/commands/worktree.js +136 -0
  13. package/dist/config/lite-scope.d.ts +33 -0
  14. package/dist/config/lite-scope.d.ts.map +1 -0
  15. package/dist/config/lite-scope.js +158 -0
  16. package/dist/config/modes.d.ts +90 -51
  17. package/dist/config/modes.d.ts.map +1 -1
  18. package/dist/config/modes.js +26 -0
  19. package/dist/error-handler.d.ts +3 -16
  20. package/dist/error-handler.d.ts.map +1 -1
  21. package/dist/generators/jest-config-generator.d.ts +32 -0
  22. package/dist/generators/jest-config-generator.d.ts.map +1 -0
  23. package/dist/index.js +36 -0
  24. package/dist/scaffold/claude-hooks.d.ts +28 -0
  25. package/dist/scaffold/claude-hooks.d.ts.map +1 -0
  26. package/dist/scaffold/claude-hooks.js +28 -0
  27. package/dist/scaffold/index.d.ts +2 -0
  28. package/dist/scaffold/index.d.ts.map +1 -1
  29. package/dist/scaffold/index.js +90 -88
  30. package/dist/templates/.caws/schemas/scope.schema.json +52 -0
  31. package/dist/templates/.caws/schemas/working-spec.schema.json +1 -1
  32. package/dist/templates/.caws/schemas/worktrees.schema.json +36 -0
  33. package/dist/templates/.claude/hooks/block-dangerous.sh +33 -0
  34. package/dist/templates/.claude/hooks/lite-sprawl-check.sh +117 -0
  35. package/dist/templates/.claude/hooks/scope-guard.sh +93 -6
  36. package/dist/templates/.claude/hooks/simplification-guard.sh +92 -0
  37. package/dist/templates/.cursor/README.md +0 -3
  38. package/dist/templates/.github/copilot-instructions.md +82 -0
  39. package/dist/templates/.junie/guidelines.md +73 -0
  40. package/dist/templates/.vscode/launch.json +0 -27
  41. package/dist/templates/.windsurf/rules/caws-quality-standards.md +54 -0
  42. package/dist/templates/CLAUDE.md +101 -0
  43. package/dist/templates/agents.md +73 -1016
  44. package/dist/templates/docs/README.md +5 -5
  45. package/dist/test-analysis.d.ts +50 -1
  46. package/dist/test-analysis.d.ts.map +1 -1
  47. package/dist/utils/error-categories.d.ts +52 -0
  48. package/dist/utils/error-categories.d.ts.map +1 -0
  49. package/dist/utils/gitignore-updater.d.ts +1 -1
  50. package/dist/utils/gitignore-updater.d.ts.map +1 -1
  51. package/dist/utils/gitignore-updater.js +4 -0
  52. package/dist/utils/ide-detection.js +133 -0
  53. package/dist/utils/quality-gates-utils.d.ts +49 -0
  54. package/dist/utils/quality-gates-utils.d.ts.map +1 -0
  55. package/dist/utils/typescript-detector.d.ts +8 -5
  56. package/dist/utils/typescript-detector.d.ts.map +1 -1
  57. package/dist/validation/spec-validation.d.ts.map +1 -1
  58. package/dist/worktree/worktree-manager.d.ts +54 -0
  59. package/dist/worktree/worktree-manager.d.ts.map +1 -0
  60. package/dist/worktree/worktree-manager.js +378 -0
  61. package/package.json +5 -1
  62. package/templates/.caws/schemas/scope.schema.json +52 -0
  63. package/templates/.caws/schemas/working-spec.schema.json +1 -1
  64. package/templates/.caws/schemas/worktrees.schema.json +36 -0
  65. package/templates/.claude/hooks/block-dangerous.sh +33 -0
  66. package/templates/.claude/hooks/lite-sprawl-check.sh +117 -0
  67. package/templates/.claude/hooks/scope-guard.sh +93 -6
  68. package/templates/.claude/hooks/simplification-guard.sh +92 -0
  69. package/templates/.cursor/README.md +0 -3
  70. package/templates/.github/copilot-instructions.md +82 -0
  71. package/templates/.junie/guidelines.md +73 -0
  72. package/templates/.vscode/launch.json +0 -27
  73. package/templates/.windsurf/rules/caws-quality-standards.md +54 -0
  74. package/templates/AGENTS.md +104 -0
  75. package/templates/CLAUDE.md +101 -0
  76. package/templates/docs/README.md +5 -5
  77. package/templates/.github/copilot/instructions.md +0 -311
  78. package/templates/agents.md +0 -1047
@@ -1,1047 +0,0 @@
1
- # CAWS - Agent Workflow Guide
2
-
3
- **Coding Agent Workflow System** - Engineering-grade operating system for AI-assisted development
4
-
5
- **Version**: 3.1.0
6
- **Last Updated**: October 8, 2025
7
-
8
- ---
9
-
10
- ## Purpose & Philosophy
11
-
12
- CAWS is an engineering-grade operating system for coding agents that:
13
-
14
- 1. **Forces planning before code** - No implementation without a validated working spec
15
- 2. **Treats tests as first-class artifacts** - Tests drive implementation, not the other way around
16
- 3. **Creates explainable provenance** - Every change is tracked and attributable
17
- 4. **Enforces quality via automated gates** - CI/CD validates coverage, mutation scores, and contracts
18
-
19
- This guide teaches agents how to collaborate effectively with humans using CAWS tooling and conventions.
20
-
21
- ---
22
-
23
- ## Quick Start for Agents
24
-
25
- ### Your First CAWS Project
26
-
27
- When you encounter a CAWS project, follow this sequence:
28
-
29
- 1. **Check for working spec**: Look for `.caws/working-spec.yaml`
30
- 2. **Understand the scope**: Read the `scope.in` and `scope.out` to know boundaries
31
- 3. **Check risk tier**: Tier 1 (critical), Tier 2 (standard), Tier 3 (low risk)
32
- 4. **Review acceptance criteria**: These are your implementation targets
33
- 5. **Validate before starting**: Run `caws validate` to ensure spec is valid
34
-
35
- ### The Golden Rule
36
-
37
- **Never write implementation code until:**
38
-
39
- - Working spec exists and validates
40
- - Test plan is defined
41
- - Acceptance criteria are clear
42
- - Scope boundaries are understood
43
-
44
- ---
45
-
46
- ## Core Concepts
47
-
48
- ### Risk Tiers - Your Quality Contract
49
-
50
- Risk tiers drive rigor and determine quality gates:
51
-
52
- | Tier | Use Case | Coverage | Mutation | Contracts | Review |
53
- | --------- | --------------------------- | -------- | -------- | --------- | -------- |
54
- | **🔴 T1** | Auth, billing, migrations | 90%+ | 70%+ | Required | Manual |
55
- | **🟡 T2** | Features, APIs, data writes | 80%+ | 50%+ | Required | Optional |
56
- | **🟢 T3** | UI, internal tools | 70%+ | 30%+ | Optional | Optional |
57
-
58
- **As an agent, you must:**
59
-
60
- - Infer and declare the tier in your plan
61
- - Meet or exceed tier requirements
62
- - Request human review for Tier 1 changes
63
- - Never downgrade a tier without human approval
64
-
65
- ### Key Invariants (Never Violate These)
66
-
67
- 1. **Atomic Change Budget**: Stay within `max_files` and `max_loc` limits
68
- 2. **In-Place Refactors**: No shadow files (`enhanced-*`, `new-*`, `v2-*`, etc.)
69
- 3. **Deterministic Code**: Use injected time/uuid/random for testability
70
- 4. **Secure Prompts**: Never include secrets, `.env` files, or keys in context
71
- 5. **Provenance**: All changes are tracked and attributable
72
-
73
- ### The Working Spec - Your Blueprint
74
-
75
- Every task needs a working spec at `.caws/working-spec.yaml`:
76
-
77
- ```yaml
78
- id: FEAT-001
79
- title: 'Add user authentication flow'
80
- risk_tier: 1
81
- mode: feature
82
- change_budget:
83
- max_files: 25
84
- max_loc: 1000
85
- blast_radius:
86
- modules: ['auth', 'api']
87
- data_migration: false
88
- operational_rollback_slo: '5m'
89
- scope:
90
- in: ['src/auth/', 'tests/auth/', 'package.json']
91
- out: ['src/billing/', 'node_modules/']
92
- invariants:
93
- - 'System maintains data consistency during rollback'
94
- - 'Authentication state is never stored in localStorage'
95
- - 'All auth tokens expire within 24h'
96
- acceptance:
97
- - id: 'A1'
98
- given: 'User is logged out'
99
- when: 'User submits valid credentials'
100
- then: 'User is logged in and redirected to dashboard'
101
- - id: 'A2'
102
- given: 'User has invalid session token'
103
- when: 'User attempts to access protected route'
104
- then: 'User is redirected to login with error message'
105
- non_functional:
106
- a11y: ['keyboard-navigation', 'screen-reader-labels']
107
- perf: { api_p95_ms: 250, lcp_ms: 2500 }
108
- security: ['input-validation', 'csrf-protection', 'rate-limiting']
109
- contracts:
110
- - type: 'openapi'
111
- path: 'docs/api/auth.yaml'
112
- ```
113
-
114
- ---
115
-
116
- ## Your Development Workflow
117
-
118
- ### Phase 1: Plan (Before Any Code)
119
-
120
- **Goal**: Create a validated working spec and test plan.
121
-
122
- ```bash
123
- # 1. Create or validate working spec
124
- caws validate --suggestions
125
-
126
- # 2. If issues exist, use auto-fix for safe corrections
127
- caws validate --auto-fix
128
-
129
- # 3. Review acceptance criteria - these are your targets
130
- cat .caws/working-spec.yaml | grep -A 20 "acceptance:"
131
- ```
132
-
133
- **What to include in your plan:**
134
-
135
- 1. **Design sketch**: Sequence diagram or API table
136
- 2. **Test matrix**: Unit/contract/integration/e2e with edge cases
137
- 3. **Data plan**: Fixtures, factories, seed strategy
138
- 4. **Observability**: Logs/metrics/traces for production verification
139
-
140
- **Output**: `feature.plan.md` committed to repo
141
-
142
- ### Phase 2: Implement (Test-Driven)
143
-
144
- **Goal**: Write tests first, then implementation.
145
-
146
- **Order of operations:**
147
-
148
- 1. **Contracts first** (if applicable)
149
-
150
- ```bash
151
- # Generate types from OpenAPI/GraphQL
152
- npm run generate:types
153
-
154
- # Add contract tests before implementation
155
- # Location: tests/contract/
156
- ```
157
-
158
- 2. **Unit tests next**
159
-
160
- ```bash
161
- # Write failing tests for each acceptance criterion
162
- # Location: tests/unit/
163
-
164
- # Run tests to confirm they fail
165
- npm test
166
- ```
167
-
168
- 3. **Implementation**
169
-
170
- ```bash
171
- # Implement to make tests pass
172
- # Stay within scope.in boundaries
173
- # Keep files under max_loc budget
174
- ```
175
-
176
- 4. **Integration/E2E tests**
177
-
178
- ```bash
179
- # Add integration tests for persistence/transactions
180
- # Location: tests/integration/
181
-
182
- # Add E2E smoke tests for critical paths
183
- # Location: tests/e2e/
184
- ```
185
-
186
- **Implementation rules:**
187
-
188
- - ✅ **DO**: Edit existing modules, use injected dependencies, write deterministic code
189
- - ❌ **DON'T**: Create shadow files, hardcode timestamps/UUIDs, exceed change budget
190
-
191
- ### Phase 3: Verify (Must Pass Before PR)
192
-
193
- **Goal**: Ensure all quality gates pass locally.
194
-
195
- ```bash
196
- # Run full verification suite
197
- npm run verify
198
-
199
- # Or run individual checks
200
- npm run lint # Code style
201
- npm run typecheck # Type safety
202
- npm test # All tests
203
- npm run test:coverage # Coverage thresholds
204
- npm run test:mutation # Mutation testing
205
- npm run test:contract # Contract validation
206
- npm run test:e2e # End-to-end smoke tests
207
- ```
208
-
209
- **Quality gates by tier:**
210
-
211
- **Tier 1:**
212
-
213
- - Branch coverage ≥ 90%
214
- - Mutation score ≥ 70%
215
- - All contract tests pass
216
- - Manual code review completed
217
- - No SAST/secret scan violations
218
-
219
- **Tier 2:**
220
-
221
- - Branch coverage ≥ 80%
222
- - Mutation score ≥ 50%
223
- - Contract tests pass (if external APIs)
224
- - E2E smoke tests pass
225
-
226
- **Tier 3:**
227
-
228
- - Branch coverage ≥ 70%
229
- - Mutation score ≥ 30%
230
- - Integration happy-path tests pass
231
-
232
- ### Phase 4: Document & Deliver
233
-
234
- **Goal**: Create comprehensive PR with all artifacts.
235
-
236
- **PR checklist:**
237
-
238
- ```markdown
239
- ## Working Spec
240
-
241
- - [ ] `.caws/working-spec.yaml` attached and validates
242
- - [ ] Risk tier appropriate for change impact
243
- - [ ] Acceptance criteria met
244
-
245
- ## Tests
246
-
247
- - [ ] Test plan documented
248
- - [ ] Coverage meets tier requirements
249
- - [ ] Mutation score meets tier requirements
250
- - [ ] Contract tests pass (if applicable)
251
- - [ ] E2E smoke tests pass (if applicable)
252
-
253
- ## Documentation
254
-
255
- - [ ] README updated (if public API changed)
256
- - [ ] Migration notes (if database changes)
257
- - [ ] Rollback plan documented
258
- - [ ] Changelog updated (semver impact noted)
259
-
260
- ## Quality Gates
261
-
262
- - [ ] All lints pass
263
- - [ ] Type checks pass
264
- - [ ] No secret scan violations
265
- - [ ] No SAST violations
266
- - [ ] Performance budgets met
267
-
268
- ## Provenance
269
-
270
- - [ ] Commits follow conventional commits format
271
- - [ ] PR title references ticket ID
272
- - [ ] Provenance updated: `caws provenance update`
273
- ```
274
-
275
- ---
276
-
277
- ## CLI Commands Reference
278
-
279
- ### Project Initialization
280
-
281
- ```bash
282
- # Interactive wizard (recommended for new projects)
283
- caws init --interactive
284
-
285
- # Initialize in existing directory
286
- caws init .
287
-
288
- # Use project template
289
- caws init my-project --template=extension
290
- ```
291
-
292
- ### Validation
293
-
294
- ```bash
295
- # Check working spec validity
296
- caws validate
297
-
298
- # Get helpful suggestions for fixing issues
299
- caws validate --suggestions
300
-
301
- # Auto-fix safe validation issues
302
- caws validate --auto-fix
303
-
304
- # Quiet mode for CI
305
- caws validate --quiet
306
- ```
307
-
308
- ### Scaffolding
309
-
310
- ```bash
311
- # Add CAWS components to existing project
312
- caws scaffold
313
-
314
- # Only essential components
315
- caws scaffold --minimal
316
-
317
- # Include specific features
318
- caws scaffold --with-codemods
319
- caws scaffold --with-oidc
320
- ```
321
-
322
- ### Provenance Tracking
323
-
324
- ```bash
325
- # Initialize provenance tracking
326
- caws provenance init
327
-
328
- # Install git hooks for automatic tracking
329
- caws hooks install --backup
330
-
331
- # Update provenance manually
332
- caws provenance update --commit <hash>
333
-
334
- # View beautiful dashboard
335
- caws provenance show --format=dashboard
336
-
337
- # Analyze AI effectiveness
338
- caws provenance analyze-ai
339
- ```
340
-
341
- ---
342
-
343
- ## Mode Matrix - Know Your Context
344
-
345
- Different modes have different rules:
346
-
347
- | Mode | Contracts | New Files | Required Artifacts |
348
- | ------------ | --------------- | ---------------------- | ----------------------------------------- |
349
- | **feature** | Required first | Allowed in scope.in | Migration plan, feature flag, perf budget |
350
- | **refactor** | Must not change | Discouraged (use mods) | Codemod script + semantic diff report |
351
- | **fix** | Unchanged | Discouraged | Red test → green; root cause note |
352
- | **doc** | N/A | Allowed (docs only) | Updated README/usage snippets |
353
- | **chore** | N/A | Limited (build/tools) | Version updates, dependency changes |
354
-
355
- ### Feature Mode (Most Common)
356
-
357
- **When to use**: Adding new functionality
358
-
359
- **Requirements**:
360
-
361
- 1. Define contracts first (OpenAPI/GraphQL/etc.)
362
- 2. Write consumer/provider tests before implementation
363
- 3. Include migration plan if database changes
364
- 4. Add feature flag for gradual rollout
365
- 5. Set performance budgets
366
-
367
- **Example workflow**:
368
-
369
- ```bash
370
- # 1. Define contract
371
- vim docs/api/new-feature.yaml
372
-
373
- # 2. Generate types
374
- npm run generate:types
375
-
376
- # 3. Write contract tests
377
- vim tests/contract/new-feature.test.ts
378
-
379
- # 4. Implement
380
- vim src/features/new-feature.ts
381
-
382
- # 5. Verify
383
- npm run verify
384
- ```
385
-
386
- ### Refactor Mode (High Risk)
387
-
388
- **When to use**: Restructuring without behavior change
389
-
390
- **Requirements**:
391
-
392
- 1. Contracts must not change
393
- 2. Provide codemod script for automatic transformation
394
- 3. Include semantic diff report
395
- 4. Prove no behavior change with tests
396
- 5. Update all imports automatically
397
-
398
- **Example workflow**:
399
-
400
- ```bash
401
- # 1. Write codemod
402
- vim codemod/rename-user-service.ts
403
-
404
- # 2. Dry run
405
- npx jscodeshift -d -t codemod/rename-user-service.ts src/
406
-
407
- # 3. Apply
408
- npx jscodeshift -t codemod/rename-user-service.ts src/
409
-
410
- # 4. Verify tests still pass
411
- npm test
412
-
413
- # 5. Generate semantic diff
414
- npm run semver-check
415
- ```
416
-
417
- ### Fix Mode (Urgent)
418
-
419
- **When to use**: Fixing bugs
420
-
421
- **Requirements**:
422
-
423
- 1. Write failing test that reproduces bug
424
- 2. Implement minimal fix
425
- 3. Document root cause in PR
426
- 4. Avoid new files - prefer in-place edits
427
-
428
- **Example workflow**:
429
-
430
- ```bash
431
- # 1. Write failing test
432
- vim tests/unit/user-service.test.ts
433
- npm test # Should fail
434
-
435
- # 2. Fix
436
- vim src/services/user-service.ts
437
- npm test # Should pass
438
-
439
- # 3. Document
440
- vim .caws/working-spec.yaml # Add root cause note
441
- ```
442
-
443
- ---
444
-
445
- ## Common Patterns & Best Practices
446
-
447
- ### Pattern: Deterministic Testing
448
-
449
- **Problem**: Tests that use `Date.now()`, `Math.random()`, or `crypto.randomUUID()` are non-deterministic.
450
-
451
- **Solution**: Inject time/random/UUID generators.
452
-
453
- ```typescript
454
- // ❌ Bad - Non-deterministic
455
- class OrderService {
456
- createOrder(items) {
457
- return {
458
- id: crypto.randomUUID(),
459
- timestamp: Date.now(),
460
- items,
461
- };
462
- }
463
- }
464
-
465
- // ✅ Good - Deterministic
466
- class OrderService {
467
- constructor(
468
- private clock: Clock,
469
- private idGenerator: IdGenerator
470
- ) {}
471
-
472
- createOrder(items) {
473
- return {
474
- id: this.idGenerator.generate(),
475
- timestamp: this.clock.now(),
476
- items,
477
- };
478
- }
479
- }
480
-
481
- // Test with injected dependencies
482
- test('createOrder generates valid order', () => {
483
- const clock = new FixedClock('2025-01-01T00:00:00Z');
484
- const idGen = new SequentialIdGenerator();
485
- const service = new OrderService(clock, idGen);
486
-
487
- const order = service.createOrder([item1, item2]);
488
-
489
- expect(order.id).toBe('00000001');
490
- expect(order.timestamp).toBe('2025-01-01T00:00:00Z');
491
- });
492
- ```
493
-
494
- ### Pattern: Guard Clauses for Safety
495
-
496
- **Problem**: Deep nesting makes code hard to read and error-prone.
497
-
498
- **Solution**: Use guard clauses and early returns.
499
-
500
- ```typescript
501
- // ❌ Bad - Deep nesting
502
- function processOrder(order) {
503
- if (order) {
504
- if (order.items && order.items.length > 0) {
505
- if (order.user) {
506
- if (order.user.active) {
507
- // Process order
508
- return calculateTotal(order.items);
509
- } else {
510
- throw new Error('User not active');
511
- }
512
- } else {
513
- throw new Error('No user');
514
- }
515
- } else {
516
- throw new Error('No items');
517
- }
518
- } else {
519
- throw new Error('No order');
520
- }
521
- }
522
-
523
- // ✅ Good - Guard clauses
524
- function processOrder(order) {
525
- if (!order) {
526
- throw new Error('No order');
527
- }
528
-
529
- if (!order.items || order.items.length === 0) {
530
- throw new Error('No items');
531
- }
532
-
533
- if (!order.user) {
534
- throw new Error('No user');
535
- }
536
-
537
- if (!order.user.active) {
538
- throw new Error('User not active');
539
- }
540
-
541
- // Now safe to process
542
- return calculateTotal(order.items);
543
- }
544
- ```
545
-
546
- ### Pattern: Contract-First Development
547
-
548
- **Problem**: API changes break consumers unexpectedly.
549
-
550
- **Solution**: Define contracts first, generate types, test before implementing.
551
-
552
- ```bash
553
- # 1. Define OpenAPI contract
554
- cat > docs/api/users.yaml << EOF
555
- openapi: 3.0.0
556
- paths:
557
- /users:
558
- get:
559
- responses:
560
- 200:
561
- content:
562
- application/json:
563
- schema:
564
- type: array
565
- items:
566
- \$ref: '#/components/schemas/User'
567
- components:
568
- schemas:
569
- User:
570
- type: object
571
- required: [id, email, name]
572
- properties:
573
- id: { type: string }
574
- email: { type: string }
575
- name: { type: string }
576
- EOF
577
-
578
- # 2. Generate TypeScript types
579
- npx openapi-typescript docs/api/users.yaml -o src/types/api.ts
580
-
581
- # 3. Write contract test
582
- cat > tests/contract/users.test.ts << EOF
583
- import { validateAgainstSchema } from '@pact-foundation/pact';
584
-
585
- test('GET /users returns valid user array', async () => {
586
- const response = await fetch('/api/users');
587
- const data = await response.json();
588
-
589
- await validateAgainstSchema(data, 'docs/api/users.yaml', '/users');
590
- });
591
- EOF
592
-
593
- # 4. Implement
594
- # src/api/users.ts now has type safety and contract validation
595
- ```
596
-
597
- ---
598
-
599
- ## Troubleshooting Common Issues
600
-
601
- ### Validation Errors
602
-
603
- #### Error: `risk_tier is required`
604
-
605
- **Cause**: Working spec missing risk tier.
606
-
607
- **Fix**:
608
-
609
- ```yaml
610
- # Add to .caws/working-spec.yaml
611
- risk_tier: 2 # Choose 1, 2, or 3 based on impact
612
- ```
613
-
614
- #### Error: `Invalid ID format`
615
-
616
- **Cause**: ID doesn't match `PREFIX-NUMBER` pattern.
617
-
618
- **Fix**:
619
-
620
- ```yaml
621
- # ❌ Bad
622
- id: feature-001
623
- id: FEAT001
624
- id: feat_001
625
-
626
- # ✅ Good
627
- id: FEAT-001
628
- id: FIX-042
629
- id: REFACTOR-003
630
- ```
631
-
632
- #### Error: `scope.in is required`
633
-
634
- **Cause**: Missing scope definition.
635
-
636
- **Fix**:
637
-
638
- ```yaml
639
- scope:
640
- in: ['src/features/auth/', 'tests/auth/']
641
- out: ['node_modules/', 'dist/']
642
- ```
643
-
644
- ### Scope Violations
645
-
646
- #### Error: `File outside scope: src/unrelated.ts`
647
-
648
- **Cause**: PR touches files not listed in `scope.in`.
649
-
650
- **Fix Option 1 - Update scope**:
651
-
652
- ```yaml
653
- scope:
654
- in:
655
- - 'src/features/auth/'
656
- - 'src/unrelated.ts' # Add file to scope
657
- ```
658
-
659
- **Fix Option 2 - Split PR**:
660
- Split changes into separate PRs with different scopes.
661
-
662
- ### Budget Exceeded
663
-
664
- #### Error: `35 files changed, exceeds budget of 25`
665
-
666
- **Cause**: Change is too large.
667
-
668
- **Fix Option 1 - Split PR**:
669
- Break into smaller, focused PRs.
670
-
671
- **Fix Option 2 - Increase budget**:
672
-
673
- ```yaml
674
- change_budget:
675
- max_files: 40 # Only if justified
676
- max_loc: 1200
677
- ```
678
-
679
- **Note**: Prefer splitting over increasing budget.
680
-
681
- ### Test Coverage Failures
682
-
683
- #### Error: `Branch coverage 75% below tier 2 requirement of 80%`
684
-
685
- **Cause**: Insufficient test coverage.
686
-
687
- **Fix**:
688
-
689
- 1. Run coverage report: `npm run test:coverage`
690
- 2. Identify untested branches in HTML report
691
- 3. Add tests for uncovered paths
692
- 4. Re-run: `npm run test:coverage`
693
-
694
- #### Error: `Mutation score 45% below tier 2 requirement of 50%`
695
-
696
- **Cause**: Tests aren't strong enough (mutants survive).
697
-
698
- **Fix**:
699
-
700
- 1. Run mutation report: `npm run test:mutation`
701
- 2. Review surviving mutants
702
- 3. Add assertions that would catch those mutations
703
- 4. Re-run: `npm run test:mutation`
704
-
705
- ---
706
-
707
- ## Provenance & AI Tracking
708
-
709
- CAWS automatically tracks all AI-assisted changes for transparency and quality analysis.
710
-
711
- ### Automatic Tracking via Git Hooks
712
-
713
- When you commit, hooks automatically:
714
-
715
- 1. Detect if change was AI-assisted (Cursor Composer, Chat, Tab)
716
- 2. Extract quality metrics (coverage, mutation score)
717
- 3. Link commits to working spec
718
- 4. Update provenance journal
719
-
720
- ### Viewing Provenance
721
-
722
- ```bash
723
- # Beautiful dashboard with insights
724
- caws provenance show --format=dashboard
725
-
726
- # JSON output for tooling
727
- caws provenance show --format=json
728
-
729
- # Analyze AI effectiveness
730
- caws provenance analyze-ai
731
- ```
732
-
733
- ### Dashboard Insights
734
-
735
- The provenance dashboard shows:
736
-
737
- - Total commits and AI-assisted percentage
738
- - Quality score trends over time
739
- - AI contribution breakdown (Composer vs Tab completions)
740
- - Acceptance rate for AI-assisted changes
741
- - Recent activity timeline
742
- - Smart recommendations for improvement
743
-
744
- ---
745
-
746
- ## Integration with Cursor IDE
747
-
748
- CAWS provides deep Cursor IDE integration via hooks and rules.
749
-
750
- ### Cursor Rules (`.cursor/rules/`)
751
-
752
- CAWS includes modular MDC rule files:
753
-
754
- 1. **01-working-style.mdc** - Working style and risk limits
755
- 2. **02-quality-gates.mdc** - Tests, linting, commit discipline
756
- 3. **03-naming-and-refactor.mdc** - Naming conventions, anti-duplication
757
- 4. **04-logging-language-style.mdc** - Logging clarity, emoji policy
758
- 5. **05-safe-defaults-guards.mdc** - Defensive coding patterns
759
- 6. **06-typescript-conventions.mdc** - TS/JS specific rules
760
- 7. **07-process-ops.mdc** - Server and process management
761
- 8. **08-solid-and-architecture.mdc** - SOLID principles
762
- 9. **09-docstrings.mdc** - Cross-language documentation
763
- 10. **10-authorship-and-attribution.mdc** - File attribution
764
-
765
- **These rules guide your behavior in Cursor automatically.**
766
-
767
- ### Cursor Hooks (`.cursor/hooks/`)
768
-
769
- Real-time quality enforcement:
770
-
771
- - **validate-command** - Blocks dangerous commands (`rm -rf /`, force push)
772
- - **validate-file-read** - Prevents reading secrets (`.env`, keys)
773
- - **validate-file-write** - Enforces naming conventions
774
- - **post-edit** - Auto-formats code after changes
775
-
776
- ### Disabling Temporarily
777
-
778
- ```bash
779
- # If you need to bypass commit hooks temporarily
780
- git commit --no-verify # Allowed for commits
781
-
782
- # Note: --no-verify is BLOCKED for git push
783
- # Push operations must pass all quality gates
784
- ```
785
-
786
- ---
787
-
788
- ## Project Templates
789
-
790
- CAWS includes templates for common project types.
791
-
792
- ### VS Code Extension
793
-
794
- ```bash
795
- caws init my-extension --template=extension
796
- ```
797
-
798
- **Optimized for:**
799
-
800
- - Risk tier: 2 (high user impact)
801
- - Webview security (CSP enforcement)
802
- - Activation performance (<1s)
803
- - Budget: 25 files, 1000 lines
804
-
805
- ### React Library
806
-
807
- ```bash
808
- caws init my-lib --template=library
809
- ```
810
-
811
- **Optimized for:**
812
-
813
- - Risk tier: 2 (API stability)
814
- - Bundle size limits
815
- - Tree-shakeable exports
816
- - Budget: 20 files, 800 lines
817
-
818
- ### API Service
819
-
820
- ```bash
821
- caws init my-api --template=api
822
- ```
823
-
824
- **Optimized for:**
825
-
826
- - Risk tier: 1 (data integrity)
827
- - Backward compatibility
828
- - Performance budgets
829
- - Budget: 40 files, 1500 lines
830
-
831
- ### CLI Tool
832
-
833
- ```bash
834
- caws init my-cli --template=cli
835
- ```
836
-
837
- **Optimized for:**
838
-
839
- - Risk tier: 3 (low risk)
840
- - Error handling
841
- - Help text and UX
842
- - Budget: 15 files, 600 lines
843
-
844
- ---
845
-
846
- ## Advanced Topics
847
-
848
- ### Codemods for Refactoring
849
-
850
- When refactoring, use codemods instead of manual edits:
851
-
852
- ```bash
853
- # Install jscodeshift
854
- npm install -g jscodeshift
855
-
856
- # Create codemod
857
- vim codemod/rename-function.ts
858
-
859
- # Dry run to preview changes
860
- jscodeshift -d -t codemod/rename-function.ts src/
861
-
862
- # Apply transformation
863
- jscodeshift -t codemod/rename-function.ts src/
864
-
865
- # Verify tests pass
866
- npm test
867
- ```
868
-
869
- **Example codemod:**
870
-
871
- ```typescript
872
- // codemod/rename-function.ts
873
- export default function transformer(file, api) {
874
- const j = api.jscodeshift;
875
- const root = j(file.source);
876
-
877
- // Find all calls to oldFunction
878
- root
879
- .find(j.CallExpression, {
880
- callee: { name: 'oldFunction' },
881
- })
882
- .forEach((path) => {
883
- // Rename to newFunction
884
- path.value.callee.name = 'newFunction';
885
- });
886
-
887
- return root.toSource();
888
- }
889
- ```
890
-
891
- ### Feature Flags
892
-
893
- For gradual rollouts, use feature flags:
894
-
895
- ```typescript
896
- // Define flags
897
- const flags = {
898
- newAuthFlow: process.env.FEATURE_NEW_AUTH === 'true',
899
- };
900
-
901
- // Use in code
902
- if (flags.newAuthFlow) {
903
- return handleAuthV2(credentials);
904
- } else {
905
- return handleAuthV1(credentials);
906
- }
907
- ```
908
-
909
- ### Performance Budgets
910
-
911
- Set budgets in working spec:
912
-
913
- ```yaml
914
- non_functional:
915
- perf:
916
- api_p95_ms: 250 # API latency budget
917
- lcp_ms: 2500 # Largest Contentful Paint
918
- tti_ms: 3500 # Time to Interactive
919
- bundle_kb: 50 # JavaScript bundle size
920
- ```
921
-
922
- **Enforce in CI:**
923
-
924
- ```bash
925
- # Lighthouse CI
926
- npm run lighthouse:ci
927
-
928
- # Bundle size check
929
- npm run build
930
- du -k dist/main.js | awk '{if ($1 > 50) exit 1}'
931
- ```
932
-
933
- ---
934
-
935
- ## FAQ for Agents
936
-
937
- ### Q: Can I skip writing tests if the change is small?
938
-
939
- **A: No.** Tests are required regardless of change size. Even a one-line fix needs:
940
-
941
- 1. A failing test that reproduces the bug
942
- 2. The fix
943
- 3. The passing test
944
-
945
- ### Q: Can I create `enhanced-foo.ts` alongside `foo.ts` for refactoring?
946
-
947
- **A: No.** Shadow files are forbidden. Instead:
948
-
949
- 1. Edit `foo.ts` in place
950
- 2. Or create a codemod to transform `foo.ts`
951
- 3. Or refactor with a different canonical name
952
-
953
- ### Q: What if the working spec doesn't exist?
954
-
955
- **A: Create one.** Before any implementation:
956
-
957
- 1. Create `.caws/working-spec.yaml`
958
- 2. Fill in all required fields
959
- 3. Run `caws validate --suggestions`
960
- 4. Request human approval
961
- 5. Then implement
962
-
963
- ### Q: Can I exceed the change budget if the task requires it?
964
-
965
- **A: Split the task.** If you need more than `max_files` or `max_loc`:
966
-
967
- 1. Break into multiple smaller PRs
968
- 2. Each with its own working spec
969
- 3. Each staying within budget
970
-
971
- Only increase budget with human approval and strong justification.
972
-
973
- ### Q: What if lints fail but I think they're wrong?
974
-
975
- **A: Fix the lints.** You can use `git commit --no-verify` to commit temporarily, but you cannot push without fixing. If the lint rule is incorrect:
976
-
977
- 1. Fix the code to satisfy the lint
978
- 2. Or request human discussion of the lint rule
979
- 3. Human can update lint config if appropriate
980
- 4. Note: `git push --no-verify` is BLOCKED
981
-
982
- ### Q: Can I commit without updating provenance?
983
-
984
- **A: Hooks do it automatically.** If hooks are installed, provenance updates on every commit. If hooks aren't installed:
985
-
986
- 1. Install them: `caws hooks install`
987
- 2. Or manually update: `caws provenance update`
988
-
989
- ---
990
-
991
- ## Additional Resources
992
-
993
- ### Documentation
994
-
995
- - **Complete Guide**: `docs/agents/full-guide.md` - Comprehensive CAWS reference
996
- - **Tutorial**: `docs/agents/tutorial.md` - Step-by-step learning path
997
- - **Examples**: `docs/agents/examples.md` - Real-world project examples
998
-
999
- ### Project-Specific
1000
-
1001
- - **Getting Started**: `.caws/GETTING_STARTED.md` - Generated per project
1002
- - **Templates**: `.caws/templates/` - Feature plans, test plans, PR templates
1003
- - **Examples**: `.caws/examples/` - Working spec examples
1004
-
1005
- ### Cursor Rules
1006
-
1007
- - **Rules Directory**: `.cursor/rules/` - Modular MDC rule files
1008
- - **Rules README**: `.cursor/rules/README.md` - Rule system documentation
1009
-
1010
- ---
1011
-
1012
- ## Summary Checklist
1013
-
1014
- Before starting any work:
1015
-
1016
- - [ ] Working spec exists and validates
1017
- - [ ] Risk tier is appropriate
1018
- - [ ] Acceptance criteria are clear
1019
- - [ ] Scope boundaries are defined
1020
- - [ ] Test plan is documented
1021
-
1022
- During implementation:
1023
-
1024
- - [ ] Write tests first (TDD)
1025
- - [ ] Stay within scope.in boundaries
1026
- - [ ] Keep under change budget
1027
- - [ ] Use guard clauses and safe defaults
1028
- - [ ] Inject dependencies for testability
1029
- - [ ] No shadow files (no enhanced-_, new-_, v2-\*)
1030
-
1031
- Before submitting PR:
1032
-
1033
- - [ ] All tests pass: `npm test`
1034
- - [ ] Coverage meets tier requirements
1035
- - [ ] Mutation score meets tier requirements
1036
- - [ ] Lints pass: `npm run lint`
1037
- - [ ] Types check: `npm run typecheck`
1038
- - [ ] Contracts validate (if applicable)
1039
- - [ ] Performance budgets met
1040
- - [ ] No secret scan violations
1041
- - [ ] Provenance updated
1042
-
1043
- **Questions?** Check the full guide or ask your human collaborator.
1044
-
1045
- ---
1046
-
1047
- _This guide is your companion for CAWS-driven development. Bookmark it, reference it often, and use it to deliver high-quality, well-tested, explainable code._