/** * AgentTaskAdapter, bridges agent sessions (AgentOrchestrator / WRFC agents) * into the unified RuntimeTask registry. * * Each running agent gets a corresponding RuntimeTask of kind 'agent'. The * adapter maps agent lifecycle state strings to task lifecycle transitions. */ import type { RuntimeStore } from '../../store/index.js'; import type { AgentLifecycleState } from '../../store/domains/agents.js'; import type { RuntimeEventBus } from '../../events/index.js'; /** Owner context for an agent task. */ export interface AgentOwner { /** Session ID that spawned this agent. */ sessionId: string; } /** * Bridges agent sessions into the RuntimeTask registry. * * @example * ```ts * const adapter = new AgentTaskAdapter(store); * const taskId = adapter.wrapAgent('agent_1', 'Fix the linting errors', { sessionId: 'sess_1' }); * adapter.handleAgentStateChange('agent_1', 'running'); * adapter.handleAgentStateChange('agent_1', 'completed'); * ``` */ export declare class AgentTaskAdapter { private readonly _store; /** Maps agent ID → task ID. */ private readonly _agentToTask; /** Maps task ID → agent ID. */ private readonly _taskToAgent; private readonly _dispatch; /** Prevent double-wiring the runtime bus. */ private _busAttached; constructor(_store: RuntimeStore); /** * Subscribe to AGENT_COMPLETED / AGENT_FAILED / AGENT_CANCELLED events on the * RuntimeEventBus and propagate them into the task registry. * * This is the authoritative wire that ensures task records reach terminal state * once their backing agent finishes, without it, tasks stay stuck in 'running' * indefinitely (the bug observed in daemon state at 192.168.0.61:3421). * * @param bus - The active RuntimeEventBus instance. * @returns An unsubscribe function that removes all three listeners. */ attachRuntimeBus(bus: RuntimeEventBus): () => void; /** * Reconcile adapter state on daemon restart. * * Any task in the runtime store with status 'running' at startup is mapped to * 'cancelled' with reason 'daemon-restart', since we cannot know if the * backing agent is still alive. */ reconcileOnRestart(): void; /** * Wrap an agent session as a RuntimeTask. * * @param agentId - Unique agent ID from the agent system. * @param task - Human-readable description of what the agent is doing. * @param owner - Session that spawned this agent. * @returns The new task ID. */ wrapAgent(agentId: string, task: string, owner: AgentOwner): string; /** * Handle an agent lifecycle state change and transition the task accordingly. * * @param agentId - The agent whose state changed. * @param state - New agent lifecycle state (AgentLifecycleState string). */ handleAgentStateChange(agentId: string, state: AgentLifecycleState): void; /** * Cancel an agent task by task ID. * Marks the task as cancelled in the store. The caller is responsible for * actually stopping the agent session. * * @param taskId - The RuntimeTask ID to cancel. */ cancelAgent(taskId: string): void; /** * Reconcile adapter state with an external agent registry snapshot. * * @param activeAgents - Current snapshot of active agents: agentId → task description. * @param owner - Default owner context for auto-wrapped agents. */ sync(activeAgents: ReadonlyMap, owner?: AgentOwner): void; private _upsertTask; private _transitionTask; } //# sourceMappingURL=agent-adapter.d.ts.map