@sanity/ailf 5.0.0 → 6.1.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 (115) hide show
  1. package/config/airbyte/ai_literacy_framework.connector.yaml +276 -0
  2. package/config/bigquery/views/synthesis_parse_failure_rate_7d.sql +42 -0
  3. package/config/diagnosis-cards.ts +318 -0
  4. package/config/models.ts +12 -0
  5. package/dist/_vendor/ailf-core/grader/failure-modes/agent-harness.d.ts +13 -0
  6. package/dist/_vendor/ailf-core/grader/failure-modes/agent-harness.js +16 -0
  7. package/dist/_vendor/ailf-core/grader/failure-modes/common.d.ts +14 -0
  8. package/dist/_vendor/ailf-core/grader/failure-modes/common.js +18 -0
  9. package/dist/_vendor/ailf-core/grader/failure-modes/index.d.ts +45 -0
  10. package/dist/_vendor/ailf-core/grader/failure-modes/index.js +109 -0
  11. package/dist/_vendor/ailf-core/grader/failure-modes/knowledge-probe.d.ts +13 -0
  12. package/dist/_vendor/ailf-core/grader/failure-modes/knowledge-probe.js +17 -0
  13. package/dist/_vendor/ailf-core/grader/failure-modes/literacy.d.ts +13 -0
  14. package/dist/_vendor/ailf-core/grader/failure-modes/literacy.js +17 -0
  15. package/dist/_vendor/ailf-core/grader/failure-modes/mcp.d.ts +13 -0
  16. package/dist/_vendor/ailf-core/grader/failure-modes/mcp.js +17 -0
  17. package/dist/_vendor/ailf-core/index.d.ts +1 -0
  18. package/dist/_vendor/ailf-core/index.js +4 -0
  19. package/dist/_vendor/ailf-core/ports/context.d.ts +12 -0
  20. package/dist/_vendor/ailf-core/schemas/eval-config.d.ts +7 -0
  21. package/dist/_vendor/ailf-core/schemas/eval-config.js +8 -0
  22. package/dist/_vendor/ailf-core/services/diagnosis/card-validators.d.ts +41 -0
  23. package/dist/_vendor/ailf-core/services/diagnosis/card-validators.js +40 -0
  24. package/dist/_vendor/ailf-core/services/diagnosis/cards/__tests__/area-summary.test.d.ts +7 -0
  25. package/dist/_vendor/ailf-core/services/diagnosis/cards/__tests__/area-summary.test.js +131 -0
  26. package/dist/_vendor/ailf-core/services/diagnosis/cards/__tests__/failure-mode-summary.test.d.ts +7 -0
  27. package/dist/_vendor/ailf-core/services/diagnosis/cards/__tests__/failure-mode-summary.test.js +230 -0
  28. package/dist/_vendor/ailf-core/services/diagnosis/cards/__tests__/no-issues.test.d.ts +7 -0
  29. package/dist/_vendor/ailf-core/services/diagnosis/cards/__tests__/no-issues.test.js +155 -0
  30. package/dist/_vendor/ailf-core/services/diagnosis/cards/area-summary.d.ts +17 -0
  31. package/dist/_vendor/ailf-core/services/diagnosis/cards/area-summary.js +43 -0
  32. package/dist/_vendor/ailf-core/services/diagnosis/cards/doc-attribution-spotlight.d.ts +46 -0
  33. package/dist/_vendor/ailf-core/services/diagnosis/cards/doc-attribution-spotlight.js +108 -0
  34. package/dist/_vendor/ailf-core/services/diagnosis/cards/failure-mode-summary.d.ts +28 -0
  35. package/dist/_vendor/ailf-core/services/diagnosis/cards/failure-mode-summary.js +140 -0
  36. package/dist/_vendor/ailf-core/services/diagnosis/cards/index.d.ts +49 -0
  37. package/dist/_vendor/ailf-core/services/diagnosis/cards/index.js +65 -0
  38. package/dist/_vendor/ailf-core/services/diagnosis/cards/low-confidence-attribution.d.ts +27 -0
  39. package/dist/_vendor/ailf-core/services/diagnosis/cards/low-confidence-attribution.js +93 -0
  40. package/dist/_vendor/ailf-core/services/diagnosis/cards/no-issues.d.ts +32 -0
  41. package/dist/_vendor/ailf-core/services/diagnosis/cards/no-issues.js +71 -0
  42. package/dist/_vendor/ailf-core/services/diagnosis/cards/regression-vs-baseline.d.ts +44 -0
  43. package/dist/_vendor/ailf-core/services/diagnosis/cards/regression-vs-baseline.js +130 -0
  44. package/dist/_vendor/ailf-core/services/diagnosis/cards/top-recommendations.d.ts +41 -0
  45. package/dist/_vendor/ailf-core/services/diagnosis/cards/top-recommendations.js +111 -0
  46. package/dist/_vendor/ailf-core/services/diagnosis/cards/weakest-area.d.ts +43 -0
  47. package/dist/_vendor/ailf-core/services/diagnosis/cards/weakest-area.js +118 -0
  48. package/dist/_vendor/ailf-core/services/diagnosis/prompt-builders.d.ts +72 -0
  49. package/dist/_vendor/ailf-core/services/diagnosis/prompt-builders.js +286 -0
  50. package/dist/_vendor/ailf-core/services/diagnosis/prompts/doc-attribution-spotlight.system.d.ts +17 -0
  51. package/dist/_vendor/ailf-core/services/diagnosis/prompts/doc-attribution-spotlight.system.js +58 -0
  52. package/dist/_vendor/ailf-core/services/diagnosis/prompts/index.d.ts +10 -0
  53. package/dist/_vendor/ailf-core/services/diagnosis/prompts/index.js +10 -0
  54. package/dist/_vendor/ailf-core/services/diagnosis/prompts/low-confidence-attribution.system.d.ts +15 -0
  55. package/dist/_vendor/ailf-core/services/diagnosis/prompts/low-confidence-attribution.system.js +53 -0
  56. package/dist/_vendor/ailf-core/services/diagnosis/prompts/regression-vs-baseline.system.d.ts +14 -0
  57. package/dist/_vendor/ailf-core/services/diagnosis/prompts/regression-vs-baseline.system.js +63 -0
  58. package/dist/_vendor/ailf-core/services/diagnosis/prompts/top-recommendations.system.d.ts +16 -0
  59. package/dist/_vendor/ailf-core/services/diagnosis/prompts/top-recommendations.system.js +78 -0
  60. package/dist/_vendor/ailf-core/services/diagnosis/prompts/weakest-area.system.d.ts +18 -0
  61. package/dist/_vendor/ailf-core/services/diagnosis/prompts/weakest-area.system.js +74 -0
  62. package/dist/_vendor/ailf-core/services/diagnosis/registry.d.ts +10 -0
  63. package/dist/_vendor/ailf-core/services/diagnosis/registry.js +10 -0
  64. package/dist/_vendor/ailf-core/services/diagnosis-runner.d.ts +119 -2
  65. package/dist/_vendor/ailf-core/services/diagnosis-runner.js +136 -2
  66. package/dist/_vendor/ailf-core/services/index.d.ts +5 -1
  67. package/dist/_vendor/ailf-core/services/index.js +15 -2
  68. package/dist/_vendor/ailf-core/services/llm-client-factory.d.ts +64 -0
  69. package/dist/_vendor/ailf-core/services/llm-client-factory.js +54 -0
  70. package/dist/_vendor/ailf-core/types/diagnosis.d.ts +115 -10
  71. package/dist/_vendor/ailf-core/types/diagnosis.js +3 -1
  72. package/dist/_vendor/ailf-core/types/index.d.ts +8 -1
  73. package/dist/_vendor/ailf-core/types/repo-config.d.ts +16 -0
  74. package/dist/_vendor/ailf-core/types/synthesis-telemetry.d.ts +101 -0
  75. package/dist/_vendor/ailf-core/types/synthesis-telemetry.js +18 -0
  76. package/dist/adapters/config-sources/file-config-adapter.js +8 -6
  77. package/dist/adapters/llm/fake-llm-client.d.ts +20 -0
  78. package/dist/adapters/llm/fake-llm-client.js +38 -1
  79. package/dist/adapters/llm/index.d.ts +1 -1
  80. package/dist/adapters/llm/index.js +1 -1
  81. package/dist/adapters/llm/openai-llm-client.js +59 -5
  82. package/dist/adapters/llm/retry.d.ts +18 -0
  83. package/dist/adapters/llm/retry.js +21 -0
  84. package/dist/adapters/synthesis/synthesis-telemetry-schema.d.ts +49 -0
  85. package/dist/adapters/synthesis/synthesis-telemetry-schema.js +55 -0
  86. package/dist/adapters/task-sources/content-lake-task-source.js +10 -5
  87. package/dist/adapters/task-sources/repo-schemas.d.ts +7 -0
  88. package/dist/adapters/task-sources/repo-schemas.js +10 -0
  89. package/dist/cli-program.js +3 -0
  90. package/dist/commands/interpret.d.ts +70 -0
  91. package/dist/commands/interpret.js +221 -0
  92. package/dist/commands/pipeline-action.d.ts +44 -0
  93. package/dist/commands/pipeline-action.js +193 -1
  94. package/dist/commands/run.d.ts +2 -0
  95. package/dist/commands/run.js +2 -0
  96. package/dist/composition-root.d.ts +21 -23
  97. package/dist/composition-root.js +107 -41
  98. package/dist/config/diagnosis-cards.ts +318 -0
  99. package/dist/config/models.ts +12 -0
  100. package/dist/grader/agent-harness.d.ts +5 -10
  101. package/dist/grader/agent-harness.js +5 -13
  102. package/dist/grader/common.d.ts +5 -13
  103. package/dist/grader/common.js +5 -17
  104. package/dist/grader/index.d.ts +15 -29
  105. package/dist/grader/index.js +15 -66
  106. package/dist/grader/knowledge-probe.d.ts +5 -10
  107. package/dist/grader/knowledge-probe.js +5 -14
  108. package/dist/grader/literacy.d.ts +5 -9
  109. package/dist/grader/literacy.js +5 -13
  110. package/dist/grader/mcp.d.ts +5 -10
  111. package/dist/grader/mcp.js +5 -14
  112. package/dist/orchestration/pipeline-orchestrator.js +3 -0
  113. package/dist/report-store.d.ts +26 -0
  114. package/dist/report-store.js +63 -0
  115. package/package.json +2 -2
