import { type CallbackAttemptOutcome, type CallbackRouteV1, type CallbackTransportContextV1, type CallbackTransportDeliverInput } from "./callback-transport.js"; import { type TerminalWatch, type TerminalWatchAnchor, type TerminalWatchManualInteractionSummary, type TerminalWatchCurrentInteraction, type TerminalWatchObservationCheckpoint, type TerminalWatchStatus, type TerminalWatchStore, type TerminalWatchTerminalIdentity } from "./terminal-watch-store.js"; import type { ExecutorKind } from "./executors.js"; export { terminalWatchCallbackEnvelope, terminalWatchCallbackMessage } from "./terminal-watch-store.js"; export type { TerminalWatchCallbackEvent, TerminalWatchCallbackMessageInput } from "./terminal-watch-store.js"; export interface CreateTerminalWatchInput { watch_id?: string; agent: ExecutorKind; terminal: TerminalWatchTerminalIdentity; anchor: TerminalWatchAnchor; warnings?: string[]; /** * Immutable Host callback authority captured when the Watch is created. * Legacy OpenClaw Watches omit this and retain their existing lazy resolver. */ callback_route?: CallbackRouteV1; openclaw_session: string; openclaw_bin: string; timeout_ms: number; last_activity_at?: string; approval_fingerprint?: string; approval_reason_code?: string; } export interface TerminalWatchObservationFence { watch_id: string; terminal_identity_fingerprint: string; anchor_fingerprint: string; } interface TerminalWatchObservationBase extends TerminalWatchObservationFence { observed_at: string; last_activity_at?: string; safe_resume_offset_bytes?: number; observation_checkpoint?: TerminalWatchObservationCheckpoint; } export type TerminalWatchObservation = (TerminalWatchObservationBase & { kind: "pending"; /** Exact main-Composer capture proved this former async surface absent. */ async_interaction_absent?: { interaction_id: string; prompt_fingerprint: string; }; }) | (TerminalWatchObservationBase & { kind: "unavailable"; reason_code?: string; }) | (TerminalWatchObservationBase & { kind: "approval"; evidence_fingerprint: string; reason_code?: string; }) | (TerminalWatchObservationBase & { kind: "interaction"; evidence_fingerprint: string; reason_code?: string; current_interaction: TerminalWatchCurrentInteraction; /** Present only when the live surface cannot be executed safely. */ manual_interaction?: TerminalWatchManualInteractionSummary; /** A higher-priority same-controller responder owns this live surface. */ suppress_notification?: boolean; }) | (TerminalWatchObservationBase & { kind: "interaction_manual_required"; evidence_fingerprint: string; reason_code?: string; manual_interaction: TerminalWatchManualInteractionSummary; }) | (TerminalWatchObservationBase & { kind: "completed" | "failed"; evidence_fingerprint: string; reason_code?: string; completion_text?: string; completion_id?: string; completion_timestamp?: string; }) | (TerminalWatchObservationBase & { kind: "invalidated"; evidence_fingerprint: string; reason_code?: string; }); export interface TerminalWatchCallbackResolution { route: CallbackRouteV1; context?: CallbackTransportContextV1; } export type TerminalWatchDeliveryInput = CallbackTransportDeliverInput; export interface TerminalWatchServiceDependencies { repository: TerminalWatchStore; now(): Date; randomUUID(): string; observe(watch: TerminalWatch): Promise; resolveCallback(watch: TerminalWatch): TerminalWatchCallbackResolution; resolveCallbackContext?(watch: TerminalWatch, route: CallbackRouteV1): CallbackTransportContextV1 | undefined; /** Local runtime eligibility; false leaves another Host's receipt untouched. */ canDeliverCallback?(watch: TerminalWatch, route: CallbackRouteV1 | undefined): boolean; deliver(input: TerminalWatchDeliveryInput): Promise | CallbackAttemptOutcome; notificationLeaseMs?: number; notificationRetryDelayMs?: number | ((attempt: number) => number); notificationMaxRetryDelayMs?: number; reconciliationDeliveryLimit?: number; classifyDeliveryError?(error: unknown): string; } export interface TerminalWatchReconciliationItem { watch_id: string; status: TerminalWatchStatus | "error"; changed: boolean; callbacks_delivered: number; error_code?: string; } export interface TerminalWatchReconciliationSummary { checked: number; changed: number; callbacks_delivered: number; errors: number; items: TerminalWatchReconciliationItem[]; } export interface TerminalWatchService { create(input: CreateTerminalWatchInput): TerminalWatch; cancel(watchId: string): TerminalWatch; get(watchId: string): TerminalWatch; list(): TerminalWatch[]; reconcile(watchId: string): Promise; reconcileAll(): Promise; } /** * Create the durable Watch application service. Terminal observation and * callback transport are the only effects; the API intentionally has no port * capable of writing to, approving, cancelling, or taking ownership of a TUI. */ export declare function createTerminalWatchService(dependencies: TerminalWatchServiceDependencies): TerminalWatchService; export declare function terminalWatchObservationFence(watch: TerminalWatch): TerminalWatchObservationFence;