@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.
Files changed (173) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_vendor/ailf-core/examples/index.d.ts +50 -1
  3. package/dist/_vendor/ailf-core/examples/index.js +66 -1
  4. package/dist/agent-harness/assertions-runtime.d.ts +49 -0
  5. package/dist/agent-harness/assertions-runtime.js +138 -0
  6. package/dist/agent-harness/provider.d.ts +58 -0
  7. package/dist/agent-harness/provider.js +104 -0
  8. package/dist/cli.js +0 -0
  9. package/dist/commands/init.js +3 -0
  10. package/dist/orchestration/steps/generate-configs-step.d.ts +7 -0
  11. package/dist/orchestration/steps/generate-configs-step.js +35 -2
  12. package/dist/pipeline/compiler/__tests__/agent-harness-handler.test.js +39 -25
  13. package/dist/pipeline/compiler/compiler-to-yaml.js +78 -7
  14. package/dist/pipeline/compiler/mode-handlers/agent-harness/assertions.d.ts +9 -0
  15. package/dist/pipeline/compiler/mode-handlers/agent-harness/assertions.js +28 -85
  16. package/dist/pipeline/compiler/mode-handlers/agent-harness/compiler.js +22 -15
  17. package/dist/pipeline/compiler/mode-handlers/agent-harness/sandbox.d.ts +8 -1
  18. package/dist/pipeline/compiler/mode-handlers/agent-harness/sandbox.js +42 -12
  19. package/package.json +25 -24
  20. package/dist/_vendor/ailf-core/__tests__/comparison-formatters.test.d.ts +0 -10
  21. package/dist/_vendor/ailf-core/__tests__/comparison-formatters.test.js +0 -185
  22. package/dist/_vendor/ailf-core/artifact-capture/__tests__/noop-collector.test.d.ts +0 -6
  23. package/dist/_vendor/ailf-core/artifact-capture/__tests__/noop-collector.test.js +0 -42
  24. package/dist/_vendor/ailf-tasks/cli.d.ts +0 -8
  25. package/dist/_vendor/ailf-tasks/cli.js +0 -61
  26. package/dist/_vendor/ailf-tasks/index.d.ts +0 -13
  27. package/dist/_vendor/ailf-tasks/index.js +0 -16
  28. package/dist/_vendor/ailf-tasks/parser.d.ts +0 -27
  29. package/dist/_vendor/ailf-tasks/parser.js +0 -73
  30. package/dist/_vendor/ailf-tasks/schemas.d.ts +0 -198
  31. package/dist/_vendor/ailf-tasks/schemas.js +0 -180
  32. package/dist/_vendor/ailf-tasks/validation.d.ts +0 -47
  33. package/dist/_vendor/ailf-tasks/validation.js +0 -162
  34. package/dist/adapters/task-sources/yaml-task-source.d.ts +0 -18
  35. package/dist/adapters/task-sources/yaml-task-source.js +0 -139
  36. package/dist/agent-observer/test-imports.d.ts +0 -7
  37. package/dist/agent-observer/test-imports.js +0 -185
  38. package/dist/commands/update-quality-scores.d.ts +0 -5
  39. package/dist/commands/update-quality-scores.js +0 -20
  40. package/dist/lib/agent-behavior-report.d.ts +0 -8
  41. package/dist/lib/agent-behavior-report.js +0 -185
  42. package/dist/lib/baseline.d.ts +0 -19
  43. package/dist/lib/baseline.js +0 -153
  44. package/dist/lib/calculate-scores.d.ts +0 -23
  45. package/dist/lib/calculate-scores.js +0 -42
  46. package/dist/lib/compare.d.ts +0 -18
  47. package/dist/lib/compare.js +0 -170
  48. package/dist/lib/coverage-audit.d.ts +0 -4
  49. package/dist/lib/coverage-audit.js +0 -42
  50. package/dist/lib/discovery-report.d.ts +0 -13
  51. package/dist/lib/discovery-report.js +0 -57
  52. package/dist/lib/fetch-docs.d.ts +0 -30
  53. package/dist/lib/fetch-docs.js +0 -171
  54. package/dist/lib/generate-configs.d.ts +0 -25
  55. package/dist/lib/generate-configs.js +0 -42
  56. package/dist/lib/grader-api.d.ts +0 -21
  57. package/dist/lib/grader-api.js +0 -34
  58. package/dist/lib/grader-compare.d.ts +0 -19
  59. package/dist/lib/grader-compare.js +0 -91
  60. package/dist/lib/grader-consistency.d.ts +0 -27
  61. package/dist/lib/grader-consistency.js +0 -79
  62. package/dist/lib/grader-sensitivity.d.ts +0 -19
  63. package/dist/lib/grader-sensitivity.js +0 -75
  64. package/dist/lib/grader-validate.d.ts +0 -19
  65. package/dist/lib/grader-validate.js +0 -78
  66. package/dist/lib/measure-retrieval.d.ts +0 -14
  67. package/dist/lib/measure-retrieval.js +0 -71
  68. package/dist/lib/pr-comment.d.ts +0 -16
  69. package/dist/lib/pr-comment.js +0 -28
  70. package/dist/lib/readiness-report.d.ts +0 -13
  71. package/dist/lib/readiness-report.js +0 -108
  72. package/dist/lib/webhook-server.d.ts +0 -11
  73. package/dist/lib/webhook-server.js +0 -24
  74. package/dist/lib/weekly-digest.d.ts +0 -24
  75. package/dist/lib/weekly-digest.js +0 -148
  76. package/dist/orchestration/env-bridge.d.ts +0 -21
  77. package/dist/orchestration/env-bridge.js +0 -66
  78. package/dist/orchestration/steps/fetch-docs-shell.d.ts +0 -17
  79. package/dist/orchestration/steps/fetch-docs-shell.js +0 -30
  80. package/dist/pipeline/compiler/__tests__/task-bridge.test.d.ts +0 -9
  81. package/dist/pipeline/compiler/__tests__/task-bridge.test.js +0 -339
  82. package/dist/pipeline/compiler/mode-handlers/agent-harness-handler.d.ts +0 -70
  83. package/dist/pipeline/compiler/mode-handlers/agent-harness-handler.js +0 -485
  84. package/dist/pipeline/compiler/mode-handlers/knowledge-probe-handler.d.ts +0 -76
  85. package/dist/pipeline/compiler/mode-handlers/knowledge-probe-handler.js +0 -245
  86. package/dist/pipeline/compiler/mode-handlers/literacy-handler.d.ts +0 -89
  87. package/dist/pipeline/compiler/mode-handlers/literacy-handler.js +0 -379
  88. package/dist/pipeline/compiler/mode-handlers/mcp-assertions.d.ts +0 -50
  89. package/dist/pipeline/compiler/mode-handlers/mcp-assertions.js +0 -334
  90. package/dist/pipeline/compiler/mode-handlers/mcp-server-handler.d.ts +0 -69
  91. package/dist/pipeline/compiler/mode-handlers/mcp-server-handler.js +0 -307
  92. package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider.d.ts +0 -65
  93. package/dist/pipeline/compiler/mode-handlers/mcp-tool-provider.js +0 -368
  94. package/dist/pipeline/compiler/task-bridge.d.ts +0 -41
  95. package/dist/pipeline/compiler/task-bridge.js +0 -92
  96. package/dist/pipeline/expand-tasks.d.ts +0 -232
  97. package/dist/pipeline/expand-tasks.js +0 -467
  98. package/dist/pipeline/generate-configs.d.ts +0 -92
  99. package/dist/pipeline/generate-configs.js +0 -445
  100. package/dist/pipeline/steps/calculate-scores-step.d.ts +0 -11
  101. package/dist/pipeline/steps/calculate-scores-step.js +0 -89
  102. package/dist/pipeline/steps/compare-step.d.ts +0 -18
  103. package/dist/pipeline/steps/compare-step.js +0 -90
  104. package/dist/pipeline/steps/eval-step.d.ts +0 -53
  105. package/dist/pipeline/steps/eval-step.js +0 -347
  106. package/dist/pipeline/steps/fetch-docs-step.d.ts +0 -11
  107. package/dist/pipeline/steps/fetch-docs-step.js +0 -84
  108. package/dist/pipeline/steps/generate-configs-step.d.ts +0 -11
  109. package/dist/pipeline/steps/generate-configs-step.js +0 -98
  110. package/dist/pipeline/steps/grader-consistency-step.d.ts +0 -21
  111. package/dist/pipeline/steps/grader-consistency-step.js +0 -74
  112. package/dist/pipeline/steps/publish-report-step.d.ts +0 -57
  113. package/dist/pipeline/steps/publish-report-step.js +0 -243
  114. package/dist/pipeline/steps/report-step.d.ts +0 -13
  115. package/dist/pipeline/steps/report-step.js +0 -56
  116. package/dist/pipeline/steps/update-scores-step.d.ts +0 -11
  117. package/dist/pipeline/steps/update-scores-step.js +0 -42
  118. package/dist/scripts/agent-behavior-report.d.ts +0 -19
  119. package/dist/scripts/agent-behavior-report.js +0 -315
  120. package/dist/scripts/baseline.d.ts +0 -43
  121. package/dist/scripts/baseline.js +0 -267
  122. package/dist/scripts/calculate-scores.d.ts +0 -166
  123. package/dist/scripts/calculate-scores.js +0 -1296
  124. package/dist/scripts/compare.d.ts +0 -22
  125. package/dist/scripts/compare.js +0 -334
  126. package/dist/scripts/coverage-audit.d.ts +0 -44
  127. package/dist/scripts/coverage-audit.js +0 -209
  128. package/dist/scripts/debug-eval.d.ts +0 -19
  129. package/dist/scripts/debug-eval.js +0 -73
  130. package/dist/scripts/discovery-report.d.ts +0 -58
  131. package/dist/scripts/discovery-report.js +0 -250
  132. package/dist/scripts/fetch-docs.d.ts +0 -35
  133. package/dist/scripts/fetch-docs.js +0 -472
  134. package/dist/scripts/generate-configs.d.ts +0 -66
  135. package/dist/scripts/generate-configs.js +0 -459
  136. package/dist/scripts/grader-api.d.ts +0 -27
  137. package/dist/scripts/grader-api.js +0 -206
  138. package/dist/scripts/grader-compare.d.ts +0 -22
  139. package/dist/scripts/grader-compare.js +0 -368
  140. package/dist/scripts/grader-consistency.d.ts +0 -20
  141. package/dist/scripts/grader-consistency.js +0 -313
  142. package/dist/scripts/grader-sensitivity.d.ts +0 -22
  143. package/dist/scripts/grader-sensitivity.js +0 -354
  144. package/dist/scripts/grader-validate.d.ts +0 -19
  145. package/dist/scripts/grader-validate.js +0 -267
  146. package/dist/scripts/measure-retrieval.d.ts +0 -10
  147. package/dist/scripts/measure-retrieval.js +0 -145
  148. package/dist/scripts/migrate-tasks-to-content-lake.d.ts +0 -24
  149. package/dist/scripts/migrate-tasks-to-content-lake.js +0 -328
  150. package/dist/scripts/pipeline.d.ts +0 -76
  151. package/dist/scripts/pipeline.js +0 -1031
  152. package/dist/scripts/pr-comment.d.ts +0 -10
  153. package/dist/scripts/pr-comment.js +0 -510
  154. package/dist/scripts/readiness-report.d.ts +0 -88
  155. package/dist/scripts/readiness-report.js +0 -342
  156. package/dist/scripts/update-quality-scores.d.ts +0 -15
  157. package/dist/scripts/update-quality-scores.js +0 -184
  158. package/dist/scripts/validate-task-sources.d.ts +0 -21
  159. package/dist/scripts/validate-task-sources.js +0 -210
  160. package/dist/scripts/validate.d.ts +0 -13
  161. package/dist/scripts/validate.js +0 -79
  162. package/dist/scripts/webhook-server.d.ts +0 -26
  163. package/dist/scripts/webhook-server.js +0 -147
  164. package/dist/scripts/weekly-digest.d.ts +0 -24
  165. package/dist/scripts/weekly-digest.js +0 -144
  166. package/dist/sinks/format-slack.d.ts +0 -64
  167. package/dist/sinks/format-slack.js +0 -306
  168. package/dist/sinks/slack-sink.d.ts +0 -27
  169. package/dist/sinks/slack-sink.js +0 -78
  170. package/dist/sinks/webhook-sink.d.ts +0 -19
  171. package/dist/sinks/webhook-sink.js +0 -50
  172. package/tasks/.expanded.agentic.yaml +0 -280
  173. package/tasks/.expanded.yaml +0 -565