@@ -1,75 +1,24 @@
1
1
  /**
2
2
  * Per-dimension failure-mode taxonomy barrel.
3
3
  *
4
+ * D-05: taxonomy data relocated to @sanity/ailf-core so card files in
5
+ * packages/core/src/services/diagnosis/cards/ can import without violating
6
+ * the core→eval import direction rule.
7
+ *
8
+ * This file is now a re-export shim — all behavior lives in
9
+ * packages/core/src/grader/failure-modes/. Existing eval-side callers
10
+ * (rubrics.ts, rubric-resolution.ts, calibration.test.ts) continue to
11
+ * work with zero source changes.
12
+ *
4
13
  * Named re-exports only (W0124 — never `export *`).
5
14
  *
6
15
  * Consumers:
7
- * - `packages/eval/config/rubrics.ts` — calls `failureModesForDimension()` to
8
- * stamp a per-template legal-mode list onto every rubric template entry.
9
- * - `packages/eval/src/pipeline/compiler/rubric-resolution.ts` — reads
10
- * `template.failureModes` at prompt-assembly time and announces the legal
11
- * modes to the grader before the structured-shape footer (Plan 03-01).
12
- * - `packages/eval/src/grader/__tests__/calibration.test.ts` — fixture-driven
13
- * ≥90% non-`unclassified` static calibration check (ROADMAP success
14
- * criterion 1).
16
+ * - `packages/eval/config/rubrics.ts` — calls `failureModesForDimension()`
17
+ * - `packages/eval/src/pipeline/compiler/rubric-resolution.ts`
18
+ * - `packages/eval/src/grader/__tests__/calibration.test.ts`
15
19
  *
20
+ * @see packages/core/src/grader/failure-modes/index.ts — canonical location
16
21
  * @see docs/design-docs/actionability-ladder/03-structured-grader-judgments.md
17
- * §"Per-dimension failure-mode taxonomies" (lines 239-283).
18
- * @see docs/decisions/D0005-grader-model-separation.md — single grader model;
19
- * taxonomies travel with the rubric prompt for reproducibility.
20
- */
21
- export { COMMON_FAILURE_MODES } from "./common.js";
22
- export { LITERACY_FAILURE_MODES } from "./literacy.js";
23
- export { MCP_FAILURE_MODES } from "./mcp.js";
24
- export { KP_FAILURE_MODES } from "./knowledge-probe.js";
25
- export { AGENT_FAILURE_MODES } from "./agent-harness.js";
26
- import { COMMON_FAILURE_MODES } from "./common.js";
27
- import { LITERACY_FAILURE_MODES } from "./literacy.js";
28
- import { MCP_FAILURE_MODES } from "./mcp.js";
29
- import { KP_FAILURE_MODES } from "./knowledge-probe.js";
30
- import { AGENT_FAILURE_MODES } from "./agent-harness.js";
31
- /**
32
- * Return the legal failure-mode list for a given rubric dimension.
33
- *
34
- * Accepts both family-level keys (`mcp-behavior`, `knowledge-probe`,
35
- * `agent-harness`) and the per-template `dimension` strings used in
36
- * `config/rubrics.ts` (`task-completion`, `input-validation`,
37
- * `factual-correctness`, `process-quality`, …). The cross-cutting
38
- * `COMMON_FAILURE_MODES` is always included.
39
- *
40
- * Unknown dimensions fall through to `COMMON_FAILURE_MODES` only — safe
41
- * default, the grader can still pick `unclassified`.
22
+ * @see docs/decisions/D0005-grader-model-separation.md
42
23
  */
