import { type Server } from "node:http"; import { type H2ALaunchContext, type H2AReplayGuard, type H2ASignature } from "@sentropic/h2a"; import type { LocalStore } from "../local-files/store.js"; import { type RelauncherRuntime } from "../drumbeat/relaunchers.js"; export interface H2ADriveInstructionPayload { readonly from: string; readonly to: string; readonly instruction: string; readonly nonce: string; readonly at: string; } export interface FormatSignedDriveInstructionOptions { readonly from: string; readonly to: string; readonly instruction: string; readonly privateKeyPem: string; readonly nonce?: string; readonly at?: string; readonly now?: () => number; } export interface ParsedSignedDriveInstruction { readonly payload: H2ADriveInstructionPayload; readonly signature: H2ASignature; } export type H2ADriveVerifyReason = "malformed" | "no-public-key" | "bad-signature" | "invalid-timestamp" | "expired" | "future" | "replayed"; export type H2ADriveVerifyResult = { readonly ok: true; readonly payload: H2ADriveInstructionPayload; } | { readonly ok: false; readonly reason: H2ADriveVerifyReason; }; export interface VerifySignedDriveInstructionOptions { readonly resolvePublicKeys: (instance: string) => readonly string[]; readonly guard: H2AReplayGuard; readonly now?: number; } export type H2ADriveAuthorizeReason = "missing-registration" | "unauthorized"; export type H2ADriveAuthorizeResult = { readonly ok: true; } | { readonly ok: false; readonly reason: H2ADriveAuthorizeReason; }; export type H2ADriveAcceptReason = H2ADriveVerifyReason | H2ADriveAuthorizeReason | "target-mismatch" | "inject-failed"; export type H2ADriveAcceptResult = { readonly ok: true; readonly payload: H2ADriveInstructionPayload; } | { readonly ok: false; readonly reason: H2ADriveAcceptReason; }; export interface AcceptDriveInstructionOptions { readonly store: Pick; readonly guard: H2AReplayGuard; readonly expectedTo?: string; readonly now?: number; readonly inject: (payload: H2ADriveInstructionPayload) => boolean | Promise; } export interface H2ADriveRequest { readonly to: string; readonly host?: string; readonly instructionLine: string; readonly launchContext?: H2ALaunchContext; } export interface H2ADriver { drive(request: H2ADriveRequest): boolean | Promise; } export type H2ADriverKind = "logging" | "native" | "local-tmux" | "headless" | "auto"; export interface NativeBackchannelDriverOptions { /** Return undefined when this transport does not own the target, so legacy native backchannels may try. */ readonly send?: (request: H2ADriveRequest) => boolean | undefined | Promise; readonly runtime?: RelauncherRuntime; readonly log?: (line: string) => void; } export interface DriverRuntimeOptions { readonly runtime?: RelauncherRuntime; readonly log?: (line: string) => void; } export interface DriveCommand { readonly file: string; readonly args: readonly string[]; readonly cwd?: string; } export interface BuildHeadlessDriveCommandInput { readonly host?: string; readonly instructionLine: string; readonly cwd?: string; } export interface NativeDriveCommandInput { readonly to: string; readonly instructionLine: string; readonly host?: string; readonly launchContext?: H2ALaunchContext; } export type H2ADriveRemoteReason = H2ADriveAcceptReason | "missing-line" | "payload-too-large"; export type H2ADriveRemoteResult = { readonly ok: true; readonly from: string; readonly to: string; readonly instruction: string; } | { readonly ok: false; readonly reason: H2ADriveRemoteReason; }; export interface RemoteDriveServerOptions { /** Local remote/sidecar instance that this injector is allowed to drive. */ readonly to: string; /** Registry/key lookup used by the verify-before-inject gate. */ readonly store: Pick; /** Called only after signature, freshness, target, and authority pass. */ readonly inject: (payload: H2ADriveInstructionPayload, line: string) => boolean | Promise; /** Shared replay guard. Defaults to an in-memory guard for the service lifetime. */ readonly guard?: H2AReplayGuard; /** POST endpoint path. Default `/h2a/drive`. */ readonly path?: string; /** Reject bodies larger than this many bytes. Default 64 KiB. */ readonly maxBodyBytes?: number; /** Clock source handed to the replay guard. Defaults to `Date.now`. */ readonly now?: () => number; } export type RemoteDriveServerForStoreOptions = Omit; export declare function formatSignedDriveInstruction(options: FormatSignedDriveInstructionOptions): string; export declare function parseSignedDriveInstruction(line: string): ParsedSignedDriveInstruction | undefined; export declare function verifySignedDriveInstruction(line: string, options: VerifySignedDriveInstructionOptions): H2ADriveVerifyResult; export type H2ADriveReceiveReason = H2ADriveVerifyReason | H2ADriveAuthorizeReason | "target-mismatch"; export type H2ADriveReceiveResult = { readonly ok: true; readonly from: string; readonly to: string; readonly instruction: string; } | { readonly ok: false; readonly reason: H2ADriveReceiveReason; }; export interface VerifyDriveOnReceiveOptions { readonly to: string; readonly guard: H2AReplayGuard; readonly now?: number; } export declare function authorizeDrive(store: Pick, request: { readonly from: string; readonly to: string; }): H2ADriveAuthorizeResult; export declare function verifyDriveOnReceive(store: Pick, line: string, options: VerifyDriveOnReceiveOptions): H2ADriveReceiveResult; export declare function acceptDriveInstruction(line: string, options: AcceptDriveInstructionOptions): Promise; export declare function loggingDriver(log?: (line: string) => void): H2ADriver; export declare function nativeBackchannelDriver(options?: NativeBackchannelDriverOptions): H2ADriver; export declare function nativeDriveCommand(input: NativeDriveCommandInput): readonly string[] | undefined; export declare function localTmuxDriver(options?: DriverRuntimeOptions): H2ADriver; export declare function buildHeadlessDriveCommand(input: BuildHeadlessDriveCommandInput): DriveCommand | undefined; export declare function headlessDriver(options?: DriverRuntimeOptions): H2ADriver; export declare function remoteDriveRejectionStatus(reason: H2ADriveRemoteReason): number; export declare function createRemoteDriveServer(options: RemoteDriveServerOptions): Server; export declare function remoteDriveServerForStore(store: Pick, options: RemoteDriveServerForStoreOptions): Server; export declare function chainDriver(...drivers: readonly H2ADriver[]): H2ADriver; /** * Return the most-recently-heartbeated launch context recorded for `instance` * in the local presence store under `root`. Used to supply `launchContext` to * drivers (e.g. local-tmux) that need to know the agent's tmux pane. */ export declare function latestLaunchContext(root: string, instance: string): H2ALaunchContext | undefined; /** * Auto-detect the tmux pane this process runs in, as a launch context, so an * agent launched inside a tmux pane becomes wakeable WITHOUT any launcher * config: `mcp-serve` is spawned as the agent's MCP server and inherits the * agent's `$TMUX_PANE`, so it can record its own pane in presence at auto-open. * The local-tmux driver then targets that pane (`tmux send-keys -t %id`, a valid * pane-id target — the session field is unused when no window is set). Returns * undefined when not under tmux (e.g. a plain terminal), so wake gracefully * no-ops there. */ export declare function detectTmuxLaunchContext(env?: NodeJS.ProcessEnv, cwd?: string, command?: string): H2ALaunchContext | undefined; //# sourceMappingURL=index.d.ts.map