@paths.design/caws-cli 3.2.4 → 3.3.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.
package/dist/index.js CHANGED
@@ -23,6 +23,9 @@ const {
23
23
  initializeLanguageSupport,
24
24
  } = require('./config');
25
25
 
26
+ // Import error handling
27
+ const { handleCliError, findSimilarCommand } = require('./error-handler');
28
+
26
29
  // Import command handlers
27
30
  const { initProject } = require('./commands/init');
28
31
  const { validateCommand } = require('./commands/validate');
@@ -30,6 +33,9 @@ const { burnupCommand } = require('./commands/burnup');
30
33
  const { testAnalysisCommand } = require('./test-analysis');
31
34
  const { provenanceCommand } = require('./commands/provenance');
32
35
  const { executeTool } = require('./commands/tool');
36
+ const { statusCommand } = require('./commands/status');
37
+ const { templatesCommand } = require('./commands/templates');
38
+ const { diagnoseCommand } = require('./commands/diagnose');
33
39
 
34
40
  // Import scaffold functionality
35
41
  const { scaffoldProject, setScaffoldDependencies } = require('./scaffold');
@@ -72,7 +78,11 @@ setFinalizationDependencies({
72
78
  });
73
79
 
74
80
  // Setup CLI program
75
- program.name('caws').description('CAWS - Coding Agent Workflow System CLI').version(CLI_VERSION);
81
+ program
82
+ .name('caws')
83
+ .description('CAWS - Coding Agent Workflow System CLI')
84
+ .version(CLI_VERSION)
85
+ .showHelpAfterError(false); // We'll show better suggestions instead
76
86
 
77
87
  // Init command
78
88
  program
@@ -103,6 +113,27 @@ program
103
113
  .option('--auto-fix', 'Automatically fix safe validation issues', false)
104
114
  .action(validateCommand);
105
115
 
116
+ // Status command
117
+ program
118
+ .command('status')
119
+ .description('Show project health overview')
120
+ .option('-s, --spec <path>', 'Path to working spec file', '.caws/working-spec.yaml')
121
+ .action(statusCommand);
122
+
123
+ // Templates command
124
+ program
125
+ .command('templates [subcommand]')
126
+ .description('Discover and manage project templates')
127
+ .option('-n, --name <template>', 'Template name (for info subcommand)')
128
+ .action(templatesCommand);
129
+
130
+ // Diagnose command
131
+ program
132
+ .command('diagnose')
133
+ .description('Run health checks and suggest fixes')
134
+ .option('--fix', 'Apply automatic fixes', false)
135
+ .action(diagnoseCommand);
136
+
106
137
  // Tool command
107
138
  program
108
139
  .command('tool')
@@ -234,7 +265,14 @@ hooksCmd
234
265
  });
235
266
 
236
267
  // Error handling
