agentv 5.3.1-next.1 → 5.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.
Files changed (66) hide show
  1. package/README.md +52 -44
  2. package/dist/{artifact-writer-7NBCOAYC.js → artifact-writer-KJEOROKQ.js} +5 -5
  3. package/dist/{chunk-ELCJ23K4.js → chunk-6262OKXM.js} +2856 -2404
  4. package/dist/chunk-6262OKXM.js.map +1 -0
  5. package/dist/{chunk-LKGARI3W.js → chunk-6RFRY7X2.js} +812 -570
  6. package/dist/chunk-6RFRY7X2.js.map +1 -0
  7. package/dist/chunk-AQ5BIAXF.js +604 -0
  8. package/dist/chunk-AQ5BIAXF.js.map +1 -0
  9. package/dist/chunk-BV5VQLI2.js +2 -0
  10. package/dist/{chunk-LXBI3SPX.js → chunk-JGSRUJZQ.js} +46 -20
  11. package/dist/chunk-JGSRUJZQ.js.map +1 -0
  12. package/dist/chunk-MMDLXYBX.js +721 -0
  13. package/dist/chunk-MMDLXYBX.js.map +1 -0
  14. package/dist/chunk-TEEXVJWM.js +2 -0
  15. package/dist/{chunk-RKE7SSET.js → chunk-WIAJ7JAV.js} +186 -64
  16. package/dist/chunk-WIAJ7JAV.js.map +1 -0
  17. package/dist/cli.d.ts +1 -0
  18. package/dist/cli.js +17517 -10
  19. package/dist/cli.js.map +1 -1
  20. package/dist/config.d.ts +2 -0
  21. package/dist/config.js +14 -0
  22. package/dist/config.js.map +1 -0
  23. package/dist/contracts-DsZmZLl8.d.ts +742 -0
  24. package/dist/contracts.d.ts +2 -0
  25. package/dist/contracts.js +28 -0
  26. package/dist/contracts.js.map +1 -0
  27. package/dist/dashboard/assets/{index-CbEMiJSb.js → index-BfqOlLOF.js} +1 -1
  28. package/dist/dashboard/assets/index-Bh8lpGce.css +1 -0
  29. package/dist/dashboard/assets/index-oPR3ywQb.js +121 -0
  30. package/dist/dashboard/index.html +2 -2
  31. package/dist/{dist-NMXMI5SK.js → dist-A3SGR7TW.js} +16 -16
  32. package/dist/dist-A3SGR7TW.js.map +1 -0
  33. package/dist/index.d.ts +4 -0
  34. package/dist/index.js +137 -18
  35. package/dist/{interactive-BN527UV3.js → interactive-WPQJDJKZ.js} +24 -24
  36. package/dist/interactive-WPQJDJKZ.js.map +1 -0
  37. package/dist/provider.d.ts +2 -0
  38. package/dist/provider.js +24 -0
  39. package/dist/provider.js.map +1 -0
  40. package/dist/sdk.d.ts +802 -0
  41. package/dist/sdk.js +145 -0
  42. package/dist/sdk.js.map +1 -0
  43. package/dist/skills/agentv-eval-migrations/references/breaking-changes.md +17 -18
  44. package/dist/skills/agentv-eval-writer/SKILL.md +27 -15
  45. package/dist/skills/agentv-eval-writer/references/custom-evaluators.md +5 -5
  46. package/dist/skills/agentv-eval-writer/references/eval.schema.json +5402 -4639
  47. package/dist/skills/agentv-eval-writer/references/python-helpers.md +2 -2
  48. package/dist/skills/agentv-eval-writer/references/rubric-evaluator.md +19 -2
  49. package/dist/templates/.agentv/providers.yaml +42 -0
  50. package/dist/templates/.env.example +2 -2
  51. package/dist/{ts-eval-loader-2RFVZHCT-7CZ3DCDD.js → ts-eval-loader-3G5GEAEC-6F52JLPP.js} +3 -3
  52. package/dist/ts-eval-loader-3G5GEAEC-6F52JLPP.js.map +1 -0
  53. package/package.json +29 -4
  54. package/dist/chunk-ASIGJIOJ.js +0 -17993
  55. package/dist/chunk-ASIGJIOJ.js.map +0 -1
  56. package/dist/chunk-ELCJ23K4.js.map +0 -1
  57. package/dist/chunk-LKGARI3W.js.map +0 -1
  58. package/dist/chunk-LXBI3SPX.js.map +0 -1
  59. package/dist/chunk-RKE7SSET.js.map +0 -1
  60. package/dist/dashboard/assets/index-DTA6-l7q.js +0 -121
  61. package/dist/dashboard/assets/index-D_bokML8.css +0 -1
  62. package/dist/interactive-BN527UV3.js.map +0 -1
  63. package/dist/templates/.agentv/targets.yaml +0 -97
  64. /package/dist/{artifact-writer-7NBCOAYC.js.map → artifact-writer-KJEOROKQ.js.map} +0 -0
  65. /package/dist/{dist-NMXMI5SK.js.map → chunk-BV5VQLI2.js.map} +0 -0
  66. /package/dist/{ts-eval-loader-2RFVZHCT-7CZ3DCDD.js.map → chunk-TEEXVJWM.js.map} +0 -0
