/** * BackgroundSpawner — creates real OpenCode sessions for background tasks * via the v2 SDK, and manages the polling loop for idle detection. * * Lifecycle: * 1. ConcurrencyManager says a task can start. * 2. Spawner creates a session, sends the prompt, marks the task running. * 3. Poller periodically checks output; after idleTimeoutMs of no change → completed. * 4. On error → marks task error. */ import type { createOpencodeClient as createV2Client } from '@opencode-ai/sdk/v2'; import type { BackgroundManager, BackgroundTask } from './manager'; import type { ConcurrencyManager } from './concurrency'; export interface SpawnerConfig { pollIntervalMs?: number; idleTimeoutMs?: number; /** * Optional listener for lifecycle transitions. Fires when a task * reaches a terminal state (completed, error, cancelled). Used by the * plugin to emit TUI toasts for user visibility. */ onTaskEvent?: (event: { type: 'completed' | 'error' | 'cancelled'; task: BackgroundTask; }) => void; } export declare class BackgroundSpawner { private readonly v2; private readonly bgManager; private readonly concurrency; private readonly directory; private readonly logger; private pollTimer; /** Last known output hash per task — used for idle detection. */ private lastOutputHash; private readonly pollIntervalMs; private readonly idleTimeoutMs; private readonly onTaskEvent?; constructor(v2: ReturnType, bgManager: BackgroundManager, concurrency: ConcurrencyManager, directory: string, logger: { log: (...args: unknown[]) => void; }, config?: SpawnerConfig); /** Safely emit a lifecycle event; errors in the listener are swallowed. */ private emitEvent; /** * Enqueue a task, immediately start it if concurrency allows, * and ensure the poll loop is running. */ spawn(params: { id: string; parentAgent: string; targetAgent: string; prompt: string; context?: string; model: string; }): Promise; /** Cancel a task; abort the session if running. */ cancel(taskId: string): Promise; /** Shut down: cancel all running tasks, clear timer. */ shutdown(): Promise; private startTask; private ensurePolling; private pollCycle; } //# sourceMappingURL=spawner.d.ts.map