@agenticprimitives/evaluation 0.0.0-alpha.4 → 0.0.0-alpha.6
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/dist/act.d.ts +97 -0
- package/dist/act.d.ts.map +1 -0
- package/dist/act.js +115 -0
- package/dist/act.js.map +1 -0
- package/dist/assessment.d.ts +136 -0
- package/dist/assessment.d.ts.map +1 -0
- package/dist/assessment.js +162 -0
- package/dist/assessment.js.map +1 -0
- package/dist/canonical.d.ts +2 -0
- package/dist/canonical.d.ts.map +1 -0
- package/dist/canonical.js +4 -0
- package/dist/canonical.js.map +1 -0
- package/dist/capture.d.ts +90 -0
- package/dist/capture.d.ts.map +1 -0
- package/dist/capture.js +195 -0
- package/dist/capture.js.map +1 -0
- package/dist/compare-runner.d.ts +204 -0
- package/dist/compare-runner.d.ts.map +1 -0
- package/dist/compare-runner.js +313 -0
- package/dist/compare-runner.js.map +1 -0
- package/dist/conformal.d.ts +113 -0
- package/dist/conformal.d.ts.map +1 -0
- package/dist/conformal.js +113 -0
- package/dist/conformal.js.map +1 -0
- package/dist/consensus.d.ts +53 -0
- package/dist/consensus.d.ts.map +1 -0
- package/dist/consensus.js +64 -0
- package/dist/consensus.js.map +1 -0
- package/dist/experiment.d.ts +218 -0
- package/dist/experiment.d.ts.map +1 -0
- package/dist/experiment.js +196 -0
- package/dist/experiment.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -1
- package/dist/ledger.d.ts +128 -0
- package/dist/ledger.d.ts.map +1 -0
- package/dist/ledger.js +146 -0
- package/dist/ledger.js.map +1 -0
- package/dist/measure.d.ts +63 -0
- package/dist/measure.d.ts.map +1 -0
- package/dist/measure.js +95 -0
- package/dist/measure.js.map +1 -0
- package/dist/replay.d.ts +50 -0
- package/dist/replay.d.ts.map +1 -0
- package/dist/replay.js +61 -0
- package/dist/replay.js.map +1 -0
- package/dist/report.d.ts +189 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +282 -0
- package/dist/report.js.map +1 -0
- package/dist/rollup.d.ts +91 -0
- package/dist/rollup.d.ts.map +1 -0
- package/dist/rollup.js +80 -0
- package/dist/rollup.js.map +1 -0
- package/dist/selection-gates.d.ts +283 -0
- package/dist/selection-gates.d.ts.map +1 -0
- package/dist/selection-gates.js +331 -0
- package/dist/selection-gates.js.map +1 -0
- package/dist/selection-score.d.ts +285 -0
- package/dist/selection-score.d.ts.map +1 -0
- package/dist/selection-score.js +392 -0
- package/dist/selection-score.js.map +1 -0
- package/dist/selection.d.ts +83 -0
- package/dist/selection.d.ts.map +1 -0
- package/dist/selection.js +86 -0
- package/dist/selection.js.map +1 -0
- package/dist/signals.d.ts +37 -0
- package/dist/signals.d.ts.map +1 -0
- package/dist/signals.js +44 -0
- package/dist/signals.js.map +1 -0
- package/dist/stats.d.ts +62 -0
- package/dist/stats.d.ts.map +1 -0
- package/dist/stats.js +279 -0
- package/dist/stats.js.map +1 -0
- package/package.json +2 -2
package/dist/replay.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type ReplayBucketV1 = 'explicit' | 'implicit' | 'contextual' | 'negative-near' | 'negative-scope' | 'negative-out'
|
|
2
|
+
/** Spec 416: no ONE skill is right — the right behaviour is to ask the person, or to hand the request on as several. */
|
|
3
|
+
| 'negative-clarify' | 'negative-several' | 'collision-a' | 'collision-b' | 'collision-ambiguous';
|
|
4
|
+
export interface ReplayIntentV1 {
|
|
5
|
+
id: string;
|
|
6
|
+
message: string;
|
|
7
|
+
/** development | held-out — held-out intents are pre-registered and never iterated against. */
|
|
8
|
+
split: 'development' | 'held-out';
|
|
9
|
+
bucket?: ReplayBucketV1;
|
|
10
|
+
/** The kind of slate it came from (per-skill, pair, ambiguous, out-of-library …). */
|
|
11
|
+
slateKind?: string;
|
|
12
|
+
/** The seeded records it runs from, when it needs any (a scenario's A-box). */
|
|
13
|
+
startingState?: {
|
|
14
|
+
domain: string;
|
|
15
|
+
scenarioId: string;
|
|
16
|
+
digest?: string;
|
|
17
|
+
};
|
|
18
|
+
provenance: 'authored' | 'harvested' | 'synthetic';
|
|
19
|
+
/** A paraphrase cluster (for cluster bootstrap). */
|
|
20
|
+
seedId?: string;
|
|
21
|
+
notes?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ReplaySetV1 {
|
|
24
|
+
type: 'ap.replay-set.v1';
|
|
25
|
+
id: string;
|
|
26
|
+
version: string;
|
|
27
|
+
title?: string;
|
|
28
|
+
/** The skill this set is about, by canonical id (absent for a library-wide set). */
|
|
29
|
+
skill?: string;
|
|
30
|
+
intents: ReplayIntentV1[];
|
|
31
|
+
}
|
|
32
|
+
/** The set's identity: SHA-256 over its canonical JSON. A new digest is a new set, never an edit. */
|
|
33
|
+
export declare const replaySetDigest: (set: ReplaySetV1) => Promise<`sha256:${string}`>;
|
|
34
|
+
/** Validate a parsed set; every problem named. */
|
|
35
|
+
export declare function validateReplaySet(raw: unknown): {
|
|
36
|
+
ok: true;
|
|
37
|
+
set: ReplaySetV1;
|
|
38
|
+
} | {
|
|
39
|
+
ok: false;
|
|
40
|
+
errors: string[];
|
|
41
|
+
};
|
|
42
|
+
/** The set's two halves. */
|
|
43
|
+
export declare const splitOf: (set: ReplaySetV1, split: ReplayIntentV1["split"]) => ReplayIntentV1[];
|
|
44
|
+
/** The set as a W3C DCAT description (a dcat:Dataset, versioned, with its checksummed distribution and its intents as
|
|
45
|
+
* apeval:ReplayIntent entities — ids, splits and buckets only; the words stay in the distribution). */
|
|
46
|
+
export declare function replaySetToJsonLd(set: ReplaySetV1, opts: {
|
|
47
|
+
context: Record<string, unknown> | string;
|
|
48
|
+
downloadUrl?: string;
|
|
49
|
+
}): Promise<Record<string, unknown>>;
|
|
50
|
+
//# sourceMappingURL=replay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../src/repl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,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAkBhH;AAED,4BAA4B;AAC5B,eAAO,MAAM,OAAO,QAAS,WAAW,SAAS,cAAc,CAAC,OAAO,CAAC,KAAG,cAAc,EAAkD,CAAC;AAE5I;wGACwG;AACxG,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAYrK"}
|
package/dist/replay.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// REPLAY SETS — spec 415 S0. A versioned set of intents to replay under variants, split into DEVELOPMENT and HELD-OUT,
|
|
2
|
+
// named by a digest (RFC 8785-style canonical JSON + SHA-256) so a comparison can refuse to compare runs of two
|
|
3
|
+
// different sets, and described in W3C DCAT for anyone else. The words of each intent live HERE, in the set's file —
|
|
4
|
+
// never in a run's graph, which cites an intent by id. Gold does NOT live here: a set says what to ask; a CRITERION
|
|
5
|
+
// (selection.ts) says what should happen, pre-registered separately so the same set can be judged against revised gold.
|
|
6
|
+
import { canonicalJson } from './canonical.js';
|
|
7
|
+
const sha256 = async (s) => {
|
|
8
|
+
const b = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(s)));
|
|
9
|
+
return `sha256:${Array.from(b, (x) => x.toString(16).padStart(2, '0')).join('')}`;
|
|
10
|
+
};
|
|
11
|
+
/** The set's identity: SHA-256 over its canonical JSON. A new digest is a new set, never an edit. */
|
|
12
|
+
export const replaySetDigest = (set) => sha256(canonicalJson(set));
|
|
13
|
+
/** Validate a parsed set; every problem named. */
|
|
14
|
+
export function validateReplaySet(raw) {
|
|
15
|
+
const errors = [];
|
|
16
|
+
const s = raw;
|
|
17
|
+
if (!s || s.type !== 'ap.replay-set.v1')
|
|
18
|
+
return { ok: false, errors: ['a replay set is { type: "ap.replay-set.v1", id, version, intents: [...] }'] };
|
|
19
|
+
if (typeof s.id !== 'string' || !s.id)
|
|
20
|
+
errors.push('id required');
|
|
21
|
+
if (typeof s.version !== 'string' || !s.version)
|
|
22
|
+
errors.push('version required');
|
|
23
|
+
if (!Array.isArray(s.intents) || !s.intents.length)
|
|
24
|
+
errors.push('at least one intent required');
|
|
25
|
+
const ids = new Set();
|
|
26
|
+
for (const [i, it] of (s.intents ?? []).entries()) {
|
|
27
|
+
const at = `intents[${i}]${it?.id ? ` (${it.id})` : ''}`;
|
|
28
|
+
if (!it || typeof it.id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(it.id)) {
|
|
29
|
+
errors.push(`${at}: id must be ASCII, ≤128 chars, starting alphanumeric`);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (ids.has(it.id))
|
|
33
|
+
errors.push(`${at}: listed twice`);
|
|
34
|
+
ids.add(it.id);
|
|
35
|
+
if (typeof it.message !== 'string' || it.message.length < 3 || it.message.length > 2000)
|
|
36
|
+
errors.push(`${at}: message must be 3–2000 chars`);
|
|
37
|
+
if (it.split !== 'development' && it.split !== 'held-out')
|
|
38
|
+
errors.push(`${at}: split must be development or held-out`);
|
|
39
|
+
if (!['authored', 'harvested', 'synthetic'].includes(String(it.provenance)))
|
|
40
|
+
errors.push(`${at}: provenance must be authored, harvested or synthetic`);
|
|
41
|
+
}
|
|
42
|
+
return errors.length ? { ok: false, errors } : { ok: true, set: s };
|
|
43
|
+
}
|
|
44
|
+
/** The set's two halves. */
|
|
45
|
+
export const splitOf = (set, split) => set.intents.filter((i) => i.split === split);
|
|
46
|
+
/** The set as a W3C DCAT description (a dcat:Dataset, versioned, with its checksummed distribution and its intents as
|
|
47
|
+
* apeval:ReplayIntent entities — ids, splits and buckets only; the words stay in the distribution). */
|
|
48
|
+
export async function replaySetToJsonLd(set, opts) {
|
|
49
|
+
const digest = await replaySetDigest(set);
|
|
50
|
+
const base = `urn:ap:replay-set:${set.id}@${set.version}`;
|
|
51
|
+
return {
|
|
52
|
+
'@context': opts.context,
|
|
53
|
+
id: base,
|
|
54
|
+
type: ['Dataset', 'ReplaySet'],
|
|
55
|
+
version: set.version,
|
|
56
|
+
setDigest: digest,
|
|
57
|
+
distribution: { id: `${base}#file`, type: ['Distribution'], ...(opts.downloadUrl ? { downloadURL: opts.downloadUrl } : {}) },
|
|
58
|
+
hasIntent: set.intents.map((i) => ({ id: `${base}#${i.id}`, type: ['Entity', 'ReplayIntent'], split: i.split, ...(i.bucket ? { bucket: i.bucket } : {}) })),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=replay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../src/replay.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,gHAAgH;AAChH,qHAAqH;AACrH,oHAAoH;AACpH,wHAAwH;AACxH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAmC/C,MAAM,MAAM,GAAG,KAAK,EAAE,CAAS,EAA+B,EAAE;IAC9D,MAAM,CAAC,GAAG,IAAI,UAAU,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7F,OAAO,UAAU,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;AACpF,CAAC,CAAC;AAEF,qGAAqG;AACrG,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAgB,EAA+B,EAA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AAiB,CAAC,GAAgB,EAAE,IAAyE;IACjI,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,qBAAqB,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;IAC1D,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,OAAO;QACxB,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC;QAC9B,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,SAAS,EAAE,MAAM;QACjB,YAAY,EAAE,EAAE,EAAE,EAAE,GAAG,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC,cAAc,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;QAC5H,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;KAC5J,CAAC;AACJ,CAAC"}
|
package/dist/report.d.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { ExperimentRecordV1 } from './experiment.js';
|
|
2
|
+
import type { ReplaySetV1 } from './replay.js';
|
|
3
|
+
import type { SelectionCriterionV1, SelectionOutcomeV1 } from './selection.js';
|
|
4
|
+
export declare const OUTCOME_WORDS: Record<SelectionOutcomeV1, {
|
|
5
|
+
label: string;
|
|
6
|
+
ok: boolean | null;
|
|
7
|
+
explain: string;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const VARIANT_WORDS: Record<string, string>;
|
|
10
|
+
export interface ReportIntentRowV1 {
|
|
11
|
+
intentId: string;
|
|
12
|
+
message: string;
|
|
13
|
+
split: string;
|
|
14
|
+
bucket?: string;
|
|
15
|
+
/** This test sentence nearly repeats an example a skill declares — its result measures the example, not selection. */
|
|
16
|
+
contaminated?: {
|
|
17
|
+
skill: string;
|
|
18
|
+
overlap: number;
|
|
19
|
+
isNot: boolean;
|
|
20
|
+
};
|
|
21
|
+
expected: string | null;
|
|
22
|
+
chosen: string | null;
|
|
23
|
+
outcome: SelectionOutcomeV1;
|
|
24
|
+
label: string;
|
|
25
|
+
ok: boolean | null;
|
|
26
|
+
why?: string;
|
|
27
|
+
ms?: number;
|
|
28
|
+
/** Spec 418 §3 — how the case's turn went: the ask's own time, the time and tokens to pick, the whole run's tokens,
|
|
29
|
+
* where the time went (stage → ms), and — for a chain — the skills run, in order, and the inputs named missing. */
|
|
30
|
+
askMs?: number;
|
|
31
|
+
selectionMs?: number;
|
|
32
|
+
tokens?: {
|
|
33
|
+
pickIn?: number;
|
|
34
|
+
pickOut?: number;
|
|
35
|
+
totalIn?: number;
|
|
36
|
+
totalOut?: number;
|
|
37
|
+
calls?: number;
|
|
38
|
+
};
|
|
39
|
+
stages?: Record<string, number>;
|
|
40
|
+
chain?: string[];
|
|
41
|
+
missing?: string[];
|
|
42
|
+
quality?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface ReportVariantV1 {
|
|
45
|
+
name: string;
|
|
46
|
+
how: string;
|
|
47
|
+
runs: number;
|
|
48
|
+
macroTa: number | null;
|
|
49
|
+
macroCi: [number, number] | null;
|
|
50
|
+
microTa: number | null;
|
|
51
|
+
holdRate: number | null;
|
|
52
|
+
holdNum?: number;
|
|
53
|
+
holdDen?: number;
|
|
54
|
+
routingPurity: number | null;
|
|
55
|
+
collisionContainment: number | null;
|
|
56
|
+
right: number;
|
|
57
|
+
wrong: number;
|
|
58
|
+
declinedCorrectly: number;
|
|
59
|
+
firedWrongly: number;
|
|
60
|
+
gate: {
|
|
61
|
+
status: string;
|
|
62
|
+
reason: string;
|
|
63
|
+
} | null;
|
|
64
|
+
intents: ReportIntentRowV1[];
|
|
65
|
+
/** Spec 416 W3 — selective prediction for a variant whose runs carry a judge's distribution: answering only its most
|
|
66
|
+
* confident runs, the error rate among those answered. Absent when no run recorded a distribution. */
|
|
67
|
+
riskCoverage?: {
|
|
68
|
+
n: number;
|
|
69
|
+
aurc: number | null;
|
|
70
|
+
points: Array<{
|
|
71
|
+
coverage: number;
|
|
72
|
+
risk: number;
|
|
73
|
+
threshold: number;
|
|
74
|
+
}>;
|
|
75
|
+
};
|
|
76
|
+
/** What an answer COST: the median run time, and the tokens providers reported — for the selection alone (the model
|
|
77
|
+
* planner's or the judge's calls) and for the whole run. `tokenRuns` says how many runs reported any; absent when
|
|
78
|
+
* none did (older experiments recorded no tokens). */
|
|
79
|
+
cost?: {
|
|
80
|
+
medianMs: number | null;
|
|
81
|
+
medianSelectionMs: number | null;
|
|
82
|
+
tokenRuns: number;
|
|
83
|
+
meanSelectionIn: number | null;
|
|
84
|
+
meanSelectionOut: number | null;
|
|
85
|
+
meanTotalIn: number | null;
|
|
86
|
+
meanTotalOut: number | null;
|
|
87
|
+
unreportedCalls: number;
|
|
88
|
+
};
|
|
89
|
+
perSkill: Array<{
|
|
90
|
+
skill: string;
|
|
91
|
+
asked: number;
|
|
92
|
+
right: number;
|
|
93
|
+
accuracy: number | null;
|
|
94
|
+
ci: [number, number] | null;
|
|
95
|
+
wronglyChosen: number;
|
|
96
|
+
confusedWith: Array<{
|
|
97
|
+
skill: string;
|
|
98
|
+
times: number;
|
|
99
|
+
}>;
|
|
100
|
+
}>;
|
|
101
|
+
}
|
|
102
|
+
export interface ReportExperimentV1 {
|
|
103
|
+
id: string;
|
|
104
|
+
slate: string;
|
|
105
|
+
split: string;
|
|
106
|
+
repeats: number;
|
|
107
|
+
startedAt: string;
|
|
108
|
+
finishedAt: string;
|
|
109
|
+
variants: ReportVariantV1[];
|
|
110
|
+
comparisons: Array<{
|
|
111
|
+
a: string;
|
|
112
|
+
b: string;
|
|
113
|
+
changed: string[];
|
|
114
|
+
confounded: boolean;
|
|
115
|
+
words: string;
|
|
116
|
+
deltaMacro: number | null;
|
|
117
|
+
fixed: number;
|
|
118
|
+
broken: number;
|
|
119
|
+
p: number | null;
|
|
120
|
+
}>;
|
|
121
|
+
}
|
|
122
|
+
export interface ReportRecommendationV1 {
|
|
123
|
+
rule: string;
|
|
124
|
+
severity: 'act' | 'watch' | 'info';
|
|
125
|
+
title: string;
|
|
126
|
+
detail: string;
|
|
127
|
+
change: string;
|
|
128
|
+
skill?: string;
|
|
129
|
+
experiment: string;
|
|
130
|
+
variant?: string;
|
|
131
|
+
evidence: {
|
|
132
|
+
intents: string[];
|
|
133
|
+
numbers: Record<string, number | string>;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export interface SkillAssessmentReportV1 {
|
|
137
|
+
type: 'ap.skill-assessment-report.v1';
|
|
138
|
+
builtAt: string;
|
|
139
|
+
experiments: ReportExperimentV1[];
|
|
140
|
+
/** One entry per skill: its latest numbers per slate, and the recommendations that name it. */
|
|
141
|
+
skillContracts: Array<{
|
|
142
|
+
skill: string;
|
|
143
|
+
slates: Array<{
|
|
144
|
+
experiment: string;
|
|
145
|
+
variant: string;
|
|
146
|
+
asked: number;
|
|
147
|
+
right: number;
|
|
148
|
+
accuracy: number | null;
|
|
149
|
+
wronglyChosen: number;
|
|
150
|
+
confusedWith: Array<{
|
|
151
|
+
skill: string;
|
|
152
|
+
times: number;
|
|
153
|
+
}>;
|
|
154
|
+
}>;
|
|
155
|
+
recommendations: number;
|
|
156
|
+
}>;
|
|
157
|
+
recommendations: ReportRecommendationV1[];
|
|
158
|
+
/** The comparison the program is working toward, in one sentence each (the headline). */
|
|
159
|
+
headline: string[];
|
|
160
|
+
/** What each outcome and each selection approach means, so every renderer says it the same way. */
|
|
161
|
+
glossary: {
|
|
162
|
+
outcomes: typeof OUTCOME_WORDS;
|
|
163
|
+
approaches: typeof VARIANT_WORDS;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/** Share of the test sentence's content words that one example also has — 1 is the sentence itself. */
|
|
167
|
+
export declare function exampleOverlap(test: string, example: string): number;
|
|
168
|
+
/** The threshold above which a test sentence counts as carried by the skills it tests (default 0.6). */
|
|
169
|
+
export declare const CONTAMINATION_THRESHOLD = 0.6;
|
|
170
|
+
/** Build the report. `sets` and `criteria` are keyed by the replay-set digest the experiments pre-registered. `examples`
|
|
171
|
+
* are the example sentences the skills under test declare (their `utterances`, as the playbook carries them) — when
|
|
172
|
+
* given, every test sentence that nearly repeats one is flagged, and so is any number resting on it. */
|
|
173
|
+
export declare function skillAssessmentReportOf(input: {
|
|
174
|
+
experiments: readonly ExperimentRecordV1[];
|
|
175
|
+
sets: Record<string, ReplaySetV1>;
|
|
176
|
+
criteria: Record<string, SelectionCriterionV1>;
|
|
177
|
+
examples?: ReadonlyArray<{
|
|
178
|
+
skill: string;
|
|
179
|
+
says: string;
|
|
180
|
+
isNot?: boolean;
|
|
181
|
+
}>;
|
|
182
|
+
now?: string;
|
|
183
|
+
/** Rename a variant IN THE REPORT for one experiment (`{ [experimentId]: { judgment: 'framed-judgment' } }`) — when a
|
|
184
|
+
* knob value's meaning changed after an experiment ran, the report says what actually ran; the record is never edited. */
|
|
185
|
+
aliases?: Record<string, Record<string, string>>;
|
|
186
|
+
/** Tool id → canonical skill id (the playbook's `source`), for reading judges' distributions (risk–coverage). */
|
|
187
|
+
toolToSkill?: Record<string, string>;
|
|
188
|
+
}): SkillAssessmentReportV1;
|
|
189
|
+
//# sourceMappingURL=report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":"AAeA,O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B,EAAE,CAAC;IAC1C,yFAAyF;IACzF,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,mGAAmG;IACnG,QAAQ,EAAE;QAAE,QAAQ,EAAE,OAAO,aAAa,CAAC;QAAC,UAAU,EAAE,OAAO,aAAa,CAAA;KAAE,CAAC;CAChF;AASD,uGAAuG;AACvG,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKpE;AACD,wGAAwG;AACxG,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C;;yGAEyG;AACzG,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAAE,WAAW,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,aAAa,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACvQ;+HAC2H;IAC3H,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,iHAAiH;IACjH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,uBAAuB,CAkGjE"}
|
package/dist/report.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// THE SKILL ASSESSMENT REPORT — spec 415 §5b (the Lab). One deterministic model of "what was tested, what happened, and
|
|
2
|
+
// what to change", built from the eval store's experiment records plus the replay sets and criteria they pre-registered.
|
|
3
|
+
// Home's Lab and skill-web's per-skill card both render THIS; neither re-derives a number.
|
|
4
|
+
//
|
|
5
|
+
// What it answers, in order: WHICH TESTS RAN (experiments: slate, split, variants, runs, when); DID IT PICK THE RIGHT
|
|
6
|
+
// SKILL (per intent: the test sentence, the skill that should have been chosen, the one that was, the outcome in words);
|
|
7
|
+
// HOW EACH SKILL FARES (accuracy, times wrongly chosen, what it was confused with); WHAT THE HARNESS DID (how each
|
|
8
|
+
// variant selected); WHAT CHANGED (before/after comparisons, in words); and WHAT TO DO (recommendations).
|
|
9
|
+
//
|
|
10
|
+
// RECOMMENDATIONS ARE NOT JUDGING (414 §3.4). Each is produced by a declared rule over the measurements and the
|
|
11
|
+
// experiment design, cites the intents and numbers it rests on, and says what change would address it. The same records
|
|
12
|
+
// yield the same recommendations. Words shown are the replay sets' AUTHORED test sentences — never a person's words:
|
|
13
|
+
// real runs never reach the eval store (414 §8).
|
|
14
|
+
import { riskCoverageOf } from './conformal.js';
|
|
15
|
+
import { foldAbstentions } from './selection-gates.js';
|
|
16
|
+
export const OUTCOME_WORDS = {
|
|
17
|
+
tp: { label: 'right skill', ok: true, explain: 'the skill that should handle this ask was chosen' },
|
|
18
|
+
'tp-alt': { label: 'acceptable alternative', ok: null, explain: 'a declared acceptable alternative was chosen (not counted either way)' },
|
|
19
|
+
tn: { label: 'correctly declined', ok: true, explain: 'no skill fits this ask and none was chosen' },
|
|
20
|
+
'mis-sib': { label: 'chose its sibling', ok: false, explain: 'the declared neighbour of the right skill was chosen instead' },
|
|
21
|
+
'mis-far': { label: 'chose an unrelated skill', ok: false, explain: 'a skill that is not even the declared neighbour was chosen' },
|
|
22
|
+
miss: { label: 'chose nothing', ok: false, explain: 'a skill fits this ask but none was chosen' },
|
|
23
|
+
spur: { label: 'should have declined', ok: false, explain: 'no skill fits this ask, but one was chosen anyway' },
|
|
24
|
+
undetected: { label: 'could not tell', ok: null, explain: 'the run\'s trace could not be read; excluded from every number' },
|
|
25
|
+
};
|
|
26
|
+
export const VARIANT_WORDS = {
|
|
27
|
+
model: 'the model planner chooses a skill by reading the skills\' descriptions',
|
|
28
|
+
declared: 'a deterministic selector matches the ask against each skill\'s declared example sentences and declines when none fits',
|
|
29
|
+
rules: 'the rule-based planner (routes no instruction skill — a baseline)',
|
|
30
|
+
ontology: 'exact: the words of the request ground it to domain classes, and the one skill covering them is chosen — several is a tie it holds, none is a decline; no model, no confidence',
|
|
31
|
+
judgment: 'probabilistic: a judge gives every skill (and \"none\") a probability; the top skill is chosen only when likely enough and clearly ahead, otherwise it declines',
|
|
32
|
+
'ontology+judgment': 'composed: the ontology narrows to the skills covering the classes the request names (none ⇒ decline), and the judge picks among those survivors or declines',
|
|
33
|
+
'propose+judgment': 'recall-first (spec 416): the ontology proposes skills — those covering the classes the request names, their cluster neighbours, and (for a small catalog) every other skill — and vetoes any whose exclusions the request names; the judge picks among the proposed or declines',
|
|
34
|
+
'ontology-first': 'fastest: when the ontology alone names exactly one skill it is taken with no model call; otherwise the judge picks from every skill or declines',
|
|
35
|
+
'framed-judgment': 'the judge first frames the request as one domain class, the skills covering that class are ranked by the judge (the 2026-09-26 shape — the judge narrows, so it is not the composed arm)',
|
|
36
|
+
};
|
|
37
|
+
const pct = (v) => (v === null || v === undefined ? 'n/a' : `${Math.round(v * 100)}%`);
|
|
38
|
+
const shortSkill = (s) => (s ? s.replace(/^skill:/, '').replace(/^[^/]+\//, '') : 'nothing');
|
|
39
|
+
// ── CONTAMINATION: a test sentence the skills themselves carry as an example measures recall of the example, not
|
|
40
|
+
// selection. Held-out is sacred (§6); this is how the report keeps it so without trusting anyone to remember. ──
|
|
41
|
+
const STOP = new Set('a an the and or of to for in on at by with from as is are be it its this that we our us i my me you your they their do does can could would should will need want help please so if but not no what which who how when where than then there here have has had get one some any all about into out up just also like more most very'.split(' '));
|
|
42
|
+
const words = (t) => t.toLowerCase().replace(/[’']/g, '').split(/[^a-z0-9]+/).filter((w) => w.length > 2 && !STOP.has(w));
|
|
43
|
+
/** Share of the test sentence's content words that one example also has — 1 is the sentence itself. */
|
|
44
|
+
export function exampleOverlap(test, example) {
|
|
45
|
+
const t = new Set(words(test));
|
|
46
|
+
const e = new Set(words(example));
|
|
47
|
+
if (!t.size)
|
|
48
|
+
return 0;
|
|
49
|
+
let n = 0;
|
|
50
|
+
for (const w of t)
|
|
51
|
+
if (e.has(w))
|
|
52
|
+
n += 1;
|
|
53
|
+
return n / t.size;
|
|
54
|
+
}
|
|
55
|
+
/** The threshold above which a test sentence counts as carried by the skills it tests (default 0.6). */
|
|
56
|
+
export const CONTAMINATION_THRESHOLD = 0.6;
|
|
57
|
+
/** Build the report. `sets` and `criteria` are keyed by the replay-set digest the experiments pre-registered. `examples`
|
|
58
|
+
* are the example sentences the skills under test declare (their `utterances`, as the playbook carries them) — when
|
|
59
|
+
* given, every test sentence that nearly repeats one is flagged, and so is any number resting on it. */
|
|
60
|
+
export function skillAssessmentReportOf(input) {
|
|
61
|
+
const experiments = [];
|
|
62
|
+
const recommendations = [];
|
|
63
|
+
const sorted = [...input.experiments].sort((a, b) => a.startedAt.localeCompare(b.startedAt));
|
|
64
|
+
for (const rec of sorted) {
|
|
65
|
+
const set = input.sets[rec.plan.replaySetDigest];
|
|
66
|
+
const crit = input.criteria[rec.plan.replaySetDigest];
|
|
67
|
+
if (!set || !crit)
|
|
68
|
+
continue;
|
|
69
|
+
const intentById = new Map(set.intents.map((i) => [i.id, i]));
|
|
70
|
+
const variants = [];
|
|
71
|
+
for (const name of Object.keys(rec.plan.variants)) {
|
|
72
|
+
const shown = input.aliases?.[rec.id]?.[name] ?? name;
|
|
73
|
+
const score = rec.scores[name];
|
|
74
|
+
const runs = rec.runs.filter((r) => r.variant === name && r.repeat === 0);
|
|
75
|
+
const intents = runs.map((r) => {
|
|
76
|
+
const it = intentById.get(r.intentId);
|
|
77
|
+
const g = crit.cases[r.intentId];
|
|
78
|
+
const outcome = r.verdict?.outcome ?? 'undetected';
|
|
79
|
+
const w = OUTCOME_WORDS[outcome];
|
|
80
|
+
const hit = input.examples?.length && it?.message ? input.examples.map((e) => ({ e, o: exampleOverlap(it.message, e.says) })).sort((a, b) => b.o - a.o)[0] : undefined;
|
|
81
|
+
const contaminated = hit && hit.o >= CONTAMINATION_THRESHOLD ? { skill: hit.e.skill, overlap: Number(hit.o.toFixed(2)), isNot: !!hit.e.isNot } : undefined;
|
|
82
|
+
return {
|
|
83
|
+
intentId: r.intentId, message: it?.message ?? '', split: it?.split ?? '', ...(it?.bucket ? { bucket: it.bucket } : {}),
|
|
84
|
+
...(contaminated ? { contaminated } : {}),
|
|
85
|
+
expected: g?.expected ?? null, chosen: r.verdict?.primary ?? r.selected[0] ?? null, outcome, label: w.label, ok: w.ok,
|
|
86
|
+
...(it?.notes ? { why: it.notes } : {}), ...(r.ms !== undefined ? { ms: r.ms } : {}),
|
|
87
|
+
...(r.askMs !== undefined ? { askMs: r.askMs } : {}), ...(r.selectionMs !== undefined ? { selectionMs: r.selectionMs } : {}),
|
|
88
|
+
...(r.tokens ? { tokens: { ...(r.tokens.selectionIn !== undefined ? { pickIn: r.tokens.selectionIn } : {}), ...(r.tokens.selectionOut !== undefined ? { pickOut: r.tokens.selectionOut } : {}), ...(r.tokens.totalIn !== undefined ? { totalIn: r.tokens.totalIn } : {}), ...(r.tokens.totalOut !== undefined ? { totalOut: r.tokens.totalOut } : {}), ...(r.tokens.calls !== undefined ? { calls: r.tokens.calls } : {}) } } : {}),
|
|
89
|
+
...(r.stages && Object.keys(r.stages).length ? { stages: r.stages } : {}),
|
|
90
|
+
...(r.selection?.chain && (r.selection.chain.length > 1 || r.selection.approach === 'outcome') ? { chain: r.selection.chain } : {}),
|
|
91
|
+
...(r.selection?.missing?.length ? { missing: r.selection.missing } : {}),
|
|
92
|
+
...(r.quality ? { quality: r.quality.score } : {}),
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
const agg = score?.aggregate;
|
|
96
|
+
const skillIds = Object.keys(score?.perSkill ?? {});
|
|
97
|
+
const perSkill = skillIds.map((sk) => {
|
|
98
|
+
const ps = score.perSkill[sk];
|
|
99
|
+
const confused = new Map();
|
|
100
|
+
for (const row of intents)
|
|
101
|
+
if (row.expected === sk && row.chosen && row.chosen !== sk && !row.ok)
|
|
102
|
+
confused.set(row.chosen, (confused.get(row.chosen) ?? 0) + 1);
|
|
103
|
+
const wronglyChosen = intents.filter((row) => row.chosen === sk && row.ok === false).length;
|
|
104
|
+
return { skill: sk, asked: ps.n_positive, right: ps.TP, accuracy: ps.n_positive ? ps.TP / ps.n_positive : null, ci: ps.ci, wronglyChosen, confusedWith: [...confused.entries()].map(([skill, times]) => ({ skill, times })).sort((a, b) => b.times - a.times) };
|
|
105
|
+
}).sort((a, b) => a.skill.localeCompare(b.skill));
|
|
106
|
+
const v = {
|
|
107
|
+
name: shown, how: VARIANT_WORDS[shown] ?? shown, runs: runs.length,
|
|
108
|
+
macroTa: agg?.macro_ta.value ?? null, macroCi: agg?.macro_ta.ci ?? null, microTa: agg?.micro_ta.value ?? null,
|
|
109
|
+
holdRate: agg && agg.n_negative ? agg.hold_rate.value : null, ...(agg && agg.n_negative ? { holdNum: agg.hold_rate.num, holdDen: agg.hold_rate.den } : {}),
|
|
110
|
+
routingPurity: agg?.routing_purity.value ?? null, collisionContainment: agg?.collision_containment.value ?? null,
|
|
111
|
+
right: intents.filter((r) => r.outcome === 'tp').length, wrong: intents.filter((r) => r.ok === false).length,
|
|
112
|
+
declinedCorrectly: intents.filter((r) => r.outcome === 'tn').length, firedWrongly: intents.filter((r) => r.outcome === 'spur').length,
|
|
113
|
+
gate: rec.verdicts[name] ? { status: rec.verdicts[name].status, reason: rec.verdicts[name].binding_reason } : null,
|
|
114
|
+
intents, perSkill,
|
|
115
|
+
};
|
|
116
|
+
const allRuns = rec.runs.filter((r) => r.variant === name);
|
|
117
|
+
{
|
|
118
|
+
const ms = allRuns.map((r) => r.askMs ?? r.ms).filter((x) => typeof x === 'number').sort((a, b) => a - b);
|
|
119
|
+
const tk = allRuns.map((r) => r.tokens).filter((x) => !!x);
|
|
120
|
+
const mean = (xs) => (xs.length ? Math.round(xs.reduce((a, b) => a + b, 0) / xs.length) : null);
|
|
121
|
+
const sms = allRuns.map((r) => r.selectionMs).filter((x) => typeof x === 'number').sort((a, b) => a - b);
|
|
122
|
+
if (ms.length || tk.length)
|
|
123
|
+
v.cost = { medianMs: ms.length ? ms[Math.floor(ms.length / 2)] : null, medianSelectionMs: sms.length ? sms[Math.floor(sms.length / 2)] : null, tokenRuns: tk.length,
|
|
124
|
+
meanSelectionIn: mean(tk.map((t) => t.selectionIn)), meanSelectionOut: mean(tk.map((t) => t.selectionOut)), meanTotalIn: mean(tk.map((t) => t.totalIn)), meanTotalOut: mean(tk.map((t) => t.totalOut)),
|
|
125
|
+
unreportedCalls: tk.reduce((n, t) => n + t.unreported, 0) };
|
|
126
|
+
}
|
|
127
|
+
if (input.toolToSkill && allRuns.some((r) => r.selection?.distribution)) {
|
|
128
|
+
const rc = riskCoverageOf({ runs: allRuns, criterion: crit, toolToSkill: input.toolToSkill, fold: (d) => foldAbstentions(d) });
|
|
129
|
+
if (rc.n)
|
|
130
|
+
v.riskCoverage = { n: rc.n, aurc: rc.aurc === null ? null : Number(rc.aurc.toFixed(4)), points: thin(rc.points, 40).map((x) => ({ coverage: Number(x.coverage.toFixed(3)), risk: Number(x.risk.toFixed(3)), threshold: Number(x.threshold.toFixed(3)) })) };
|
|
131
|
+
}
|
|
132
|
+
variants.push(v);
|
|
133
|
+
recommendations.push(...rulesFor(rec, v));
|
|
134
|
+
}
|
|
135
|
+
const comparisons = rec.comparisons.map((c) => {
|
|
136
|
+
const k = c.comparison;
|
|
137
|
+
const words = !k ? `not compared: ${c.error ?? 'a side was not scored'}`
|
|
138
|
+
: `${c.b} vs ${c.a}: accuracy ${k.delta_macro !== null && k.delta_macro >= 0 ? 'up' : 'down'} ${pct(Math.abs(k.delta_macro ?? 0))} — ${k.fixed} intent${k.fixed === 1 ? '' : 's'} fixed, ${k.broken} broken${k.p_value < 0.05 ? ' (significant)' : ' (not significant yet)'}${c.confounded ? ' — CONFOUNDED: more than one thing changed' : ''}`;
|
|
139
|
+
return { a: c.a, b: c.b, changed: c.confounds, confounded: c.confounded, words, deltaMacro: k?.delta_macro ?? null, fixed: k?.fixed ?? 0, broken: k?.broken ?? 0, p: k?.p_value ?? null };
|
|
140
|
+
});
|
|
141
|
+
experiments.push({ id: rec.id, slate: `${set.id}@${set.version}`, split: rec.plan.split, repeats: rec.plan.repeats, startedAt: rec.startedAt, finishedAt: rec.finishedAt, variants, comparisons });
|
|
142
|
+
}
|
|
143
|
+
recommendations.push(...repairRules(sorted, experiments));
|
|
144
|
+
// Per skill: the LATEST experiment per slate (and its first variant), plus how many recommendations name the skill.
|
|
145
|
+
const latestBySlate = new Map();
|
|
146
|
+
for (const e of experiments)
|
|
147
|
+
latestBySlate.set(`${e.slate}|${e.split}`, e);
|
|
148
|
+
// CURRENT ADVICE comes from the latest experiment on each slate; what earlier experiments said is history (their
|
|
149
|
+
// numbers stay in `experiments`). A change's effect (R8) is stated on the experiment that measured it.
|
|
150
|
+
const current = new Set([...latestBySlate.values()].map((e) => e.id));
|
|
151
|
+
for (let i = recommendations.length - 1; i >= 0; i--)
|
|
152
|
+
if (!current.has(recommendations[i].experiment))
|
|
153
|
+
recommendations.splice(i, 1);
|
|
154
|
+
const skillMap = new Map();
|
|
155
|
+
for (const e of latestBySlate.values())
|
|
156
|
+
for (const v of e.variants)
|
|
157
|
+
for (const ps of v.perSkill) {
|
|
158
|
+
const entry = skillMap.get(ps.skill) ?? { skill: ps.skill, slates: [], recommendations: 0 };
|
|
159
|
+
entry.slates.push({ experiment: e.id, variant: v.name, asked: ps.asked, right: ps.right, accuracy: ps.accuracy, wronglyChosen: ps.wronglyChosen, confusedWith: ps.confusedWith });
|
|
160
|
+
skillMap.set(ps.skill, entry);
|
|
161
|
+
}
|
|
162
|
+
for (const r of recommendations)
|
|
163
|
+
if (r.skill && skillMap.has(r.skill))
|
|
164
|
+
skillMap.get(r.skill).recommendations += 1;
|
|
165
|
+
const headline = [...latestBySlate.values()].map((e) => {
|
|
166
|
+
const parts = e.variants.map((v) => `${v.name}: ${v.right}/${v.intents.filter((i) => i.expected).length} right skill${v.holdDen ? `, declined ${v.holdNum}/${v.holdDen} it should` : ''}`);
|
|
167
|
+
return `${e.slate} (${e.split}) — ${parts.join('; ')}`;
|
|
168
|
+
});
|
|
169
|
+
return { type: 'ap.skill-assessment-report.v1', builtAt: input.now ?? new Date().toISOString(), experiments, skillContracts: [...skillMap.values()].sort((a, b) => a.skill.localeCompare(b.skill)), recommendations, headline, glossary: { outcomes: OUTCOME_WORDS, approaches: VARIANT_WORDS } };
|
|
170
|
+
}
|
|
171
|
+
/** The declared recommendation rules over one variant of one experiment. */
|
|
172
|
+
function rulesFor(rec, v) {
|
|
173
|
+
const out = [];
|
|
174
|
+
const base = { experiment: rec.id, variant: v.name };
|
|
175
|
+
// R1 — ABSTENTION: the harness fires a skill on asks it should decline.
|
|
176
|
+
if (v.holdDen && v.holdRate !== null && v.holdRate < (rec.plan.thresholds?.negative_hold_rate ?? 0.95)) {
|
|
177
|
+
const fired = v.intents.filter((i) => i.outcome === 'spur');
|
|
178
|
+
out.push({ rule: 'R1-abstention', severity: 'act', ...base,
|
|
179
|
+
title: `Declines only ${v.holdNum}/${v.holdDen} asks it should (target ≥ ${pct(rec.plan.thresholds?.negative_hold_rate ?? 0.95)})`,
|
|
180
|
+
detail: `${fired.length} out-of-scope ask${fired.length === 1 ? '' : 's'} got a skill anyway: ${fired.slice(0, 4).map((i) => `“${i.message.slice(0, 70)}${i.message.length > 70 ? '…' : ''}” → ${shortSkill(i.chosen)}`).join('; ')}${fired.length > 4 ? '; …' : ''}.`,
|
|
181
|
+
change: 'Give the skills that fired declared `isNot` examples of these asks (and a NOT-for line in the description), or measure a selection approach that can decline (the declared selector).',
|
|
182
|
+
evidence: { intents: fired.map((i) => i.intentId), numbers: { hold: v.holdRate, declined: v.holdNum ?? 0, of: v.holdDen } } });
|
|
183
|
+
}
|
|
184
|
+
// R2 — ATTRACTOR: one skill charged with ≥ 2 wrong choices.
|
|
185
|
+
const charged = new Map();
|
|
186
|
+
for (const i of v.intents)
|
|
187
|
+
if (i.ok === false && i.chosen)
|
|
188
|
+
charged.set(i.chosen, [...(charged.get(i.chosen) ?? []), i]);
|
|
189
|
+
for (const [skill, rows] of charged)
|
|
190
|
+
if (rows.length >= 2)
|
|
191
|
+
out.push({ rule: 'R2-attractor', severity: 'act', ...base, skill,
|
|
192
|
+
title: `${shortSkill(skill)} is chosen for asks that are not its job (${rows.length}×)`,
|
|
193
|
+
detail: rows.slice(0, 4).map((i) => `“${i.message.slice(0, 80)}${i.message.length > 80 ? '…' : ''}” (${i.label})`).join('; '),
|
|
194
|
+
change: `Narrow ${shortSkill(skill)}'s description and add these as its \`isNot\` examples; if they belong to a sibling, add a hand-off clause.`,
|
|
195
|
+
evidence: { intents: rows.map((i) => i.intentId), numbers: { times: rows.length } } });
|
|
196
|
+
// R3 — CONFUSION: a skill's own asks went to another skill.
|
|
197
|
+
for (const ps of v.perSkill)
|
|
198
|
+
for (const c of ps.confusedWith)
|
|
199
|
+
out.push({ rule: 'R3-confusion', severity: 'act', ...base, skill: ps.skill,
|
|
200
|
+
title: `Asks for ${shortSkill(ps.skill)} went to ${shortSkill(c.skill)} (${c.times}×)`,
|
|
201
|
+
detail: v.intents.filter((i) => i.expected === ps.skill && i.chosen === c.skill).map((i) => `“${i.message.slice(0, 90)}${i.message.length > 90 ? '…' : ''}”`).join('; '),
|
|
202
|
+
change: `State the boundary in both descriptions (when it is ${shortSkill(ps.skill)} and not ${shortSkill(c.skill)}), and add these sentences to ${shortSkill(ps.skill)}'s \`says\` examples.`,
|
|
203
|
+
evidence: { intents: v.intents.filter((i) => i.expected === ps.skill && i.chosen === c.skill).map((i) => i.intentId), numbers: { times: c.times } } });
|
|
204
|
+
// R4 — MISSED: a skill fits and nothing was chosen (the declared selector's typical failure).
|
|
205
|
+
const missed = v.intents.filter((i) => i.outcome === 'miss');
|
|
206
|
+
const positives = v.intents.filter((i) => i.expected).length;
|
|
207
|
+
// A variant that selects NO skill at all is a baseline, said once as such — not 24 action items.
|
|
208
|
+
if (missed.length && missed.length === positives && v.right === 0)
|
|
209
|
+
out.push({ rule: 'R4-baseline', severity: 'info', ...base,
|
|
210
|
+
title: `${v.name} selects no skill at all — a baseline, not a candidate`,
|
|
211
|
+
detail: `All ${positives} asks a skill should handle got none under “${v.how}”.`, change: 'Nothing to repair; compare candidates against it.', evidence: { intents: [], numbers: { positives } } });
|
|
212
|
+
else if (missed.length)
|
|
213
|
+
out.push({ rule: 'R4-missed', severity: missed.length >= 3 ? 'act' : 'watch', ...base,
|
|
214
|
+
title: `${missed.length} ask${missed.length === 1 ? '' : 's'} a skill should handle got no skill`,
|
|
215
|
+
detail: missed.slice(0, 4).map((i) => `“${i.message.slice(0, 80)}${i.message.length > 80 ? '…' : ''}” → should be ${shortSkill(i.expected)}`).join('; '),
|
|
216
|
+
change: v.name === 'declared' ? 'Add `says` examples phrased like these asks to the skills they belong to — the declared selector only knows the sentences it was given.' : 'Check the skill\'s description names this situation; add it to its `says` examples.',
|
|
217
|
+
evidence: { intents: missed.map((i) => i.intentId), numbers: { missed: missed.length } } });
|
|
218
|
+
// R0 — CONTAMINATION: test sentences the skills carry as their own examples. Said first: every other number on this
|
|
219
|
+
// variant rests partly on them.
|
|
220
|
+
const leaked = v.intents.filter((i) => i.contaminated);
|
|
221
|
+
if (leaked.length)
|
|
222
|
+
out.push({ rule: 'R0-contamination', severity: 'act', ...base,
|
|
223
|
+
title: `${leaked.length} of ${v.intents.length} test sentences are (nearly) the skills' own examples — their results do not measure selection`,
|
|
224
|
+
detail: leaked.slice(0, 4).map((i) => `“${i.message.slice(0, 70)}${i.message.length > 70 ? '…' : ''}” ≈ an example of ${shortSkill(i.contaminated.skill)} (${Math.round(i.contaminated.overlap * 100)}% of its words)`).join('; '),
|
|
225
|
+
change: 'Keep test sentences out of the skills\' examples: write examples from other phrasings, or move these sentences to a set nobody writes examples from, and re-measure on fresh sentences before reading a lift.',
|
|
226
|
+
evidence: { intents: leaked.map((i) => i.intentId), numbers: { contaminated: leaked.length, of: v.intents.length } } });
|
|
227
|
+
// R5 — TOO FEW CASES to gate: per-skill intervals this wide cannot clear a floor.
|
|
228
|
+
const asked = v.perSkill.map((p) => p.asked).filter((n) => n > 0);
|
|
229
|
+
if (asked.length && Math.max(...asked) < 10)
|
|
230
|
+
out.push({ rule: 'R5-sample-size', severity: 'info', ...base,
|
|
231
|
+
title: `Too few cases per skill to pass or fail a skill (${Math.min(...asked)}–${Math.max(...asked)} each)`,
|
|
232
|
+
detail: `At this size a skill's interval spans roughly ${pct(v.perSkill.find((p) => p.ci)?.ci?.[0] ?? null)}–100% even when every case is right, so the per-skill gate cannot pass.`,
|
|
233
|
+
change: 'Grow the slate toward ~40 cases per skill before treating a per-skill result as a verdict; use repeats (Stage 2) to measure instability.',
|
|
234
|
+
evidence: { intents: [], numbers: { minPerSkill: Math.min(...asked), maxPerSkill: Math.max(...asked) } } });
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
/** Rules over PAIRS of experiments on the same slate: what a change did. */
|
|
238
|
+
function repairRules(sorted, reports) {
|
|
239
|
+
const out = [];
|
|
240
|
+
for (const e of reports)
|
|
241
|
+
for (const c of e.comparisons) {
|
|
242
|
+
if (c.confounded)
|
|
243
|
+
out.push({ rule: 'R6-confounded', severity: 'watch', experiment: e.id, title: `${c.b} vs ${c.a} changed more than one thing (${c.changed.join(', ')})`, detail: 'The difference cannot be attributed to either change.', change: 'Re-run changing one component at a time.', evidence: { intents: [], numbers: {} } });
|
|
244
|
+
if (c.broken > 0 && c.p !== null)
|
|
245
|
+
out.push({ rule: 'R7-regressions', severity: 'watch', experiment: e.id, variant: c.b, title: `${c.b} broke ${c.broken} intent${c.broken === 1 ? '' : 's'} that ${c.a} got right`, detail: c.words, change: 'Open the broken intents; a repair that fixes some and breaks others needs its boundary tightened, not shipped.', evidence: { intents: [], numbers: { fixed: c.fixed, broken: c.broken } } });
|
|
246
|
+
}
|
|
247
|
+
// Across experiments on the same slate+split (e.g. the NOT-for repair): same variant name, before → after.
|
|
248
|
+
const bySlate = new Map();
|
|
249
|
+
for (const e of reports)
|
|
250
|
+
bySlate.set(`${e.slate}|${e.split}`, [...(bySlate.get(`${e.slate}|${e.split}`) ?? []), e]);
|
|
251
|
+
for (const list of bySlate.values())
|
|
252
|
+
for (let i = 1; i < list.length; i++) {
|
|
253
|
+
const before = list[i - 1], after = list[i];
|
|
254
|
+
for (const v of after.variants) {
|
|
255
|
+
const pv = before.variants.find((x) => x.name === v.name);
|
|
256
|
+
if (!pv)
|
|
257
|
+
continue;
|
|
258
|
+
const prev = new Map(pv.intents.map((x) => [x.intentId, x]));
|
|
259
|
+
const fixed = v.intents.filter((x) => x.ok === true && prev.get(x.intentId)?.ok === false);
|
|
260
|
+
const broken = v.intents.filter((x) => x.ok === false && prev.get(x.intentId)?.ok === true);
|
|
261
|
+
if (!fixed.length && !broken.length)
|
|
262
|
+
continue;
|
|
263
|
+
out.push({ rule: 'R8-change-effect', severity: broken.length > fixed.length ? 'act' : 'info', experiment: after.id, variant: v.name,
|
|
264
|
+
title: `Since ${before.id}: ${fixed.length} fixed, ${broken.length} broken (${v.name})`,
|
|
265
|
+
detail: [...fixed.slice(0, 3).map((x) => `fixed “${x.message.slice(0, 60)}…”`), ...broken.slice(0, 3).map((x) => `broke “${x.message.slice(0, 60)}…” (${x.label})`)].join('; '),
|
|
266
|
+
change: broken.length ? 'Keep the change only if the broken intents are explained; otherwise revert or narrow it.' : 'Confirm on the held-out split before calling it a lift.',
|
|
267
|
+
evidence: { intents: [...fixed, ...broken].map((x) => x.intentId), numbers: { fixed: fixed.length, broken: broken.length } } });
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
void sorted;
|
|
271
|
+
return out;
|
|
272
|
+
}
|
|
273
|
+
/** Keep at most `max` points of a curve, always the first and the last (the chart needs the shape, not every run). */
|
|
274
|
+
function thin(xs, max) {
|
|
275
|
+
if (xs.length <= max)
|
|
276
|
+
return [...xs];
|
|
277
|
+
const out = [];
|
|
278
|
+
for (let i = 0; i < max; i++)
|
|
279
|
+
out.push(xs[Math.round((i * (xs.length - 1)) / (max - 1))]);
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=report.js.map
|