@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
package/evals/glob.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a glob is well formed, in the grammar Stigmer's eval graders
|
|
3
|
+
* match with: `*`, `**`, `?`, `[...]` classes with ranges and `!` or `^`
|
|
4
|
+
* negation (a `]` right after the opening or the negation is a member),
|
|
5
|
+
* and `{a,b}` alternatives that may nest, expanding to at most
|
|
6
|
+
* GLOB_MAX_ALTERNATIVES and nesting at most GLOB_MAX_BRACE_DEPTH deep;
|
|
7
|
+
* everything else is literal, a `}` with no `{` included.
|
|
8
|
+
*
|
|
9
|
+
* A glob is also bounded in size, because a match costs its alternatives
|
|
10
|
+
* times their tokens times the path's length: at most GLOB_MAX_LENGTH
|
|
11
|
+
* characters, and at most GLOB_MAX_TOKENS tokens summed over every
|
|
12
|
+
* alternative it expands to. A token is a literal character, a `?`, a
|
|
13
|
+
* class, or a run of stars; a `/` right after `**` counts as its own token,
|
|
14
|
+
* so the count does not depend on whether the glob matches paths or names,
|
|
15
|
+
* and a class counts once per range or character it holds, since the
|
|
16
|
+
* matcher tests a character against each of them. A class holds at most
|
|
17
|
+
* GLOB_MAX_CLASS_ITEMS ranges or characters.
|
|
18
|
+
*
|
|
19
|
+
* Only validity is checked here: the suite reader refuses a `file_exists`
|
|
20
|
+
* grader whose `path` is malformed (too long, a class or a brace never
|
|
21
|
+
* closed, a reversed range, a class too large, too many alternatives or
|
|
22
|
+
* tokens, braces nested too deep), so the author hears it at push rather than as a try left not
|
|
23
|
+
* graded. The server
|
|
24
|
+
* compiles and matches globs with its own matcher over the same grammar,
|
|
25
|
+
* and its tests pin the two readers to one table, error sentences
|
|
26
|
+
* included.
|
|
27
|
+
*/
|
|
28
|
+
/** The most alternatives a glob's braces may expand to. */
|
|
29
|
+
export const GLOB_MAX_ALTERNATIVES = 64;
|
|
30
|
+
/** The deepest braces may nest. */
|
|
31
|
+
export const GLOB_MAX_BRACE_DEPTH = 16;
|
|
32
|
+
/** The most characters (code points) a glob may hold. */
|
|
33
|
+
export const GLOB_MAX_LENGTH = 1024;
|
|
34
|
+
/** The most tokens a glob may expand to, summed over its alternatives. */
|
|
35
|
+
export const GLOB_MAX_TOKENS = 4096;
|
|
36
|
+
/** The most ranges or characters one `[...]` class may hold. */
|
|
37
|
+
export const GLOB_MAX_CLASS_ITEMS = 32;
|
|
38
|
+
/** Whether `glob` holds more than GLOB_MAX_LENGTH code points, counting no further. */
|
|
39
|
+
function tooLong(glob) {
|
|
40
|
+
if (glob.length <= GLOB_MAX_LENGTH)
|
|
41
|
+
return false;
|
|
42
|
+
let points = 0;
|
|
43
|
+
for (const _ of glob) {
|
|
44
|
+
if (++points > GLOB_MAX_LENGTH)
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
/** Why `glob` is malformed, or `undefined` when it is a glob. */
|
|
50
|
+
export function globError(glob) {
|
|
51
|
+
if (tooLong(glob))
|
|
52
|
+
return `it is longer than ${GLOB_MAX_LENGTH} characters`;
|
|
53
|
+
const chars = Array.from(glob);
|
|
54
|
+
let pos = 0;
|
|
55
|
+
const cap = GLOB_MAX_ALTERNATIVES + 1;
|
|
56
|
+
const tokenCap = GLOB_MAX_TOKENS + 1;
|
|
57
|
+
/** Skips a class from its `[`: its ranges and characters, or the error when it never closes, holds a reversed range or holds too many. */
|
|
58
|
+
const skipClass = () => {
|
|
59
|
+
const open = pos;
|
|
60
|
+
let i = open + 1;
|
|
61
|
+
if (chars[i] === "!" || chars[i] === "^")
|
|
62
|
+
i++;
|
|
63
|
+
let first = true;
|
|
64
|
+
let items = 0;
|
|
65
|
+
for (;;) {
|
|
66
|
+
const char = chars[i];
|
|
67
|
+
if (char === undefined)
|
|
68
|
+
return `'[' at ${open} is never closed`;
|
|
69
|
+
if (char === "]" && !first)
|
|
70
|
+
break;
|
|
71
|
+
first = false;
|
|
72
|
+
const end = chars[i + 2];
|
|
73
|
+
if (chars[i + 1] === "-" && end !== undefined && end !== "]") {
|
|
74
|
+
if ((char.codePointAt(0) ?? 0) > (end.codePointAt(0) ?? 0))
|
|
75
|
+
return `range '${char}-${end}' is reversed`;
|
|
76
|
+
i += 3;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
i++;
|
|
80
|
+
}
|
|
81
|
+
if (++items > GLOB_MAX_CLASS_ITEMS)
|
|
82
|
+
return `'[' at ${open} holds more than ${GLOB_MAX_CLASS_ITEMS} ranges or characters`;
|
|
83
|
+
}
|
|
84
|
+
pos = i + 1;
|
|
85
|
+
return items;
|
|
86
|
+
};
|
|
87
|
+
/** The size of a sequence, up to the end or, inside braces, its `,` or `}`. */
|
|
88
|
+
const sequence = (depth) => {
|
|
89
|
+
let count = 1;
|
|
90
|
+
let tokens = 0;
|
|
91
|
+
while (pos < chars.length) {
|
|
92
|
+
const char = chars[pos];
|
|
93
|
+
if (depth > 0 && (char === "," || char === "}"))
|
|
94
|
+
return { count, tokens };
|
|
95
|
+
if (char === "{") {
|
|
96
|
+
const open = pos;
|
|
97
|
+
if (depth + 1 > GLOB_MAX_BRACE_DEPTH)
|
|
98
|
+
return `braces are nested more than ${GLOB_MAX_BRACE_DEPTH} deep`;
|
|
99
|
+
pos++;
|
|
100
|
+
let sum = 0;
|
|
101
|
+
let sumTokens = 0;
|
|
102
|
+
for (;;) {
|
|
103
|
+
const inner = sequence(depth + 1);
|
|
104
|
+
if (typeof inner === "string")
|
|
105
|
+
return inner;
|
|
106
|
+
sum = Math.min(sum + inner.count, cap);
|
|
107
|
+
sumTokens = Math.min(sumTokens + inner.tokens, tokenCap);
|
|
108
|
+
const close = chars[pos];
|
|
109
|
+
if (close === undefined)
|
|
110
|
+
return `'{' at ${open} is never closed`;
|
|
111
|
+
pos++;
|
|
112
|
+
if (close === "}")
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
// Each head alternative is followed by every tail: n heads of t tokens
|
|
116
|
+
// in all, m tails of s, make n*m alternatives of t*m + s*n tokens.
|
|
117
|
+
tokens = Math.min(tokens * sum + sumTokens * count, tokenCap);
|
|
118
|
+
count = Math.min(count * sum, cap);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
let weight = 1;
|
|
122
|
+
if (char === "[") {
|
|
123
|
+
const items = skipClass();
|
|
124
|
+
if (typeof items === "string")
|
|
125
|
+
return items;
|
|
126
|
+
weight = items;
|
|
127
|
+
}
|
|
128
|
+
else if (char === "*") {
|
|
129
|
+
while (chars[pos] === "*")
|
|
130
|
+
pos++;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
pos++;
|
|
134
|
+
}
|
|
135
|
+
tokens = Math.min(tokens + count * weight, tokenCap);
|
|
136
|
+
}
|
|
137
|
+
return { count, tokens };
|
|
138
|
+
};
|
|
139
|
+
const result = sequence(0);
|
|
140
|
+
if (typeof result === "string")
|
|
141
|
+
return result;
|
|
142
|
+
if (result.count > GLOB_MAX_ALTERNATIVES)
|
|
143
|
+
return `it expands to more than ${GLOB_MAX_ALTERNATIVES} alternatives`;
|
|
144
|
+
return result.tokens > GLOB_MAX_TOKENS ? `it expands to more than ${GLOB_MAX_TOKENS} tokens` : undefined;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=glob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../src/evals/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAExC,mCAAmC;AACnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE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,MAAM,GAAG,KAAK,CAAC;YACjB,CAAC;iBAAM,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;gBACxB,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG;oBAAE,GAAG,EAAE,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACN,GAAG,EAAE,CAAC;YACR,CAAC;YACD,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,KAAK,GAAG,MAAM,EAAE,QAAQ,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC3B,CAAC,CAAC;IAEF,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,MAAM,CAAC,KAAK,GAAG,qBAAqB;QAAE,OAAO,2BAA2B,qBAAqB,eAAe,CAAC;IACjH,OAAO,MAAM,CAAC,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,2BAA2B,eAAe,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3G,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One grader, from a `graders/<name>.md` file's frontmatter and body or a
|
|
3
|
+
* `case.yaml` `graders:` entry, into the normalised `EvalGrader`.
|
|
4
|
+
*
|
|
5
|
+
* The keys are the format's: `type`, `weight` and `arm` for every grader,
|
|
6
|
+
* plus the options of its type, and `name` on a `case.yaml` entry. A key
|
|
7
|
+
* outside that set, or a value of the wrong type, is `eval-grader-invalid`
|
|
8
|
+
* and the case does not load: a grader read leniently is a different check
|
|
9
|
+
* from the one the author wrote, and a score built on it is wrong.
|
|
10
|
+
*
|
|
11
|
+
* In the `.md` layout the body carries the text a grader needs most: the
|
|
12
|
+
* rubric of an `llm` or `baseline` grader, or a `regex` grader's pattern.
|
|
13
|
+
* A frontmatter key of the same name wins when both are present, so a
|
|
14
|
+
* file that sets `criteria:` and also keeps notes in its body grades on
|
|
15
|
+
* the key. The body of a criteria is trimmed (a judge reads it as prose);
|
|
16
|
+
* a pattern from the body is trimmed too, since its trailing newline would
|
|
17
|
+
* otherwise be part of the expression.
|
|
18
|
+
*
|
|
19
|
+
* A weight is at most {@link EVAL_MAX_GRADER_WEIGHT}, so a weighted mean
|
|
20
|
+
* of passing checks never overflows to a score that is not a number.
|
|
21
|
+
*
|
|
22
|
+
* Defaults the format documents are applied here: weight 1, regex flags
|
|
23
|
+
* empty and `match: contains`, `target`/`focus` `last_message`,
|
|
24
|
+
* `tool_used` min 1 and max unlimited, `file_exists` `exists: true`. A
|
|
25
|
+
* `file_exists` `path` must be a well-formed glob (glob.ts).
|
|
26
|
+
*/
|
|
27
|
+
import { type JsonObject } from "../documents.js";
|
|
28
|
+
import { type FieldScope } from "./fields.js";
|
|
29
|
+
import type { EvalGrader } from "./types.js";
|
|
30
|
+
/** What one grader is read from. */
|
|
31
|
+
export interface GraderSource {
|
|
32
|
+
/** The grader's name: the file stem, or the entry's `name`. */
|
|
33
|
+
readonly name: string;
|
|
34
|
+
/** The file that declared it, plugin-relative. */
|
|
35
|
+
readonly path: string;
|
|
36
|
+
/** The frontmatter or the entry, `name` removed. */
|
|
37
|
+
readonly fields: JsonObject;
|
|
38
|
+
/** A `.md` file's body; `undefined` for a `case.yaml` entry. */
|
|
39
|
+
readonly body?: string;
|
|
40
|
+
/** The case's files, to check a `baseline_file` is one of them. */
|
|
41
|
+
readonly caseDir: string;
|
|
42
|
+
readonly caseFiles: ReadonlySet<string>;
|
|
43
|
+
}
|
|
44
|
+
/** The grader, or `undefined` after at least one finding in `scope`. */
|
|
45
|
+
export declare function readGrader(source: GraderSource, scope: FieldScope, noun: string): EvalGrader | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The heaviest weight a grader may carry. A try's score is a weighted mean
|
|
48
|
+
* over a case's at most 32 graders, so this keeps every sum of weights and
|
|
49
|
+
* of weighted scores finite.
|
|
50
|
+
*/
|
|
51
|
+
export declare const EVAL_MAX_GRADER_WEIGHT = 1000;
|
|
52
|
+
//# sourceMappingURL=graders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graders.d.ts","sourceRoot":"","sources":["../src/evals/graders.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EACL,KAAK,UAAU,EAOhB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAa,UAAU,EAA+D,MAAM,YAAY,CAAC;AAoBrH,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,gEAAgE;IAChE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,mEAAmE;IACnE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACzC;AAED,wEAAwE;AACxE,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAwBxG;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,OAAO,CAAC"}
|
package/evals/graders.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One grader, from a `graders/<name>.md` file's frontmatter and body or a
|
|
3
|
+
* `case.yaml` `graders:` entry, into the normalised `EvalGrader`.
|
|
4
|
+
*
|
|
5
|
+
* The keys are the format's: `type`, `weight` and `arm` for every grader,
|
|
6
|
+
* plus the options of its type, and `name` on a `case.yaml` entry. A key
|
|
7
|
+
* outside that set, or a value of the wrong type, is `eval-grader-invalid`
|
|
8
|
+
* and the case does not load: a grader read leniently is a different check
|
|
9
|
+
* from the one the author wrote, and a score built on it is wrong.
|
|
10
|
+
*
|
|
11
|
+
* In the `.md` layout the body carries the text a grader needs most: the
|
|
12
|
+
* rubric of an `llm` or `baseline` grader, or a `regex` grader's pattern.
|
|
13
|
+
* A frontmatter key of the same name wins when both are present, so a
|
|
14
|
+
* file that sets `criteria:` and also keeps notes in its body grades on
|
|
15
|
+
* the key. The body of a criteria is trimmed (a judge reads it as prose);
|
|
16
|
+
* a pattern from the body is trimmed too, since its trailing newline would
|
|
17
|
+
* otherwise be part of the expression.
|
|
18
|
+
*
|
|
19
|
+
* A weight is at most {@link EVAL_MAX_GRADER_WEIGHT}, so a weighted mean
|
|
20
|
+
* of passing checks never overflows to a score that is not a number.
|
|
21
|
+
*
|
|
22
|
+
* Defaults the format documents are applied here: weight 1, regex flags
|
|
23
|
+
* empty and `match: contains`, `target`/`focus` `last_message`,
|
|
24
|
+
* `tool_used` min 1 and max unlimited, `file_exists` `exists: true`. A
|
|
25
|
+
* `file_exists` `path` must be a well-formed glob (glob.ts).
|
|
26
|
+
*/
|
|
27
|
+
import { isJsonObject } from "../documents.js";
|
|
28
|
+
import { quote, readNonEmptyString, readString, regexError, unknownKeys, wrong, } from "./fields.js";
|
|
29
|
+
import { globError } from "./glob.js";
|
|
30
|
+
const COMMON_KEYS = ["type", "weight", "arm"];
|
|
31
|
+
/** Each type's own options, the format's "Grader types" table. */
|
|
32
|
+
const TYPE_KEYS = {
|
|
33
|
+
regex: ["pattern", "flags", "match", "target"],
|
|
34
|
+
tool_used: ["tool", "input_match", "min", "max"],
|
|
35
|
+
tool_order: ["before", "after"],
|
|
36
|
+
file_exists: ["path", "exists"],
|
|
37
|
+
llm: ["criteria", "focus"],
|
|
38
|
+
baseline: ["baseline_file", "criteria"],
|
|
39
|
+
};
|
|
40
|
+
const GRADER_TYPES = Object.keys(TYPE_KEYS);
|
|
41
|
+
function isGraderType(value) {
|
|
42
|
+
return typeof value === "string" && GRADER_TYPES.includes(value);
|
|
43
|
+
}
|
|
44
|
+
/** The grader, or `undefined` after at least one finding in `scope`. */
|
|
45
|
+
export function readGrader(source, scope, noun) {
|
|
46
|
+
const { fields } = source;
|
|
47
|
+
const before = scope.findings.list.length;
|
|
48
|
+
const type = fields["type"];
|
|
49
|
+
if (type === undefined) {
|
|
50
|
+
scope.findings.add(scope.invalid, scope.path, `${scope.label}type is required (one of ${GRADER_TYPES.join(", ")})`);
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
if (!isGraderType(type)) {
|
|
54
|
+
return wrong(scope, "type", `one of ${GRADER_TYPES.join(", ")}`);
|
|
55
|
+
}
|
|
56
|
+
unknownKeys(fields, new Set([...COMMON_KEYS, ...TYPE_KEYS[type]]), scope, scope.invalid, noun);
|
|
57
|
+
const weight = readWeight(fields, scope);
|
|
58
|
+
const arm = readArm(fields, scope);
|
|
59
|
+
const check = readCheck(type, source, scope);
|
|
60
|
+
if (scope.findings.list.length > before || check === undefined)
|
|
61
|
+
return undefined;
|
|
62
|
+
return {
|
|
63
|
+
name: source.name,
|
|
64
|
+
path: source.path,
|
|
65
|
+
weight: weight ?? 1,
|
|
66
|
+
...(arm !== undefined && { arm }),
|
|
67
|
+
check,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The heaviest weight a grader may carry. A try's score is a weighted mean
|
|
72
|
+
* over a case's at most 32 graders, so this keeps every sum of weights and
|
|
73
|
+
* of weighted scores finite.
|
|
74
|
+
*/
|
|
75
|
+
export const EVAL_MAX_GRADER_WEIGHT = 1000;
|
|
76
|
+
function readWeight(fields, scope) {
|
|
77
|
+
const value = fields["weight"];
|
|
78
|
+
if (value === undefined)
|
|
79
|
+
return undefined;
|
|
80
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0 || value > EVAL_MAX_GRADER_WEIGHT) {
|
|
81
|
+
return wrong(scope, "weight", `a positive number no larger than ${EVAL_MAX_GRADER_WEIGHT}`);
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
function readArm(fields, scope) {
|
|
86
|
+
const value = fields["arm"];
|
|
87
|
+
if (value === undefined)
|
|
88
|
+
return undefined;
|
|
89
|
+
if (value !== "with-only" && value !== "both")
|
|
90
|
+
return wrong(scope, "arm", "'with-only' or 'both'");
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
function readCheck(type, source, scope) {
|
|
94
|
+
const { fields } = source;
|
|
95
|
+
switch (type) {
|
|
96
|
+
case "regex":
|
|
97
|
+
return readRegex(source, scope);
|
|
98
|
+
case "tool_used": {
|
|
99
|
+
const tool = readNonEmptyString(fields, "tool", scope);
|
|
100
|
+
const inputMatch = readPattern(fields, "input_match", scope);
|
|
101
|
+
const writtenMin = readCount(fields, "min", scope);
|
|
102
|
+
const max = readCount(fields, "max", scope);
|
|
103
|
+
if (tool === undefined)
|
|
104
|
+
return required(scope, "tool", fields);
|
|
105
|
+
// A max alone lowers the default min of 1 to it, so `max: 0` reads as
|
|
106
|
+
// "never called" rather than a range nothing can satisfy.
|
|
107
|
+
const min = writtenMin ?? (max === undefined ? 1 : Math.min(1, max));
|
|
108
|
+
if (max !== undefined && min > max)
|
|
109
|
+
return wrong(scope, "min", `at most max (${max})`);
|
|
110
|
+
return {
|
|
111
|
+
type,
|
|
112
|
+
tool,
|
|
113
|
+
...(inputMatch !== undefined && { inputMatch }),
|
|
114
|
+
min,
|
|
115
|
+
...(max !== undefined && { max }),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
case "tool_order": {
|
|
119
|
+
const before = readToolRef(fields, "before", scope);
|
|
120
|
+
const after = readToolRef(fields, "after", scope);
|
|
121
|
+
if (before === undefined)
|
|
122
|
+
return required(scope, "before", fields);
|
|
123
|
+
if (after === undefined)
|
|
124
|
+
return required(scope, "after", fields);
|
|
125
|
+
return { type, before, after };
|
|
126
|
+
}
|
|
127
|
+
case "file_exists": {
|
|
128
|
+
const path = readNonEmptyString(fields, "path", scope);
|
|
129
|
+
const exists = fields["exists"];
|
|
130
|
+
if (exists !== undefined && typeof exists !== "boolean")
|
|
131
|
+
return wrong(scope, "exists", "true or false");
|
|
132
|
+
if (path === undefined)
|
|
133
|
+
return required(scope, "path", fields);
|
|
134
|
+
const malformed = globError(path);
|
|
135
|
+
if (malformed !== undefined)
|
|
136
|
+
return wrong(scope, "path", `a glob (${malformed})`);
|
|
137
|
+
return { type, path, exists: exists ?? true };
|
|
138
|
+
}
|
|
139
|
+
case "llm": {
|
|
140
|
+
const criteria = readCriteria(source, scope);
|
|
141
|
+
const focus = readFocus(fields["focus"], "focus", scope);
|
|
142
|
+
if (criteria === undefined || focus === undefined)
|
|
143
|
+
return undefined;
|
|
144
|
+
return { type, criteria, focus };
|
|
145
|
+
}
|
|
146
|
+
case "baseline": {
|
|
147
|
+
const criteria = readCriteria(source, scope);
|
|
148
|
+
const baselineFile = readNonEmptyString(fields, "baseline_file", scope);
|
|
149
|
+
if (baselineFile === undefined)
|
|
150
|
+
return required(scope, "baseline_file", fields);
|
|
151
|
+
if (!source.caseFiles.has(`${source.caseDir}/${baselineFile.replace(/^\.\//, "")}`)) {
|
|
152
|
+
return wrong(scope, "baseline_file", `a file in the case directory (${quote(baselineFile)} is not)`);
|
|
153
|
+
}
|
|
154
|
+
if (criteria === undefined)
|
|
155
|
+
return undefined;
|
|
156
|
+
return { type, baselineFile, criteria };
|
|
157
|
+
}
|
|
158
|
+
/* v8 ignore start -- @preserve: the never arm; readGrader admits only GRADER_TYPES, so no type reaches it */
|
|
159
|
+
default: {
|
|
160
|
+
const exhaustive = type;
|
|
161
|
+
throw new Error(`unknown grader type ${String(exhaustive)}`);
|
|
162
|
+
}
|
|
163
|
+
/* v8 ignore stop */
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** A required option that is absent; a present one of the wrong type already reported itself. */
|
|
167
|
+
function required(scope, field, fields) {
|
|
168
|
+
if (fields[field] === undefined)
|
|
169
|
+
scope.findings.add(scope.invalid, scope.path, `${scope.label}${field} is required`);
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
function readRegex(source, scope) {
|
|
173
|
+
const { fields } = source;
|
|
174
|
+
const flags = readString(fields, "flags", scope) ?? "";
|
|
175
|
+
const fromBody = source.body?.trim();
|
|
176
|
+
const pattern = fields["pattern"] !== undefined ? readNonEmptyString(fields, "pattern", scope) : fromBody === "" ? undefined : fromBody;
|
|
177
|
+
const match = readMatch(fields["match"], scope);
|
|
178
|
+
const target = readFocus(fields["target"], "target", scope);
|
|
179
|
+
if (pattern === undefined) {
|
|
180
|
+
if (fields["pattern"] === undefined) {
|
|
181
|
+
scope.findings.add(scope.invalid, scope.path, `${scope.label}pattern is required`);
|
|
182
|
+
}
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
if (regexError("", flags) !== undefined)
|
|
186
|
+
return wrong(scope, "flags", "JavaScript regular expression flags, such as 'i'");
|
|
187
|
+
const error = regexError(pattern, flags);
|
|
188
|
+
if (error !== undefined)
|
|
189
|
+
return wrong(scope, "pattern", `a JavaScript regular expression (${error})`);
|
|
190
|
+
if (match === undefined || target === undefined)
|
|
191
|
+
return undefined;
|
|
192
|
+
return { type: "regex", pattern, flags, match, target };
|
|
193
|
+
}
|
|
194
|
+
const COUNT_MATCH = /^count:(\d+)$/;
|
|
195
|
+
function readMatch(value, scope) {
|
|
196
|
+
if (value === undefined || value === "contains")
|
|
197
|
+
return { kind: "contains" };
|
|
198
|
+
if (value === "not_contains")
|
|
199
|
+
return { kind: "not_contains" };
|
|
200
|
+
const count = typeof value === "string" ? COUNT_MATCH.exec(value) : null;
|
|
201
|
+
if (count?.[1] !== undefined)
|
|
202
|
+
return { kind: "count", count: Number(count[1]) };
|
|
203
|
+
return wrong(scope, "match", "'contains', 'not_contains' or \"count:N\"");
|
|
204
|
+
}
|
|
205
|
+
const NAMED_FOCUS = {
|
|
206
|
+
last_message: { kind: "last_message" },
|
|
207
|
+
trace: { kind: "trace" },
|
|
208
|
+
files: { kind: "files" },
|
|
209
|
+
mock_calls: { kind: "mock_calls" },
|
|
210
|
+
};
|
|
211
|
+
/** A `target` or `focus`; absent is `last_message`. */
|
|
212
|
+
function readFocus(value, field, scope) {
|
|
213
|
+
if (value === undefined)
|
|
214
|
+
return { kind: "last_message" };
|
|
215
|
+
const expected = "last_message, trace, files, mock_calls, or { source: file, path: <path> }";
|
|
216
|
+
// Own keys only: an author's `toString` or `constructor` is not a focus.
|
|
217
|
+
if (typeof value === "string")
|
|
218
|
+
return Object.hasOwn(NAMED_FOCUS, value) ? NAMED_FOCUS[value] : wrong(scope, field, expected);
|
|
219
|
+
if (!isJsonObject(value))
|
|
220
|
+
return wrong(scope, field, expected);
|
|
221
|
+
const keys = Object.keys(value);
|
|
222
|
+
const path = value["path"];
|
|
223
|
+
if (value["source"] !== "file" || typeof path !== "string" || path.trim() === "" || keys.some((k) => k !== "source" && k !== "path")) {
|
|
224
|
+
return wrong(scope, field, expected);
|
|
225
|
+
}
|
|
226
|
+
return { kind: "file", path };
|
|
227
|
+
}
|
|
228
|
+
/** A `tool_order` side: a tool name, or `{ tool, input_match }`. */
|
|
229
|
+
function readToolRef(fields, field, scope) {
|
|
230
|
+
const value = fields[field];
|
|
231
|
+
if (value === undefined)
|
|
232
|
+
return undefined;
|
|
233
|
+
if (typeof value === "string" && value.trim() !== "")
|
|
234
|
+
return { tool: value };
|
|
235
|
+
const expected = "a tool name or { tool, input_match }";
|
|
236
|
+
if (!isJsonObject(value))
|
|
237
|
+
return wrong(scope, field, expected);
|
|
238
|
+
const tool = value["tool"];
|
|
239
|
+
if (typeof tool !== "string" || tool.trim() === "" || Object.keys(value).some((k) => k !== "tool" && k !== "input_match")) {
|
|
240
|
+
return wrong(scope, field, expected);
|
|
241
|
+
}
|
|
242
|
+
const inputMatch = readPattern(value, "input_match", { ...scope, label: `${scope.label}${field}.` });
|
|
243
|
+
if (value["input_match"] !== undefined && inputMatch === undefined)
|
|
244
|
+
return undefined;
|
|
245
|
+
return { tool, ...(inputMatch !== undefined && { inputMatch }) };
|
|
246
|
+
}
|
|
247
|
+
/** An `input_match` regex, checked to compile. */
|
|
248
|
+
function readPattern(fields, field, scope) {
|
|
249
|
+
const pattern = readString(fields, field, scope);
|
|
250
|
+
if (pattern === undefined)
|
|
251
|
+
return undefined;
|
|
252
|
+
const error = regexError(pattern, "");
|
|
253
|
+
if (error !== undefined)
|
|
254
|
+
return wrong(scope, field, `a JavaScript regular expression (${error})`);
|
|
255
|
+
return pattern;
|
|
256
|
+
}
|
|
257
|
+
function readCount(fields, field, scope) {
|
|
258
|
+
const value = fields[field];
|
|
259
|
+
if (value === undefined)
|
|
260
|
+
return undefined;
|
|
261
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0)
|
|
262
|
+
return wrong(scope, field, "a whole number, 0 or more");
|
|
263
|
+
return value;
|
|
264
|
+
}
|
|
265
|
+
/** The rubric: the `criteria` key, else a `.md` file's body. */
|
|
266
|
+
function readCriteria(source, scope) {
|
|
267
|
+
const { fields } = source;
|
|
268
|
+
if (fields["criteria"] !== undefined) {
|
|
269
|
+
const criteria = readNonEmptyString(fields, "criteria", scope);
|
|
270
|
+
return criteria?.trim();
|
|
271
|
+
}
|
|
272
|
+
const body = source.body?.trim() ?? "";
|
|
273
|
+
if (body !== "")
|
|
274
|
+
return body;
|
|
275
|
+
const where = source.body === undefined ? "" : " (the file's body, or a criteria key)";
|
|
276
|
+
scope.findings.add(scope.invalid, scope.path, `${scope.label}criteria is required${where}`);
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=graders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graders.js","sourceRoot":"","sources":["../src/evals/graders.ts"],"names":[],"mappings":"AAAA;;;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,CAAC;AACf,CAAC;AAED,gEAAgE;AAChE,SAAS,YAAY,CAAC,MAAoB,EAAE,KAAiB;IAC3D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC1B,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;QAC/D,OAAO,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACvC,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAC7B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,uCAAuC,CAAC;IACvF,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,KAAK,uBAAuB,KAAK,EAAE,CAAC,CAAC;IAC5F,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The suite's documents as the reader opens them: a file's text through the
|
|
3
|
+
* `evalDocument` cap, a YAML mapping, and a Markdown file with optional
|
|
4
|
+
* frontmatter. Each records a finding and returns `undefined` when the file
|
|
5
|
+
* cannot be read, so the caller keeps reading the rest. Shared by the case
|
|
6
|
+
* reader (`read-eval-suite.ts`) and the mock reader (`mocks.ts`).
|
|
7
|
+
*/
|
|
8
|
+
import { type JsonObject } from "../documents.js";
|
|
9
|
+
import { type PluginFileIndex } from "../files.js";
|
|
10
|
+
import type { CaseFindings, EvalFindingKind, FieldScope } from "./fields.js";
|
|
11
|
+
/** One document's text through the `evalDocument` cap, or `undefined` after a finding of `kind`. */
|
|
12
|
+
export declare function readDocument(index: PluginFileIndex, path: string, kind: EvalFindingKind, findings: CaseFindings): string | undefined;
|
|
13
|
+
/** A YAML mapping, or `undefined` after a finding. */
|
|
14
|
+
export declare function parseMapping(yaml: string, scope: FieldScope, what: string): JsonObject | undefined;
|
|
15
|
+
export interface MarkdownDocument {
|
|
16
|
+
readonly fields: JsonObject;
|
|
17
|
+
readonly body: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A Markdown file with optional frontmatter: no opening `---` is a body
|
|
21
|
+
* with no fields, an unclosed one is a finding.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readMarkdown(index: PluginFileIndex, scope: FieldScope): MarkdownDocument | undefined;
|
|
24
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/evals/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,UAAU,EAAc,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE7E,oGAAoG;AACpG,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAOpI;AAED,sDAAsD;AACtD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAOlG;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,GAAG,gBAAgB,GAAG,SAAS,CAapG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The suite's documents as the reader opens them: a file's text through the
|
|
3
|
+
* `evalDocument` cap, a YAML mapping, and a Markdown file with optional
|
|
4
|
+
* frontmatter. Each records a finding and returns `undefined` when the file
|
|
5
|
+
* cannot be read, so the caller keeps reading the rest. Shared by the case
|
|
6
|
+
* reader (`read-eval-suite.ts`) and the mock reader (`mocks.ts`).
|
|
7
|
+
*/
|
|
8
|
+
import { readCapped } from "../documents.js";
|
|
9
|
+
import { decodeUtf8 } from "../files.js";
|
|
10
|
+
import { extractFrontmatter, parseFrontmatter } from "../frontmatter.js";
|
|
11
|
+
/** One document's text through the `evalDocument` cap, or `undefined` after a finding of `kind`. */
|
|
12
|
+
export function readDocument(index, path, kind, findings) {
|
|
13
|
+
const read = readCapped(index, path, "evalDocument");
|
|
14
|
+
if (!read.ok) {
|
|
15
|
+
findings.add(kind, path, `the file is ${read.size} bytes, over the ${read.limit}-byte limit`);
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return decodeUtf8(read.bytes);
|
|
19
|
+
}
|
|
20
|
+
/** A YAML mapping, or `undefined` after a finding. */
|
|
21
|
+
export function parseMapping(yaml, scope, what) {
|
|
22
|
+
const parsed = parseFrontmatter(yaml);
|
|
23
|
+
if (!parsed.ok) {
|
|
24
|
+
scope.findings.add(scope.invalid, scope.path, `${what} is not valid YAML: ${parsed.detail}`);
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return parsed.fields;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A Markdown file with optional frontmatter: no opening `---` is a body
|
|
31
|
+
* with no fields, an unclosed one is a finding.
|
|
32
|
+
*/
|
|
33
|
+
export function readMarkdown(index, scope) {
|
|
34
|
+
const text = readDocument(index, scope.path, scope.invalid, scope.findings);
|
|
35
|
+
if (text === undefined)
|
|
36
|
+
return undefined;
|
|
37
|
+
const extracted = extractFrontmatter(text);
|
|
38
|
+
if (!extracted.ok) {
|
|
39
|
+
if (extracted.reason === "unclosed") {
|
|
40
|
+
scope.findings.add(scope.invalid, scope.path, "the frontmatter is not closed (missing the closing '---')");
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return { fields: {}, body: text };
|
|
44
|
+
}
|
|
45
|
+
const fields = parseMapping(extracted.yaml, scope, "the frontmatter");
|
|
46
|
+
return fields === undefined ? undefined : { fields, body: extracted.body };
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../src/evals/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAmB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAwB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAGzE,oGAAoG;AACpG,MAAM,UAAU,YAAY,CAAC,KAAsB,EAAE,IAAY,EAAE,IAAqB,EAAE,QAAsB;IAC9G,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;IACrD,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;QACb,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,eAAe,IAAI,CAAC,IAAI,oBAAoB,IAAI,CAAC,KAAK,aAAa,CAAC,CAAC;QAC9F,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,KAAiB,EAAE,IAAY;IACxE,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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A case's MCP mocks, in the plugin-eval format's layout: the suite's
|
|
3
|
+
* `<suite>/mocks/<server>/` and the case's own `<case>/mocks/<server>/`,
|
|
4
|
+
* merged file by file with the case's file winning, so a case overrides
|
|
5
|
+
* one tool and keeps the suite's others.
|
|
6
|
+
*
|
|
7
|
+
* In a server's directory:
|
|
8
|
+
* - `<tool>.md`: one tool. Frontmatter `type` (`fixed`, the default, or
|
|
9
|
+
* `agent`), `expect`, `error` (`fixed` only) and `abort_when` (`agent`
|
|
10
|
+
* only); the body answers.
|
|
11
|
+
* - `_server.md`: one `agent` mock for the tools its `tools:` key lists; a
|
|
12
|
+
* `<tool>.md` for the same tool takes precedence. Its `expect:` is
|
|
13
|
+
* accepted only when `tools:` lists one tool.
|
|
14
|
+
* - `_tools.json`: the real server's saved `tools/list`, recorded by path
|
|
15
|
+
* for the runner to offer real descriptions and schemas.
|
|
16
|
+
* - `fixtures/`: files a body inserts; the runner resolves them, case
|
|
17
|
+
* directory first.
|
|
18
|
+
* `mocks/.replay/` holds adopted agent-mock recordings, which Stigmer does
|
|
19
|
+
* not read; the case only notes that it has them.
|
|
20
|
+
*
|
|
21
|
+
* A file that breaks these rules (an unknown key, a wrong type, an `expect`
|
|
22
|
+
* pattern outside the dialect) is an `eval-mock-invalid` finding of the
|
|
23
|
+
* case, which then does not load, as Claude Code stops such a case. Which
|
|
24
|
+
* servers a suite may mock is its reader's rule ({@link MockServerRule}): a
|
|
25
|
+
* plugin's suite mocks only the servers the plugin declares, a pushed
|
|
26
|
+
* folder any server whose name could be one. A directory the rule refuses
|
|
27
|
+
* is a finding of the suite and is ignored: no try could reach that server.
|
|
28
|
+
*/
|
|
29
|
+
import { type PluginFileIndex } from "../files.js";
|
|
30
|
+
import { type CaseFindings } from "./fields.js";
|
|
31
|
+
import type { EvalMockServer, EvalSuiteFinding } from "./types.js";
|
|
32
|
+
/** The directory under the suite or a case that holds mocks. */
|
|
33
|
+
export declare const MOCKS_DIR = "mocks";
|
|
34
|
+
/** What a case's mocks read to: the servers, and whether replays exist. */
|
|
35
|
+
export interface CaseMocks {
|
|
36
|
+
readonly servers: readonly EvalMockServer[];
|
|
37
|
+
readonly replays: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether a suite may mock the server a mock directory names: `undefined`
|
|
41
|
+
* keeps the directory, a sentence says why it is ignored.
|
|
42
|
+
*/
|
|
43
|
+
export type MockServerRule = (server: string) => string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Read the mocks one case sees. A mock directory `rule` refuses adds a
|
|
46
|
+
* finding to `suiteFindings` (once per directory: `reported` remembers the
|
|
47
|
+
* suite's) and is skipped.
|
|
48
|
+
*/
|
|
49
|
+
export declare function readCaseMocks(index: PluginFileIndex, suiteDir: string, caseDir: string, rule: MockServerRule, findings: CaseFindings, suiteFindings: EvalSuiteFinding[], reported: Set<string>): CaseMocks;
|
|
50
|
+
//# sourceMappingURL=mocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mocks.d.ts","sourceRoot":"","sources":["../src/evals/mocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH,OAAO,EAA0B,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,KAAK,YAAY,EAA2E,MAAM,aAAa,CAAC;AAEzH,OAAO,KAAK,EAAE,cAAc,EAAgB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEjF,gEAAgE;AAChE,eAAO,MAAM,SAAS,UAAU,CAAC;AAWjC,2EAA2E;AAC3E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAC;IAC5C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAEpE;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,gBAAgB,EAAE,EACjC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,GACpB,SAAS,CAqBX"}
|