import type { BackendType, SessionBackend, SpawnOpts, SessionProbe } from './types.js'; export type PersistentBackendType = Exclude; export interface HerdrExternalTarget { sessionName: string; target: string; paneId?: string; } interface HerdrBackendOptions { createSession?: boolean; isReattach?: boolean; externalTarget?: HerdrExternalTarget; /** Managed agent inside a user's existing herdr session. */ agentName?: string; /** Whether /close should stop the whole herdr session. */ ownsSession?: boolean; /** Whether /close should close just the managed pane in a shared session. */ ownsAgent?: boolean; } declare const WATCHED_STATUSES: readonly ["working", "done", "blocked", "idle"]; export type HerdrAgentStatus = typeof WATCHED_STATUSES[number]; export interface HerdrWebTerminalSize { cols: number; rows: number; } export interface HerdrWebTerminalCursor { col: number; row: number; } export declare class HerdrBackend implements SessionBackend { readonly sessionName: string; private readonly opts; private serverProcess; private pollTimer; private statusWaitProcesses; private readonly dataCbs; private readonly snapshotCbs; private readonly webCursorCbs; private readonly exitCbs; private readonly agentStatusCbs; private readonly agentName; private paneId; private lastText; private exited; private started; private actuallyReattached; private cols; private rows; private agentProbeFailures; private webAttach; private webCursorTerminal; private webCursor; private webCursorTimer; private webOwner; private webSize; private readonly webViewers; private childEnv; claudeJsonlPath?: string; cliPid?: number; cliCwd?: string; /** Default managed agent name for a Botmux-launched CLI (the single source of * truth shared by the constructor default and the selector's agent-precise * reattach probe). */ static defaultAgentName(): string; constructor(sessionName: string, opts?: HerdrBackendOptions); static isAvailable(): boolean; static sessionName(sessionId: string): string; /** Machine-wide host for every agent actively launched by Botmux. */ static managedSessionName(): string; static hasSession(name: string): boolean; /** * Tri-state existence probe. A failed/timed-out `session list` (tryJsonCommand * → {ok:false}) yields 'unknown' rather than collapsing into 'missing', so a * transient herdr-server hiccup on restore can't be mistaken for a gone * session. A present-but-not-running row is a genuine zombie → 'missing'. */ static probeSession(name: string): SessionProbe; static killSession(name: string): void; static listBotmuxSessions(): string[]; static hasAgent(sessionName: string, agentName: string): boolean; /** Tri-state probe for a Botmux-managed agent inside a shared session. */ static probeAgent(sessionName: string, agentName: string): SessionProbe; /** * Close selected managed panes after one agent-list snapshot. * * Startup cleanup can discover many historical rows for the same shared * Herdr host. Listing the host once keeps that sweep proportional to live * hosts + live matching panes instead of issuing one probe/list command per * persisted row. */ static killAgents(sessionName: string, agentNames: Iterable): void; /** Close only the managed pane, never the surrounding user-owned session. */ static killAgent(sessionName: string, agentName: string): void; get isReattach(): boolean; spawn(bin: string, args: string[], opts: SpawnOpts): void; write(data: string): boolean; sendText(text: string): boolean; sendSpecialKeys(...keys: string[]): boolean; pasteText(text: string): boolean; resize(cols: number, rows: number): void; acquireWebTerminal(viewer: object): HerdrWebTerminalSize | null; resizeWebTerminal(viewer: object, cols: number, rows: number): HerdrWebTerminalSize | null; releaseWebTerminal(viewer: object): object | null; isWebTerminalOwner(viewer: object): boolean; onData(cb: (data: string) => void): void; /** Full interpreted terminal frame for snapshot-aware web history merging. */ onSnapshot(cb: (snapshot: string) => void): void; /** Cursor coordinates from the real managed attach stream (0-based). */ onWebTerminalCursor(cb: (cursor: HerdrWebTerminalCursor) => void): void; getWebTerminalCursor(): HerdrWebTerminalCursor | null; onExit(cb: (code: number | null, signal: string | null) => void): void; /** Authoritative Herdr lifecycle signal for input gating. * * Screen deltas are insufficient for TUIs such as Pi whose empty prompt can * render identically before and after becoming interactive. Herdr already * classifies that state, so expose it to the worker rather than guessing from * terminal text. Registration also reports the current settled state to avoid * missing a fast `idle` transition that happened during spawn(). */ onAgentStatus(cb: (status: HerdrAgentStatus) => void): void; kill(): void; destroySession(): void; getChildPid(): number | null; getAttachInfo(): null; captureCurrentScreen(): string; captureViewport(): string; getPaneSize(): { cols: number; rows: number; } | null; private ensureServer; /** Herdr >=0.7.5 managed-agent launch protocol. * * The new facade no longer accepts an arbitrary executable or cwd directly: * create a shell workspace with the requested cwd/env, then ask Herdr to * launch a supported coding-agent kind in that exact root pane. Prepending * an absolute binary's directory to PATH preserves cliPathOverride installs * whose basename is still the canonical Herdr executable (for example a Pi * installed under ~/.local/bin/node/bin/pi). */ private startPaneAgent; private startWebAttach; private resetWebTerminal; private resetWebCursorTracking; private getAgent; private listAgents; private readVisibleAnsi; private readRecentAnsi; private startPolling; private stopPolling; private poll; /** Read herdr pane recent output and emit the delta vs. last snapshot. */ private readAndEmitDelta; /** * Spawn one `herdr wait agent-status` child per useful status other than the * current one. The first to fire wins → we read+emit, tear down the losers, * and re-arm while excluding the winning (now-current) status. * * Excluding the current status is essential because Herdr waits are * level-triggered. Re-arming the same status immediately would make a pane * parked at `idle`/`done` spawn a new wait cohort every ~20ms and saturate * the Herdr API socket. `working` participates solely to advance the state * machine so settled statuses are eligible again on the next turn. */ private startStatusWatcher; private stopStatusWatcher; private handleExit; } export {}; //# sourceMappingURL=herdr-backend.d.ts.map