@paths.design/caws-cli 3.3.1 → 3.5.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 (43) 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/git-hooks.d.ts.map +1 -1
  29. package/dist/scaffold/git-hooks.js +27 -6
  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 +2 -1
  34. package/templates/agents.md +6 -5
  35. package/templates/apps/tools/caws/gates.ts +34 -0
  36. package/templates/apps/tools/caws/shared/gate-checker.ts +265 -13
  37. package/templates/apps/tools/caws/templates/working-spec.template.yml +14 -0
  38. package/dist/index-new.d.ts +0 -5
  39. package/dist/index-new.d.ts.map +0 -1
  40. package/dist/index-new.js +0 -317
  41. package/dist/index.js.backup +0 -4711
  42. package/templates/apps/tools/caws/prompt-lint.js.backup +0 -274
  43. package/templates/apps/tools/caws/provenance.js.backup +0 -73
@@ -0,0 +1,243 @@
1
+ /**
2
+ * CAWS Workflow Command
3
+ *
4
+ * Provides workflow-specific guidance for development tasks.
5
+ * Supports TDD, refactor, and feature development workflows.
6
+ *
7
+ * @author @darianrosebrook
8
+ */
9
+
10
+ const chalk = require('chalk');
11
+
12
+ /**
13
+ * Workflow templates with steps and guidance
14
+ */
15
+ const WORKFLOW_TEMPLATES = {
16
+ tdd: {
17
+ name: 'Test-Driven Development',
18
+ steps: [
19
+ 'Define requirements and acceptance criteria',
20
+ 'Write failing test',
21
+ 'Implement minimal code to pass test',
22
+ 'Run CAWS validation',
23
+ 'Refactor while maintaining tests',
24
+ 'Repeat for next requirement',
25
+ ],
26
+ guidance: {
27
+ 1: 'Start by clearly defining what the code should do. Use CAWS working spec to document requirements.',
28
+ 2: 'Write a test that captures the desired behavior but will initially fail.',
29
+ 3: 'Implement only the minimal code needed to make the test pass.',
30
+ 4: 'Run CAWS evaluation to ensure quality standards are maintained.',
31
+ 5: 'Improve code structure while keeping all tests passing.',
32
+ 6: 'Move to the next requirement and repeat the cycle.',
33
+ },
34
+ recommendations: {
35
+ 1: ['caws evaluate --feedback-only', 'Ensure spec completeness'],
36
+ 2: ['Write failing test first', 'caws validate for basic checks'],
37
+ 3: ['Implement minimal solution', 'Run tests to verify'],
38
+ 4: ['caws evaluate', 'Address any quality issues'],
39
+ 5: ['Refactor safely', 'Re-run CAWS validation'],
40
+ 6: ['caws iterate for next steps', 'Continue TDD cycle'],
41
+ },
42
+ },
43
+ refactor: {
44
+ name: 'Refactoring Workflow',
45
+ steps: [
46
+ 'Establish baseline quality metrics',
47
+ 'Apply refactoring changes',
48
+ 'Run comprehensive validation',
49
+ 'Address any quality gate failures',
50
+ 'Document changes and rationale',
51
+ ],
52
+ guidance: {
53
+ 1: 'Run CAWS evaluation to establish current quality baseline.',
54
+ 2: 'Make your refactoring changes incrementally.',
55
+ 3: 'Run full CAWS validation to ensure no quality degradation.',
56
+ 4: 'Address any failing quality gates with waivers if necessary.',
57
+ 5: 'Update documentation and provenance records.',
58
+ },
59
+ recommendations: {
60
+ 1: ['caws evaluate', 'Establish quality baseline'],
61
+ 2: ['Apply changes incrementally', 'caws validate frequently'],
62
+ 3: ['caws evaluate', 'Full quality assessment'],
63
+ 4: ['Create waivers if needed', 'Document rationale'],
64
+ 5: ['Update provenance', 'caws provenance update'],
65
+ },
66
+ },
67
+ feature: {
68
+ name: 'Feature Development',
69
+ steps: [
70
+ 'Create working specification',
71
+ 'Design and plan implementation',
72
+ 'Implement core functionality',
73
+ 'Add comprehensive testing',
74
+ 'Run full quality validation',
75
+ 'Prepare for integration',
76
+ ],
77
+ guidance: {
78
+ 1: 'Define clear requirements, acceptance criteria, and risk assessment.',
79
+ 2: 'Break down the feature into manageable tasks.',
80
+ 3: 'Implement core functionality with error handling.',
81
+ 4: 'Add unit, integration, and contract tests.',
82
+ 5: 'Run complete CAWS validation and address issues.',
83
+ 6: 'Ensure documentation and provenance are complete.',
84
+ },
85
+ recommendations: {
86
+ 1: ['caws init --interactive', 'Create comprehensive spec'],
87
+ 2: ['caws iterate', 'Get implementation guidance'],
88
+ 3: ['caws evaluate', 'Validate progress'],
89
+ 4: ['Add comprehensive tests', 'Run test suite'],
90
+ 5: ['caws validate', 'Final quality gates'],
91
+ 6: ['caws provenance update', 'Prepare for integration'],
92
+ },
93
+ },
94
+ };
95
+
96
+ /**
97
+ * Generate workflow guidance
98
+ *
99
+ * @param {string} workflowType - Type of workflow (tdd, refactor, feature)
100
+ * @param {number} currentStep - Current step number (1-based)
101
+ * @param {object} context - Optional context information
102
+ * @returns {object} Workflow guidance
103
+ */
104
+ function generateWorkflowGuidance(workflowType, currentStep, context = {}) {
105
+ const template = WORKFLOW_TEMPLATES[workflowType];
106
+
107
+ if (!template) {
108
+ return {
109
+ error: `Unknown workflow type: ${workflowType}`,
110
+ available_types: Object.keys(WORKFLOW_TEMPLATES),
111
+ };
112
+ }
113
+
114
+ const step = parseInt(currentStep, 10);
115
+ if (isNaN(step) || step < 1 || step > template.steps.length) {
116
+ return {
117
+ error: `Invalid step number: ${currentStep}. Must be between 1 and ${template.steps.length}`,
118
+ total_steps: template.steps.length,
119
+ };
120
+ }
121
+
122
+ const currentGuidance = template.guidance[step] || 'Continue with the next logical step.';
123
+ const nextStep = step < template.steps.length ? step + 1 : null;
124
+
125
+ return {
126
+ workflow_type: workflowType,
127
+ workflow_name: template.name,
128
+ current_step: step,
129
+ total_steps: template.steps.length,
130
+ step_description: template.steps[step - 1] || 'Unknown step',
131
+ guidance: currentGuidance,
132
+ next_step: nextStep,
133
+ next_step_description: nextStep ? template.steps[nextStep - 1] : null,
134
+ all_steps: template.steps,
135
+ caws_recommendations: template.recommendations[step] || ['caws evaluate'],
136
+ context: context.description || null,
137
+ };
138
+ }
139
+
140
+ /**
141
+ * Workflow command handler
142
+ *
143
+ * @param {string} workflowType - Type of workflow
144
+ * @param {object} options - Command options
145
+ */
146
+ async function workflowCommand(workflowType, options = {}) {
147
+ try {
148
+ const step = parseInt(options.step || '1', 10);
149
+ let context = {};
150
+
151
+ // Parse context if provided
152
+ if (options.currentState) {
153
+ try {
154
+ context =
155
+ typeof options.currentState === 'string'
156
+ ? JSON.parse(options.currentState)
157
+ : options.currentState;
158
+ } catch (e) {
159
+ console.warn(chalk.yellow('⚠️ Invalid context JSON, ignoring'));
160
+ }
161
+ }
162
+
163
+ // Generate guidance
164
+ const guidance = generateWorkflowGuidance(workflowType, step, context);
165
+
166
+ // Handle errors
167
+ if (guidance.error) {
168
+ console.error(chalk.red(`\n❌ ${guidance.error}`));
169
+ if (guidance.available_types) {
170
+ console.log(chalk.blue('\n💡 Available workflow types:'));
171
+ guidance.available_types.forEach((type) => {
172
+ console.log(chalk.blue(` • ${type}`));
173
+ });
174
+ }
175
+ if (guidance.total_steps) {
176
+ console.log(chalk.blue(`\n💡 Valid steps: 1-${guidance.total_steps}`));
177
+ }
178
+ process.exit(1);
179
+ }
180
+
181
+ // Display guidance
182
+ console.log(chalk.bold('\n🔄 CAWS Workflow Guidance\n'));
183
+ console.log('─'.repeat(60));
184
+ console.log(chalk.bold(`\nWorkflow: ${guidance.workflow_name} (${guidance.workflow_type})`));
185
+ console.log(
186
+ chalk.bold(
187
+ `Step ${guidance.current_step}/${guidance.total_steps}: ${guidance.step_description}`
188
+ )
189
+ );
190
+
191
+ if (guidance.context) {
192
+ console.log(chalk.gray(`\nContext: ${guidance.context}`));
193
+ }
194
+
195
+ console.log(chalk.bold('\n📋 Guidance:\n'));
196
+ console.log(` ${guidance.guidance}`);
197
+
198
+ console.log(chalk.bold('\n✅ CAWS Recommendations:\n'));
199
+ guidance.caws_recommendations.forEach((rec) => {
200
+ console.log(chalk.blue(` • ${rec}`));
201
+ });
202
+
203
+ // Show next step if available
204
+ if (guidance.next_step) {
205
+ console.log(chalk.bold('\n⏭️ Next Step:\n'));
206
+ console.log(chalk.gray(` Step ${guidance.next_step}: ${guidance.next_step_description}`));
207
+ console.log(
208
+ chalk.gray(`\n Run: caws workflow ${workflowType} --step ${guidance.next_step}`)
209
+ );
210
+ } else {
211
+ console.log(chalk.bold('\n🎉 Workflow Complete!\n'));
212
+ console.log(chalk.green(' All steps in this workflow have been completed.'));
213
+ console.log(chalk.blue('\n 💡 Run: caws evaluate to check final quality'));
214
+ }
215
+
216
+ // Show all steps for reference
217
+ console.log(chalk.bold('\n📊 All Steps:\n'));
218
+ guidance.all_steps.forEach((stepDesc, idx) => {
219
+ const stepNum = idx + 1;
220
+ const icon =
221
+ stepNum === guidance.current_step ? '▶️ ' : stepNum < guidance.current_step ? '✅ ' : '⬜ ';
222
+ const color =
223
+ stepNum === guidance.current_step
224
+ ? chalk.bold
225
+ : stepNum < guidance.current_step
226
+ ? chalk.green
227
+ : chalk.gray;
228
+ console.log(color(` ${icon}${stepNum}. ${stepDesc}`));
229
+ });
230
+
231
+ console.log('\n' + '─'.repeat(60) + '\n');
232
+ } catch (error) {
233
+ console.error(chalk.red(`\n❌ Workflow guidance failed: ${error.message}`));
234
+ console.error(chalk.gray(error.stack));
235
+ process.exit(1);
236
+ }
237
+ }
238
+
239
+ module.exports = {
240
+ workflowCommand,
241
+ generateWorkflowGuidance,
242
+ WORKFLOW_TEMPLATES,
243
+ };
@@ -5,6 +5,8 @@ export class CAWSError extends Error {
5
5
  constructor(message: any, category?: any, suggestions?: any[]);
6
6
  category: any;
7
7
  suggestions: any[];
8
+ timestamp: Date;
9
+ executionTime: any;
8
10
  }