@@ -0,0 +1,604 @@
1
+ import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
+ import {
3
+ external_exports,
4
+ toCamelCaseDeep
5
+ } from "./chunk-6262OKXM.js";
6
+
7
+ // ../../packages/core/dist/script-grader.js
8
+ import { readFileSync } from "node:fs";
9
+ import { spawn } from "node:child_process";
10
+ import { copyFile, mkdtemp, readFile, rm } from "node:fs/promises";
11
+ import { tmpdir } from "node:os";
12
+ import nodePath from "node:path";
13
+ var TokenUsageSchema = external_exports.object({
14
+ input: external_exports.number(),
15
+ output: external_exports.number(),
16
+ cached: external_exports.number().optional(),
17
+ reasoning: external_exports.number().optional()
18
+ });
19
+ var TraceSummarySchema = external_exports.object({
20
+ eventCount: external_exports.number(),
21
+ toolCalls: external_exports.record(external_exports.string(), external_exports.number()),
22
+ errorCount: external_exports.number(),
23
+ toolDurations: external_exports.record(external_exports.string(), external_exports.array(external_exports.number())).optional(),
24
+ llmCallCount: external_exports.number().optional()
25
+ });
26
+ var TRACE_SOURCE_KINDS = [
27
+ "agentv_run",
28
+ "otlp",
29
+ "phoenix",
30
+ "langfuse",
31
+ "pi_session",
32
+ "imported_transcript",
33
+ "compact_transcript"
34
+ ];
35
+ var TRACE_EVENT_TYPES = [
36
+ "message",
37
+ "model_turn",
38
+ "tool_call",
39
+ "tool_result",
40
+ "final_response",
41
+ "error"
42
+ ];
43
+ var TRACE_TOOL_STATUSES = ["ok", "error", "timeout", "cancelled", "unknown"];
44
+ var TRACE_REDACTION_LEVELS = ["none", "partial", "full"];
45
+ var MetadataSchema = external_exports.record(external_exports.string(), external_exports.unknown());
46
+ var TraceRedactionStateSchema = external_exports.object({
47
+ level: external_exports.enum(TRACE_REDACTION_LEVELS),
48
+ fields: external_exports.array(external_exports.string()).optional(),
49
+ reason: external_exports.string().optional()
50
+ });
51
+ var TraceErrorSchema = external_exports.object({
52
+ message: external_exports.string(),
53
+ name: external_exports.string().optional(),
54
+ code: external_exports.string().optional(),
55
+ stack: external_exports.string().optional(),
56
+ metadata: MetadataSchema.optional()
57
+ });
58
+ var TraceSourceSchema = external_exports.object({
59
+ kind: external_exports.enum(TRACE_SOURCE_KINDS),
60
+ path: external_exports.string().optional(),
61
+ url: external_exports.string().optional(),
62
+ provider: external_exports.string().optional(),
63
+ format: external_exports.string().optional(),
64
+ version: external_exports.string().optional(),
65
+ metadata: MetadataSchema.optional()
66
+ });
67
+ var TraceSessionSchema = external_exports.object({
68
+ sessionId: external_exports.string().optional(),
69
+ conversationId: external_exports.string().optional(),
70
+ cwd: external_exports.string().optional(),
71
+ startedAt: external_exports.string().optional(),
72
+ endedAt: external_exports.string().optional(),
73
+ metadata: MetadataSchema.optional()
74
+ });
75
+ var TraceBranchSchema = external_exports.object({
76
+ selectedLeafId: external_exports.string().optional(),
77
+ selectedPathIds: external_exports.array(external_exports.string()).optional(),
78
+ includedEventIds: external_exports.array(external_exports.string()).optional(),
79
+ omittedEventIds: external_exports.array(external_exports.string()).optional(),
80
+ selectionReason: external_exports.string().optional()
81
+ });
82
+ var TraceSourceRefSchema = external_exports.object({
83
+ eventId: external_exports.string().optional(),
84
+ messageId: external_exports.string().optional(),
85
+ spanId: external_exports.string().optional(),
86
+ traceId: external_exports.string().optional(),
87
+ rawKind: external_exports.string().optional(),
88
+ path: external_exports.string().optional(),
89
+ line: external_exports.number().int().nonnegative().optional(),
90
+ metadata: MetadataSchema.optional()
91
+ });
92
+ var TraceRawEvidenceSchema = external_exports.object({
93
+ kind: external_exports.string(),
94
+ ref: external_exports.string().optional(),
95
+ mediaType: external_exports.string().optional(),
96
+ content: external_exports.unknown().optional(),
97
+ redacted: external_exports.boolean().optional(),
98
+ metadata: MetadataSchema.optional()
99
+ });
100
+ var TraceMessageSchema = external_exports.object({
101
+ role: external_exports.string(),
102
+ name: external_exports.string().optional(),
103
+ content: external_exports.unknown().optional(),
104
+ redaction: TraceRedactionStateSchema.optional(),
105
+ tokenUsage: TokenUsageSchema.optional(),
106
+ metadata: MetadataSchema.optional()
107
+ });
108
+ var TraceModelSchema = external_exports.object({
109
+ provider: external_exports.string().optional(),
110
+ name: external_exports.string().optional(),
111
+ invocationId: external_exports.string().optional(),
112
+ tokenUsage: TokenUsageSchema.optional(),
113
+ metadata: MetadataSchema.optional()
114
+ });
115
+ var TraceToolSchema = external_exports.object({
116
+ name: external_exports.string(),
117
+ callId: external_exports.string().optional(),
118
+ input: external_exports.unknown().optional(),
119
+ output: external_exports.unknown().optional(),
120
+ status: external_exports.enum(TRACE_TOOL_STATUSES).optional(),
121
+ error: TraceErrorSchema.optional(),
122
+ redaction: TraceRedactionStateSchema.optional(),
123
+ metadata: MetadataSchema.optional()
124
+ });
125
+ var TraceEventSchema = external_exports.object({
126
+ eventId: external_exports.string(),
127
+ parentEventId: external_exports.string().optional(),
128
+ ordinal: external_exports.number().int().nonnegative(),
129
+ type: external_exports.enum(TRACE_EVENT_TYPES),
130
+ timestamp: external_exports.string().optional(),
131
+ durationMs: external_exports.number().nonnegative().optional(),
132
+ durationInferred: external_exports.boolean().optional(),
133
+ turnIndex: external_exports.number().int().nonnegative().optional(),
134
+ message: TraceMessageSchema.optional(),
135
+ model: TraceModelSchema.optional(),
136
+ tool: TraceToolSchema.optional(),
137
+ error: TraceErrorSchema.optional(),
138
+ sourceRef: TraceSourceRefSchema.optional(),
139
+ rawEvidence: external_exports.array(TraceRawEvidenceSchema).optional(),
140
+ redaction: TraceRedactionStateSchema.optional(),
141
+ metadata: MetadataSchema.optional()
142
+ });
143
+ var TraceArtifactSchema = external_exports.object({
144
+ source: TraceSourceSchema,
145
+ session: TraceSessionSchema,
146
+ branch: TraceBranchSchema.optional(),
147
+ events: external_exports.array(TraceEventSchema),
148
+ tokenUsage: TokenUsageSchema.optional(),
149
+ costUsd: external_exports.number().optional(),
150
+ durationMs: external_exports.number().optional(),
151
+ startedAt: external_exports.string().optional(),
152
+ endedAt: external_exports.string().optional(),
153
+ metadata: MetadataSchema.optional()
154
+ });
155
+ var ToolCallSchema = external_exports.object({
156
+ tool: external_exports.string(),
157
+ input: external_exports.unknown().optional(),
158
+ output: external_exports.unknown().optional(),
159
+ id: external_exports.string().optional(),
160
+ startTime: external_exports.string().optional(),
161
+ endTime: external_exports.string().optional(),
162
+ durationMs: external_exports.number().optional()
163
+ });
164
+ var ContentTextSchema = external_exports.object({
165
+ type: external_exports.literal("text"),
166
+ text: external_exports.string()
167
+ });
168
+ var ContentImageSchema = external_exports.object({
169
+ type: external_exports.literal("image"),
170
+ media_type: external_exports.string(),
171
+ path: external_exports.string()
172
+ });
173
+ var ContentFileSchema = external_exports.object({
174
+ type: external_exports.literal("file"),
175
+ media_type: external_exports.string(),
176
+ path: external_exports.string()
177
+ });
178
+ var ContentSchema = external_exports.discriminatedUnion("type", [
179
+ ContentTextSchema,
180
+ ContentImageSchema,
181
+ ContentFileSchema
182
+ ]);
183
+ var MessageContentBlockSchema = external_exports.union([ContentSchema, external_exports.record(external_exports.unknown())]);
184
+ var MessageSchema = external_exports.object({
185
+ role: external_exports.enum(["assistant", "user", "system", "tool"]),
186
+ content: external_exports.union([external_exports.string(), external_exports.array(MessageContentBlockSchema), external_exports.record(external_exports.unknown())]).optional(),
187
+ toolCalls: external_exports.array(ToolCallSchema).optional(),
188
+ name: external_exports.string().optional(),
189
+ startTime: external_exports.string().optional(),
190
+ endTime: external_exports.string().optional(),
191
+ durationMs: external_exports.number().optional(),
192
+ metadata: external_exports.record(external_exports.unknown()).optional()
193
+ });
194
+ var TraceSchema = TraceSummarySchema.extend({
195
+ messages: external_exports.array(MessageSchema),
196
+ events: external_exports.array(TraceEventSchema),
197
+ tokenUsage: TokenUsageSchema.optional(),
198
+ costUsd: external_exports.number().optional(),
199
+ durationMs: external_exports.number().optional(),
200
+ startTime: external_exports.string().optional(),
201
+ endTime: external_exports.string().optional(),
202
+ metadata: MetadataSchema.optional()
203
+ });
204
+ var ScriptGraderInputSchema = external_exports.object({
205
+ criteria: external_exports.string(),
206
+ expectedOutput: external_exports.array(MessageSchema),
207
+ output: external_exports.string().nullable().optional(),
208
+ messages: external_exports.array(MessageSchema).optional().default([]),
209
+ /** Path to a temp file containing the output JSON (used for large payloads). */
210
+ outputPath: external_exports.string().optional(),
211
+ inputFiles: external_exports.array(external_exports.string()),
212
+ input: external_exports.array(MessageSchema),
213
+ metadata: external_exports.record(external_exports.unknown()).nullable().optional(),
214
+ trace: TraceSchema.nullable().optional(),
215
+ traceSummary: TraceSummarySchema.nullable().optional(),
216
+ tokenUsage: TokenUsageSchema.nullable().optional(),
217
+ costUsd: external_exports.number().nullable().optional(),
218
+ durationMs: external_exports.number().nullable().optional(),
219
+ startTime: external_exports.string().nullable().optional(),
220
+ endTime: external_exports.string().nullable().optional(),
221
+ fileChanges: external_exports.string().nullable().optional(),
222
+ workspacePath: external_exports.string().nullable().optional(),
223
+ config: external_exports.record(external_exports.unknown()).nullable().optional()
224
+ });
225
+ var ScriptGraderCheckSchema = external_exports.object({
226
+ id: external_exports.string().optional(),
227
+ text: external_exports.string(),
228
+ pass: external_exports.boolean(),
229
+ score: external_exports.number().min(0).max(1).optional(),
230
+ reason: external_exports.string(),
231
+ evidence: external_exports.string().optional()
232
+ });
233
+ var ScriptGraderResultSchema = external_exports.object({
234
+ pass: external_exports.boolean(),
235
+ score: external_exports.number().min(0).max(1),
236
+ reason: external_exports.string(),
237
+ checks: external_exports.array(ScriptGraderCheckSchema).optional().default([]),
238
+ /** Optional structured details for domain-specific metrics (e.g., TP/TN/FP/FN counts, alignments). */
239
+ details: external_exports.record(external_exports.unknown()).optional()
240
+ });
241
+ var PromptTemplateInputSchema = ScriptGraderInputSchema;
242
+ var CodeGraderInputSchema = ScriptGraderInputSchema;
243
+ var CodeGraderResultSchema = ScriptGraderResultSchema;
244
+ function readStdin() {
245
+ return readFileSync(0, "utf8");
246
+ }
247
+ function clampScore(value) {
248
+ if (Number.isNaN(value) || !Number.isFinite(value)) {
249
+ return 0;
250
+ }
251
+ return Math.max(0, Math.min(1, value));
252
+ }
253
+ function formatError(error) {
254
+ if (error instanceof Error) {
255
+ return error.message;
256
+ }
257
+ return String(error);
258
+ }
259
+ async function runScriptGrader(handler) {
260
+ try {
261
+ const stdin = readStdin();
262
+ const rawInput = JSON.parse(stdin);
263
+ const camelInput = toCamelCaseDeep(rawInput);
264
+ const input = ScriptGraderInputSchema.parse(camelInput);
265
+ if (input.outputPath && (input.output === null || input.output === void 0)) {
266
+ let cachedOutput;
267
+ const filePath = input.outputPath;
268
+ Object.defineProperty(input, "output", {
269
+ get() {
270
+ if (cachedOutput === void 0) {
271
+ cachedOutput = JSON.parse(readFileSync(filePath, "utf8"));
272
+ }
273
+ return cachedOutput;
274
+ },
275
+ configurable: true,
276
+ enumerable: true
277
+ });
278
+ }
279
+ const rawResult = await handler(input);
280
+ const result = ScriptGraderResultSchema.parse({
281
+ ...rawResult,
282
+ score: clampScore(rawResult.score),
283
+ checks: rawResult.checks?.map((check) => ({
284
+ ...check,
285
+ ...check.score !== void 0 ? { score: clampScore(check.score) } : {}
286
+ }))
287
+ });
288
+ console.log(JSON.stringify(result, null, 2));
289
+ } catch (error) {
290
+ const errorMessage = formatError(error);
291
+ const errorResult = {
292
+ pass: false,
293
+ score: 0,
294
+ reason: `Evaluation failed: ${errorMessage}`,
295
+ checks: [
296
+ {
297
+ text: "Script grader execution",
298
+ pass: false,
299
+ reason: errorMessage
300
+ }
301
+ ]
302
+ };
303
+ console.log(JSON.stringify(errorResult, null, 2));
304
+ process.exit(1);
305
+ }
306
+ }
307
+ var runCodeGrader = runScriptGrader;
308
+ function workspacePathFrom(input) {
309
+ const workspacePath = input.workspacePath ?? process.env.AGENTV_WORKSPACE_PATH;
310
+ return workspacePath?.trim() ? workspacePath : void 0;
311
+ }
312
+ function truncate(value, maxLength = 2e3) {
313
+ if (value.length <= maxLength) {
314
+ return value;
315
+ }
316
+ return `${value.slice(0, maxLength)}
317
+ ...(truncated)`;
318
+ }
319
+ function resolveInsideWorkspace(workspacePath, relativePath, label, options = {}) {
320
+ if (!relativePath.trim()) {
321
+ throw new Error(`${label} must not be empty.`);
322
+ }
323
+ if (nodePath.isAbsolute(relativePath)) {
324
+ throw new Error(`${label} must be relative to the workspace: ${relativePath}`);
325
+ }
326
+ const root = nodePath.resolve(workspacePath);
327
+ const resolvedPath = nodePath.resolve(root, relativePath);
328
+ const relativeToRoot = nodePath.relative(root, resolvedPath);
329
+ if (relativeToRoot === "" && options.allowRoot === true) {
330
+ return resolvedPath;
331
+ }
332
+ if (relativeToRoot === "" || relativeToRoot.startsWith("..") || nodePath.isAbsolute(relativeToRoot)) {
333
+ throw new Error(`${label} must stay inside the workspace: ${relativePath}`);
334
+ }
335
+ return resolvedPath;
336
+ }
337
+ function normalizeTestFiles(testFile) {
338
+ if (testFile === void 0) {
339
+ return [];
340
+ }
341
+ return typeof testFile === "string" ? [testFile] : [...testFile];
342
+ }
343
+ function buildCommand(options, testFiles = normalizeTestFiles(options.testFile)) {
344
+ if (options.command && options.command.length > 0) {
345
+ return [...options.command];
346
+ }
347
+ const command = [...options.vitestCommand ?? ["bunx", "vitest", "run"]];
348
+ command.push(...testFiles);
349
+ return command;
350
+ }
351
+ function parseJsonObjectFromText(text) {
352
+ const trimmed = text.trim();
353
+ if (!trimmed) {
354
+ return void 0;
355
+ }
356
+ try {
357
+ return JSON.parse(trimmed);
358
+ } catch {
359
+ const start = trimmed.indexOf("{");
360
+ const end = trimmed.lastIndexOf("}");
361
+ if (start >= 0 && end > start) {
362
+ return JSON.parse(trimmed.slice(start, end + 1));
363
+ }
364
+ throw new Error("Vitest output did not contain a JSON object.");
365
+ }
366
+ }
367
+ function isVitestJsonReport(value) {
368
+ return typeof value === "object" && value !== null && Array.isArray(value.testResults);
369
+ }
370
+ function assertionText(file, assertion) {
371
+ const title = assertion.fullName ?? [...assertion.ancestorTitles ?? [], assertion.title].filter(Boolean).join(" ");
372
+ return title || file.name || "Vitest assertion";
373
+ }
374
+ function vitestReportToScriptGraderResult(report, options = {}) {
375
+ const checks = (report.testResults ?? []).flatMap(
376
+ (file) => (file.assertionResults ?? []).map((item) => {
377
+ const pass2 = item.status === "passed";
378
+ const evidence = item.failureMessages && item.failureMessages.length > 0 ? truncate(item.failureMessages.join("\n\n")) : void 0;
379
+ return {
380
+ text: assertionText(file, item),
381
+ pass: pass2,
382
+ reason: pass2 ? "Vitest test passed." : "Vitest test failed.",
383
+ ...evidence !== void 0 ? { evidence } : {}
384
+ };
385
+ })
386
+ );
387
+ if (checks.length === 0) {
388
+ const pass2 = options.passWithNoTests === true;
389
+ return ScriptGraderResultSchema.parse({
390
+ pass: pass2,
391
+ score: pass2 ? 1 : 0,
392
+ reason: pass2 ? "Vitest reported no tests; configured to pass." : "Vitest reported no tests.",
393
+ checks: [
394
+ {
395
+ text: "Vitest reported no tests",
396
+ pass: pass2,
397
+ reason: pass2 ? "passWithNoTests is enabled." : "No Vitest tests were discovered."
398
+ }
399
+ ],
400
+ details: {
401
+ vitest_success: report.success ?? false,
402
+ num_total_tests: report.numTotalTests ?? 0,
403
+ num_passed_tests: report.numPassedTests ?? 0,
404
+ num_failed_tests: report.numFailedTests ?? 0,
405
+ num_pending_tests: report.numPendingTests ?? 0,
406
+ num_todo_tests: report.numTodoTests ?? 0
407
+ }
408
+ });
409
+ }
410
+ const passedCount = checks.filter((item) => item.pass).length;
411
+ const pass = passedCount === checks.length;
412
+ return ScriptGraderResultSchema.parse({
413
+ pass,
414
+ score: passedCount / checks.length,
415
+ reason: `${passedCount}/${checks.length} Vitest tests passed.`,
416
+ checks,
417
+ details: {
418
+ vitest_success: report.success ?? pass,
419
+ num_total_tests: report.numTotalTests ?? checks.length,
420
+ num_passed_tests: report.numPassedTests ?? passedCount,
421
+ num_failed_tests: report.numFailedTests ?? checks.length - passedCount,
422
+ num_pending_tests: report.numPendingTests ?? 0,
423
+ num_todo_tests: report.numTodoTests ?? 0
424
+ }
425
+ });
426
+ }
427
+ var vitestReportToCodeGraderResult = vitestReportToScriptGraderResult;
428
+ function runCommand(command, options) {
429
+ if (command.length === 0) {
430
+ return Promise.reject(new Error("Vitest command must not be empty."));
431
+ }
432
+ return new Promise((resolve, reject) => {
433
+ const child = spawn(command[0], command.slice(1), {
434
+ cwd: options.cwd,
435
+ env: { ...process.env, ...options.env },
436
+ stdio: ["ignore", "pipe", "pipe"]
437
+ });
438
+ let stdout = "";
439
+ let stderr = "";
440
+ let timedOut = false;
441
+ const timeout = options.timeoutMs !== void 0 ? setTimeout(() => {
442
+ timedOut = true;
443
+ child.kill("SIGTERM");
444
+ }, options.timeoutMs) : void 0;
445
+ child.stdout.setEncoding("utf8");
446
+ child.stderr.setEncoding("utf8");
447
+ child.stdout.on("data", (chunk) => {
448
+ stdout += chunk;
449
+ });
450
+ child.stderr.on("data", (chunk) => {
451
+ stderr += chunk;
452
+ });
453
+ child.on("error", reject);
454
+ child.on("close", (exitCode) => {
455
+ if (timeout) {
456
+ clearTimeout(timeout);
457
+ }
458
+ if (timedOut) {
459
+ reject(new Error(`Vitest command timed out after ${options.timeoutMs}ms.`));
460
+ return;
461
+ }
462
+ resolve({ exitCode, stdout, stderr });
463
+ });
464
+ });
465
+ }
466
+ function resolveSourceTestFile(testFileRoot, testFile) {
467
+ if (!testFile.trim()) {
468
+ throw new Error("testFile entries must not be empty.");
469
+ }
470
+ return nodePath.isAbsolute(testFile) ? nodePath.resolve(testFile) : nodePath.resolve(testFileRoot, testFile);
471
+ }
472
+ async function copyTestFilesIntoWorkspace(testFiles, options, cwd) {
473
+ if (testFiles.length === 0) {
474
+ return { testFiles };
475
+ }
476
+ const tempDir = await mkdtemp(nodePath.join(cwd, ".agentv-vitest-"));
477
+ const testFileRoot = nodePath.resolve(options.testFileRoot ?? process.cwd());
478
+ const copiedFiles = await Promise.all(
479
+ testFiles.map(async (testFile, index) => {
480
+ const sourcePath = resolveSourceTestFile(testFileRoot, testFile);
481
+ const destinationPath = nodePath.join(tempDir, `${index}-${nodePath.basename(testFile)}`);
482
+ await copyFile(sourcePath, destinationPath);
483
+ return nodePath.relative(cwd, destinationPath);
484
+ })
485
+ );
486
+ return { testFiles: copiedFiles, tempDir };
487
+ }
488
+ async function readVitestReport(commandResult, outputFile) {
489
+ const rawReport = outputFile !== void 0 ? await readFile(outputFile, "utf8") : commandResult.stdout;
490
+ const parsed = parseJsonObjectFromText(rawReport);
491
+ if (!isVitestJsonReport(parsed)) {
492
+ throw new Error("Vitest JSON report did not include testResults[].");
493
+ }
494
+ return parsed;
495
+ }
496
+ async function runVitestWorkspaceGrader(options, input) {
497
+ const workspacePath = workspacePathFrom(input);
498
+ if (!workspacePath) {
499
+ return {
500
+ pass: false,
501
+ score: 0,
502
+ reason: "Vitest workspace verifier requires workspace_path.",
503
+ checks: [
504
+ {
505
+ text: "Vitest workspace verifier requires workspace_path",
506
+ pass: false,
507
+ reason: "Configure an environment recipe in the eval YAML so AgentV can pass workspace_path."
508
+ }
509
+ ]
510
+ };
511
+ }
512
+ const tempDirs = [];
513
+ try {
514
+ const cwd = options.cwd ? resolveInsideWorkspace(workspacePath, options.cwd, "cwd", { allowRoot: true }) : workspacePath;
515
+ const testFiles = normalizeTestFiles(options.testFile);
516
+ const preparedTestFiles = options.copyTestFilesToWorkspace === true ? await copyTestFilesIntoWorkspace(testFiles, options, cwd) : { testFiles };
517
+ if (preparedTestFiles.tempDir) {
518
+ tempDirs.push(preparedTestFiles.tempDir);
519
+ }
520
+ const command = buildCommand(options, preparedTestFiles.testFiles);
521
+ const appendReporterArgs = options.appendReporterArgs ?? options.command === void 0;
522
+ let outputFile = options.outputFile ? resolveInsideWorkspace(cwd, options.outputFile, "outputFile") : void 0;
523
+ if (appendReporterArgs) {
524
+ const tempDir = await mkdtemp(nodePath.join(tmpdir(), "agentv-vitest-"));
525
+ tempDirs.push(tempDir);
526
+ outputFile = nodePath.join(tempDir, "results.json");
527
+ command.push("--reporter=json", `--outputFile=${outputFile}`);
528
+ }
529
+ const result = await runCommand(command, {
530
+ cwd,
531
+ timeoutMs: options.timeoutMs,
532
+ env: {
533
+ AGENTV_WORKSPACE_PATH: workspacePath,
534
+ ...outputFile !== void 0 ? { AGENTV_VITEST_JSON_PATH: outputFile } : {},
535
+ ...options.env
536
+ }
537
+ });
538
+ const report = await readVitestReport(result, outputFile);
539
+ return vitestReportToScriptGraderResult(report, options);
540
+ } catch (error) {
541
+ const reason = error instanceof Error ? error.message : String(error);
542
+ return {
543
+ pass: false,
544
+ score: 0,
545
+ reason: "Vitest workspace verifier failed to run.",
546
+ checks: [
547
+ {
548
+ text: "Vitest workspace verifier failed to run",
549
+ pass: false,
550
+ reason
551
+ }
552
+ ]
553
+ };
554
+ } finally {
555
+ for (const tempDir of tempDirs.reverse()) {
556
+ await rm(tempDir, { recursive: true, force: true }).catch(() => {
557
+ });
558
+ }
559
+ }
560
+ }
561
+ function defineVitestWorkspaceGrader(options) {
562
+ runScriptGrader((input) => runVitestWorkspaceGrader(options, input));
563
+ }
564
+
565
+ export {
566
+ TokenUsageSchema,
567
+ TraceSummarySchema,
568
+ TRACE_SOURCE_KINDS,
569
+ TRACE_EVENT_TYPES,
570
+ TRACE_TOOL_STATUSES,
571
+ TRACE_REDACTION_LEVELS,
572
+ TraceRedactionStateSchema,
573
+ TraceErrorSchema,
574
+ TraceSourceSchema,
575
+ TraceSessionSchema,
576
+ TraceBranchSchema,
577
+ TraceSourceRefSchema,
578
+ TraceRawEvidenceSchema,
579
+ TraceMessageSchema,
580
+ TraceModelSchema,
581
+ TraceToolSchema,
582
+ TraceEventSchema,
583
+ TraceArtifactSchema,
584
+ ToolCallSchema,
585
+ ContentTextSchema,
586
+ ContentImageSchema,
587
+ ContentFileSchema,
588
+ ContentSchema,
589
+ MessageSchema,
590
+ TraceSchema,
591
+ ScriptGraderInputSchema,
592
+ ScriptGraderCheckSchema,
593
+ ScriptGraderResultSchema,
594
+ PromptTemplateInputSchema,
595
+ CodeGraderInputSchema,
596
+ CodeGraderResultSchema,
597
+ runScriptGrader,
598
+ runCodeGrader,
599
+ vitestReportToScriptGraderResult,
600
+ vitestReportToCodeGraderResult,
601
+ runVitestWorkspaceGrader,
602
+ defineVitestWorkspaceGrader
603
+ };
604
+ //# sourceMappingURL=chunk-AQ5BIAXF.js.map