/** * ProcessTaskAdapter, bridges ProcessManager background processes into the * unified RuntimeTask registry. * * Each spawned background process gets a corresponding RuntimeTask of kind * 'exec'. The adapter tracks the pid→taskId mapping and reconciles state * on demand via sync(). * * NOTE: This adapter writes directly to the Zustand store for performance, * bypassing TaskManager. Lifecycle validation is the caller's responsibility. * This is intentional, adapters are authoritative sources for their subsystem. */ import type { RuntimeStore } from '../../store/index.js'; import { ProcessManager } from '../../../tools/shared/process-manager.js'; /** Owner context supplied when wrapping a process. */ export interface ProcessOwner { /** Session ID that spawned this process. */ sessionId: string; /** Optional agent ID that owns this process. */ agentId?: string | undefined; } /** * Bridges ProcessManager background processes into the RuntimeTask registry. * * @example * ```ts * const adapter = new ProcessTaskAdapter(store); * const taskId = adapter.wrapProcess(proc.pid, 'npm run build', { sessionId: 'sess_1' }); * // later... * adapter.handleProcessExit(proc.pid, 0); * ``` */ export declare class ProcessTaskAdapter { private readonly _store; /** Maps process internal ID (bg_N_ts) → task ID. */ private readonly _idToTask; /** Maps task ID → process internal ID. */ private readonly _taskToId; /** Maps pid → process internal ID (for exit handling). */ private readonly _pidToId; private readonly _manager; private readonly _dispatch; constructor(_store: RuntimeStore, manager: ProcessManager); /** * Wrap a spawned process as a RuntimeTask. * * @param processId - The ProcessManager internal ID (process_id from spawn result). * @param pid - OS process ID. * @param command - The shell command string for display. * @param owner - Session/agent that owns this process. * @returns The new task ID. */ wrapProcess(processId: string, pid: number, command: string, owner: ProcessOwner): string; /** * Update task status when a process exits. * * @param pid - OS process ID that exited. * @param exitCode - Process exit code (0 = success). */ handleProcessExit(pid: number, exitCode: number): void; /** * Cancel a process task by task ID. * Stops the underlying process via ProcessManager and marks the task cancelled. * * @param taskId - The RuntimeTask ID to cancel. */ cancelProcess(taskId: string): void; /** * Reconcile adapter state with the RuntimeTask registry. * * Scans all ProcessManager processes: * - Wraps any un-tracked processes as new tasks (with a derived owner). * - Marks completed (done) processes as completed or failed in the task store. * - Removes task mappings for processes that have been cleaned up. * * @param defaultOwner - Owner context used when auto-wrapping unknown processes. */ sync(defaultOwner?: ProcessOwner): void; private _upsertTask; private _transitionTask; } //# sourceMappingURL=process-adapter.d.ts.map