@principal-ai/principal-view-cli 0.3.3 → 0.3.4

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 (58) hide show
  1. package/dist/commands/coverage.d.ts +9 -0
  2. package/dist/commands/coverage.d.ts.map +1 -0
  3. package/dist/commands/coverage.js +158 -0
  4. package/dist/commands/create.d.ts +6 -0
  5. package/dist/commands/create.d.ts.map +1 -0
  6. package/dist/commands/create.js +50 -0
  7. package/dist/commands/doctor.d.ts +10 -0
  8. package/dist/commands/doctor.d.ts.map +1 -0
  9. package/dist/commands/doctor.js +274 -0
  10. package/dist/commands/formats.d.ts +6 -0
  11. package/dist/commands/formats.d.ts.map +1 -0
  12. package/dist/commands/formats.js +475 -0
  13. package/dist/commands/hooks.d.ts +9 -0
  14. package/dist/commands/hooks.d.ts.map +1 -0
  15. package/dist/commands/hooks.js +295 -0
  16. package/dist/commands/init.d.ts +6 -0
  17. package/dist/commands/init.d.ts.map +1 -0
  18. package/dist/commands/init.js +271 -0
  19. package/dist/commands/lint.d.ts +6 -0
  20. package/dist/commands/lint.d.ts.map +1 -0
  21. package/dist/commands/lint.js +506 -0
  22. package/dist/commands/list.d.ts +6 -0
  23. package/dist/commands/list.d.ts.map +1 -0
  24. package/dist/commands/list.js +80 -0
  25. package/dist/commands/narrative/index.d.ts +3 -0
  26. package/dist/commands/narrative/index.d.ts.map +1 -0
  27. package/dist/commands/narrative/index.js +17 -0
  28. package/dist/commands/narrative/inspect.d.ts +3 -0
  29. package/dist/commands/narrative/inspect.d.ts.map +1 -0
  30. package/dist/commands/narrative/inspect.js +109 -0
  31. package/dist/commands/narrative/list.d.ts +3 -0
  32. package/dist/commands/narrative/list.d.ts.map +1 -0
  33. package/dist/commands/narrative/list.js +101 -0
  34. package/dist/commands/narrative/render.d.ts +3 -0
  35. package/dist/commands/narrative/render.d.ts.map +1 -0
  36. package/dist/commands/narrative/render.js +99 -0
  37. package/dist/commands/narrative/test.d.ts +3 -0
  38. package/dist/commands/narrative/test.d.ts.map +1 -0
  39. package/dist/commands/narrative/test.js +150 -0
  40. package/dist/commands/narrative/utils.d.ts +49 -0
  41. package/dist/commands/narrative/utils.d.ts.map +1 -0
  42. package/dist/commands/narrative/utils.js +164 -0
  43. package/dist/commands/narrative/validate.d.ts +3 -0
  44. package/dist/commands/narrative/validate.d.ts.map +1 -0
  45. package/dist/commands/narrative/validate.js +149 -0
  46. package/dist/commands/schema.d.ts +6 -0
  47. package/dist/commands/schema.d.ts.map +1 -0
  48. package/dist/commands/schema.js +336 -0
  49. package/dist/commands/validate-execution.d.ts +11 -0
  50. package/dist/commands/validate-execution.d.ts.map +1 -0
  51. package/dist/commands/validate-execution.js +223 -0
  52. package/dist/commands/validate.d.ts +6 -0
  53. package/dist/commands/validate.d.ts.map +1 -0
  54. package/dist/commands/validate.js +1065 -0
  55. package/dist/index.d.ts +8 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +45 -0
  58. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-execution.d.ts","sourceRoot":"","sources":["../../src/commands/validate-execution.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqJpC;;GAEG;AACH,wBAAgB,8BAA8B,IAAI,OAAO,CAwGxD"}
