UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

82 lines • 5.35 kB
/** * The manifest write side: `createTerminalManifestStore` plus `TerminalManifestWriter`, * persisting ONLY lifecycle transitions and debounced checkpoints of the record shaped in * `terminal-manifest-model.ts` — never per-line output and never a runtime handle. */ import { type SidecarStore } from "../../../session-sidecar-store.ts"; import type { MonitorSnapshotEntry } from "./monitor-registry.ts"; import { type ManifestBackgroundSession, type ManifestMonitor, type MonitorRegistration, type TerminalManifest, type TerminalManifestCheckpoint, type TerminalManifestRpcCheckpoint, type TerminalManifestSession } from "./terminal-manifest-model.ts"; export type { CommandMonitorSpec, FileMonitorSpec, ManifestBackgroundSession, ManifestMonitor, MonitorDurabilityClass, MonitorRegistration, MonitorRuntimeKind, MonitorSpec, TerminalManifest, TerminalManifestCheckpoint, TerminalManifestSession, } from "./terminal-manifest-model.ts"; export { DURABLE_MONITOR_EXPIRY_MS, TERMINAL_MANIFEST_CHECKPOINT_DEBOUNCE_MS, TERMINAL_MANIFEST_VERSION, } from "./terminal-manifest-model.ts"; export declare function createTerminalManifestStore(session: TerminalManifestSession): SidecarStore<TerminalManifest>; export declare class TerminalManifestWriter { #private; readonly store: SidecarStore<TerminalManifest>; /** Last persist failure: transitions never reject, so a durability write can never fail a live tool call. */ persistFailure: unknown; constructor(options: { session: TerminalManifestSession; debounceMs?: number; now?: () => number; }); recordRegister(registration: MonitorRegistration): Promise<void>; /** * Re-adopt an entry a restore handler just brought back to life, so THIS generation's * in-memory map owns it again. Without this, the writer starts every generation empty and * the next persist (a register, a background start, a checkpoint flush, recordShutdown) * rewrites the manifest WITHOUT the restored monitors — the monitor survives one restart * and is erased on the second. * * Every persisted field is preserved verbatim, notably `createdAt` and `expiresAt`: the * durability deadline is set once at registration and a restore NEVER extends it. Only * `suspended` is cleared, because the monitor is live again in this process. * * Deliberately does NOT write: re-adoption is not a state transition, it is recovery of * state already on disk. The entry reaches the file again on the restore's own next * persist (the file class's checkpoint, any later transition, or recordShutdown), so a * restart costs zero extra writes and the write-on-transition invariant holds. */ adoptRestored(entry: ManifestMonitor): void; /** * Write the post-restore truth once: re-spawned watches carry their new runtime identity (so * the NEXT crash stops them instead of starting copies), and entries that did not come back * are gone (so they are never re-run). With nothing left, the manifest file is removed. */ persistRestored(): Promise<void>; /** * Reload seam (SF-2): a reload generation starts with an empty writer, and its first * transition would rewrite the manifest without the entries the previous generation * recorded. Seed the live (non-suspended) entries and background sessions from disk * without writing; a corrupt or absent manifest seeds nothing. */ seedFromDisk(): Promise<void>; /** * Live durable-monitor count for admission control: entries that survive a restart. * Ephemeral entries are never counted, so any number of one-shot watches can coexist * with the durable ones. */ durableCount(): number; /** * Reconcile a registry transition snapshot (the bundle's single onChange consumer * forwards it here): settle removes entries, pause/resume/rearm flips deliveryPaused. * An entry missing its stable monitorId throws — never silently skipped; entries not * registered through the tool call site are left alone (durability spec unknown). */ observeMonitorState(snapshot: readonly MonitorSnapshotEntry[]): Promise<void>; /** Debounced checkpoint persist: a burst inside the window collapses into one write. */ scheduleCheckpoint(monitorId: string, checkpoint: TerminalManifestCheckpoint): void; /** An rpc watch's view (hosts, statuses), debounced like a file checkpoint. */ scheduleRpcCheckpoint(monitorId: string, checkpoint: TerminalManifestRpcCheckpoint): void; /** Drain: apply any pending checkpoints and await every in-flight write. */ flush(): Promise<void>; /** Shutdown transition: flush checkpoints and mark every live monitor suspended in one write. */ recordShutdown(): Promise<void>; /** * A graceful close (oh-my-openagent#14313): the session ended on request, so its monitors and background jobs stop * for good. Nothing is left to re-run on a reopen, and the manifest file goes away with the last entry. */ recordClosed(): Promise<void>; recordBackgroundStart(id: string, command: string, startedAtMs?: number, runtime?: ManifestBackgroundSession["runtime"]): Promise<void>; recordBackgroundExit(id: string): Promise<void>; } //# sourceMappingURL=terminal-manifest.d.ts.map