Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/37928-skill-evals-any-of.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@objectstack/scenarios': patch
'@objectstack/skills': patch
---

feat(qa): the skill-evals grader takes an any-of form, `must_contain_any`; `objectstack-ai` case 6 moves to it

Clause-②: no
Metadata-protocol: none

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.

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.

`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.
16 changes: 11 additions & 5 deletions packages/qa/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ wrapper, with no change to the runner.
## Running the published skills' eval cases — `skill-evals`

Every published skill bundle carries eval cases (`skills/BUNDLE/evals/*.json`: a `prompt`, an `expected_output` and
`assertions.must_contain` / `must_not_contain`). `skill-evals` sends each case to the local Claude Code login twice,
`assertions.must_contain` / `must_contain_any` / `must_not_contain`). `skill-evals` sends each case to the local Claude Code login twice,
once with the bundle installed and once without, and grades each answer by the case's own tokens. A trigger case
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
the skill authors' and the runner never edits them.
Expand Down Expand Up @@ -1025,8 +1025,13 @@ pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's o
`--no-session-persistence`. A read outside the directory needs a permission no turn is given, and `-p` denies it.
The skills built into Claude Code are present in both arms.
- **Grading**: the answer is the result line's text, the reply a user reads. It passes when every `must_contain` token
is in it and no `must_not_contain` token is. Tokens match as literal, case-sensitive substrings, and no model judges
an answer. A turn whose init line shows the wrong arm is `invalid`: the with-skill arm does not list the bundle, or
is in it, every `must_contain_any` group has at least one of its tokens in it, and no `must_not_contain` token is.
Tokens match as literal, case-sensitive substrings in all three forms, nothing is normalised, and no model judges
an answer. `must_contain_any` is a list of groups, each a list of tokens, for a case whose correct answers do not
share one literal: `[["ai:approve", "signed-in session"], ["refused", "403"]]` reads "(the first or the second) and
(the third or the fourth)". The reader refuses a group that is empty or holds an empty token, and a case with no
token in any of the three forms. A failing record names each unmet group whole in `unmetAny` (the key is absent when
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
the no-skill arm lists one or launches one. A bundle whose `SKILL.md` sets `user-invocable: false` (`objectui`) is
never in the init line's `skills` list, though the model can launch it. Its with-skill turns are graded, and each
record's `armEvidence` says whether the turn launched the bundle (`launched`) or nothing in the stream shows it
Expand Down Expand Up @@ -1060,11 +1065,12 @@ pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's o
`evals/files/`, so the arms still differ only in the bundle. A case whose prompt states its context needs none.
`--regrade DIR` applies the current rules to a recorded round's answers and arm facts. A changed record keeps the
verdict its turn was first given as `regradedFrom`. Each record carries `caseHash`, a hash of its case's prompt and
token lists as the turn ran them. A case changed or removed since the round is set apart: it is not regraded, its
token lists as the turn ran them, its `must_contain_any` groups included when it has any: a case with none hashes
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
records are left as they are, and the summary names it outside every pass rate. A record with no hash predates the
hash; it is regraded against the case as it is now, and the summary counts it as unhashed.
- **Records**: by default the round goes to `docs/qa/platform-checklist/runs/skill-evals/ROUND/` (git-ignored), or to
`--out`. It holds one `runs/*.json` per turn (verdict, missing and forbidden tokens, the answer, the skills listed
`--out`. It holds one `runs/*.json` per turn (verdict, missing and forbidden tokens, unmet any-of groups, the answer, the skills listed
and launched, the skill files read, the served model, the CLI's notional cost and the rate-limit reading), `round.json` (environment,
scope and the full per-case scores on both arms) and `summary.md`. The summary has one row per bundle (each arm's
pass rate, the with-skill failing cases, and the cases where the no-skill arm scored at least as high) and then
Expand Down
50 changes: 43 additions & 7 deletions packages/qa/scenarios/src/skill-evals/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* { "skill_name": BUNDLE, "evals": [ { "id", "prompt", "expected_output",
* "files": [], "assertions": { "must_contain": [..], "must_not_contain": [..] } } ] }
*
* `assertions.must_contain_any` is the any-of form beside them: a list of
* groups, each a non-empty list of tokens, and a group is met by any one of
* its tokens (`[["ai:approve", "signed-in session"], ["refused", "403"]]`).
*
* A TRIGGER case asks the other question about a skill: was it loaded when
* it should be, and left alone when it should not. It is the same entry with
* `"should_trigger": true | false` in place of `assertions`, and it is graded
Expand All @@ -24,7 +28,8 @@
*
* The reader is strict, never lenient: a file that does not parse, a case
* whose prompt is not a string, an assertion list that is not a list of
* strings, a case with no assertion at all, a trigger case that also carries
* strings, a `must_contain_any` that is not a list of non-empty lists of
* non-empty strings, a case with no assertion at all, a trigger case that also carries
* assertions, a `files` entry outside `evals/files/` or missing from it, and a
* bundle whose trigger cases are all of one kind (all positive cannot show a
* false load; all negative cannot show a missed one) are located refusals —
Expand All @@ -50,6 +55,8 @@ export interface SkillEvalCase {
expectedOutput?: string;
mustContain: string[];
mustNotContain: string[];
/** The `must_contain_any` groups, each met by any one of its tokens; absent ⇒ the case has none. */
mustContainAny?: string[][];
/**
* Set ⇒ a trigger case: graded on whether the with-skill turn loaded the
* bundle (`true`: it should; `false`: it should not), on that arm only. Its
Expand Down Expand Up @@ -84,22 +91,42 @@ export interface SkillEvalCatalog {

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

/**
* Why a `must_contain_any` value is refused; `undefined` ⇒ it is a list of
* groups, each a non-empty list of non-empty strings. An empty group can be
* met by no answer, and an empty token is in every answer, so either would
* decide the case whatever was answered. Pure.
*/
export function anyOfProblem(v: unknown): string | undefined {
if (!Array.isArray(v)) return '`assertions.must_contain_any` must be a list of groups, each a non-empty list of strings';
for (const [i, group] of v.entries()) {
const at = `\`assertions.must_contain_any[${i}]\``;
if (!isStringList(group)) return `${at} is not a list of strings: a group lists the tokens any one of which meets it`;
if (group.length === 0) return `${at} is an empty group: no answer could meet it`;
if (group.includes('')) return `${at} holds an empty token: every answer contains it, so the group would be met by any answer`;
}
return undefined;
}