43
- export function failureModesForDimension(dimension) {
44
- switch (dimension) {
45
- // ── Literacy family ──────────────────────────────────────
46
- case "task-completion":
47
- case "code-correctness":
48
- case "doc-coverage":
49
- return [...COMMON_FAILURE_MODES, ...LITERACY_FAILURE_MODES];
50
- // ── MCP family ───────────────────────────────────────────
51
- // `mcp-behavior` is the family-level key (profile / depends-on
52
- // shorthand). The per-template `dimension` strings are the four
53
- // entries from config/rubrics.ts mcp-* templates.
54
- case "mcp-behavior":
55
- case "input-validation":
56
- case "output-correctness":
57
- case "error-handling":
58
- case "security":
59
- return [...COMMON_FAILURE_MODES, ...MCP_FAILURE_MODES];
60
- // ── Knowledge-probe family ───────────────────────────────
61
- case "knowledge-probe":
62
- case "factual-correctness":
63
- case "completeness":
64
- case "currency":
65
- return [...COMMON_FAILURE_MODES, ...KP_FAILURE_MODES];
66
- // ── Agent-harness family ─────────────────────────────────
67
- case "agent-harness":
68
- case "process-quality":
69
- case "agent-output":
70
- case "tool-usage":
71
- return [...COMMON_FAILURE_MODES, ...AGENT_FAILURE_MODES];
72
- default:
73
- return COMMON_FAILURE_MODES;
74
- }
75
- }
24
+ export { AGENT_FAILURE_MODES, CANONICAL_DIMENSIONS, COMMON_FAILURE_MODES, KP_FAILURE_MODES, LITERACY_FAILURE_MODES, MCP_FAILURE_MODES, failureModesForDimension, isCanonicalFailureMode, } from "../_vendor/ailf-core/index.js";
@@ -1,14 +1,9 @@
1
1
  /**
2
- * Knowledge-probe failure modes — valid for the `knowledge-probe` dimension
3
- * family (factual-correctness, completeness, currency).
2
+ * Knowledge-probe failure modes — re-export shim (D-05).
4
3
  *
5
- * Phase 3 GRAD-03 (Plan 03-02). Knowledge-probe failures track the model's
6
- * ability to recall facts about Sanity's surface area; the v0 modes
7
- * differentiate factual errors from omissions, currency drift, and
8
- * hallucination.
4
+ * Canonical data relocated to @sanity/ailf-core.
5
+ * Existing callers of this file continue to work unchanged.
9
6
  *
10
- * @see docs/design-docs/actionability-ladder/03-structured-grader-judgments.md
11
- * §"Per-dimension failure-mode taxonomies" (lines 239-283).
7
+ * @see packages/core/src/grader/failure-modes/knowledge-probe.ts
12
8
  */
