@paths.design/caws-cli 3.3.0 → 3.4.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 (38) hide show
  1. package/dist/commands/diagnose.d.ts.map +1 -1
  2. package/dist/commands/diagnose.js +39 -4
  3. package/dist/commands/evaluate.d.ts +8 -0
  4. package/dist/commands/evaluate.d.ts.map +1 -0
  5. package/dist/commands/evaluate.js +288 -0
  6. package/dist/commands/iterate.d.ts +8 -0
  7. package/dist/commands/iterate.d.ts.map +1 -0
  8. package/dist/commands/iterate.js +341 -0
  9. package/dist/commands/quality-monitor.d.ts +17 -0
  10. package/dist/commands/quality-monitor.d.ts.map +1 -0
  11. package/dist/commands/quality-monitor.js +265 -0
  12. package/dist/commands/status.d.ts +6 -1
  13. package/dist/commands/status.d.ts.map +1 -1
  14. package/dist/commands/status.js +120 -20
  15. package/dist/commands/troubleshoot.d.ts +8 -0
  16. package/dist/commands/troubleshoot.d.ts.map +1 -0
  17. package/dist/commands/troubleshoot.js +104 -0
  18. package/dist/commands/waivers.d.ts +8 -0
  19. package/dist/commands/waivers.d.ts.map +1 -0
  20. package/dist/commands/waivers.js +293 -0
  21. package/dist/commands/workflow.d.ts +85 -0
  22. package/dist/commands/workflow.d.ts.map +1 -0
  23. package/dist/commands/workflow.js +243 -0
  24. package/dist/error-handler.d.ts +91 -2
  25. package/dist/error-handler.d.ts.map +1 -1
  26. package/dist/error-handler.js +362 -16
  27. package/dist/index.js +95 -0
  28. package/dist/scaffold/index.d.ts.map +1 -1
  29. package/dist/scaffold/index.js +13 -0
  30. package/dist/utils/typescript-detector.d.ts +31 -0
  31. package/dist/utils/typescript-detector.d.ts.map +1 -1
  32. package/dist/utils/typescript-detector.js +245 -7
  33. package/package.json +5 -4
  34. package/templates/OIDC_SETUP.md +300 -0
  35. package/templates/agents.md +912 -686
  36. package/templates/apps/tools/caws/gates.ts +34 -0
  37. package/templates/apps/tools/caws/shared/gate-checker.ts +265 -13
  38. package/templates/apps/tools/caws/templates/working-spec.template.yml +14 -0
@@ -87,6 +87,16 @@ class GatesCLI {
87
87
  if (result.errors && result.errors.length > 0) {
88
88
  result.errors.forEach((error) => console.error(` - ${error}`));
89
89
  }
90
+ if (result.details?.searched_paths) {
91
+ console.error(` Searched paths: ${result.details.searched_paths.join(', ')}`);
92
+ }
93
+ if (result.details?.run_command) {
94
+ console.error(` Run: ${result.details.run_command}`);
95
+ }
96
+ if (result.details?.waiver_available) {
97
+ console.error(` 💡 ${result.details.waiver_suggestion}`);
98
+ console.error(` ${result.details.waiver_command}`);
99
+ }
90
100
  return false;
91
101
  }
92
102
  } catch (error) {
@@ -118,6 +128,18 @@ class GatesCLI {
118
128
  if (result.errors && result.errors.length > 0) {
119
129
  result.errors.forEach((error) => console.error(` - ${error}`));
120
130
  }
131
+ if (result.details?.searched_paths) {
132
+ console.error(` Searched paths: ${result.details.searched_paths.join(', ')}`);
133
+ }
134
+ if (result.details?.run_command) {
135
+ console.error(` Run: ${result.details.run_command}`);
136
+ }
137
+ if (result.details?.waiver_available) {
138
+ console.error(` 💡 ${result.details.waiver_suggestion}`);
139
+ console.error(
140
+ ` caws waivers create --title="Mutation waiver" --reason=emergency_hotfix --gates=mutation`
141
+ );
142
+ }
121
143
  return false;
122
144
  }
123
145
  } catch (error) {
@@ -144,6 +166,18 @@ class GatesCLI {
144
166
  if (result.errors && result.errors.length > 0) {
145
167
  result.errors.forEach((error) => console.error(` - ${error}`));
146
168
  }
169
+ if (result.details?.searched_paths) {
170
+ console.error(` Searched paths: ${result.details.searched_paths.join(', ')}`);
171
+ }
172
+ if (result.details?.example_command) {
173
+ console.error(` Example: ${result.details.example_command}`);
174
+ }
175
+ console.error(
176
+ ` 💡 If contracts are not required for this tier, consider creating a waiver`
177
+ );
178
+ console.error(
179
+ ` caws waivers create --title="Contract waiver" --reason=experimental_feature --gates=contracts`
180
+ );
147
181
  return false;
148
182
  }
149
183
  } catch (error) {
@@ -60,6 +60,146 @@ export class CawsGateChecker extends CawsBaseTool {
60
60
  }
61
61
  }