/** `BUNDLE/FILE_STEM#ID`. */
export const caseKey = (bundle: string, file: string, id: number | string): string => `${bundle}/${file.replace(/\.json$/, '')}#${id}`;

/**
* The case as a turn meets it: a hash of the prompt the turn is asked and the
* two token lists its answer is graded on (`expected_output` is neither sent
* nor graded, so it is left out), and, only when the case has them, its
* trigger kind and its `files` list (names, not contents) — so a behaviour
* case with no files hashes as it did before either existed. Every run record
* trigger kind, its `files` list (names, not contents) and its
* `must_contain_any` groups — so a behaviour case with none of the three
* hashes as it did before any existed, and a case that gains a group, or has
* one edited, hashes anew. Every run record
* carries it, so `--regrade` can tell a case reworded since the round from the
* case that ran. Pure.
*/
export const hashCase = (c: Pick<SkillEvalCase, 'prompt' | 'mustContain' | 'mustNotContain' | 'shouldTrigger' | 'files'>): string => {
export const hashCase = (c: Pick<SkillEvalCase, 'prompt' | 'mustContain' | 'mustNotContain' | 'mustContainAny' | 'shouldTrigger' | 'files'>): string => {
const extra = {
...(c.shouldTrigger !== undefined ? { shouldTrigger: c.shouldTrigger } : {}),
...(c.files?.length ? { files: c.files } : {}),
...(c.mustContainAny?.length ? { mustContainAny: c.mustContainAny } : {}),
};
const parts: unknown[] = [c.prompt, c.mustContain, c.mustNotContain];
if (Object.keys(extra).length) parts.push(extra);
Expand Down Expand Up @@ -167,6 +194,7 @@ export function parseEvalFile(bundle: string, file: string, text: string): { cas
}
let mc: string[] = [];
let mnc: string[] = [];
let any: string[][] = [];
const trigger = e.should_trigger;
if (trigger !== undefined) {
if (typeof trigger !== 'boolean') {
Expand All @@ -183,17 +211,24 @@ export function parseEvalFile(bundle: string, file: string, text: string): { cas
refusals.push({ path: at, message: '`assertions` is not an object' });
return;
}
const { must_contain: rawMc = [], must_not_contain: rawMnc = [] } = a as Record<string, unknown>;
const { must_contain: rawMc = [], must_not_contain: rawMnc = [], must_contain_any: rawAny = [] } = a as Record<string, unknown>;
if (!isStringList(rawMc) || !isStringList(rawMnc)) {
refusals.push({ path: at, message: '`assertions.must_contain` / `must_not_contain` must each be a list of strings' });
return;
}
if (rawMc.length + rawMnc.length === 0) {
refusals.push({ path: at, message: 'asserts nothing: a case with no `must_contain` and no `must_not_contain` would pass every answer' });
const badAny = anyOfProblem(rawAny);
if (badAny) {
refusals.push({ path: at, message: badAny });
return;
}
const groups = rawAny as string[][];
if (rawMc.length + rawMnc.length + groups.length === 0) {
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' });
return;
}
mc = rawMc;
mnc = rawMnc;
any = groups;
}
const key = caseKey(bundle, file, id);
if (seen.has(key)) {
Expand All @@ -210,6 +245,7 @@ export function parseEvalFile(bundle: string, file: string, text: string): { cas
...(typeof e.expected_output === 'string' ? { expectedOutput: e.expected_output } : {}),
mustContain: mc,
mustNotContain: mnc,
...(any.length ? { mustContainAny: any } : {}),
...(typeof trigger === 'boolean' ? { shouldTrigger: trigger } : {}),
...(files.length ? { files } : {}),
});
Expand Down
20 changes: 17 additions & 3 deletions packages/qa/scenarios/src/skill-evals/grade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

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

export interface GradeAssertions {
mustContain: readonly string[];
mustNotContain: readonly string[];
/** `must_contain_any` groups; absent ⇒ none. */
mustContainAny?: ReadonlyArray<readonly string[]>;
}

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

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

export const gradeAnswer: Grader = (answer, { mustContain, mustNotContain }) => {
export const gradeAnswer: Grader = (answer, { mustContain, mustNotContain, mustContainAny = [] }) => {
const missing = mustContain.filter((t) => !answer.includes(t));
const forbidden = mustNotContain.filter((t) => answer.includes(t));
return { pass: missing.length === 0 && forbidden.length === 0, missing, forbidden };
const unmetAny = mustContainAny.filter((group) => !group.some((t) => answer.includes(t))).map((group) => [...group]);
return { pass: missing.length === 0 && forbidden.length === 0 && unmetAny.length === 0, missing, forbidden, ...(unmetAny.length ? { unmetAny } : {}) };
};
8 changes: 6 additions & 2 deletions packages/qa/scenarios/src/skill-evals/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export interface SkillEvalRunRecord {
missing: string[];
/** `must_not_contain` tokens the answer carries. */
forbidden: string[];
/** `must_contain_any` groups with none of their tokens in the answer; absent ⇒ every group was met, or the case has none. */
unmetAny?: string[][];
/** The answer graded; absent ⇒ the turn gave none. */
answer?: string;
/** Bundles of the catalog the init line listed. */
Expand Down Expand Up @@ -228,6 +230,7 @@ export interface Verdict {
reason?: string;
missing: string[];
forbidden: string[];
unmetAny?: string[][];
armEvidence?: ArmEvidence;
trigger?: TriggerReading;
}
Expand Down Expand Up @@ -306,7 +309,7 @@ export function verdictOf(c: SkillEvalCase, arm: Arm, f: VerdictFacts, catalog:
return { verdict: 'error', reason: `no answer to grade: the result line is \`${f.resultSubtype ?? 'absent'}\``, ...none, ...ev };
}
const g = grade(f.answer, c);
return { verdict: g.pass ? 'pass' : 'fail', missing: g.missing, forbidden: g.forbidden, ...ev };
return { verdict: g.pass ? 'pass' : 'fail', missing: g.missing, forbidden: g.forbidden, ...(g.unmetAny?.length ? { unmetAny: g.unmetAny } : {}), ...ev };
}

const applyVerdict = <T extends object>(base: T, v: Verdict) => ({
Expand All @@ -315,6 +318,7 @@ const applyVerdict = <T extends object>(base: T, v: Verdict) => ({
...(v.reason ? { reason: v.reason } : {}),
missing: v.missing,
forbidden: v.forbidden,
...(v.unmetAny?.length ? { unmetAny: v.unmetAny } : {}),
...(v.armEvidence ? { armEvidence: v.armEvidence } : {}),
...(v.trigger ? { trigger: v.trigger } : {}),
});
Expand Down Expand Up @@ -386,7 +390,7 @@ export function caseDrift(rec: Pick<SkillEvalRunRecord, 'caseHash'>, c: SkillEva
*/
export function regradeRecord(rec: SkillEvalRunRecord, c: SkillEvalCase, catalog: CatalogView, grade: Grader = gradeAnswer): SkillEvalRunRecord {
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`);
const { reason: _reason, armEvidence: _ev, regradedFrom: _was, trigger: _trigger, ...rest } = rec;
const { reason: _reason, armEvidence: _ev, regradedFrom: _was, trigger: _trigger, unmetAny: _unmetAny, ...rest } = rec;
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);
const out = applyVerdict(rest, v);
const asRun = rec.regradedFrom ?? rec.verdict;
Expand Down
Loading
Loading