13
- export declare const KP_FAILURE_MODES: readonly ["factual-error", "incompleteness", "currency-violation", "hallucination"];
14
- export type KPFailureMode = (typeof KP_FAILURE_MODES)[number];
9
+ export { KP_FAILURE_MODES, type KPFailureMode } from "../_vendor/ailf-core/index.d.ts";
@@ -1,18 +1,9 @@
1
1
  /**
2
- * Knowledge-probe failure modes — valid for the `knowledge-probe` dimension
3
- * family (factual-correctness, completeness, currency).
2
+ * Knowledge-probe failure modes — re-export shim (D-05).
4
3
  *
5
- * Phase 3 GRAD-03 (Plan 03-02). Knowledge-probe failures track the model's
6
- * ability to recall facts about Sanity's surface area; the v0 modes
7
- * differentiate factual errors from omissions, currency drift, and
8
- * hallucination.
4
+ * Canonical data relocated to @sanity/ailf-core.
5
+ * Existing callers of this file continue to work unchanged.
9
6
  *
10
- * @see docs/design-docs/actionability-ladder/03-structured-grader-judgments.md
11
- * §"Per-dimension failure-mode taxonomies" (lines 239-283).
7
+ * @see packages/core/src/grader/failure-modes/knowledge-probe.ts
12
8
  */