@@ -0,0 +1,223 @@
1
+ /**
2
+ * Validate execution files command
3
+ *
4
+ * Validates .otel.json files to ensure they conform to the expected ExecutionData structure.
5
+ */
6
+ import { Command } from 'commander';
7
+ import { readFileSync } from 'node:fs';
8
+ import { resolve, relative } from 'node:path';
9
+ import chalk from 'chalk';
10
+ import { globby } from 'globby';
11
+ import { createExecutionValidator } from '@principal-ai/principal-view-core';
12
+ /**
13
+ * Load and parse an execution file
14
+ */
15
+ function loadExecutionFile(filePath) {
16
+ try {
17
+ const content = readFileSync(filePath, 'utf-8');
18
+ return JSON.parse(content);
19
+ }
20
+ catch (error) {
21
+ throw new Error(`Failed to parse JSON: ${error.message}`);
22
+ }
23
+ }
24
+ /**
25
+ * Format validation results for console output
26
+ */
27
+ function formatConsoleOutput(results, options) {
28
+ const lines = [];
29
+ let totalErrors = 0;
30
+ let totalWarnings = 0;
31
+ for (const { file, result } of results) {
32
+ totalErrors += result.errors.length;
33
+ totalWarnings += result.warnings.length;
34
+ // If quiet mode, only show files with issues
35
+ if (options.quiet && result.valid && result.warnings.length === 0) {
36
+ continue;
37
+ }
38
+ // Show file status
39
+ if (result.valid && result.warnings.length === 0) {
40
+ lines.push(chalk.green(`✓ ${file}`));
41
+ }
42
+ else if (result.valid && result.warnings.length > 0) {
43
+ lines.push(chalk.yellow(`⚠ ${file}`));
44
+ }
45
+ else {
46
+ lines.push(chalk.red(`✗ ${file}`));
47
+ }
48
+ // Show errors
49
+ if (result.errors.length > 0) {
50
+ lines.push('');
51
+ result.errors.forEach((error) => {
52
+ lines.push(chalk.red(` ERROR: ${error.path}`));
53
+ lines.push(` ${error.message}`);
54
+ if (error.suggestion) {
55
+ lines.push(chalk.dim(` → ${error.suggestion}`));
56
+ }
57
+ });
58
+ lines.push('');
59
+ }
60
+ // Show warnings
61
+ if (result.warnings.length > 0) {
62
+ lines.push('');
63
+ result.warnings.forEach((warning) => {
64
+ lines.push(chalk.yellow(` WARN: ${warning.path}`));
65
+ lines.push(` ${warning.message}`);
66
+ if (warning.suggestion) {
67
+ lines.push(chalk.dim(` → ${warning.suggestion}`));
68
+ }
69
+ });
70
+ lines.push('');
71
+ }
72
+ }
73
+ // Summary
74
+ lines.push('');
75
+ if (totalErrors === 0 && totalWarnings === 0) {
76
+ lines.push(chalk.green(`✓ All ${results.length} file${results.length === 1 ? '' : 's'} passed validation`));
77
+ }
78
+ else {
79
+ const parts = [];
80
+ if (totalErrors > 0) {
81
+ parts.push(chalk.red(`${totalErrors} error${totalErrors === 1 ? '' : 's'}`));
82
+ }
83
+ if (totalWarnings > 0) {
84
+ parts.push(chalk.yellow(`${totalWarnings} warning${totalWarnings === 1 ? '' : 's'}`));
85
+ }
86
+ lines.push(`✖ ${parts.join(', ')} found in ${results.length} file${results.length === 1 ? '' : 's'}`);
87
+ }
88
+ return {
89
+ output: lines.join('\n'),
90
+ hasErrors: totalErrors > 0,
91
+ };
92
+ }
93
+ /**
94
+ * Format validation results as JSON
95
+ */
96
+ function formatJsonOutput(results) {
97
+ let totalErrors = 0;
98
+ let totalWarnings = 0;
99
+ const files = results.map(({ file, result }) => {
100
+ totalErrors += result.errors.length;
101
+ totalWarnings += result.warnings.length;
102
+ return {
103
+ file,
104
+ valid: result.valid,
105
+ errorCount: result.errors.length,
106
+ warningCount: result.warnings.length,
107
+ errors: result.errors,
108
+ warnings: result.warnings,
109
+ };
110
+ });
111
+ return {
112
+ files,
113
+ summary: {
114
+ totalFiles: files.length,
115
+ totalErrors,
116
+ totalWarnings,
117
+ validFiles: files.filter((f) => f.valid).length,
118
+ invalidFiles: files.filter((f) => !f.valid).length,
119
+ },
120
+ };
121
+ }
122
+ /**
123
+ * Create the validate-execution command
124
+ */
125
+ export function createValidateExecutionCommand() {
126
+ const command = new Command('validate-execution');
127
+ command
128
+ .description('Validate execution files (.otel.json)')
129
+ .argument('[files...]', 'Files or glob patterns to validate (defaults to **/__executions__/**/*.otel.json)')
130
+ .option('--json', 'Output results as JSON')
131
+ .option('-q, --quiet', 'Only show files with errors or warnings')
132
+ .action(async (files, options) => {
133
+ try {
134
+ const cwd = process.cwd();
135
+ const validator = createExecutionValidator();
136
+ // Determine files to validate
137
+ let patterns;
138
+ if (files.length > 0) {
139
+ patterns = files;
140
+ }
141
+ else {
142
+ // Default: find all .otel.json files in __executions__ directories
143
+ patterns = [
144
+ '**/__executions__/*.otel.json',
145
+ '.principal-views/__executions__/*.otel.json',
146
+ ];
147
+ }
148
+ // Find matching files
149
+ const matchedFiles = await globby(patterns, {
150
+ ignore: ['**/node_modules/**'],
151
+ absolute: false,
152
+ });
153
+ if (matchedFiles.length === 0) {
154
+ if (options.json) {
155
+ console.log(JSON.stringify({
156
+ files: [],
157
+ summary: {
158
+ totalFiles: 0,
159
+ totalErrors: 0,
160
+ totalWarnings: 0,
161
+ validFiles: 0,
162
+ invalidFiles: 0,
163
+ },
164
+ }));
165
+ }
166
+ else {
167
+ console.log(chalk.yellow('No execution files found matching the specified patterns.'));
168
+ console.log(chalk.dim(`Patterns searched: ${patterns.join(', ')}`));
169
+ }
170
+ return;
171
+ }
172
+ // Validate each file
173
+ const results = [];
174
+ for (const filePath of matchedFiles) {
175
+ const absolutePath = resolve(cwd, filePath);
176
+ const relativePath = relative(cwd, absolutePath);
177
+ try {
178
+ const data = loadExecutionFile(absolutePath);
179
+ const result = validator.validate(data, relativePath);
180
+ results.push({ file: relativePath, result });
181
+ }
182
+ catch (error) {
183
+ // Parse error
184
+ results.push({
185
+ file: relativePath,
186
+ result: {
187
+ valid: false,
188
+ errors: [
189
+ {
190
+ path: relativePath,
191
+ message: error.message,
192
+ severity: 'error',
193
+ },
194
+ ],
195
+ warnings: [],
196
+ },
197
+ });
198
+ }
199
+ }
200
+ // Output results
201
+ if (options.json) {
202
+ console.log(JSON.stringify(formatJsonOutput(results), null, 2));
203
+ }
204
+ else {
205
+ const { output, hasErrors } = formatConsoleOutput(results, options);
206
+ console.log(output);
207
+ if (hasErrors) {
208
+ process.exit(1);
209
+ }
210
+ }
211
+ }
212
+ catch (error) {
213
+ if (options.json) {
214
+ console.log(JSON.stringify({ error: error.message }));
215
+ }
216
+ else {
217
+ console.error(chalk.red('Error:'), error.message);
218
+ }
219
+ process.exit(1);
220
+ }
221
+ });
222
+ return command;
223
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Validate command - Validate .canvas configuration files
3
+ */
4
+ import { Command } from 'commander';
5
+ export declare function createValidateCommand(): Command;
6
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/commands/validate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0sCpC,wBAAgB,qBAAqB,IAAI,OAAO,CAiI/C"}