@sanity/ailf 2.0.2 → 2.2.0
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/LICENSE +21 -0
- package/dist/_vendor/ailf-core/examples/index.d.ts +50 -1
- package/dist/_vendor/ailf-core/examples/index.js +66 -1
- package/dist/agent-harness/assertions-runtime.d.ts +49 -0
- package/dist/agent-harness/assertions-runtime.js +138 -0
- package/dist/agent-harness/provider.d.ts +58 -0
- package/dist/agent-harness/provider.js +104 -0
- package/dist/cli.js +0 -0
- package/dist/commands/init.js +3 -0
- package/dist/orchestration/steps/generate-configs-step.d.ts +7 -0
- package/dist/orchestration/steps/generate-configs-step.js +35 -2
- package/dist/pipeline/compiler/__tests__/agent-harness-handler.test.js +39 -25
- package/dist/pipeline/compiler/compiler-to-yaml.js +78 -7
- package/dist/pipeline/compiler/mode-handlers/agent-harness/assertions.d.ts +9 -0
- package/dist/pipeline/compiler/mode-handlers/agent-harness/assertions.js +28 -85
- package/dist/pipeline/compiler/mode-handlers/agent-harness/compiler.js +22 -15
- package/dist/pipeline/compiler/mode-handlers/agent-harness/sandbox.d.ts +8 -1
- package/dist/pipeline/compiler/mode-handlers/agent-harness/sandbox.js +42 -12
- package/package.json +25 -24
- package/dist/_vendor/ailf-core/__tests__/comparison-formatters.test.d.ts +0 -10
- package/dist/_vendor/ailf-core/__tests__/comparison-formatters.test.js +0 -185
- package/dist/_vendor/ailf-core/artifact-capture/__tests__/noop-collector.test.d.ts +0 -6
- package/dist/_vendor/ailf-core/artifact-capture/__tests__/noop-collector.test.js +0 -42
- package/dist/_vendor/ailf-tasks/cli.d.ts +0 -8
- package/dist/_vendor/ailf-tasks/cli.js +0 -61
- package/dist/_vendor/ailf-tasks/index.d.ts +0 -13
- package/dist/_vendor/ailf-tasks/index.js +0 -16
- package/dist/_vendor/ailf-tasks/parser.d.ts +0 -27
- package/dist/_vendor/ailf-tasks/parser.js +0 -73
- package/dist/_vendor/ailf-tasks/schemas.d.ts +0 -198
- package/dist/_vendor/ailf-tasks/schemas.js +0 -180
- package/dist/_vendor/ailf-tasks/validation.d.ts +0 -47
- package/dist/_vendor/ailf-tasks/validation.js +0 -162
- package/dist/adapters/task-sources/yaml-task-source.d.ts +0 -18
- package/dist/adapters/task-sources/yaml-task-source.js +0 -139
- package/dist/agent-observer/test-imports.d.ts +0 -7
- package/dist/agent-observer/test-imports.js +0 -185
- package/dist/commands/update-quality-scores.d.ts +0 -5
- package/dist/commands/update-quality-scores.js +0 -20
- package/dist/lib/agent-behavior-report.d.ts +0 -8
- package/dist/lib/agent-behavior-report.js +0 -185
- package/dist/lib/baseline.d.ts +0 -19
- package/dist/lib/baseline.js +0 -153
- package/dist/lib/calculate-scores.d.ts +0 -23
- package/dist/lib/calculate-scores.js +0 -42
- package/dist/lib/compare.d.ts +0 -18
- package/dist/lib/compare.js +0 -170
- package/dist/lib/coverage-audit.d.ts +0 -4
- package/dist/lib/coverage-audit.js +0 -42
- package/dist/lib/discovery-report.d.ts +0 -13
- package/dist/lib/discovery-report.js +0 -57
- package/dist/lib/fetch-docs.d.ts +0 -30
- package/dist/lib/fetch-docs.js +0 -171
- package/dist/lib/generate-configs.d.ts +0 -25
- package/dist/lib/generate-configs.js +0 -42
- package/dist/lib/grader-api.d.ts +0 -21
- package/dist/lib/grader-api.js +0 -34
- package/dist/lib/grader-compare.d.ts +0 -19
- package/dist/lib/grader-compare.js +0 -91
- package/dist/lib/grader-consistency.d.ts +0 -27
- package/dist/lib/grader-consistency.js +0 -79
- package/dist/lib/grader-sensitivity.d.ts +0 -19
- package/dist/lib/grader-sensitivity.js +0 -75
- package/dist/lib/grader-validate.d.ts +0 -19
- package/dist/lib/grader-validate.js +0 -78
- package/dist/lib/measure-retrieval.d.ts +0 -14
- package/dist/lib/measure-retrieval.js +0 -71
- package/dist/lib/pr-comment.d.ts +0 -16
- package/dist/lib/pr-comment.js +0 -28
- package/dist/lib/readiness-report.d.ts +0 -13
- package/dist/lib/readiness-report.js +0 -108
- package/dist/lib/webhook-server.d.ts +0 -11
- package/dist/lib/webhook-server.js +0 -24
- package/dist/lib/weekly-digest.d.ts +0 -24
- package/dist/lib/weekly-digest.js +0 -148
- package/dist/orchestration/env-bridge.d.ts +0 -21
- package/dist/orchestration/env-bridge.js +0 -66
- package/dist/orchestration/steps/fetch-docs-shell.d.ts +0 -17
- package/dist/orchestration/steps/fetch-docs-shell.js +0 -30
- package/dist/pipeline/compiler/__tests__/task-bridge.test.d.ts +0 -9
- package/dist/pipeline/compiler/__tests__/task-bridge.test.js +0 -339
- package/dist/pipeline/compiler/mode-handlers/agent-harness-handler.d.ts +0 -70
- package/dist/pipeline/compiler/mode-handlers/agent-harness-handler.js +0 -485
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe-handler.d.ts +0 -76
- package/dist/pipeline/compiler/mode-handlers/knowledge-probe-handler.js +0 -245
- package/dist/pipeline/compiler/mode-handlers/literacy-handler.d.ts +0 -89
- package/dist/pipeline/compiler/mode-handlers/literacy-handler.js +0 -379
- package/dist/pipeline/compiler/mode-handlers/mcp-assertions.d.ts +0 -50
- package/dist/pipeline/compiler/mode-handlers/mcp-assertions.js +0 -334
- package/dist/pipeline/compiler/mode-handlers/mcp-server-handler.d.ts +0 -69
- package/dist/pipeline/compiler/mode-handlers/mcp-server-handler.js +0 -307
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider.d.ts +0 -65
- package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider.js +0 -368
- package/dist/pipeline/compiler/task-bridge.d.ts +0 -41
- package/dist/pipeline/compiler/task-bridge.js +0 -92
- package/dist/pipeline/expand-tasks.d.ts +0 -232
- package/dist/pipeline/expand-tasks.js +0 -467
- package/dist/pipeline/generate-configs.d.ts +0 -92
- package/dist/pipeline/generate-configs.js +0 -445
- package/dist/pipeline/steps/calculate-scores-step.d.ts +0 -11
- package/dist/pipeline/steps/calculate-scores-step.js +0 -89
- package/dist/pipeline/steps/compare-step.d.ts +0 -18
- package/dist/pipeline/steps/compare-step.js +0 -90
- package/dist/pipeline/steps/eval-step.d.ts +0 -53
- package/dist/pipeline/steps/eval-step.js +0 -347
- package/dist/pipeline/steps/fetch-docs-step.d.ts +0 -11
- package/dist/pipeline/steps/fetch-docs-step.js +0 -84
- package/dist/pipeline/steps/generate-configs-step.d.ts +0 -11
- package/dist/pipeline/steps/generate-configs-step.js +0 -98
- package/dist/pipeline/steps/grader-consistency-step.d.ts +0 -21
- package/dist/pipeline/steps/grader-consistency-step.js +0 -74
- package/dist/pipeline/steps/publish-report-step.d.ts +0 -57
- package/dist/pipeline/steps/publish-report-step.js +0 -243
- package/dist/pipeline/steps/report-step.d.ts +0 -13
- package/dist/pipeline/steps/report-step.js +0 -56
- package/dist/pipeline/steps/update-scores-step.d.ts +0 -11
- package/dist/pipeline/steps/update-scores-step.js +0 -42
- package/dist/scripts/agent-behavior-report.d.ts +0 -19
- package/dist/scripts/agent-behavior-report.js +0 -315
- package/dist/scripts/baseline.d.ts +0 -43
- package/dist/scripts/baseline.js +0 -267
- package/dist/scripts/calculate-scores.d.ts +0 -166
- package/dist/scripts/calculate-scores.js +0 -1296
- package/dist/scripts/compare.d.ts +0 -22
- package/dist/scripts/compare.js +0 -334
- package/dist/scripts/coverage-audit.d.ts +0 -44
- package/dist/scripts/coverage-audit.js +0 -209
- package/dist/scripts/debug-eval.d.ts +0 -19
- package/dist/scripts/debug-eval.js +0 -73
- package/dist/scripts/discovery-report.d.ts +0 -58
- package/dist/scripts/discovery-report.js +0 -250
- package/dist/scripts/fetch-docs.d.ts +0 -35
- package/dist/scripts/fetch-docs.js +0 -472
- package/dist/scripts/generate-configs.d.ts +0 -66
- package/dist/scripts/generate-configs.js +0 -459
- package/dist/scripts/grader-api.d.ts +0 -27
- package/dist/scripts/grader-api.js +0 -206
- package/dist/scripts/grader-compare.d.ts +0 -22
- package/dist/scripts/grader-compare.js +0 -368
- package/dist/scripts/grader-consistency.d.ts +0 -20
- package/dist/scripts/grader-consistency.js +0 -313
- package/dist/scripts/grader-sensitivity.d.ts +0 -22
- package/dist/scripts/grader-sensitivity.js +0 -354
- package/dist/scripts/grader-validate.d.ts +0 -19
- package/dist/scripts/grader-validate.js +0 -267
- package/dist/scripts/measure-retrieval.d.ts +0 -10
- package/dist/scripts/measure-retrieval.js +0 -145
- package/dist/scripts/migrate-tasks-to-content-lake.d.ts +0 -24
- package/dist/scripts/migrate-tasks-to-content-lake.js +0 -328
- package/dist/scripts/pipeline.d.ts +0 -76
- package/dist/scripts/pipeline.js +0 -1031
- package/dist/scripts/pr-comment.d.ts +0 -10
- package/dist/scripts/pr-comment.js +0 -510
- package/dist/scripts/readiness-report.d.ts +0 -88
- package/dist/scripts/readiness-report.js +0 -342
- package/dist/scripts/update-quality-scores.d.ts +0 -15
- package/dist/scripts/update-quality-scores.js +0 -184
- package/dist/scripts/validate-task-sources.d.ts +0 -21
- package/dist/scripts/validate-task-sources.js +0 -210
- package/dist/scripts/validate.d.ts +0 -13
- package/dist/scripts/validate.js +0 -79
- package/dist/scripts/webhook-server.d.ts +0 -26
- package/dist/scripts/webhook-server.js +0 -147
- package/dist/scripts/weekly-digest.d.ts +0 -24
- package/dist/scripts/weekly-digest.js +0 -144
- package/dist/sinks/format-slack.d.ts +0 -64
- package/dist/sinks/format-slack.js +0 -306
- package/dist/sinks/slack-sink.d.ts +0 -27
- package/dist/sinks/slack-sink.js +0 -78
- package/dist/sinks/webhook-sink.d.ts +0 -19
- package/dist/sinks/webhook-sink.js +0 -50
- package/tasks/.expanded.agentic.yaml +0 -280
- package/tasks/.expanded.yaml +0 -565
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* grader-validate.ts
|
|
3
|
-
*
|
|
4
|
-
* CLI script for validating grader accuracy against human reference grades
|
|
5
|
-
* (Phase 2 of grader reliability).
|
|
6
|
-
*
|
|
7
|
-
* Loads human-graded reference samples from canonical/grader-references/,
|
|
8
|
-
* runs the grader model on each sample, and compares against human scores.
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* pnpm grader-validate # validate with default grader
|
|
12
|
-
* pnpm grader-validate --grader openai:gpt-5.5 # validate a candidate grader
|
|
13
|
-
* pnpm grader-validate --threshold 15 # custom MAE threshold
|
|
14
|
-
*
|
|
15
|
-
* Reads: canonical/grader-references/*.yaml
|
|
16
|
-
* Reads: config/models.yaml (for default grader model)
|
|
17
|
-
* Writes: results/latest/grader-validation.json
|
|
18
|
-
*/
|
|
19
|
-
import "dotenv/config";
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* grader-validate.ts
|
|
3
|
-
*
|
|
4
|
-
* CLI script for validating grader accuracy against human reference grades
|
|
5
|
-
* (Phase 2 of grader reliability).
|
|
6
|
-
*
|
|
7
|
-
* Loads human-graded reference samples from canonical/grader-references/,
|
|
8
|
-
* runs the grader model on each sample, and compares against human scores.
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* pnpm grader-validate # validate with default grader
|
|
12
|
-
* pnpm grader-validate --grader openai:gpt-5.5 # validate a candidate grader
|
|
13
|
-
* pnpm grader-validate --threshold 15 # custom MAE threshold
|
|
14
|
-
*
|
|
15
|
-
* Reads: canonical/grader-references/*.yaml
|
|
16
|
-
* Reads: config/models.yaml (for default grader model)
|
|
17
|
-
* Writes: results/latest/grader-validation.json
|
|
18
|
-
*/
|
|
19
|
-
// oxlint-disable-next-line import/no-unassigned-import -- side-effect: loads .env into process.env
|
|
20
|
-
import "dotenv/config";
|
|
21
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync, } from "fs";
|
|
22
|
-
import { dirname, join, resolve } from "path";
|
|
23
|
-
import { fileURLToPath } from "url";
|
|
24
|
-
import { load } from "js-yaml";
|
|
25
|
-
import { classifyCorrelation, validateGrader, } from "../pipeline/grader-validation.js";
|
|
26
|
-
import { gradeOnce, loadGraderModel } from "./grader-api.js";
|
|
27
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
28
|
-
const ROOT = resolve(__dirname, "..", "..");
|
|
29
|
-
// ---------------------------------------------------------------------------
|
|
30
|
-
// CLI argument parsing
|
|
31
|
-
// ---------------------------------------------------------------------------
|
|
32
|
-
const args = process.argv.slice(2);
|
|
33
|
-
function getFlag(name) {
|
|
34
|
-
return args.includes(`--${name}`);
|
|
35
|
-
}
|
|
36
|
-
function getOption(name) {
|
|
37
|
-
const idx = args.indexOf(`--${name}`);
|
|
38
|
-
return idx !== -1 && idx + 1 < args.length ? args[idx + 1] : undefined;
|
|
39
|
-
}
|
|
40
|
-
const graderOverride = getOption("grader");
|
|
41
|
-
const thresholdStr = getOption("threshold");
|
|
42
|
-
const maeThreshold = thresholdStr ? parseFloat(thresholdStr) : 10;
|
|
43
|
-
const showHelp = getFlag("help") || getFlag("h");
|
|
44
|
-
if (showHelp) {
|
|
45
|
-
console.log(`
|
|
46
|
-
Usage: pnpm grader-validate [options]
|
|
47
|
-
|
|
48
|
-
Validate grader accuracy against human reference grades.
|
|
49
|
-
|
|
50
|
-
Options:
|
|
51
|
-
--grader <model> Grader model to validate (default: from config/models.yaml)
|
|
52
|
-
--threshold <n> MAE threshold for pass/fail (default: 10)
|
|
53
|
-
--help, -h Show this help
|
|
54
|
-
|
|
55
|
-
Examples:
|
|
56
|
-
pnpm grader-validate # validate current grader
|
|
57
|
-
pnpm grader-validate --grader openai:gpt-5.5 # test a candidate
|
|
58
|
-
pnpm grader-validate --threshold 15 # lenient threshold
|
|
59
|
-
`);
|
|
60
|
-
process.exit(0);
|
|
61
|
-
}
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
// Load reference grades
|
|
64
|
-
// ---------------------------------------------------------------------------
|
|
65
|
-
// ---------------------------------------------------------------------------
|
|
66
|
-
// Dimension mapping
|
|
67
|
-
// ---------------------------------------------------------------------------
|
|
68
|
-
function loadReferenceGrades() {
|
|
69
|
-
const refsDir = join(ROOT, "canonical", "grader-references");
|
|
70
|
-
if (!existsSync(refsDir)) {
|
|
71
|
-
console.error(`❌ Reference grades directory not found: ${refsDir}`);
|
|
72
|
-
console.error("Create canonical/grader-references/ with YAML reference files.");
|
|
73
|
-
console.error("See docs/exec-plans/completed/grader-reliability.md — Phase 2.");
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
const files = readdirSync(refsDir)
|
|
77
|
-
.filter((f) => f.endsWith(".yaml") || f.endsWith(".yml"))
|
|
78
|
-
.sort();
|
|
79
|
-
if (files.length === 0) {
|
|
80
|
-
console.error(`❌ No YAML files found in ${refsDir}`);
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
const allGrades = [];
|
|
84
|
-
for (const file of files) {
|
|
85
|
-
const filePath = join(refsDir, file);
|
|
86
|
-
const raw = readFileSync(filePath, "utf-8");
|
|
87
|
-
const parsed = load(raw);
|
|
88
|
-
if (Array.isArray(parsed)) {
|
|
89
|
-
allGrades.push(...parsed);
|
|
90
|
-
}
|
|
91
|
-
else if (typeof parsed === "object" && parsed !== null) {
|
|
92
|
-
allGrades.push(parsed);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return allGrades;
|
|
96
|
-
}
|
|
97
|
-
// ---------------------------------------------------------------------------
|
|
98
|
-
// OpenAI grading API call (reuse from grader-consistency)
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
async function main() {
|
|
101
|
-
console.log("=== Grader Validation ===\n");
|
|
102
|
-
// Resolve grader model
|
|
103
|
-
const graderModel = graderOverride ?? loadGraderModel().id;
|
|
104
|
-
console.log(` Grader: ${graderModel}`);
|
|
105
|
-
console.log(` Threshold: MAE < ${maeThreshold}`);
|
|
106
|
-
// Load reference grades
|
|
107
|
-
const rawGrades = loadReferenceGrades();
|
|
108
|
-
console.log(` Samples: ${rawGrades.length} reference-graded responses`);
|
|
109
|
-
// Count total rubric judgments
|
|
110
|
-
let totalJudgments = 0;
|
|
111
|
-
for (const rg of rawGrades) {
|
|
112
|
-
totalJudgments += rg.rubrics.length;
|
|
113
|
-
}
|
|
114
|
-
console.log(` Judgments: ${totalJudgments} (response × rubric pairs)`);
|
|
115
|
-
const estimatedCost = totalJudgments * 0.005;
|
|
116
|
-
console.log(` Est. cost: ~$${estimatedCost.toFixed(2)}`);
|
|
117
|
-
console.log();
|
|
118
|
-
// Grade each reference sample
|
|
119
|
-
console.log(" Running grader on reference samples...");
|
|
120
|
-
const grades = [];
|
|
121
|
-
let completed = 0;
|
|
122
|
-
let failed = 0;
|
|
123
|
-
for (const ref of rawGrades) {
|
|
124
|
-
for (const rubric of ref.rubrics) {
|
|
125
|
-
const dimension = mapDimension(rubric.dimension);
|
|
126
|
-
if (!dimension) {
|
|
127
|
-
console.error(` ⚠ Unknown dimension '${rubric.dimension}' — skipping`);
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
const graderScore = await gradeOnce(graderModel, ref.response, rubric.rubricText);
|
|
131
|
-
completed++;
|
|
132
|
-
if (completed % 5 === 0 || completed === totalJudgments) {
|
|
133
|
-
process.stdout.write(`\r Progress: ${completed}/${totalJudgments}`);
|
|
134
|
-
}
|
|
135
|
-
if (graderScore === null) {
|
|
136
|
-
failed++;
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
grades.push({
|
|
140
|
-
area: ref.area,
|
|
141
|
-
dimension,
|
|
142
|
-
graderScore,
|
|
143
|
-
humanScore: rubric.humanScore,
|
|
144
|
-
taskId: ref.taskId,
|
|
145
|
-
...(rubric.notes && { notes: rubric.notes }),
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
console.log(); // newline after progress
|
|
150
|
-
if (failed > 0) {
|
|
151
|
-
console.log(` ⚠ ${failed} grading calls failed (excluded from analysis)`);
|
|
152
|
-
}
|
|
153
|
-
console.log();
|
|
154
|
-
if (grades.length === 0) {
|
|
155
|
-
console.error("❌ No grades to analyze.");
|
|
156
|
-
process.exit(1);
|
|
157
|
-
}
|
|
158
|
-
// Validate
|
|
159
|
-
const result = validateGrader(grades, graderModel, { maeThreshold });
|
|
160
|
-
// Print report
|
|
161
|
-
printReport(result);
|
|
162
|
-
// Write output
|
|
163
|
-
const outDir = join(ROOT, "results", "latest");
|
|
164
|
-
mkdirSync(outDir, { recursive: true });
|
|
165
|
-
const outPath = join(outDir, "grader-validation.json");
|
|
166
|
-
writeFileSync(outPath, JSON.stringify(result, null, 2));
|
|
167
|
-
console.log(`\n 📄 Results written to ${outPath}`);
|
|
168
|
-
// Exit with error code if threshold not met
|
|
169
|
-
if (!result.passesThreshold) {
|
|
170
|
-
console.error(`\n ❌ VALIDATION FAILED: MAE ${result.overallMae} exceeds threshold ${maeThreshold}`);
|
|
171
|
-
process.exit(1);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
// ---------------------------------------------------------------------------
|
|
175
|
-
// Main
|
|
176
|
-
// ---------------------------------------------------------------------------
|
|
177
|
-
function mapDimension(dim) {
|
|
178
|
-
switch (dim) {
|
|
179
|
-
case "code-correctness":
|
|
180
|
-
return "codeCorrectness";
|
|
181
|
-
case "doc-coverage":
|
|
182
|
-
return "docCoverage";
|
|
183
|
-
case "task-completion":
|
|
184
|
-
return "taskCompletion";
|
|
185
|
-
default:
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
// ---------------------------------------------------------------------------
|
|
190
|
-
// Report formatting
|
|
191
|
-
// ---------------------------------------------------------------------------
|
|
192
|
-
function printReport(result) {
|
|
193
|
-
console.log("=".repeat(80));
|
|
194
|
-
console.log(" GRADER VALIDATION REPORT");
|
|
195
|
-
console.log("=".repeat(80));
|
|
196
|
-
console.log();
|
|
197
|
-
console.log(` Grader: ${result.graderModel}`);
|
|
198
|
-
console.log(` Observations: ${result.totalObservations}`);
|
|
199
|
-
console.log();
|
|
200
|
-
// Overall metrics
|
|
201
|
-
console.log("-".repeat(80));
|
|
202
|
-
console.log("OVERALL METRICS");
|
|
203
|
-
console.log("-".repeat(80));
|
|
204
|
-
console.log();
|
|
205
|
-
console.log(` MAE: ${result.overallMae} points`);
|
|
206
|
-
console.log(` Correlation: r=${result.overallCorrelation} (${classifyCorrelation(result.overallCorrelation)})`);
|
|
207
|
-
console.log(` Bias: ${result.overallBias > 0 ? "+" : ""}${result.overallBias} (${result.overallBias > 0 ? "grader scores higher" : result.overallBias < 0 ? "grader scores lower" : "no bias"})`);
|
|
208
|
-
console.log();
|
|
209
|
-
// Per-dimension table
|
|
210
|
-
console.log("-".repeat(80));
|
|
211
|
-
console.log("PER-DIMENSION VALIDITY");
|
|
212
|
-
console.log("-".repeat(80));
|
|
213
|
-
console.log();
|
|
214
|
-
const h = "| Dimension | MAE | Correlation | Quality | Bias | Count |";
|
|
215
|
-
const sep = "|------------------|-------|-------------|-----------|--------|-------|";
|
|
216
|
-
console.log(h);
|
|
217
|
-
console.log(sep);
|
|
218
|
-
const dims = [
|
|
219
|
-
{ data: result.perDimension.taskCompletion, name: "Task Completion" },
|
|
220
|
-
{ data: result.perDimension.codeCorrectness, name: "Code Correctness" },
|
|
221
|
-
{ data: result.perDimension.docCoverage, name: "Doc Coverage" },
|
|
222
|
-
];
|
|
223
|
-
for (const { data, name } of dims) {
|
|
224
|
-
const quality = classifyCorrelation(data.correlation);
|
|
225
|
-
const biasStr = data.bias > 0 ? `+${data.bias}` : `${data.bias}`;
|
|
226
|
-
console.log(`| ${name.padEnd(16)} | ${String(data.mae).padStart(5)} | r=${String(data.correlation).padStart(9)} | ${quality.padEnd(9)} | ${biasStr.padStart(6)} | ${String(data.count).padStart(5)} |`);
|
|
227
|
-
}
|
|
228
|
-
console.log();
|
|
229
|
-
// Pass/fail verdict
|
|
230
|
-
console.log("-".repeat(80));
|
|
231
|
-
console.log("VERDICT");
|
|
232
|
-
console.log("-".repeat(80));
|
|
233
|
-
console.log();
|
|
234
|
-
if (result.passesThreshold) {
|
|
235
|
-
console.log(` ✅ PASSED: MAE ${result.overallMae} < threshold ${result.maeThreshold}`);
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
console.log(` ❌ FAILED: MAE ${result.overallMae} >= threshold ${result.maeThreshold}`);
|
|
239
|
-
}
|
|
240
|
-
console.log();
|
|
241
|
-
// Largest disagreements
|
|
242
|
-
const topN = Math.min(5, result.largestDisagreements.length);
|
|
243
|
-
if (topN > 0) {
|
|
244
|
-
console.log("-".repeat(80));
|
|
245
|
-
console.log(`TOP ${topN} LARGEST DISAGREEMENTS`);
|
|
246
|
-
console.log("-".repeat(80));
|
|
247
|
-
console.log();
|
|
248
|
-
for (let i = 0; i < topN; i++) {
|
|
249
|
-
const d = result.largestDisagreements[i];
|
|
250
|
-
const sign = d.signedError > 0 ? "+" : "";
|
|
251
|
-
console.log(` ${i + 1}. ${d.taskId} — ${d.dimension}`);
|
|
252
|
-
console.log(` Human=${d.humanScore}, Grader=${d.graderScore} (${sign}${d.signedError})`);
|
|
253
|
-
if (d.notes) {
|
|
254
|
-
console.log(` Note: ${d.notes}`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
console.log();
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
// Only run when invoked directly
|
|
261
|
-
if (process.argv[1]?.endsWith("grader-validate.ts") ||
|
|
262
|
-
process.argv[1]?.endsWith("grader-validate.js")) {
|
|
263
|
-
main().catch((err) => {
|
|
264
|
-
console.error("❌ Fatal error:", err);
|
|
265
|
-
process.exit(1);
|
|
266
|
-
});
|
|
267
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* measure-retrieval.ts
|
|
3
|
-
*
|
|
4
|
-
* Evaluates retrieval quality by comparing what Sanity's text search
|
|
5
|
-
* returns against the manually-annotated canonical documents for each
|
|
6
|
-
* evaluation task. Produces Recall@K and NDCG@K metrics.
|
|
7
|
-
*
|
|
8
|
-
* This answers: "Can a retriever find the docs an LLM actually needs?"
|
|
9
|
-
*/
|
|
10
|
-
import "dotenv/config";
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* measure-retrieval.ts
|
|
3
|
-
*
|
|
4
|
-
* Evaluates retrieval quality by comparing what Sanity's text search
|
|
5
|
-
* returns against the manually-annotated canonical documents for each
|
|
6
|
-
* evaluation task. Produces Recall@K and NDCG@K metrics.
|
|
7
|
-
*
|
|
8
|
-
* This answers: "Can a retriever find the docs an LLM actually needs?"
|
|
9
|
-
*/
|
|
10
|
-
// oxlint-disable-next-line import/no-unassigned-import -- side-effect: loads .env into process.env
|
|
11
|
-
import "dotenv/config";
|
|
12
|
-
import { writeFileSync, mkdirSync } from "fs";
|
|
13
|
-
import { join, dirname } from "path";
|
|
14
|
-
import { resolveMappings, } from "../pipeline/resolve-mappings.js";
|
|
15
|
-
import { getSanityClient } from "../sanity/client.js";
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
// Retrieval via Sanity text search
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
function calculateNDCG(canonical, retrieved, k) {
|
|
20
|
-
const canonicalSet = new Set(canonical);
|
|
21
|
-
// Discounted Cumulative Gain
|
|
22
|
-
let dcg = 0;
|
|
23
|
-
for (let i = 0; i < Math.min(k, retrieved.length); i++) {
|
|
24
|
-
if (canonicalSet.has(retrieved[i])) {
|
|
25
|
-
dcg += 1 / Math.log2(i + 2); // +2 because log2(1) = 0
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// Ideal DCG
|
|
29
|
-
let idcg = 0;
|
|
30
|
-
for (let i = 0; i < Math.min(k, canonical.length); i++) {
|
|
31
|
-
idcg += 1 / Math.log2(i + 2);
|
|
32
|
-
}
|
|
33
|
-
return idcg === 0 ? 0 : dcg / idcg;
|
|
34
|
-
}
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
// Metrics
|
|
37
|
-
// ---------------------------------------------------------------------------
|
|
38
|
-
function calculateRecall(canonical, retrieved, k) {
|
|
39
|
-
const retrievedSet = new Set(retrieved.slice(0, k));
|
|
40
|
-
const hits = canonical.filter((doc) => retrievedSet.has(doc)).length;
|
|
41
|
-
return canonical.length === 0 ? 0 : hits / canonical.length;
|
|
42
|
-
}
|
|
43
|
-
async function main() {
|
|
44
|
-
console.log("=== Sanity AI Literacy — Retrieval Quality Measurement ===\n");
|
|
45
|
-
const ROOT = join(dirname(new URL(import.meta.url).pathname), "..", "..");
|
|
46
|
-
const mappings = resolveMappings(ROOT);
|
|
47
|
-
const results = [];
|
|
48
|
-
for (const [area, areaData] of Object.entries(mappings.feature_areas)) {
|
|
49
|
-
console.log(`Feature area: ${area}`);
|
|
50
|
-
for (const task of areaData.tasks) {
|
|
51
|
-
const canonicalSlugs = task.canonical_docs.map((d) => d.slug);
|
|
52
|
-
// Use the task description as a search query
|
|
53
|
-
const retrieved = await retrieveDocsForQuery(task.description, 10);
|
|
54
|
-
const result = {
|
|
55
|
-
canonical_docs: canonicalSlugs,
|
|
56
|
-
feature_area: area,
|
|
57
|
-
ndcg_at_10: calculateNDCG(canonicalSlugs, retrieved, 10),
|
|
58
|
-
recall_at_5: calculateRecall(canonicalSlugs, retrieved, 5),
|
|
59
|
-
recall_at_10: calculateRecall(canonicalSlugs, retrieved, 10),
|
|
60
|
-
retrieved_docs: retrieved,
|
|
61
|
-
task_id: task.id,
|
|
62
|
-
};
|
|
63
|
-
results.push(result);
|
|
64
|
-
console.log(` ${task.id}:`);
|
|
65
|
-
console.log(` Recall@5: ${(result.recall_at_5 * 100).toFixed(1)}%`);
|
|
66
|
-
console.log(` Recall@10: ${(result.recall_at_10 * 100).toFixed(1)}%`);
|
|
67
|
-
console.log(` NDCG@10: ${(result.ndcg_at_10 * 100).toFixed(1)}%`);
|
|
68
|
-
}
|
|
69
|
-
console.log();
|
|
70
|
-
}
|
|
71
|
-
// -----------------------------------------------------------------------
|
|
72
|
-
// Aggregate by feature area
|
|
73
|
-
// -----------------------------------------------------------------------
|
|
74
|
-
const byArea = {};
|
|
75
|
-
for (const area of Object.keys(mappings.feature_areas)) {
|
|
76
|
-
const areaResults = results.filter((r) => r.feature_area === area);
|
|
77
|
-
if (areaResults.length === 0)
|
|
78
|
-
continue;
|
|
79
|
-
byArea[area] = {
|
|
80
|
-
avg_ndcg_at_10: areaResults.reduce((s, r) => s + r.ndcg_at_10, 0) / areaResults.length,
|
|
81
|
-
avg_recall_at_5: areaResults.reduce((s, r) => s + r.recall_at_5, 0) / areaResults.length,
|
|
82
|
-
avg_recall_at_10: areaResults.reduce((s, r) => s + r.recall_at_10, 0) /
|
|
83
|
-
areaResults.length,
|
|
84
|
-
task_count: areaResults.length,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
// -----------------------------------------------------------------------
|
|
88
|
-
// Overall
|
|
89
|
-
// -----------------------------------------------------------------------
|
|
90
|
-
const overall = {
|
|
91
|
-
avg_ndcg_at_10: results.reduce((s, r) => s + r.ndcg_at_10, 0) / results.length,
|
|
92
|
-
avg_recall_at_5: results.reduce((s, r) => s + r.recall_at_5, 0) / results.length,
|
|
93
|
-
avg_recall_at_10: results.reduce((s, r) => s + r.recall_at_10, 0) / results.length,
|
|
94
|
-
};
|
|
95
|
-
// -----------------------------------------------------------------------
|
|
96
|
-
// Print summary
|
|
97
|
-
// -----------------------------------------------------------------------
|
|
98
|
-
console.log("=".repeat(70));
|
|
99
|
-
console.log("RETRIEVAL QUALITY SUMMARY");
|
|
100
|
-
console.log("=".repeat(70));
|
|
101
|
-
console.log();
|
|
102
|
-
console.log("| Feature Area | Recall@5 | Recall@10 | NDCG@10 | Tasks |");
|
|
103
|
-
console.log("|---------------------|----------|-----------|---------|-------|");
|
|
104
|
-
for (const [area, stats] of Object.entries(byArea)) {
|
|
105
|
-
console.log(`| ${area.padEnd(19)} | ${(stats.avg_recall_at_5 * 100).toFixed(1).padStart(7)}% | ` +
|
|
106
|
-
`${(stats.avg_recall_at_10 * 100).toFixed(1).padStart(8)}% | ` +
|
|
107
|
-
`${(stats.avg_ndcg_at_10 * 100).toFixed(1).padStart(6)}% | ` +
|
|
108
|
-
`${stats.task_count.toString().padStart(5)} |`);
|
|
109
|
-
}
|
|
110
|
-
console.log();
|
|
111
|
-
console.log(`Overall: Recall@5=${(overall.avg_recall_at_5 * 100).toFixed(1)}% ` +
|
|
112
|
-
`Recall@10=${(overall.avg_recall_at_10 * 100).toFixed(1)}% ` +
|
|
113
|
-
`NDCG@10=${(overall.avg_ndcg_at_10 * 100).toFixed(1)}%`);
|
|
114
|
-
// -----------------------------------------------------------------------
|
|
115
|
-
// Persist results
|
|
116
|
-
// -----------------------------------------------------------------------
|
|
117
|
-
const summary = { by_area: byArea, overall, results };
|
|
118
|
-
const outDir = join(ROOT, "results", "latest");
|
|
119
|
-
mkdirSync(outDir, { recursive: true });
|
|
120
|
-
writeFileSync(join(outDir, "retrieval-results.json"), JSON.stringify(summary, null, 2));
|
|
121
|
-
console.log("\nResults written to results/latest/retrieval-results.json");
|
|
122
|
-
}
|
|
123
|
-
// ---------------------------------------------------------------------------
|
|
124
|
-
// Main
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
async function retrieveDocsForQuery(query, k = 10) {
|
|
127
|
-
const client = getSanityClient();
|
|
128
|
-
const results = await client.fetch(`
|
|
129
|
-
*[_type == "article" && !(_id in path("drafts.**"))]
|
|
130
|
-
| score(
|
|
131
|
-
boost(title match $query, 3),
|
|
132
|
-
boost(pt::text(content) match $query, 1)
|
|
133
|
-
)
|
|
134
|
-
| order(_score desc)
|
|
135
|
-
[0...$k] {
|
|
136
|
-
"slug": slug.current,
|
|
137
|
-
_score
|
|
138
|
-
}
|
|
139
|
-
`, { k, query });
|
|
140
|
-
return results.map((r) => r.slug);
|
|
141
|
-
}
|
|
142
|
-
main().catch((err) => {
|
|
143
|
-
console.error("Fatal error:", err);
|
|
144
|
-
process.exit(1);
|
|
145
|
-
});
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env tsx
|
|
2
|
-
/**
|
|
3
|
-
* Migration script: YAML tasks → Content Lake documents
|
|
4
|
-
*
|
|
5
|
-
* Reads all existing task definitions from tasks/*.yaml via YamlTaskSource,
|
|
6
|
-
* reference solution files from canonical/reference-solutions/, and creates
|
|
7
|
-
* corresponding ailf.featureArea, ailf.referenceSolution, and ailf.task
|
|
8
|
-
* documents in the Sanity Content Lake.
|
|
9
|
-
*
|
|
10
|
-
* Idempotent — uses createOrReplace with deterministic document IDs.
|
|
11
|
-
* Safe to run multiple times during development/testing.
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* cd packages/eval
|
|
15
|
-
* npx tsx src/scripts/migrate-tasks-to-content-lake.ts
|
|
16
|
-
* npx tsx src/scripts/migrate-tasks-to-content-lake.ts --dry-run
|
|
17
|
-
*
|
|
18
|
-
* Prerequisites:
|
|
19
|
-
* - SANITY_API_TOKEN (or AILF_REPORT_SANITY_API_TOKEN) with write access
|
|
20
|
-
* - SANITY_PROJECT_ID and SANITY_DATASET configured
|
|
21
|
-
*
|
|
22
|
-
* @see docs/archive/exec-plans/tasks-as-content/phase-3-migration.md
|
|
23
|
-
*/
|
|
24
|
-
export {};
|