13
- export const KP_FAILURE_MODES = [
14
- "factual-error", // assistant asserts something demonstrably false
15
- "incompleteness", // assistant covers part of the answer; misses key piece
16
- "currency-violation", // assistant cites stale facts beyond doc currency horizon
17
- "hallucination", // assistant invents details not present in any doc
18
- ];
9
+ export { KP_FAILURE_MODES } from "../_vendor/ailf-core/index.js";
@@ -1,13 +1,9 @@
1
1
  /**
2
- * Literacy failure modes — valid for `task-completion`, `code-correctness`,
3
- * `doc-coverage` (the literacy dimension family).
2
+ * Literacy failure modes — re-export shim (D-05).
4
3
  *
5
- * Phase 3 GRAD-03 (Plan 03-02). The v0 list is the four canonical
6
- * documentation-quality failure modes. Conservative on purpose; calibration
7
- * (Plan 03-02 Task 3) reveals whether expansion is needed in a follow-on.
4
+ * Canonical data relocated to @sanity/ailf-core.
5
+ * Existing callers of this file continue to work unchanged.
8
6
  *
9
- * @see docs/design-docs/actionability-ladder/03-structured-grader-judgments.md
10
- * §"Per-dimension failure-mode taxonomies" (lines 239-283).
7
+ * @see packages/core/src/grader/failure-modes/literacy.ts
11
8
  */