@@ -1,98 +0,0 @@
1
- /**
2
- * Pipeline step: Generate promptfoo config files from config/models.yaml.
3
- *
4
- * Preconditions: config/models.yaml is valid
5
- * Postconditions: promptfooconfig*.yaml files exist
6
- *
7
- * Cache key: config/models.yaml + config/sources.yaml + tasks/*.yaml
8
- * Cache outputs: promptfooconfig*.yaml files
9
- */
10
- import { execSync } from "child_process";
11
- import { dirname, resolve } from "path";
12
- import { fileURLToPath } from "url";
13
- import { getStepInputPaths, hashFiles, lookupCache, recordCache, } from "../cache.js";
14
- import { checkGeneratedConfigsExist } from "../checks.js";
15
- import { validateModelsYaml } from "../validate.js";
16
- const __dirname = dirname(fileURLToPath(import.meta.url));
17
- const ROOT = resolve(__dirname, "..", "..", "..");
18
- export function runGenerateConfigs(source, noCache = false) {
19
- const start = Date.now();
20
- // Precondition: config/models.yaml must be valid
21
- const modelIssues = validateModelsYaml(ROOT);
22
- const errors = modelIssues.filter((i) => i.severity === "error");
23
- if (errors.length > 0) {
24
- return {
25
- durationMs: Date.now() - start,
26
- error: `config/models.yaml validation failed: ${errors.map((e) => e.message).join("; ")}`,
27
- status: "failed",
28
- };
29
- }
30
- // Cache check — include filter env vars so scoped runs don't reuse
31
- // cached results from unscoped (or differently-scoped) runs.
32
- const filterContext = buildFilterContext();
33
- if (!noCache) {
34
- const cacheResult = lookupCache(ROOT, "generate-configs", filterContext);
35
- if (cacheResult.hit) {
36
- return {
37
- durationMs: Date.now() - start,
38
- status: "success",
39
- summary: `Skipped (cached) — ${cacheResult.entry.summary}`,
40
- };
41
- }
42
- }
43
- // Execute
44
- try {
45
- const sourceArg = source ? ` --source ${source}` : "";
46
- execSync(`pnpm generate-configs${sourceArg}`, {
47
- cwd: ROOT,
48
- env: process.env,
49
- stdio: "inherit",
50
- });
51
- }
52
- catch (err) {
53
- return {
54
- durationMs: Date.now() - start,
55
- error: `generate-configs failed: ${err instanceof Error ? err.message : String(err)}`,
56
- status: "failed",
57
- };
58
- }
59
- // Postcondition: config files exist
60
- const configIssues = checkGeneratedConfigsExist(ROOT);
61
- const configErrors = configIssues.filter((i) => i.severity === "error");
62
- if (configErrors.length > 0) {
63
- return {
64
- durationMs: Date.now() - start,
65
- error: `Postcondition failed: ${configErrors.map((e) => e.message).join("; ")}`,
66
- status: "failed",
67
- };
68
- }
69
- const durationMs = Date.now() - start;
70
- const summary = "Generated promptfoo config files";
71
- // Record cache
72
- if (!noCache) {
73
- const inputPaths = getStepInputPaths(ROOT, "generate-configs");
74
- const inputHash = hashFiles(inputPaths, filterContext);
75
- const outputPaths = [
76
- "promptfooconfig.yaml",
77
- "promptfooconfig.observed.yaml",
78
- "promptfooconfig.agentic.yaml",
79
- ];
80
- recordCache(ROOT, "generate-configs", inputHash, summary, durationMs, outputPaths);
81
- }
82
- return { durationMs, status: "success", summary };
83
- }
84
- /**
85
- * Build cache context strings from filter environment variables.
86
- * When EVAL_FILTER_AREAS or EVAL_FILTER_TASKS are set, they become part
87
- * of the cache key so that differently-scoped runs don't share cache entries.
88
- */
89
- function buildFilterContext() {
90
- const context = [];
91
- if (process.env.EVAL_FILTER_AREAS) {
92
- context.push(`areas:${process.env.EVAL_FILTER_AREAS}`);
93
- }
94
- if (process.env.EVAL_FILTER_TASKS) {
95
- context.push(`tasks:${process.env.EVAL_FILTER_TASKS}`);
96
- }
97
- return context;
98
- }
@@ -1,21 +0,0 @@
1
- /**
2
- * Pipeline step: Measure grader consistency via replicated grading.
3
- *
4
- * This step is OPTIONAL — it only runs when --grader-replications N is passed.
5
- * It re-runs grading assertions N additional times on the same model responses
6
- * and measures score variance across replications.
7
- *
8
- * Preconditions: eval-results.json exists (model responses to re-grade)
9
- * Postconditions: grader-consistency.json written to results/latest/
10
- *
11
- * Not cached: Each run involves fresh API calls to the grader model.
12
- * The whole point is to measure variance, so caching would defeat the purpose.
13
- */
14
- import type { EvalMode, StepResult } from "../types.js";
15
- /**
16
- * Run grader consistency analysis.
17
- *
18
- * @param replications Number of additional grading replications (default: 5)
19
- * @param mode Eval mode — determines which results file to read
20
- */
21
- export declare function runGraderConsistency(replications?: number, mode?: EvalMode): StepResult;
@@ -1,74 +0,0 @@
1
- /**
2
- * Pipeline step: Measure grader consistency via replicated grading.
3
- *
4
- * This step is OPTIONAL — it only runs when --grader-replications N is passed.
5
- * It re-runs grading assertions N additional times on the same model responses
6
- * and measures score variance across replications.
7
- *
8
- * Preconditions: eval-results.json exists (model responses to re-grade)
9
- * Postconditions: grader-consistency.json written to results/latest/
10
- *
11
- * Not cached: Each run involves fresh API calls to the grader model.
12
- * The whole point is to measure variance, so caching would defeat the purpose.
13
- */
14
- import { execSync } from "child_process";
15
- import { existsSync } from "fs";
16
- import { dirname, resolve } from "path";
17
- import { fileURLToPath } from "url";
18
- import { checkResultsExist } from "../checks.js";
19
- import { RESULTS_FILES } from "./eval-step.js";
20
- const __dirname = dirname(fileURLToPath(import.meta.url));
21
- const ROOT = resolve(__dirname, "..", "..", "..");
22
- /**
23
- * Run grader consistency analysis.
24
- *
25
- * @param replications Number of additional grading replications (default: 5)
26
- * @param mode Eval mode — determines which results file to read
27
- */
28
- export function runGraderConsistency(replications = 5, mode = "baseline") {
29
- const start = Date.now();
30
- // For full mode, use baseline results for grader consistency analysis
31
- const concreteMode = mode === "full" ? "baseline" : mode;
32
- const resultsFile = RESULTS_FILES[concreteMode];
33
- const resultsIssues = checkResultsExist(ROOT, resultsFile);
34
- const resultsErrors = resultsIssues.filter((i) => i.severity === "error");
35
- if (resultsErrors.length > 0) {
36
- return {
37
- durationMs: Date.now() - start,
38
- error: `Results missing: ${resultsErrors.map((e) => e.message).join("; ")}. Run eval first.`,
39
- status: "failed",
40
- };
41
- }
42
- // Execute
43
- try {
44
- execSync(`tsx src/lib/grader-consistency.ts --replications ${replications} --results ${resultsFile}`, {
45
- cwd: ROOT,
46
- env: process.env,
47
- stdio: "inherit",
48
- });
49
- }
50
- catch (err) {
51
- const code = err !== null && typeof err === "object" && "status" in err
52
- ? err.status
53
- : 1;
54
- return {
55
- durationMs: Date.now() - start,
56
- error: `grader-consistency failed with exit code ${code}`,
57
- status: "failed",
58
- };
59
- }
60
- // Postcondition: output file exists
61
- const outputPath = resolve(ROOT, "results", "latest", "grader-consistency.json");
62
- if (!existsSync(outputPath)) {
63
- return {
64
- durationMs: Date.now() - start,
65
- error: "grader-consistency.json was not created",
66
- status: "failed",
67
- };
68
- }
69
- return {
70
- durationMs: Date.now() - start,
71
- status: "success",
72
- summary: `Grader consistency analysis complete (${replications} replications)`,
73
- };
74
- }
@@ -1,57 +0,0 @@
1
- /**
2
- * Pipeline step: Publish evaluation report to the report store.
3
- *
4
- * This step wraps ScoreSummary + provenance into a Report, writes it to
5
- * the Sanity Content Lake (system of record), optionally auto-compares
6
- * against the most recent comparable baseline, and fans out to configured
7
- * sinks (BigQuery, Slack, webhooks, etc.).
8
- *
9
- * Opt-in via `--publish` flag or `AILF_PUBLISH=1` environment variable.
10
- * Without this flag, the pipeline writes results locally only (unchanged
11
- * from current behavior).
12
- *
13
- * Design principles:
14
- * - P1: Reports are immutable events (write-once to Sanity)
15
- * - P5: Local-first (pipeline never fails because of a store write)
16
- * - P6: Sinks are fire-and-forget (failures logged, not thrown)
17
- *
18
- * Preconditions: score-summary.json exists and is valid
19
- * Postconditions: Report written to Sanity (best-effort), sinks notified
20
- *
21
- * @see docs/design-docs/report-store/architecture.md
22
- * @see docs/design-docs/report-store/sink-architecture.md
23
- */
24
- import { type ProvenanceInput } from "../provenance.js";
25
- import type { PromptfooUrlEntry, StepResult } from "../types.js";
26
- export interface PublishOptions {
27
- /** Whether this is a debug run (debug runs don't store fingerprints) */
28
- debug?: boolean;
29
- /** Evaluation fingerprint override (computed externally by the pipeline) */
30
- evalFingerprint?: string;
31
- /** @deprecated Use `promptfooUrls` — kept for backward compatibility */
32
- promptfooUrl?: string;
33
- /** Per-mode Promptfoo share URLs */
34
- promptfooUrls?: PromptfooUrlEntry[];
35
- /** Override provenance input (for testing or custom workflows) */
36
- provenanceInput?: Partial<ProvenanceInput>;
37
- /** Sanity dataset for report storage (independent of eval dataset) */
38
- reportDataset?: string;
39
- /** Sanity project ID for report storage (independent of eval project) */
40
- reportProjectId?: string;
41
- /** Sanity API token for writes */
42
- sanityToken?: string;
43
- /** Optional human-supplied tag */
44
- tag?: string;
45
- }
46
- /**
47
- * Run the publish-report pipeline step.
48
- *
49
- * 1. Read score-summary.json
50
- * 2. Build provenance from pipeline context
51
- * 3. Create Report with generated UUID v7 ID
52
- * 4. Auto-compare against most recent comparable baseline
53
- * 5. Write to Sanity Content Lake (system of record)
54
- * 6. Fan out to configured sinks (fire-and-forget)
55
- * 7. Return step result with report ID and sink outcomes
56
- */
57
- export declare function runPublishReport(pipelineStart: number, options?: PublishOptions): Promise<StepResult>;
@@ -1,243 +0,0 @@
1
- /**
2
- * Pipeline step: Publish evaluation report to the report store.
3
- *
4
- * This step wraps ScoreSummary + provenance into a Report, writes it to
5
- * the Sanity Content Lake (system of record), optionally auto-compares
6
- * against the most recent comparable baseline, and fans out to configured
7
- * sinks (BigQuery, Slack, webhooks, etc.).
8
- *
9
- * Opt-in via `--publish` flag or `AILF_PUBLISH=1` environment variable.
10
- * Without this flag, the pipeline writes results locally only (unchanged
11
- * from current behavior).
12
- *
13
- * Design principles:
14
- * - P1: Reports are immutable events (write-once to Sanity)
15
- * - P5: Local-first (pipeline never fails because of a store write)
16
- * - P6: Sinks are fire-and-forget (failures logged, not thrown)
17
- *
18
- * Preconditions: score-summary.json exists and is valid
19
- * Postconditions: Report written to Sanity (best-effort), sinks notified
20
- *
21
- * @see docs/design-docs/report-store/architecture.md
22
- * @see docs/design-docs/report-store/sink-architecture.md
23
- */
24
- import { readFileSync } from "fs";
25
- import { dirname, resolve } from "path";
26
- import { fileURLToPath } from "url";
27
- import { checkScoreSummaryValid } from "../checks.js";
28
- import { buildProvenance } from "../provenance.js";
29
- import { generateReportId, ReportStore } from "../../report-store.js";
30
- import { loadSinks } from "../../sinks/index.js";
31
- import { withRetry } from "../../sinks/retry.js";
32
- const __dirname = dirname(fileURLToPath(import.meta.url));
33
- const ROOT = resolve(__dirname, "..", "..", "..");
34
- /**
35
- * Run the publish-report pipeline step.
36
- *
37
- * 1. Read score-summary.json
38
- * 2. Build provenance from pipeline context
39
- * 3. Create Report with generated UUID v7 ID
40
- * 4. Auto-compare against most recent comparable baseline
41
- * 5. Write to Sanity Content Lake (system of record)
42
- * 6. Fan out to configured sinks (fire-and-forget)
43
- * 7. Return step result with report ID and sink outcomes
44
- */
45
- export async function runPublishReport(pipelineStart, options = {}) {
46
- const start = Date.now();
47
- // Precondition: score summary exists
48
- const summaryIssues = checkScoreSummaryValid(ROOT);
49
- const summaryErrors = summaryIssues.filter((i) => i.severity === "error");
50
- if (summaryErrors.length > 0) {
51
- return {
52
- durationMs: Date.now() - start,
53
- error: `Score summary missing: ${summaryErrors.map((e) => e.message).join("; ")}`,
54
- status: "failed",
55
- };
56
- }
57
- // Read score summary
58
- let summary;
59
- try {
60
- const summaryPath = resolve(ROOT, "results", "latest", "score-summary.json");
61
- summary = JSON.parse(readFileSync(summaryPath, "utf-8"));
62
- }
63
- catch (err) {
64
- return {
65
- durationMs: Date.now() - start,
66
- error: `Failed to read score-summary.json: ${err instanceof Error ? err.message : String(err)}`,
67
- status: "failed",
68
- };
69
- }
70
- // Build provenance
71
- const provenanceInput = buildProvenanceInput(summary, options);
72
- const provenance = buildProvenance(provenanceInput);
73
- // Create report
74
- const now = new Date().toISOString();
75
- const reportId = generateReportId();
76
- const durationMs = Date.now() - pipelineStart;
77
- // Initialize report store — uses AILF_REPORT_* env vars, independent of
78
- // SANITY_DATASET/SANITY_PROJECT_ID which control doc evaluation.
79
- const token = options.sanityToken ??
80
- process.env.AILF_REPORT_SANITY_API_TOKEN ??
81
- process.env.SANITY_API_TOKEN;
82
- const dataset = options.reportDataset ?? process.env.AILF_REPORT_DATASET ?? undefined;
83
- const projectId = options.reportProjectId ?? process.env.AILF_REPORT_PROJECT_ID ?? undefined;
84
- const store = new ReportStore({ dataset, projectId, token });
85
- // Auto-compare against most recent comparable baseline
86
- const comparison = await store.autoCompare(summary, provenance, now);
87
- const report = {
88
- comparison: comparison ?? undefined,
89
- completedAt: now,
90
- durationMs,
91
- id: reportId,
92
- provenance,
93
- summary,
94
- tag: options.tag,
95
- };
96
- // Write to Sanity (system of record — best-effort, P5)
97
- const sanityResult = await store.write(report);
98
- // Load and run sinks (fire-and-forget, P6)
99
- const publishResult = await runSinks(report);
100
- // Build result summary
101
- const parts = [];
102
- if (sanityResult) {
103
- parts.push(`report:${sanityResult}`);
104
- }
105
- else {
106
- parts.push("Sanity write skipped (no token or unreachable)");
107
- }
108
- if (comparison) {
109
- const delta = comparison.deltas.overall;
110
- const sign = delta >= 0 ? "+" : "";
111
- parts.push(`vs baseline: ${sign}${delta.toFixed(1)}`);
112
- }
113
- if (publishResult.sinkResults.length > 0) {
114
- const succeeded = publishResult.sinkResults.filter((r) => r.result.status === "success").length;
115
- const total = publishResult.sinkResults.length;
116
- parts.push(`sinks: ${succeeded}/${total}`);
117
- }
118
- return {
119
- durationMs: Date.now() - start,
120
- status: "success",
121
- summary: `Published — ${parts.join(", ")}`,
122
- };
123
- }
124
- // ---------------------------------------------------------------------------
125
- // Sink runner
126
- // ---------------------------------------------------------------------------
127
- /**
128
- * Assemble provenance input from the score summary and pipeline context.
129
- */
130
- function buildProvenanceInput(summary, options) {
131
- const areas = summary.scores.map((s) => s.feature);
132
- const mode = (process.env.EVAL_MODE ?? "baseline");
133
- // Read document IDs from env (set by pipeline.ts from --sanity-document flags)
134
- const docIds = process.env.SANITY_DOCUMENT_IDS;
135
- const sanityDocumentIds = docIds
136
- ? docIds
137
- .split(",")
138
- .map((id) => id.trim())
139
- .filter(Boolean)
140
- : undefined;
141
- // Read task filter from env
142
- const taskFilter = process.env.EVAL_FILTER_TASKS;
143
- const taskIds = taskFilter
144
- ? taskFilter
145
- .split(",")
146
- .map((t) => t.trim())
147
- .filter(Boolean)
148
- : undefined;
149
- // Build source from summary metadata or env
150
- const source = {
151
- baseUrl: summary.source?.baseUrl ?? "https://www.sanity.io/docs",
152
- dataset: summary.source?.dataset ?? process.env.SANITY_DATASET ?? "next",
153
- documentIds: [],
154
- llmsTxt: (summary.source?.baseUrl ?? "https://www.sanity.io/docs") + "/llms.txt",
155
- name: summary.source?.name ?? "production",
156
- perspective: summary.source?.perspective ??
157
- process.env.SANITY_PERSPECTIVE ??
158
- undefined,
159
- priorityDomain: "sanity.io",
160
- projectId: summary.source?.projectId ?? process.env.SANITY_PROJECT_ID ?? "3do82whm",
161
- studioOrigin: "https://admin.sanity.io",
162
- urls: [],
163
- };
164
- // Pass through eval fingerprint for cross-environment cache lookup.
165
- // Debug runs don't store fingerprints (they evaluate a subset of tests
166
- // and would produce misleading cache hits for full runs).
167
- const evalFingerprint = !options.debug ? options.evalFingerprint : undefined;
168
- return {
169
- areas,
170
- evalFingerprint,
171
- mode,
172
- promptfooUrl: options.promptfooUrl,
173
- promptfooUrls: options.promptfooUrls,
174
- rootDir: ROOT,
175
- sanityDocumentIds,
176
- source,
177
- taskIds,
178
- ...options.provenanceInput,
179
- };
180
- }
181
- // ---------------------------------------------------------------------------
182
- // Provenance input builder
183
- // ---------------------------------------------------------------------------
184
- /**
185
- * Fan out a report to all configured sinks.
186
- *
187
- * Sinks are loaded from config/sinks.yaml. Each sink is run with retry
188
- * logic (3 attempts, exponential backoff). Failures are logged but never
189
- * block the pipeline.
190
- */
191
- async function runSinks(report) {
192
- const sinks = loadSinks();
193
- const sinkResults = [];
194
- if (sinks.length === 0) {
195
- return { report, sinkResults };
196
- }
197
- // Health check all sinks first (non-blocking)
198
- for (const sink of sinks) {
199
- if (sink.healthCheck) {
200
- try {
201
- const health = await sink.healthCheck();
202
- if (!health.healthy) {
203
- console.warn(` ⚠️ Sink ${sink.name} health check failed: ${health.reason}`);
204
- }
205
- }
206
- catch (err) {
207
- console.warn(` ⚠️ Sink ${sink.name} health check error: ${err instanceof Error ? err.message : String(err)}`);
208
- }
209
- }
210
- }
211
- // Publish to all sinks in parallel (fire-and-forget with retries)
212
- const settled = await Promise.allSettled(sinks.map(async (sink) => {
213
- const result = await withRetry(() => sink.publish(report));
214
- return { name: sink.name, result };
215
- }));
216
- for (const outcome of settled) {
217
- if (outcome.status === "fulfilled") {
218
- sinkResults.push(outcome.value);
219
- const { name, result } = outcome.value;
220
- if (result.status === "failed") {
221
- console.warn(` ⚠️ Sink ${name} failed: ${result.error}`);
222
- }
223
- else if (result.status === "skipped") {
224
- console.log(` ⏭️ Sink ${name} skipped: ${result.reason}`);
225
- }
226
- else {
227
- console.log(` ✅ Sink ${name} delivered${result.detail ? ` (${result.detail})` : ""}`);
228
- }
229
- }
230
- else {
231
- // Promise.allSettled rejection — shouldn't happen with withRetry, but just in case
232
- const error = outcome.reason instanceof Error
233
- ? outcome.reason.message
234
- : String(outcome.reason);
235
- sinkResults.push({
236
- name: "unknown",
237
- result: { error, status: "failed" },
238
- });
239
- console.warn(` ⚠️ Sink delivery error: ${error}`);
240
- }
241
- }
242
- return { report, sinkResults };
243
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Pipeline step: Generate PR comment / report from scores.
3
- *
4
- * Preconditions: score-summary.json exists
5
- * Postconditions: report markdown generated
6
- *
7
- * Cache key: results/latest/score-summary.json
8
- * Note: Report is always regenerated (not cached) since it may include
9
- * dynamic data like Promptfoo URLs. The cache infrastructure is wired up
10
- * for consistency but reports are cheap to generate.
11
- */
12
- import type { StepResult } from "../types.js";
13
- export declare function runReport(outputPath?: string, promptfooUrl?: string): StepResult;
@@ -1,56 +0,0 @@
1
- /**
2
- * Pipeline step: Generate PR comment / report from scores.
3
- *
4
- * Preconditions: score-summary.json exists
5
- * Postconditions: report markdown generated
6
- *
7
- * Cache key: results/latest/score-summary.json
8
- * Note: Report is always regenerated (not cached) since it may include
9
- * dynamic data like Promptfoo URLs. The cache infrastructure is wired up
10
- * for consistency but reports are cheap to generate.
11
- */
12
- import { execSync } from "child_process";
13
- import { dirname, resolve } from "path";
14
- import { fileURLToPath } from "url";
15
- import { checkScoreSummaryValid } from "../checks.js";
16
- const __dirname = dirname(fileURLToPath(import.meta.url));
17
- const ROOT = resolve(__dirname, "..", "..", "..");
18
- const DEFAULT_REPORT_PATH = resolve(ROOT, "results/latest/pr-comment.md");
19
- export function runReport(outputPath, promptfooUrl) {
20
- const start = Date.now();
21
- // Precondition: score summary exists
22
- const summaryIssues = checkScoreSummaryValid(ROOT);
23
- const summaryErrors = summaryIssues.filter((i) => i.severity === "error");
24
- if (summaryErrors.length > 0) {
25
- return {
26
- durationMs: Date.now() - start,
27
- error: `Score summary missing: ${summaryErrors.map((e) => e.message).join("; ")}`,
28
- status: "failed",
29
- };
30
- }
31
- // Always write to a file — use the caller's path or a default.
32
- // This avoids dumping the full PR-comment markdown into the terminal.
33
- const resolvedOutput = outputPath ?? DEFAULT_REPORT_PATH;
34
- // Execute — reports are always regenerated (cheap, may include dynamic URLs)
35
- try {
36
- const outputArg = ` --output ${resolvedOutput}`;
37
- const urlArg = promptfooUrl ? ` --promptfoo-url ${promptfooUrl}` : "";
38
- execSync(`pnpm pr-comment${outputArg}${urlArg}`, {
39
- cwd: ROOT,
40
- env: process.env,
41
- stdio: ["inherit", "ignore", "inherit"],
42
- });
43
- }
44
- catch (err) {
45
- return {
46
- durationMs: Date.now() - start,
47
- error: `pr-comment failed: ${err instanceof Error ? err.message : String(err)}`,
48
- status: "failed",
49
- };
50
- }
51
- return {
52
- durationMs: Date.now() - start,
53
- status: "success",
54
- summary: `Report written to ${resolvedOutput}`,
55
- };
56
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Pipeline step: Update QUALITY_SCORE.md from score summary.
3
- *
4
- * Preconditions: score-summary.json exists and is valid
5
- * Postconditions: QUALITY_SCORE.md is updated with latest scores
6
- *
7
- * Note: Not cached — writing to a git-tracked file is intentionally
8
- * always re-executed to ensure the file reflects the latest scores.
9
- */
10
- import type { StepResult } from "../types.js";
11
- export declare function runUpdateQualityScores(): Promise<StepResult>;
@@ -1,42 +0,0 @@
1
- /**
2
- * Pipeline step: Update QUALITY_SCORE.md from score summary.
3
- *
4
- * Preconditions: score-summary.json exists and is valid
5
- * Postconditions: QUALITY_SCORE.md is updated with latest scores
6
- *
7
- * Note: Not cached — writing to a git-tracked file is intentionally
8
- * always re-executed to ensure the file reflects the latest scores.
9
- */
10
- import { dirname, resolve } from "path";
11
- import { fileURLToPath } from "url";
12
- import { checkScoreSummaryValid } from "../checks.js";
13
- const __dirname = dirname(fileURLToPath(import.meta.url));
14
- const ROOT = resolve(__dirname, "..", "..", "..");
15
- export async function runUpdateQualityScores() {
16
- const start = Date.now();
17
- // Precondition: score summary exists and is valid
18
- const summaryIssues = checkScoreSummaryValid(ROOT);
19
- const summaryErrors = summaryIssues.filter((i) => i.severity === "error");
20
- if (summaryErrors.length > 0) {
21
- return {
22
- durationMs: Date.now() - start,
23
- error: `Score summary missing or invalid: ${summaryErrors.map((e) => e.message).join("; ")}`,
24
- status: "failed",
25
- };
26
- }
27
- // Dynamic import to avoid loading file-writing code at module parse time
28
- const { updateQualityScores } = await import("../../scripts/update-quality-scores.js");
29
- const result = updateQualityScores();
30
- if (!result.success) {
31
- return {
32
- durationMs: Date.now() - start,
33
- error: result.message,
34
- status: "failed",
35
- };
36
- }
37
- return {
38
- durationMs: Date.now() - start,
39
- status: "success",
40
- summary: result.message,
41
- };
42
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * agent-behavior-report.ts
3
- *
4
- * Standalone script that reads Promptfoo evaluation results containing
5
- * agent behavior observation data and generates a detailed report.
6
- *
7
- * This provides deeper analysis than the summary included in the main
8
- * calculate-scores report, including:
9
- *
10
- * - Per-task behavior breakdown (which specific pages each task visited)
11
- * - Canonical doc coverage (did the agent find the "right" docs?)
12
- * - Request timeline and latency analysis
13
- * - Search strategy analysis
14
- * - Cross-task navigation pattern detection
15
- *
16
- * Usage:
17
- * tsx src/scripts/agent-behavior-report.ts [results-path]
18
- */
19
- import "dotenv/config";