import { SandboxProviderCommand, ModalRouterProviderCommand, CommandSupervisionReceipt, type SessionEvent } from "@opengeni/contracts"; import { type Database } from "./database.js"; export type ProcessScope = { accountId: string; workspaceId: string; sessionId: string; processId: string; }; /** Bound to an already-authorized exact process scope by runtime wiring. */ export declare function retainedProviderCommandPersistence(db: Database, scope: ProcessScope, publish?: (events: SessionEvent[]) => Promise): { recordSupervisionReceipt: (receipt: SupervisionReceipt) => Promise; loadSupervisionReceipt: () => Promise<{ protocol: "native-subreaper-v1"; invocationId: string; receiptId: string; leaderExitCode: number; } | null>; requestCancellation: (reason: "provider_deadline" | "explicit_stop") => Promise; cancellationRequested: () => Promise; load: () => Promise<{ kind: "modal-router-v1"; sandboxId: string; taskId: string; execId: string; pty?: boolean | undefined; supervision?: { protocol: "native-subreaper-v1"; invocationId: string; nonce: string; controlPath: string; } | undefined; streams: { stdout: { byteOffset: number; utf8Remainder: string; eof: boolean; exitCode: number | null; }; stderr: { byteOffset: number; utf8Remainder: string; eof: boolean; exitCode: number | null; }; }; } | null>; reserveInput: (byteLength: number) => Promise; captureRouterPage: (page: RetainedRouterOutputPage) => Promise<{ command: { kind: "modal-router-v1"; sandboxId: string; taskId: string; execId: string; pty?: boolean | undefined; supervision?: { protocol: "native-subreaper-v1"; invocationId: string; nonce: string; controlPath: string; } | undefined; streams: { stdout: { byteOffset: number; utf8Remainder: string; eof: boolean; exitCode: number | null; }; stderr: { byteOffset: number; utf8Remainder: string; eof: boolean; exitCode: number | null; }; }; }; captured: boolean; }>; }; /** Promotion and the opaque provider locator commit together. Preserve the * existing durable-but-output-rejected promotion contract: its typed rejection * is rethrown only AFTER this outer transaction has committed the locator. */ export declare function createProviderCommandRetainer(promote: (db: Database, input: Input) => Promise, recoverDurablePromotion: (error: unknown) => Process | null): (db: Database, input: Input & { providerCommand?: SandboxProviderCommand | null; }) => Promise; export declare function getRetainedProviderCommand(db: Database, scope: ProcessScope): Promise; export type RetainedRouterOutputPage = { expected: ModalRouterProviderCommand; command: ModalRouterProviderCommand; stdout: string; stderr: string; }; export declare function validateRouterOutputAdvance(page: RetainedRouterOutputPage): void; /** Output past this many bytes of one stream is still read, so the command's * exit stays observable, but its middle is not recorded: a command that prints * without bound would otherwise grow the session event log without limit. The * final page is always recorded, so a trailing error or summary survives. * Live output returned to the agent is not affected. */ export declare const RECORDED_COMMAND_OUTPUT_LIMIT_BYTES: number; export declare function recordedCommandOutput(stream: "stdout" | "stderr", startOffset: number, endOffset: number, eof: boolean, text: string): string; /** Capture and offsets commit atomically. The session lock is acquired before * the process lock, matching the event-write lock order. A concurrent reader * with a stale cursor discards its page and reloads; it never appends overlapping * output or silently advances the other reader's cursor. */ export declare function captureRetainedRouterOutput(db: Database, scope: ProcessScope, page: RetainedRouterOutputPage): Promise<{ command: ModalRouterProviderCommand; events: SessionEvent[]; captured: boolean; }>; /** Reserve the next stdin byte range before dispatch and return its starting * offset. An ambiguous send consumes its range and is never silently replayed. */ export declare function reserveRetainedProviderInput(db: Database, scope: ProcessScope, byteLength: number): Promise; export type SupervisionReceipt = CommandSupervisionReceipt; /** Fail before provider start, not after discovering an unprotected DB at retention. */ export declare function supervisedCommandProtocolReady(db: Database): Promise; /** Only an authenticated control-channel receipt; never parsed stdout/stderr. * ACK the supervisor only after this transaction returns successfully. */ export declare function recordRetainedSupervisionReceipt(db: Database, scope: ProcessScope, receipt: SupervisionReceipt): Promise; export declare function loadRetainedSupervisionReceipt(db: Database, scope: ProcessScope): Promise; export declare function requestRetainedProcessCancellation(db: Database, scope: ProcessScope, reason: "provider_deadline" | "explicit_stop"): Promise; export declare function retainedProcessCancellationRequested(db: Database, scope: ProcessScope): Promise; /** Record deadline cancellation for an exact retained Modal command. Legacy * PTY callers send Ctrl-C first because cancellation fences stdin; non-PTY * callers only probe, since Ctrl-C would be data. An earlier explicit stop * remains immutable; the deadline uses its own clock. Lock order: process -> lease. */ export declare function requestRetainedProcessDeadlineCancellation(db: Database, scope: ProcessScope): Promise;