import type { DispatchTask, DispatchTaskStatus } from "../types.ts"; import type { ProgressStore } from "../types.progress.ts"; import type { DispatchManagerConfig } from "../config.ts"; /** Index mapping parentSessionId → set of task IDs for O(1) lookup. */ export type ParentTasksIndex = Map>; /** * Add a task ID to the parent-tasks index. */ export declare function addToParentIndex(index: ParentTasksIndex, parentSessionId: string, taskId: string): void; /** * Remove a task ID from the parent-tasks index. * Cleans up the parent key if the set becomes empty. */ export declare function removeFromParentIndex(index: ParentTasksIndex, parentSessionId: string, taskId: string): void; /** Shared mutable state injected by DispatchManager — defined in task-lifecycle.ts for manager.ts imports. */ export interface TaskLifecycleDeps { tasks: Map; eventState: Map; client: import("../../platform/ports/session-client.ts").ISessionClient; watchdog: import("./watchdog.ts").TaskWatchdogManager; config: DispatchManagerConfig; cancelQueue: Map void>; syncControllers: Map; completedSyncSessions: Map; completedSyncSessionsSetAt: Map; cleanupTimers: Map>; sidecarGCTimers: Map>; pendingNotifications: Set; sessionToTask: Map; notifyOutbox: Set; deferredIdleTimers: Map>; cleanedUpTasks: Map; subagentModelKey: Map; /** Maps a dispatched agent ID to its owning root role ID — the role prefix of composite concurrency keys. */ subagentRoleKey: Map; /** Per-role merged dispatch configs keyed by root role ID — resolved by resolveDispatchingRole/effectiveConfigFor. */ roleConfigs: ReadonlyMap; directory: string; sessionMonitor: { verifyExistence: (client: import("../../platform/ports/session-client.ts").ISessionClient, sessionId: string) => Promise<"exists" | "missing" | "unknown">; }; cleanupTask: (taskId: string) => void; persistState: () => void; addToOutbox: (taskId: string) => void; sendNotification: (task: DispatchTask, remainingTasks: number, resultText?: string) => Promise; progressStore: ProgressStore; /** Clear per-task emitted milestone thresholds (from progress-tools.ts). */ clearEmittedThresholds: (taskId: string) => void; /** Delete on-disk checkpoint data for a task (fire-and-forget). */ deleteTaskCheckpoint: (taskId: string) => Promise; /** Per-task terminated listeners (fire-once: auto-cleared after notify). */ taskTerminatedListeners: Map>; /** Parent→taskIds index for O(1) getTasksByParent lookups. */ parentTasksIndex: ParentTasksIndex; /** Inflight running task count per parentSessionId — replaces O(n) scan in getInflightCount. */ inflightByParent: Map; /** Oldest startedAt timestamp per parentSessionId — replaces O(n) scan in getOldestInflightChildStartedAt. */ oldestStartedAtByParent: Map; } /** * Resolve the owning root role ID for a dispatched agent. * * Priority: the explicit subagent→role map (d.subagentRoleKey), then treating * the agent ID itself as a root role ID when it has a per-role dispatch config * (covers graph dispatch of a root role id). Returns undefined when neither * applies — the legacy plain-model-key path. */ export declare function resolveDispatchingRole(d: TaskLifecycleDeps, agentId: string): string | undefined; /** * Resolve the effective dispatch config for a dispatched agent: the owning * role's merged config when a role resolves, otherwise the manager's base config. */ export declare function effectiveConfigFor(d: TaskLifecycleDeps, agentId: string): DispatchManagerConfig; /** Compute the nesting depth for a task dispatched from the given parent session. */ export declare function computeDepth(d: TaskLifecycleDeps, parentSessionId: string): number; /** * Atomic compare-and-swap status transition. * Returns true iff THIS call won the race. */ export declare function transition(d: TaskLifecycleDeps, taskId: string, from: DispatchTaskStatus[], to: DispatchTaskStatus, fields?: Partial>): boolean; /** Count inflight (running + pending) tasks for a given parent session. */ export declare function getInflightCount(d: TaskLifecycleDeps, parentSessionId: string): number; /** Schedule cleanup of a task (via the cleanupTask callback). */ export declare function scheduleCleanup(d: TaskLifecycleDeps, taskId: string): void; /** Schedule garbage collection of the result sidecar file. */ export declare function scheduleSidecarGC(d: TaskLifecycleDeps, taskId: string): void; /** * Notify parent about task completion. * * Graph-scope suppression: tasks dispatched by the graph engine (marker * `task.graphScoped`) are skipped entirely — graph-node completion is reported * EXCLUSIVELY by the graph notifier (`createGraphNotifier` / * `createGraphTerminalNotifier` in `src/graph/engine/graph-notify.ts`), which * references the node id rather than the internal `bg_*` dispatch task id. * Emitting both would give the emperor two reminders with two id namespaces. * Real-session tasks notify exactly as before. */ export declare function notifyCompletion(d: TaskLifecycleDeps, task: DispatchTask, remainingTasks: number, resultText?: string): Promise; /** Schedule cleanup for a task that has finished running. */ export declare function leaveRunning(d: TaskLifecycleDeps, taskId: string): void; /** Notify terminated listeners for a task (fire-once — auto-clears after notification). * Must be called AFTER the task status has been transitioned to its terminal value. * Callbacks receive (taskId, status). */ export declare function notifyTerminated(d: TaskLifecycleDeps, taskId: string, status: string): void; //# sourceMappingURL=lifecycle-shared.d.ts.map