UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

47 lines (46 loc) • 2.25 kB
/** * The file backend's ONE disclosure-seat guard: `@contract store.read_back_shape_judged`'s second legal * posture — an absence that DISCLOSES — rides a host's `onCorruptRead`, and the guard around it was * hand-written four times. Three copies contained an async sink's rejection; the mailbox's caught only a * synchronous throw, so an `async` sink there became an unhandled rejection. */ import type { CorruptBodyForm } from "../../core/store-contracts/read-back-shape-contract.js"; /** One disclosure. Every level carries `path` + `reason`; `kind` names the level. */ export type CorruptReadInfo = CorruptRecordRead | CorruptReplayTally | CorruptFileRead; /** One JSONL record a replay skipped: fired per skipped record, in file order, before its read's tally. */ export interface CorruptRecordRead { kind: "record"; path: string; reason: string; /** 1-based line of the skipped record. */ line: number; form: CorruptBodyForm; } /** * The count of one replay that skipped at least one record, fired once after its record disclosures; a * read that skipped nothing fires none. `total` = `kept` + `dropped` (an unterminated crash tail is not a * record); `kept === 0` = nothing in the file was readable. */ export interface CorruptReplayTally { kind: "replay"; path: string; reason: string; kept: number; dropped: number; total: number; } /** A disclosure about a file or directory as a whole, outside any JSONL replay. */ export interface CorruptFileRead { kind: "file"; path: string; reason: string; } /** * Wrap a host's disclosure seat: neither a synchronous throw nor an async rejection can re-introduce the * fault the fail-open avoids. `undefined` in ⇒ `undefined` out. Generic in the payload because the * session-policy store discloses session coordinates rather than a path. */ /** The sink is invoked UNBOUND (`this` is undefined): pass a bound function or an arrow, never a bare * method reference — a method reading `this` throws, and the throw is contained here, so the disclosure * is silently lost rather than surfaced. */ export declare function guardCorruptSink<I>(sink: ((info: I) => void) | undefined): ((info: I) => void) | undefined;