@agenticprimitives/evaluation 0.0.0-alpha.1 → 0.0.0-alpha.11

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.
Files changed (90) hide show
  1. package/README.md +2 -0
  2. package/dist/act.d.ts +97 -0
  3. package/dist/act.d.ts.map +1 -0
  4. package/dist/act.js +115 -0
  5. package/dist/act.js.map +1 -0
  6. package/dist/agent-record.d.ts +86 -0
  7. package/dist/agent-record.d.ts.map +1 -0
  8. package/dist/agent-record.js +108 -0
  9. package/dist/agent-record.js.map +1 -0
  10. package/dist/assessment.d.ts +158 -0
  11. package/dist/assessment.d.ts.map +1 -0
  12. package/dist/assessment.js +167 -0
  13. package/dist/assessment.js.map +1 -0
  14. package/dist/canonical.d.ts +2 -0
  15. package/dist/canonical.d.ts.map +1 -0
  16. package/dist/canonical.js +4 -0
  17. package/dist/canonical.js.map +1 -0
  18. package/dist/capture.d.ts +90 -0
  19. package/dist/capture.d.ts.map +1 -0
  20. package/dist/capture.js +195 -0
  21. package/dist/capture.js.map +1 -0
  22. package/dist/compare-runner.d.ts +211 -0
  23. package/dist/compare-runner.d.ts.map +1 -0
  24. package/dist/compare-runner.js +379 -0
  25. package/dist/compare-runner.js.map +1 -0
  26. package/dist/conformal.d.ts +113 -0
  27. package/dist/conformal.d.ts.map +1 -0
  28. package/dist/conformal.js +113 -0
  29. package/dist/conformal.js.map +1 -0
  30. package/dist/consensus.d.ts +53 -0
  31. package/dist/consensus.d.ts.map +1 -0
  32. package/dist/consensus.js +64 -0
  33. package/dist/consensus.js.map +1 -0
  34. package/dist/eval-file.d.ts +104 -0
  35. package/dist/eval-file.d.ts.map +1 -0
  36. package/dist/eval-file.js +92 -0
  37. package/dist/eval-file.js.map +1 -0
  38. package/dist/experiment.d.ts +301 -0
  39. package/dist/experiment.d.ts.map +1 -0
  40. package/dist/experiment.js +237 -0
  41. package/dist/experiment.js.map +1 -0
  42. package/dist/index.d.ts +38 -0
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +38 -0
  45. package/dist/index.js.map +1 -1
  46. package/dist/ledger.d.ts +128 -0
  47. package/dist/ledger.d.ts.map +1 -0
  48. package/dist/ledger.js +146 -0
  49. package/dist/ledger.js.map +1 -0
  50. package/dist/live-gates.d.ts +3 -0
  51. package/dist/live-gates.d.ts.map +1 -1
  52. package/dist/live-gates.js +3 -1
  53. package/dist/live-gates.js.map +1 -1
  54. package/dist/measure.d.ts +63 -0
  55. package/dist/measure.d.ts.map +1 -0
  56. package/dist/measure.js +95 -0
  57. package/dist/measure.js.map +1 -0
  58. package/dist/replay.d.ts +58 -0
  59. package/dist/replay.d.ts.map +1 -0
  60. package/dist/replay.js +65 -0
  61. package/dist/replay.js.map +1 -0
  62. package/dist/report.d.ts +249 -0
  63. package/dist/report.d.ts.map +1 -0
  64. package/dist/report.js +363 -0
  65. package/dist/report.js.map +1 -0
  66. package/dist/rollup.d.ts +91 -0
  67. package/dist/rollup.d.ts.map +1 -0
  68. package/dist/rollup.js +80 -0
  69. package/dist/rollup.js.map +1 -0
  70. package/dist/selection-gates.d.ts +283 -0
  71. package/dist/selection-gates.d.ts.map +1 -0
  72. package/dist/selection-gates.js +331 -0
  73. package/dist/selection-gates.js.map +1 -0
  74. package/dist/selection-score.d.ts +285 -0
  75. package/dist/selection-score.d.ts.map +1 -0
  76. package/dist/selection-score.js +392 -0
  77. package/dist/selection-score.js.map +1 -0
  78. package/dist/selection.d.ts +83 -0
  79. package/dist/selection.d.ts.map +1 -0
  80. package/dist/selection.js +86 -0
  81. package/dist/selection.js.map +1 -0
  82. package/dist/signals.d.ts +37 -0
  83. package/dist/signals.d.ts.map +1 -0
  84. package/dist/signals.js +44 -0
  85. package/dist/signals.js.map +1 -0
  86. package/dist/stats.d.ts +62 -0
  87. package/dist/stats.d.ts.map +1 -0
  88. package/dist/stats.js +279 -0
  89. package/dist/stats.js.map +1 -0
  90. package/package.json +17 -2
