@stigmer/plugin-package 0.1.0-dev.20261017020314.g644422724c27
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/LICENSE +194 -0
- package/README.md +72 -0
- package/client/archive.d.ts +27 -0
- package/client/archive.d.ts.map +1 -0
- package/client/archive.js +38 -0
- package/client/archive.js.map +1 -0
- package/client/builtin.d.ts +37 -0
- package/client/builtin.d.ts.map +1 -0
- package/client/builtin.js +49 -0
- package/client/builtin.js.map +1 -0
- package/client/ignore/defaults.d.ts +2 -0
- package/client/ignore/defaults.d.ts.map +1 -0
- package/client/ignore/defaults.js +140 -0
- package/client/ignore/defaults.js.map +1 -0
- package/client/ignore/match.d.ts +3 -0
- package/client/ignore/match.d.ts.map +1 -0
- package/client/ignore/match.js +166 -0
- package/client/ignore/match.js.map +1 -0
- package/client/ignore/matcher.d.ts +50 -0
- package/client/ignore/matcher.d.ts.map +1 -0
- package/client/ignore/matcher.js +116 -0
- package/client/ignore/matcher.js.map +1 -0
- package/client/ignore/pattern.d.ts +13 -0
- package/client/ignore/pattern.d.ts.map +1 -0
- package/client/ignore/pattern.js +119 -0
- package/client/ignore/pattern.js.map +1 -0
- package/client/prepare-eval.d.ts +62 -0
- package/client/prepare-eval.d.ts.map +1 -0
- package/client/prepare-eval.js +60 -0
- package/client/prepare-eval.js.map +1 -0
- package/client/prepare.d.ts +99 -0
- package/client/prepare.d.ts.map +1 -0
- package/client/prepare.js +89 -0
- package/client/prepare.js.map +1 -0
- package/client/presentation.d.ts +19 -0
- package/client/presentation.d.ts.map +1 -0
- package/client/presentation.js +44 -0
- package/client/presentation.js.map +1 -0
- package/client/refs.d.ts +76 -0
- package/client/refs.d.ts.map +1 -0
- package/client/refs.js +123 -0
- package/client/refs.js.map +1 -0
- package/client/release.d.ts +20 -0
- package/client/release.d.ts.map +1 -0
- package/client/release.js +28 -0
- package/client/release.js.map +1 -0
- package/client/reroot.d.ts +21 -0
- package/client/reroot.d.ts.map +1 -0
- package/client/reroot.js +37 -0
- package/client/reroot.js.map +1 -0
- package/client/select.d.ts +74 -0
- package/client/select.d.ts.map +1 -0
- package/client/select.js +121 -0
- package/client/select.js.map +1 -0
- package/client/vocabulary.d.ts +13 -0
- package/client/vocabulary.d.ts.map +1 -0
- package/client/vocabulary.js +17 -0
- package/client/vocabulary.js.map +1 -0
- package/client.d.ts +51 -0
- package/client.d.ts.map +1 -0
- package/client.js +51 -0
- package/client.js.map +1 -0
- package/detect.d.ts +83 -0
- package/detect.d.ts.map +1 -0
- package/detect.js +210 -0
- package/detect.js.map +1 -0
- package/dialects/claude.d.ts +34 -0
- package/dialects/claude.d.ts.map +1 -0
- package/dialects/claude.js +84 -0
- package/dialects/claude.js.map +1 -0
- package/dialects/codex.d.ts +20 -0
- package/dialects/codex.d.ts.map +1 -0
- package/dialects/codex.js +21 -0
- package/dialects/codex.js.map +1 -0
- package/dialects/cursor.d.ts +25 -0
- package/dialects/cursor.d.ts.map +1 -0
- package/dialects/cursor.js +66 -0
- package/dialects/cursor.js.map +1 -0
- package/dialects/manifest.d.ts +164 -0
- package/dialects/manifest.d.ts.map +1 -0
- package/dialects/manifest.js +256 -0
- package/dialects/manifest.js.map +1 -0
- package/dialects/open.d.ts +19 -0
- package/dialects/open.d.ts.map +1 -0
- package/dialects/open.js +49 -0
- package/dialects/open.js.map +1 -0
- package/documents.d.ts +58 -0
- package/documents.d.ts.map +1 -0
- package/documents.js +121 -0
- package/documents.js.map +1 -0
- package/evals/eval-dir.d.ts +59 -0
- package/evals/eval-dir.d.ts.map +1 -0
- package/evals/eval-dir.js +84 -0
- package/evals/eval-dir.js.map +1 -0
- package/evals/fields.d.ts +78 -0
- package/evals/fields.d.ts.map +1 -0
- package/evals/fields.js +156 -0
- package/evals/fields.js.map +1 -0
- package/evals/glob.d.ts +40 -0
- package/evals/glob.d.ts.map +1 -0
- package/evals/glob.js +146 -0
- package/evals/glob.js.map +1 -0
- package/evals/graders.d.ts +52 -0
- package/evals/graders.d.ts.map +1 -0
- package/evals/graders.js +279 -0
- package/evals/graders.js.map +1 -0
- package/evals/markdown.d.ts +24 -0
- package/evals/markdown.d.ts.map +1 -0
- package/evals/markdown.js +48 -0
- package/evals/markdown.js.map +1 -0
- package/evals/mocks.d.ts +50 -0
- package/evals/mocks.d.ts.map +1 -0
- package/evals/mocks.js +182 -0
- package/evals/mocks.js.map +1 -0
- package/evals/read-eval-suite.d.ts +110 -0
- package/evals/read-eval-suite.d.ts.map +1 -0
- package/evals/read-eval-suite.js +603 -0
- package/evals/read-eval-suite.js.map +1 -0
- package/evals/summary.d.ts +61 -0
- package/evals/summary.d.ts.map +1 -0
- package/evals/summary.js +69 -0
- package/evals/summary.js.map +1 -0
- package/evals/types.d.ts +203 -0
- package/evals/types.d.ts.map +1 -0
- package/evals/types.js +21 -0
- package/evals/types.js.map +1 -0
- package/files.d.ts +135 -0
- package/files.d.ts.map +1 -0
- package/files.js +209 -0
- package/files.js.map +1 -0
- package/frontmatter.d.ts +51 -0
- package/frontmatter.d.ts.map +1 -0
- package/frontmatter.js +61 -0
- package/frontmatter.js.map +1 -0
- package/index.d.ts +37 -0
- package/index.d.ts.map +1 -0
- package/index.js +33 -0
- package/index.js.map +1 -0
- package/marketplace/messages.d.ts +20 -0
- package/marketplace/messages.d.ts.map +1 -0
- package/marketplace/messages.js +49 -0
- package/marketplace/messages.js.map +1 -0
- package/marketplace/outcome.d.ts +70 -0
- package/marketplace/outcome.d.ts.map +1 -0
- package/marketplace/outcome.js +29 -0
- package/marketplace/outcome.js.map +1 -0
- package/marketplace/read-marketplace.d.ts +52 -0
- package/marketplace/read-marketplace.d.ts.map +1 -0
- package/marketplace/read-marketplace.js +351 -0
- package/marketplace/read-marketplace.js.map +1 -0
- package/messages.d.ts +55 -0
- package/messages.d.ts.map +1 -0
- package/messages.js +167 -0
- package/messages.js.map +1 -0
- package/normalise/hooks.d.ts +91 -0
- package/normalise/hooks.d.ts.map +1 -0
- package/normalise/hooks.js +437 -0
- package/normalise/hooks.js.map +1 -0
- package/normalise/ignored.d.ts +34 -0
- package/normalise/ignored.d.ts.map +1 -0
- package/normalise/ignored.js +78 -0
- package/normalise/ignored.js.map +1 -0
- package/normalise/mcp-servers.d.ts +50 -0
- package/normalise/mcp-servers.d.ts.map +1 -0
- package/normalise/mcp-servers.js +398 -0
- package/normalise/mcp-servers.js.map +1 -0
- package/normalise/settings.d.ts +32 -0
- package/normalise/settings.d.ts.map +1 -0
- package/normalise/settings.js +72 -0
- package/normalise/settings.js.map +1 -0
- package/normalise/skills.d.ts +39 -0
- package/normalise/skills.d.ts.map +1 -0
- package/normalise/skills.js +135 -0
- package/normalise/skills.js.map +1 -0
- package/normalise/stigmer-folder.d.ts +17 -0
- package/normalise/stigmer-folder.d.ts.map +1 -0
- package/normalise/stigmer-folder.js +19 -0
- package/normalise/stigmer-folder.js.map +1 -0
- package/normalise/sub-agents.d.ts +54 -0
- package/normalise/sub-agents.d.ts.map +1 -0
- package/normalise/sub-agents.js +219 -0
- package/normalise/sub-agents.js.map +1 -0
- package/normalise/variables.d.ts +31 -0
- package/normalise/variables.d.ts.map +1 -0
- package/normalise/variables.js +170 -0
- package/normalise/variables.js.map +1 -0
- package/outcome.d.ts +59 -0
- package/outcome.d.ts.map +1 -0
- package/outcome.js +32 -0
- package/outcome.js.map +1 -0
- package/package.json +47 -0
- package/placeholders.d.ts +65 -0
- package/placeholders.d.ts.map +1 -0
- package/placeholders.js +99 -0
- package/placeholders.js.map +1 -0
- package/presentation.d.ts +53 -0
- package/presentation.d.ts.map +1 -0
- package/presentation.js +156 -0
- package/presentation.js.map +1 -0
- package/read-plugin-package.d.ts +20 -0
- package/read-plugin-package.d.ts.map +1 -0
- package/read-plugin-package.js +73 -0
- package/read-plugin-package.js.map +1 -0
- package/src/client/archive.ts +44 -0
- package/src/client/builtin.ts +60 -0
- package/src/client/ignore/defaults.ts +155 -0
- package/src/client/ignore/match.ts +158 -0
- package/src/client/ignore/matcher.ts +156 -0
- package/src/client/ignore/pattern.ts +132 -0
- package/src/client/prepare-eval.ts +92 -0
- package/src/client/prepare.ts +160 -0
- package/src/client/presentation.ts +47 -0
- package/src/client/refs.ts +170 -0
- package/src/client/release.ts +29 -0
- package/src/client/reroot.ts +35 -0
- package/src/client/select.ts +161 -0
- package/src/client/vocabulary.ts +19 -0
- package/src/client.ts +102 -0
- package/src/detect.ts +245 -0
- package/src/dialects/claude.ts +102 -0
- package/src/dialects/codex.ts +26 -0
- package/src/dialects/cursor.ts +77 -0
- package/src/dialects/manifest.ts +316 -0
- package/src/dialects/open.ts +50 -0
- package/src/documents.ts +158 -0
- package/src/evals/eval-dir.ts +101 -0
- package/src/evals/fields.ts +184 -0
- package/src/evals/glob.ts +141 -0
- package/src/evals/graders.ts +293 -0
- package/src/evals/markdown.ts +56 -0
- package/src/evals/mocks.ts +202 -0
- package/src/evals/read-eval-suite.ts +713 -0
- package/src/evals/summary.ts +100 -0
- package/src/evals/types.ts +217 -0
- package/src/files.ts +235 -0
- package/src/frontmatter.ts +70 -0
- package/src/index.ts +129 -0
- package/src/marketplace/messages.ts +61 -0
- package/src/marketplace/outcome.ts +91 -0
- package/src/marketplace/read-marketplace.ts +388 -0
- package/src/messages.ts +248 -0
- package/src/normalise/hooks.ts +469 -0
- package/src/normalise/ignored.ts +79 -0
- package/src/normalise/mcp-servers.ts +423 -0
- package/src/normalise/settings.ts +81 -0
- package/src/normalise/skills.ts +145 -0
- package/src/normalise/stigmer-folder.ts +23 -0
- package/src/normalise/sub-agents.ts +231 -0
- package/src/normalise/variables.ts +181 -0
- package/src/outcome.ts +158 -0
- package/src/placeholders.ts +110 -0
- package/src/presentation.ts +170 -0
- package/src/read-plugin-package.ts +80 -0
- package/src/testing.ts +347 -0
- package/src/tool-names.ts +30 -0
- package/src/trim.ts +10 -0
- package/src/types.ts +214 -0
- package/testing.d.ts +127 -0
- package/testing.d.ts.map +1 -0
- package/testing.js +266 -0
- package/testing.js.map +1 -0
- package/tool-names.d.ts +21 -0
- package/tool-names.d.ts.map +1 -0
- package/tool-names.js +28 -0
- package/tool-names.js.map +1 -0
- package/trim.d.ts +7 -0
- package/trim.d.ts.map +1 -0
- package/trim.js +12 -0
- package/trim.js.map +1 -0
- package/types.d.ts +179 -0
- package/types.d.ts.map +1 -0
- package/types.js +19 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `readEvalSuite`: a plugin's eval suite, in Claude Code's plugin-eval
|
|
3
|
+
* format, read from the same `PluginFiles` the install reads; and
|
|
4
|
+
* `readEvalFolder`: a pushed eval, the same format with the archive's root
|
|
5
|
+
* as the suite's directory. Both read cases one way; they differ in where
|
|
6
|
+
* the suite is and which servers its mocks may stand in for (the end of
|
|
7
|
+
* this comment).
|
|
8
|
+
*
|
|
9
|
+
* Pure and synchronous like `readPluginPackage`, and never a refusal: a
|
|
10
|
+
* suite is the author's tests, not part of what Stigmer installs, so a case
|
|
11
|
+
* that cannot load is a finding and the rest of the suite still reads. The
|
|
12
|
+
* install summarises the result on the plugin; the eval workflow reads the
|
|
13
|
+
* archive again at the digest it runs, so both see one reading.
|
|
14
|
+
*
|
|
15
|
+
* The directory is `evals/`, or a Claude-shaped manifest's
|
|
16
|
+
* `experimental.evals` when that is a relative path of plain directory
|
|
17
|
+
* names clear of the plugin's skills (with or without a `./` prefix, or an
|
|
18
|
+
* array's first entry); any other value is an
|
|
19
|
+
* `eval-dir-invalid` finding and `evals/` is used, the format's rule for an
|
|
20
|
+
* unusable manifest value. Skills a manifest declares in `evals/` leave the
|
|
21
|
+
* plugin no suite: an `eval-dir-invalid` finding and no case, since the
|
|
22
|
+
* skills keep their files. The manifest is found by the library's own
|
|
23
|
+
* detection, so the reader and the install never disagree on which manifest
|
|
24
|
+
* a plugin has, and the rule is `eval-dir.ts`'s, which the skill listing
|
|
25
|
+
* shares to leave the suite out of every skill.
|
|
26
|
+
*
|
|
27
|
+
* A case is a directory under the suite holding `prompt.md` or `case.yaml`;
|
|
28
|
+
* a directory that is neither may group cases beneath it, and everything
|
|
29
|
+
* inside a case belongs to it (its `graders/`, fixtures, its own `mocks/`).
|
|
30
|
+
* `results/` and `mocks/` at the suite root are the runner's output and the
|
|
31
|
+
* suite's MCP mocks, never cases. Every file is read through the
|
|
32
|
+
* `evalDocument` cap. A case's mocks are its own `mocks/` over the suite's,
|
|
33
|
+
* file by file (`mocks.ts`).
|
|
34
|
+
*
|
|
35
|
+
* The search goes at most {@link EVAL_MAX_CASE_DEPTH} directories below the
|
|
36
|
+
* suite, and a deeper directory is a finding rather than a recursion that
|
|
37
|
+
* runs out of stack: the install accepts any depth its archive holds. A
|
|
38
|
+
* case's name is at most {@link EVAL_MAX_CASE_NAME} characters and its
|
|
39
|
+
* directory's path at most {@link EVAL_MAX_CASE_DIR} characters, else the
|
|
40
|
+
* case is invalid: both are matched against an eval's `case_glob` on the
|
|
41
|
+
* server's request path, and both are stored on the plugin and every eval.
|
|
42
|
+
*
|
|
43
|
+
* Fields follow the format's precedence: `prompt.md` frontmatter overrides
|
|
44
|
+
* the matching `case.yaml` field (a whole field, a list included, never
|
|
45
|
+
* merged), the `prompt.md` body is the prompt and `execution.prompt` the
|
|
46
|
+
* fallback when that body is blank, and the graders are `case.yaml`'s list
|
|
47
|
+
* then `graders/*.md` in path order. An unknown key in either file is an
|
|
48
|
+
* error for that case, as Claude Code treats it.
|
|
49
|
+
*
|
|
50
|
+
* A case's `context` paths are checked against its files, as a baseline
|
|
51
|
+
* grader's file is: the scaffold script a file, each of `add_dirs` a
|
|
52
|
+
* directory, the history a `.jsonl` file whose conversation can be resumed
|
|
53
|
+
* (`@stigmer/eval-runtime`'s transcript reader, tool calls and results
|
|
54
|
+
* paired). A path that climbs out of the case or names nothing there stops
|
|
55
|
+
* the case.
|
|
56
|
+
*
|
|
57
|
+
* A case that uses a feature Stigmer does not run yet still loads, with
|
|
58
|
+
* `unsupported` naming the first such feature in `EVAL_UNSUPPORTED_FEATURES`
|
|
59
|
+
* order: running it without the feature would produce a wrong score. A
|
|
60
|
+
* feature one engine cannot run is that engine's alone
|
|
61
|
+
* ({@link evalCaseUnsupportedOnCursor}): the server lists the case as not
|
|
62
|
+
* run on that engine's targets and runs it on the others.
|
|
63
|
+
*
|
|
64
|
+
* A plugin's suite may mock only the servers its plugin declares, the
|
|
65
|
+
* suite's `servers`. A pushed folder names no plugin, so it keeps every
|
|
66
|
+
* mock directory whose name could be an MCP server's
|
|
67
|
+
* (`isToolNameSegment`), and its `servers` are those directories' names:
|
|
68
|
+
* which agent server each stands in for is decided when the eval runs on
|
|
69
|
+
* an agent, not here. A manifest in the folder is a file like any other,
|
|
70
|
+
* and a case naming `plugins` is unsupported: the agent's plugins load,
|
|
71
|
+
* never a folder.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
import { isJsonObject, type JsonObject } from "../documents.js";
|
|
75
|
+
import { detectManifests } from "../detect.js";
|
|
76
|
+
import { basename, comparePaths, decodeUtf8, joinPath, PluginFileIndex, type PluginFiles } from "../files.js";
|
|
77
|
+
import { Findings } from "../messages.js";
|
|
78
|
+
import {
|
|
79
|
+
CaseFindings,
|
|
80
|
+
checkSchemaVersion,
|
|
81
|
+
type EvalFindingKind,
|
|
82
|
+
type FieldScope,
|
|
83
|
+
readEnv,
|
|
84
|
+
readInteger,
|
|
85
|
+
quote,
|
|
86
|
+
quoteJson,
|
|
87
|
+
readNonEmptyString,
|
|
88
|
+
readString,
|
|
89
|
+
readStringList,
|
|
90
|
+
unknownKeys,
|
|
91
|
+
wrong,
|
|
92
|
+
} from "./fields.js";
|
|
93
|
+
import { DEFAULT_EVAL_DIR, type EvalDirResolution, resolveEvalDir } from "./eval-dir.js";
|
|
94
|
+
import { readGrader } from "./graders.js";
|
|
95
|
+
import { type MockServerRule, readCaseMocks } from "./mocks.js";
|
|
96
|
+
import { isToolNameSegment } from "../tool-names.js";
|
|
97
|
+
import { normaliseMcpServers } from "../normalise/mcp-servers.js";
|
|
98
|
+
import { parseTranscript } from "@stigmer/eval-runtime";
|
|
99
|
+
import { parseMapping, readDocument, readMarkdown } from "./markdown.js";
|
|
100
|
+
import type { EvalCase, EvalCaseContext, EvalGrader, EvalSuite, EvalSuiteFinding } from "./types.js";
|
|
101
|
+
|
|
102
|
+
export { DEFAULT_EVAL_DIR } from "./eval-dir.js";
|
|
103
|
+
|
|
104
|
+
/** Graders a case may carry and still run: one Score criterion per grader, and a Score holds 32. */
|
|
105
|
+
export const EVAL_MAX_GRADERS = 32;
|
|
106
|
+
|
|
107
|
+
/** The most directories a case may sit below the suite's directory. */
|
|
108
|
+
export const EVAL_MAX_CASE_DEPTH = 32;
|
|
109
|
+
|
|
110
|
+
/** The longest case name, in characters (code points). */
|
|
111
|
+
export const EVAL_MAX_CASE_NAME = 200;
|
|
112
|
+
|
|
113
|
+
/** The longest plugin-relative path of a case's directory, in characters (code points). */
|
|
114
|
+
export const EVAL_MAX_CASE_DIR = 1024;
|
|
115
|
+
|
|
116
|
+
/** The longest `append_system_prompt` a case may carry, in characters: the most a run takes (`RunSpec.append_system_prompt`). */
|
|
117
|
+
export const EVAL_MAX_APPEND_SYSTEM_PROMPT = 32_768;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The features Stigmer reads but does not run yet, in the order a case is
|
|
121
|
+
* checked for them; `EvalCase.unsupported` is one of these phrases.
|
|
122
|
+
*/
|
|
123
|
+
export const EVAL_UNSUPPORTED_FEATURES = ["plugins", "more than 32 graders"] as const;
|
|
124
|
+
|
|
125
|
+
export type EvalUnsupportedFeature = (typeof EVAL_UNSUPPORTED_FEATURES)[number];
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The features the Cursor engine cannot run, in the order a case is
|
|
129
|
+
* checked for them. Its SDK keeps a conversation's history in a store it
|
|
130
|
+
* owns, so a recorded conversation cannot be resumed there, and its shell
|
|
131
|
+
* runs in the runner's process with no per-run environment, so `env` cannot
|
|
132
|
+
* reach it.
|
|
133
|
+
*/
|
|
134
|
+
export const EVAL_CURSOR_UNSUPPORTED_FEATURES = ["resumed conversations", "env"] as const;
|
|
135
|
+
|
|
136
|
+
export type EvalCursorUnsupportedFeature = (typeof EVAL_CURSOR_UNSUPPORTED_FEATURES)[number];
|
|
137
|
+
|
|
138
|
+
/** The first feature of `evalCase` the Cursor engine cannot run, or `undefined`. */
|
|
139
|
+
export function evalCaseUnsupportedOnCursor(evalCase: EvalCase): EvalCursorUnsupportedFeature | undefined {
|
|
140
|
+
if (evalCase.context.historyFile !== undefined) return "resumed conversations";
|
|
141
|
+
if (Object.keys(evalCase.env).length > 0) return "env";
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const PROMPT_FILE = "prompt.md";
|
|
146
|
+
const CASE_FILE = "case.yaml";
|
|
147
|
+
|
|
148
|
+
/** The defaults the format documents. */
|
|
149
|
+
const DEFAULT_RUNS = 3;
|
|
150
|
+
const DEFAULT_MAX_TURNS = 10;
|
|
151
|
+
const DEFAULT_TIMEOUT_SECONDS = 300;
|
|
152
|
+
|
|
153
|
+
/** Fields a case takes from either file; only those present are set, so a spread overrides by field. */
|
|
154
|
+
interface CaseFields {
|
|
155
|
+
readonly name?: string;
|
|
156
|
+
readonly description?: string;
|
|
157
|
+
readonly tags?: readonly string[];
|
|
158
|
+
readonly plugins?: readonly string[];
|
|
159
|
+
readonly runs?: number;
|
|
160
|
+
readonly model?: string;
|
|
161
|
+
readonly maxTurns?: number;
|
|
162
|
+
readonly timeoutSeconds?: number;
|
|
163
|
+
readonly allowedTools?: readonly string[];
|
|
164
|
+
readonly appendSystemPrompt?: string;
|
|
165
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** `prompt.md` frontmatter keys, the format's table. */
|
|
169
|
+
const PROMPT_KEYS: ReadonlySet<string> = new Set([
|
|
170
|
+
"schema_version",
|
|
171
|
+
"name",
|
|
172
|
+
"description",
|
|
173
|
+
"tags",
|
|
174
|
+
"plugins",
|
|
175
|
+
"runs",
|
|
176
|
+
"expected_outcome",
|
|
177
|
+
"model",
|
|
178
|
+
"max_turns",
|
|
179
|
+
"timeout_seconds",
|
|
180
|
+
"allowed_tools",
|
|
181
|
+
"append_system_prompt",
|
|
182
|
+
"env",
|
|
183
|
+
]);
|
|
184
|
+
|
|
185
|
+
const CASE_KEYS: ReadonlySet<string> = new Set([
|
|
186
|
+
"schema_version",
|
|
187
|
+
"name",
|
|
188
|
+
"description",
|
|
189
|
+
"tags",
|
|
190
|
+
"plugins",
|
|
191
|
+
"runs",
|
|
192
|
+
"expected_outcome",
|
|
193
|
+
"context",
|
|
194
|
+
"graders",
|
|
195
|
+
"execution",
|
|
196
|
+
]);
|
|
197
|
+
|
|
198
|
+
const EXECUTION_KEYS: ReadonlySet<string> = new Set([
|
|
199
|
+
"model",
|
|
200
|
+
"max_turns",
|
|
201
|
+
"timeout_seconds",
|
|
202
|
+
"allowed_tools",
|
|
203
|
+
"append_system_prompt",
|
|
204
|
+
"env",
|
|
205
|
+
"prompt",
|
|
206
|
+
]);
|
|
207
|
+
|
|
208
|
+
const CONTEXT_KEYS: ReadonlySet<string> = new Set(["scaffold_script", "add_dirs", "history_file"]);
|
|
209
|
+
|
|
210
|
+
export function readEvalSuite(files: PluginFiles): EvalSuite {
|
|
211
|
+
const index = new PluginFileIndex(files);
|
|
212
|
+
const findings: EvalSuiteFinding[] = [];
|
|
213
|
+
// The install reports manifest and server problems; this read only needs the values.
|
|
214
|
+
const set = detectManifests(index, new Findings());
|
|
215
|
+
const declared = new Set(
|
|
216
|
+
set === undefined ? [] : normaliseMcpServers(index, set.mcpSources, new Findings()).servers.map((server) => server.name),
|
|
217
|
+
);
|
|
218
|
+
const servers = [...declared].sort(comparePaths);
|
|
219
|
+
const { dir, held } = suiteDir(set, findings);
|
|
220
|
+
if (held) return { dir, cases: [], findings, servers };
|
|
221
|
+
const rule: MockServerRule = (server) =>
|
|
222
|
+
declared.has(server) ? undefined : `the plugin declares no MCP server ${quote(server)}, so these mocks are ignored`;
|
|
223
|
+
const cases = readCases({ index, dir, rule, findings, reportedMocks: new Set(), mocked: new Set(), loadsPlugins: true });
|
|
224
|
+
return { dir, cases, findings, servers };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* A pushed eval: the folder at the archive's root, read as a suite whose
|
|
229
|
+
* mocks may stand in for any server a name could be (the module comment).
|
|
230
|
+
* `dir` is the empty string, the root.
|
|
231
|
+
*/
|
|
232
|
+
export function readEvalFolder(files: PluginFiles): EvalSuite {
|
|
233
|
+
const index = new PluginFileIndex(files);
|
|
234
|
+
const findings: EvalSuiteFinding[] = [];
|
|
235
|
+
const rule: MockServerRule = (server) =>
|
|
236
|
+
isToolNameSegment(server)
|
|
237
|
+
? undefined
|
|
238
|
+
: `${quote(server)} cannot name an MCP server (letters, digits, '-' and '_', with no '__' and no trailing '_'), so these mocks are ignored`;
|
|
239
|
+
const suite: SuiteContext = { index, dir: "", rule, findings, reportedMocks: new Set(), mocked: new Set(), loadsPlugins: false };
|
|
240
|
+
const cases = readCases(suite);
|
|
241
|
+
return { dir: "", cases, findings, servers: [...suite.mocked].sort(comparePaths) };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Every case of the suite, in directory order, its findings added to the suite's. */
|
|
245
|
+
function readCases(suite: SuiteContext): readonly EvalCase[] {
|
|
246
|
+
const { index, dir, findings } = suite;
|
|
247
|
+
const cases: EvalCase[] = [];
|
|
248
|
+
const caseByName = new Map<string, string>();
|
|
249
|
+
for (const caseDir of findCaseDirs(index, dir, findings)) {
|
|
250
|
+
const caseFindings = new CaseFindings();
|
|
251
|
+
const evalCase = readCase(suite, caseDir, caseFindings);
|
|
252
|
+
if (evalCase !== undefined) {
|
|
253
|
+
const first = caseByName.get(evalCase.name);
|
|
254
|
+
if (first === undefined) {
|
|
255
|
+
caseByName.set(evalCase.name, caseDir);
|
|
256
|
+
cases.push(evalCase);
|
|
257
|
+
} else {
|
|
258
|
+
caseFindings.add("eval-case-invalid", caseDir, `case name ${quote(evalCase.name)} is already used by ${quote(first)}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
findings.push(...caseFindings.list);
|
|
262
|
+
}
|
|
263
|
+
return cases;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** What every case of one suite is read against. */
|
|
267
|
+
interface SuiteContext {
|
|
268
|
+
readonly index: PluginFileIndex;
|
|
269
|
+
/** The suite's directory; the empty string for a folder at the root. */
|
|
270
|
+
readonly dir: string;
|
|
271
|
+
/** Which servers the suite's mocks may stand in for. */
|
|
272
|
+
readonly rule: MockServerRule;
|
|
273
|
+
/** The suite's findings, where an ignored mock directory is reported. */
|
|
274
|
+
readonly findings: EvalSuiteFinding[];
|
|
275
|
+
/** Mock directories already reported as ignored. */
|
|
276
|
+
readonly reportedMocks: Set<string>;
|
|
277
|
+
/** The servers some case's mocks stand in for, the rule's kept ones. */
|
|
278
|
+
readonly mocked: Set<string>;
|
|
279
|
+
/**
|
|
280
|
+
* Whether a case's `plugins` may name the suite's own plugin: a plugin's
|
|
281
|
+
* suite runs with its plugin, so naming it is no feature Stigmer lacks.
|
|
282
|
+
* A pushed folder runs on an agent with the agent's plugins and loads no
|
|
283
|
+
* folder as a plugin, so any `plugins` entry is unsupported there.
|
|
284
|
+
*/
|
|
285
|
+
readonly loadsPlugins: boolean;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** The suite's directory, and whether declared skills hold it, so no case is read; findings for both. */
|
|
289
|
+
function suiteDir(
|
|
290
|
+
set: ReturnType<typeof detectManifests>,
|
|
291
|
+
findings: EvalSuiteFinding[],
|
|
292
|
+
): { readonly dir: string; readonly held: boolean } {
|
|
293
|
+
const { dir, unusable, heldBySkills } = resolveEvalDir(set);
|
|
294
|
+
const fallback = heldBySkills === undefined ? `using ${DEFAULT_EVAL_DIR}/` : `${DEFAULT_EVAL_DIR}/ is not usable either`;
|
|
295
|
+
if (unusable !== undefined) {
|
|
296
|
+
findings.push({ kind: "eval-dir-invalid", path: unusable.manifest, message: evalDirMessage(unusable, fallback) });
|
|
297
|
+
}
|
|
298
|
+
if (heldBySkills !== undefined) {
|
|
299
|
+
const problem =
|
|
300
|
+
`the skills path ${quote(`./${heldBySkills.path}`)} lies in ${DEFAULT_EVAL_DIR}/, the suite's default directory, so no suite is read; ` +
|
|
301
|
+
"move the skills or name another directory in experimental.evals";
|
|
302
|
+
findings.push({ kind: "eval-dir-invalid", path: heldBySkills.manifest, message: `${heldBySkills.manifest}: ${problem}` });
|
|
303
|
+
}
|
|
304
|
+
return { dir, held: heldBySkills !== undefined };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function evalDirMessage(unusable: NonNullable<EvalDirResolution["unusable"]>, fallback: string): string {
|
|
308
|
+
const named = `${unusable.manifest}: experimental.evals ${quoteJson(unusable.value)}`;
|
|
309
|
+
switch (unusable.reason) {
|
|
310
|
+
case "not-a-plain-path":
|
|
311
|
+
return `${named} is not a relative path of plain directory names (such as 'qa' or 'quality/evals'); ${fallback}`;
|
|
312
|
+
case "overlaps-skills":
|
|
313
|
+
return `${named} overlaps the plugin's skills; ${fallback}`;
|
|
314
|
+
/* v8 ignore start -- @preserve: the never arm; resolveEvalDir gives only these reasons */
|
|
315
|
+
default: {
|
|
316
|
+
const exhaustive: never = unusable.reason;
|
|
317
|
+
throw new Error(`unknown eval-dir reason ${String(exhaustive)}`);
|
|
318
|
+
}
|
|
319
|
+
/* v8 ignore stop */
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Every case directory under the suite, sorted by path, at most
|
|
325
|
+
* {@link EVAL_MAX_CASE_DEPTH} levels down; a directory at that depth that
|
|
326
|
+
* is no case and still holds directories is a finding, and its contents
|
|
327
|
+
* are not searched.
|
|
328
|
+
*/
|
|
329
|
+
function findCaseDirs(index: PluginFileIndex, root: string, findings: EvalSuiteFinding[]): readonly string[] {
|
|
330
|
+
const found: string[] = [];
|
|
331
|
+
const visit = (dir: string, depth: number): void => {
|
|
332
|
+
for (const child of index.childDirectories(dir)) {
|
|
333
|
+
if (depth === 0 && (child === "results" || child === "mocks")) continue;
|
|
334
|
+
const path = joinPath(dir, child);
|
|
335
|
+
if (index.has(`${path}/${PROMPT_FILE}`) || index.has(`${path}/${CASE_FILE}`)) found.push(path);
|
|
336
|
+
else if (depth + 1 < EVAL_MAX_CASE_DEPTH) visit(path, depth + 1);
|
|
337
|
+
else if (index.childDirectories(path).length > 0) {
|
|
338
|
+
findings.push({
|
|
339
|
+
kind: "eval-case-invalid",
|
|
340
|
+
path,
|
|
341
|
+
message: `${path}: the directory is nested too deep (cases sit at most ${EVAL_MAX_CASE_DEPTH} directories below ${root === "" ? "the folder's root" : `${root}/`}), so nothing beneath it is read`,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
visit(root, 0);
|
|
347
|
+
return found.sort(comparePaths);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** Whether `text` has more than `max` characters (code points), reading no further than it must. */
|
|
351
|
+
function longerThan(text: string, max: number): boolean {
|
|
352
|
+
if (text.length <= max) return false;
|
|
353
|
+
let characters = 0;
|
|
354
|
+
for (const _ of text) {
|
|
355
|
+
if (++characters > max) return true;
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** The fields `prompt.md` puts at its top level and `case.yaml` at its own. */
|
|
361
|
+
function readTopFields(object: JsonObject, scope: FieldScope): CaseFields {
|
|
362
|
+
const name = readNonEmptyString(object, "name", scope);
|
|
363
|
+
const description = readString(object, "description", scope);
|
|
364
|
+
const tags = readStringList(object, "tags", scope);
|
|
365
|
+
const plugins = readStringList(object, "plugins", scope);
|
|
366
|
+
const runs = readInteger(object, "runs", 1, 50, scope);
|
|
367
|
+
readString(object, "expected_outcome", scope);
|
|
368
|
+
return {
|
|
369
|
+
...(name !== undefined && { name }),
|
|
370
|
+
...(description !== undefined && { description }),
|
|
371
|
+
...(tags !== undefined && { tags }),
|
|
372
|
+
...(plugins !== undefined && { plugins }),
|
|
373
|
+
...(runs !== undefined && { runs }),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** The fields `prompt.md` puts at its top level and `case.yaml` under `execution:`. */
|
|
378
|
+
function readExecutionFields(object: JsonObject, scope: FieldScope): CaseFields {
|
|
379
|
+
const model = readNonEmptyString(object, "model", scope);
|
|
380
|
+
const maxTurns = readInteger(object, "max_turns", 1, 200, scope);
|
|
381
|
+
const timeoutSeconds = readInteger(object, "timeout_seconds", 1, 3600, scope);
|
|
382
|
+
const allowedTools = readStringList(object, "allowed_tools", scope);
|
|
383
|
+
const appendSystemPrompt = readAppendSystemPrompt(object, scope);
|
|
384
|
+
const env = readEnv(object, "env", scope);
|
|
385
|
+
return {
|
|
386
|
+
...(model !== undefined && { model }),
|
|
387
|
+
...(maxTurns !== undefined && { maxTurns }),
|
|
388
|
+
...(timeoutSeconds !== undefined && { timeoutSeconds }),
|
|
389
|
+
...(allowedTools !== undefined && { allowedTools }),
|
|
390
|
+
...(appendSystemPrompt !== undefined && { appendSystemPrompt }),
|
|
391
|
+
...(env !== undefined && { env }),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* A case's `append_system_prompt`, refused when longer than a run takes: a
|
|
397
|
+
* case loaded with it would fail every try at the run's create. Counted in
|
|
398
|
+
* characters (code points), as the run's limit is.
|
|
399
|
+
*/
|
|
400
|
+
function readAppendSystemPrompt(object: JsonObject, scope: FieldScope): string | undefined {
|
|
401
|
+
const value = readString(object, "append_system_prompt", scope);
|
|
402
|
+
if (value === undefined || !longerThan(value, EVAL_MAX_APPEND_SYSTEM_PROMPT)) return value;
|
|
403
|
+
return wrong(scope, "append_system_prompt", `at most ${EVAL_MAX_APPEND_SYSTEM_PROMPT} characters`);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
interface PromptFile {
|
|
407
|
+
readonly fields: CaseFields;
|
|
408
|
+
readonly body: string;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function readPromptFile(index: PluginFileIndex, path: string, findings: CaseFindings): PromptFile | undefined {
|
|
412
|
+
const scope: FieldScope = { path, label: "", invalid: "eval-case-invalid", findings };
|
|
413
|
+
const document = readMarkdown(index, scope);
|
|
414
|
+
if (document === undefined) return undefined;
|
|
415
|
+
const { fields } = document;
|
|
416
|
+
unknownKeys(fields, PROMPT_KEYS, scope, "eval-field-unknown", "frontmatter key");
|
|
417
|
+
if (fields["schema_version"] !== undefined) checkSchemaVersion(fields["schema_version"], scope);
|
|
418
|
+
return { fields: { ...readTopFields(fields, scope), ...readExecutionFields(fields, scope) }, body: document.body };
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
interface CaseFile {
|
|
422
|
+
readonly fields: CaseFields;
|
|
423
|
+
readonly prompt?: string;
|
|
424
|
+
readonly context: EvalCaseContext;
|
|
425
|
+
readonly graders: readonly EvalGrader[];
|
|
426
|
+
/** Entries under `graders:`, loaded or not. */
|
|
427
|
+
readonly graderCount: number;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function readCaseFile(index: PluginFileIndex, caseDir: string, caseFiles: ReadonlySet<string>, findings: CaseFindings): CaseFile | undefined {
|
|
431
|
+
const path = `${caseDir}/${CASE_FILE}`;
|
|
432
|
+
const scope: FieldScope = { path, label: "", invalid: "eval-case-invalid", findings };
|
|
433
|
+
const text = readDocument(index, path, "eval-case-invalid", findings);
|
|
434
|
+
if (text === undefined) return undefined;
|
|
435
|
+
const object = parseMapping(text, scope, "the file");
|
|
436
|
+
if (object === undefined) return undefined;
|
|
437
|
+
unknownKeys(object, CASE_KEYS, scope, "eval-field-unknown", "key");
|
|
438
|
+
|
|
439
|
+
if (object["schema_version"] === undefined) {
|
|
440
|
+
findings.add("eval-case-invalid", path, `schema_version is required ("1.1")`);
|
|
441
|
+
} else {
|
|
442
|
+
checkSchemaVersion(object["schema_version"], scope);
|
|
443
|
+
}
|
|
444
|
+
if (object["name"] === undefined) findings.add("eval-case-invalid", path, "name is required");
|
|
445
|
+
const top = readTopFields(object, scope);
|
|
446
|
+
|
|
447
|
+
let execution: CaseFields = {};
|
|
448
|
+
let prompt: string | undefined;
|
|
449
|
+
const executionValue = object["execution"];
|
|
450
|
+
if (executionValue !== undefined) {
|
|
451
|
+
if (!isJsonObject(executionValue)) {
|
|
452
|
+
wrong(scope, "execution", "a mapping");
|
|
453
|
+
} else {
|
|
454
|
+
const executionScope: FieldScope = { ...scope, label: "execution." };
|
|
455
|
+
unknownKeys(executionValue, EXECUTION_KEYS, executionScope, "eval-field-unknown", "key");
|
|
456
|
+
execution = readExecutionFields(executionValue, executionScope);
|
|
457
|
+
prompt = readString(executionValue, "prompt", executionScope);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const context = readContext(object["context"], scope);
|
|
462
|
+
|
|
463
|
+
const graders: EvalGrader[] = [];
|
|
464
|
+
let graderCount = 0;
|
|
465
|
+
const gradersValue = object["graders"];
|
|
466
|
+
if (gradersValue !== undefined) {
|
|
467
|
+
if (!Array.isArray(gradersValue)) {
|
|
468
|
+
scope.findings.add("eval-grader-invalid", path, "graders must be a list");
|
|
469
|
+
} else {
|
|
470
|
+
graderCount = gradersValue.length;
|
|
471
|
+
gradersValue.forEach((entry: unknown, i: number) => {
|
|
472
|
+
const entryScope: FieldScope = { path, label: `graders[${i}].`, invalid: "eval-grader-invalid", findings };
|
|
473
|
+
if (!isJsonObject(entry)) {
|
|
474
|
+
wrong({ ...entryScope, label: "" }, `graders[${i}]`, "a mapping");
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const name = readNonEmptyString(entry, "name", entryScope);
|
|
478
|
+
if (name === undefined) {
|
|
479
|
+
if (entry["name"] === undefined) findings.add("eval-grader-invalid", path, `graders[${i}].name is required`);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const fields = Object.fromEntries(Object.entries(entry).filter(([key]) => key !== "name"));
|
|
483
|
+
const grader = readGrader({ name, path, fields, caseDir, caseFiles }, entryScope, "key");
|
|
484
|
+
if (grader !== undefined) graders.push(grader);
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return {
|
|
490
|
+
fields: { ...top, ...execution },
|
|
491
|
+
...(prompt !== undefined && { prompt }),
|
|
492
|
+
context,
|
|
493
|
+
graders,
|
|
494
|
+
graderCount,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function readContext(value: unknown, scope: FieldScope): EvalCaseContext {
|
|
499
|
+
if (value === undefined) return { addDirs: [] };
|
|
500
|
+
if (!isJsonObject(value)) {
|
|
501
|
+
wrong(scope, "context", "a mapping");
|
|
502
|
+
return { addDirs: [] };
|
|
503
|
+
}
|
|
504
|
+
const contextScope: FieldScope = { ...scope, label: "context." };
|
|
505
|
+
unknownKeys(value, CONTEXT_KEYS, contextScope, "eval-field-unknown", "key");
|
|
506
|
+
const scaffoldScript = readNonEmptyString(value, "scaffold_script", contextScope);
|
|
507
|
+
const historyFile = readNonEmptyString(value, "history_file", contextScope);
|
|
508
|
+
const addDirs = readStringList(value, "add_dirs", contextScope) ?? [];
|
|
509
|
+
return {
|
|
510
|
+
...(scaffoldScript !== undefined && { scaffoldScript }),
|
|
511
|
+
...(historyFile !== undefined && { historyFile }),
|
|
512
|
+
addDirs,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** `graders/*.md`, in path order. */
|
|
517
|
+
function readGraderFiles(
|
|
518
|
+
index: PluginFileIndex,
|
|
519
|
+
caseDir: string,
|
|
520
|
+
caseFiles: ReadonlySet<string>,
|
|
521
|
+
findings: CaseFindings,
|
|
522
|
+
): { readonly graders: readonly EvalGrader[]; readonly count: number } {
|
|
523
|
+
const dir = `${caseDir}/graders`;
|
|
524
|
+
const names = index.childFiles(dir).filter((file) => file.endsWith(".md"));
|
|
525
|
+
const graders: EvalGrader[] = [];
|
|
526
|
+
for (const file of names) {
|
|
527
|
+
const path = `${dir}/${file}`;
|
|
528
|
+
const scope: FieldScope = { path, label: "", invalid: "eval-grader-invalid", findings };
|
|
529
|
+
const document = readMarkdown(index, scope);
|
|
530
|
+
if (document === undefined) continue;
|
|
531
|
+
const grader = readGrader(
|
|
532
|
+
{ name: file.slice(0, -".md".length), path, fields: document.fields, body: document.body, caseDir, caseFiles },
|
|
533
|
+
scope,
|
|
534
|
+
"frontmatter key",
|
|
535
|
+
);
|
|
536
|
+
if (grader !== undefined) graders.push(grader);
|
|
537
|
+
}
|
|
538
|
+
return { graders, count: names.length };
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function readCase(suite: SuiteContext, caseDir: string, findings: CaseFindings): EvalCase | undefined {
|
|
542
|
+
const { index } = suite;
|
|
543
|
+
if (longerThan(caseDir, EVAL_MAX_CASE_DIR)) {
|
|
544
|
+
findings.add("eval-case-invalid", caseDir, `the case directory's path is over ${EVAL_MAX_CASE_DIR} characters`);
|
|
545
|
+
return undefined;
|
|
546
|
+
}
|
|
547
|
+
const files = index.filesUnder(caseDir);
|
|
548
|
+
const caseFiles = new Set(files);
|
|
549
|
+
const promptPath = `${caseDir}/${PROMPT_FILE}`;
|
|
550
|
+
const casePath = `${caseDir}/${CASE_FILE}`;
|
|
551
|
+
const promptFile = index.has(promptPath) ? readPromptFile(index, promptPath, findings) : undefined;
|
|
552
|
+
const caseFile = index.has(casePath) ? readCaseFile(index, caseDir, caseFiles, findings) : undefined;
|
|
553
|
+
const graderFiles = readGraderFiles(index, caseDir, caseFiles, findings);
|
|
554
|
+
|
|
555
|
+
const graders = [...(caseFile?.graders ?? []), ...graderFiles.graders];
|
|
556
|
+
if ((caseFile?.graderCount ?? 0) + graderFiles.count === 0) {
|
|
557
|
+
findings.add("eval-case-invalid", caseDir, "graders is required: add a graders/<name>.md file or a 'graders' entry in case.yaml");
|
|
558
|
+
}
|
|
559
|
+
const seen = new Set<string>();
|
|
560
|
+
for (const grader of graders) {
|
|
561
|
+
if (seen.has(grader.name)) {
|
|
562
|
+
findings.add("eval-grader-invalid", grader.path, `grader name ${quote(grader.name)} is used by another grader of this case`);
|
|
563
|
+
}
|
|
564
|
+
seen.add(grader.name);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// A file that could not be read already said so; its prompt is unknown, not missing.
|
|
568
|
+
const unread = (index.has(promptPath) && promptFile === undefined) || (index.has(casePath) && caseFile === undefined);
|
|
569
|
+
const body = promptFile?.body;
|
|
570
|
+
const prompt = body !== undefined && body.trim() !== "" ? body : caseFile?.prompt;
|
|
571
|
+
if (!unread && (prompt === undefined || prompt.trim() === "")) {
|
|
572
|
+
findings.add(
|
|
573
|
+
"eval-case-invalid",
|
|
574
|
+
promptFile !== undefined ? promptPath : casePath,
|
|
575
|
+
"the prompt is required: write it as prompt.md's body or as case.yaml's execution.prompt",
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const fields: CaseFields = { ...caseFile?.fields, ...promptFile?.fields };
|
|
580
|
+
const name = fields.name ?? basename(caseDir);
|
|
581
|
+
if (longerThan(name, EVAL_MAX_CASE_NAME)) {
|
|
582
|
+
const source = promptFile?.fields.name !== undefined ? promptPath : caseFile?.fields.name !== undefined ? casePath : caseDir;
|
|
583
|
+
findings.add("eval-case-invalid", source, `the case name ${quote(name)} is over ${EVAL_MAX_CASE_NAME} characters`);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
const context = checkContext(index, caseDir, caseFiles, caseFile?.context ?? { addDirs: [] }, findings);
|
|
587
|
+
const mocks = readCaseMocks(index, suite.dir, caseDir, suite.rule, findings, suite.findings, suite.reportedMocks);
|
|
588
|
+
for (const server of mocks.servers) suite.mocked.add(server.server);
|
|
589
|
+
|
|
590
|
+
if (!findings.empty || prompt === undefined) return undefined;
|
|
591
|
+
|
|
592
|
+
const env = fields.env ?? {};
|
|
593
|
+
const plugins = fields.plugins ?? [];
|
|
594
|
+
const unsupported = unsupportedOf(caseDir, plugins, graders, suite.loadsPlugins);
|
|
595
|
+
return {
|
|
596
|
+
name,
|
|
597
|
+
dir: caseDir,
|
|
598
|
+
...(fields.description !== undefined && { description: fields.description }),
|
|
599
|
+
tags: fields.tags ?? [],
|
|
600
|
+
prompt,
|
|
601
|
+
runs: fields.runs ?? DEFAULT_RUNS,
|
|
602
|
+
...(fields.model !== undefined && { model: fields.model }),
|
|
603
|
+
maxTurns: fields.maxTurns ?? DEFAULT_MAX_TURNS,
|
|
604
|
+
timeoutSeconds: fields.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS,
|
|
605
|
+
allowedTools: fields.allowedTools ?? [],
|
|
606
|
+
...(fields.appendSystemPrompt !== undefined && { appendSystemPrompt: fields.appendSystemPrompt }),
|
|
607
|
+
env,
|
|
608
|
+
plugins,
|
|
609
|
+
context,
|
|
610
|
+
files,
|
|
611
|
+
graders,
|
|
612
|
+
mocks: mocks.servers,
|
|
613
|
+
replays: mocks.replays,
|
|
614
|
+
...(unsupported !== undefined && { unsupported }),
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* A case-relative path, normalised: no `./`, no empty segment. `undefined`
|
|
620
|
+
* when it is absolute, backslashed, or climbs with `..`, since every context
|
|
621
|
+
* path must name something inside the case.
|
|
622
|
+
*/
|
|
623
|
+
function inCase(path: string): string | undefined {
|
|
624
|
+
if (path.startsWith("/") || path.includes("\\")) return undefined;
|
|
625
|
+
const parts = path.split("/").filter((part) => part !== "" && part !== ".");
|
|
626
|
+
if (parts.length === 0 || parts.includes("..")) return undefined;
|
|
627
|
+
return parts.join("/");
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** The case's `context`, its paths normalised and checked against its files (the module header). */
|
|
631
|
+
function checkContext(
|
|
632
|
+
index: PluginFileIndex,
|
|
633
|
+
caseDir: string,
|
|
634
|
+
caseFiles: ReadonlySet<string>,
|
|
635
|
+
context: EvalCaseContext,
|
|
636
|
+
findings: CaseFindings,
|
|
637
|
+
): EvalCaseContext {
|
|
638
|
+
const path = `${caseDir}/${CASE_FILE}`;
|
|
639
|
+
const wrongPath = (field: string, expected: string, value: string): undefined => {
|
|
640
|
+
findings.add("eval-case-invalid", path, `context.${field} must be ${expected} (${quote(value)} is not)`);
|
|
641
|
+
return undefined;
|
|
642
|
+
};
|
|
643
|
+
const file = (field: string, value: string | undefined): string | undefined => {
|
|
644
|
+
if (value === undefined) return undefined;
|
|
645
|
+
const normalised = inCase(value);
|
|
646
|
+
if (normalised === undefined || !caseFiles.has(`${caseDir}/${normalised}`)) {
|
|
647
|
+
return wrongPath(field, "a file in the case directory", value);
|
|
648
|
+
}
|
|
649
|
+
return normalised;
|
|
650
|
+
};
|
|
651
|
+
const scaffoldScript = file("scaffold_script", context.scaffoldScript);
|
|
652
|
+
let historyFile = file("history_file", context.historyFile);
|
|
653
|
+
if (historyFile !== undefined) {
|
|
654
|
+
if (!historyFile.endsWith(".jsonl")) {
|
|
655
|
+
historyFile = wrongPath("history_file", "a .jsonl transcript", historyFile);
|
|
656
|
+
} else {
|
|
657
|
+
const text = readDocument(index, `${caseDir}/${historyFile}`, "eval-case-invalid", findings);
|
|
658
|
+
const parsed = text === undefined ? undefined : parseTranscript(text, { requirePairing: true });
|
|
659
|
+
if (parsed !== undefined && !parsed.ok) {
|
|
660
|
+
findings.add("eval-case-invalid", `${caseDir}/${historyFile}`, `the conversation cannot be resumed: ${parsed.error}`);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
const addDirs: string[] = [];
|
|
665
|
+
for (const dir of context.addDirs) {
|
|
666
|
+
const normalised = inCase(dir);
|
|
667
|
+
if (normalised === undefined || !index.isDirectory(`${caseDir}/${normalised}`)) {
|
|
668
|
+
wrongPath("add_dirs", "directories inside the case directory", dir);
|
|
669
|
+
} else {
|
|
670
|
+
addDirs.push(normalised);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
return {
|
|
674
|
+
...(scaffoldScript !== undefined && { scaffoldScript }),
|
|
675
|
+
...(historyFile !== undefined && { historyFile }),
|
|
676
|
+
addDirs,
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Whether `entry`, read relative to the plugin-relative `caseDir`, is the
|
|
682
|
+
* plugin's root. Resolved lexically, segment by segment, the way the reader
|
|
683
|
+
* sees the package: an absolute or backslashed path, or one that climbs
|
|
684
|
+
* above the root on the way, names something outside the package read here.
|
|
685
|
+
*/
|
|
686
|
+
function namesPluginRoot(caseDir: string, entry: string): boolean {
|
|
687
|
+
if (entry.startsWith("/") || entry.includes("\\")) return false;
|
|
688
|
+
const resolved = caseDir.split("/");
|
|
689
|
+
for (const segment of entry.split("/")) {
|
|
690
|
+
if (segment === "" || segment === ".") continue;
|
|
691
|
+
if (segment !== "..") resolved.push(segment);
|
|
692
|
+
else if (resolved.pop() === undefined) return false;
|
|
693
|
+
}
|
|
694
|
+
return resolved.length === 0;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* A case's `plugins` names the plugins it runs with, relative to the case.
|
|
699
|
+
* An entry that resolves to this plugin's root is the plugin under test, the
|
|
700
|
+
* format's override of auto-detect; any other entry is a plugin Stigmer would
|
|
701
|
+
* not attach, so the case does not run rather than score without it.
|
|
702
|
+
*/
|
|
703
|
+
function unsupportedOf(
|
|
704
|
+
caseDir: string,
|
|
705
|
+
plugins: readonly string[],
|
|
706
|
+
graders: readonly EvalGrader[],
|
|
707
|
+
loadsPlugins: boolean,
|
|
708
|
+
): EvalUnsupportedFeature | undefined {
|
|
709
|
+
if (plugins.length > 0 && !loadsPlugins) return "plugins";
|
|
710
|
+
if (!plugins.every((entry) => namesPluginRoot(caseDir, entry))) return "plugins";
|
|
711
|
+
if (graders.length > EVAL_MAX_GRADERS) return "more than 32 graders";
|
|
712
|
+
return undefined;
|
|
713
|
+
}
|