import type { OrgXClient } from "../../api.js"; import { type RuntimeHookPayload, type RuntimeInstanceRecord, type RuntimeSourceClient } from "../../runtime-instance-store.js"; import { type MissionControlNode, type SliceScope } from "./mission-control.js"; import type { KickoffContext, KickoffContextRequest } from "../../types.js"; export interface CreateAutoContinueEngineDeps { client: OrgXClient; filename: string; safeErrorMessage: (err: unknown) => string; pidAlive: (pid: number) => boolean; stopProcess: (pid: number) => Promise<{ stopped: boolean; wasRunning: boolean; }>; resolveOrgxAgentForDomain: (domain: string) => { id: string; name: string; }; checkSpawnGuardSafe: (input: { domain: string; taskId?: string | null; initiativeId: string | null; correlationId: string; runId?: string | null; targetLabel?: string | null; }) => Promise; syncParentRollupsForTask: (input: { initiativeId: string | null; taskId: string | null; workstreamId?: string | null; milestoneId?: string | null; correlationId?: string | null; }) => Promise; emitActivitySafe: (input: { initiativeId: string | null; runId?: string | null; correlationId?: string | null; phase: "intent" | "execution" | "blocked" | "review" | "handoff" | "completed"; level?: "info" | "warn" | "error"; message: string; progressPct?: number; nextStep?: string; metadata?: Record; }) => Promise; requestDecisionSafe: (input: { initiativeId: string | null; correlationId?: string | null; title: string; summary?: string | null; urgency?: "low" | "medium" | "high" | "urgent"; options?: Array>; blocking?: boolean; decisionType?: string | null; workstreamId?: string | null; agentId?: string | null; dueAt?: string | null; sourceSystem?: string | null; conflictSource?: string | null; dedupeKey?: string | null; recommendedAction?: string | null; sourceRunId?: string | null; sourceSessionId?: string | null; sourceStreamId?: string | null; sourceRef?: Record | null; evidenceRefs?: Array> | null; metadata?: Record | null; }) => Promise; registerArtifactSafe: (input: { initiativeId: string; runId: string; agentId: string; agentName?: string | null; workstreamId: string; fallbackMilestoneId?: string | null; fallbackTaskIds?: string[] | null; artifact: { name: string; artifact_type?: string | null; confidence_score?: number | null; description?: string | null; url?: string | null; milestone_id?: string | null; task_ids?: string[] | null; }; isMockWorker?: boolean; }) => Promise<{ ok: boolean; id: string | null; }>; applyAgentStatusUpdatesSafe: (input: { initiativeId: string; runId: string; correlationId: string; taskUpdates: Array<{ task_id: string; status: string; reason?: string | null; }>; milestoneUpdates: Array<{ milestone_id: string; status: string; reason?: string | null; }>; isMockWorker?: boolean; }) => Promise<{ applied: number; buffered: boolean; taskUpdates: Array<{ taskId: string; status: string; reason: string | null; }>; milestoneUpdates: Array<{ milestoneId: string; status: string; reason: string | null; }>; }>; upsertRuntimeInstanceFromHook: (payload: RuntimeHookPayload) => RuntimeInstanceRecord; broadcastRuntimeSse: (event: string, payload: RuntimeInstanceRecord) => void; clearSnapshotResponseCache: () => void; resolveByokEnvOverrides: () => Record; randomUUID?: () => string; fetchKickoffContextSafe?: (client: OrgXClient, payload: KickoffContextRequest) => Promise; renderKickoffMessage?: (input: { baseMessage: string; kickoff: KickoffContext | null; domain: string | null; requiredSkills: string[]; }) => { message: string; contextHash: string | null; }; } export declare function createAutoContinueEngine(deps: CreateAutoContinueEngineDeps): { autoContinueRuns: Map; blockedWorkstreamIds: string[]; activeTaskId: string | null; activeRunId: string | null; activeTaskTokenEstimate: number | null; workerEnvOverrides: Record | null; lastInitiativeStatus: string | null; }>; autoContinueSliceRuns: Map; localInitiativeStatusOverrides: Map; writeRuntimeEvent: (input: { sourceClient: RuntimeSourceClient; event: RuntimeHookPayload["event"]; runId: string; initiativeId: string; workstreamId: string | null; taskId: string | null; agentId: string | null; agentName: string | null; phase: string | null; message?: string | null; progressPct?: number | null; metadata?: Record | null; timestamp?: string | null; }) => RuntimeInstanceRecord; autoContinueTickMs: number; defaultAutoContinueTokenBudget: () => number | null; defaultAutoContinueMaxParallelSlices: () => number; setLocalInitiativeStatusOverride: (initiativeId: string, status: string) => void; clearLocalInitiativeStatusOverride: (initiativeId: string) => void; applyLocalInitiativeOverrides: (rows: Record[]) => Record[]; applyLocalInitiativeOverrideToGraph: (graph: T) => T; updateInitiativeAutoContinueState: (input: { initiativeId: string; run: { initiativeId: string; workspaceId: string | null; agentId: string; agentName: string | null; includeVerification: boolean; allowedWorkstreamIds: string[] | null; stopAfterSlice: boolean; ignoreSpawnGuardRateLimit: boolean; maxParallelSlices: number; parallelMode: "iwmt"; scope: SliceScope; tokenBudget: number | null; tokensUsed: number; status: "stopped" | "running" | "stopping"; stopReason: ("error" | "blocked" | "completed" | "stopped" | "budget_exhausted") | null; stopRequested: boolean; startedAt: string; stoppedAt: string | null; updatedAt: string; lastError: string | null; lastTaskId: string | null; lastRunId: string | null; activeSliceRunIds: string[]; activeTaskIds: string[]; laneByWorkstreamId: Record; blockedWorkstreamIds: string[]; activeTaskId: string | null; activeRunId: string | null; activeTaskTokenEstimate: number | null; workerEnvOverrides: Record | null; lastInitiativeStatus: string | null; }; }) => Promise; stopAutoContinueRun: (input: { run: { initiativeId: string; workspaceId: string | null; agentId: string; agentName: string | null; includeVerification: boolean; allowedWorkstreamIds: string[] | null; stopAfterSlice: boolean; ignoreSpawnGuardRateLimit: boolean; maxParallelSlices: number; parallelMode: "iwmt"; scope: SliceScope; tokenBudget: number | null; tokensUsed: number; status: "stopped" | "running" | "stopping"; stopReason: ("error" | "blocked" | "completed" | "stopped" | "budget_exhausted") | null; stopRequested: boolean; startedAt: string; stoppedAt: string | null; updatedAt: string; lastError: string | null; lastTaskId: string | null; lastRunId: string | null; activeSliceRunIds: string[]; activeTaskIds: string[]; laneByWorkstreamId: Record; blockedWorkstreamIds: string[]; activeTaskId: string | null; activeRunId: string | null; activeTaskTokenEstimate: number | null; workerEnvOverrides: Record | null; lastInitiativeStatus: string | null; }; reason: "error" | "blocked" | "completed" | "stopped" | "budget_exhausted"; error?: string | null; decisionRequired?: boolean; decisionIds?: string[]; }) => Promise; tickAutoContinueRun: (run: { initiativeId: string; workspaceId: string | null; agentId: string; agentName: string | null; includeVerification: boolean; allowedWorkstreamIds: string[] | null; stopAfterSlice: boolean; ignoreSpawnGuardRateLimit: boolean; maxParallelSlices: number; parallelMode: "iwmt"; scope: SliceScope; tokenBudget: number | null; tokensUsed: number; status: "stopped" | "running" | "stopping"; stopReason: ("error" | "blocked" | "completed" | "stopped" | "budget_exhausted") | null; stopRequested: boolean; startedAt: string; stoppedAt: string | null; updatedAt: string; lastError: string | null; lastTaskId: string | null; lastRunId: string | null; activeSliceRunIds: string[]; activeTaskIds: string[]; laneByWorkstreamId: Record; blockedWorkstreamIds: string[]; activeTaskId: string | null; activeRunId: string | null; activeTaskTokenEstimate: number | null; workerEnvOverrides: Record | null; lastInitiativeStatus: string | null; }) => Promise; tickAllAutoContinue: () => Promise; isInitiativeActiveStatus: (status: string | null | undefined) => boolean; runningAutoContinueForWorkstream: (initiativeId: string, workstreamId: string) => { initiativeId: string; workspaceId: string | null; agentId: string; agentName: string | null; includeVerification: boolean; allowedWorkstreamIds: string[] | null; stopAfterSlice: boolean; ignoreSpawnGuardRateLimit: boolean; maxParallelSlices: number; parallelMode: "iwmt"; scope: SliceScope; tokenBudget: number | null; tokensUsed: number; status: "stopped" | "running" | "stopping"; stopReason: ("error" | "blocked" | "completed" | "stopped" | "budget_exhausted") | null; stopRequested: boolean; startedAt: string; stoppedAt: string | null; updatedAt: string; lastError: string | null; lastTaskId: string | null; lastRunId: string | null; activeSliceRunIds: string[]; activeTaskIds: string[]; laneByWorkstreamId: Record; blockedWorkstreamIds: string[]; activeTaskId: string | null; activeRunId: string | null; activeTaskTokenEstimate: number | null; workerEnvOverrides: Record | null; lastInitiativeStatus: string | null; } | null; getAutoContinueLaneForWorkstream: (initiativeId: string, workstreamId: string) => { workstreamId: string; state: "idle" | "blocked" | "completed" | "running" | "rate_limited" | "waiting_dependency"; activeRunId: string | null; activeTaskIds: string[]; blockedReason: string | null; waitingOnWorkstreamIds: string[]; retryAt: string | null; updatedAt: string; } | null; scheduleAutoFixForWorkstream: (input: { initiativeId: string; workstreamId: string; runId?: string | null; event?: string | null; requestedByAgentId?: string | null; requestedByAgentName?: string | null; graceMs?: number | null; }) => Promise<{ requestId: string; initiativeId: string; workstreamId: string; runId: string | null; sourceEvent: string | null; graceMs: number; scheduledAt: string; dueAt: string; }>; startAutoContinueRun: (input: { initiativeId: string; workspaceId?: string | null; agentId: string; agentName?: string | null; tokenBudget: unknown; includeVerification: boolean; allowedWorkstreamIds: string[] | null; maxParallelSlices?: unknown; parallelMode?: unknown; stopAfterSlice?: boolean; ignoreSpawnGuardRateLimit?: boolean; scope?: SliceScope; workerEnvOverrides?: Record | null; }) => Promise<{ initiativeId: string; workspaceId: string | null; agentId: string; agentName: string | null; includeVerification: boolean; allowedWorkstreamIds: string[] | null; stopAfterSlice: boolean; ignoreSpawnGuardRateLimit: boolean; maxParallelSlices: number; parallelMode: "iwmt"; scope: SliceScope; tokenBudget: number | null; tokensUsed: number; status: "stopped" | "running" | "stopping"; stopReason: ("error" | "blocked" | "completed" | "stopped" | "budget_exhausted") | null; stopRequested: boolean; startedAt: string; stoppedAt: string | null; updatedAt: string; lastError: string | null; lastTaskId: string | null; lastRunId: string | null; activeSliceRunIds: string[]; activeTaskIds: string[]; laneByWorkstreamId: Record; blockedWorkstreamIds: string[]; activeTaskId: string | null; activeRunId: string | null; activeTaskTokenEstimate: number | null; workerEnvOverrides: Record | null; lastInitiativeStatus: string | null; }>; restoreAutoContinueRun: (initiativeId: string) => Promise<{ initiativeId: string; workspaceId: string | null; agentId: string; agentName: string | null; includeVerification: boolean; allowedWorkstreamIds: string[] | null; stopAfterSlice: boolean; ignoreSpawnGuardRateLimit: boolean; maxParallelSlices: number; parallelMode: "iwmt"; scope: SliceScope; tokenBudget: number | null; tokensUsed: number; status: "stopped" | "running" | "stopping"; stopReason: ("error" | "blocked" | "completed" | "stopped" | "budget_exhausted") | null; stopRequested: boolean; startedAt: string; stoppedAt: string | null; updatedAt: string; lastError: string | null; lastTaskId: string | null; lastRunId: string | null; activeSliceRunIds: string[]; activeTaskIds: string[]; laneByWorkstreamId: Record; blockedWorkstreamIds: string[]; activeTaskId: string | null; activeRunId: string | null; activeTaskTokenEstimate: number | null; workerEnvOverrides: Record | null; lastInitiativeStatus: string | null; } | null>; skipCurrentWorkstream: (initiativeId: string, workstreamId: string, reason?: string) => Promise<{ ok: boolean; skippedWorkstreamId: string; nextWorkstreamId?: string; nextWorkstreamTitle?: string; }>; getCanonicalAutopilotState: (initiativeId: string) => { state: "idle" | "running" | "blocked" | "stopping"; reason: string | null; activeRunId: string | null; activeWorkstreamId: string | null; activeWorkstreamTitle: string | null; queueHeadTitle: string | null; lastTransitionAt: string; } | null; workstreamSessionStore: Map; getWorkstreamSession: (workstreamId: string) => { sessionId: string; workstreamId: string; initiativeId: string; sourceClient: RuntimeSourceClient; capturedAt: string; fromRunId: string; } | null; setWorkstreamSession: (workstreamId: string, entry: { sessionId: string; workstreamId: string; initiativeId: string; sourceClient: RuntimeSourceClient; capturedAt: string; fromRunId: string; }) => void; clearWorkstreamSession: (initiativeId: string) => void; listWorkstreamSessions: (initiativeId?: string) => { sessionId: string; workstreamId: string; initiativeId: string; sourceClient: RuntimeSourceClient; capturedAt: string; fromRunId: string; }[]; sessionResumeEnabled: () => boolean; };