UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

44 lines (43 loc) • 3.27 kB
/** * The changed-files scan: the ONE reading of "which files this session read have moved on disk since" that every request * the engine owes a frame to asks — the turn boundary's bundle collection and a leg's first request (a fresh run's * first message, a resumed leg's continuation). One door, one scanner, one frame ({@link collectChangedFilesAttachment}): * the stations differ only in WHERE the frame rides, never in what is scanned. Whether the model was already told is asked * of the request's own view (the notice's record on its message, `request-copy-projection.ts`), never of a table here. */ import type { TaskSpec } from "../types.js"; import type { Prepared } from "./contracts.js"; /** One path the scan found moved on disk, with the modification time it was found at. */ export type ChangedFile = { path: string; mtimeMs: number; }; export interface ChangedFilesScanInput { /** The run's `spec.attachments` — the opt-in and the `maxFiles` knob. */ cfg: TaskSpec["attachments"]; /** The leg's scanner (`Prepared.detectExternalChanges`); absent without hands. */ detect: Prepared["detectExternalChanges"]; /** The leg's frame-receipt ledger: a changed-files frame already on its way to the next request (`frameCarried`) is not scanned for again. */ ledger: Prepared["frameReceipts"]; /** A request a settlement boundary precedes — a resumed leg with calls of its suspended batch still to run — is scanned for THERE, after * those calls ran, and answers true here: the request then owes no scan of its own, which would also hold the boundary's scan back as a frame * already on its way. Asked only when a scan is owed. */ settlesFirst?: () => Promise<boolean>; } /** * The scan this request owes, or `undefined` when it owes none: the opt-in is off, a frame is already on its way, or the leg * has no scanner. The answer is synchronous so a request that owes nothing costs no await and, above all, ZERO fileInfo calls * — OFF means literally nothing is stat'ed. Truthiness (not `!== undefined`): the type says `true | {maxFiles}`, but a JS * caller passing `false` must read as OFF, never as opted-in. The array (possibly empty) is every file found changed and not * read again — {@link collectChangedFilesAttachment} lists them all. */ export declare function scanChangedFiles(input: ChangedFilesScanInput): Promise<ChangedFile[]> | undefined; /** * The receipt step of a changed-files notice, once its message is in the session: `announce` (the notice's `steering_injected` * echo and its injected count) runs only when the request tells the model something with it — the request projection's * own answer ({@link lastNoticeCarried}) over the session's context with the notice's message last. A scan that finds the * same file changed and unread at every boundary mints a notice each time; the view carries each (path, modification time) * once, and so do the shell's display and the event store. A view that cannot be read announces (the notice was minted * to be told; the display saying more than the request is the safe side). */ export declare function announceWhenCarried(prepared: Pick<Prepared, "session" | "harness">, announce: () => void): () => Promise<void>;