/**
 * per-entry-attribution-writer.ts — Zod schema for the per-judgment
 * attribution artifact (ATTR-01) emitted by Phase 4's
 * `ComputeAttributionStep` and read back by Phase 5's diagnosis runner.
 *
 * The schema asserts `satisfies z.ZodType<JudgmentAttribution>` against
 * the canonical domain type in `packages/core/src/types/attribution.ts`
 * (D0045 / W0187) — drift between schema and type is a build error.
 *
 * Phase 1 lands the SHAPE only — no compute, no file I/O. Phase 4 wires
 * the writer; Phase 5 wires the reader. Both `satisfies` against this
 * single source-of-truth schema.
 *
 * `hallucinationCheckedAgainst` is REQUIRED (Pitfall #11): consumers
 * must be able to audit citation grounding without re-deriving the
 * resolvable-set. The canonical task field is `contextDocs`; do NOT
 * invent `expectedDocs` / `usedDocs` synonyms.
 *
 * @see docs/decisions/D0045-type-architecture-and-contract-enforcement.md
 * @see docs/decisions/D0049-shared-confidence-contract.md
 * @see docs/decisions/D0052-judgment-ref-granularity.md
 * @see docs/design-docs/actionability-ladder/04-per-document-attribution-ensemble.md
 */
import { z } from "zod";
import { ConfidenceSchema } from "../../_vendor/ailf-core/schemas/index.js";
const DocAttributionSchema = z.object({
    documentId: z.string().min(1),
    slug: z.string().optional(),
    score: z.number().min(0).max(1),
    signals: z.object({
        citation: z.number().min(0).max(1).optional(),
        canonical: z.number().min(0).max(1).optional(),
        retrieved: z.number().min(0).max(1).optional(),
    }),
    confidence: ConfidenceSchema,
});
/**
 * Canonical schema for {@link JudgmentAttribution}. Persisted at
 * `runs/{runId}/attribution/{entryKey}.json` (Phase 4) and parsed by
 * the diagnosis runner on read (Phase 5).
 */
export const JudgmentAttributionSchema = z.object({
    judgmentRef: z.string().min(1),
    taskId: z.string().min(1),
    modelId: z.string().min(1),
    dimension: z.string().min(1),
    attributions: z.array(DocAttributionSchema),
    hallucinationCheckedAgainst: z.array(z.string()),
});