9
11
  export namespace ERROR_CATEGORIES {
10
12
  let VALIDATION: string;
@@ -16,6 +18,17 @@ export namespace ERROR_CATEGORIES {
16
18
  let DEPENDENCY: string;
17
19
  let UNKNOWN: string;
18
20
  }
21
+ /**
22
+ * Execution timing utilities
23
+ */
24
+ export class ExecutionTimer {
25
+ startTime: bigint;
26
+ endTime: bigint;
27
+ start(): void;
28
+ end(): number;
29
+ getDuration(): number;
30
+ formatDuration(): string;
31
+ }
19
32
  /**
20
33
  * Get error category from error object or message
21
34
  * @param {Error|string} error - Error object or message
@@ -23,12 +36,21 @@ export namespace ERROR_CATEGORIES {
23
36
  */
24
37
  export function getErrorCategory(error: Error | string): string;
25
38
  /**
26
- * Wrap async operations with consistent error handling
39
+ * Wrap async operations with consistent error handling and timing
27
40
  * @param {Function} operation - Async operation to wrap
28
41
  * @param {string} context - Context for error messages
42
+ * @param {boolean} includeTiming - Whether to include timing in results
29
43
  * @returns {Promise<any>} Operation result or throws handled error
30
44
  */
31
- export function safeAsync(operation: Function, context?: string): Promise<any>;
45
+ export function safeAsync(operation: Function, context?: string, includeTiming?: boolean): Promise<any>;
46
+ /**
47
+ * Wrap sync operations with timing
48
+ * @param {Function} operation - Sync operation to wrap
49
+ * @param {string} context - Context for error messages
50
+ * @param {boolean} includeTiming - Whether to include timing in results
51
+ * @returns {any} Operation result or throws handled error
52
+ */
53
+ export function safeSync(operation: Function, context?: string, includeTiming?: boolean): any;
32
54
  /**
33
55
  * Handle CLI errors with consistent formatting and user guidance
34
56
  * @param {Error} error - Error to handle
@@ -72,4 +94,71 @@ export const COMMAND_SUGGESTIONS: {
72
94
  'template not found': () => string[];
73
95
  'not a caws project': () => string[];
74
96
  };
97
+ /**
98
+ * JSON output formatter for programmatic use
99
+ * @param {Object} data - Data to format as JSON
100
+ * @param {boolean} pretty - Whether to pretty-print (default: true)
101
+ */
102
+ export function formatJsonOutput(data: any, pretty?: boolean): string;
103
+ /**
104
+ * Check if user requested JSON output
105
+ * @returns {boolean} True if --json flag is present
106
+ */
107
+ export function isJsonOutput(): boolean;
108
+ /**
109
+ * Output data in appropriate format (JSON or human-readable)
110
+ * @param {Object} data - Data to output
111
+ * @param {boolean} success - Whether this is a success response
112
+ */
113
+ export function outputResult(data: any, success?: boolean): any;
114
+ /**
115
+ * Troubleshooting guide system
116
+ */
117
+ export const TROUBLESHOOTING_GUIDES: {
118
+ 'coverage-report-not-found': {
119
+ title: string;
120
+ symptoms: string[];
121
+ rootCauses: string[];
122
+ solutions: string[];
123
+ commands: string[];
124
+ };
125
+ 'mutation-report-not-found': {
126
+ title: string;
127
+ symptoms: string[];
128
+ rootCauses: string[];
129
+ solutions: string[];
130
+ commands: string[];
131
+ };
132
+ 'working-spec-validation': {
133
+ title: string;
134
+ symptoms: string[];
135
+ rootCauses: string[];
136
+ solutions: string[];
137
+ commands: string[];
138
+ };
139
+ 'monorepo-detection': {
140
+ title: string;
141
+ symptoms: string[];
142
+ rootCauses: string[];
143
+ solutions: string[];
144
+ commands: string[];
145
+ };
146
+ };
147
+ /**
148
+ * Get troubleshooting guide for a specific issue
149
+ * @param {string} issueKey - Key for the troubleshooting guide
150
+ * @returns {Object|null} Troubleshooting guide or null if not found
151
+ */
152
+ export function getTroubleshootingGuide(issueKey: string): any | null;
153
+ /**
154
+ * Get all available troubleshooting guides
155
+ * @returns {Object} All troubleshooting guides
156
+ */
157
+ export function getAllTroubleshootingGuides(): any;
158
+ /**
159
+ * Suggest troubleshooting guide based on error message
160
+ * @param {string} errorMessage - Error message to analyze
161
+ * @returns {string|null} Issue key if match found, null otherwise
162
+ */
163
+ export function suggestTroubleshootingGuide(errorMessage: string): string | null;
75
164
  //# sourceMappingURL=error-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../src/error-handler.js"],"names":[],"mappings":"AA0GA;;GAEG;AACH;IACE,+DAKC;IAFC,cAAqD;IACrD,mBAA2F;CAE9F;;;;;;;;;;;AA9ED;;;;GAIG;AACH,wCAHW,KAAK,GAAC,MAAM,GACV,MAAM,CA+DlB;AAcD;;;;;GAKG;AACH,yDAHW,MAAM,GACJ,OAAO,CAAC,GAAG,CAAC,CAexB;AA4ND;;;;;GAKG;AACH,sCAJW,KAAK,wBAEL,OAAO,QAsBjB;AAED;;;GAGG;AACH,2CAqBC;AAtJD;;;;;;GAMG;AACH,8CALW,KAAK,YACL,MAAM,kBAEJ,MAAM,EAAE,CAwDpB;AAED;;;;;GAKG;AACH,+CAJW,MAAM,kBAEJ,MAAM,CA4BlB;AAxJD;;;;;GAKG;AACH,0CAJW,MAAM,iBACN,MAAM,EAAE,GACN,MAAM,GAAC,IAAI,CAiBvB;AArFD;;GAEG;AACH;;;;;EA2DE"}
1
+ {"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../src/error-handler.js"],"names":[],"mappings":"AA0GA;;GAEG;AACH;IACE,+DAOC;IAJC,cAAqD;IACrD,mBAA2F;IAC3F,gBAA2B;IAC3B,mBAAyB;CAE5B;;;;;;;;;;;AAED;;GAEG;AACH;IAEI,kBAAqB;IACrB,gBAAmB;IAGrB,cAEC;IAED,cAGC;IAED,sBAIC;IAED,yBAMC;CACF;AAjHD;;;;GAIG;AACH,wCAHW,KAAK,GAAC,MAAM,GACV,MAAM,CA+DlB;AAiDD;;;;;;GAMG;AACH,yDAJW,MAAM,kBACN,OAAO,GACL,OAAO,CAAC,GAAG,CAAC,CA8BxB;AAED;;;;;;GAMG;AACH,wDAJW,MAAM,kBACN,OAAO,GACL,GAAG,CA8Bf;AAgSD;;;;;GAKG;AACH,sCAJW,KAAK,wBAEL,OAAO,QAmDjB;AA0JD;;;GAGG;AACH,2CAqBC;AAnXD;;;;;;GAMG;AACH,8CALW,KAAK,YACL,MAAM,kBAEJ,MAAM,EAAE,CAwDpB;AAED;;;;;GAKG;AACH,+CAJW,MAAM,kBAEJ,MAAM,CA4BlB;AAxJD;;;;;GAKG;AACH,0CAJW,MAAM,iBACN,MAAM,EAAE,GACN,MAAM,GAAC,IAAI,CAiBvB;AAjHD;;GAEG;AACH;;;;;EAuFE;AA4JF;;;;GAIG;AACH,qDAFW,OAAO,UAIjB;AAED;;;GAGG;AACH,gCAFa,OAAO,CAQnB;AAED;;;;GAIG;AACH,kDAFW,OAAO,OAcjB;AA2DD;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0GE;AAEF;;;;GAIG;AACH,kDAHW,MAAM,GACJ,MAAO,IAAI,CAIvB;AAED;;;GAGG;AACH,mDAEC;AAED;;;;GAIG;AACH,0DAHW,MAAM,GACJ,MAAM,GAAC,IAAI,CAmBvB"}