/** * Librarian — the knowledge write arbiter for iranti. * * All mutations to the knowledge store flow through `librarianWrite`. The * function enforces a multi-layer conflict resolution pipeline before any row * is created, updated, or escalated: * * 1. Input validation — clamp confidence, block future `validFrom`, enforce * write permissions (`guards.ts`), and check the `attendant_state` guard. * 2. Idempotency (M-2) — claim a `writeReceipt` slot before executing; replay * if the requestId was already processed. * 3. Identity lock — advisory Postgres xact lock + in-process queue per * `(entityType, entityId, key)` so concurrent writers serialise. * 4. Conflict resolution (in priority order): * a. No existing entry → contextual conflict check then create. * b. Direct user personal-memory correction → always replaces. * c. Checkpoint continuity keys → replace without scoring. * d. Equal confidence + same source → accept latest. * e. Temporal tiebreak (validFrom) → newer wins. * f. Authoritative source overrides → per-key policy. * g. Score gap ≥ threshold → higher score wins. * h. Close scores → LLM arbitration with sibling evidence (S4) or escalate. * 5. Escalation — unresolvable conflicts write a markdown file to the active * escalation folder for human review; the Archivist later consumes * `**Status:** RESOLVED` files. * 6. Post-write verification — immediate read-back check; emits staff event. * 7. Shared-state invalidation broadcast — notifies other processes that the * entity has changed. * * `librarianIngest` is the bulk ingestion path: it calls the chunker to * extract structured facts from raw text, then writes each fact via `librarianWrite`. */ import { EntryInput } from '../types'; import { KnowledgeEntry } from '../generated/prisma/client'; import { ChunkInput } from './chunker'; type WriteAction = 'created' | 'updated' | 'escalated' | 'rejected'; export declare function librarianWrite(input: EntryInput): Promise<{ action: WriteAction; entry?: KnowledgeEntry; reason: string; idempotentReplay?: boolean; }>; export declare function librarianIngest(input: ChunkInput): Promise<{ extractedCandidates: number; written: number; rejected: number; escalated: number; skippedMalformed: number; reason?: string; results: Array<{ key: string; action: string; reason: string; }>; }>; export {}; //# sourceMappingURL=index.d.ts.map