declare const AGENT_EFFORT_LEVELS: readonly [ "low", "medium", "high", "xhigh", "max" ]; declare const AGENT_PERMISSION_MODES: readonly [ "default", "plan", "acceptEdits", "auto", "dontAsk", "bypassPermissions" ]; type AgentPermissionMode = (typeof AGENT_PERMISSION_MODES)[number]; type AgentEffortLevel = (typeof AGENT_EFFORT_LEVELS)[number]; type AgentRunStatus = "queued" | "starting" | "running" | "blocked" | "waiting_for_user" | "waiting_for_tool" | "waiting_for_hook" | "waiting_for_permission" | "paused" | "completed" | "failed" | "cancelled" | "interrupted" | "detached"; interface AgentRunUsage { input: number; output: number; total: number; estimatedCostUsd?: number; } interface AgentRunAgentDefinitionRef { name: string; scope: "project" | "user" | "plugin" | "built-in"; path: string; description?: string; model?: string; } interface AgentRunRecord { schemaVersion: 1; runId: string; sessionId: string; rootRunId: string; parentRunId?: string; cwd: string; workspaceId: string; prompt: string; title?: string; status: AgentRunStatus; statusReason?: string; blockedReason?: string; model: string; effort?: AgentEffortLevel; agent?: AgentRunAgentDefinitionRef; permissionMode: AgentPermissionMode; createdByCliVersion?: string; createdBySdkVersion?: string; createdAt: string; updatedAt: string; startedAt?: string; endedAt?: string; lastActivityAt?: string; pinned: boolean; attachedClients: number; workerPid?: number; workerVersion?: string; cliVersion?: string; sdkVersion?: string; stdoutPath: string; stderrPath: string; eventsPath: string; exitCode?: number | null; git?: { root?: string; originBranch?: string; originCommit?: string; branch?: string; baseRef?: string; commit?: string; worktree?: string; }; usage: AgentRunUsage; children: string[]; tags: string[]; } interface AgentRunEvent { schemaVersion: 1; eventId?: string; sequence?: number; runId: string; type: string; timestamp: string; payload: Record; } interface AgentRunListOptions { cwd?: string; all?: boolean; status?: AgentRunStatus[]; limit?: number; } interface AgentRunCreateInput { prompt: string; cwd: string; model: string; effort?: AgentRunRecord["effort"]; agent?: AgentRunAgentDefinitionRef; permissionMode: AgentRunRecord["permissionMode"]; title?: string; pinned?: boolean; git?: AgentRunRecord["git"]; cliVersion?: string; sdkVersion?: string; } declare function getAgentRunStoreDir(): string; declare function getAgentRunDir(runId: string): string; declare function createAgentRunId(date?: Date): string; declare class AgentRunStore { private readonly runsDir; private readonly eventStore; constructor(runsDir?: string); create(input: AgentRunCreateInput): AgentRunRecord; get(runId: string): AgentRunRecord | null; list(options?: AgentRunListOptions): AgentRunRecord[]; markSpawned(runId: string, pid: number, workerVersion?: string): AgentRunRecord | null; markStarted(runId: string, input: { pid: number; workerVersion?: string; model?: string; effort?: AgentRunRecord["effort"]; }): AgentRunRecord | null; markCompleted(runId: string, input: { status: AgentRunStatus; statusReason?: string; exitCode?: number | null; usage?: AgentRunUsage; }): AgentRunRecord | null; markCancelled(runId: string, reason: string): AgentRunRecord | null; markPaused(runId: string, reason?: string): AgentRunRecord | null; markResumed(runId: string, reason?: string): AgentRunRecord | null; setPinned(runId: string, pinned: boolean): AgentRunRecord | null; appendEvent(runId: string, type: string, payload?: Record): void; readEvents(runId: string): AgentRunEvent[]; delete(runId: string): void; refreshRecordStatus(record: AgentRunRecord): AgentRunRecord; private update; private write; private recordPath; private runDir; } declare class AgentEventStore { private readonly runsDir; constructor(runsDir: string); pathFor(runId: string): string; append(runId: string, type: string, payload?: Record, timestamp?: string): AgentRunEvent; read(runId: string): AgentRunEvent[]; tail(runId: string, limit?: number): AgentRunEvent[]; } interface AgentRunSpawnResult { pid: number; workerVersion?: string; } interface AgentRunControllerOptions { store?: AgentRunStore; spawn?: (record: AgentRunRecord) => AgentRunSpawnResult | Promise; stop?: (record: AgentRunRecord, reason: string) => void | Promise; pause?: (record: AgentRunRecord, reason: string) => void | Promise; resume?: (record: AgentRunRecord, reason: string) => void | Promise; } declare class AgentRunController { private readonly options; readonly store: AgentRunStore; constructor(options?: AgentRunControllerOptions); create(input: AgentRunCreateInput): AgentRunRecord; start(input: AgentRunCreateInput): Promise; get(runId: string): AgentRunRecord | null; list(options?: AgentRunListOptions): AgentRunRecord[]; events(runId: string, limit?: number): AgentRunEvent[]; stop(runId: string, reason?: string): Promise; pause(runId: string, reason?: string): Promise; resume(runId: string, reason?: string): Promise; complete(runId: string, status: Extract, options?: { reason?: string; exitCode?: number | null; usage?: AgentRunUsage; }): AgentRunRecord | null; } declare const AGENT_DAEMON_PROTOCOL_VERSION: 1; interface AgentDaemonRequest { protocolVersion: typeof AGENT_DAEMON_PROTOCOL_VERSION; id: string; method: string; params: T; authToken?: string; } interface AgentDaemonError { code: string; message: string; } type AgentDaemonResponse = { protocolVersion: 1; id: string; result: T; } | { protocolVersion: 1; id: string; error: AgentDaemonError; }; type AgentDaemonHandler = (params: unknown, request: AgentDaemonRequest) => unknown | Promise; type AgentDaemonTransport = (request: AgentDaemonRequest) => AgentDaemonResponse | Promise; declare class AgentDaemonServer { private readonly options; private readonly handlers; constructor(options?: { authToken?: string; }); register(method: string, handler: AgentDaemonHandler): this; registerController(controller: AgentRunController): this; handle(request: AgentDaemonRequest): Promise; private error; } declare class AgentDaemonClient { private readonly transport; private readonly options; constructor(transport: AgentDaemonTransport, options?: { authToken?: string; }); request(method: string, params: TParams): Promise; } interface WorkflowNodeDefinition { id: string; dependsOn?: string[]; input?: unknown; } interface WorkflowDefinition { schemaVersion: 1; id: string; name: string; nodes: WorkflowNodeDefinition[]; maxConcurrency?: number; failFast?: boolean; } type WorkflowNodeStatus = "pending" | "running" | "completed" | "failed" | "skipped"; type WorkflowRunStatus = "queued" | "running" | "completed" | "failed" | "cancelled"; interface WorkflowRunNodeRecord { status: WorkflowNodeStatus; startedAt?: string; completedAt?: string; output?: unknown; error?: string; } interface WorkflowRunRecord { schemaVersion: 1; runId: string; workflowId: string; status: WorkflowRunStatus; createdAt: string; updatedAt: string; completedAt?: string; nodes: Record; } interface WorkflowEvent { schemaVersion: 1; eventId: string; runId: string; type: string; timestamp: string; nodeId?: string; payload: Record; } interface WorkflowPlan { workflowId: string; waves: string[][]; } declare class WorkflowPlanner { plan(definition: WorkflowDefinition): WorkflowPlan; } declare class WorkflowStore { private readonly rootDir; constructor(rootDir?: string); saveDefinition(definition: WorkflowDefinition): WorkflowDefinition; getDefinition(id: string): WorkflowDefinition | null; listDefinitions(): WorkflowDefinition[]; createRun(definition: WorkflowDefinition): WorkflowRunRecord; getRun(runId: string): WorkflowRunRecord | null; updateRun(runId: string, updater: (record: WorkflowRunRecord) => WorkflowRunRecord): WorkflowRunRecord; appendEvent(runId: string, type: string, payload: Record, nodeId?: string): WorkflowEvent; readEvents(runId: string): WorkflowEvent[]; private writeRun; private definitionsDir; private runsDir; private runPath; private eventsPath; } type WorkflowNodeExecutor = (node: WorkflowNodeDefinition, context: { run: WorkflowRunRecord; definition: WorkflowDefinition; }) => unknown | Promise; declare class WorkflowRuntime { private readonly store; private readonly planner; constructor(store?: WorkflowStore, planner?: WorkflowPlanner); run(definition: WorkflowDefinition, executor: WorkflowNodeExecutor): Promise; } interface MonitorEvent { schemaVersion: 1; eventId: string; sourceId: string; type: string; timestamp: string; payload: Record; } interface MonitorSource { id: string; start?(): void | Promise; poll(): Array & { timestamp?: string; }> | Promise & { timestamp?: string; }>>; stop?(): void | Promise; } interface MonitorSnapshot { sourceId: string; running: boolean; events: MonitorEvent[]; } declare class MonitorManager { private readonly maxEvents; private readonly sources; private readonly events; constructor(maxEvents?: number); register(source: MonitorSource): this; start(sourceId: string, intervalMs?: number): Promise; poll(sourceId: string): Promise; stop(sourceId: string): Promise; stopAll(): Promise; snapshot(sourceId: string, limit?: number): MonitorSnapshot; list(): Array<{ sourceId: string; running: boolean; }>; private require; } declare class MonitorTool { private readonly manager; constructor(manager: MonitorManager); execute(input: { sourceId: string; intervalMs?: number; }): Promise; } declare class MonitorStopTool { private readonly manager; constructor(manager: MonitorManager); execute(input: { sourceId: string; }): Promise; } interface UsageAttribution { runId?: string; sessionId?: string; workflowRunId?: string; agentId?: string; provider?: string; model?: string; } interface UsageEvent extends UsageAttribution { schemaVersion: 1; eventId: string; timestamp: string; inputTokens: number; outputTokens: number; cachedInputTokens?: number; estimatedCostUsd?: number; metadata?: Record; } interface UsageQuery extends UsageAttribution { from?: string; to?: string; } interface UsageTotals { inputTokens: number; outputTokens: number; totalTokens: number; cachedInputTokens: number; estimatedCostUsd: number; events: number; } declare class UsageAccumulator { private totalsValue; add(event: Pick): this; snapshot(): UsageTotals; } declare class UsageLedger { private readonly path; constructor(path?: string); append(input: Omit & { timestamp?: string; }): UsageEvent; query(query?: UsageQuery): UsageEvent[]; summarize(query?: UsageQuery): UsageTotals; } interface OtelUsageAdapter { addCounter(name: string, value: number, attributes: Readonly>): void; recordEvent?(name: string, attributes: Readonly>): void; } declare class OtelExporter { private readonly adapter; constructor(adapter: OtelUsageAdapter); export(events: readonly UsageEvent[]): void; } interface ControlPlaneLockRecord { schemaVersion: 1; name: string; pid: number; hostname: string; processStartedAt: string; version: string; acquiredAt: string; updatedAt: string; } interface ControlPlaneLockHandle { record: ControlPlaneLockRecord; release: () => void; } declare function acquireControlPlaneLock(path: string, name: string, version: string): ControlPlaneLockHandle; declare const PEER_SCHEMA_VERSION: 2; declare const PEER_PRESENCE_TTL_MS = 30000; declare const PEER_MESSAGE_DEFAULT_TTL_MS: number; type PeerSurface = "cli" | "interface" | "hub" | "shell" | "other"; type PeerPresenceState = "idle" | "busy" | "awaiting-approval" | "offline"; type PeerInboundPolicy = "accept" | "hold" | "refuse"; type PeerMessageKind = "task" | "message" | "question" | "report"; type PeerDeliveryStatus = "queued" | "held" | "received" | "refused" | "expired" | "cancelled"; type PeerTaskStatus = "offered" | "accepted" | "running" | "completed" | "failed" | "cancelled" | "blocked" | "recovery-required"; type PeerPermissionPosture = "plan" | "default" | "acceptEdits" | "bypassPermissions" | "unknown"; interface PeerPresence { schemaVersion: typeof PEER_SCHEMA_VERSION; sessionId: string; incarnationId: string; name?: string; host: string; owner: string; pid: number; workspace: string; surface: PeerSurface; state: PeerPresenceState; inboundPolicy: PeerInboundPolicy; posture: PeerPermissionPosture; capabilities: string[]; startedAt: string; heartbeatAt: string; parentSessionId?: string; dockedAgents?: Array<{ name: string; agentId?: string; capabilities?: string[]; status?: string; }>; } interface PeerAddress { sessionId: string; incarnationId?: string; name?: string; host?: string; workspace?: string; } interface PeerDelivery { status: PeerDeliveryStatus; at: string; reason?: string; incarnationId?: string; } interface PeerTask { status: PeerTaskStatus; at: string; executorIncarnationId?: string; startedAt?: string; endedAt?: string; result?: string; error?: string; reportMessageId?: string; cancelRequestedAt?: string; } interface PeerMessage { schemaVersion: typeof PEER_SCHEMA_VERSION; messageId: string; idempotencyKey?: string; kind: PeerMessageKind; from: PeerAddress; to: PeerAddress; text: string; correlationId?: string; causedBy?: string; chainDepth: number; createdAt: string; updatedAt: string; expiresAt: string; delivery: PeerDelivery; task?: PeerTask; } type PeerSendOutcome = { status: "queued"; message: PeerMessage; } | { status: "held"; message: PeerMessage; reason: string; } | { status: "refused"; messageId?: string; reason: string; }; interface PeerSendInput { from: PeerAddress; to: PeerAddress; text: string; kind?: PeerMessageKind; correlationId?: string; causedBy?: string; idempotencyKey?: string; ttlMs?: number; } interface PeerMessagingStoreOptions { now?: () => number; maxPerSenderPerWindow?: number; windowMs?: number; maxQueuedPerRecipient?: number; maxHeldPerRecipient?: number; maxChainDepth?: number; presenceTtlMs?: number; defaultTtlMs?: number; } declare const PEER_TASK_TERMINAL_STATUSES: readonly PeerTaskStatus[]; declare function isPeerTaskTerminal(status: PeerTaskStatus): boolean; declare function movesTrustUpward(sender: PeerPermissionPosture, receiver: PeerPermissionPosture): boolean; declare function toPeerPosture(permissionMode: string | undefined): PeerPermissionPosture; declare function peerShortId(sessionId: string): string; declare function renderPeerLabel(peer: Pick): string; type PeerResolution = { kind: "resolved"; peer: PeerPresence; } | { kind: "ambiguous"; candidates: PeerPresence[]; } | { kind: "unknown"; }; declare function resolvePeerTarget(peers: readonly PeerPresence[], query: string, self?: string): PeerResolution; declare function defaultPeerDirectory(): string; declare class PeerMessagingStore { readonly directory: string; private readonly now; private readonly options; constructor(directory?: string, options?: PeerMessagingStoreOptions); private presencePath; private presenceLock; registerSession(input: { sessionId: string; name?: string; workspace: string; surface?: PeerSurface; inboundPolicy?: PeerInboundPolicy; posture?: PeerPermissionPosture; capabilities?: string[]; state?: PeerPresenceState; incarnationId?: string; parentSessionId?: string; dockedAgents?: Array<{ name: string; agentId?: string; capabilities?: string[]; status?: string; }>; }): PeerPresence; heartbeat(sessionId: string, incarnationId: string, update?: Partial>): PeerPresence | null; unregisterSession(sessionId: string, incarnationId: string): boolean; getPresence(sessionId: string): PeerPresence | null; listSessions(options?: { includeOffline?: boolean; }): PeerPresence[]; private withLiveness; private mailboxDir; private messagePath; private messageLock; send(input: PeerSendInput): PeerSendOutcome; inbox(sessionId: string): PeerMessage[]; listSent(sessionId: string): PeerMessage[]; find(messageId: string): PeerMessage | null; private mutate; setDelivery(messageId: string, status: PeerDeliveryStatus, detail?: { reason?: string; incarnationId?: string; }): PeerMessage; release(messageId: string): PeerMessage; receive(messageId: string, incarnationId: string): PeerMessage; setTask(messageId: string, status: PeerTaskStatus, detail?: { executorIncarnationId?: string; result?: string; error?: string; reportMessageId?: string; }): PeerMessage; requestCancel(messageId: string, reason?: string): PeerMessage; expireStale(sessionId: string): PeerMessage[]; reconcileAbandonedTasks(sessionId: string, liveIncarnationId: string): PeerMessage[]; compact(olderThanMs?: number): { messages: number; presence: number; }; } export { AGENT_DAEMON_PROTOCOL_VERSION, AgentDaemonClient, type AgentDaemonError, type AgentDaemonHandler, type AgentDaemonRequest, type AgentDaemonResponse, AgentDaemonServer, type AgentDaemonTransport, AgentEventStore, type AgentRunAgentDefinitionRef, AgentRunController, type AgentRunControllerOptions, type AgentRunCreateInput, type AgentRunEvent, type AgentRunListOptions, type AgentRunRecord, type AgentRunSpawnResult, type AgentRunStatus, AgentRunStore, type AgentRunUsage, type ControlPlaneLockHandle, type ControlPlaneLockRecord, type MonitorEvent, MonitorManager, type MonitorSnapshot, type MonitorSource, MonitorStopTool, MonitorTool, OtelExporter, type OtelUsageAdapter, PEER_MESSAGE_DEFAULT_TTL_MS, PEER_PRESENCE_TTL_MS, PEER_SCHEMA_VERSION, PEER_TASK_TERMINAL_STATUSES, type PeerAddress, type PeerDelivery, type PeerDeliveryStatus, type PeerInboundPolicy, type PeerMessage, type PeerMessageKind, PeerMessagingStore, type PeerMessagingStoreOptions, type PeerPermissionPosture, type PeerPresence, type PeerPresenceState, type PeerResolution, type PeerSendInput, type PeerSendOutcome, type PeerSurface, type PeerTask, type PeerTaskStatus, UsageAccumulator, type UsageAttribution, type UsageEvent, UsageLedger, type UsageQuery, type UsageTotals, type WorkflowDefinition, type WorkflowEvent, type WorkflowNodeDefinition, type WorkflowNodeExecutor, type WorkflowNodeStatus, type WorkflowPlan, WorkflowPlanner, type WorkflowRunNodeRecord, type WorkflowRunRecord, type WorkflowRunStatus, WorkflowRuntime, WorkflowStore, acquireControlPlaneLock, createAgentRunId, defaultPeerDirectory, getAgentRunDir, getAgentRunStoreDir, isPeerTaskTerminal, movesTrustUpward, peerShortId, renderPeerLabel, resolvePeerTarget, toPeerPosture };