62
62
 
63
+ /**
64
+ * Auto-detect the correct working directory for coverage/mutation reports in monorepos
65
+ */
66
+ private findReportDirectory(startPath: string = this.getWorkingDirectory()): string {
67
+ // Priority 1: Check if the current directory has the reports or test results
68
+ if (
69
+ this.hasCoverageReports(startPath) ||
70
+ this.hasMutationReports(startPath) ||
71
+ this.hasTestResults(startPath)
72
+ ) {
73
+ return startPath;
74
+ }
75
+
76
+ // Priority 2: Check for npm workspaces configuration
77
+ const packageJsonPath = path.join(startPath, 'package.json');
78
+ if (this.pathExists(packageJsonPath)) {
79
+ try {
80
+ const packageJson = this.readJsonFile<any>(packageJsonPath);
81
+ if (packageJson?.workspaces) {
82
+ const workspaces = packageJson.workspaces;
83
+
84
+ // Handle workspace patterns (e.g., ["packages/*", "iterations/*"])
85
+ for (const wsPattern of workspaces) {
86
+ if (wsPattern.includes('*')) {
87
+ const baseDir = wsPattern.split('*')[0];
88
+ const fullBaseDir = path.join(startPath, baseDir);
89
+
90
+ if (this.pathExists(fullBaseDir)) {
91
+ const entries = fs.readdirSync(fullBaseDir, { withFileTypes: true });
92
+ for (const entry of entries) {
93
+ if (entry.isDirectory()) {
94
+ const wsPath = path.join(fullBaseDir, entry.name);
95
+ if (
96
+ this.hasCoverageReports(wsPath) ||
97
+ this.hasMutationReports(wsPath) ||
98
+ this.hasTestResults(wsPath)
99
+ ) {
100
+ return wsPath;
101
+ }
102
+ }
103
+ }
104
+ }
105
+ } else {
106
+ // Direct workspace path
107
+ const wsPath = path.join(startPath, wsPattern);
108
+ if (
109
+ this.hasCoverageReports(wsPath) ||
110
+ this.hasMutationReports(wsPath) ||
111
+ this.hasTestResults(wsPath)
112
+ ) {
113
+ return wsPath;
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ // Priority 3: If no reports found in workspaces, look for workspaces with test scripts
120
+ if (packageJson?.workspaces) {
121
+ for (const wsPattern of workspaces) {
122
+ if (wsPattern.includes('*')) {
123
+ const baseDir = wsPattern.split('*')[0];
124
+ const fullBaseDir = path.join(startPath, baseDir);
125
+
126
+ if (this.pathExists(fullBaseDir)) {
127
+ const entries = fs.readdirSync(fullBaseDir, { withFileTypes: true });
128
+ for (const entry of entries) {
129
+ if (entry.isDirectory()) {
130
+ const wsPath = path.join(fullBaseDir, entry.name);
131
+ if (this.hasTestScript(wsPath)) {
132
+ // Found a workspace with tests, prefer this even without reports
133
+ return wsPath;
134
+ }
135
+ }
136
+ }
137
+ }
138
+ } else {
139
+ const wsPath = path.join(startPath, wsPattern);
140
+ if (this.hasTestScript(wsPath)) {
141
+ return wsPath;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ } catch (error) {
147
+ // Ignore workspace parsing errors
148
+ }
149
+ }
150
+
151
+ // Fall back to original working directory
152
+ return startPath;
153
+ }
154
+
155
+ /**
156
+ * Check if a directory has coverage reports
157
+ */
158
+ private hasCoverageReports(dirPath: string): boolean {
159
+ const coveragePath = path.join(dirPath, 'coverage', 'coverage-final.json');
160
+ return this.pathExists(coveragePath);
161
+ }
162
+
163
+ /**
164
+ * Check if a directory has mutation reports
165
+ */
166
+ private hasMutationReports(dirPath: string): boolean {
167
+ const mutationPath = path.join(dirPath, 'reports', 'mutation', 'mutation.json');
168
+ return this.pathExists(mutationPath);
169
+ }
170
+
171
+ /**
172
+ * Check if a directory has test results
173
+ */
174
+ private hasTestResults(dirPath: string): boolean {
175
+ const testResultsPath = path.join(dirPath, 'test-results');
176
+ if (this.pathExists(testResultsPath)) {
177
+ try {
178
+ const entries = fs.readdirSync(testResultsPath);
179
+ return entries.some((entry) => entry.endsWith('.json') || entry.endsWith('.xml'));
180
+ } catch (error) {
181
+ // Ignore read errors
182
+ }
183
+ }
184
+ return false;
185
+ }
186
+
187
+ /**
188
+ * Check if a directory has a package.json with test scripts
189
+ */
190
+ private hasTestScript(dirPath: string): boolean {
191
+ const packageJsonPath = path.join(dirPath, 'package.json');
192
+ if (this.pathExists(packageJsonPath)) {
193
+ try {
194
+ const packageJson = this.readJsonFile<any>(packageJsonPath);
195
+ return !!packageJson?.scripts?.test;
196
+ } catch (error) {
197
+ // Ignore parse errors
198
+ }
199
+ }
200
+ return false;
201
+ }
202
+
63
203
  /**
64
204
  * Check if a waiver applies to the given gate
65
205
  */
@@ -223,10 +363,11 @@ export class CawsGateChecker extends CawsBaseTool {
223
363
  };
224
364
  }
225
365
 
226
- const coveragePath = path.join(
227
- options.workingDirectory || this.getWorkingDirectory(),
228
- 'coverage/coverage-final.json'
366
+ // Auto-detect the correct directory for coverage reports
367
+ const reportDir = this.findReportDirectory(
368
+ options.workingDirectory || this.getWorkingDirectory()
229
369
  );
370
+ const coveragePath = path.join(reportDir, 'coverage', 'coverage-final.json');
230
371
 
231
372
  if (!this.pathExists(coveragePath)) {
232
373
  return {
@@ -234,8 +375,55 @@ export class CawsGateChecker extends CawsBaseTool {
234
375
  score: 0,
235
376
  details: {
236
377
  error: 'Coverage report not found. Run tests with coverage first.',
378
+ searched_paths: [
379
+ path.join(reportDir, 'coverage', 'coverage-final.json'),
380
+ path.join(this.getWorkingDirectory(), 'coverage', 'coverage-final.json'),
381
+ ],
382
+ expected_format: 'Istanbul coverage format (coverage-final.json)',
383
+ expected_schema: {
384
+ description: 'JSON object with coverage data by file',
385
+ example: {
386
+ '/path/to/file.js': {
387
+ statementMap: {
388
+ /* ... */
389
+ },
390
+ fnMap: {
391
+ /* ... */
392
+ },
393
+ branchMap: {
394
+ /* ... */
395
+ },
396
+ s: {
397
+ /* hit counts */
398
+ },
399
+ f: {
400
+ /* function hits */
401
+ },
402
+ b: {
403
+ /* branch hits */
404
+ },
405
+ },
406
+ },
407
+ },
408
+ run_command: 'npm test -- --coverage --coverageReporters=json',
409
+ alternative_commands: [
410
+ 'npm run test:coverage',
411
+ 'jest --coverage --coverageReporters=json',
412
+ 'vitest run --coverage',
413
+ ],
414
+ workspace_hint:
415
+ reportDir !== this.getWorkingDirectory()
416
+ ? `Auto-detected workspace: ${path.relative(this.getWorkingDirectory(), reportDir)}`
417
+ : 'Run from workspace directory if using monorepo',
418
+ waiver_available: true,
419
+ waiver_suggestion:
420
+ 'If this is an exceptional case, consider creating a coverage waiver',
421
+ waiver_command:
422
+ 'caws waivers create --title="Coverage waiver" --reason=emergency_hotfix --gates=coverage',
237
423
  },
238
- errors: ['Coverage report not found'],
424
+ errors: [
425
+ `Coverage report not found at ${path.relative(this.getWorkingDirectory(), coveragePath)}`,
426
+ ],
239
427
  };
240
428
  }
241
429
 
@@ -356,10 +544,11 @@ export class CawsGateChecker extends CawsBaseTool {
356
544
  };
357
545
  }
358
546
 
359
- const mutationPath = path.join(
360
- options.workingDirectory || this.getWorkingDirectory(),
361
- 'reports/mutation/mutation.json'
547
+ // Auto-detect the correct directory for mutation reports
548
+ const reportDir = this.findReportDirectory(
549
+ options.workingDirectory || this.getWorkingDirectory()
362
550
  );
551
+ const mutationPath = path.join(reportDir, 'reports', 'mutation', 'mutation.json');
363
552
 
364
553
  if (!this.pathExists(mutationPath)) {
365
554
  return {
@@ -367,8 +556,49 @@ export class CawsGateChecker extends CawsBaseTool {
367
556
  score: 0,
368
557
  details: {
369
558
  error: 'Mutation report not found. Run mutation tests first.',
559
+ searched_paths: [
560
+ path.join(reportDir, 'reports', 'mutation', 'mutation.json'),
561
+ path.join(this.getWorkingDirectory(), 'reports', 'mutation', 'mutation.json'),
562
+ ],
563
+ expected_format: 'Stryker mutation testing JSON report',
564
+ expected_schema: {
565
+ description: 'JSON object with mutation testing results',
566
+ example: {
567
+ files: {
568
+ /* file-specific results */
569
+ },
570
+ testFiles: {
571
+ /* test file results */
572
+ },
573
+ mutants: [
574
+ {
575
+ /* mutant details */
576
+ },
577
+ ],
578
+ metrics: {
579
+ killed: 85,
580
+ survived: 5,
581
+ timeout: 2,
582
+ totalDetected: 92,
583
+ totalUndetected: 0,
584
+ totalValid: 92,
585
+ },
586
+ },
587
+ },
588
+ run_command: 'npx stryker run',
589
+ alternative_commands: [
590
+ 'npm run test:mutation',
591
+ 'npx stryker run --configFile stryker.conf.json',
592
+ 'yarn mutation:test',
593
+ ],
594
+ workspace_hint:
595
+ reportDir !== this.getWorkingDirectory()
596
+ ? `Auto-detected workspace: ${path.relative(this.getWorkingDirectory(), reportDir)}`
597
+ : 'Run from workspace directory if using monorepo',
370
598
  },
371
- errors: ['Mutation report not found'],
599
+ errors: [
600
+ `Mutation report not found at ${path.relative(this.getWorkingDirectory(), mutationPath)}`,
601
+ ],
372
602
  };
373
603
  }
374
604
 
@@ -439,17 +669,39 @@ export class CawsGateChecker extends CawsBaseTool {
439
669
  };
440
670
  }
441
671
 
442
- const contractResultsPath = path.join(
443
- options.workingDirectory || this.getWorkingDirectory(),
444
- 'test-results/contract-results.json'
672
+ // Auto-detect the correct directory for contract test results
673
+ const reportDir = this.findReportDirectory(
674
+ options.workingDirectory || this.getWorkingDirectory()
445
675
  );
676
+ const contractResultsPath = path.join(reportDir, 'test-results', 'contract-results.json');
446
677
 
447
678
  if (!this.pathExists(contractResultsPath)) {
448
679
  return {
449
680
  passed: false,
450
681
  score: 0,
451
- details: { error: 'Contract test results not found' },
452
- errors: ['Contract tests not run or results not found'],
682
+ details: {
683
+ error: 'Contract test results not found',
684
+ searched_paths: [
685
+ path.join(reportDir, 'test-results', 'contract-results.json'),
686
+ path.join(this.getWorkingDirectory(), 'test-results', 'contract-results.json'),
687
+ path.join(reportDir, '.caws', 'contract-results.json'),
688
+ path.join(this.getWorkingDirectory(), '.caws', 'contract-results.json'),
689
+ ],
690
+ expected_format:
691
+ 'JSON with { tests: [], passed: boolean, numPassed: number, numTotal: number }',
692
+ example_command:
693
+ 'npm run test:contract -- --json --outputFile=test-results/contract-results.json',
694
+ },
695
+ errors: [
696
+ `Contract test results not found. Searched in: ${[
697
+ path.relative(
698
+ this.getWorkingDirectory(),
699
+ path.join(reportDir, 'test-results', 'contract-results.json')
700
+ ),
701
+ 'test-results/contract-results.json',
702
+ '.caws/contract-results.json',
703
+ ].join(', ')}`,
704
+ ],
453
705
  };
454
706
  }
455
707
 
@@ -15,10 +15,24 @@ acceptance:
15
15
  given: '{{GIVEN_CONDITION}}'
16
16
  when: '{{WHEN_ACTION}}'
17
17
  then: '{{THEN_OUTCOME}}'
18
+ status: pending # pending | in_progress | completed
19
+ # Optional: detailed progress tracking
20
+ # tests:
21
+ # written: 0
22
+ # passing: 0
23
+ # coverage: 0.0
24
+ # last_updated: '2025-10-09T14:30:00Z'
18
25
  - id: A2
19
26
  given: '{{GIVEN_CONDITION_2}}'
20
27
  when: '{{WHEN_ACTION_2}}'
21
28
  then: '{{THEN_OUTCOME_2}}'
29
+ status: pending # pending | in_progress | completed
30
+ # Optional: detailed progress tracking
31
+ # tests:
32
+ # written: 0
33
+ # passing: 0
34
+ # coverage: 0.0
35
+ # last_updated: '2025-10-09T14:30:00Z'
22
36
  non_functional:
23
37
  a11y:
24
38
  - '{{ACCESSIBILITY_REQUIREMENT}}'