@agenticprimitives/evaluation 0.0.0-alpha.4 → 0.0.0-alpha.5
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/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/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 +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -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 +64 -0
- package/dist/rollup.d.ts.map +1 -0
- package/dist/rollup.js +53 -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/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 +1 -1
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import type { ExperimentRecordV1 } from './experiment.js';
|
|
2
|
+
import type { SelectionCriterionV1 } from './selection.js';
|
|
3
|
+
/** What the runner keeps from a run's `plannerTrace.selection` — ids, class IRIs and numbers; never words. */
|
|
4
|
+
export interface RunSelectionFactsV1 {
|
|
5
|
+
approach: string;
|
|
6
|
+
chose: string | null;
|
|
7
|
+
hold?: string;
|
|
8
|
+
/** Ontology arm (or the composed arm's narrowing): the grounded classes, the survivors, excluded skills, how reached. */
|
|
9
|
+
grounded?: string[];
|
|
10
|
+
survivors?: string[];
|
|
11
|
+
excluded?: string[];
|
|
12
|
+
via?: string;
|
|
13
|
+
/** spec 416 propose+judgment: the proposed skills (in proposal order) and how each was proposed. `excluded` holds the vetoed. */
|
|
14
|
+
proposed?: string[];
|
|
15
|
+
proposedVia?: Record<string, string>;
|
|
16
|
+
/** The proposal's parameters as recorded — re-derivation runs under the rule the run ran under. */
|
|
17
|
+
proposalParams?: Record<string, unknown>;
|
|
18
|
+
/** Judgment arm (or the composed arm's judge): the slate it was offered and its distribution (`none` included). */
|
|
19
|
+
offered?: string[];
|
|
20
|
+
distribution?: Record<string, number>;
|
|
21
|
+
/** Spec 417 — the outcome arm: the chain of skills in run order (the outcome's last), the consumed classes named
|
|
22
|
+
* missing, and P(the request supplies it) per consumed class. Any other arm's chain is its one choice. */
|
|
23
|
+
chain?: string[];
|
|
24
|
+
missing?: string[];
|
|
25
|
+
supplied?: Record<string, number>;
|
|
26
|
+
}
|
|
27
|
+
/** Reduce a planner trace's `selection` to the facts the gates need. */
|
|
28
|
+
export declare function runSelectionFactsOf(sel: unknown): RunSelectionFactsV1 | undefined;
|
|
29
|
+
/** Gold for an outcome request: the skills to run, in order ([] = none of them), and — optionally — the consumed classes
|
|
30
|
+
* the right plan names missing (to be asked for). */
|
|
31
|
+
export interface OutcomeGoldV1 {
|
|
32
|
+
plan: string[];
|
|
33
|
+
missing?: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface OutcomePlanScoreV1 {
|
|
36
|
+
variant: string;
|
|
37
|
+
n: number;
|
|
38
|
+
/** The run's chain equals the gold plan, in order. */
|
|
39
|
+
exact: number;
|
|
40
|
+
/** Runs with a step the gold plan does not have (a needless step — context should have removed it). */
|
|
41
|
+
needless: number;
|
|
42
|
+
/** Runs missing a step the gold plan has (the chain stopped short). */
|
|
43
|
+
short: number;
|
|
44
|
+
/** Of the runs whose gold names missing classes: those whose plan named every one. */
|
|
45
|
+
asked: {
|
|
46
|
+
of: number;
|
|
47
|
+
right: number;
|
|
48
|
+
};
|
|
49
|
+
/** Where the gold plan is one step vs longer — whether the chain helps or hurts each. */
|
|
50
|
+
bySteps: Record<string, {
|
|
51
|
+
n: number;
|
|
52
|
+
exact: number;
|
|
53
|
+
}>;
|
|
54
|
+
/** Spec 418 — the STEPS SCORE (graphrag-eval style): mean of 1 − edit distance / max(len(gold), len(run)) over ok runs —
|
|
55
|
+
* partial credit for a chain one step off, 1 for exact, 0 for a wholly different plan; an empty gold scores 1 only for an empty run. */
|
|
56
|
+
stepsScore: number;
|
|
57
|
+
}
|
|
58
|
+
/** Levenshtein distance over skill ids. */
|
|
59
|
+
export declare function planEditDistance(a: readonly string[], b: readonly string[]): number;
|
|
60
|
+
export declare const stepsScoreOf: (run: readonly string[], gold: readonly string[]) => number;
|
|
61
|
+
/** Score each variant's chains against the gold plans. Failed runs count against `n` (never silently dropped). */
|
|
62
|
+
export declare function outcomePlanScoresOf(runs: ReadonlyArray<{
|
|
63
|
+
intentId: string;
|
|
64
|
+
variant: string;
|
|
65
|
+
status: string;
|
|
66
|
+
selection?: RunSelectionFactsV1;
|
|
67
|
+
}>, gold: Record<string, OutcomeGoldV1>): OutcomePlanScoreV1[];
|
|
68
|
+
/** Structurally orchestration's `decideFromGrounding`. */
|
|
69
|
+
export type DecideFromGrounding = (grounded: readonly string[], candidates: ReadonlyArray<{
|
|
70
|
+
id: string;
|
|
71
|
+
covers: ReadonlyArray<{
|
|
72
|
+
iri: string;
|
|
73
|
+
label: string;
|
|
74
|
+
}>;
|
|
75
|
+
excludes?: ReadonlyArray<{
|
|
76
|
+
iri: string;
|
|
77
|
+
label: string;
|
|
78
|
+
}>;
|
|
79
|
+
}>, lexicon?: ReadonlyArray<{
|
|
80
|
+
iri: string;
|
|
81
|
+
label: string;
|
|
82
|
+
terms: readonly string[];
|
|
83
|
+
clusters: readonly string[];
|
|
84
|
+
}>) => {
|
|
85
|
+
chose: string | null;
|
|
86
|
+
survivors: string[];
|
|
87
|
+
excluded: Record<string, string[]>;
|
|
88
|
+
via?: string;
|
|
89
|
+
};
|
|
90
|
+
/** Structurally orchestration's `proposeFromGrounding` (spec 416 W1). */
|
|
91
|
+
export type ProposeFromGrounding = (grounded: readonly string[], candidates: ReadonlyArray<{
|
|
92
|
+
id: string;
|
|
93
|
+
covers: ReadonlyArray<{
|
|
94
|
+
iri: string;
|
|
95
|
+
label: string;
|
|
96
|
+
}>;
|
|
97
|
+
excludes?: ReadonlyArray<{
|
|
98
|
+
iri: string;
|
|
99
|
+
label: string;
|
|
100
|
+
}>;
|
|
101
|
+
}>, lexicon?: ReadonlyArray<{
|
|
102
|
+
iri: string;
|
|
103
|
+
label: string;
|
|
104
|
+
terms: readonly string[];
|
|
105
|
+
clusters: readonly string[];
|
|
106
|
+
}>, params?: Record<string, unknown>) => {
|
|
107
|
+
candidates: string[];
|
|
108
|
+
via: Record<string, string>;
|
|
109
|
+
removed: Record<string, string[]>;
|
|
110
|
+
};
|
|
111
|
+
export interface RboxDisagreementV1 {
|
|
112
|
+
intentId: string;
|
|
113
|
+
variant: string;
|
|
114
|
+
repeat: number;
|
|
115
|
+
field: 'chose' | 'survivors' | 'excluded' | 'via' | 'proposed';
|
|
116
|
+
recorded: unknown;
|
|
117
|
+
derived: unknown;
|
|
118
|
+
}
|
|
119
|
+
export interface RboxReportV1 {
|
|
120
|
+
gate: 'rbox-agreement';
|
|
121
|
+
status: 'PASS' | 'FAIL' | 'INCOMPLETE';
|
|
122
|
+
checked: number;
|
|
123
|
+
agreed: number;
|
|
124
|
+
disagreements: RboxDisagreementV1[];
|
|
125
|
+
reason: string;
|
|
126
|
+
}
|
|
127
|
+
export declare function rboxAgreementOf(input: {
|
|
128
|
+
experiment: Pick<ExperimentRecordV1, 'runs'>;
|
|
129
|
+
/** The compiled playbook the runs ran under. */
|
|
130
|
+
definition: {
|
|
131
|
+
tools: ReadonlyArray<{
|
|
132
|
+
id: string;
|
|
133
|
+
execution?: string;
|
|
134
|
+
covers?: ReadonlyArray<{
|
|
135
|
+
iri: string;
|
|
136
|
+
label: string;
|
|
137
|
+
}>;
|
|
138
|
+
excludes?: ReadonlyArray<{
|
|
139
|
+
iri: string;
|
|
140
|
+
label: string;
|
|
141
|
+
}>;
|
|
142
|
+
}>;
|
|
143
|
+
domainLexicon?: ReadonlyArray<{
|
|
144
|
+
iri: string;
|
|
145
|
+
label: string;
|
|
146
|
+
terms: readonly string[];
|
|
147
|
+
clusters: readonly string[];
|
|
148
|
+
}>;
|
|
149
|
+
};
|
|
150
|
+
decide: DecideFromGrounding;
|
|
151
|
+
/** Re-derives a `propose+judgment` run's proposal; without it those runs are not checked (and not counted). */
|
|
152
|
+
propose?: ProposeFromGrounding;
|
|
153
|
+
}): RboxReportV1;
|
|
154
|
+
/** The abstaining outcomes of a selection judge: none of the skills, ask the person, needs several skills. */
|
|
155
|
+
export declare const ABSTENTION_OUTCOMES: readonly string[];
|
|
156
|
+
/** Map a judge's distribution onto canonical skill ids + `none`, summing the abstentions into `none`. */
|
|
157
|
+
export declare function foldAbstentions(dist: Record<string, number>, toolToSkill?: Record<string, string>): Record<string, number>;
|
|
158
|
+
export interface CalibrationBinV1 {
|
|
159
|
+
lo: number;
|
|
160
|
+
hi: number;
|
|
161
|
+
n: number;
|
|
162
|
+
confidence: number | null;
|
|
163
|
+
accuracy: number | null;
|
|
164
|
+
}
|
|
165
|
+
export interface CalibrationReportV1 {
|
|
166
|
+
gate: 'judgment-calibration';
|
|
167
|
+
status: 'PASS' | 'FAIL' | 'INCOMPLETE';
|
|
168
|
+
n: number;
|
|
169
|
+
accuracy: number | null;
|
|
170
|
+
meanConfidence: number | null;
|
|
171
|
+
brier: number | null;
|
|
172
|
+
ece: number | null;
|
|
173
|
+
bins: CalibrationBinV1[];
|
|
174
|
+
overconfident: Array<{
|
|
175
|
+
intentId: string;
|
|
176
|
+
variant: string;
|
|
177
|
+
predicted: string;
|
|
178
|
+
p: number;
|
|
179
|
+
gold: string;
|
|
180
|
+
}>;
|
|
181
|
+
thresholds: CalibrationThresholdsV1;
|
|
182
|
+
reason: string;
|
|
183
|
+
}
|
|
184
|
+
export interface CalibrationThresholdsV1 {
|
|
185
|
+
minRuns: number;
|
|
186
|
+
eceMax: number;
|
|
187
|
+
brierMax: number;
|
|
188
|
+
}
|
|
189
|
+
export declare const DEFAULT_CALIBRATION_THRESHOLDS: CalibrationThresholdsV1;
|
|
190
|
+
/** `toolToSkill` maps a distribution key (a tool id) to the canonical skill id the criterion names. */
|
|
191
|
+
export declare function judgmentCalibrationOf(input: {
|
|
192
|
+
experiment: Pick<ExperimentRecordV1, 'runs'>;
|
|
193
|
+
criterion: Pick<SelectionCriterionV1, 'cases'>;
|
|
194
|
+
toolToSkill: Record<string, string>;
|
|
195
|
+
thresholds?: Partial<CalibrationThresholdsV1>;
|
|
196
|
+
}): CalibrationReportV1;
|
|
197
|
+
export interface ConsistencyThresholdsV1 {
|
|
198
|
+
minGroups: number;
|
|
199
|
+
agreementMin: number;
|
|
200
|
+
spreadMax: number;
|
|
201
|
+
}
|
|
202
|
+
export declare const DEFAULT_CONSISTENCY_THRESHOLDS: ConsistencyThresholdsV1;
|
|
203
|
+
export interface ConsistencyReportV1 {
|
|
204
|
+
gate: 'judgment-consistency';
|
|
205
|
+
status: 'PASS' | 'FAIL' | 'INCOMPLETE';
|
|
206
|
+
groups: number;
|
|
207
|
+
agreement: number | null;
|
|
208
|
+
spread: number | null;
|
|
209
|
+
unstable: Array<{
|
|
210
|
+
intentId: string;
|
|
211
|
+
variant: string;
|
|
212
|
+
tops: string[];
|
|
213
|
+
}>;
|
|
214
|
+
thresholds: ConsistencyThresholdsV1;
|
|
215
|
+
reason: string;
|
|
216
|
+
}
|
|
217
|
+
export declare function judgmentConsistencyOf(input: {
|
|
218
|
+
experiment: Pick<ExperimentRecordV1, 'runs'>;
|
|
219
|
+
thresholds?: Partial<ConsistencyThresholdsV1>;
|
|
220
|
+
}): ConsistencyReportV1;
|
|
221
|
+
export interface CandidateRecallThresholdsV1 {
|
|
222
|
+
minRuns: number;
|
|
223
|
+
recallMin: number;
|
|
224
|
+
}
|
|
225
|
+
export declare const DEFAULT_CANDIDATE_RECALL_THRESHOLDS: CandidateRecallThresholdsV1;
|
|
226
|
+
export interface CandidateRecallReportV1 {
|
|
227
|
+
gate: 'candidate-recall';
|
|
228
|
+
status: 'PASS' | 'FAIL' | 'INCOMPLETE';
|
|
229
|
+
n: number;
|
|
230
|
+
recall: number | null;
|
|
231
|
+
meanProposed: number | null;
|
|
232
|
+
/** How the gold skill was proposed, when it was (direct · neighbourhood · catalog). */
|
|
233
|
+
byVia: Record<string, number>;
|
|
234
|
+
missed: Array<{
|
|
235
|
+
intentId: string;
|
|
236
|
+
variant: string;
|
|
237
|
+
gold: string;
|
|
238
|
+
}>;
|
|
239
|
+
thresholds: CandidateRecallThresholdsV1;
|
|
240
|
+
reason: string;
|
|
241
|
+
}
|
|
242
|
+
export declare function candidateRecallOf(input: {
|
|
243
|
+
experiment: Pick<ExperimentRecordV1, 'runs'>;
|
|
244
|
+
criterion: Pick<SelectionCriterionV1, 'cases'>;
|
|
245
|
+
toolToSkill: Record<string, string>;
|
|
246
|
+
thresholds?: Partial<CandidateRecallThresholdsV1>;
|
|
247
|
+
}): CandidateRecallReportV1;
|
|
248
|
+
export type BehaviourOutcomeV1 = 'asked' | 'planned' | 'crossed' | 'declined' | 'guessed';
|
|
249
|
+
export interface BehaviourThresholdsV1 {
|
|
250
|
+
minCases: number;
|
|
251
|
+
rightMin: number;
|
|
252
|
+
overAskMax: number;
|
|
253
|
+
}
|
|
254
|
+
export declare const DEFAULT_BEHAVIOUR_THRESHOLDS: BehaviourThresholdsV1;
|
|
255
|
+
export interface BehaviourReportV1 {
|
|
256
|
+
gate: 'selection-behaviour';
|
|
257
|
+
status: 'PASS' | 'FAIL' | 'INCOMPLETE';
|
|
258
|
+
n: number;
|
|
259
|
+
right: number | null;
|
|
260
|
+
counts: Record<BehaviourOutcomeV1, number>;
|
|
261
|
+
byBehaviour: Record<'clarify' | 'several', {
|
|
262
|
+
n: number;
|
|
263
|
+
right: number;
|
|
264
|
+
}>;
|
|
265
|
+
positives: number;
|
|
266
|
+
overAsked: number;
|
|
267
|
+
overAskRate: number | null;
|
|
268
|
+
wrong: Array<{
|
|
269
|
+
intentId: string;
|
|
270
|
+
variant: string;
|
|
271
|
+
behaviour: string;
|
|
272
|
+
outcome: BehaviourOutcomeV1;
|
|
273
|
+
chose: string | null;
|
|
274
|
+
}>;
|
|
275
|
+
thresholds: BehaviourThresholdsV1;
|
|
276
|
+
reason: string;
|
|
277
|
+
}
|
|
278
|
+
export declare function selectionBehaviourOf(input: {
|
|
279
|
+
experiment: Pick<ExperimentRecordV1, 'runs'>;
|
|
280
|
+
criterion: Pick<SelectionCriterionV1, 'cases'>;
|
|
281
|
+
thresholds?: Partial<BehaviourThresholdsV1>;
|
|
282
|
+
}): BehaviourReportV1;
|
|
283
|
+
//# sourceMappingURL=selection-gates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection-gates.d.ts","sourceRoot":"","sources":["../src/selection-gates.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,iBAAiB,CAAC;AAC3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,8GAA8G;AAC9G,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yHAAyH;IACzH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iIAAiI;IACjI,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,mGAAmG;IACnG,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,mHAAmH;IACnH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC;+GAC2G;IAC3G,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,mBAAmB,GAAG,SAAS,CAqBjF;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,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAA;CAAE,GAAG,iBAAiB,CAgC5M"}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/** Reduce a planner trace's `selection` to the facts the gates need. */
|
|
2
|
+
export function runSelectionFactsOf(sel) {
|
|
3
|
+
const s = sel;
|
|
4
|
+
if (!s || typeof s.approach !== 'string')
|
|
5
|
+
return undefined;
|
|
6
|
+
const onto = (s.approach === 'ontology+judgment' || s.approach === 'ontology-first' ? s.ontology : s);
|
|
7
|
+
const judge = (s.approach === 'ontology+judgment' || s.approach === 'propose+judgment' || s.approach === 'ontology-first' ? s.judgment : s);
|
|
8
|
+
const prop = (s.approach === 'propose+judgment' ? s.proposal : undefined);
|
|
9
|
+
const iris = (v) => (Array.isArray(v) ? v.map((g) => (typeof g === 'string' ? g : String(g.iri ?? ''))).filter(Boolean) : undefined);
|
|
10
|
+
return {
|
|
11
|
+
approach: s.approach, chose: typeof s.chose === 'string' ? s.chose : null, ...(typeof s.hold === 'string' ? { hold: s.hold } : {}),
|
|
12
|
+
...(onto && Array.isArray(onto.grounded) ? { grounded: iris(onto.grounded) } : {}),
|
|
13
|
+
...(onto && Array.isArray(onto.survivors) ? { survivors: onto.survivors.slice() } : {}),
|
|
14
|
+
...(onto && onto.excluded && typeof onto.excluded === 'object' ? { excluded: Object.keys(onto.excluded).sort() } : {}),
|
|
15
|
+
...(onto && typeof onto.via === 'string' ? { via: onto.via } : {}),
|
|
16
|
+
...(prop && Array.isArray(prop.candidates) ? { proposed: prop.candidates.slice() } : {}),
|
|
17
|
+
...(prop && prop.via && typeof prop.via === 'object' ? { proposedVia: { ...prop.via } } : {}),
|
|
18
|
+
...(prop && prop.params && typeof prop.params === 'object' ? { proposalParams: { ...(prop.params) } } : {}),
|
|
19
|
+
...(prop && prop.removed && typeof prop.removed === 'object' ? { excluded: Object.keys(prop.removed).sort() } : {}),
|
|
20
|
+
...(judge && Array.isArray(judge.offered) ? { offered: judge.offered.slice() } : {}),
|
|
21
|
+
...(judge && judge.distribution && typeof judge.distribution === 'object' ? { distribution: { ...judge.distribution } } : {}),
|
|
22
|
+
...outcomeFactsOf(s),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function outcomeFactsOf(s) {
|
|
26
|
+
const plan = s.plan;
|
|
27
|
+
const chain = plan && Array.isArray(plan.steps) ? plan.steps.map((x) => String(x.tool ?? '')).filter(Boolean) : typeof s.chose === 'string' ? [s.chose] : undefined;
|
|
28
|
+
return {
|
|
29
|
+
...(chain ? { chain } : {}),
|
|
30
|
+
...(plan && Array.isArray(plan.missing) ? { missing: plan.missing.slice() } : {}),
|
|
31
|
+
...(s.supplied && typeof s.supplied === 'object' ? { supplied: { ...s.supplied } } : {}),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Levenshtein distance over skill ids. */
|
|
35
|
+
export function planEditDistance(a, b) {
|
|
36
|
+
const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
|
|
37
|
+
for (let j = 1; j <= b.length; j++)
|
|
38
|
+
d[0][j] = j;
|
|
39
|
+
for (let i = 1; i <= a.length; i++)
|
|
40
|
+
for (let j = 1; j <= b.length; j++)
|
|
41
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
42
|
+
return d[a.length][b.length];
|
|
43
|
+
}
|
|
44
|
+
export const stepsScoreOf = (run, gold) => (!run.length && !gold.length ? 1 : 1 - planEditDistance(run, gold) / Math.max(run.length, gold.length));
|
|
45
|
+
/** Score each variant's chains against the gold plans. Failed runs count against `n` (never silently dropped). */
|
|
46
|
+
export function outcomePlanScoresOf(runs, gold) {
|
|
47
|
+
const by = new Map();
|
|
48
|
+
for (const r of runs) {
|
|
49
|
+
const g = gold[r.intentId];
|
|
50
|
+
if (!g)
|
|
51
|
+
continue;
|
|
52
|
+
const row = by.get(r.variant) ?? { variant: r.variant, n: 0, exact: 0, needless: 0, short: 0, asked: { of: 0, right: 0 }, bySteps: {}, stepsScore: 0 };
|
|
53
|
+
row.__steps ??= [];
|
|
54
|
+
by.set(r.variant, row);
|
|
55
|
+
row.n++;
|
|
56
|
+
const k = g.plan.length > 1 ? 'chain' : g.plan.length === 1 ? 'one' : 'none';
|
|
57
|
+
const b = (row.bySteps[k] ??= { n: 0, exact: 0 });
|
|
58
|
+
b.n++;
|
|
59
|
+
if (g.missing?.length)
|
|
60
|
+
row.asked.of++;
|
|
61
|
+
if (r.status !== 'ok')
|
|
62
|
+
continue;
|
|
63
|
+
const chain = r.selection?.chain ?? [];
|
|
64
|
+
row.__steps.push(stepsScoreOf(chain, g.plan));
|
|
65
|
+
const exact = chain.length === g.plan.length && chain.every((t, i) => t === g.plan[i]);
|
|
66
|
+
if (exact) {
|
|
67
|
+
row.exact++;
|
|
68
|
+
b.exact++;
|
|
69
|
+
}
|
|
70
|
+
if (chain.some((t) => !g.plan.includes(t)))
|
|
71
|
+
row.needless++;
|
|
72
|
+
if (g.plan.some((t) => !chain.includes(t)))
|
|
73
|
+
row.short++;
|
|
74
|
+
if (g.missing?.length && g.missing.every((c) => r.selection?.missing?.includes(c)))
|
|
75
|
+
row.asked.right++;
|
|
76
|
+
}
|
|
77
|
+
return [...by.values()].map((row) => { const xs = row.__steps ?? []; const { __steps: _drop, ...rest } = row; return { ...rest, stepsScore: xs.length ? Number((xs.reduce((a, b) => a + b, 0) / row.n).toFixed(4)) : 0 }; }).sort((a, b) => a.variant.localeCompare(b.variant));
|
|
78
|
+
}
|
|
79
|
+
export function rboxAgreementOf(input) {
|
|
80
|
+
const candidates = input.definition.tools.filter((t) => t.execution === 'instruction').map((t) => ({ id: t.id, covers: t.covers ?? [], ...(t.excludes?.length ? { excludes: t.excludes } : {}) }));
|
|
81
|
+
const disagreements = [];
|
|
82
|
+
let checked = 0, agreed = 0;
|
|
83
|
+
for (const r of input.experiment.runs) {
|
|
84
|
+
const f = r.selection;
|
|
85
|
+
if (f && f.grounded && f.approach === 'propose+judgment' && input.propose) {
|
|
86
|
+
checked++;
|
|
87
|
+
// A proposal recorded before the veto rule was a parameter ran under `any` (spec 416 W1, first run).
|
|
88
|
+
const d = input.propose(f.grounded, candidates, input.definition.domainLexicon, { veto: 'any', ...(f.proposalParams ?? {}) });
|
|
89
|
+
const at = { intentId: r.intentId, variant: r.variant, repeat: r.repeat };
|
|
90
|
+
const diff = [];
|
|
91
|
+
// Order matters: the proposal's order is part of what it says (direct → neighbourhood → catalog).
|
|
92
|
+
if (JSON.stringify(f.proposed ?? []) !== JSON.stringify(d.candidates))
|
|
93
|
+
diff.push({ ...at, field: 'proposed', recorded: f.proposed ?? [], derived: d.candidates });
|
|
94
|
+
if (JSON.stringify(f.excluded ?? []) !== JSON.stringify(Object.keys(d.removed).sort()))
|
|
95
|
+
diff.push({ ...at, field: 'excluded', recorded: f.excluded ?? [], derived: Object.keys(d.removed).sort() });
|
|
96
|
+
if (diff.length)
|
|
97
|
+
disagreements.push(...diff);
|
|
98
|
+
else
|
|
99
|
+
agreed++;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (!f || !f.grounded || (f.approach !== 'ontology' && f.approach !== 'ontology+judgment' && f.approach !== 'ontology-first'))
|
|
103
|
+
continue;
|
|
104
|
+
checked++;
|
|
105
|
+
const d = input.decide(f.grounded, candidates, input.definition.domainLexicon);
|
|
106
|
+
const diff = [];
|
|
107
|
+
const at = { intentId: r.intentId, variant: r.variant, repeat: r.repeat };
|
|
108
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
109
|
+
if (f.approach === 'ontology' && !same(f.chose, d.chose))
|
|
110
|
+
diff.push({ ...at, field: 'chose', recorded: f.chose, derived: d.chose });
|
|
111
|
+
if (f.survivors && !same([...f.survivors].sort(), [...d.survivors].sort()))
|
|
112
|
+
diff.push({ ...at, field: 'survivors', recorded: f.survivors, derived: d.survivors });
|
|
113
|
+
if (f.excluded && !same(f.excluded, Object.keys(d.excluded).sort()))
|
|
114
|
+
diff.push({ ...at, field: 'excluded', recorded: f.excluded, derived: Object.keys(d.excluded).sort() });
|
|
115
|
+
if ((f.via ?? null) !== (d.via ?? null))
|
|
116
|
+
diff.push({ ...at, field: 'via', recorded: f.via ?? null, derived: d.via ?? null });
|
|
117
|
+
if (diff.length)
|
|
118
|
+
disagreements.push(...diff);
|
|
119
|
+
else
|
|
120
|
+
agreed++;
|
|
121
|
+
}
|
|
122
|
+
const status = checked === 0 ? 'INCOMPLETE' : disagreements.length ? 'FAIL' : 'PASS';
|
|
123
|
+
const reason = checked === 0 ? 'no run recorded an ontology decision with its grounding' : disagreements.length ? `${checked - agreed} of ${checked} ontology decisions do not re-derive from their recorded grounding` : `all ${checked} ontology decisions re-derive from their recorded grounding`;
|
|
124
|
+
return { gate: 'rbox-agreement', status, checked, agreed, disagreements, reason };
|
|
125
|
+
}
|
|
126
|
+
// ── judgment calibration ──
|
|
127
|
+
/** The abstaining outcomes of a selection judge: none of the skills, ask the person, needs several skills. */
|
|
128
|
+
export const ABSTENTION_OUTCOMES = ['none', 'clarify', 'several'];
|
|
129
|
+
/** Map a judge's distribution onto canonical skill ids + `none`, summing the abstentions into `none`. */
|
|
130
|
+
export function foldAbstentions(dist, toolToSkill = {}) {
|
|
131
|
+
const out = {};
|
|
132
|
+
for (const [k, v] of Object.entries(dist)) {
|
|
133
|
+
const f = ABSTENTION_OUTCOMES.includes(k) ? 'none' : toolToSkill[k] ?? k;
|
|
134
|
+
out[f] = (out[f] ?? 0) + v;
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
export const DEFAULT_CALIBRATION_THRESHOLDS = { minRuns: 20, eceMax: 0.1, brierMax: 0.25 };
|
|
139
|
+
/** `toolToSkill` maps a distribution key (a tool id) to the canonical skill id the criterion names. */
|
|
140
|
+
export function judgmentCalibrationOf(input) {
|
|
141
|
+
const th = { ...DEFAULT_CALIBRATION_THRESHOLDS, ...input.thresholds };
|
|
142
|
+
const rows = [];
|
|
143
|
+
for (const r of input.experiment.runs) {
|
|
144
|
+
const dist = r.selection?.distribution;
|
|
145
|
+
const g = input.criterion.cases[r.intentId];
|
|
146
|
+
if (!dist || !Object.keys(dist).length || !g)
|
|
147
|
+
continue;
|
|
148
|
+
const gold = g.expected ?? 'none';
|
|
149
|
+
// Folded to what the criterion can say: a skill, or `none` — "ask the person" and "needs several" (judge v5) are
|
|
150
|
+
// abstentions, so they count toward `none`.
|
|
151
|
+
const folded = foldAbstentions(dist, input.toolToSkill);
|
|
152
|
+
const keys = Object.keys(folded);
|
|
153
|
+
const [predicted, p] = Object.entries(folded).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0];
|
|
154
|
+
// Multi-class Brier over the outcomes the judge was offered (the gold outcome counts even when it was not offered).
|
|
155
|
+
const goldOffered = keys.includes(gold);
|
|
156
|
+
const brier = keys.reduce((s, k) => s + ((folded[k] ?? 0) - (k === gold ? 1 : 0)) ** 2, 0) + (goldOffered ? 0 : 1);
|
|
157
|
+
rows.push({ intentId: r.intentId, variant: r.variant, predicted, p, correct: predicted === gold, brier, gold });
|
|
158
|
+
}
|
|
159
|
+
const n = rows.length;
|
|
160
|
+
const mean = (xs) => (xs.length ? xs.reduce((a, b) => a + b, 0) / xs.length : null);
|
|
161
|
+
const bins = Array.from({ length: 10 }, (_, i) => {
|
|
162
|
+
const lo = i / 10, hi = (i + 1) / 10;
|
|
163
|
+
const inBin = rows.filter((x) => x.p >= lo && (i === 9 ? x.p <= hi : x.p < hi));
|
|
164
|
+
return { lo, hi, n: inBin.length, confidence: mean(inBin.map((x) => x.p)), accuracy: mean(inBin.map((x) => (x.correct ? 1 : 0))) };
|
|
165
|
+
});
|
|
166
|
+
const ece = n ? bins.reduce((s, b) => s + (b.n ? (b.n / n) * Math.abs((b.confidence ?? 0) - (b.accuracy ?? 0)) : 0), 0) : null;
|
|
167
|
+
const brier = mean(rows.map((x) => x.brier));
|
|
168
|
+
const accuracy = mean(rows.map((x) => (x.correct ? 1 : 0)));
|
|
169
|
+
const meanConfidence = mean(rows.map((x) => x.p));
|
|
170
|
+
const overconfident = rows.filter((x) => !x.correct && x.p >= 0.8).map(({ intentId, variant, predicted, p, gold }) => ({ intentId, variant, predicted, p, gold }));
|
|
171
|
+
let status, reason;
|
|
172
|
+
if (n < th.minRuns) {
|
|
173
|
+
status = 'INCOMPLETE';
|
|
174
|
+
reason = `${n} judged run${n === 1 ? '' : 's'} — calibration needs at least ${th.minRuns}`;
|
|
175
|
+
}
|
|
176
|
+
else if ((ece ?? 1) > th.eceMax) {
|
|
177
|
+
status = 'FAIL';
|
|
178
|
+
reason = `expected calibration error ${ece.toFixed(3)} > ${th.eceMax}`;
|
|
179
|
+
}
|
|
180
|
+
else if ((brier ?? 2) > th.brierMax) {
|
|
181
|
+
status = 'FAIL';
|
|
182
|
+
reason = `Brier ${brier.toFixed(3)} > ${th.brierMax}`;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
status = 'PASS';
|
|
186
|
+
reason = `ECE ${ece.toFixed(3)} ≤ ${th.eceMax}, Brier ${brier.toFixed(3)} ≤ ${th.brierMax} over ${n} runs`;
|
|
187
|
+
}
|
|
188
|
+
return { gate: 'judgment-calibration', status, n, accuracy, meanConfidence, brier, ece, bins, overconfident, thresholds: th, reason };
|
|
189
|
+
}
|
|
190
|
+
export const DEFAULT_CONSISTENCY_THRESHOLDS = { minGroups: 10, agreementMin: 0.9, spreadMax: 0.1 };
|
|
191
|
+
export function judgmentConsistencyOf(input) {
|
|
192
|
+
const th = { ...DEFAULT_CONSISTENCY_THRESHOLDS, ...input.thresholds };
|
|
193
|
+
const groups = new Map();
|
|
194
|
+
for (const r of input.experiment.runs) {
|
|
195
|
+
const d = r.selection?.distribution;
|
|
196
|
+
if (!d || !Object.keys(d).length)
|
|
197
|
+
continue;
|
|
198
|
+
const k = `${r.intentId}\u0000${r.variant}`;
|
|
199
|
+
const g = groups.get(k) ?? { intentId: r.intentId, variant: r.variant, dists: [] };
|
|
200
|
+
g.dists.push(d);
|
|
201
|
+
groups.set(k, g);
|
|
202
|
+
}
|
|
203
|
+
const top = (d) => Object.entries(foldAbstentions(d)).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0][0];
|
|
204
|
+
const rows = [];
|
|
205
|
+
for (const g of groups.values()) {
|
|
206
|
+
if (g.dists.length < 2)
|
|
207
|
+
continue;
|
|
208
|
+
const tops = g.dists.map(top);
|
|
209
|
+
const counts = new Map();
|
|
210
|
+
for (const t of tops)
|
|
211
|
+
counts.set(t, (counts.get(t) ?? 0) + 1);
|
|
212
|
+
const modal = [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0][0];
|
|
213
|
+
const ps = g.dists.map((d) => foldAbstentions(d)[modal] ?? 0);
|
|
214
|
+
const mean = ps.reduce((s, v) => s + v, 0) / ps.length;
|
|
215
|
+
const spread = Math.sqrt(ps.reduce((s, v) => s + (v - mean) ** 2, 0) / (ps.length - 1));
|
|
216
|
+
rows.push({ agreement: counts.get(modal) / tops.length, spread, intentId: g.intentId, variant: g.variant, tops });
|
|
217
|
+
}
|
|
218
|
+
const n = rows.length;
|
|
219
|
+
const agreement = n ? rows.reduce((s, r) => s + r.agreement, 0) / n : null;
|
|
220
|
+
const spread = n ? rows.reduce((s, r) => s + r.spread, 0) / n : null;
|
|
221
|
+
const unstable = rows.filter((r) => r.agreement < 1).map(({ intentId, variant, tops }) => ({ intentId, variant, tops }));
|
|
222
|
+
let status, reason;
|
|
223
|
+
if (n < th.minGroups) {
|
|
224
|
+
status = 'INCOMPLETE';
|
|
225
|
+
reason = `${n} case${n === 1 ? '' : 's'} judged more than once — consistency needs at least ${th.minGroups} (run with --repeat ≥ 2)`;
|
|
226
|
+
}
|
|
227
|
+
else if (agreement < th.agreementMin) {
|
|
228
|
+
status = 'FAIL';
|
|
229
|
+
reason = `agreement ${agreement.toFixed(3)} < ${th.agreementMin}`;
|
|
230
|
+
}
|
|
231
|
+
else if (spread > th.spreadMax) {
|
|
232
|
+
status = 'FAIL';
|
|
233
|
+
reason = `spread ${spread.toFixed(3)} > ${th.spreadMax}`;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
status = 'PASS';
|
|
237
|
+
reason = `agreement ${agreement.toFixed(3)} ≥ ${th.agreementMin}, spread ${spread.toFixed(3)} ≤ ${th.spreadMax} over ${n} repeated cases`;
|
|
238
|
+
}
|
|
239
|
+
return { gate: 'judgment-consistency', status, groups: n, agreement, spread, unstable, thresholds: th, reason };
|
|
240
|
+
}
|
|
241
|
+
export const DEFAULT_CANDIDATE_RECALL_THRESHOLDS = { minRuns: 20, recallMin: 0.98 };
|
|
242
|
+
export function candidateRecallOf(input) {
|
|
243
|
+
const th = { ...DEFAULT_CANDIDATE_RECALL_THRESHOLDS, ...input.thresholds };
|
|
244
|
+
let n = 0, hit = 0, sizes = 0;
|
|
245
|
+
const byVia = {};
|
|
246
|
+
const missed = [];
|
|
247
|
+
for (const r of input.experiment.runs) {
|
|
248
|
+
const f = r.selection;
|
|
249
|
+
const g = input.criterion.cases[r.intentId];
|
|
250
|
+
if (!f?.proposed || !g?.expected)
|
|
251
|
+
continue;
|
|
252
|
+
n++;
|
|
253
|
+
sizes += f.proposed.length;
|
|
254
|
+
const at = f.proposed.find((t) => (input.toolToSkill[t] ?? t) === g.expected);
|
|
255
|
+
if (at) {
|
|
256
|
+
hit++;
|
|
257
|
+
const v = f.proposedVia?.[at] ?? 'unknown';
|
|
258
|
+
byVia[v] = (byVia[v] ?? 0) + 1;
|
|
259
|
+
}
|
|
260
|
+
else
|
|
261
|
+
missed.push({ intentId: r.intentId, variant: r.variant, gold: g.expected });
|
|
262
|
+
}
|
|
263
|
+
const recall = n ? hit / n : null;
|
|
264
|
+
let status, reason;
|
|
265
|
+
if (n < th.minRuns) {
|
|
266
|
+
status = 'INCOMPLETE';
|
|
267
|
+
reason = `${n} positive run${n === 1 ? '' : 's'} with a recorded proposal — recall needs at least ${th.minRuns}`;
|
|
268
|
+
}
|
|
269
|
+
else if (recall < th.recallMin) {
|
|
270
|
+
status = 'FAIL';
|
|
271
|
+
reason = `candidate recall ${recall.toFixed(3)} < ${th.recallMin} — ${missed.length} gold skill(s) never reached the judge`;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
status = 'PASS';
|
|
275
|
+
reason = `candidate recall ${recall.toFixed(3)} ≥ ${th.recallMin} over ${n} positive runs`;
|
|
276
|
+
}
|
|
277
|
+
return { gate: 'candidate-recall', status, n, recall, meanProposed: n ? sizes / n : null, byVia, missed, thresholds: th, reason };
|
|
278
|
+
}
|
|
279
|
+
export const DEFAULT_BEHAVIOUR_THRESHOLDS = { minCases: 8, rightMin: 0.8, overAskMax: 0.1 };
|
|
280
|
+
export function selectionBehaviourOf(input) {
|
|
281
|
+
const th = { ...DEFAULT_BEHAVIOUR_THRESHOLDS, ...input.thresholds };
|
|
282
|
+
const counts = { asked: 0, planned: 0, crossed: 0, declined: 0, guessed: 0 };
|
|
283
|
+
const byBehaviour = { clarify: { n: 0, right: 0 }, several: { n: 0, right: 0 } };
|
|
284
|
+
const wrong = [];
|
|
285
|
+
let n = 0, positives = 0, overAsked = 0;
|
|
286
|
+
for (const r of input.experiment.runs) {
|
|
287
|
+
const g = input.criterion.cases[r.intentId];
|
|
288
|
+
const f = r.selection;
|
|
289
|
+
if (!g || !f)
|
|
290
|
+
continue;
|
|
291
|
+
const hold = f.hold ?? null;
|
|
292
|
+
if (g.behaviour) {
|
|
293
|
+
n++;
|
|
294
|
+
byBehaviour[g.behaviour].n++;
|
|
295
|
+
const want = g.behaviour === 'clarify' ? 'needs-clarification' : 'needs-several';
|
|
296
|
+
const other = g.behaviour === 'clarify' ? 'needs-several' : 'needs-clarification';
|
|
297
|
+
const outcome = f.chose ? 'guessed' : hold === want ? (g.behaviour === 'clarify' ? 'asked' : 'planned') : hold === other ? 'crossed' : 'declined';
|
|
298
|
+
counts[outcome]++;
|
|
299
|
+
if (outcome === 'asked' || outcome === 'planned')
|
|
300
|
+
byBehaviour[g.behaviour].right++;
|
|
301
|
+
else
|
|
302
|
+
wrong.push({ intentId: r.intentId, variant: r.variant, behaviour: g.behaviour, outcome, chose: f.chose });
|
|
303
|
+
}
|
|
304
|
+
else if (g.expected) {
|
|
305
|
+
positives++;
|
|
306
|
+
if (hold === 'needs-clarification' || hold === 'needs-several')
|
|
307
|
+
overAsked++;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
const right = n ? (counts.asked + counts.planned) / n : null;
|
|
311
|
+
const overAskRate = positives ? overAsked / positives : null;
|
|
312
|
+
let status, reason;
|
|
313
|
+
if (n < th.minCases) {
|
|
314
|
+
status = 'INCOMPLETE';
|
|
315
|
+
reason = `${n} run${n === 1 ? '' : 's'} on requests whose right behaviour is to ask or hand on — the gate needs at least ${th.minCases}`;
|
|
316
|
+
}
|
|
317
|
+
else if (right < th.rightMin) {
|
|
318
|
+
status = 'FAIL';
|
|
319
|
+
reason = `asked / handed on when it should ${right.toFixed(3)} < ${th.rightMin}`;
|
|
320
|
+
}
|
|
321
|
+
else if (overAskRate !== null && overAskRate > th.overAskMax) {
|
|
322
|
+
status = 'FAIL';
|
|
323
|
+
reason = `asked when one skill was right ${overAskRate.toFixed(3)} > ${th.overAskMax}`;
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
status = 'PASS';
|
|
327
|
+
reason = `right behaviour ${right.toFixed(3)} ≥ ${th.rightMin} over ${n} runs; over-asked ${overAsked}/${positives}`;
|
|
328
|
+
}
|
|
329
|
+
return { gate: 'selection-behaviour', status, n, right, counts, byBehaviour, positives, overAsked, overAskRate, wrong, thresholds: th, reason };
|
|
330
|
+
}
|
|
331
|
+
//# sourceMappingURL=selection-gates.js.map
|