@@ -0,0 +1,249 @@
1
+ import { type OutcomeGoldV1, type OutcomePlanScoreV1 } from './selection-gates.js';
2
+ import { type ExperimentRecordV1, type FailureCauseV1 } from './experiment.js';
3
+ import { type ReplaySetV1, type SuiteKindV1 } from './replay.js';
4
+ import type { SelectionCriterionV1, SelectionOutcomeV1 } from './selection.js';
5
+ export declare const CAUSE_WORDS: Record<FailureCauseV1 | 'isolation', string>;
6
+ export declare const SUITE_WORDS: Record<SuiteKindV1, string>;
7
+ /** A capability set that passes this many consecutive experiments at or above this accuracy is flagged for graduation. */
8
+ export declare const GRADUATION: {
9
+ readonly consecutive: 3;
10
+ readonly accuracy: 0.95;
11
+ };
12
+ export declare const OUTCOME_WORDS: Record<SelectionOutcomeV1, {
13
+ label: string;
14
+ ok: boolean | null;
15
+ explain: string;
16
+ }>;
17
+ export declare const VARIANT_WORDS: Record<string, string>;
18
+ export interface ReportIntentRowV1 {
19
+ intentId: string;
20
+ message: string;
21
+ split: string;
22
+ bucket?: string;
23
+ /** This test sentence nearly repeats an example a skill declares — its result measures the example, not selection. */
24
+ contaminated?: {
25
+ skill: string;
26
+ overlap: number;
27
+ isNot: boolean;
28
+ };
29
+ expected: string | null;
30
+ chosen: string | null;
31
+ outcome: SelectionOutcomeV1;
32
+ label: string;
33
+ ok: boolean | null;
34
+ why?: string;
35
+ ms?: number;
36
+ /** 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,
37
+ * where the time went (stage → ms), and — for a chain — the skills run, in order, and the inputs named missing. */
38
+ askMs?: number;
39
+ selectionMs?: number;
40
+ tokens?: {
41
+ pickIn?: number;
42
+ pickOut?: number;
43
+ totalIn?: number;
44
+ totalOut?: number;
45
+ calls?: number;
46
+ };
47
+ stages?: Record<string, number>;
48
+ chain?: string[];
49
+ missing?: string[];
50
+ quality?: number;
51
+ /** W1 — why this case has no verdict (absent when it has one). */
52
+ failureCause?: FailureCauseV1 | 'isolation';
53
+ /** W4 — pass^k: every repeat of this case was right (null when the case ran once or no repeat was scored). */
54
+ passK?: boolean | null;
55
+ /** Spec 418 A2 / W2 — the outcome judge's score (`delivered`, against the GOLD plan when `deliveredBasis` says so),
56
+ * and the agent-plan number beside it. (`outcome` above is the SELECTION outcome — a different question.) */
57
+ delivered?: number;
58
+ deliveredBasis?: 'gold-plan' | 'agent-plan';
59
+ deliveredAgentPlan?: number;
60
+ cantTell?: number;
61
+ /** W3 — the state check: every gold-plan class exists in the vault and validates against its shape. */
62
+ stateCheck?: boolean;
63
+ }
64
+ export interface ReportVariantV1 {
65
+ name: string;
66
+ how: string;
67
+ runs: number;
68
+ /** W1 — the denominator, explained: runs dispatched, runs with a verdict, and the runs without one BY CAUSE. */
69
+ n: {
70
+ runs: number;
71
+ scored: number;
72
+ agent: number;
73
+ grader: number;
74
+ environment: number;
75
+ isolation: number;
76
+ };
77
+ /** W4 — pass^k over the cases that ran more than once: all repeats right / cases with repeats. */
78
+ passK?: {
79
+ passed: number;
80
+ of: number;
81
+ k: number;
82
+ };
83
+ /** THE OUTCOME, FIRST (W3/W4): the state check (records exist and validate) then the judge (mean, over the runs it
84
+ * scored; cantTell classes counted and out of the denominator). The plan metrics come after, as diagnostics. */
85
+ stateCheck?: {
86
+ pass: number;
87
+ n: number;
88
+ };
89
+ outcome?: {
90
+ mean: number;
91
+ n: number;
92
+ cantTell: number;
93
+ basis: 'gold-plan' | 'agent-plan' | 'mixed';
94
+ agentPlanMean?: number;
95
+ };
96
+ /** DIAGNOSTIC — how the plan compared with the gold plan (exact · needless · short · stepsScore). Never pass/fail. */
97
+ planMetrics?: Omit<OutcomePlanScoreV1, 'variant'>;
98
+ macroTa: number | null;
99
+ macroCi: [number, number] | null;
100
+ microTa: number | null;
101
+ holdRate: number | null;
102
+ holdNum?: number;
103
+ holdDen?: number;
104
+ routingPurity: number | null;
105
+ collisionContainment: number | null;
106
+ right: number;
107
+ wrong: number;
108
+ declinedCorrectly: number;
109
+ firedWrongly: number;
110
+ gate: {
111
+ status: string;
112
+ reason: string;
113
+ } | null;
114
+ intents: ReportIntentRowV1[];
115
+ /** Spec 416 W3 — selective prediction for a variant whose runs carry a judge's distribution: answering only its most
116
+ * confident runs, the error rate among those answered. Absent when no run recorded a distribution. */
117
+ riskCoverage?: {
118
+ n: number;
119
+ aurc: number | null;
120
+ points: Array<{
121
+ coverage: number;
122
+ risk: number;
123
+ threshold: number;
124
+ }>;
125
+ };
126
+ /** What an answer COST: the median run time, and the tokens providers reported — for the selection alone (the model
127
+ * planner's or the judge's calls) and for the whole run. `tokenRuns` says how many runs reported any; absent when
128
+ * none did (older experiments recorded no tokens). */
129
+ cost?: {
130
+ medianMs: number | null;
131
+ medianSelectionMs: number | null;
132
+ tokenRuns: number;
133
+ meanSelectionIn: number | null;
134
+ meanSelectionOut: number | null;
135
+ meanTotalIn: number | null;
136
+ meanTotalOut: number | null;
137
+ unreportedCalls: number;
138
+ };
139
+ perSkill: Array<{
140
+ skill: string;
141
+ asked: number;
142
+ right: number;
143
+ accuracy: number | null;
144
+ ci: [number, number] | null;
145
+ wronglyChosen: number;
146
+ confusedWith: Array<{
147
+ skill: string;
148
+ times: number;
149
+ }>;
150
+ }>;
151
+ }
152
+ export interface ReportExperimentV1 {
153
+ id: string;
154
+ slate: string;
155
+ split: string;
156
+ repeats: number;
157
+ startedAt: string;
158
+ finishedAt: string;
159
+ /** W4 — capability | regression (declared on the set, else inferred from its id). */
160
+ suiteKind: SuiteKindV1;
161
+ variants: ReportVariantV1[];
162
+ comparisons: Array<{
163
+ a: string;
164
+ b: string;
165
+ changed: string[];
166
+ confounded: boolean;
167
+ words: string;
168
+ deltaMacro: number | null;
169
+ fixed: number;
170
+ broken: number;
171
+ p: number | null;
172
+ }>;
173
+ }
174
+ export interface ReportRecommendationV1 {
175
+ rule: string;
176
+ severity: 'act' | 'watch' | 'info';
177
+ title: string;
178
+ detail: string;
179
+ change: string;
180
+ skill?: string;
181
+ experiment: string;
182
+ variant?: string;
183
+ evidence: {
184
+ intents: string[];
185
+ numbers: Record<string, number | string>;
186
+ };
187
+ }
188
+ export interface SkillAssessmentReportV1 {
189
+ type: 'ap.skill-assessment-report.v1';
190
+ builtAt: string;
191
+ experiments: ReportExperimentV1[];
192
+ /** One entry per skill: its latest numbers per slate, and the recommendations that name it. */
193
+ skillContracts: Array<{
194
+ skill: string;
195
+ slates: Array<{
196
+ experiment: string;
197
+ variant: string;
198
+ asked: number;
199
+ right: number;
200
+ accuracy: number | null;
201
+ wronglyChosen: number;
202
+ confusedWith: Array<{
203
+ skill: string;
204
+ times: number;
205
+ }>;
206
+ }>;
207
+ recommendations: number;
208
+ }>;
209
+ recommendations: ReportRecommendationV1[];
210
+ /** The comparison the program is working toward, in one sentence each (the headline) — capability slates first,
211
+ * regression slates after, each line saying which it is. */
212
+ headline: string[];
213
+ /** W4 — the same, split by suite kind, so a renderer never pools them. */
214
+ byKind: Record<SuiteKindV1, string[]>;
215
+ /** What each outcome, approach, failure cause and suite kind means, so every renderer says it the same way. */
216
+ glossary: {
217
+ outcomes: typeof OUTCOME_WORDS;
218
+ approaches: typeof VARIANT_WORDS;
219
+ causes: typeof CAUSE_WORDS;
220
+ suites: typeof SUITE_WORDS;
221
+ };
222
+ }
223
+ /** Share of the test sentence's content words that one example also has — 1 is the sentence itself. */
224
+ export declare function exampleOverlap(test: string, example: string): number;
225
+ /** The threshold above which a test sentence counts as carried by the skills it tests (default 0.6). */
226
+ export declare const CONTAMINATION_THRESHOLD = 0.6;
227
+ /** Build the report. `sets` and `criteria` are keyed by the replay-set digest the experiments pre-registered. `examples`
228
+ * are the example sentences the skills under test declare (their `utterances`, as the playbook carries them) — when
229
+ * given, every test sentence that nearly repeats one is flagged, and so is any number resting on it. */
230
+ export declare function skillAssessmentReportOf(input: {
231
+ experiments: readonly ExperimentRecordV1[];
232
+ sets: Record<string, ReplaySetV1>;
233
+ criteria: Record<string, SelectionCriterionV1>;
234
+ examples?: ReadonlyArray<{
235
+ skill: string;
236
+ says: string;
237
+ isNot?: boolean;
238
+ }>;
239
+ now?: string;
240
+ /** Rename a variant IN THE REPORT for one experiment (`{ [experimentId]: { judgment: 'framed-judgment' } }`) — when a
241
+ * knob value's meaning changed after an experiment ran, the report says what actually ran; the record is never edited. */
242
+ aliases?: Record<string, Record<string, string>>;
243
+ /** Tool id → canonical skill id (the playbook's `source`), for reading judges' distributions (risk–coverage). */
244
+ toolToSkill?: Record<string, string>;
245
+ /** The outcome gold per replay-set digest (`ap.outcome-gold.v1` cases) — when given, the PLAN METRICS are computed and
246
+ * reported as diagnostics under the outcome. */
247
+ outcomeGold?: Record<string, Record<string, OutcomeGoldV1>>;
248
+ }): SkillAssessmentReportV1;
249
+ //# sourceMappingURL=report.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../src/report.ts"],"names":[],"mappings":"AAcA,OAAO,EAAwC,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACzH,OAAO,EAAkB,KAAK,kBAAkB,EAAwB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACrH,OAAO,EAAe,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAS/E,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,cAAc,GAAG,WAAW,EAAE,MAAM,CAKpE,CAAC;AACF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAGnD,CAAC;AACF,0HAA0H;AAC1H,eAAO,MAAM,UAAU;;;CAA8C,CAAC;AAEtE,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,kBAAkB,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAS5G,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAA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,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,CAAC;IACrC;qDACiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAA;CAAE,GAAG,uBAAuB,CAiIxF"}
package/dist/report.js ADDED
@@ -0,0 +1,363 @@
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, outcomePlanScoresOf } from './selection-gates.js';
16
+ import { failureSplitOf } from './experiment.js';
17
+ import { suiteKindOf } from './replay.js';
18
+ // WHAT CHANGED ON 2026-10-14 ("evals article gap", W1/W4). Every number here is now INTERPRETABLE on its own: a variant
19
+ // says how many runs produced no verdict and WHY (agent · grader · environment · isolation), so an estate outage never
20
+ // reads as an agent miss; an experiment says what KIND of suite it ran (capability vs regression), so a saturated
21
+ // regression number is never quoted as a capability; each case carries pass@1 AND pass^k (every repeat right), so
22
+ // consistency is a number beside accuracy; and the OUTCOME (state check, then the judge) stands above the plan metrics,
23
+ // which stay computed and are reported as diagnostics. The glossary says each of these in words.
24
+ export const CAUSE_WORDS = {
25
+ agent: 'the agent produced no verdict for a reason the harness owns (counted against it)',
26
+ grader: 'the judge failed — timed out, errored or answered unreadably; the instrument, not the subject (not counted against the agent)',
27
+ environment: 'the estate failed — a store, a provider, a timeout, a trace that never landed (not counted against the agent)',
28
+ isolation: 'a repeat refused because it was not a fresh context (recalled turns, or a context id another run already used) — recorded, never scored',
29
+ };
30
+ export const SUITE_WORDS = {
31
+ capability: 'a fresh, hard set written to find out what the harness can do — its number is a capability number',
32
+ regression: 'a saturated set kept to catch a step backwards — a pass is expected and is never published as a capability number',
33
+ };
34
+ /** A capability set that passes this many consecutive experiments at or above this accuracy is flagged for graduation. */
35
+ export const GRADUATION = { consecutive: 3, accuracy: 0.95 };
36
+ export const OUTCOME_WORDS = {
37
+ tp: { label: 'right skill', ok: true, explain: 'the skill that should handle this ask was chosen' },
38
+ 'tp-alt': { label: 'acceptable alternative', ok: null, explain: 'a declared acceptable alternative was chosen (not counted either way)' },
39
+ tn: { label: 'correctly declined', ok: true, explain: 'no skill fits this ask and none was chosen' },
40
+ 'mis-sib': { label: 'chose its sibling', ok: false, explain: 'the declared neighbour of the right skill was chosen instead' },
41
+ 'mis-far': { label: 'chose an unrelated skill', ok: false, explain: 'a skill that is not even the declared neighbour was chosen' },
42
+ miss: { label: 'chose nothing', ok: false, explain: 'a skill fits this ask but none was chosen' },
43
+ spur: { label: 'should have declined', ok: false, explain: 'no skill fits this ask, but one was chosen anyway' },
44
+ undetected: { label: 'could not tell', ok: null, explain: 'the run\'s trace could not be read; excluded from every number' },
45
+ };
46
+ export const VARIANT_WORDS = {
47
+ model: 'the model planner chooses a skill by reading the skills\' descriptions',
48
+ declared: 'a deterministic selector matches the ask against each skill\'s declared example sentences and declines when none fits',
49
+ rules: 'the rule-based planner (routes no instruction skill — a baseline)',
50
+ 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',
51
+ 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',
52
+ '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',
53
+ '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',
54
+ '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',
55
+ '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)',
56
+ };
57
+ const pct = (v) => (v === null || v === undefined ? 'n/a' : `${Math.round(v * 100)}%`);
58
+ const shortSkill = (s) => (s ? s.replace(/^skill:/, '').replace(/^[^/]+\//, '') : 'nothing');
59
+ // ── CONTAMINATION: a test sentence the skills themselves carry as an example measures recall of the example, not
60
+ // selection. Held-out is sacred (§6); this is how the report keeps it so without trusting anyone to remember. ──
61
+ 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(' '));
62
+ const words = (t) => t.toLowerCase().replace(/[’']/g, '').split(/[^a-z0-9]+/).filter((w) => w.length > 2 && !STOP.has(w));
63
+ /** Share of the test sentence's content words that one example also has — 1 is the sentence itself. */
64
+ export function exampleOverlap(test, example) {
65
+ const t = new Set(words(test));
66
+ const e = new Set(words(example));
67
+ if (!t.size)
68
+ return 0;
69
+ let n = 0;
70
+ for (const w of t)
71
+ if (e.has(w))
72
+ n += 1;
73
+ return n / t.size;
74
+ }
75
+ /** The threshold above which a test sentence counts as carried by the skills it tests (default 0.6). */
76
+ export const CONTAMINATION_THRESHOLD = 0.6;
77
+ /** Build the report. `sets` and `criteria` are keyed by the replay-set digest the experiments pre-registered. `examples`
78
+ * are the example sentences the skills under test declare (their `utterances`, as the playbook carries them) — when
79
+ * given, every test sentence that nearly repeats one is flagged, and so is any number resting on it. */
80
+ export function skillAssessmentReportOf(input) {
81
+ const experiments = [];
82
+ const recommendations = [];
83
+ const sorted = [...input.experiments].sort((a, b) => a.startedAt.localeCompare(b.startedAt));
84
+ for (const rec of sorted) {
85
+ const set = input.sets[rec.plan.replaySetDigest];
86
+ const crit = input.criteria[rec.plan.replaySetDigest];
87
+ if (!set || !crit)
88
+ continue;
89
+ const intentById = new Map(set.intents.map((i) => [i.id, i]));
90
+ const variants = [];
91
+ for (const name of Object.keys(rec.plan.variants)) {
92
+ const shown = input.aliases?.[rec.id]?.[name] ?? name;
93
+ const score = rec.scores[name];
94
+ const runs = rec.runs.filter((r) => r.variant === name && r.repeat === 0);
95
+ const allOfVariant = rec.runs.filter((r) => r.variant === name);
96
+ // W4 — pass^k: a case passes^k when EVERY scored repeat passed; null when fewer than two repeats were scored.
97
+ const passKOf = (intentId) => {
98
+ const reps = allOfVariant.filter((r) => r.intentId === intentId && r.status === 'ok' && r.verdict && r.verdict.outcome !== 'undetected');
99
+ if (reps.length < 2)
100
+ return null;
101
+ return reps.every((r) => OUTCOME_WORDS[r.verdict.outcome].ok !== false);
102
+ };
103
+ const intents = runs.map((r) => {
104
+ const it = intentById.get(r.intentId);
105
+ const g = crit.cases[r.intentId];
106
+ const outcome = r.verdict?.outcome ?? 'undetected';
107
+ const w = OUTCOME_WORDS[outcome];
108
+ 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;
109
+ const contaminated = hit && hit.o >= CONTAMINATION_THRESHOLD ? { skill: hit.e.skill, overlap: Number(hit.o.toFixed(2)), isNot: !!hit.e.isNot } : undefined;
110
+ return {
111
+ intentId: r.intentId, message: it?.message ?? '', split: it?.split ?? '', ...(it?.bucket ? { bucket: it.bucket } : {}),
112
+ ...(contaminated ? { contaminated } : {}),
113
+ expected: g?.expected ?? null, chosen: r.verdict?.primary ?? r.selected[0] ?? null, outcome, label: w.label, ok: w.ok,
114
+ ...(it?.notes ? { why: it.notes } : {}), ...(r.ms !== undefined ? { ms: r.ms } : {}),
115
+ ...(r.askMs !== undefined ? { askMs: r.askMs } : {}), ...(r.selectionMs !== undefined ? { selectionMs: r.selectionMs } : {}),
116
+ ...(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 } : {}) } } : {}),
117
+ ...(r.stages && Object.keys(r.stages).length ? { stages: r.stages } : {}),
118
+ ...(r.selection?.chain && (r.selection.chain.length > 1 || r.selection.approach === 'outcome') ? { chain: r.selection.chain } : {}),
119
+ ...(r.selection?.missing?.length ? { missing: r.selection.missing } : {}),
120
+ ...(r.quality ? { quality: r.quality.score } : {}),
121
+ ...(causeOf(r) ? { failureCause: causeOf(r) } : {}),
122
+ ...(rec.plan.repeats > 1 ? { passK: passKOf(r.intentId) } : {}),
123
+ ...(r.outcome ? { delivered: r.outcome.score, ...(r.outcome.basis ? { deliveredBasis: r.outcome.basis } : {}), ...(r.outcome.cantTell ? { cantTell: r.outcome.cantTell } : {}) } : {}),
124
+ ...(r.outcomeAgentPlan ? { deliveredAgentPlan: r.outcomeAgentPlan.score } : {}),
125
+ ...(r.stateCheck ? { stateCheck: r.stateCheck.pass } : {}),
126
+ };
127
+ });
128
+ const agg = score?.aggregate;
129
+ const skillIds = Object.keys(score?.perSkill ?? {});
130
+ const perSkill = skillIds.map((sk) => {
131
+ const ps = score.perSkill[sk];
132
+ const confused = new Map();
133
+ for (const row of intents)
134
+ if (row.expected === sk && row.chosen && row.chosen !== sk && !row.ok)
135
+ confused.set(row.chosen, (confused.get(row.chosen) ?? 0) + 1);
136
+ const wronglyChosen = intents.filter((row) => row.chosen === sk && row.ok === false).length;
137
+ 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) };
138
+ }).sort((a, b) => a.skill.localeCompare(b.skill));
139
+ const split = failureSplitOf(allOfVariant);
140
+ const scoredOutcome = allOfVariant.filter((r) => r.outcome);
141
+ const withK = rec.plan.repeats > 1 ? intents.map((i) => passKOf(i.intentId)).filter((x) => x !== null) : [];
142
+ const bases = new Set(scoredOutcome.map((r) => r.outcome.basis ?? 'agent-plan'));
143
+ const agentPlanScores = allOfVariant.map((r) => r.outcomeAgentPlan?.score).filter((x) => typeof x === 'number');
144
+ const checked = allOfVariant.filter((r) => r.stateCheck);
145
+ const gold = input.outcomeGold?.[rec.plan.replaySetDigest];
146
+ const planRow = gold ? outcomePlanScoresOf(allOfVariant.map((r) => ({ intentId: r.intentId, variant: r.variant, status: r.status, ...(r.selection ? { selection: r.selection } : {}) })), gold).find((x) => x.variant === name) : undefined;
147
+ const v = {
148
+ name: shown, how: VARIANT_WORDS[shown] ?? shown, runs: runs.length,
149
+ n: { runs: allOfVariant.length, scored: allOfVariant.filter((r) => r.status === 'ok' && !r.isolation).length, agent: split.agent ?? 0, grader: split.grader ?? 0, environment: split.environment ?? 0, isolation: split.isolation ?? 0 },
150
+ ...(withK.length ? { passK: { passed: withK.filter(Boolean).length, of: withK.length, k: rec.plan.repeats } } : {}),
151
+ ...(checked.length ? { stateCheck: { pass: checked.filter((r) => r.stateCheck.pass).length, n: checked.length } } : {}),
152
+ ...(scoredOutcome.length ? { outcome: { mean: round3(scoredOutcome.reduce((a, r) => a + r.outcome.score, 0) / scoredOutcome.length), n: scoredOutcome.length, cantTell: scoredOutcome.reduce((a, r) => a + (r.outcome.cantTell ?? 0), 0), basis: bases.size > 1 ? 'mixed' : [...bases][0], ...(agentPlanScores.length ? { agentPlanMean: round3(agentPlanScores.reduce((a, b) => a + b, 0) / agentPlanScores.length) } : {}) } } : {}),
153
+ ...(planRow ? { planMetrics: (({ variant: _v, ...rest }) => rest)(planRow) } : {}),
154
+ macroTa: agg?.macro_ta.value ?? null, macroCi: agg?.macro_ta.ci ?? null, microTa: agg?.micro_ta.value ?? null,
155
+ holdRate: agg && agg.n_negative ? agg.hold_rate.value : null, ...(agg && agg.n_negative ? { holdNum: agg.hold_rate.num, holdDen: agg.hold_rate.den } : {}),
156
+ routingPurity: agg?.routing_purity.value ?? null, collisionContainment: agg?.collision_containment.value ?? null,
157
+ right: intents.filter((r) => r.outcome === 'tp').length, wrong: intents.filter((r) => r.ok === false).length,
158
+ declinedCorrectly: intents.filter((r) => r.outcome === 'tn').length, firedWrongly: intents.filter((r) => r.outcome === 'spur').length,
159
+ gate: rec.verdicts[name] ? { status: rec.verdicts[name].status, reason: rec.verdicts[name].binding_reason } : null,
160
+ intents, perSkill,
161
+ };
162
+ const allRuns = rec.runs.filter((r) => r.variant === name);
163
+ {
164
+ const ms = allRuns.map((r) => r.askMs ?? r.ms).filter((x) => typeof x === 'number').sort((a, b) => a - b);
165
+ const tk = allRuns.map((r) => r.tokens).filter((x) => !!x);
166
+ const mean = (xs) => (xs.length ? Math.round(xs.reduce((a, b) => a + b, 0) / xs.length) : null);
167
+ const sms = allRuns.map((r) => r.selectionMs).filter((x) => typeof x === 'number').sort((a, b) => a - b);
168
+ if (ms.length || tk.length)
169
+ 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,
170
+ 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)),
171
+ unreportedCalls: tk.reduce((n, t) => n + t.unreported, 0) };
172
+ }
173
+ if (input.toolToSkill && allRuns.some((r) => r.selection?.distribution)) {
174
+ const rc = riskCoverageOf({ runs: allRuns, criterion: crit, toolToSkill: input.toolToSkill, fold: (d) => foldAbstentions(d) });
175
+ if (rc.n)
176
+ 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)) })) };
177
+ }
178
+ variants.push(v);
179
+ recommendations.push(...rulesFor(rec, v));
180
+ }
181
+ const comparisons = rec.comparisons.map((c) => {
182
+ const k = c.comparison;
183
+ const words = !k ? `not compared: ${c.error ?? 'a side was not scored'}`
184
+ : `${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' : ''}`;
185
+ 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 };
186
+ });
187
+ experiments.push({ id: rec.id, slate: `${set.id}@${set.version}`, split: rec.plan.split, repeats: rec.plan.repeats, startedAt: rec.startedAt, finishedAt: rec.finishedAt, suiteKind: suiteKindOf(set), variants, comparisons });
188
+ }
189
+ recommendations.push(...repairRules(sorted, experiments));
190
+ // Per skill: the LATEST experiment per slate (and its first variant), plus how many recommendations name the skill.
191
+ const latestBySlate = new Map();
192
+ for (const e of experiments)
193
+ latestBySlate.set(`${e.slate}|${e.split}`, e);
194
+ // CURRENT ADVICE comes from the latest experiment on each slate; what earlier experiments said is history (their
195
+ // numbers stay in `experiments`). A change's effect (R8) is stated on the experiment that measured it.
196
+ const current = new Set([...latestBySlate.values()].map((e) => e.id));
197
+ for (let i = recommendations.length - 1; i >= 0; i--)
198
+ if (!current.has(recommendations[i].experiment))
199
+ recommendations.splice(i, 1);
200
+ const skillMap = new Map();
201
+ for (const e of latestBySlate.values())
202
+ for (const v of e.variants)
203
+ for (const ps of v.perSkill) {
204
+ const entry = skillMap.get(ps.skill) ?? { skill: ps.skill, slates: [], recommendations: 0 };
205
+ entry.slates.push({ experiment: e.id, variant: v.name, asked: ps.asked, right: ps.right, accuracy: ps.accuracy, wronglyChosen: ps.wronglyChosen, confusedWith: ps.confusedWith });
206
+ skillMap.set(ps.skill, entry);
207
+ }
208
+ for (const r of recommendations)
209
+ if (r.skill && skillMap.has(r.skill))
210
+ skillMap.get(r.skill).recommendations += 1;
211
+ const line = (e) => {
212
+ const parts = e.variants.map((v) => {
213
+ const noVerdict = v.n.grader + v.n.environment + v.n.isolation;
214
+ return `${v.name}: ${v.right}/${v.intents.filter((i) => i.expected).length} right skill${v.holdDen ? `, declined ${v.holdNum}/${v.holdDen} it should` : ''}${v.stateCheck ? `, state check ${v.stateCheck.pass}/${v.stateCheck.n}` : ''}${v.outcome ? `, outcome ${v.outcome.mean}${v.outcome.cantTell ? ` (${v.outcome.cantTell} cantTell)` : ''}` : ''}${v.passK ? `, pass^${v.passK.k} ${v.passK.passed}/${v.passK.of}` : ''}${noVerdict ? ` [no verdict: ${[v.n.grader ? `grader ${v.n.grader}` : '', v.n.environment ? `environment ${v.n.environment}` : '', v.n.isolation ? `isolation ${v.n.isolation}` : ''].filter(Boolean).join(', ')}]` : ''}`;
215
+ });
216
+ return `${e.slate} (${e.split}, ${e.suiteKind}) — ${parts.join('; ')}`;
217
+ };
218
+ const byKind = { capability: [], regression: [] };
219
+ for (const e of latestBySlate.values())
220
+ byKind[e.suiteKind].push(line(e));
221
+ const headline = [...byKind.capability, ...byKind.regression];
222
+ 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, byKind, glossary: { outcomes: OUTCOME_WORDS, approaches: VARIANT_WORDS, causes: CAUSE_WORDS, suites: SUITE_WORDS } };
223
+ }
224
+ const round3 = (x) => Math.round(x * 1000) / 1000;
225
+ /** W1 — a run's failure cause as the report names it (isolation is its own word). */
226
+ function causeOf(r) {
227
+ if (r.isolation?.refused)
228
+ return 'isolation';
229
+ if (r.status !== 'ok')
230
+ return r.failureCause ?? (r.status === 'unreadable' ? 'environment' : 'agent');
231
+ if (r.graderError)
232
+ return 'grader';
233
+ return undefined;
234
+ }
235
+ /** The declared recommendation rules over one variant of one experiment. */
236
+ function rulesFor(rec, v) {
237
+ const out = [];
238
+ const base = { experiment: rec.id, variant: v.name };
239
+ // R1 — ABSTENTION: the harness fires a skill on asks it should decline.
240
+ if (v.holdDen && v.holdRate !== null && v.holdRate < (rec.plan.thresholds?.negative_hold_rate ?? 0.95)) {
241
+ const fired = v.intents.filter((i) => i.outcome === 'spur');
242
+ out.push({ rule: 'R1-abstention', severity: 'act', ...base,
243
+ title: `Declines only ${v.holdNum}/${v.holdDen} asks it should (target ≥ ${pct(rec.plan.thresholds?.negative_hold_rate ?? 0.95)})`,
244
+ 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 ? '; …' : ''}.`,
245
+ 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).',
246
+ evidence: { intents: fired.map((i) => i.intentId), numbers: { hold: v.holdRate, declined: v.holdNum ?? 0, of: v.holdDen } } });
247
+ }
248
+ // R2 — ATTRACTOR: one skill charged with ≥ 2 wrong choices.
249
+ const charged = new Map();
250
+ for (const i of v.intents)
251
+ if (i.ok === false && i.chosen)
252
+ charged.set(i.chosen, [...(charged.get(i.chosen) ?? []), i]);
253
+ for (const [skill, rows] of charged)
254
+ if (rows.length >= 2)
255
+ out.push({ rule: 'R2-attractor', severity: 'act', ...base, skill,
256
+ title: `${shortSkill(skill)} is chosen for asks that are not its job (${rows.length}×)`,
257
+ detail: rows.slice(0, 4).map((i) => `“${i.message.slice(0, 80)}${i.message.length > 80 ? '…' : ''}” (${i.label})`).join('; '),
258
+ change: `Narrow ${shortSkill(skill)}'s description and add these as its \`isNot\` examples; if they belong to a sibling, add a hand-off clause.`,
259
+ evidence: { intents: rows.map((i) => i.intentId), numbers: { times: rows.length } } });
260
+ // R3 — CONFUSION: a skill's own asks went to another skill.
261
+ for (const ps of v.perSkill)
262
+ for (const c of ps.confusedWith)
263
+ out.push({ rule: 'R3-confusion', severity: 'act', ...base, skill: ps.skill,
264
+ title: `Asks for ${shortSkill(ps.skill)} went to ${shortSkill(c.skill)} (${c.times}×)`,
265
+ 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('; '),
266
+ 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.`,
267
+ evidence: { intents: v.intents.filter((i) => i.expected === ps.skill && i.chosen === c.skill).map((i) => i.intentId), numbers: { times: c.times } } });
268
+ // R4 — MISSED: a skill fits and nothing was chosen (the declared selector's typical failure).
269
+ const missed = v.intents.filter((i) => i.outcome === 'miss');
270
+ const positives = v.intents.filter((i) => i.expected).length;
271
+ // A variant that selects NO skill at all is a baseline, said once as such — not 24 action items.
272
+ if (missed.length && missed.length === positives && v.right === 0)
273
+ out.push({ rule: 'R4-baseline', severity: 'info', ...base,
274
+ title: `${v.name} selects no skill at all — a baseline, not a candidate`,
275
+ 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 } } });
276
+ else if (missed.length)
277
+ out.push({ rule: 'R4-missed', severity: missed.length >= 3 ? 'act' : 'watch', ...base,
278
+ title: `${missed.length} ask${missed.length === 1 ? '' : 's'} a skill should handle got no skill`,
279
+ detail: missed.slice(0, 4).map((i) => `“${i.message.slice(0, 80)}${i.message.length > 80 ? '…' : ''}” → should be ${shortSkill(i.expected)}`).join('; '),
280
+ 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.',
281
+ evidence: { intents: missed.map((i) => i.intentId), numbers: { missed: missed.length } } });
282
+ // R0 — CONTAMINATION: test sentences the skills carry as their own examples. Said first: every other number on this
283
+ // variant rests partly on them.
284
+ const leaked = v.intents.filter((i) => i.contaminated);
285
+ if (leaked.length)
286
+ out.push({ rule: 'R0-contamination', severity: 'act', ...base,
287
+ title: `${leaked.length} of ${v.intents.length} test sentences are (nearly) the skills' own examples — their results do not measure selection`,
288
+ 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('; '),
289
+ 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.',
290
+ evidence: { intents: leaked.map((i) => i.intentId), numbers: { contaminated: leaked.length, of: v.intents.length } } });
291
+ // R5 — TOO FEW CASES to gate: per-skill intervals this wide cannot clear a floor.
292
+ const asked = v.perSkill.map((p) => p.asked).filter((n) => n > 0);
293
+ if (asked.length && Math.max(...asked) < 10)
294
+ out.push({ rule: 'R5-sample-size', severity: 'info', ...base,
295
+ title: `Too few cases per skill to pass or fail a skill (${Math.min(...asked)}–${Math.max(...asked)} each)`,
296
+ 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.`,
297
+ 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.',
298
+ evidence: { intents: [], numbers: { minPerSkill: Math.min(...asked), maxPerSkill: Math.max(...asked) } } });
299
+ return out;
300
+ }
301
+ /** Rules over PAIRS of experiments on the same slate: what a change did. */
302
+ function repairRules(sorted, reports) {
303
+ const out = [];
304
+ for (const e of reports)
305
+ for (const c of e.comparisons) {
306
+ if (c.confounded)
307
+ 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: {} } });
308
+ if (c.broken > 0 && c.p !== null)
309
+ 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 } } });
310
+ }
311
+ // Across experiments on the same slate+split (e.g. the NOT-for repair): same variant name, before → after.
312
+ const bySlate = new Map();
313
+ for (const e of reports)
314
+ bySlate.set(`${e.slate}|${e.split}`, [...(bySlate.get(`${e.slate}|${e.split}`) ?? []), e]);
315
+ // R9 — GRADUATION (W4): a CAPABILITY slate a variant has passed in its last three consecutive experiments at ≥ 95% is
316
+ // saturated for that variant — it has stopped measuring capability and should become a regression suite (and a fresh,
317
+ // harder set should take its place). Said once, on the latest experiment; a regression slate is never flagged.
318
+ for (const list of bySlate.values()) {
319
+ const latest = list[list.length - 1];
320
+ if (latest.suiteKind !== 'capability' || list.length < GRADUATION.consecutive)
321
+ continue;
322
+ for (const v of latest.variants) {
323
+ const tail = list.slice(-GRADUATION.consecutive).map((e) => e.variants.find((x) => x.name === v.name)?.microTa ?? null);
324
+ if (tail.every((x) => x !== null && x >= GRADUATION.accuracy))
325
+ out.push({ rule: 'R9-graduate', severity: 'info', experiment: latest.id, variant: v.name,
326
+ title: `${latest.slate} is saturated for ${v.name}: ≥ ${pct(GRADUATION.accuracy)} on ${GRADUATION.consecutive} consecutive runs`,
327
+ detail: `micro accuracy ${tail.map((x) => pct(x)).join(', ')} over ${list.slice(-GRADUATION.consecutive).map((e) => e.id).join(', ')}.`,
328
+ change: 'Mark the set `suiteKind: regression` (its pass is now expected, not a capability number) and write a fresh, harder capability set in its place.',
329
+ evidence: { intents: [], numbers: { consecutive: GRADUATION.consecutive, floor: GRADUATION.accuracy, latest: tail[tail.length - 1] ?? 0 } } });
330
+ }
331
+ }
332
+ for (const list of bySlate.values())
333
+ for (let i = 1; i < list.length; i++) {
334
+ const before = list[i - 1], after = list[i];
335
+ for (const v of after.variants) {
336
+ const pv = before.variants.find((x) => x.name === v.name);
337
+ if (!pv)
338
+ continue;
339
+ const prev = new Map(pv.intents.map((x) => [x.intentId, x]));
340
+ const fixed = v.intents.filter((x) => x.ok === true && prev.get(x.intentId)?.ok === false);
341
+ const broken = v.intents.filter((x) => x.ok === false && prev.get(x.intentId)?.ok === true);
342
+ if (!fixed.length && !broken.length)
343
+ continue;
344
+ out.push({ rule: 'R8-change-effect', severity: broken.length > fixed.length ? 'act' : 'info', experiment: after.id, variant: v.name,
345
+ title: `Since ${before.id}: ${fixed.length} fixed, ${broken.length} broken (${v.name})`,
346
+ 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('; '),
347
+ 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.',
348
+ evidence: { intents: [...fixed, ...broken].map((x) => x.intentId), numbers: { fixed: fixed.length, broken: broken.length } } });
349
+ }
350
+ }
351
+ void sorted;
352
+ return out;
353
+ }
354
+ /** Keep at most `max` points of a curve, always the first and the last (the chart needs the shape, not every run). */
355
+ function thin(xs, max) {
356
+ if (xs.length <= max)
357
+ return [...xs];
358
+ const out = [];
359
+ for (let i = 0; i < max; i++)
360
+ out.push(xs[Math.round((i * (xs.length - 1)) / (max - 1))]);
361
+ return out;
362
+ }
363
+ //# sourceMappingURL=report.js.map