12
- export declare const LITERACY_FAILURE_MODES: readonly ["missing-docs", "outdated-docs", "incorrect-docs", "poor-structure"];
13
- export type LiteracyFailureMode = (typeof LITERACY_FAILURE_MODES)[number];
9
+ export { LITERACY_FAILURE_MODES, type LiteracyFailureMode, } from "../_vendor/ailf-core/index.d.ts";
@@ -1,17 +1,9 @@
1
1
  /**
2
- * Literacy failure modes — valid for `task-completion`, `code-correctness`,
3
- * `doc-coverage` (the literacy dimension family).
2
+ * Literacy failure modes — re-export shim (D-05).
4
3
  *
5
- * Phase 3 GRAD-03 (Plan 03-02). The v0 list is the four canonical
6
- * documentation-quality failure modes. Conservative on purpose; calibration
7
- * (Plan 03-02 Task 3) reveals whether expansion is needed in a follow-on.
4
+ * Canonical data relocated to @sanity/ailf-core.
5
+ * Existing callers of this file continue to work unchanged.
8
6
  *
9
- * @see docs/design-docs/actionability-ladder/03-structured-grader-judgments.md
10
- * §"Per-dimension failure-mode taxonomies" (lines 239-283).
7
+ * @see packages/core/src/grader/failure-modes/literacy.ts
11
8
  */
12
- export const LITERACY_FAILURE_MODES = [
13
- "missing-docs", // relevant doc didn't exist
14
- "outdated-docs", // doc reflects an older API/version
15
- "incorrect-docs", // doc states something factually wrong
16
- "poor-structure", // doc exists but is hard to find or follow
17
- ];
9
+ export { LITERACY_FAILURE_MODES, } from "../_vendor/ailf-core/index.js";
@@ -1,14 +1,9 @@
1
1
  /**
2
- * MCP failure modes — valid for the `mcp-behavior` dimension family
3
- * (input-validation, output-correctness, error-handling, security).
2
+ * MCP failure modes — re-export shim (D-05).
4
3
  *
5
- * Phase 3 GRAD-03 (Plan 03-02). `missing-docs` is intentionally re-exported
6
- * from the literacy family MCP server tasks frequently fail because the
7
- * MCP spec itself is under-documented; that's a literacy failure even when
8
- * surfaced through MCP grading.
4
+ * Canonical data relocated to @sanity/ailf-core.
5
+ * Existing callers of this file continue to work unchanged.
9
6
  *
10
- * @see docs/design-docs/actionability-ladder/03-structured-grader-judgments.md
11
- * §"Per-dimension failure-mode taxonomies" (lines 239-283).
7
+ * @see packages/core/src/grader/failure-modes/mcp.ts
12
8
  */
13
- export declare const MCP_FAILURE_MODES: readonly ["spec-mismatch", "missing-error-handling", "over-privileged", "missing-docs"];
14
- export type MCPFailureMode = (typeof MCP_FAILURE_MODES)[number];
9
+ export { MCP_FAILURE_MODES, type MCPFailureMode } from "../_vendor/ailf-core/index.d.ts";
@@ -1,18 +1,9 @@
1
1
  /**
2
- * MCP failure modes — valid for the `mcp-behavior` dimension family
3
- * (input-validation, output-correctness, error-handling, security).
2
+ * MCP failure modes — re-export shim (D-05).
4
3
  *
5
- * Phase 3 GRAD-03 (Plan 03-02). `missing-docs` is intentionally re-exported
6
- * from the literacy family MCP server tasks frequently fail because the
7
- * MCP spec itself is under-documented; that's a literacy failure even when
8
- * surfaced through MCP grading.
4
+ * Canonical data relocated to @sanity/ailf-core.
5
+ * Existing callers of this file continue to work unchanged.
9
6
  *
10
- * @see docs/design-docs/actionability-ladder/03-structured-grader-judgments.md
11
- * §"Per-dimension failure-mode taxonomies" (lines 239-283).
7
+ * @see packages/core/src/grader/failure-modes/mcp.ts
12
8
  */
