import type { SpawnRequest, SpawnResult, WorkflowPhase } from '../types/index.js'; import { type SpawnExecutionMode, type SpawnGuardrails } from './spawn-bridge.js'; export type SpawnSessionStatus = 'running' | 'completed' | 'failed' | 'timeout' | 'rejected' | 'queued'; /** * Build descriptor for a not-yet-started sibling spawn ("B"), set by the * dispatching parent on the SOURCE spawn's ("A") launch options — never by A * itself mid-run (phase-spawns have no inbound channel). Not a session id: * B doesn't exist until spawn-relay.ts builds it from this descriptor once A * settles. See spawn-relay.ts for the listener that consumes this field. */ export type SpawnRelayTarget = { taskId: string; runId: string; phase: WorkflowPhase; /** Defaults to PHASE_TO_PROFILE[phase] if omitted, same as buildPhaseRequest today. */ role?: string; goal: string; /** Defaults to 'claude', same default validateSpawnBody already applies. */ adapterId?: string; label?: string; /** Default false — a failed source spawn does not auto-launch the relay target unless opted in. */ relayOnFailure?: boolean; guardrails?: Partial; }; export type SpawnSession = { id: string; request: SpawnRequest; status: SpawnSessionStatus; startedAt: string; completedAt?: string; result?: SpawnResult; violation?: string; fallback?: boolean; /** Chat session that originated this spawn, when launched from a web-console chat turn. */ parentChatSessionId?: string; /** Human-friendly label surfaced in the chat UI (e.g. the delegated goal). */ label?: string; /** Sibling spawn to build and launch once this session settles. See SpawnRelayTarget. */ relayTarget?: SpawnRelayTarget; }; export type SpawnSessionEvent = { type: 'spawn-started' | 'spawn-completed' | 'spawn-failed' | 'spawn-queued' | 'chat-resumed' | 'chat-turn-completed' | 'spawn-relayed' | 'spawn-relay-skipped'; sessionId: string; taskId?: string; phase?: WorkflowPhase; role?: string; timestamp: string; result?: SpawnResult; reason?: string; /** Correlates the event back to the originating chat session, when present. */ parentChatSessionId?: string; label?: string; /** `chat-turn-completed` only: the conversation the completed turn belongs to. */ conversationId?: string; /** `chat-turn-completed` only: a short preview of the assistant's reply. */ preview?: string; /** Sibling spawn to build and launch once this session settles. See SpawnRelayTarget. */ relayTarget?: SpawnRelayTarget; }; export type SpawnDetachedOptions = { /** Chat session id to correlate this spawn with, surfaced on every emitted event. */ parentChatSessionId?: string; /** Human-friendly label surfaced in the chat UI. */ label?: string; /** Sibling spawn to build and launch once this session settles. See SpawnRelayTarget. */ relayTarget?: SpawnRelayTarget; }; export declare function getSession(sessionId: string): SpawnSession | undefined; export declare function listSessions(filter?: { taskId?: string; status?: SpawnSessionStatus; }): SpawnSession[]; export declare function onSessionEvent(listener: (event: SpawnSessionEvent) => void): () => void; /** * Publish an event onto the shared spawn event bus from OUTSIDE this module. * Used by the durable background-command lane (GH-535), which runs its own * session registry but surfaces lifecycle through the same /spawn/events SSE * stream the web-console already subscribes to — so no client changes are needed. */ export declare function publishSessionEvent(event: SpawnSessionEvent): void; export declare function spawnDetached(request: SpawnRequest, cwd: string, mode?: SpawnExecutionMode, options?: SpawnDetachedOptions): SpawnSession; export declare function loadPersistedSessions(cwd: string): SpawnSession[];