@principal-ai/principal-view-cli 0.3.1 → 0.3.3
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.cjs +6414 -340
- package/dist/index.cjs.map +4 -4
- package/package.json +2 -2
- package/dist/commands/coverage.d.ts +0 -9
- package/dist/commands/coverage.d.ts.map +0 -1
- package/dist/commands/coverage.js +0 -158
- package/dist/commands/create.d.ts +0 -6
- package/dist/commands/create.d.ts.map +0 -1
- package/dist/commands/create.js +0 -50
- package/dist/commands/doctor.d.ts +0 -10
- package/dist/commands/doctor.d.ts.map +0 -1
- package/dist/commands/doctor.js +0 -274
- package/dist/commands/formats.d.ts +0 -6
- package/dist/commands/formats.d.ts.map +0 -1
- package/dist/commands/formats.js +0 -475
- package/dist/commands/hooks.d.ts +0 -9
- package/dist/commands/hooks.d.ts.map +0 -1
- package/dist/commands/hooks.js +0 -295
- package/dist/commands/init.d.ts +0 -6
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.js +0 -271
- package/dist/commands/lint.d.ts +0 -6
- package/dist/commands/lint.d.ts.map +0 -1
- package/dist/commands/lint.js +0 -506
- package/dist/commands/list.d.ts +0 -6
- package/dist/commands/list.d.ts.map +0 -1
- package/dist/commands/list.js +0 -80
- package/dist/commands/narrative/eval.d.ts +0 -3
- package/dist/commands/narrative/eval.d.ts.map +0 -1
- package/dist/commands/narrative/eval.js +0 -76
- package/dist/commands/narrative/index.d.ts +0 -3
- package/dist/commands/narrative/index.d.ts.map +0 -1
- package/dist/commands/narrative/index.js +0 -19
- package/dist/commands/narrative/inspect.d.ts +0 -3
- package/dist/commands/narrative/inspect.d.ts.map +0 -1
- package/dist/commands/narrative/inspect.js +0 -109
- package/dist/commands/narrative/list.d.ts +0 -3
- package/dist/commands/narrative/list.d.ts.map +0 -1
- package/dist/commands/narrative/list.js +0 -101
- package/dist/commands/narrative/render.d.ts +0 -3
- package/dist/commands/narrative/render.d.ts.map +0 -1
- package/dist/commands/narrative/render.js +0 -99
- package/dist/commands/narrative/test.d.ts +0 -3
- package/dist/commands/narrative/test.d.ts.map +0 -1
- package/dist/commands/narrative/test.js +0 -150
- package/dist/commands/narrative/utils.d.ts +0 -69
- package/dist/commands/narrative/utils.d.ts.map +0 -1
- package/dist/commands/narrative/utils.js +0 -158
- package/dist/commands/narrative/validate.d.ts +0 -3
- package/dist/commands/narrative/validate.d.ts.map +0 -1
- package/dist/commands/narrative/validate.js +0 -149
- package/dist/commands/schema.d.ts +0 -6
- package/dist/commands/schema.d.ts.map +0 -1
- package/dist/commands/schema.js +0 -336
- package/dist/commands/validate-execution.d.ts +0 -11
- package/dist/commands/validate-execution.d.ts.map +0 -1
- package/dist/commands/validate-execution.js +0 -223
- package/dist/commands/validate.d.ts +0 -6
- package/dist/commands/validate.d.ts.map +0 -1
- package/dist/commands/validate.js +0 -1065
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -45
|
@@ -1,223 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|