13
- export const MCP_FAILURE_MODES = [
14
- "spec-mismatch", // tool/server output doesn't match published MCP spec
15
- "missing-error-handling", // tool failure path under-documented or absent
16
- "over-privileged", // tool exposes operations the doc didn't sanction
17
- "missing-docs", // re-export from literacy (cross-cutting)
18
- ];
9
+ export { MCP_FAILURE_MODES } from "../_vendor/ailf-core/index.js";
@@ -275,6 +275,9 @@ export async function orchestratePipeline(ctx, steps) {
275
275
  belowCritical: state.belowCritical,
276
276
  durationMs,
277
277
  promptfooUrls: state.promptfooUrls,
278
+ // Phase 6 / DIAG-06 — thread reportId from state so the post-run hook in
279
+ // pipeline-action.ts can target the published Content Lake document.
280
+ reportId: state.reportId,
278
281
  steps: results,
279
282
  success: true,
280
283
  testSummary: state.testSummary,
@@ -15,6 +15,7 @@
15
15
  * @see docs/design-docs/report-store/domain-model.md
16
16
  */
17
17
  import type { SanityClient } from "@sanity/client";
18
+ import type { SynthesisCostTelemetry } from "./_vendor/ailf-core/index.d.ts";
18
19
  import type { ComparisonReport, ISOTimestamp, LineageQuery, Report, ReportId, ReportProvenance, ScoreSummary } from "./pipeline/types.js";
19
20
  /**
20
21
  * Result of an auto-comparison, bundling the ComparisonReport with the
@@ -89,6 +90,22 @@ export declare class ReportStore {
89
90
  * @see docs/design-docs/report-store/architecture.md — Auto-comparison
90
91
  */
91
92
  findComparableBaseline(query: LineageQuery): Promise<null | Report>;
93
+ /**
94
+ * Fetch the most recent report from the Content Lake.
95
+ *
96
+ * Mirrors the API gateway's `ReportStoreApi.latest()` signature
97
+ * (`packages/api/src/lib/sanity.ts`). Used by `ailf interpret latest`
98
+ * when no explicit report ID is supplied.
99
+ *
100
+ * @param query Optional narrowing by `mode` and/or `source.name`.
101
+ * @returns The most recent matching report, or null if none exist
102
+ * or on API failure. Schema-validation errors are advisory (logged
103
+ * and null-returned) per the same rationale as `findByFingerprint`.
104
+ */
105
+ latest(query?: {
106
+ mode?: string;
107
+ source?: string;
108
+ }): Promise<null | Report>;
92
109
  /**
93
110
  * Read a report by its ID.
94
111
  *
@@ -108,6 +125,15 @@ export declare class ReportStore {
108
125
  * runtime schema gate. Schema drift is a bug, not an outage.
109
126
  */
110
127
  write(report: Report): Promise<null | ReportId>;
128
+ /**
129
+ * Patch synthesis telemetry onto a published report (Phase 6 / DIAG-06).
130
+ * Non-fatal on Sanity failure — the on-disk reportSnapshot artifact
131
+ * remains the source of truth. Mirrors `write()` (L379–411) for
132
+ * error handling.
133
+ *
134
+ * Document _id is `report-${reportId}` (see `toSanityReportDoc` L559).
135
+ */
136
+ patchSynthesis(reportId: ReportId, telemetry: SynthesisCostTelemetry): Promise<void>;
111
137
  /**
112
138
  * Query error arrays from the last N reports for chronic failure detection.
113
139
  *
@@ -207,6 +207,50 @@ export class ReportStore {
207
207
  return null;
208
208
  }
209
209
  }
210
+ /**
211
+ * Fetch the most recent report from the Content Lake.
212
+ *
213
+ * Mirrors the API gateway's `ReportStoreApi.latest()` signature
214
+ * (`packages/api/src/lib/sanity.ts`). Used by `ailf interpret latest`
215
+ * when no explicit report ID is supplied.
216
+ *
217
+ * @param query Optional narrowing by `mode` and/or `source.name`.
218
+ * @returns The most recent matching report, or null if none exist
219
+ * or on API failure. Schema-validation errors are advisory (logged
220
+ * and null-returned) per the same rationale as `findByFingerprint`.
221
+ */
222
+ async latest(query) {
223
+ try {
224
+ let groq = `*[_type == $type`;
225
+ const params = { type: REPORT_TYPE };
226
+ if (query?.mode) {
227
+ groq += ` && provenance.mode == $mode`;
228
+ params.mode = query.mode;
229
+ }
230
+ if (query?.source) {
231
+ groq += ` && provenance.source.name == $source`;
232
+ params.source = query.source;
233
+ }
234
+ groq += `] | order(completedAt desc) [0]`;
235
+ const doc = await this.client.fetch(groq, params);
236
+ return doc ? toReport(doc) : null;
237
+ }
238
+ catch (error) {
239
+ // Advisory lookup — a malformed prior doc must not break a read-only
240
+ // CLI invocation. Log and return null so the caller surfaces a
241
+ // user-friendly "no report found" error instead of a Zod stack trace.
242
+ if (error instanceof ReportSchemaValidationError) {
243
+ logAdvisoryQuerySchemaFailure({
244
+ query: "latest",
245
+ context: { mode: query?.mode, sourceName: query?.source },
246
+ error,
247
+ });
248
+ return null;
249
+ }
250
+ console.warn(` ⚠️ Failed to fetch latest report from Sanity: ${error instanceof Error ? error.message : String(error)}`);
251
+ return null;
252
+ }
253
+ }
210
254
  /**
211
255
  * Read a report by its ID.
212
256
  *
@@ -264,6 +308,25 @@ export class ReportStore {
264
308
  return null;
265
309
  }
266
310
  }
311
+ /**
312
+ * Patch synthesis telemetry onto a published report (Phase 6 / DIAG-06).
313
+ * Non-fatal on Sanity failure — the on-disk reportSnapshot artifact
314
+ * remains the source of truth. Mirrors `write()` (L379–411) for
315
+ * error handling.
316
+ *
317
+ * Document _id is `report-${reportId}` (see `toSanityReportDoc` L559).
318
+ */
319
+ async patchSynthesis(reportId, telemetry) {
320
+ try {
321
+ await this.client
322
+ .patch(`report-${reportId}`)
323
+ .set({ "summary.synthesis": { diagnosis: telemetry } })
324
+ .commit();
325
+ }
326
+ catch (error) {
327
+ console.warn(` ⚠️ Failed to patch synthesis telemetry on report ${reportId}: ${error instanceof Error ? error.message : String(error)}`);
328
+ }
329
+ }
267
330
  /**
268
331
  * Query error arrays from the last N reports for chronic failure detection.
269
332
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ailf",
3
- "version": "5.0.0",
3
+ "version": "6.1.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -61,7 +61,7 @@
61
61
  },
62
62
  "scripts": {
63
63
  "build": "tsc && tsc -p tsconfig.scripts.json && tsx scripts/bundle-workspace-deps.ts",
64
- "generate-configs": "tsx src/cli.ts generate-configs",
64
+ "generate-configs": "tsx src/cli.ts generate-configs && tsx scripts/generate-diagnosis-config.ts",
65
65
  "fetch-docs": "tsx src/cli.ts fetch-docs",
66
66
  "measure-retrieval": "tsx src/cli.ts measure-retrieval",
67
67
  "eval": "tsx src/cli.ts eval",