import type { EventBus } from '../events/index.js'; export interface RunningExecution { threadId: string | null; channel: string | null; /** Primary key — the executionId when present, otherwise the ad-hoc registryKey. */ registryKey: string; agentSlotId: string | null; executionId: string | null; /** Execution kind ('local' | 'dispatch' | 'scheduled' | null) — used for dispatch concurrency accounting. */ kind: string | null; kill: () => boolean; startTime: number; backend: string; /** Agent process reference — used by PI backend to route extension_ui_response for plan/ask interactions. */ agentProcess?: unknown; /** Claude session ID — saved on cancel so the next message can resume the same session. */ sessionId?: string | null; } /** Input accepted by register(). registryKey/startTime are assigned internally; kind defaults to null. */ export type RunningExecutionInput = Omit & { registryKey?: string; kind?: string | null; }; export declare class RunningExecutions { /** Primary index: key is executionId (or ad-hoc registryKey when executionId is null). */ private byKey; /** Secondary index: threadId → RunningExecution, only if threadId is non-null. */ private byThreadId; /** Secondary index: channel → set of RunningExecutions on that channel. */ private byChannel; /** EventBus for publishing agent.* lifecycle events. May be set after construction. */ private _bus; constructor(bus?: EventBus); setBus(bus: EventBus): void; /** * Register a live execution, keyed by its executionId (or an ad-hoc registryKey). * Returns the primary key. Secondary indices (byThreadId / byChannel) are kept in sync. * Publishes agent.started if executionId is non-null and a bus is wired. */ register(exec: RunningExecutionInput): string; /** Look up an execution by its primary key (executionId or ad-hoc registryKey). */ getById(id: string): RunningExecution | null; /** Returns true if an execution is registered under the given id/key. */ hasId(id: string): boolean; /** Look up an execution by threadId. Returns null if not found. */ getByThreadId(threadId: string): RunningExecution | null; /** Return all live executions registered on a channel (empty array if none). */ getByChannel(channel: string): RunningExecution[]; /** Returns true if at least one live execution is registered on the channel. */ hasChannel(channel: string): boolean; /** Return all registered executions (snapshot of the primary index). */ getAll(): RunningExecution[]; /** * Kill the execution for an id, remove it from all indices, and return the result of kill(). * Returns false if no entry is registered for the id. */ killById(id: string): boolean; /** * Kill the execution for a threadId, remove it from all indices, and return true. * Returns false if no entry has that threadId. */ killByThreadId(threadId: string): boolean; /** Kill every execution on a channel; returns the number killed. */ killByChannel(channel: string): number; /** * Remove an execution by id without calling kill() or publishing events. * No-op if the id is not registered. */ remove(id: string): void; /** * Mark the execution for an id as completed and publish agent.completed. * Returns false if no entry is registered (e.g., already removed). */ complete(id: string, costUsd?: number): boolean; /** * Mark the execution for an id as failed and publish agent.failed. * Returns false if no entry is registered (e.g., already removed). */ fail(id: string, error: string): boolean; /** * Kill the execution for an id, remove it, and publish agent.superseded. * Returns false if no entry is registered for the id. */ supersede(id: string, reason: string): boolean; /** Supersede (kill + event) every execution on a channel; returns the number superseded. */ supersedeByChannel(channel: string, reason: string): number; /** Delete an entry from the primary map and all secondary indices. */ private _delete; /** * Remove an entry from secondary indices (byThreadId / byChannel). * Guards each delete with an identity check: only clears the index if it still points * to this entry, preventing corruption when a stale entry (whose threadId has been * claimed by a newer entry) is removed. */ private _removeFromIndices; } /** Singleton instance of RunningExecutions. */ export declare const runningExecutions: RunningExecutions;