/** * FEAT-533 (+ FEAT-547 v2): LLM atom-triage tier — a batched, post- * extraction, pre-persist classification call that returns up to THREE * verdicts per atom in the SAME call: * * 1. keep|junk|meta-echo|capability-disclaimer|ephemeral|rephrase-of- * existing (FEAT-533, unchanged labels/semantics). * 2. `corrected_type` (FEAT-547, optional): a 7-class re-label, applied * post-triage ONLY when `confidence >= CORRECTED_TYPE_CONFIDENCE_GATE` * — see that constant's doc comment. Absent or under-gate leaves the * atom's original type untouched. * 3. `evidence_supported` (FEAT-547, optional): whether an evidence- * bearing atom's quote actually supports its claim (semantic check — * FEAT-542's mechanical quote-verification catches string mismatch; * this catches supported-string/unsupported-claim). Stored as a * queryable flag on the memory row; NEVER deletes or rewrites the atom. * * Layered ON TOP of the existing regex `durability-gate.ts` taxonomy at the * SAME insertion point (`src/distill/stages/08-embed-index.ts`'s * `embedAndIndex` loop) — the regex gate runs first (free, no LLM call), * this tier only ever sees survivors. * * Batching: a fixed ATOM-COUNT batch (`distill.atomTriage.batchSize`) over * the flat post-reduce/post-normalize atom stream for the WHOLE JOB, never * per chunk and never one call per atom — see * `Config['distill']['atomTriage']`'s doc comment for why (stage 6's * `reduce()` destroys chunk identity before this point). FEAT-547 v2 fuses * the two new verdicts into this SAME batched call rather than issuing * separate round-trips — a local clerk-role model should make ONE batched * judgment call per atom, not multiple (see FEAT-547 spec "Options * considered"), and fusing avoids doubling `maxPerRun`/wall-clock budget. * * Fail-open, mirroring `contradiction-judge.ts`'s posture exactly: a parse * failure or a thrown/rejected `chat()` call returns an EMPTY verdict map * rather than throwing — the caller (embedAndIndex) treats every atom with * no verdict entry as an implicit 'keep' (ADR-015: a broken triage provider * must never silently drop real atoms; it must fail loud in the log and * fail open in behavior). The SAME fail-open posture applies per-entry: a * single verdict entry with an invalid `corrected_type` label or malformed * `evidence_supported` value is dropped on its own (see * `TriageVerdictSchema` below) without discarding any other real verdict in * the same batch response. */ import type { LLMProvider, MemoryType } from '../contracts/index.js'; import { RunCapTracker } from '../util/run-cap-tracker.js'; /** * Stable marker embedded in the system prompt, mirroring * `CONTRADICTION_JUDGE_MARKER` (contradiction-judge.ts) — lets test mock * providers route a batched triage call to its own deterministic branch * BEFORE the `opts.json === true` extraction-call check would otherwise * misclassify it (extraction, the judge, and triage all ask for * `json: true`). */ export declare const ATOM_TRIAGE_MARKER = "astramem-atom-triage-v1"; export declare const TRIAGE_VERDICT_LABELS: readonly ["keep", "junk", "meta-echo", "capability-disclaimer", "ephemeral", "rephrase-of-existing"]; export type TriageVerdictLabel = (typeof TRIAGE_VERDICT_LABELS)[number]; /** * FEAT-547: 7-class atom-type taxonomy `corrected_type` may re-label an * atom into — the SAME closed enum `AtomSchema.type` uses * (`src/distill/prompts/extract.ts`), NOT the wider 10-value * `MEMORY_TYPES` union (`src/contracts/memory.ts`). A re-typing pass can * only assign a label the extractor itself is capable of producing; the 3 * cloud-only values (`preference`/`task_result`/`summary`) are deliberately * excluded, mirroring `extract.ts`'s own out-of-scope note for that same * split. */ export declare const CORRECTED_TYPE_LABELS: readonly ["decision", "fact", "lesson", "command", "todo", "note", "event"]; /** * FEAT-547 AC-2: confidence floor a `corrected_type` verdict must clear * before `embedAndIndex` overwrites an atom's stored type with it. Named * (not a magic number inline) per AC-2's explicit requirement. Measured * typeAcc (codex 63%, qwen2.5:7b 25-48%, phi 31-48%) means an ungated apply * would introduce as much mis-typing as it fixes for the weaker providers * — see FEAT-547 spec "Options considered" for why this gate is required, * not optional, and is applied per-atom against ONE shared `confidence` * value (the verdict's own, not a separate per-field confidence). */ export declare const CORRECTED_TYPE_CONFIDENCE_GATE = 0.8; export interface TriageVerdict { /** The position (in the ORIGINAL, whole-job atom stream) this verdict * applies to — echoed back by the model from the numbered prompt so the * caller can map a possibly-reordered/partial response back to the * right atom. */ index: number; verdict: TriageVerdictLabel; confidence: number; /** FEAT-547: optional re-label into the 7-class taxonomy above. Applied * by the caller (embedAndIndex) only when `confidence >= * CORRECTED_TYPE_CONFIDENCE_GATE`; absent (the overwhelming majority of * verdicts — most atoms are typed correctly on first pass) leaves the * atom's original type untouched. */ corrected_type?: MemoryType; /** FEAT-547: optional semantic evidence-support flag — only meaningful * for an atom whose `evidence` quote was included in this verdict's * input (see `TriageableAtom.evidence` below); the model is instructed * to omit this field for an atom with no evidence quote to judge. * `false` flags a queryable mismatch (evidence present but does not * actually support the claim) — the caller NEVER deletes or rewrites * the atom for this, only sets a flag. */ evidence_supported?: boolean; } export interface TriageableAtom { /** Position in the whole-job atom stream — echoed back in the verdict so * the caller can reassemble a Map keyed by this same index. */ index: number; text: string; /** FEAT-547: this atom's evidence quote (if any), shown alongside its * text so the model has something to judge `evidence_supported` * against. Omitted for an atom with no evidence — the prompt instructs * the model to omit `evidence_supported` for those, never guess. */ evidence?: string; } /** * Classify one batch of atoms in a single LLM call. Never throws — a parse * failure or a thrown/rejected `chat()` call is logged and resolves to an * EMPTY Map (fail-open: the caller treats every atom in this batch as an * implicit 'keep'). */ export declare function triageBatch(llm: LLMProvider, atoms: TriageableAtom[], opts?: { log?: (message: string) => void; }): Promise>; export interface AtomTriageCaps { /** Cap on triage LLM calls (batches, not atoms) for a SINGLE embedAndIndex * call. Mirrors `contradictionDetection.maxPerRun`. */ maxPerRun: number; /** Wall-clock cap (ms) on the entire triage sweep within a single * embedAndIndex call. Mirrors `contradictionDetection.maxWallClockMs` — * bounds worst-case duration against a slow/rate-limited provider, which * maxPerRun alone cannot (FEAT-482 lesson). */ maxWallClockMs: number; } /** * Per-job call-count + wall-clock tracker for the triage batch sweep. * Mirrors `DistillCostCapTracker` (src/distill/cost-cap.ts) exactly, minus * the `enabled` toggle — a caller only ever constructs this when * `distill.atomTriage.mode !== 'off'`, so there is no disabled state to * represent here (unlike the opt-in cost cap, which ships off by default * and needs to no-op). * * `shouldStop()` is checked BEFORE each batch's LLM call; once it trips, * every remaining un-triaged atom in this job falls through un-triaged — * the caller's "no verdict entry means keep" fail-open convention means * this is a graceful degrade to "persist unfiltered", never a * drop-by-timeout (FEAT-482 lesson, restated for this cap). */ export declare class AtomTriageRunTracker extends RunCapTracker { constructor(caps: AtomTriageCaps, log?: (message: string) => void); }