import type BetterSqlite3 from 'better-sqlite3';
import type { OrchestratorEngine } from '../engines/orchestrator.js';
import type { MemoryEngine } from '../engines/memory.js';
import type { SessionDNAManager } from '../engines/session-dna.js';
import type { SkillRuntime } from '../engines/skill-runtime.js';
import type { KnowledgeFabricEngine } from '../engines/knowledge-fabric.js';
import type { EngineHealthStatus } from '../engines/runtime-health.js';
import type { ExecutionRun } from '../phantom/runtime.js';
export type SynapseDb = BetterSqlite3.Database;
export type OperativeState = 'IDLE' | 'ACTIVE' | 'CHECKOUT' | 'STANDDOWN' | 'SUSPENDED' | 'DONE';
export type MissionComplexity = 'read' | 'orchestrate' | 'mutate';
export type OperativeHealthState = 'WORKING' | 'STALLED' | 'ZOMBIE' | 'BLOCKED' | 'IDLE';
export type GovernanceScope = 'operative' | 'mission' | 'crew' | 'project';
export type OperativeOrigin = 'mandate' | 'manual' | 'approval' | 'system';
export interface Operative {
    id: string;
    name: string;
    roleTitle: string | null;
    reportsToOperativeId: string | null;
    skillId: string | null;
    specialistId: string | null;
    origin: OperativeOrigin;
    state: OperativeState;
    suspendReason: 'budget_exceeded' | 'compaction' | 'manual' | null;
    terminationReason: string | null;
    healthState: OperativeHealthState;
    missionId: string | null;
    strikeTeamId: string | null;
    budgetCapUsd: number;
    budgetScope: GovernanceScope;
    budgetScopeId: string | null;
    spentUsd: number;
    commendationScore: number;
    sortieIntervalMs: number;
    lastSortieAt: string | null;
    createdAt: string;
}
export interface HireOperativeInput {
    name?: string;
    roleTitle?: string | null;
    reportsToOperativeId?: string | null;
    skillId?: string | null;
    specialistId?: string | null;
    strikeTeamId?: string | null;
    budgetCapUsd?: number;
    sortieIntervalMs?: number;
    origin?: OperativeOrigin;
    requestApproval?: boolean;
    requestedByOperativeId?: string | null;
}
export interface OperativeUpdateInput {
    operativeId: string;
    action?: 'pause' | 'resume' | 'terminate' | 'reassign' | 'profile';
    roleTitle?: string | null;
    reportsToOperativeId?: string | null;
    skillId?: string | null;
    specialistId?: string | null;
    budgetCapUsd?: number;
    sortieIntervalMs?: number;
    missionId?: string | null;
    strikeTeamId?: string | null;
    reason?: string | null;
}
export interface StrikeTeamHiringPlanEntry {
    operativeId: string;
    name: string;
    roleTitle: string | null;
    skillId: string | null;
    specialistId: string | null;
    reportsToOperativeId: string | null;
    budgetCapUsd: number;
}
export interface StrikeTeamMissionPlanEntry {
    missionId: string;
    title: string;
    assignedOperativeId: string;
    complexity: MissionComplexity;
    requiresApprovalGate: boolean;
}
export interface StrikeTeam {
    id: string;
    mandateText: string;
    operativeIds: string[];
    missionIds: string[];
    blueprintId: string | null;
    status: 'deploying' | 'active' | 'converging' | 'done' | 'standdown';
    createdAt: string;
    selectionSummary?: {
        domains: string[];
        complexity: MissionComplexity;
        skills: string[];
        specialists: string[];
        workflows: string[];
        operativeCount: number;
        missionCount: number;
    };
    hiringPlan?: StrikeTeamHiringPlanEntry[];
    missionPlan?: StrikeTeamMissionPlanEntry[];
}
export interface Mission {
    id: string;
    parentMissionId: string | null;
    strikeTeamId: string | null;
    title: string;
    ancestryPath: string[];
    correlationId: string | null;
    complexity: MissionComplexity;
    status: 'open' | 'active' | 'done' | 'blocked' | 'failed';
    assignedOperativeId: string | null;
    requiresApprovalGate: boolean;
    approvalScope: GovernanceScope;
    approvalScopeId: string | null;
    budgetScope: GovernanceScope;
    budgetScopeId: string | null;
    createdAt: string;
}
export interface Sortie {
    id: string;
    operativeId: string;
    missionId: string | null;
    status: 'running' | 'completed' | 'failed' | 'interrupted_compaction' | 'deferred';
    tokensUsed: number;
    costUsd: number;
    fieldReportId: string | null;
    startedAt: string;
    completedAt: string | null;
}
export interface FieldReport {
    id: string;
    sortieId: string;
    operativeId: string;
    strikeTeamId: string | null;
    missionTitle: string;
    findings: string;
    filesChanged: string[];
    blockersEncountered: string;
    nextRecommendedAction: string;
    tokensUsed: number;
    costUsd: number;
    ledgerPath: string | null;
    status: 'completed' | 'blocked' | 'failed';
    completedAt: string;
}
export interface ApprovalRequest {
    id: string;
    missionId: string | null;
    operativeId: string;
    scope: GovernanceScope;
    scopeId: string | null;
    action: string;
    description: string;
    payload: Record<string, unknown> | null;
    status: 'pending' | 'approved' | 'rejected';
    decidedAt: string | null;
    createdAt: string;
}
export interface EchoResult {
    found: boolean;
    summary: string;
    predecessorSortieIds: string[];
    priorBlockers: string[];
}
export interface MandateSignals {
    domains: string[];
    complexity: MissionComplexity;
    subGoalHints: string[];
}
export interface SynapseCoordinationSignal {
    phase: 'mandate' | 'worklist' | 'sortie' | 'field-report' | 'convergence';
    summary: string;
    strikeTeamId?: string | null;
    worklistId?: string | null;
    workItemId?: string | null;
    operativeId?: string | null;
    sortieId?: string | null;
    runId?: string | null;
    correlationId?: string | null;
    status?: string | null;
}
export interface SynapseCoordinationBridge {
    claimWorkItem(workItemId: string, operativeId: string): Promise<unknown | null>;
    completeWorkItem(workItemId: string, operativeId: string, status: 'done' | 'failed' | 'blocked'): Promise<unknown>;
    getWorklistId(strikeTeamId: string): string | null;
    publish(signal: SynapseCoordinationSignal): void;
}
export interface SynapseProviders {
    repoRoot: string;
    orchestrator: OrchestratorEngine;
    memory: MemoryEngine;
    sessionDNA: SessionDNAManager;
    skillRuntime: SkillRuntime;
    knowledgeFabric: KnowledgeFabricEngine;
    coordination?: SynapseCoordinationBridge;
    claimWorkItem?: (workItemId: string, operativeId: string) => Promise<unknown | null>;
    completeWorkItem?: (workItemId: string, operativeId: string, status: 'done' | 'failed' | 'blocked') => Promise<unknown>;
}
export interface SynapseRuntime {
    db: SynapseDb;
    providers: SynapseProviders;
    executeMandatePipeline(mandateText: string, opts?: {
        budgetUsd?: number;
        maxOperatives?: number;
    }): Promise<StrikeTeam>;
    hireOperative(input: HireOperativeInput): Operative | ApprovalRequest;
    updateOperative(input: OperativeUpdateInput): Operative | null;
    triggerHeartbeat(operativeId: string, force?: boolean): Promise<Sortie>;
    runSortie(operativeId: string): Promise<Sortie>;
    requestApproval(input: {
        operativeId: string;
        missionId?: string | null;
        scope?: GovernanceScope;
        scopeId?: string | null;
        action: string;
        description: string;
        payload?: Record<string, unknown> | null;
    }): ApprovalRequest;
    resolveApproval(approvalId: string, decision: 'approved' | 'rejected'): ApprovalRequest | null;
    noteMissionProgress(operativeId: string, missionId: string | null, note: string): string;
    submitFieldReport(report: FieldReport): FieldReport;
    getStrikeTeamStatus(strikeTeamId?: string): StrikeTeam[] | StrikeTeam | null;
    getOperativeHealth(operativeId?: string): Operative[] | Operative | null;
    queryEcho(input: {
        missionId?: string | null;
        missionTitle: string;
        currentOperativeId: string;
    }): Promise<EchoResult>;
    getPendingApprovals(): ApprovalRequest[];
    getStatus(): EngineHealthStatus;
    stop(): void;
}
export interface SortieExecutionContext {
    operative: Operative;
    mission: Mission | null;
    execution: ExecutionRun;
}
