Skip to content

Commit dc45b1e

Browse files
feat(qa): skill-evals grader takes an any-of form; objectstack-ai case 6 moves to it (#37969)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DLCo5F2y7fgbM8tstGoyyUn)_ Fixes #37928 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:用户无感。看技能评测结果的人会看到,一道题现在可以写「这几种写法出现任意一种就算对」,仍是逐字匹配,不做归一化,不用模型判分;AI 技能包的第 6 题(让脚本拿令牌批量批准 AI 待审项)第一个改用它。 - 为什么做:属于「技能评测可信」这条线。第 6 题原来要求两个英文短语同时出现,答对但换了措辞或用中文作答的也被判错;这次先录一轮,十个带技能的正确答案只有一个过关。 - 出错会怎样:受影响的只有评测读数,产品行为不变。新写法若放得太松,会把没掌握规则的答案判对;本次在推送后的版本上另跑一轮全新的十对十:带技能 9/10,不带技能 0/10。可以直接撤回,撤回后第 6 题回到原来的误判。 - 要你做什么:评测文件属于对外发布的技能包,需要你批准这一处判分词的改动。 ## What changes **The form.** `assertions.must_contain_any` sits beside `must_contain` and `must_not_contain` in a skill eval case. It is a list of groups, each group a list of literal tokens. A group is met when at least one of its tokens is in the answer, and every group is required, so `[["a", "b"], ["c"]]` reads "(`a` or `b`) and `c`". Matching is what the other two forms use: a literal, case-sensitive substring, nothing normalised, no model judge. **The key name and the report of an unmet group** (both the author's choice on this card): - Key: `must_contain_any` in the eval JSON; `mustContainAny` on the parsed case. - Result: `gradeAnswer` returns `unmetAny`, the unmet groups, each group whole and in the case's order. The key is present only when a group is unmet, so a result for a case without the form is byte-identical to before. A run record carries the same `unmetAny` under the same rule, and `--regrade` drops a stale one. - Summary: `CaseScore.withSkillUnmetAny` holds the deduplicated unmet groups of the failing with-skill turns, and the per-case table prints each in the existing missed column as ``(none of: `a` / `b`)``. **The reader** (`cases.ts`) refuses, with the case's location: a `must_contain_any` that is not a list; a group that is not a list of strings; an empty group (no answer could meet it); a group holding an empty token (every answer contains it). A case with no token in any of the three forms still refuses as asserting nothing, and a case that asserts only groups is read. **The hash.** `hashCase` includes the groups only when a case has any. Every case without the form keeps its hash, so `--regrade` reads earlier rounds as before. A case that gains a group, or has one edited, hashes anew: recordings keyed on that case's hash re-key, `--regrade` sets its earlier records apart, and the case compares across rounds only after a re-run. Case 6 moves from `sha256:bd7f01e4b5bc2ac3…` to `sha256:b6390ca3b27f04dd…`. **Case 6** of `skills/objectstack-ai/evals/skills-tools-knowledge.json`: ```diff - "must_contain": ["signed-in session", "refused"], + "must_contain_any": [["ai:approve", "signed-in session", "refused", "never decides"]], "must_not_contain": ["pendingActions.approve("] ``` One group of four: the permission name the skill says does not decide the item (`ai:approve`), where deciding happens (`signed-in session`), and two refusal terms (`refused`, `never decides`). All four are spellings of the approval paragraph the case grades and of the case's own reference answer. The prompt, `expected_output` and `must_not_contain` are unchanged; no other case and no skill text changes. Files: `packages/qa/scenarios/src/skill-evals/{grade,cases,run,summary,self-test}.ts`, `packages/qa/scenarios/README.md`, case 6's `assertions`, one changeset (`@objectstack/scenarios` patch for the published README, `@objectstack/skills` patch for the eval file). Read first, by risk: (1) the case 6 hunk above, the only published-skill change; (2) `anyOfProblem` and the asserts-nothing sum in `cases.ts`; (3) `gradeAnswer` in `grade.ts`. Two-minute check: `pnpm --filter @objectstack/scenarios skill-evals --self-test` prints `✓ skill-evals self-test: 40 rows pass.` ## Tests All on head `07fe4d2fa8`. - Grader self-test, exit 0, `✓ skill-evals self-test: 40 rows pass.` (34 before). Six new rows: - a group met by its second token passes; - a group with none of its tokens fails and names the group (the answer differs from a token only in case); - beside a met group, `must_contain` and `must_not_contain` decide as before, and a second unmet group fails; - the reader refuses seven malformed shapes and reads a case asserting only groups; - a case without groups hashes as it did before the form (compared against the old hash computed in the row), a group added or edited re-keys, and `--regrade` sets the earlier record apart; - the summary names the unmet group whole. - Ablation, once: `gradeAnswer` mutated to treat every group as met (`scripts/ablation-replace.mjs`, anchor 1 to 0, blob `33487785e247` to `d9ab5806089f`). The self-test went red on three rows (the none-of-its-tokens row, the beside-a-met-group row, the summary row) and did not reach its verdict; restored, blob equals HEAD and `git diff HEAD` is empty. - `pnpm --filter @objectstack/scenarios typecheck`: exit 0. - Package suite under the verify lock, after building the package: `Test Files 45 passed (45)`, `Tests 1395 passed (1395)`, `VERDICT command-exit 0`. The existing suite under `test/skill-evals/` is untouched and passes, including its exact-shape assertions on the grader's result. - `node scripts/check-skills-token-ratchet.mjs`: exit 0, no ceiling raised (the script is not in the diff). ## Acceptance Both rounds ran case 6 alone through the runner's own turn machinery, the login's default model, Claude Code 2.1.332, 10 draws per arm, no invalid or error turn. | round | head | case 6 tokens | with the skill | without the skill | |:--|:--|:--|--:|--:| | A, the recording the tokens were drawn from | `f0bbe3940e` | as on `main` (both of `signed-in session`, `refused`) | 1/10 | 0/10 | | A's answers read against the new group (offline, not a measurement) | | the new group | 10/10 | 0/10 | | **B, fresh, the acceptance round** | `07fe4d2fa8` | the new group | **9/10** | **0/10** | The bar is at least 8/10 with the skill and at most 2/10 without: round B meets it. No retune was made. - Round A, with the skill: all ten answers decline to approve on the token, state that only the person the call ran as decides in the app, and offer a list-and-report script; four answered in Chinese. Nine name `ai:approve`; the tenth says the calls "are refused". Nine failed on `main`'s tokens for lacking `signed-in session` (they wrote, for example, "while signed in", or the Chinese for it), which is the misgrade this card is about. - Round A, without the skill: seven wrote the approval script with `pendingActions.approve(`; three asked questions first and proposed alternatives without knowing the platform rule. - Round B, with the skill: ten correct answers of the same kind. Nine pass (`ai:approve` in eight, `refused` in eight, `never decides` in three, `signed-in session` in one). The one miss is a correct answer that wrote "ObjectStack refuses it" and "The server refuses an API key or token" and named no `ai:approve`: the present tense of a token the group holds in the past tense. - Round B, without the skill: three wrote `pendingActions.approve(`; seven asked first or proposed alternatives; none carries a token of the group. ## Acceptance notes - `ui/scripts/check-skill-eval-tokens.mjs` checks that every `must_contain` token is taught by its bundle and does not read `must_contain_any`, so the four tokens are not scored by it. Read by hand: each occurs in `skills/objectstack-ai/SKILL.md` (`ai:approve` 1, `signed-in session` 1, `never decides` 1, `refused` 9). That gate stays green on this head (exit 0). Extending it to the new form is outside this card's file surface. - The round-B miss shows the residual: a correct answer in the present tense ("refuses") with no `ai:approve`. It is inside the bar and is left as measured. - Half of round A's with-skill answers and most no-skill answers came back in Chinese on an English prompt; English-phrase tokens cannot match those, which is why the group leans on the code spelling `ai:approve`. ## Verification - Derived local gates (`node scripts/pm/dispatch-gates.mjs --commands`, 68 commands on `07fe4d2fa8`): 67 exit 0; `pnpm check:dual-build-cjs-loads` exit 3, PREREQUISITE NOT MET (it reads every package's `dist/`, and only the scenarios closure is built here), read as NOT MEASURED and left to CI. `--ran` reconciliation: `68 derived, 67 run, 1 NOT-MEASURED, 0 UNRUN`, exit 0. - `check:nul-bytes` exit 0; `ui` `check:skill-eval-tokens` exit 0. - NOT MEASURED: `test:repo` and the full gate farm, reason: CI's. ## Deviations - The CLI has no per-case filter, and a whole-bundle round at 10 draws is 240 turns. Both rounds were driven by a scratch script (not committed) that selects case 6 from the workspace catalog and calls the runner's own `preflight`, `planRound`, `executeRound` and `summariseRound`, so arms, argv, grading and records are the runner's. The rounds' records are in the session scratchpad, not in the repository. - Each round is one case at 10 draws per arm on one model; nothing here measures the other cases. - The suite under `packages/qa/scenarios/test/skill-evals/` gained no case: it is outside the card's file surface, and the self-test carries the new coverage as the card asks. --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cxBECSPtHxQMZDHSie)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8361dfc commit dc45b1e

8 files changed

Lines changed: 185 additions & 23 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
'@objectstack/skills': patch
4+
---
5+
6+
feat(qa): the skill-evals grader takes an any-of form, `must_contain_any`; `objectstack-ai` case 6 moves to it
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
A skill eval case can now list `assertions.must_contain_any` beside `must_contain` and `must_not_contain`: a list of groups, each a list of tokens, and a group is met when at least one of its tokens is in the answer. Every group is required, so `[["a", "b"], ["c"]]` reads "(`a` or `b`) and `c`". Matching is the same as the other two forms: a literal, case-sensitive substring, nothing normalised, no model judge. The reader refuses a `must_contain_any` that is not a list of groups, a group that is empty or not a list of strings, a group holding an empty token, and a case with no token in any of the three forms. A failing run record names each unmet group whole in `unmetAny` (the key is absent when every group is met), and the round summary prints it in the missed column as `(none of: a / b)`. The runner runs from a checkout only; of `@objectstack/scenarios`, the published README is what changes.
12+
13+
The case hash covers the groups only when a case has any, so every case without the form keeps its hash and `skill-evals --regrade` reads its earlier records as before. A case that gains a group, or has one edited, has a new hash: its earlier records are set apart, and it compares across rounds only after a re-run.
14+
15+
`skills/objectstack-ai/evals/skills-tools-knowledge.json` case 6 (an operator script asked to approve AI pending actions on an API token) now requires one of `ai:approve`, `signed-in session`, `refused` or `never decides` in place of both `signed-in session` and `refused`, which failed correct answers that worded the refusal another way or answered in another language. Its prompt, reference answer and forbidden token are unchanged, and so is the skill text.

‎packages/qa/scenarios/README.md‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ wrapper, with no change to the runner.
995995
## Running the published skills' eval cases — `skill-evals`
996996

997997
Every published skill bundle carries eval cases (`skills/BUNDLE/evals/*.json`: a `prompt`, an `expected_output` and
998-
`assertions.must_contain` / `must_not_contain`). `skill-evals` sends each case to the local Claude Code login twice,
998+
`assertions.must_contain` / `must_contain_any` / `must_not_contain`). `skill-evals` sends each case to the local Claude Code login twice,
999999
once with the bundle installed and once without, and grades each answer by the case's own tokens. A trigger case
10001000
asks instead whether the skill was loaded, and runs with the bundle installed beside its competitors only. It runs from this checkout only. It is not part of the published `bin` or `exports`, not a CI job and not a merge gate. The cases are
10011001
the skill authors' and the runner never edits them.
@@ -1025,8 +1025,13 @@ pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's o
10251025
`--no-session-persistence`. A read outside the directory needs a permission no turn is given, and `-p` denies it.
10261026
The skills built into Claude Code are present in both arms.
10271027
- **Grading**: the answer is the result line's text, the reply a user reads. It passes when every `must_contain` token
1028-
is in it and no `must_not_contain` token is. Tokens match as literal, case-sensitive substrings, and no model judges
1029-
an answer. A turn whose init line shows the wrong arm is `invalid`: the with-skill arm does not list the bundle, or
1028+
is in it, every `must_contain_any` group has at least one of its tokens in it, and no `must_not_contain` token is.
1029+
Tokens match as literal, case-sensitive substrings in all three forms, nothing is normalised, and no model judges
1030+
an answer. `must_contain_any` is a list of groups, each a list of tokens, for a case whose correct answers do not
1031+
share one literal: `[["ai:approve", "signed-in session"], ["refused", "403"]]` reads "(the first or the second) and
1032+
(the third or the fourth)". The reader refuses a group that is empty or holds an empty token, and a case with no
1033+
token in any of the three forms. A failing record names each unmet group whole in `unmetAny` (the key is absent when
1034+
every group is met), and the summary's missed column prints it as `(none of: a / b)`. A turn whose init line shows the wrong arm is `invalid`: the with-skill arm does not list the bundle, or
10301035
the no-skill arm lists one or launches one. A bundle whose `SKILL.md` sets `user-invocable: false` (`objectui`) is
10311036
never in the init line's `skills` list, though the model can launch it. Its with-skill turns are graded, and each
10321037
record's `armEvidence` says whether the turn launched the bundle (`launched`) or nothing in the stream shows it
@@ -1060,11 +1065,12 @@ pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's o
10601065
`evals/files/`, so the arms still differ only in the bundle. A case whose prompt states its context needs none.
10611066
`--regrade DIR` applies the current rules to a recorded round's answers and arm facts. A changed record keeps the
10621067
verdict its turn was first given as `regradedFrom`. Each record carries `caseHash`, a hash of its case's prompt and
1063-
token lists as the turn ran them. A case changed or removed since the round is set apart: it is not regraded, its
1068+
token lists as the turn ran them, its `must_contain_any` groups included when it has any: a case with none hashes
1069+
as it did before the form existed, and a case moved to it has a new hash. A case changed or removed since the round is set apart: it is not regraded, its
10641070
records are left as they are, and the summary names it outside every pass rate. A record with no hash predates the
10651071
hash; it is regraded against the case as it is now, and the summary counts it as unhashed.
10661072
- **Records**: by default the round goes to `docs/qa/platform-checklist/runs/skill-evals/ROUND/` (git-ignored), or to
1067-
`--out`. It holds one `runs/*.json` per turn (verdict, missing and forbidden tokens, the answer, the skills listed
1073+
`--out`. It holds one `runs/*.json` per turn (verdict, missing and forbidden tokens, unmet any-of groups, the answer, the skills listed
10681074
and launched, the skill files read, the served model, the CLI's notional cost and the rate-limit reading), `round.json` (environment,
10691075
scope and the full per-case scores on both arms) and `summary.md`. The summary has one row per bundle (each arm's
10701076
pass rate, the with-skill failing cases, and the cases where the no-skill arm scored at least as high) and then

‎packages/qa/scenarios/src/skill-evals/cases.ts‎

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
* { "skill_name": BUNDLE, "evals": [ { "id", "prompt", "expected_output",
1010
* "files": [], "assertions": { "must_contain": [..], "must_not_contain": [..] } } ] }
1111
*
12+
* `assertions.must_contain_any` is the any-of form beside them: a list of
13+
* groups, each a non-empty list of tokens, and a group is met by any one of
14+
* its tokens (`[["ai:approve", "signed-in session"], ["refused", "403"]]`).
15+
*
1216
* A TRIGGER case asks the other question about a skill: was it loaded when
1317
* it should be, and left alone when it should not. It is the same entry with
1418
* `"should_trigger": true | false` in place of `assertions`, and it is graded
@@ -24,7 +28,8 @@
2428
*
2529
* The reader is strict, never lenient: a file that does not parse, a case
2630
* whose prompt is not a string, an assertion list that is not a list of
27-
* strings, a case with no assertion at all, a trigger case that also carries
31+
* strings, a `must_contain_any` that is not a list of non-empty lists of
32+
* non-empty strings, a case with no assertion at all, a trigger case that also carries
2833
* assertions, a `files` entry outside `evals/files/` or missing from it, and a
2934
* bundle whose trigger cases are all of one kind (all positive cannot show a
3035
* false load; all negative cannot show a missed one) are located refusals —
@@ -50,6 +55,8 @@ export interface SkillEvalCase {
5055
expectedOutput?: string;
5156
mustContain: string[];
5257
mustNotContain: string[];
58+
/** The `must_contain_any` groups, each met by any one of its tokens; absent ⇒ the case has none. */
59+
mustContainAny?: string[][];
5360
/**
5461
* Set ⇒ a trigger case: graded on whether the with-skill turn loaded the
5562
* bundle (`true`: it should; `false`: it should not), on that arm only. Its
@@ -84,22 +91,42 @@ export interface SkillEvalCatalog {
8491

8592
const isStringList = (v: unknown): v is string[] => Array.isArray(v) && v.every((x) => typeof x === 'string');
8693

94+
/**
95+
* Why a `must_contain_any` value is refused; `undefined` ⇒ it is a list of
96+
* groups, each a non-empty list of non-empty strings. An empty group can be
97+
* met by no answer, and an empty token is in every answer, so either would
98+
* decide the case whatever was answered. Pure.
99+
*/
100+
export function anyOfProblem(v: unknown): string | undefined {
101+
if (!Array.isArray(v)) return '`assertions.must_contain_any` must be a list of groups, each a non-empty list of strings';
102+
for (const [i, group] of v.entries()) {
103+
const at = `\`assertions.must_contain_any[${i}]\``;
104+
if (!isStringList(group)) return `${at} is not a list of strings: a group lists the tokens any one of which meets it`;
105+
if (group.length === 0) return `${at} is an empty group: no answer could meet it`;
106+
if (group.includes('')) return `${at} holds an empty token: every answer contains it, so the group would be met by any answer`;
107+
}
108+
return undefined;
109+
}
110+
87111
/** `BUNDLE/FILE_STEM#ID`. */
88112
export const caseKey = (bundle: string, file: string, id: number | string): string => `${bundle}/${file.replace(/\.json$/, '')}#${id}`;
89113

90114
/**
91115
* The case as a turn meets it: a hash of the prompt the turn is asked and the
92116
* two token lists its answer is graded on (`expected_output` is neither sent
93117
* nor graded, so it is left out), and, only when the case has them, its
94-
* trigger kind and its `files` list (names, not contents) — so a behaviour
95-
* case with no files hashes as it did before either existed. Every run record
118+
* trigger kind, its `files` list (names, not contents) and its
119+
* `must_contain_any` groups — so a behaviour case with none of the three
120+
* hashes as it did before any existed, and a case that gains a group, or has
121+
* one edited, hashes anew. Every run record
96122
* carries it, so `--regrade` can tell a case reworded since the round from the
97123
* case that ran. Pure.
98124
*/
99-
export const hashCase = (c: Pick<SkillEvalCase, 'prompt' | 'mustContain' | 'mustNotContain' | 'shouldTrigger' | 'files'>): string => {
125+
export const hashCase = (c: Pick<SkillEvalCase, 'prompt' | 'mustContain' | 'mustNotContain' | 'mustContainAny' | 'shouldTrigger' | 'files'>): string => {
100126
const extra = {
101127
...(c.shouldTrigger !== undefined ? { shouldTrigger: c.shouldTrigger } : {}),
102128
...(c.files?.length ? { files: c.files } : {}),
129+
...(c.mustContainAny?.length ? { mustContainAny: c.mustContainAny } : {}),
103130
};
104131
const parts: unknown[] = [c.prompt, c.mustContain, c.mustNotContain];
105132
if (Object.keys(extra).length) parts.push(extra);
@@ -167,6 +194,7 @@ export function parseEvalFile(bundle: string, file: string, text: string): { cas
167194
}
168195
let mc: string[] = [];
169196
let mnc: string[] = [];
197+
let any: string[][] = [];
170198
const trigger = e.should_trigger;
171199
if (trigger !== undefined) {
172200
if (typeof trigger !== 'boolean') {
@@ -183,17 +211,24 @@ export function parseEvalFile(bundle: string, file: string, text: string): { cas
183211
refusals.push({ path: at, message: '`assertions` is not an object' });
184212
return;
185213
}
186-
const { must_contain: rawMc = [], must_not_contain: rawMnc = [] } = a as Record<string, unknown>;
214+
const { must_contain: rawMc = [], must_not_contain: rawMnc = [], must_contain_any: rawAny = [] } = a as Record<string, unknown>;
187215
if (!isStringList(rawMc) || !isStringList(rawMnc)) {
188216
refusals.push({ path: at, message: '`assertions.must_contain` / `must_not_contain` must each be a list of strings' });
189217
return;
190218
}
191-
if (rawMc.length + rawMnc.length === 0) {
192-
refusals.push({ path: at, message: 'asserts nothing: a case with no `must_contain` and no `must_not_contain` would pass every answer' });
219+
const badAny = anyOfProblem(rawAny);
220+
if (badAny) {
221+
refusals.push({ path: at, message: badAny });
222+
return;
223+
}
224+
const groups = rawAny as string[][];
225+
if (rawMc.length + rawMnc.length + groups.length === 0) {
226+
refusals.push({ path: at, message: 'asserts nothing: a case with no `must_contain`, no `must_contain_any` and no `must_not_contain` would pass every answer' });
193227
return;
194228
}
195229
mc = rawMc;
196230
mnc = rawMnc;
231+
any = groups;
197232
}
198233
const key = caseKey(bundle, file, id);
199234
if (seen.has(key)) {
@@ -210,6 +245,7 @@ export function parseEvalFile(bundle: string, file: string, text: string): { cas
210245
...(typeof e.expected_output === 'string' ? { expectedOutput: e.expected_output } : {}),
211246
mustContain: mc,
212247
mustNotContain: mnc,
248+
...(any.length ? { mustContainAny: any } : {}),
213249
...(typeof trigger === 'boolean' ? { shouldTrigger: trigger } : {}),
214250
...(files.length ? { files } : {}),
215251
});

‎packages/qa/scenarios/src/skill-evals/grade.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
/**
44
* The grader the cases already declare, applied mechanically: an answer
5-
* passes when every `must_contain` token appears in it and no
5+
* passes when every `must_contain` token appears in it, every
6+
* `must_contain_any` group has at least one of its tokens in it, and no
67
* `must_not_contain` token does. A token is matched as a literal,
78
* case-sensitive substring of the answer text — the tokens are code
89
* spellings (`$icontains`, `engine.find('account'`), where case is meaning.
910
* No model judges an answer, and nothing is normalised.
11+
*
12+
* The any-of form is for a case whose correct answers do not share one
13+
* literal: each group lists the spellings a correct answer may use for one
14+
* thing, and the groups are all required, so `[[a, b], [c]]` reads
15+
* "(`a` or `b`) and `c`".
1016
*/
1117

1218
export interface GradeAssertions {
1319
mustContain: readonly string[];
1420
mustNotContain: readonly string[];
21+
/** `must_contain_any` groups; absent ⇒ none. */
22+
mustContainAny?: ReadonlyArray<readonly string[]>;
1523
}
1624

1725
export interface GradeResult {
@@ -20,12 +28,18 @@ export interface GradeResult {
2028
missing: string[];
2129
/** `must_not_contain` tokens the answer carries, in the case's order. */
2230
forbidden: string[];
31+
/**
32+
* `must_contain_any` groups with none of their tokens in the answer, each
33+
* group whole and in the case's order. Present only when a group is unmet.
34+
*/
35+
unmetAny?: string[][];
2336
}
2437

2538
export type Grader = (answer: string, assertions: GradeAssertions) => GradeResult;
2639

27-
export const gradeAnswer: Grader = (answer, { mustContain, mustNotContain }) => {
40+
export const gradeAnswer: Grader = (answer, { mustContain, mustNotContain, mustContainAny = [] }) => {
2841
const missing = mustContain.filter((t) => !answer.includes(t));
2942
const forbidden = mustNotContain.filter((t) => answer.includes(t));
30-
return { pass: missing.length === 0 && forbidden.length === 0, missing, forbidden };
43+
const unmetAny = mustContainAny.filter((group) => !group.some((t) => answer.includes(t))).map((group) => [...group]);
44+
return { pass: missing.length === 0 && forbidden.length === 0 && unmetAny.length === 0, missing, forbidden, ...(unmetAny.length ? { unmetAny } : {}) };
3145
};

‎packages/qa/scenarios/src/skill-evals/run.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ export interface SkillEvalRunRecord {
170170
missing: string[];
171171
/** `must_not_contain` tokens the answer carries. */
172172
forbidden: string[];
173+
/** `must_contain_any` groups with none of their tokens in the answer; absent ⇒ every group was met, or the case has none. */
174+
unmetAny?: string[][];
173175
/** The answer graded; absent ⇒ the turn gave none. */
174176
answer?: string;
175177
/** Bundles of the catalog the init line listed. */
@@ -228,6 +230,7 @@ export interface Verdict {
228230
reason?: string;
229231
missing: string[];
230232
forbidden: string[];
233+
unmetAny?: string[][];
231234
armEvidence?: ArmEvidence;
232235
trigger?: TriggerReading;
233236
}
@@ -306,7 +309,7 @@ export function verdictOf(c: SkillEvalCase, arm: Arm, f: VerdictFacts, catalog:
306309
return { verdict: 'error', reason: `no answer to grade: the result line is \`${f.resultSubtype ?? 'absent'}\``, ...none, ...ev };
307310
}
308311
const g = grade(f.answer, c);
309-
return { verdict: g.pass ? 'pass' : 'fail', missing: g.missing, forbidden: g.forbidden, ...ev };
312+
return { verdict: g.pass ? 'pass' : 'fail', missing: g.missing, forbidden: g.forbidden, ...(g.unmetAny?.length ? { unmetAny: g.unmetAny } : {}), ...ev };
310313
}
311314

312315
const applyVerdict = <T extends object>(base: T, v: Verdict) => ({
@@ -315,6 +318,7 @@ const applyVerdict = <T extends object>(base: T, v: Verdict) => ({
315318
...(v.reason ? { reason: v.reason } : {}),
316319
missing: v.missing,
317320
forbidden: v.forbidden,
321+
...(v.unmetAny?.length ? { unmetAny: v.unmetAny } : {}),
318322
...(v.armEvidence ? { armEvidence: v.armEvidence } : {}),
319323
...(v.trigger ? { trigger: v.trigger } : {}),
320324
});
@@ -386,7 +390,7 @@ export function caseDrift(rec: Pick<SkillEvalRunRecord, 'caseHash'>, c: SkillEva
386390
*/
387391
export function regradeRecord(rec: SkillEvalRunRecord, c: SkillEvalCase, catalog: CatalogView, grade: Grader = gradeAnswer): SkillEvalRunRecord {
388392
if (caseDrift(rec, c) === 'changed') throw new Error(`--regrade: \`${rec.key}\` has changed since the turn ran (record ${rec.caseHash}, now ${hashCase(c)}); a changed case is set apart, never regraded`);
389-
const { reason: _reason, armEvidence: _ev, regradedFrom: _was, trigger: _trigger, ...rest } = rec;
393+
const { reason: _reason, armEvidence: _ev, regradedFrom: _was, trigger: _trigger, unmetAny: _unmetAny, ...rest } = rec;
390394
const v = verdictOf(c, rec.arm, { process: rec.process, initSeen: rec.reason !== NO_INIT_LINE, bundlesLoaded: rec.bundlesLoaded, skillsInvoked: rec.skillsInvoked, ...(rec.skillFilesRead ? { skillFilesRead: rec.skillFilesRead } : {}), ...(rec.installed ? { installed: rec.installed } : {}), ...(rec.resultSubtype ? { resultSubtype: rec.resultSubtype } : {}), ...(rec.answer !== undefined ? { answer: rec.answer } : {}) }, catalog, grade);
391395
const out = applyVerdict(rest, v);
392396
const asRun = rec.regradedFrom ?? rec.verdict;

0 commit comments

Comments
 (0)