268
+ // Custom error event handler for better messages
269
+ program.configureHelp({
270
+ // Override error display
271
+ showError: () => {}, // Suppress default error display
272
+ });
273
+
237
274
  program.exitOverride((err) => {
275
+ // Handle help and version requests gracefully
238
276
  if (
239
277
  err.code === 'commander.help' ||
240
278
  err.code === 'commander.version' ||
@@ -242,7 +280,74 @@ program.exitOverride((err) => {
242
280
  ) {
243
281
  process.exit(0);
244
282
  }
245
- console.error(chalk.red('❌ Error:'), err.message);
283
+
284
+ const commandName = process.argv[2];
285
+
286
+ // Check for unknown command
287
+ if (err.code === 'commander.unknownCommand') {
288
+ const validCommands = [
289
+ 'init',
290
+ 'validate',
291
+ 'scaffold',
292
+ 'status',
293
+ 'templates',
294
+ 'provenance',
295
+ 'hooks',
296
+ 'burnup',
297
+ 'tool',
298
+ ];
299
+ const similar = findSimilarCommand(commandName, validCommands);
300
+
301
+ console.error(chalk.red(`\n❌ Unknown command: ${commandName}`));
302
+
303
+ if (similar) {
304
+ console.error(chalk.yellow(`\n💡 Did you mean: caws ${similar}?`));
305
+ }
306
+
307
+ console.error(
308
+ chalk.yellow('💡 Available commands: init, validate, scaffold, provenance, hooks')
309
+ );
310
+ console.error(chalk.yellow('💡 Try: caws --help for full command list'));
311
+ console.error(
312
+ chalk.blue(
313
+ '\n📚 Documentation: https://github.com/Paths-Design/coding-agent-working-standard/blob/main/docs/api/cli.md'
314
+ )
315
+ );
316
+
317
+ process.exit(1);
318
+ }
319
+
320
+ // Check for unknown option
321
+ if (err.code === 'commander.unknownOption' || err.message.includes('unknown option')) {
322
+ const optionMatch = err.message.match(/unknown option ['"]([^'"]+)['"]/i);
323
+ const option = optionMatch ? optionMatch[1] : '';
324
+
325
+ console.error(chalk.red(`\n❌ Unknown option: ${option}`));
326
+ console.error(chalk.yellow(`\n💡 Try: caws ${commandName || ''} --help for available options`));
327
+
328
+ // Provide specific suggestions for common mistakes
329
+ if (option === '--suggestions' || option === '--suggest') {
330
+ console.error(chalk.yellow('💡 Note: Validation includes suggestions by default'));
331
+ console.error(chalk.yellow(' Just run: caws validate'));
332
+ }
333
+
334
+ console.error(
335
+ chalk.blue(
336
+ '\n📚 Documentation: https://github.com/Paths-Design/coding-agent-working-standard/blob/main/docs/api/cli.md'
337
+ )
338
+ );
339
+
340
+ process.exit(1);
341
+ }
342
+
343
+ // Generic Commander error
344
+ console.error(chalk.red('\n❌ Error:'), err.message);
345
+ console.error(chalk.yellow('\n💡 Try: caws --help for usage information'));
346
+ console.error(
347
+ chalk.blue(
348
+ '\n📚 Documentation: https://github.com/Paths-Design/coding-agent-working-standard/blob/main/docs/agents/full-guide.md'
349
+ )
350
+ );
246
351
  process.exit(1);
247
352
  });
248
353
 
@@ -251,16 +356,81 @@ if (require.main === module) {
251
356
  try {
252
357
  program.parse();
253
358
  } catch (error) {
359
+ // Handle help and version requests gracefully
254
360
  if (
255
361
  error.code === 'commander.help' ||
256
362
  error.code === 'commander.version' ||
257
363
  error.message.includes('outputHelp')
258
364
  ) {
259
365
  process.exit(0);
260
- } else {
261
- console.error(chalk.red('❌ Error:'), error.message);
366
+ }
367
+
368
+ // Enhanced error handling for Commander.js errors
369
+ const commandName = process.argv[2];
370
+ const context = {
371
+ command: commandName,
372
+ option: process.argv[3],
373
+ };
374
+
375
+ // Check for unknown command
376
+ if (error.code === 'commander.unknownCommand') {
377
+ const validCommands = [
378
+ 'init',
379
+ 'validate',
380
+ 'scaffold',
381
+ 'provenance',
382
+ 'hooks',
383
+ 'burnup',
384
+ 'tool',
385
+ ];
386
+ const similar = findSimilarCommand(commandName, validCommands);
387
+
388
+ console.error(chalk.red(`\n❌ Unknown command: ${commandName}`));
389
+
390
+ if (similar) {
391
+ console.error(chalk.yellow(`\n💡 Did you mean: caws ${similar}?`));
392
+ }
393
+
394
+ console.error(
395
+ chalk.yellow('💡 Available commands: init, validate, scaffold, provenance, hooks')
396
+ );
397
+ console.error(chalk.yellow('💡 Try: caws --help for full command list'));
398
+ console.error(
399
+ chalk.blue(
400
+ '\n📚 Documentation: https://github.com/Paths-Design/coding-agent-working-standard/blob/main/docs/api/cli.md'
401
+ )
402
+ );
403
+
262
404
  process.exit(1);
263
405
  }
406
+
407
+ // Check for unknown option
408
+ if (error.code === 'commander.unknownOption' || error.message.includes('unknown option')) {
409
+ const optionMatch = error.message.match(/unknown option ['"]([^'"]+)['"]/i);
410
+ const option = optionMatch ? optionMatch[1] : '';
411
+
412
+ console.error(chalk.red(`\n❌ Unknown option: ${option}`));
413
+ console.error(
414
+ chalk.yellow(`\n💡 Try: caws ${commandName || ''} --help for available options`)
415
+ );
416
+
417
+ // Provide specific suggestions for common mistakes
418
+ if (option === '--suggestions' || option === '--suggest') {
419
+ console.error(chalk.yellow('💡 Note: Validation includes suggestions by default'));
420
+ console.error(chalk.yellow(' Just run: caws validate'));
421
+ }
422
+
423
+ console.error(
424
+ chalk.blue(
425
+ '\n📚 Documentation: https://github.com/Paths-Design/coding-agent-working-standard/blob/main/docs/api/cli.md'
426
+ )
427
+ );
428
+
429
+ process.exit(1);
430
+ }
431
+
432
+ // Generic error with enhanced handling
433
+ handleCliError(error, context, true);
264
434
  }
265
435
  }
266
436
 
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Detect if project is using TypeScript
3
+ * @param {string} projectDir - Project directory path
4
+ * @returns {Object} TypeScript detection result
5
+ */
6
+ export function detectTypeScript(projectDir?: string): any;
7
+ /**
8
+ * Detect testing framework in use
9
+ * @param {string} projectDir - Project directory path
10
+ * @param {Object} packageJson - Parsed package.json (optional)
11
+ * @returns {Object} Testing framework detection result
12
+ */
13
+ export function detectTestFramework(projectDir?: string, packageJson?: any): any;
14
+ /**
15
+ * Check if TypeScript project needs test configuration
16
+ * @param {string} projectDir - Project directory path
17
+ * @returns {Object} Configuration status
18
+ */
19
+ export function checkTypeScriptTestConfig(projectDir?: string): any;
20
+ /**
21
+ * Generate configuration recommendations
22
+ * @param {Object} tsDetection - TypeScript detection result
23
+ * @param {Object} testDetection - Test framework detection result
24
+ * @returns {string[]} Array of recommendations
25
+ */
26
+ export function generateRecommendations(tsDetection: any, testDetection: any): string[];
27
+ /**
28
+ * Display TypeScript detection results
29
+ * @param {Object} detection - Detection result from checkTypeScriptTestConfig
30
+ */
31
+ export function displayTypeScriptDetection(detection: any): void;
32
+ //# sourceMappingURL=typescript-detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-detector.d.ts","sourceRoot":"","sources":["../../src/utils/typescript-detector.js"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,8CAHW,MAAM,OAkChB;AAED;;;;;GAKG;AACH,iDAJW,MAAM,0BAkDhB;AAED;;;;GAIG;AACH,uDAHW,MAAM,OAiBhB;AAED;;;;;GAKG;AACH,+EAFa,MAAM,EAAE,CAuBpB;AAED;;;GAGG;AACH,iEAoBC"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @fileoverview TypeScript Project Detection and Configuration
3
+ * Auto-detects TypeScript projects and configures testing frameworks
4
+ * @author @darianrosebrook
5
+ */
6
+
7
+ const fs = require('fs-extra');
8
+ const path = require('path');
9
+ const chalk = require('chalk');
10
+
11
+ /**
12
+ * Detect if project is using TypeScript
13
+ * @param {string} projectDir - Project directory path
14
+ * @returns {Object} TypeScript detection result
15
+ */
16
+ function detectTypeScript(projectDir = process.cwd()) {
17
+ const tsconfigPath = path.join(projectDir, 'tsconfig.json');
18
+ const packageJsonPath = path.join(projectDir, 'package.json');
19
+
20
+ const hasTsConfig = fs.existsSync(tsconfigPath);
21
+
22
+ let hasTypeScriptDep = false;
23
+ let packageJson = null;
24
+
25
+ if (fs.existsSync(packageJsonPath)) {
26
+ try {
27
+ packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
28
+ const allDeps = {
29
+ ...packageJson.dependencies,
30
+ ...packageJson.devDependencies,
31
+ };
32
+ hasTypeScriptDep = 'typescript' in allDeps;
33
+ } catch (error) {
34
+ // Ignore parse errors
35
+ }
36
+ }
37
+
38
+ const isTypeScript = hasTsConfig || hasTypeScriptDep;
39
+
40
+ return {
41
+ isTypeScript,
42
+ hasTsConfig,
43
+ hasTypeScriptDep,
44
+ packageJson,
45
+ tsconfigPath: hasTsConfig ? tsconfigPath : null,
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Detect testing framework in use
51
+ * @param {string} projectDir - Project directory path
52
+ * @param {Object} packageJson - Parsed package.json (optional)
53
+ * @returns {Object} Testing framework detection result
54
+ */
55
+ function detectTestFramework(projectDir = process.cwd(), packageJson = null) {
56
+ if (!packageJson) {
57
+ const packageJsonPath = path.join(projectDir, 'package.json');
58
+ if (fs.existsSync(packageJsonPath)) {
59
+ packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
60
+ }
61
+ }
62
+
63
+ const hasJestConfig =
64
+ fs.existsSync(path.join(projectDir, 'jest.config.js')) ||
65
+ fs.existsSync(path.join(projectDir, 'jest.config.ts')) ||
66
+ fs.existsSync(path.join(projectDir, 'jest.config.json')) ||
67
+ packageJson?.jest;
68
+
69
+ const hasVitestConfig =
70
+ fs.existsSync(path.join(projectDir, 'vitest.config.js')) ||
71
+ fs.existsSync(path.join(projectDir, 'vitest.config.ts'));
72
+
73
+ const allDeps = {
74
+ ...packageJson?.dependencies,
75
+ ...packageJson?.devDependencies,
76
+ };
77
+
78
+ const hasJestDep = 'jest' in allDeps || '@types/jest' in allDeps;
79
+ const hasVitestDep = 'vitest' in allDeps;
80
+ const hasTsJest = 'ts-jest' in allDeps;
81
+
82
+ let framework = 'none';
83
+ let isConfigured = false;
84
+
85
+ if (hasJestConfig || hasJestDep) {
86
+ framework = 'jest';
87
+ isConfigured = hasJestConfig;
88
+ } else if (hasVitestConfig || hasVitestDep) {
89
+ framework = 'vitest';
90
+ isConfigured = hasVitestConfig;
91
+ }
92
+
93
+ return {
94
+ framework,
95
+ isConfigured,
96
+ hasJest: hasJestDep,
97
+ hasVitest: hasVitestDep,
98
+ hasTsJest,
99
+ needsTypeScriptConfig: false, // Will be set by checkTypeScriptTestConfig
100
+ };
101
+ }
102
+
103
+ /**
104
+ * Check if TypeScript project needs test configuration
105
+ * @param {string} projectDir - Project directory path
106
+ * @returns {Object} Configuration status
107
+ */
108
+ function checkTypeScriptTestConfig(projectDir = process.cwd()) {
109
+ const tsDetection = detectTypeScript(projectDir);
110
+ const testDetection = detectTestFramework(projectDir, tsDetection.packageJson);
111
+
112
+ const needsConfig =
113
+ tsDetection.isTypeScript && testDetection.framework === 'jest' && !testDetection.hasTsJest;
114
+
115
+ return {
116
+ ...tsDetection,
117
+ testFramework: testDetection,
118
+ needsJestConfig: tsDetection.isTypeScript && !testDetection.isConfigured,
119
+ needsTsJest: needsConfig,
120
+ recommendations: generateRecommendations(tsDetection, testDetection),
121
+ };
122
+ }
123
+
124
+ /**
125
+ * Generate configuration recommendations
126
+ * @param {Object} tsDetection - TypeScript detection result
127
+ * @param {Object} testDetection - Test framework detection result
128
+ * @returns {string[]} Array of recommendations
129
+ */
130
+ function generateRecommendations(tsDetection, testDetection) {
131
+ const recommendations = [];
132
+
133
+ if (tsDetection.isTypeScript && testDetection.framework === 'none') {
134
+ recommendations.push('No testing framework detected');
135
+ recommendations.push('Recommended: Install Jest with ts-jest');
136
+ recommendations.push('Run: npm install --save-dev jest @types/jest ts-jest');
137
+ }
138
+
139
+ if (tsDetection.isTypeScript && testDetection.framework === 'jest' && !testDetection.hasTsJest) {
140
+ recommendations.push('Jest detected but missing TypeScript support');
141
+ recommendations.push('Install ts-jest: npm install --save-dev ts-jest');
142
+ recommendations.push('Or run: caws diagnose to auto-configure');
143
+ }
144
+
145
+ if (tsDetection.isTypeScript && !testDetection.isConfigured) {
146
+ recommendations.push('Testing framework not configured');
147
+ recommendations.push('Run: caws scaffold to add test configuration');
148
+ }
149
+
150
+ return recommendations;
151
+ }
152
+
153
+ /**
154
+ * Display TypeScript detection results
155
+ * @param {Object} detection - Detection result from checkTypeScriptTestConfig
156
+ */
157
+ function displayTypeScriptDetection(detection) {
158
+ if (!detection.isTypeScript) {
159
+ return;
160
+ }
161
+
162
+ console.log(chalk.cyan('\n📦 TypeScript Project Detected'));
163
+ console.log(chalk.gray(` tsconfig.json: ${detection.hasTsConfig ? '✅' : '❌'}`));
164
+ console.log(chalk.gray(` typescript dependency: ${detection.hasTypeScriptDep ? '✅' : '❌'}`));
165
+
166
+ if (detection.testFramework.framework !== 'none') {
167
+ console.log(chalk.gray(` Test framework: ${detection.testFramework.framework}`));
168
+ console.log(chalk.gray(` Configured: ${detection.testFramework.isConfigured ? '✅' : '❌'}`));
169
+ }
170
+
171
+ if (detection.recommendations.length > 0) {
172
+ console.log(chalk.yellow('\n💡 Recommendations:'));
173
+ detection.recommendations.forEach((rec) => {
174
+ console.log(chalk.yellow(` ${rec}`));
175
+ });
176
+ }
177
+ }
178
+
179
+ module.exports = {
180
+ detectTypeScript,
181
+ detectTestFramework,
182
+ checkTypeScriptTestConfig,
183
+ generateRecommendations,
184
+ displayTypeScriptDetection,
185
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paths.design/caws-cli",
3
- "version": "3.2.4",
3
+ "version": "3.3.0",
4
4
  "description": "CAWS CLI - Coding Agent Workflow System command line tools",
5
5
  "main": "dist/index.js",
6
6
  "bin": {