@cursor/july 0.1.15 → 0.1.17
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/README.md +9 -4
- package/dist/bin/agent-serve.js +60 -2
- package/dist/channels/slack/api.d.ts.map +1 -1
- package/dist/channels/slack/api.js +13 -3
- package/dist/channels/slack/auth.d.ts +7 -1
- package/dist/channels/slack/auth.d.ts.map +1 -1
- package/dist/channels/slack/auth.js +14 -0
- package/dist/channels/slack/blocks.d.ts +61 -0
- package/dist/channels/slack/blocks.d.ts.map +1 -0
- package/dist/channels/slack/blocks.js +90 -0
- package/dist/channels/slack/defaults.d.ts +2 -0
- package/dist/channels/slack/defaults.d.ts.map +1 -1
- package/dist/channels/slack/defaults.js +29 -3
- package/dist/channels/slack/dispatch.d.ts +3 -17
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/index.d.ts +1 -0
- package/dist/channels/slack/index.d.ts.map +1 -1
- package/dist/channels/slack/index.js +1 -0
- package/dist/channels/slack/interactive.d.ts +39 -3
- package/dist/channels/slack/interactive.d.ts.map +1 -1
- package/dist/channels/slack/interactive.js +152 -7
- package/dist/channels/slack/manifest.d.ts +3 -0
- package/dist/channels/slack/manifest.d.ts.map +1 -1
- package/dist/channels/slack/manifest.js +3 -0
- package/dist/channels/slack/setup.d.ts +4 -1
- package/dist/channels/slack/setup.d.ts.map +1 -1
- package/dist/channels/slack/setup.js +16 -2
- package/dist/channels/slack/slack-channel.d.ts.map +1 -1
- package/dist/channels/slack/slack-channel.js +24 -3
- package/dist/channels/slack/types.d.ts +77 -0
- package/dist/channels/slack/types.d.ts.map +1 -1
- package/dist/connections.d.ts +4 -1
- package/dist/connections.d.ts.map +1 -1
- package/dist/connections.js +4 -1
- package/dist/docs/404.html +2 -2
- package/dist/docs/ab.html +3 -3
- package/dist/docs/assets/{app.DpdGZTLe.js → app.BbEXr2KO.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DCBsrfwP.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.IB-0QqIT.js → VPLocalSearchBox.DBEi4HDp.js} +1 -1
- package/dist/docs/assets/chunks/{theme.-fYBoNtR.js → theme.DGfptcHw.js} +2 -2
- package/dist/docs/assets/{example-agents_index.md.BPXjUtRB.js → example-agents_index.md.D2PEVSXl.js} +2 -2
- package/dist/docs/assets/{example-agents_index.md.BPXjUtRB.lean.js → example-agents_index.md.D2PEVSXl.lean.js} +1 -1
- package/dist/docs/assets/example-agents_security-reviewer.md.BZSNycMf.js +19 -0
- package/dist/docs/assets/{example-agents_security-reviewer.md.CE9v-aKm.lean.js → example-agents_security-reviewer.md.BZSNycMf.lean.js} +1 -1
- package/dist/docs/assets/{guides_mcp-oauth.md.DqmEOQY1.js → guides_mcp-oauth.md.Dd8EgSem.js} +3 -2
- package/dist/docs/assets/{guides_mcp-oauth.md.DqmEOQY1.lean.js → guides_mcp-oauth.md.Dd8EgSem.lean.js} +1 -1
- package/dist/docs/assets/{guides_slack.md.FWale6Ip.js → guides_slack.md.D_xFKlnF.js} +1 -1
- package/dist/docs/assets/{reference_connections.md.CsSr3rDz.js → reference_connections.md.B9Q3TOve.js} +12 -5
- package/dist/docs/assets/{reference_connections.md.CsSr3rDz.lean.js → reference_connections.md.B9Q3TOve.lean.js} +1 -1
- package/dist/docs/building-with-agents.html +3 -3
- package/dist/docs/concepts.html +3 -3
- package/dist/docs/deployment.html +3 -3
- package/dist/docs/evals.html +3 -3
- package/dist/docs/example-agents/approval-buddy.html +3 -3
- package/dist/docs/example-agents/benny.html +3 -3
- package/dist/docs/example-agents/bugbot.html +3 -3
- package/dist/docs/example-agents/codebase-wiki.html +3 -3
- package/dist/docs/example-agents/codeowners-review.html +3 -3
- package/dist/docs/example-agents/concierge.html +3 -3
- package/dist/docs/example-agents/fsd.html +3 -3
- package/dist/docs/example-agents/index.html +5 -5
- package/dist/docs/example-agents/knowledge-base.html +3 -3
- package/dist/docs/example-agents/oncall.html +3 -3
- package/dist/docs/example-agents/security-reviewer.html +14 -14
- package/dist/docs/example-agents/slack-agent.html +3 -3
- package/dist/docs/example-agents/weather-agent.html +3 -3
- package/dist/docs/guides/agent-to-agent.html +3 -3
- package/dist/docs/guides/cloud-runtime.html +3 -3
- package/dist/docs/guides/github.html +3 -3
- package/dist/docs/guides/human-in-the-loop.html +3 -3
- package/dist/docs/guides/mcp-oauth.html +6 -5
- package/dist/docs/guides/slack.html +5 -5
- package/dist/docs/guides/webhooks.html +3 -3
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +3 -3
- package/dist/docs/index.html +3 -3
- package/dist/docs/quickstart.html +3 -3
- package/dist/docs/reference/agent-config.html +3 -3
- package/dist/docs/reference/channels.html +3 -3
- package/dist/docs/reference/cli.html +3 -3
- package/dist/docs/reference/connections.html +14 -7
- package/dist/docs/reference/hooks.html +3 -3
- package/dist/docs/reference/http-api.html +3 -3
- package/dist/docs/reference/instructions.html +3 -3
- package/dist/docs/reference/playground.html +3 -3
- package/dist/docs/reference/project-layout.html +3 -3
- package/dist/docs/reference/prompt.html +3 -3
- package/dist/docs/reference/schedules.html +3 -3
- package/dist/docs/reference/sessions.html +3 -3
- package/dist/docs/reference/skills.html +3 -3
- package/dist/docs/reference/subagents.html +3 -3
- package/dist/docs/reference/tools.html +3 -3
- package/dist/docs/scaffolding-agents.html +3 -3
- package/dist/docs/storage.html +3 -3
- package/dist/docs/troubleshooting.html +3 -3
- package/dist/evals/assertions.d.ts +190 -0
- package/dist/evals/assertions.d.ts.map +1 -0
- package/dist/evals/assertions.js +461 -0
- package/dist/evals/expect.d.ts +95 -0
- package/dist/evals/expect.d.ts.map +1 -0
- package/dist/evals/expect.js +194 -0
- package/dist/evals/judge.d.ts +133 -0
- package/dist/evals/judge.d.ts.map +1 -0
- package/dist/evals/judge.js +228 -0
- package/dist/evals/loaders.d.ts +51 -0
- package/dist/evals/loaders.d.ts.map +1 -0
- package/dist/evals/loaders.js +124 -0
- package/dist/evals/matchers.d.ts +95 -0
- package/dist/evals/matchers.d.ts.map +1 -0
- package/dist/evals/matchers.js +145 -0
- package/dist/evals/reporters.d.ts +70 -0
- package/dist/evals/reporters.d.ts.map +1 -0
- package/dist/evals/reporters.js +221 -0
- package/dist/evals/results.d.ts +103 -0
- package/dist/evals/results.d.ts.map +1 -0
- package/dist/evals/results.js +28 -0
- package/dist/evals/run-facts.d.ts +77 -0
- package/dist/evals/run-facts.d.ts.map +1 -0
- package/dist/evals/run-facts.js +187 -0
- package/dist/evals.d.ts +136 -31
- package/dist/evals.d.ts.map +1 -1
- package/dist/evals.js +76 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/cli-ax.d.ts +27 -0
- package/dist/internal/cli-ax.d.ts.map +1 -1
- package/dist/internal/cli-ax.js +90 -12
- package/dist/internal/cli-mcp.d.ts +8 -0
- package/dist/internal/cli-mcp.d.ts.map +1 -1
- package/dist/internal/cli-mcp.js +98 -0
- package/dist/internal/cli-slack.d.ts +29 -1
- package/dist/internal/cli-slack.d.ts.map +1 -1
- package/dist/internal/cli-slack.js +777 -12
- package/dist/internal/deploy-client.d.ts +7 -0
- package/dist/internal/deploy-client.d.ts.map +1 -1
- package/dist/internal/deploy-client.js +9 -0
- package/dist/internal/discovery.d.ts.map +1 -1
- package/dist/internal/discovery.js +29 -9
- package/dist/internal/distribution.d.ts.map +1 -1
- package/dist/internal/distribution.js +2 -0
- package/dist/internal/eval-judge-model.d.ts +59 -0
- package/dist/internal/eval-judge-model.d.ts.map +1 -0
- package/dist/internal/eval-judge-model.js +131 -0
- package/dist/internal/eval-run-store.d.ts.map +1 -1
- package/dist/internal/eval-run-store.js +12 -20
- package/dist/internal/eval-runner.d.ts +31 -25
- package/dist/internal/eval-runner.d.ts.map +1 -1
- package/dist/internal/eval-runner.js +332 -128
- package/dist/internal/evals-client.d.ts.map +1 -1
- package/dist/internal/evals-client.js +7 -3
- package/dist/internal/local-env.d.ts +8 -0
- package/dist/internal/local-env.d.ts.map +1 -0
- package/dist/internal/local-env.js +47 -0
- package/dist/internal/playground/static.d.ts +3 -0
- package/dist/internal/playground/static.d.ts.map +1 -1
- package/dist/internal/playground/static.js +3 -0
- package/dist/internal/run-client.d.ts +15 -0
- package/dist/internal/run-client.d.ts.map +1 -1
- package/dist/internal/run-client.js +3 -2
- package/dist/internal/sdk-runner.d.ts +36 -1
- package/dist/internal/sdk-runner.d.ts.map +1 -1
- package/dist/internal/sdk-runner.js +65 -25
- package/dist/internal/server.d.ts.map +1 -1
- package/dist/internal/server.js +10 -1
- package/dist/internal/session-engine.d.ts +18 -5
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +72 -19
- package/dist/internal/slack-provision-client.d.ts +130 -0
- package/dist/internal/slack-provision-client.d.ts.map +1 -0
- package/dist/internal/slack-provision-client.js +284 -0
- package/dist/playground/assets/cursor-icons-16-f_W_ogc-.woff2 +0 -0
- package/dist/playground/assets/index-CidizGZv.css +1 -0
- package/dist/playground/assets/index-DNqirsrK.js +85 -0
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +70 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +26 -0
- package/docs/example-agents/index.md +1 -1
- package/docs/example-agents/security-reviewer.md +23 -21
- package/docs/guides/mcp-oauth.md +10 -5
- package/docs/guides/slack.md +3 -2
- package/docs/reference/connections.md +28 -18
- package/package.json +20 -2
- package/skills/create-agent/SKILL.md +15 -7
- package/skills/debug/SKILL.md +3 -1
- package/skills/mcp-auth/SKILL.md +1 -1
- package/skills/setup-slack/SKILL.md +173 -11
- package/src/bin/agent-serve.ts +63 -2
- package/src/channels/slack/api.ts +16 -3
- package/src/channels/slack/auth.ts +16 -1
- package/src/channels/slack/blocks.ts +139 -0
- package/src/channels/slack/defaults.ts +32 -4
- package/src/channels/slack/dispatch.ts +3 -18
- package/src/channels/slack/index.ts +1 -0
- package/src/channels/slack/interactive.ts +183 -19
- package/src/channels/slack/manifest.ts +3 -0
- package/src/channels/slack/setup.ts +16 -2
- package/src/channels/slack/slack-channel.ts +37 -6
- package/src/channels/slack/types.ts +89 -0
- package/src/connections.ts +4 -1
- package/src/evals/assertions.ts +704 -0
- package/src/evals/expect.ts +272 -0
- package/src/evals/judge.ts +346 -0
- package/src/evals/loaders.ts +113 -0
- package/src/evals/matchers.ts +246 -0
- package/src/evals/reporters.ts +274 -0
- package/src/evals/results.ts +132 -0
- package/src/evals/run-facts.ts +274 -0
- package/src/evals.ts +249 -42
- package/src/index.ts +2 -0
- package/src/internal/cli-ax.ts +134 -15
- package/src/internal/cli-mcp.ts +118 -5
- package/src/internal/cli-slack.ts +993 -15
- package/src/internal/deploy-client.ts +10 -0
- package/src/internal/discovery.ts +31 -5
- package/src/internal/distribution.ts +2 -0
- package/src/internal/eval-judge-model.ts +148 -0
- package/src/internal/eval-run-store.ts +10 -14
- package/src/internal/eval-runner.ts +466 -215
- package/src/internal/evals-client.ts +14 -2
- package/src/internal/local-env.ts +53 -0
- package/src/internal/playground/static.ts +3 -0
- package/src/internal/run-client.ts +17 -1
- package/src/internal/sdk-runner.ts +103 -22
- package/src/internal/server.ts +10 -0
- package/src/internal/session-engine.ts +89 -21
- package/src/internal/slack-provision-client.ts +438 -0
- package/src/types.ts +92 -4
- package/dist/channels/slack/post-update-delivery.d.ts +0 -85
- package/dist/channels/slack/post-update-delivery.d.ts.map +0 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.D2d8CfFS.js +0 -1
- package/dist/docs/assets/example-agents_security-reviewer.md.CE9v-aKm.js +0 -19
- package/dist/internal/json-dir-store.d.ts +0 -32
- package/dist/internal/json-dir-store.d.ts.map +0 -1
- package/dist/internal/persistence-coordinator.d.ts +0 -127
- package/dist/internal/persistence-coordinator.d.ts.map +0 -1
- package/dist/persistence.d.ts +0 -184
- package/dist/persistence.d.ts.map +0 -1
- package/dist/playground/assets/cursor-icons-16-CQ50JpfO.woff2 +0 -0
- package/dist/playground/assets/index-BVMOoiek.js +0 -86
- package/dist/playground/assets/index-DYmP4b--.css +0 -1
- /package/dist/docs/assets/{guides_slack.md.FWale6Ip.lean.js → guides_slack.md.D_xFKlnF.lean.js} +0 -0
|
@@ -13,23 +13,61 @@ import { readdir } from "node:fs/promises";
|
|
|
13
13
|
import { join, relative, resolve } from "node:path";
|
|
14
14
|
import { pathToFileURL } from "node:url";
|
|
15
15
|
import type {
|
|
16
|
-
|
|
16
|
+
EvalAssertionHandle,
|
|
17
|
+
EvalAssertions,
|
|
18
|
+
} from "../evals/assertions.js";
|
|
19
|
+
import {
|
|
20
|
+
computeVerdict,
|
|
21
|
+
createAssertions,
|
|
22
|
+
EvalAssertionRecorder,
|
|
23
|
+
EvalRequireFailure,
|
|
24
|
+
EvalSkipSignal,
|
|
25
|
+
} from "../evals/assertions.js";
|
|
26
|
+
import { evaluateExpectation } from "../evals/expect.js";
|
|
27
|
+
import type {
|
|
28
|
+
EvalJudge,
|
|
29
|
+
EvalJudgeCaller,
|
|
30
|
+
EvalJudgeCallOptions,
|
|
31
|
+
EvalJudgeConfig,
|
|
32
|
+
EvalJudgeGrader,
|
|
33
|
+
} from "../evals/judge.js";
|
|
34
|
+
import {
|
|
35
|
+
EVAL_JUDGE_GRADERS,
|
|
36
|
+
EvalJudgeUnavailableError,
|
|
37
|
+
renderSubmission,
|
|
38
|
+
} from "../evals/judge.js";
|
|
39
|
+
import { EVAL_ROOT_ENV } from "../evals/loaders.js";
|
|
40
|
+
import { combineReporters } from "../evals/reporters.js";
|
|
41
|
+
import { summarizeEvalResults } from "../evals/results.js";
|
|
42
|
+
import type {
|
|
17
43
|
EvalCaseDefinition,
|
|
18
44
|
EvalConfigFile,
|
|
19
45
|
EvalDefinition,
|
|
46
|
+
EvalReporter,
|
|
47
|
+
EvalReporterTarget,
|
|
48
|
+
EvalRunResult,
|
|
49
|
+
EvalRunSummary,
|
|
20
50
|
EvalSendOptions,
|
|
21
51
|
EvalTestContext,
|
|
22
52
|
EvalTurnResult,
|
|
53
|
+
EvalVerdict,
|
|
23
54
|
Expectation,
|
|
24
55
|
} from "../evals.js";
|
|
25
56
|
import {
|
|
26
57
|
EVAL_MAX_CONCURRENCY_LIMIT,
|
|
27
58
|
expandEvalDefinition,
|
|
59
|
+
expandSummarySuiteSelection,
|
|
60
|
+
isEvalSummaryCase,
|
|
28
61
|
matchesEvalIdFilter,
|
|
29
62
|
normalizeEvalMaxConcurrency,
|
|
30
63
|
} from "../evals.js";
|
|
31
|
-
import type { SessionEvent } from "../types.js";
|
|
64
|
+
import type { ModelSetting, SessionEvent } from "../types.js";
|
|
32
65
|
import { isDefinitionOfKind } from "./brand.js";
|
|
66
|
+
import {
|
|
67
|
+
callJudgeModel,
|
|
68
|
+
EVAL_JUDGE_MODEL_ENV,
|
|
69
|
+
resolveJudgeModel,
|
|
70
|
+
} from "./eval-judge-model.js";
|
|
33
71
|
import { mapPool } from "./map-pool.js";
|
|
34
72
|
import { RunSessionTimeoutError, runSession } from "./run-client.js";
|
|
35
73
|
import { buildTrajectory } from "./trajectory.js";
|
|
@@ -43,30 +81,7 @@ export interface DiscoveredEval {
|
|
|
43
81
|
definition: EvalCaseDefinition;
|
|
44
82
|
}
|
|
45
83
|
|
|
46
|
-
export
|
|
47
|
-
id: string;
|
|
48
|
-
path: string;
|
|
49
|
-
description?: string;
|
|
50
|
-
ok: boolean;
|
|
51
|
-
assertions: EvalAssertionResult[];
|
|
52
|
-
sessionId?: string;
|
|
53
|
-
/** Messages passed to `t.send` (eval inputs). */
|
|
54
|
-
inputs: string[];
|
|
55
|
-
finalText?: string;
|
|
56
|
-
tools?: string[];
|
|
57
|
-
/** Tool calls with args/results from the trajectory. */
|
|
58
|
-
toolCalls?: Array<{
|
|
59
|
-
toolName: string;
|
|
60
|
-
args?: unknown;
|
|
61
|
-
output?: unknown;
|
|
62
|
-
isError: boolean;
|
|
63
|
-
}>;
|
|
64
|
-
error?: string;
|
|
65
|
-
logs: string[];
|
|
66
|
-
/** Structured scores from {@link import("../evals.js").EvalTestContext.metric}. */
|
|
67
|
-
metrics: Record<string, string | number>;
|
|
68
|
-
durationMs: number;
|
|
69
|
-
}
|
|
84
|
+
export type { EvalRunResult } from "../evals.js";
|
|
70
85
|
|
|
71
86
|
export interface EvalSelectionOptions {
|
|
72
87
|
filterIds?: string[];
|
|
@@ -77,6 +92,21 @@ export interface RunEvalsOptions extends EvalSelectionOptions {
|
|
|
77
92
|
projectRoot: string;
|
|
78
93
|
baseUrl: string;
|
|
79
94
|
timeoutMs?: number;
|
|
95
|
+
/** Override `evals.config.ts` `maxConcurrency` (CLI `--max-concurrency`). */
|
|
96
|
+
maxConcurrency?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Reporters attached by the caller (CLI `--junit` / `--artifacts`), in
|
|
99
|
+
* addition to the ones declared in `evals.config.ts` and on each eval.
|
|
100
|
+
*/
|
|
101
|
+
reporters?: readonly EvalReporter[];
|
|
102
|
+
/** Ignore reporters declared in config and eval files (`--skip-report`). */
|
|
103
|
+
skipReport?: boolean;
|
|
104
|
+
/** Reported to reporters so a destination can label the run. */
|
|
105
|
+
target?: EvalReporterTarget;
|
|
106
|
+
/** Treat soft threshold misses as failures when summarizing. */
|
|
107
|
+
strict?: boolean;
|
|
108
|
+
/** Injected judge model call; defaults to the Cursor SDK caller. */
|
|
109
|
+
judgeCaller?: EvalJudgeCaller;
|
|
80
110
|
bearerToken?: string;
|
|
81
111
|
/** Extra request headers (e.g. hosted engineAccess). */
|
|
82
112
|
headers?: Record<string, string>;
|
|
@@ -153,6 +183,11 @@ export async function discoverEvals(
|
|
|
153
183
|
const evals: DiscoveredEval[] = [];
|
|
154
184
|
let config: Partial<EvalConfigFile> = {};
|
|
155
185
|
|
|
186
|
+
// Fixture loaders resolve relative paths against the app root, so a dataset
|
|
187
|
+
// path reads the same however deep the eval file sits and whatever cwd the
|
|
188
|
+
// CLI ran from.
|
|
189
|
+
process.env[EVAL_ROOT_ENV] = root;
|
|
190
|
+
|
|
156
191
|
for (const abs of files) {
|
|
157
192
|
const rel = relative(evalsDir, abs).replace(/\\/g, "/");
|
|
158
193
|
if (rel === "evals.config.ts" || rel === "evals.config.js") {
|
|
@@ -166,16 +201,9 @@ export async function discoverEvals(
|
|
|
166
201
|
continue;
|
|
167
202
|
}
|
|
168
203
|
const mod = await importModule(abs);
|
|
169
|
-
const def = mod.default;
|
|
170
|
-
if (!isDefinitionOfKind(def, "eval")) {
|
|
171
|
-
throw new Error(`${rel}: default export must be defineEval({ ... })`);
|
|
172
|
-
}
|
|
173
204
|
const fileId = rel.replace(/\.eval\.(ts|js)$/, "").replace(/\/index$/, "");
|
|
174
205
|
try {
|
|
175
|
-
for (const expanded of
|
|
176
|
-
fileId,
|
|
177
|
-
def as EvalDefinition
|
|
178
|
-
)) {
|
|
206
|
+
for (const expanded of expandEvalModule(fileId, mod.default)) {
|
|
179
207
|
evals.push({
|
|
180
208
|
id: expanded.id,
|
|
181
209
|
fileId,
|
|
@@ -192,6 +220,45 @@ export async function discoverEvals(
|
|
|
192
220
|
return { evals, config };
|
|
193
221
|
}
|
|
194
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Expand one eval module's default export into runnable datapoints.
|
|
225
|
+
*
|
|
226
|
+
* A file normally exports a single `defineEval(...)`. It may instead export an
|
|
227
|
+
* **array** of them to fan out over a dataset, in which case ids come from the
|
|
228
|
+
* file name plus a zero-padded index in array order (`sql/0000`, `sql/0001`, …).
|
|
229
|
+
* Prefer `cases` when the datapoints are hand-written and deserve stable names;
|
|
230
|
+
* the array form is for generated datasets where the index *is* the name.
|
|
231
|
+
*/
|
|
232
|
+
export function expandEvalModule(
|
|
233
|
+
fileId: string,
|
|
234
|
+
defaultExport: unknown
|
|
235
|
+
): Array<{ id: string; definition: EvalCaseDefinition }> {
|
|
236
|
+
if (Array.isArray(defaultExport)) {
|
|
237
|
+
if (defaultExport.length === 0) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
"default export array is empty; export at least one defineEval({ ... })"
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return defaultExport.flatMap((entry, index) => {
|
|
243
|
+
if (!isDefinitionOfKind(entry, "eval")) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`default export array entry ${index} must be defineEval({ ... })`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
return expandEvalDefinition(
|
|
249
|
+
`${fileId}/${String(index).padStart(4, "0")}`,
|
|
250
|
+
entry as EvalDefinition
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (!isDefinitionOfKind(defaultExport, "eval")) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
"default export must be defineEval({ ... }) or an array of them"
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
return expandEvalDefinition(fileId, defaultExport as EvalDefinition);
|
|
260
|
+
}
|
|
261
|
+
|
|
195
262
|
/** Apply id/tag filters used by CLI, playground, and `runDiscoveredEvals`. */
|
|
196
263
|
export function filterDiscoveredEvals(
|
|
197
264
|
evals: readonly DiscoveredEval[],
|
|
@@ -208,7 +275,10 @@ export function filterDiscoveredEvals(
|
|
|
208
275
|
(e.definition.tags ?? []).some((t) => options.tags!.includes(t))
|
|
209
276
|
);
|
|
210
277
|
}
|
|
211
|
-
|
|
278
|
+
// Suite aggregators (`summary` tag) need sibling cases from the same file.
|
|
279
|
+
return expandSummarySuiteSelection(evals, selected, (e) =>
|
|
280
|
+
isEvalSummaryCase(e.definition.tags)
|
|
281
|
+
);
|
|
212
282
|
}
|
|
213
283
|
|
|
214
284
|
export async function runDiscoveredEvals(
|
|
@@ -234,8 +304,18 @@ export async function runDiscoveredEvals(
|
|
|
234
304
|
return [];
|
|
235
305
|
}
|
|
236
306
|
|
|
237
|
-
const maxConcurrency =
|
|
307
|
+
const maxConcurrency =
|
|
308
|
+
options.maxConcurrency === undefined
|
|
309
|
+
? resolveEvalMaxConcurrency(config)
|
|
310
|
+
: normalizeEvalMaxConcurrency(options.maxConcurrency);
|
|
238
311
|
const defaultTimeoutMs = options.timeoutMs ?? config.timeoutMs ?? 180_000;
|
|
312
|
+
const reporter = buildReporterHub(options, config, selected);
|
|
313
|
+
const startedAt = new Date().toISOString();
|
|
314
|
+
|
|
315
|
+
await reporter?.runStart(
|
|
316
|
+
selected,
|
|
317
|
+
options.target ?? { baseUrl: options.baseUrl, mode: "local" }
|
|
318
|
+
);
|
|
239
319
|
|
|
240
320
|
// Iterations of the same authored datapoint share one concurrency slot and
|
|
241
321
|
// run sequentially. maxConcurrency is therefore the max number of distinct
|
|
@@ -261,19 +341,103 @@ export async function runDiscoveredEvals(
|
|
|
261
341
|
headers: options.headers,
|
|
262
342
|
verbose: Boolean(options.verbose),
|
|
263
343
|
signal: options.signal,
|
|
344
|
+
judge: {
|
|
345
|
+
configModel: config.judge?.model,
|
|
346
|
+
caller: options.judgeCaller ?? callJudgeModel,
|
|
347
|
+
},
|
|
264
348
|
onEvent: (event) => {
|
|
265
349
|
options.onCaseEvent?.(discovered.id, event);
|
|
266
350
|
options.onEvent?.(event);
|
|
267
351
|
},
|
|
268
352
|
});
|
|
269
353
|
options.onCaseDone?.(result);
|
|
354
|
+
await reporter?.caseComplete(discovered, result);
|
|
270
355
|
results.push(result);
|
|
271
356
|
}
|
|
272
357
|
return results;
|
|
273
358
|
},
|
|
274
359
|
{ signal: options.signal }
|
|
275
360
|
);
|
|
276
|
-
|
|
361
|
+
const results = nested.flat();
|
|
362
|
+
|
|
363
|
+
await reporter?.runComplete(
|
|
364
|
+
summarizeEvalResults(results, {
|
|
365
|
+
strict: options.strict === true,
|
|
366
|
+
startedAt,
|
|
367
|
+
finishedAt: new Date().toISOString(),
|
|
368
|
+
})
|
|
369
|
+
);
|
|
370
|
+
return results;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
interface ReporterHub {
|
|
374
|
+
runStart(
|
|
375
|
+
evals: readonly DiscoveredEval[],
|
|
376
|
+
target: EvalReporterTarget
|
|
377
|
+
): Promise<void>;
|
|
378
|
+
caseComplete(
|
|
379
|
+
discovered: DiscoveredEval,
|
|
380
|
+
result: EvalRunResult
|
|
381
|
+
): Promise<void>;
|
|
382
|
+
runComplete(summary: EvalRunSummary): Promise<void>;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Fan results out to the reporters that observe them.
|
|
387
|
+
*
|
|
388
|
+
* Run-wide reporters (CLI flags plus `evals.config.ts`) see every case; an
|
|
389
|
+
* eval's own `reporters` only see that eval. The run lifecycle hooks fire on
|
|
390
|
+
* every reporter in the run, so a per-eval destination still gets its
|
|
391
|
+
* `onRunStart` / `onRunComplete` pair.
|
|
392
|
+
*/
|
|
393
|
+
function buildReporterHub(
|
|
394
|
+
options: RunEvalsOptions,
|
|
395
|
+
config: Partial<EvalConfigFile>,
|
|
396
|
+
selected: readonly DiscoveredEval[]
|
|
397
|
+
): ReporterHub | undefined {
|
|
398
|
+
const skip = options.skipReport === true;
|
|
399
|
+
const runWide = [
|
|
400
|
+
...(options.reporters ?? []),
|
|
401
|
+
...(skip ? [] : (config.reporters ?? [])),
|
|
402
|
+
];
|
|
403
|
+
const perEval = skip
|
|
404
|
+
? []
|
|
405
|
+
: selected.flatMap((e) => e.definition.reporters ?? []);
|
|
406
|
+
const everyReporter = [...new Set([...runWide, ...perEval])];
|
|
407
|
+
if (everyReporter.length === 0) {
|
|
408
|
+
return undefined;
|
|
409
|
+
}
|
|
410
|
+
const onError = (error: unknown): void => {
|
|
411
|
+
// A broken destination must not fail the eval run itself.
|
|
412
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
413
|
+
process.stderr.write(`eval reporter error: ${detail}\n`);
|
|
414
|
+
};
|
|
415
|
+
const all = combineReporters(everyReporter, onError);
|
|
416
|
+
return {
|
|
417
|
+
async runStart(evals, target) {
|
|
418
|
+
await all.onRunStart?.(
|
|
419
|
+
evals.map((e) => ({
|
|
420
|
+
id: e.id,
|
|
421
|
+
fileId: e.fileId,
|
|
422
|
+
description: e.definition.description,
|
|
423
|
+
tags: e.definition.tags,
|
|
424
|
+
})),
|
|
425
|
+
target
|
|
426
|
+
);
|
|
427
|
+
},
|
|
428
|
+
async caseComplete(discovered, result) {
|
|
429
|
+
const observers = [
|
|
430
|
+
...new Set([
|
|
431
|
+
...runWide,
|
|
432
|
+
...(skip ? [] : (discovered.definition.reporters ?? [])),
|
|
433
|
+
]),
|
|
434
|
+
];
|
|
435
|
+
await combineReporters(observers, onError).onEvalComplete?.(result);
|
|
436
|
+
},
|
|
437
|
+
async runComplete(summary) {
|
|
438
|
+
await all.onRunComplete?.(summary);
|
|
439
|
+
},
|
|
440
|
+
};
|
|
277
441
|
}
|
|
278
442
|
|
|
279
443
|
/**
|
|
@@ -331,6 +495,12 @@ function resolveEvalMaxConcurrency(config: Partial<EvalConfigFile>): number {
|
|
|
331
495
|
return normalizeEvalMaxConcurrency(config.maxConcurrency);
|
|
332
496
|
}
|
|
333
497
|
|
|
498
|
+
interface RunOneEvalJudgeOptions {
|
|
499
|
+
/** Judge model from `evals.config.ts`. */
|
|
500
|
+
configModel?: ModelSetting;
|
|
501
|
+
caller: EvalJudgeCaller;
|
|
502
|
+
}
|
|
503
|
+
|
|
334
504
|
async function runOneEval(
|
|
335
505
|
discovered: DiscoveredEval,
|
|
336
506
|
opts: {
|
|
@@ -339,50 +509,29 @@ async function runOneEval(
|
|
|
339
509
|
bearerToken?: string;
|
|
340
510
|
headers?: Record<string, string>;
|
|
341
511
|
verbose: boolean;
|
|
512
|
+
judge: RunOneEvalJudgeOptions;
|
|
342
513
|
onEvent?: (event: SessionEvent) => void;
|
|
343
514
|
signal?: AbortSignal;
|
|
344
515
|
}
|
|
345
516
|
): Promise<EvalRunResult> {
|
|
346
517
|
const logs: string[] = [];
|
|
347
518
|
const metrics: Record<string, string | number> = {};
|
|
348
|
-
const
|
|
519
|
+
const recorder = new EvalAssertionRecorder();
|
|
349
520
|
const def = discovered.definition;
|
|
350
521
|
const timeoutMs = def.timeoutMs ?? opts.defaultTimeoutMs;
|
|
351
522
|
const startedAt = Date.now();
|
|
352
523
|
|
|
353
524
|
let sessionId: string | undefined;
|
|
354
525
|
let continuationToken: string | undefined;
|
|
526
|
+
// The session stream replays from an index and the client stops at the first
|
|
527
|
+
// terminal event, so each send must resume after the previous turn's last
|
|
528
|
+
// event or it would re-read that turn instead of the new one.
|
|
529
|
+
let nextEventIndex = 0;
|
|
355
530
|
const allEvents: SessionEvent[] = [];
|
|
356
531
|
const inputs: string[] = [];
|
|
532
|
+
const turns: EvalTurnResult[] = [];
|
|
357
533
|
let reply: string | null = null;
|
|
358
534
|
|
|
359
|
-
if (opts.signal?.aborted) {
|
|
360
|
-
return {
|
|
361
|
-
id: discovered.id,
|
|
362
|
-
path: discovered.path,
|
|
363
|
-
...(def.description === undefined
|
|
364
|
-
? {}
|
|
365
|
-
: { description: def.description }),
|
|
366
|
-
ok: false,
|
|
367
|
-
assertions,
|
|
368
|
-
error: "cancelled",
|
|
369
|
-
logs,
|
|
370
|
-
metrics,
|
|
371
|
-
inputs,
|
|
372
|
-
toolCalls: [],
|
|
373
|
-
tools: [],
|
|
374
|
-
durationMs: Date.now() - startedAt,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const record = (name: string, passed: boolean, detail?: string): void => {
|
|
379
|
-
assertions.push({
|
|
380
|
-
name,
|
|
381
|
-
passed,
|
|
382
|
-
...(detail === undefined ? {} : { detail }),
|
|
383
|
-
});
|
|
384
|
-
};
|
|
385
|
-
|
|
386
535
|
const toolsUsed = (): string[] =>
|
|
387
536
|
buildTrajectory(allEvents).turns.flatMap((t) =>
|
|
388
537
|
t.toolCalls.map((c) => c.toolName)
|
|
@@ -398,7 +547,69 @@ async function runOneEval(
|
|
|
398
547
|
}))
|
|
399
548
|
);
|
|
400
549
|
|
|
550
|
+
const finish = (extra: {
|
|
551
|
+
verdict: EvalVerdict;
|
|
552
|
+
ok: boolean;
|
|
553
|
+
error?: string;
|
|
554
|
+
skipReason?: string;
|
|
555
|
+
finalText?: string;
|
|
556
|
+
}): EvalRunResult => ({
|
|
557
|
+
id: discovered.id,
|
|
558
|
+
path: discovered.path,
|
|
559
|
+
...(def.description === undefined ? {} : { description: def.description }),
|
|
560
|
+
ok: extra.ok,
|
|
561
|
+
verdict: extra.verdict,
|
|
562
|
+
skipReason: extra.skipReason,
|
|
563
|
+
assertions: recorder.results(),
|
|
564
|
+
error: extra.error,
|
|
565
|
+
logs,
|
|
566
|
+
metrics,
|
|
567
|
+
metadata: def.metadata,
|
|
568
|
+
tags: def.tags,
|
|
569
|
+
inputs,
|
|
570
|
+
toolCalls: toolCallIo(),
|
|
571
|
+
...(sessionId === undefined ? {} : { sessionId }),
|
|
572
|
+
finalText: extra.finalText,
|
|
573
|
+
tools: toolsUsed(),
|
|
574
|
+
durationMs: Date.now() - startedAt,
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
if (opts.signal?.aborted) {
|
|
578
|
+
return finish({ verdict: "failed", ok: false, error: "cancelled" });
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// A judge that cannot reach a model must not look like a quality regression:
|
|
582
|
+
// the case is skipped visibly instead.
|
|
583
|
+
let judgeUnavailable: string | undefined;
|
|
584
|
+
const timeout = new AbortController();
|
|
585
|
+
const timer = setTimeout(() => timeout.abort(), clampTimerDelay(timeoutMs));
|
|
586
|
+
// A pending case timer must not hold the process open on its own.
|
|
587
|
+
timer.unref?.();
|
|
588
|
+
|
|
589
|
+
const runAssertions: EvalAssertions = createAssertions({
|
|
590
|
+
recorder,
|
|
591
|
+
events: () => allEvents,
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
const judge = createJudgeSurface({
|
|
595
|
+
recorder,
|
|
596
|
+
grader: (name) => EVAL_JUDGE_GRADERS[name],
|
|
597
|
+
resolveModel: (callModel) =>
|
|
598
|
+
resolveJudgeModel({
|
|
599
|
+
call: callModel,
|
|
600
|
+
evalLevel: def.judge?.model,
|
|
601
|
+
config: opts.judge.configModel,
|
|
602
|
+
env: process.env[EVAL_JUDGE_MODEL_ENV],
|
|
603
|
+
}),
|
|
604
|
+
caller: opts.judge.caller,
|
|
605
|
+
defaultValue: () => reply,
|
|
606
|
+
onUnavailable: (message) => {
|
|
607
|
+
judgeUnavailable = judgeUnavailable ?? message;
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
|
|
401
611
|
const t: EvalTestContext = {
|
|
612
|
+
...runAssertions,
|
|
402
613
|
get reply() {
|
|
403
614
|
return reply;
|
|
404
615
|
},
|
|
@@ -408,12 +619,19 @@ async function runOneEval(
|
|
|
408
619
|
get events() {
|
|
409
620
|
return allEvents;
|
|
410
621
|
},
|
|
622
|
+
get turns() {
|
|
623
|
+
return turns;
|
|
624
|
+
},
|
|
411
625
|
get iteration() {
|
|
412
626
|
return def.iteration ?? 1;
|
|
413
627
|
},
|
|
414
628
|
get iterations() {
|
|
415
629
|
return def.iterations ?? 1;
|
|
416
630
|
},
|
|
631
|
+
get signal() {
|
|
632
|
+
return timeout.signal;
|
|
633
|
+
},
|
|
634
|
+
judge,
|
|
417
635
|
async send(
|
|
418
636
|
message: string,
|
|
419
637
|
options: EvalSendOptions = {}
|
|
@@ -424,6 +642,7 @@ async function runOneEval(
|
|
|
424
642
|
messages: [message],
|
|
425
643
|
sessionId,
|
|
426
644
|
continuationToken,
|
|
645
|
+
startIndex: nextEventIndex,
|
|
427
646
|
// Keep defineEval traffic out of live defineAB enrollment/metrics.
|
|
428
647
|
purpose: "eval",
|
|
429
648
|
bearerToken: opts.bearerToken,
|
|
@@ -437,57 +656,57 @@ async function runOneEval(
|
|
|
437
656
|
});
|
|
438
657
|
sessionId = result.sessionId;
|
|
439
658
|
continuationToken = result.continuationToken;
|
|
659
|
+
nextEventIndex = result.nextEventIndex ?? nextEventIndex;
|
|
440
660
|
allEvents.push(...result.events);
|
|
441
661
|
if (result.trajectory.finalText !== "") {
|
|
442
662
|
reply = result.trajectory.finalText;
|
|
443
663
|
}
|
|
444
|
-
|
|
664
|
+
const index = turns.length + 1;
|
|
665
|
+
// The turn is immutable, so its assertions read a frozen event slice
|
|
666
|
+
// even after later turns append to the run.
|
|
667
|
+
const turnEvents = [...result.events];
|
|
668
|
+
const turn: EvalTurnResult = {
|
|
669
|
+
...createAssertions({
|
|
670
|
+
recorder,
|
|
671
|
+
events: () => turnEvents,
|
|
672
|
+
scope: `turn[${index}]`,
|
|
673
|
+
}),
|
|
445
674
|
message: result.trajectory.finalText,
|
|
446
675
|
sessionId: result.sessionId,
|
|
447
|
-
events:
|
|
676
|
+
events: turnEvents,
|
|
448
677
|
toolCalls: result.trajectory.turns.flatMap((turn) =>
|
|
449
678
|
turn.toolCalls.map((c) => c.toolName)
|
|
450
679
|
),
|
|
451
680
|
ok: result.ok,
|
|
681
|
+
index,
|
|
682
|
+
expectOk() {
|
|
683
|
+
if (!result.ok) {
|
|
684
|
+
throw new Error(
|
|
685
|
+
`turn[${index}] failed: ${result.trajectory.turns.find((x) => x.failed)?.error ?? "unknown error"}`
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
return turn;
|
|
689
|
+
},
|
|
452
690
|
};
|
|
691
|
+
turns.push(turn);
|
|
692
|
+
return turn;
|
|
453
693
|
},
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
record(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
tools.includes(name) ? undefined : `got [${tools.join(", ")}]`
|
|
468
|
-
);
|
|
469
|
-
},
|
|
470
|
-
notCalledTool(name: string) {
|
|
471
|
-
const tools = toolsUsed();
|
|
472
|
-
record(
|
|
473
|
-
`notCalledTool(${name})`,
|
|
474
|
-
!tools.includes(name),
|
|
475
|
-
tools.includes(name) ? "tool was called" : undefined
|
|
476
|
-
);
|
|
477
|
-
},
|
|
478
|
-
messageIncludes(token: string | RegExp) {
|
|
479
|
-
const text = reply ?? "";
|
|
480
|
-
const passed =
|
|
481
|
-
typeof token === "string" ? text.includes(token) : token.test(text);
|
|
482
|
-
record(
|
|
483
|
-
`messageIncludes(${String(token)})`,
|
|
484
|
-
passed,
|
|
485
|
-
passed ? undefined : `reply=${JSON.stringify(text.slice(0, 120))}`
|
|
486
|
-
);
|
|
694
|
+
async require<T>(value: T, assertion: Expectation): Promise<T> {
|
|
695
|
+
const outcome = evaluateExpectation(value, assertion);
|
|
696
|
+
recorder.record({
|
|
697
|
+
name: `require(${assertion.kind})`,
|
|
698
|
+
passed: outcome.passed,
|
|
699
|
+
detail: outcome.detail,
|
|
700
|
+
score: outcome.score,
|
|
701
|
+
severity: "gate",
|
|
702
|
+
});
|
|
703
|
+
if (!outcome.passed) {
|
|
704
|
+
throw new EvalRequireFailure(`require(${assertion.kind})`);
|
|
705
|
+
}
|
|
706
|
+
return value;
|
|
487
707
|
},
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
record(`check(${assertion.kind})`, passed, detail);
|
|
708
|
+
skip(reason: string): never {
|
|
709
|
+
throw new EvalSkipSignal(reason);
|
|
491
710
|
},
|
|
492
711
|
log(message: string) {
|
|
493
712
|
logs.push(message);
|
|
@@ -510,129 +729,161 @@ async function runOneEval(
|
|
|
510
729
|
try {
|
|
511
730
|
await def.test(t);
|
|
512
731
|
} catch (error) {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
732
|
+
if (error instanceof EvalSkipSignal) {
|
|
733
|
+
clearTimeout(timer);
|
|
734
|
+
return finish({
|
|
735
|
+
verdict: "skipped",
|
|
736
|
+
ok: true,
|
|
737
|
+
skipReason: error.reason,
|
|
738
|
+
finalText: reply ?? undefined,
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
if (!(error instanceof EvalRequireFailure)) {
|
|
742
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
743
|
+
if (error instanceof RunSessionTimeoutError && sessionId === undefined) {
|
|
744
|
+
sessionId = error.sessionId;
|
|
745
|
+
}
|
|
746
|
+
await recorder.waitForPending().catch(() => undefined);
|
|
747
|
+
clearTimeout(timer);
|
|
748
|
+
return finish({
|
|
749
|
+
verdict: "failed",
|
|
750
|
+
ok: false,
|
|
751
|
+
error: message,
|
|
752
|
+
finalText: reply ?? undefined,
|
|
753
|
+
});
|
|
516
754
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
path: discovered.path,
|
|
520
|
-
...(def.description === undefined
|
|
521
|
-
? {}
|
|
522
|
-
: { description: def.description }),
|
|
523
|
-
ok: false,
|
|
524
|
-
assertions,
|
|
525
|
-
error: message,
|
|
526
|
-
logs,
|
|
527
|
-
metrics,
|
|
528
|
-
inputs,
|
|
529
|
-
toolCalls: toolCallIo(),
|
|
530
|
-
...(sessionId === undefined ? {} : { sessionId }),
|
|
531
|
-
...(reply === null ? {} : { finalText: reply }),
|
|
532
|
-
tools: toolsUsed(),
|
|
533
|
-
durationMs: Date.now() - startedAt,
|
|
534
|
-
};
|
|
755
|
+
// `require` already recorded the failing gate; fall through so the verdict
|
|
756
|
+
// comes from the assertions rather than a duplicate execution error.
|
|
535
757
|
}
|
|
536
758
|
|
|
759
|
+
await recorder.waitForPending();
|
|
760
|
+
clearTimeout(timer);
|
|
761
|
+
|
|
762
|
+
const assertions = recorder.results();
|
|
537
763
|
const traj = buildTrajectory(allEvents);
|
|
538
|
-
|
|
764
|
+
// With no assertions at all, keep the historical fallback: a case that just
|
|
765
|
+
// drives the agent passes when the run itself succeeded.
|
|
766
|
+
const verdict: EvalVerdict =
|
|
539
767
|
assertions.length > 0
|
|
540
|
-
? assertions
|
|
541
|
-
: traj.ok && traj.turns.length > 0
|
|
768
|
+
? computeVerdict(assertions)
|
|
769
|
+
: traj.ok && traj.turns.length > 0
|
|
770
|
+
? "passed"
|
|
771
|
+
: "failed";
|
|
772
|
+
const finalText = reply ?? traj.finalText;
|
|
542
773
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
774
|
+
// An unreachable judge means the *judged* signal is unknown, so the case is
|
|
775
|
+
// reported as skipped rather than as a quality regression. It must not also
|
|
776
|
+
// bury a deterministic gate that already failed: skipping a failed case would
|
|
777
|
+
// turn a red eval green on any machine that happens to lack credentials.
|
|
778
|
+
if (judgeUnavailable !== undefined && verdict !== "failed") {
|
|
779
|
+
logs.push(`judge skipped: ${judgeUnavailable}`);
|
|
780
|
+
return finish({
|
|
781
|
+
verdict: "skipped",
|
|
782
|
+
ok: true,
|
|
783
|
+
skipReason: judgeUnavailable,
|
|
784
|
+
finalText,
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
if (judgeUnavailable !== undefined) {
|
|
788
|
+
logs.push(
|
|
789
|
+
`judge unavailable (${judgeUnavailable}), but a gate already failed — reporting the failure`
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
return finish({
|
|
794
|
+
verdict,
|
|
795
|
+
ok: verdict !== "failed",
|
|
796
|
+
finalText,
|
|
797
|
+
});
|
|
558
798
|
}
|
|
559
799
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
800
|
+
/** Clamp a case timeout to a delay `setTimeout` can represent. */
|
|
801
|
+
function clampTimerDelay(timeoutMs: number): number {
|
|
802
|
+
const MAX_TIMER = 2_147_483_647;
|
|
803
|
+
return Math.min(Math.max(timeoutMs, 0), MAX_TIMER);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Build `t.judge`. Each grader records its slot immediately and resolves it
|
|
808
|
+
* during finalization, so several judges overlap instead of serializing.
|
|
809
|
+
*/
|
|
810
|
+
function createJudgeSurface(args: {
|
|
811
|
+
recorder: EvalAssertionRecorder;
|
|
812
|
+
grader: (name: keyof typeof EVAL_JUDGE_GRADERS) => EvalJudgeGrader;
|
|
813
|
+
resolveModel: (call?: ModelSetting) => ModelSetting | undefined;
|
|
814
|
+
caller: EvalJudgeCaller;
|
|
815
|
+
defaultValue: () => unknown;
|
|
816
|
+
onUnavailable: (message: string) => void;
|
|
817
|
+
}): EvalJudge {
|
|
818
|
+
const grade = (
|
|
819
|
+
graderName: keyof typeof EVAL_JUDGE_GRADERS,
|
|
820
|
+
reference: string,
|
|
821
|
+
options: EvalJudgeCallOptions | undefined
|
|
822
|
+
): EvalAssertionHandle => {
|
|
823
|
+
const grader = args.grader(graderName);
|
|
824
|
+
const model = args.resolveModel(options?.model);
|
|
825
|
+
const name = `judge.${graderName}(${truncateForName(reference)})`;
|
|
826
|
+
if (model === undefined) {
|
|
827
|
+
// A missing judge model is an authoring error, not a flaky provider.
|
|
828
|
+
return args.recorder.record({
|
|
829
|
+
name,
|
|
830
|
+
passed: false,
|
|
831
|
+
severity: "gate",
|
|
832
|
+
detail:
|
|
833
|
+
"no judge model configured; set judge.model in evals.config.ts, on the eval, or on the call",
|
|
834
|
+
});
|
|
590
835
|
}
|
|
591
|
-
|
|
592
|
-
|
|
836
|
+
const submission = renderSubmission(
|
|
837
|
+
options !== undefined && "on" in options
|
|
838
|
+
? options.on
|
|
839
|
+
: args.defaultValue()
|
|
840
|
+
);
|
|
841
|
+
const settle = (async () => {
|
|
842
|
+
const reply = await args.caller({
|
|
843
|
+
prompt: grader.buildPrompt({ submission, reference }),
|
|
844
|
+
model,
|
|
845
|
+
});
|
|
846
|
+
const result = grader.parse(reply);
|
|
593
847
|
return {
|
|
594
|
-
passed,
|
|
595
|
-
|
|
848
|
+
passed: true,
|
|
849
|
+
score: result.score,
|
|
850
|
+
detail:
|
|
851
|
+
result.rationale === undefined
|
|
852
|
+
? `${result.choice} (${result.score.toFixed(2)})`
|
|
853
|
+
: `${result.choice} (${result.score.toFixed(2)}) — ${result.rationale}`,
|
|
596
854
|
};
|
|
597
|
-
}
|
|
598
|
-
|
|
855
|
+
})().catch((error: unknown) => {
|
|
856
|
+
if (error instanceof EvalJudgeUnavailableError) {
|
|
857
|
+
args.onUnavailable(error.message);
|
|
858
|
+
return { passed: true, detail: `skipped: ${error.message}` };
|
|
859
|
+
}
|
|
860
|
+
throw error;
|
|
861
|
+
});
|
|
862
|
+
// Soft by default: a judge is a tracked score until given a bar.
|
|
863
|
+
return args.recorder.recordAsync(
|
|
864
|
+
{ name, passed: true, severity: "soft", detail: "grading…" },
|
|
865
|
+
settle
|
|
866
|
+
);
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
return {
|
|
870
|
+
async model(prompt, options) {
|
|
871
|
+
const model = args.resolveModel(options?.model);
|
|
872
|
+
if (model === undefined) {
|
|
873
|
+
throw new Error(
|
|
874
|
+
"t.judge.model: no judge model configured; set judge.model in evals.config.ts, on the eval, or on the call"
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
return args.caller({ prompt, model });
|
|
878
|
+
},
|
|
879
|
+
factuality: (expected, options) => grade("factuality", expected, options),
|
|
880
|
+
summarizes: (expected, options) => grade("summarizes", expected, options),
|
|
881
|
+
closedQA: (criteria, options) => grade("closedQA", criteria, options),
|
|
882
|
+
sql: (expected, options) => grade("sql", expected, options),
|
|
883
|
+
};
|
|
599
884
|
}
|
|
600
885
|
|
|
601
|
-
function
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
}
|
|
605
|
-
if (
|
|
606
|
-
typeof a !== "object" ||
|
|
607
|
-
typeof b !== "object" ||
|
|
608
|
-
a === null ||
|
|
609
|
-
b === null
|
|
610
|
-
) {
|
|
611
|
-
return false;
|
|
612
|
-
}
|
|
613
|
-
if (Array.isArray(a) !== Array.isArray(b)) {
|
|
614
|
-
return false;
|
|
615
|
-
}
|
|
616
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
617
|
-
if (a.length !== b.length) {
|
|
618
|
-
return false;
|
|
619
|
-
}
|
|
620
|
-
return a.every((item, i) => deepEqual(item, b[i]));
|
|
621
|
-
}
|
|
622
|
-
const aKeys = Object.keys(a as object);
|
|
623
|
-
const bKeys = Object.keys(b as object);
|
|
624
|
-
if (aKeys.length !== bKeys.length) {
|
|
625
|
-
return false;
|
|
626
|
-
}
|
|
627
|
-
for (const key of aKeys) {
|
|
628
|
-
if (
|
|
629
|
-
!deepEqual(
|
|
630
|
-
(a as Record<string, unknown>)[key],
|
|
631
|
-
(b as Record<string, unknown>)[key]
|
|
632
|
-
)
|
|
633
|
-
) {
|
|
634
|
-
return false;
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
return true;
|
|
886
|
+
function truncateForName(text: string): string {
|
|
887
|
+
const oneLine = text.replace(/\s+/g, " ").trim();
|
|
888
|
+
return oneLine.length > 60 ? `${oneLine.slice(0, 59)}…` : oneLine;
|
|
638
889
|
}
|