export interface SessionFrame { stream: 'stdout' | 'stderr'; text: string; at: string; } export interface SessionMeta { sessionId: string; agentId: string; projectId?: string; taskId?: string; /** Mirrors the backend `SessionMode` union (the backend accepts more than * this list validates - it is a display label for the live console). */ mode: 'run' | 'chat' | 'build' | 'blog' | 'workflow'; model?: string | null; /** * Chat channel this session reads from and replies in (2026-10). * * Announced so the hub can match a follow-up mention's lane * (`chat:`) against the live session: same lane steers via * `get_instructions`, a different lane wakes new work. Without it every * chat session announced `project:` while its wakes sat on * `chat:`, so the lanes never matched and each mention spawned. */ channelId?: string; /** * Workflow definition this session authors (2026-10, workflow mode). * Announced so the hub can match a follow-up mention's lane * (`workflow-def:`) against the live session. */ workflowId?: string; } /** Hard cap for ONE console frame (WS payload + transcript stay bounded). */ export declare const MAX_FRAME_CHARS: number; /** * Bounds a single console line before it enters any buffer/WS frame. * Formatter output is already small; this is the backstop for plain-text * harness lines and old callers - a multi-MB frame used to risk the socket's * 1MB payload limit (server closes the connection → streaming dies) and * freeze the browser rendering a megabyte-long line. */ export declare function capFrameText(text: string): string; export declare function sessionsDir(): string; /** Generates a session id (`session_`), shared by spawn/daemon. */ export declare function newSessionId(): string; export declare class SessionStream { readonly sessionId: string; readonly meta: SessionMeta; private readonly startedAtISO; private socket; private lines; private pending; private timer; private persistTimer; private ended; private started; constructor(meta: SessionMeta); /** Best-effort connect + emit session:start. Never throws. */ connect(wsBase: string, apiKey: string): void; /** Tees a console line into the stream buffer (batched upstream). */ line(text: string, stream?: 'stdout' | 'stderr'): void; private emitFrame; private flush; /** Flushes and emits session:end (waits briefly for the ack). */ end(exitCode: number | null): Promise; /** * Debounced transcript write (1s). The old per-line persist rewrote the * whole JSON file on EVERY console line - heavy disk churn on busy runs. * `end()` flushes the final state synchronously, so a late joiner never * misses the tail beyond 1s of churn. */ private schedulePersist; private cancelPersist; /** Writes the transcript tail to ~/.teamshare/sessions/.json. */ private persist; }