@evalgate/sdk 2.0.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/CHANGELOG.md +638 -0
- package/README.md +398 -0
- package/dist/assertions.d.ts +189 -0
- package/dist/assertions.js +662 -0
- package/dist/batch.d.ts +68 -0
- package/dist/batch.js +179 -0
- package/dist/cache.d.ts +65 -0
- package/dist/cache.js +131 -0
- package/dist/cli/api.d.ts +108 -0
- package/dist/cli/api.js +132 -0
- package/dist/cli/baseline.d.ts +10 -0
- package/dist/cli/baseline.js +172 -0
- package/dist/cli/check.d.ts +73 -0
- package/dist/cli/check.js +355 -0
- package/dist/cli/ci-context.d.ts +6 -0
- package/dist/cli/ci-context.js +112 -0
- package/dist/cli/ci.d.ts +45 -0
- package/dist/cli/ci.js +192 -0
- package/dist/cli/config.d.ts +30 -0
- package/dist/cli/config.js +230 -0
- package/dist/cli/constants.d.ts +15 -0
- package/dist/cli/constants.js +18 -0
- package/dist/cli/diff.d.ts +173 -0
- package/dist/cli/diff.js +685 -0
- package/dist/cli/discover.d.ts +84 -0
- package/dist/cli/discover.js +419 -0
- package/dist/cli/doctor.d.ts +88 -0
- package/dist/cli/doctor.js +675 -0
- package/dist/cli/env.d.ts +21 -0
- package/dist/cli/env.js +42 -0
- package/dist/cli/explain.d.ts +58 -0
- package/dist/cli/explain.js +561 -0
- package/dist/cli/formatters/github.d.ts +8 -0
- package/dist/cli/formatters/github.js +135 -0
- package/dist/cli/formatters/human.d.ts +6 -0
- package/dist/cli/formatters/human.js +110 -0
- package/dist/cli/formatters/json.d.ts +6 -0
- package/dist/cli/formatters/json.js +10 -0
- package/dist/cli/formatters/pr-comment.d.ts +12 -0
- package/dist/cli/formatters/pr-comment.js +103 -0
- package/dist/cli/formatters/types.d.ts +103 -0
- package/dist/cli/formatters/types.js +8 -0
- package/dist/cli/gate.d.ts +21 -0
- package/dist/cli/gate.js +179 -0
- package/dist/cli/impact-analysis.d.ts +63 -0
- package/dist/cli/impact-analysis.js +252 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.js +332 -0
- package/dist/cli/init.d.ts +16 -0
- package/dist/cli/init.js +292 -0
- package/dist/cli/manifest.d.ts +103 -0
- package/dist/cli/manifest.js +282 -0
- package/dist/cli/migrate.d.ts +41 -0
- package/dist/cli/migrate.js +349 -0
- package/dist/cli/policy-packs.d.ts +23 -0
- package/dist/cli/policy-packs.js +89 -0
- package/dist/cli/print-config.d.ts +29 -0
- package/dist/cli/print-config.js +270 -0
- package/dist/cli/profiles.d.ts +28 -0
- package/dist/cli/profiles.js +30 -0
- package/dist/cli/reason-codes.d.ts +17 -0
- package/dist/cli/reason-codes.js +19 -0
- package/dist/cli/regression-gate.d.ts +15 -0
- package/dist/cli/regression-gate.js +341 -0
- package/dist/cli/render/snippet.d.ts +5 -0
- package/dist/cli/render/snippet.js +15 -0
- package/dist/cli/render/sort.d.ts +10 -0
- package/dist/cli/render/sort.js +24 -0
- package/dist/cli/report/build-check-report.d.ts +19 -0
- package/dist/cli/report/build-check-report.js +132 -0
- package/dist/cli/run.d.ts +101 -0
- package/dist/cli/run.js +395 -0
- package/dist/cli/share.d.ts +17 -0
- package/dist/cli/share.js +91 -0
- package/dist/cli/upgrade.d.ts +15 -0
- package/dist/cli/upgrade.js +492 -0
- package/dist/cli/workspace.d.ts +31 -0
- package/dist/cli/workspace.js +68 -0
- package/dist/client.d.ts +368 -0
- package/dist/client.js +893 -0
- package/dist/client.request.test.d.ts +1 -0
- package/dist/client.request.test.js +232 -0
- package/dist/context.d.ts +134 -0
- package/dist/context.js +215 -0
- package/dist/errors.d.ts +82 -0
- package/dist/errors.js +298 -0
- package/dist/export.d.ts +195 -0
- package/dist/export.js +344 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +153 -0
- package/dist/integrations/anthropic.d.ts +91 -0
- package/dist/integrations/anthropic.js +163 -0
- package/dist/integrations/openai-eval.d.ts +57 -0
- package/dist/integrations/openai-eval.js +232 -0
- package/dist/integrations/openai.d.ts +92 -0
- package/dist/integrations/openai.js +160 -0
- package/dist/local.d.ts +39 -0
- package/dist/local.js +148 -0
- package/dist/logger.d.ts +128 -0
- package/dist/logger.js +227 -0
- package/dist/matchers/index.d.ts +1 -0
- package/dist/matchers/index.js +6 -0
- package/dist/matchers/to-pass-gate.d.ts +29 -0
- package/dist/matchers/to-pass-gate.js +35 -0
- package/dist/pagination.d.ts +74 -0
- package/dist/pagination.js +139 -0
- package/dist/regression.d.ts +100 -0
- package/dist/regression.js +44 -0
- package/dist/runtime/adapters/config-to-dsl.d.ts +33 -0
- package/dist/runtime/adapters/config-to-dsl.js +400 -0
- package/dist/runtime/adapters/testsuite-to-dsl.d.ts +63 -0
- package/dist/runtime/adapters/testsuite-to-dsl.js +276 -0
- package/dist/runtime/context.d.ts +26 -0
- package/dist/runtime/context.js +74 -0
- package/dist/runtime/eval.d.ts +46 -0
- package/dist/runtime/eval.js +244 -0
- package/dist/runtime/execution-mode.d.ts +80 -0
- package/dist/runtime/execution-mode.js +357 -0
- package/dist/runtime/executor.d.ts +16 -0
- package/dist/runtime/executor.js +152 -0
- package/dist/runtime/registry.d.ts +78 -0
- package/dist/runtime/registry.js +403 -0
- package/dist/runtime/run-report.d.ts +200 -0
- package/dist/runtime/run-report.js +222 -0
- package/dist/runtime/types.d.ts +356 -0
- package/dist/runtime/types.js +76 -0
- package/dist/snapshot.d.ts +176 -0
- package/dist/snapshot.js +322 -0
- package/dist/streaming.d.ts +173 -0
- package/dist/streaming.js +268 -0
- package/dist/testing.d.ts +273 -0
- package/dist/testing.js +317 -0
- package/dist/types.d.ts +754 -0
- package/dist/types.js +54 -0
- package/dist/utils/input-hash.d.ts +8 -0
- package/dist/utils/input-hash.js +41 -0
- package/dist/version.d.ts +7 -0
- package/dist/version.js +10 -0
- package/dist/workflows.d.ts +389 -0
- package/dist/workflows.js +671 -0
- package/package.json +117 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TICKET 1 — evalgate discover
|
|
3
|
+
*
|
|
4
|
+
* Your first "holy shit" moment feature
|
|
5
|
+
*
|
|
6
|
+
* Goal:
|
|
7
|
+
* npm install
|
|
8
|
+
* evalgate discover
|
|
9
|
+
*
|
|
10
|
+
* Output:
|
|
11
|
+
* Found 42 behavioral specifications
|
|
12
|
+
* Safety: 12
|
|
13
|
+
* Accuracy: 18
|
|
14
|
+
* Agents: 7
|
|
15
|
+
* Tools: 5
|
|
16
|
+
*
|
|
17
|
+
* Why this matters:
|
|
18
|
+
* - makes EvalGate feel alive
|
|
19
|
+
* - proves DSL works
|
|
20
|
+
* - enables intelligence layer
|
|
21
|
+
*
|
|
22
|
+
* This becomes your entry point command.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Discovered specification statistics
|
|
26
|
+
*/
|
|
27
|
+
export interface DiscoveryStats {
|
|
28
|
+
/** Total number of specifications found */
|
|
29
|
+
totalSpecs: number;
|
|
30
|
+
/** Specifications by category/tag */
|
|
31
|
+
categories: Record<string, number>;
|
|
32
|
+
/** Specifications by file */
|
|
33
|
+
files: Record<string, number>;
|
|
34
|
+
/** Execution mode information */
|
|
35
|
+
executionMode: {
|
|
36
|
+
mode: string;
|
|
37
|
+
hasSpecRuntime: boolean;
|
|
38
|
+
hasLegacyRuntime: boolean;
|
|
39
|
+
specFiles: string[];
|
|
40
|
+
legacyConfig?: string;
|
|
41
|
+
};
|
|
42
|
+
/** Project metadata */
|
|
43
|
+
project: {
|
|
44
|
+
root: string;
|
|
45
|
+
name: string;
|
|
46
|
+
hasPackageJson: boolean;
|
|
47
|
+
hasGit: boolean;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Specification analysis result
|
|
52
|
+
*/
|
|
53
|
+
export interface SpecAnalysis {
|
|
54
|
+
/** Specification ID */
|
|
55
|
+
id: string;
|
|
56
|
+
/** Specification name */
|
|
57
|
+
name: string;
|
|
58
|
+
/** File path */
|
|
59
|
+
file: string;
|
|
60
|
+
/** Tags/categories */
|
|
61
|
+
tags: string[];
|
|
62
|
+
/** Has assertions */
|
|
63
|
+
hasAssertions: boolean;
|
|
64
|
+
/** Uses external models */
|
|
65
|
+
usesModels: boolean;
|
|
66
|
+
/** Uses tools */
|
|
67
|
+
usesTools: boolean;
|
|
68
|
+
/** Estimated complexity */
|
|
69
|
+
complexity: "simple" | "medium" | "complex";
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Discover and analyze behavioral specifications in the current project
|
|
73
|
+
*/
|
|
74
|
+
export declare function discoverSpecs(options?: {
|
|
75
|
+
manifest?: boolean;
|
|
76
|
+
}): Promise<DiscoveryStats>;
|
|
77
|
+
/**
|
|
78
|
+
* Print discovery results in a beautiful format
|
|
79
|
+
*/
|
|
80
|
+
export declare function printDiscoveryResults(stats: DiscoveryStats): void;
|
|
81
|
+
/**
|
|
82
|
+
* Run discovery command
|
|
83
|
+
*/
|
|
84
|
+
export declare function runDiscover(): Promise<void>;
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TICKET 1 — evalgate discover
|
|
4
|
+
*
|
|
5
|
+
* Your first "holy shit" moment feature
|
|
6
|
+
*
|
|
7
|
+
* Goal:
|
|
8
|
+
* npm install
|
|
9
|
+
* evalgate discover
|
|
10
|
+
*
|
|
11
|
+
* Output:
|
|
12
|
+
* Found 42 behavioral specifications
|
|
13
|
+
* Safety: 12
|
|
14
|
+
* Accuracy: 18
|
|
15
|
+
* Agents: 7
|
|
16
|
+
* Tools: 5
|
|
17
|
+
*
|
|
18
|
+
* Why this matters:
|
|
19
|
+
* - makes EvalGate feel alive
|
|
20
|
+
* - proves DSL works
|
|
21
|
+
* - enables intelligence layer
|
|
22
|
+
*
|
|
23
|
+
* This becomes your entry point command.
|
|
24
|
+
*/
|
|
25
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
28
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
29
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
30
|
+
}
|
|
31
|
+
Object.defineProperty(o, k2, desc);
|
|
32
|
+
}) : (function(o, m, k, k2) {
|
|
33
|
+
if (k2 === undefined) k2 = k;
|
|
34
|
+
o[k2] = m[k];
|
|
35
|
+
}));
|
|
36
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
37
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
38
|
+
}) : function(o, v) {
|
|
39
|
+
o["default"] = v;
|
|
40
|
+
});
|
|
41
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
42
|
+
var ownKeys = function(o) {
|
|
43
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
44
|
+
var ar = [];
|
|
45
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
46
|
+
return ar;
|
|
47
|
+
};
|
|
48
|
+
return ownKeys(o);
|
|
49
|
+
};
|
|
50
|
+
return function (mod) {
|
|
51
|
+
if (mod && mod.__esModule) return mod;
|
|
52
|
+
var result = {};
|
|
53
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
54
|
+
__setModuleDefault(result, mod);
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
})();
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.discoverSpecs = discoverSpecs;
|
|
60
|
+
exports.printDiscoveryResults = printDiscoveryResults;
|
|
61
|
+
exports.runDiscover = runDiscover;
|
|
62
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
63
|
+
const path = __importStar(require("node:path"));
|
|
64
|
+
const execution_mode_1 = require("../runtime/execution-mode");
|
|
65
|
+
const manifest_1 = require("./manifest");
|
|
66
|
+
/**
|
|
67
|
+
* Discover and analyze behavioral specifications in the current project
|
|
68
|
+
*/
|
|
69
|
+
async function discoverSpecs(options = {}) {
|
|
70
|
+
try {
|
|
71
|
+
const projectRoot = process.cwd();
|
|
72
|
+
const executionMode = await (0, execution_mode_1.getExecutionMode)(projectRoot);
|
|
73
|
+
// Get project metadata
|
|
74
|
+
const project = await getProjectMetadata(projectRoot);
|
|
75
|
+
if (executionMode.specFiles.length === 0) {
|
|
76
|
+
console.log("\n✨ No behavioral specifications found.");
|
|
77
|
+
console.log("💡 Create files with defineEval() calls to get started.");
|
|
78
|
+
return {
|
|
79
|
+
totalSpecs: 0,
|
|
80
|
+
categories: {},
|
|
81
|
+
files: {},
|
|
82
|
+
executionMode: {
|
|
83
|
+
mode: executionMode.mode,
|
|
84
|
+
hasSpecRuntime: executionMode.hasSpecRuntime,
|
|
85
|
+
hasLegacyRuntime: executionMode.hasLegacyRuntime,
|
|
86
|
+
specFiles: executionMode.specFiles,
|
|
87
|
+
legacyConfig: executionMode.legacyConfig,
|
|
88
|
+
},
|
|
89
|
+
project,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// Analyze specifications
|
|
93
|
+
const specs = await analyzeSpecifications(executionMode.specFiles);
|
|
94
|
+
// Generate manifest if requested
|
|
95
|
+
if (options.manifest) {
|
|
96
|
+
console.log("🔧 Generating evaluation manifest...");
|
|
97
|
+
const manifest = await (0, manifest_1.generateManifest)(specs, projectRoot, project.name, executionMode);
|
|
98
|
+
await (0, manifest_1.writeManifest)(manifest, projectRoot);
|
|
99
|
+
console.log(`✅ Manifest written to .evalgate/manifest.json`);
|
|
100
|
+
console.log(`✅ Lock file written to .evalgate/manifest.lock.json`);
|
|
101
|
+
}
|
|
102
|
+
// Calculate statistics
|
|
103
|
+
const stats = calculateStats(specs, executionMode, project);
|
|
104
|
+
printDiscoveryResults(stats);
|
|
105
|
+
return stats;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.error("❌ Discovery failed:", error instanceof Error ? error.message : String(error));
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get project metadata
|
|
114
|
+
*/
|
|
115
|
+
async function getProjectMetadata(projectRoot) {
|
|
116
|
+
const packageJsonPath = path.join(projectRoot, "package.json");
|
|
117
|
+
const gitPath = path.join(projectRoot, ".git");
|
|
118
|
+
let hasPackageJson = false;
|
|
119
|
+
let projectName = "unknown";
|
|
120
|
+
try {
|
|
121
|
+
const packageJson = await fs.readFile(packageJsonPath, "utf-8");
|
|
122
|
+
const parsed = JSON.parse(packageJson);
|
|
123
|
+
hasPackageJson = true;
|
|
124
|
+
projectName = parsed.name || "unknown";
|
|
125
|
+
}
|
|
126
|
+
catch (_error) {
|
|
127
|
+
// No package.json
|
|
128
|
+
}
|
|
129
|
+
const hasGit = await fs
|
|
130
|
+
.access(gitPath)
|
|
131
|
+
.then(() => true)
|
|
132
|
+
.catch(() => false);
|
|
133
|
+
return {
|
|
134
|
+
root: projectRoot,
|
|
135
|
+
name: projectName,
|
|
136
|
+
hasPackageJson,
|
|
137
|
+
hasGit,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Analyze specification files
|
|
142
|
+
*/
|
|
143
|
+
async function analyzeSpecifications(specFiles) {
|
|
144
|
+
const specs = [];
|
|
145
|
+
for (const filePath of specFiles) {
|
|
146
|
+
try {
|
|
147
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
148
|
+
const analysis = analyzeSpecFile(filePath, content);
|
|
149
|
+
specs.push(analysis);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
console.warn(`Warning: Could not analyze ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return specs;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Analyze a single specification file
|
|
159
|
+
*/
|
|
160
|
+
function analyzeSpecFile(filePath, content) {
|
|
161
|
+
// Extract defineEval calls
|
|
162
|
+
const defineEvalMatches = content.match(/defineEval\s*\([^)]+\)/g) || [];
|
|
163
|
+
const specNames = defineEvalMatches.map((match) => {
|
|
164
|
+
const nameMatch = match.match(/["'`](.+?)["'`](?:\s*,|\s*\))/);
|
|
165
|
+
return nameMatch ? nameMatch[1] : "unnamed";
|
|
166
|
+
});
|
|
167
|
+
// Extract tags
|
|
168
|
+
const tags = extractTags(content);
|
|
169
|
+
// Analyze complexity
|
|
170
|
+
const complexity = analyzeComplexity(content);
|
|
171
|
+
// Check for models and tools
|
|
172
|
+
const usesModels = content.includes("model:") ||
|
|
173
|
+
content.includes("model=") ||
|
|
174
|
+
content.includes("openai") ||
|
|
175
|
+
content.includes("anthropic");
|
|
176
|
+
const usesTools = content.includes("tool:") ||
|
|
177
|
+
content.includes("function.") ||
|
|
178
|
+
content.includes("call(");
|
|
179
|
+
// Check for assertions
|
|
180
|
+
const hasAssertions = content.includes("assert") ||
|
|
181
|
+
content.includes("expect") ||
|
|
182
|
+
content.includes("should");
|
|
183
|
+
// Generate ID from file path
|
|
184
|
+
const id = generateSpecId(filePath);
|
|
185
|
+
return {
|
|
186
|
+
id,
|
|
187
|
+
name: specNames[0] || path.basename(filePath, ".ts"),
|
|
188
|
+
file: path.relative(process.cwd(), filePath),
|
|
189
|
+
tags,
|
|
190
|
+
hasAssertions,
|
|
191
|
+
usesModels,
|
|
192
|
+
usesTools,
|
|
193
|
+
complexity,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Extract tags from specification content
|
|
198
|
+
*/
|
|
199
|
+
function extractTags(content) {
|
|
200
|
+
const tags = [];
|
|
201
|
+
// Extract tags parameter
|
|
202
|
+
const tagsMatch = content.match(/tags\s*:\s*\[([^\]]+)\]/);
|
|
203
|
+
if (tagsMatch) {
|
|
204
|
+
const tagContent = tagsMatch[1];
|
|
205
|
+
const tagStrings = tagContent.match(/["'`](.+?)["'`](?:\s*,|\s*)/g) || [];
|
|
206
|
+
tags.push(...tagStrings.map((tag) => tag.replace(/["'`](.+?)["'`](?:\s*,|\s*)/, "$1")));
|
|
207
|
+
}
|
|
208
|
+
// Extract from description and metadata
|
|
209
|
+
const descriptionMatch = content.match(/description\s*:\s*["'`](.+?)["'`](?:\s*,|\s*)/);
|
|
210
|
+
if (descriptionMatch) {
|
|
211
|
+
const description = descriptionMatch[1].toLowerCase();
|
|
212
|
+
// Auto-categorize based on description
|
|
213
|
+
if (description.includes("safety") || description.includes("security"))
|
|
214
|
+
tags.push("safety");
|
|
215
|
+
if (description.includes("accuracy") || description.includes("precision"))
|
|
216
|
+
tags.push("accuracy");
|
|
217
|
+
if (description.includes("agent") || description.includes("autonomous"))
|
|
218
|
+
tags.push("agents");
|
|
219
|
+
if (description.includes("tool") || description.includes("function"))
|
|
220
|
+
tags.push("tools");
|
|
221
|
+
if (description.includes("latency") || description.includes("speed"))
|
|
222
|
+
tags.push("performance");
|
|
223
|
+
if (description.includes("hallucination") || description.includes("fact"))
|
|
224
|
+
tags.push("factual");
|
|
225
|
+
if (description.includes("bias") || description.includes("fairness"))
|
|
226
|
+
tags.push("bias");
|
|
227
|
+
if (description.includes("privacy") || description.includes("pii"))
|
|
228
|
+
tags.push("privacy");
|
|
229
|
+
}
|
|
230
|
+
return [...new Set(tags)]; // Remove duplicates
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Analyze specification complexity
|
|
234
|
+
*/
|
|
235
|
+
function analyzeComplexity(content) {
|
|
236
|
+
const lines = content.split("\n").length;
|
|
237
|
+
const hasAsync = content.includes("async") || content.includes("await");
|
|
238
|
+
const hasLoops = content.includes("for") || content.includes("while");
|
|
239
|
+
const hasConditionals = content.includes("if") || content.includes("switch");
|
|
240
|
+
const hasTryCatch = content.includes("try") || content.includes("catch");
|
|
241
|
+
const hasExternalCalls = content.includes("fetch") ||
|
|
242
|
+
content.includes("http") ||
|
|
243
|
+
content.includes("api");
|
|
244
|
+
let complexityScore = 0;
|
|
245
|
+
if (lines > 50)
|
|
246
|
+
complexityScore += 2;
|
|
247
|
+
if (lines > 100)
|
|
248
|
+
complexityScore += 3;
|
|
249
|
+
if (hasAsync)
|
|
250
|
+
complexityScore += 2;
|
|
251
|
+
if (hasLoops)
|
|
252
|
+
complexityScore += 1;
|
|
253
|
+
if (hasConditionals)
|
|
254
|
+
complexityScore += 1;
|
|
255
|
+
if (hasTryCatch)
|
|
256
|
+
complexityScore += 1;
|
|
257
|
+
if (hasExternalCalls)
|
|
258
|
+
complexityScore += 2;
|
|
259
|
+
if (complexityScore <= 2)
|
|
260
|
+
return "simple";
|
|
261
|
+
if (complexityScore <= 5)
|
|
262
|
+
return "medium";
|
|
263
|
+
return "complex";
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Generate specification ID from file path
|
|
267
|
+
*/
|
|
268
|
+
function generateSpecId(filePath) {
|
|
269
|
+
const relativePath = path.relative(process.cwd(), filePath);
|
|
270
|
+
const hash = Buffer.from(relativePath)
|
|
271
|
+
.toString("base64")
|
|
272
|
+
.replace(/[+/=]/g, "")
|
|
273
|
+
.slice(0, 8);
|
|
274
|
+
return hash;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Calculate discovery statistics
|
|
278
|
+
*/
|
|
279
|
+
function calculateStats(specs, executionMode, project) {
|
|
280
|
+
const categories = {};
|
|
281
|
+
const files = {};
|
|
282
|
+
// Count by categories
|
|
283
|
+
for (const spec of specs) {
|
|
284
|
+
for (const tag of spec.tags) {
|
|
285
|
+
categories[tag] = (categories[tag] || 0) + 1;
|
|
286
|
+
}
|
|
287
|
+
// Count by files
|
|
288
|
+
files[spec.file] = (files[spec.file] || 0) + 1;
|
|
289
|
+
}
|
|
290
|
+
// Add default categories if none found
|
|
291
|
+
if (Object.keys(categories).length === 0) {
|
|
292
|
+
categories.general = specs.length;
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
totalSpecs: specs.length,
|
|
296
|
+
categories,
|
|
297
|
+
files,
|
|
298
|
+
executionMode: {
|
|
299
|
+
mode: executionMode.mode,
|
|
300
|
+
hasSpecRuntime: executionMode.hasSpecRuntime,
|
|
301
|
+
hasLegacyRuntime: executionMode.hasLegacyRuntime,
|
|
302
|
+
specFiles: executionMode.specFiles,
|
|
303
|
+
legacyConfig: executionMode.legacyConfig,
|
|
304
|
+
},
|
|
305
|
+
project,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Print discovery results in a beautiful format
|
|
310
|
+
*/
|
|
311
|
+
function printDiscoveryResults(stats) {
|
|
312
|
+
console.log(`🔍 EvalGate Discovery Results`);
|
|
313
|
+
console.log(``);
|
|
314
|
+
console.log(`📊 Found ${stats.totalSpecs} behavioral specifications`);
|
|
315
|
+
console.log(``);
|
|
316
|
+
// Print categories
|
|
317
|
+
if (Object.keys(stats.categories).length > 0) {
|
|
318
|
+
console.log(`📋 Categories:`);
|
|
319
|
+
const sortedCategories = Object.entries(stats.categories)
|
|
320
|
+
.sort(([, a], [, b]) => b - a)
|
|
321
|
+
.slice(0, 10); // Top 10 categories
|
|
322
|
+
for (const [category, count] of sortedCategories) {
|
|
323
|
+
const icon = getCategoryIcon(category);
|
|
324
|
+
console.log(` ${icon} ${category}: ${count}`);
|
|
325
|
+
}
|
|
326
|
+
console.log(``);
|
|
327
|
+
}
|
|
328
|
+
// Print execution mode
|
|
329
|
+
console.log(`⚙️ Execution Mode: ${stats.executionMode.mode.toUpperCase()}`);
|
|
330
|
+
if (stats.executionMode.hasSpecRuntime) {
|
|
331
|
+
console.log(` ✅ Spec runtime: ${stats.executionMode.specFiles.length} files`);
|
|
332
|
+
}
|
|
333
|
+
if (stats.executionMode.hasLegacyRuntime) {
|
|
334
|
+
console.log(` ✅ Legacy runtime: ${stats.executionMode.legacyConfig ? path.basename(stats.executionMode.legacyConfig) : "config"}`);
|
|
335
|
+
}
|
|
336
|
+
console.log(``);
|
|
337
|
+
// Print project info
|
|
338
|
+
console.log(`📁 Project: ${stats.project.name}`);
|
|
339
|
+
console.log(` 📍 Root: ${stats.project.root}`);
|
|
340
|
+
console.log(` 📦 Package.json: ${stats.project.hasPackageJson ? "✅" : "❌"}`);
|
|
341
|
+
console.log(` 🔄 Git: ${stats.project.hasGit ? "✅" : "❌"}`);
|
|
342
|
+
console.log(``);
|
|
343
|
+
// Print recommendations
|
|
344
|
+
printRecommendations(stats);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Get icon for category
|
|
348
|
+
*/
|
|
349
|
+
function getCategoryIcon(category) {
|
|
350
|
+
const icons = {
|
|
351
|
+
safety: "🛡️",
|
|
352
|
+
security: "🔒",
|
|
353
|
+
accuracy: "🎯",
|
|
354
|
+
precision: "🎯",
|
|
355
|
+
agents: "🤖",
|
|
356
|
+
autonomous: "🤖",
|
|
357
|
+
tools: "🔧",
|
|
358
|
+
functions: "🔧",
|
|
359
|
+
performance: "⚡",
|
|
360
|
+
latency: "⚡",
|
|
361
|
+
speed: "⚡",
|
|
362
|
+
factual: "📊",
|
|
363
|
+
hallucination: "📊",
|
|
364
|
+
bias: "⚖️",
|
|
365
|
+
fairness: "⚖️",
|
|
366
|
+
privacy: "🔐",
|
|
367
|
+
pii: "🔐",
|
|
368
|
+
general: "📝",
|
|
369
|
+
};
|
|
370
|
+
return icons[category.toLowerCase()] || "📝";
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Print recommendations based on discovery results
|
|
374
|
+
*/
|
|
375
|
+
function printRecommendations(stats) {
|
|
376
|
+
console.log(`💡 Recommendations:`);
|
|
377
|
+
if (stats.totalSpecs === 0) {
|
|
378
|
+
console.log(` 🚀 No specifications found. Create your first eval with:
|
|
379
|
+
echo 'import { defineEval } from "@evalgate/sdk";
|
|
380
|
+
defineEval("hello-world", async (context) => {
|
|
381
|
+
return { pass: true, score: 100 };
|
|
382
|
+
});' > eval/hello.spec.ts`);
|
|
383
|
+
}
|
|
384
|
+
else if (stats.totalSpecs < 5) {
|
|
385
|
+
console.log(` 📈 Add more specifications to improve coverage`);
|
|
386
|
+
}
|
|
387
|
+
else if (stats.totalSpecs < 20) {
|
|
388
|
+
console.log(` 🎯 Good start! Consider organizing by categories`);
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
console.log(` 🏆 Excellent coverage! Consider running evalgate run`);
|
|
392
|
+
}
|
|
393
|
+
if (!stats.executionMode.hasSpecRuntime &&
|
|
394
|
+
!stats.executionMode.hasLegacyRuntime) {
|
|
395
|
+
console.log(` 🆕 New project? Try 'evalgate init' to get started`);
|
|
396
|
+
}
|
|
397
|
+
if (stats.executionMode.hasLegacyRuntime &&
|
|
398
|
+
!stats.executionMode.hasSpecRuntime) {
|
|
399
|
+
console.log(` 🔄 Legacy project detected. Try 'evalgate migrate config' to upgrade`);
|
|
400
|
+
}
|
|
401
|
+
if (stats.executionMode.hasSpecRuntime) {
|
|
402
|
+
console.log(` 🚀 Ready to run! Use 'evalgate run' to execute specifications`);
|
|
403
|
+
}
|
|
404
|
+
console.log(``);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Run discovery command
|
|
408
|
+
*/
|
|
409
|
+
async function runDiscover() {
|
|
410
|
+
try {
|
|
411
|
+
const stats = await discoverSpecs();
|
|
412
|
+
printDiscoveryResults(stats);
|
|
413
|
+
process.exit(0);
|
|
414
|
+
}
|
|
415
|
+
catch (error) {
|
|
416
|
+
console.error(`❌ Discovery failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
417
|
+
process.exit(1);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* evalgate doctor — Comprehensive CI/CD readiness checklist.
|
|
3
|
+
*
|
|
4
|
+
* Runs itemized pass/fail checks with exact remediation commands.
|
|
5
|
+
*
|
|
6
|
+
* Exit codes:
|
|
7
|
+
* 0 — All checks passed (ready)
|
|
8
|
+
* 2 — One or more checks failed (not ready)
|
|
9
|
+
* 3 — Infrastructure error (couldn't complete checks)
|
|
10
|
+
*
|
|
11
|
+
* Flags:
|
|
12
|
+
* --report Output JSON diagnostic bundle (redacted)
|
|
13
|
+
* --format <fmt> Output format: human (default), json
|
|
14
|
+
* --apiKey <key> API key (or EVALGATE_API_KEY env)
|
|
15
|
+
* --baseUrl <url> API base URL
|
|
16
|
+
* --evaluationId <id> Evaluation to verify
|
|
17
|
+
* --baseline <mode> Baseline mode
|
|
18
|
+
*/
|
|
19
|
+
import { type EvalAIConfig } from "./config";
|
|
20
|
+
export declare const DOCTOR_EXIT: {
|
|
21
|
+
readonly READY: 0;
|
|
22
|
+
readonly NOT_READY: 2;
|
|
23
|
+
readonly INFRA_ERROR: 3;
|
|
24
|
+
};
|
|
25
|
+
export type CheckStatus = "pass" | "fail" | "warn" | "skip";
|
|
26
|
+
export interface CheckResult {
|
|
27
|
+
id: string;
|
|
28
|
+
label: string;
|
|
29
|
+
status: CheckStatus;
|
|
30
|
+
message: string;
|
|
31
|
+
remediation?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface DiagnosticBundle {
|
|
34
|
+
timestamp: string;
|
|
35
|
+
cliVersion: string;
|
|
36
|
+
specVersion: string;
|
|
37
|
+
platform: string;
|
|
38
|
+
nodeVersion: string;
|
|
39
|
+
checks: CheckResult[];
|
|
40
|
+
config: Partial<EvalAIConfig> & {
|
|
41
|
+
path?: string | null;
|
|
42
|
+
};
|
|
43
|
+
baseline: {
|
|
44
|
+
path: string;
|
|
45
|
+
exists: boolean;
|
|
46
|
+
hash?: string;
|
|
47
|
+
schemaVersion?: number;
|
|
48
|
+
stale?: boolean;
|
|
49
|
+
} | null;
|
|
50
|
+
api: {
|
|
51
|
+
reachable: boolean;
|
|
52
|
+
latencyMs?: number;
|
|
53
|
+
scopes?: string[];
|
|
54
|
+
} | null;
|
|
55
|
+
ci: {
|
|
56
|
+
workflowPath: string;
|
|
57
|
+
exists: boolean;
|
|
58
|
+
} | null;
|
|
59
|
+
overall: "ready" | "not_ready" | "infra_error";
|
|
60
|
+
}
|
|
61
|
+
export interface DoctorFlags {
|
|
62
|
+
report: boolean;
|
|
63
|
+
format: "human" | "json";
|
|
64
|
+
strict: boolean;
|
|
65
|
+
baseUrl: string;
|
|
66
|
+
apiKey: string;
|
|
67
|
+
evaluationId: string;
|
|
68
|
+
baseline: "published" | "previous" | "production";
|
|
69
|
+
}
|
|
70
|
+
export declare function checkProject(cwd: string): CheckResult;
|
|
71
|
+
export declare function checkConfig(cwd: string): CheckResult & {
|
|
72
|
+
config: EvalAIConfig | null;
|
|
73
|
+
configPath: string | null;
|
|
74
|
+
};
|
|
75
|
+
export declare function checkBaseline(cwd: string): CheckResult & {
|
|
76
|
+
baselineInfo: DiagnosticBundle["baseline"];
|
|
77
|
+
};
|
|
78
|
+
export declare function checkAuth(apiKey: string): CheckResult;
|
|
79
|
+
export declare function checkConnectivity(baseUrl: string, apiKey: string): Promise<CheckResult & {
|
|
80
|
+
latencyMs?: number;
|
|
81
|
+
}>;
|
|
82
|
+
export declare function checkEvalTarget(evaluationId: string): CheckResult;
|
|
83
|
+
export declare function checkEvalAccess(baseUrl: string, apiKey: string, evaluationId: string, baseline: string): Promise<CheckResult>;
|
|
84
|
+
export declare function checkCiWiring(cwd: string): CheckResult & {
|
|
85
|
+
ciInfo: DiagnosticBundle["ci"];
|
|
86
|
+
};
|
|
87
|
+
export declare function checkProviderEnv(): CheckResult;
|
|
88
|
+
export declare function runDoctor(argv: string[]): Promise<number>;
|