/** Minimal socket shape — avoids importing socket.io-client types here. */ interface MinimalSocket { connected: boolean; emit(event: string, ...args: unknown[]): unknown; } interface SessionFrame { stream: 'stdout' | 'stderr'; text: string; at: string; } export declare class SessionRelay { /** agentId → live socket (set on daemon connect, cleared on disconnect). */ private readonly sockets; /** sessionId → active session state. */ private readonly sessions; /** agentId → active sessionId (for watch:agent discovery). */ private readonly agentCurrent; /** * Sessions whose `session:end` was emitted while the socket LOOKED connected * (2026-10). Socket.io gives no delivery guarantee: the b320a4e6 incident had * an end emitted milliseconds after a reconnect, the hub never persisted it, * and the dead session stayed "live" for 12 minutes - so every mention became * a steer to a run that no longer existed. * * The ledger is replayed on EVERY reconnect (the hub's end handler is * idempotent). It is bounded like the offline-ended queue: TTL + cap. */ private readonly recentEnds; /** * Session ids a human just FORCE-STOPPED (2026-11-04). * * A dying CLI can POST `/internal/session-start` again immediately after the * daemon's forced end: `DaemonReporter.end()` announces when the session was * never announced, and a failed output post triggers a throttled * re-announce. That resurrected a stopped run on task e3806a55 - the relay * re-created the session and the hub's `upsert` cleared `endedAt`, so the run * stayed "live" for 6.5 minutes after the stop and every wake on the task was * routed to a steer. A retry always uses a NEW session id, so refusing the * same id is safe; the entry is short-lived and bounded. */ private readonly forceStopped; registerSocket(agentId: string, socket: MinimalSocket): void; unregisterSocket(agentId: string): void; sessionStart(body: { sessionId: string; agentId: string; projectId?: string; taskId?: string; workflowId?: string; mode: 'run' | 'chat' | 'build' | 'blog' | 'workflow'; model?: string | null; startedAt?: string; }): boolean; sessionOutput(body: { sessionId: string; stream: 'stdout' | 'stderr'; text: string; at: string; }): boolean; sessionEnd(body: { sessionId: string; exitCode?: number | null; }): boolean; /** * Record a session id a human just force-stopped so a late re-announce from * the dying CLI cannot resurrect it (2026-11-04). */ markForceStopped(sessionId: string): void; /** True when this session id was force-stopped recently (see `forceStopped`). */ private isForceStopped; private pruneForceStopped; current(agentId: string): string | null; replay(sessionId: string): SessionFrame[]; /** * Drop ended sessions that are too old or beyond the cap, oldest first. * * Only ever touches sessions whose `ended` is true - a LIVE session is never * pruned, however long it runs, because its transcript is what the console is * currently rendering. */ private pruneEnded; /** Record an emitted end so a later reconnect can re-deliver it. */ private rememberEnd; private pruneRecentEnds; private flushSession; /** Emits pending frames if the socket is up; NEVER drops them while down. */ private emitFrames; private persist; } export {};