/** * CoordinatorEvent — union of all event types emitted by the AutonomousCoordinator. * Consumed by the TUI to drive coordinator panel state and the reducer. */ export type CoordinatorEvent = { type: 'goal:added'; goalId: string; title?: string; text?: string; participants?: string[]; } | { type: 'goal:completed'; goalId: string; text?: string; participants?: string[]; } | { type: 'goal:failed'; goalId: string; text?: string; } | { type: 'task:ready'; goalId: string; taskId: string; title?: string; assignedTo?: string; text?: string; } | { type: 'task:completed'; goalId: string; taskId: string; text?: string; } | { type: 'knowledge:added'; knowledgeId: string; title?: string; text?: string; } | { type: 'consensus:reached'; goalId: string; text?: string; participants?: string[]; } | { type: 'deadlock:detected'; goalId: string; text?: string; } | { type: 'coordinator:mode'; mode: 'standalone' | 'fleet'; }; import type { EventBus } from '../kernel/events.js'; import type { Logger } from '../types/logger.js'; import type { FleetBus } from './fleet-bus.js'; import type { FleetManager } from './fleet-manager.js'; import type { Mailbox } from './mailbox-types.js'; import type { FactNode, GoalNode, FactCategory } from './knowledge-graph.js'; import type { Director } from './director.js'; import { KnowledgeGraph } from './knowledge-graph.js'; import { TaskDAG } from './task-dag.js'; import { TaskAuctioneer } from './task-auctioneer.js'; import { ConsensusProtocol } from './consensus-protocol.js'; import { ChangeManager } from './change-manager.js'; import { AutonomousBrain, type LLMProvider } from './autonomous-brain.js'; export interface AutonomousCoordinatorOptions { sessionDir: string; selfAgentId: string; selfAgentName: string; fleet?: FleetBus | undefined; fleetManager?: FleetManager | undefined; director?: Director | undefined; mailbox?: Mailbox | undefined; events?: EventBus | undefined; llmProvider: LLMProvider; /** Disable self-improvement. Default: false. */ disableSelfImprove?: boolean; /** Max concurrent subagents. Default: 5. */ maxConcurrentAgents?: number; /** * Called with every CoordinatorEvent so the caller (e.g. execution.ts) * can forward it to the TUI coordinator panel timeline. */ onCoordinatorEvent?: (event: CoordinatorEvent) => void; /** Logger for structured error events. Falls back to console.error when omitted. */ logger?: Logger | undefined; } export interface RunOptions { /** Top-level goal description. Default: "Improve the codebase". */ goal?: string; /** If true, the loop runs until all goals are done (no timeout). Default: false. */ runUntilComplete?: boolean; /** Max iterations. Default: 100. */ maxIterations?: number; /** Stop if cost exceeds this. Default: no limit. */ maxCostUsd?: number; } export interface CoordinatorStats { goals: { total: number; done: number; pending: number; failed: number; progress: number; }; dag: ReturnType; auction: ReturnType; changes: { proposed: number; approved: number; applied: number; rejected: number; }; decisions: number; costSoFar?: number | undefined; } /** * AutonomousCoordinator — wires all coordination components into one engine. * * ## Quick start * * ```typescript * const coord = new AutonomousCoordinator({ * sessionDir: '/tmp/session', * selfAgentId: 'director-1', * selfAgentName: 'Director', * llmProvider: myLLMProvider, * fleet: myFleetBus, * mailbox: myMailbox, * }); * * // Run a self-directing session * await coord.run({ goal: 'Audit and fix all security issues in the auth module' }); * ``` */ export declare class AutonomousCoordinator { readonly graph: KnowledgeGraph; readonly dag: TaskDAG; readonly auction: TaskAuctioneer; readonly consensus: ConsensusProtocol; readonly changes: ChangeManager; readonly brain: AutonomousBrain; private readonly selfAgentId; private readonly fleet?; private readonly fleetManager?; private readonly director?; private readonly mailbox?; private readonly events?; private readonly onCoordinatorEvent?; private readonly logger; private running; private iterationCount; private lastSyncAt; private static readonly SYNC_INTERVAL_MS; /** * Tasks already handled by _onSubagentTerminated (to avoid double goal:failed * on a late fleet event). Bounded FIFO: entries must outlive the duplicate-event * window but not accumulate for the life of a long autonomous run, so the oldest * ids are evicted past a cap. Cleared at the top of run(). */ private readonly _handledBySubagent; private static readonly HANDLED_BY_SUBAGENT_MAX; /** FleetBus subscription disposers, detached in dispose(). */ private readonly unsubs; constructor(opts: AutonomousCoordinatorOptions); /** * Run the autonomous loop until the goal is satisfied or max iterations reached. * This is the main entry point for a fully autonomous session. */ run(opts?: RunOptions): Promise; /** Stop the autonomous loop. */ stop(): void; /** * Report that a terminal worker (not a Director subagent) completed a claimed * task. This updates the auction, DAG, publishes a task-result fact, and * extracts follow-up goals — the same path as subagent completion. */ reportTaskCompletion(taskId: string, result: string): Promise; /** * Record a task id in the bounded dedup guard, evicting the oldest ids once the * cap is exceeded. Set preserves insertion order, so the first entry is the * oldest — well outside any realistic late-duplicate-event window. */ private _markHandledBySubagent; /** * Report that a terminal worker failed a claimed task. */ reportTaskFailure(taskId: string, error: string): Promise; /** * Reload the KnowledgeGraph from disk and sync the in-memory DAG with any * changes published by other terminal sessions. New goals are added to the * DAG; existing goals whose status changed (e.g. completed by another * terminal) are transitioned accordingly. * * Safe to call at any time — also used internally by the run loop. */ syncFromGraph(): Promise; private _syncDagStatuses; private _maybeSyncFromGraph; /** * Tear down the coordinator for good: stop the loop and detach all FleetBus * subscriptions (this coordinator's + the auctioneer's) plus any open bid * timers. Call this when discarding the instance (e.g. `/coordinator stop` * that recreates a fresh coordinator on the next start) so handlers and * timers don't accumulate across cycles. `stop()` only pauses the loop. */ dispose(): void; /** Get a stats snapshot. */ getStats(): CoordinatorStats; /** * Publish a fact discovered by an agent. Facts are immutable and form * the basis for other agents' decisions. */ publishFact(input: { category: FactCategory; subject: string; detail: string; file?: string; line?: number; severity?: 'critical' | 'high' | 'medium' | 'low'; tags?: string[]; }): Promise; /** * Publish a goal and add it to the DAG. */ createGoal(input: { title: string; description: string; priority?: 'critical' | 'high' | 'medium' | 'low'; deps?: string[]; tags?: string[]; }): Promise; private _waitForDagProgress; private _dagProgressKey; private _rebuildDagFromGraph; private _rebuildDagNode; private _decomposeGoal; private _inferCategory; private _processGoal; private _stringifyTaskResult; private _completeTask; private _publishTaskResultFact; private _createFollowUpGoalsFromResult; private _extractFollowUps; private _failTask; private _recordTaskFailed; private _handlePendingChange; /** Emit on the optional shared bus; no-op when no bus was wired. */ private _busEmit; private _onDagEvent; private _onSubagentTerminated; private _fleetStatus; private _buildVoters; private _goalToOptions; private _optionToGoal; private _mailboxBroadcast; /** Emit a CoordinatorEvent to the subscriber (e.g. TUI panel timeline). */ private _emit; } //# sourceMappingURL=autonomous-coordinator.d.ts.map