/**
 * Phantom Workers — Parallel Git Worktree Agents
 *
 * Beyond sub-agents: each Phantom Worker gets an isolated git worktree,
 * works in parallel, and the Merge Oracle picks the best result.
 *
 * Pattern:
 *   GhostPass (read-only analysis)
 *     → N PhantomWorkers (parallel, git worktrees)
 *       → MergeOracle (Byzantine vote, synthesize best)
 *         → LiveNexus (self-improvement trigger)
 */
import type { MemoryEngine } from '../engines/memory.js';
import { MergeOracle } from './merge-oracle.js';
export { MergeOracle };
import { type FileRef, type ReadingPlan } from '../engines/token-supremacy.js';
import { type PodMessage } from '../engines/pod-network.js';
export interface WorkerTask {
    id: string;
    goal: string;
    files: FileRef[];
    approach: string;
    tokenBudget: number;
    entangledPeers?: string[];
    context?: string;
    readingPlan?: ReadingPlan;
}
export interface WorkerResult {
    workerId: string;
    taskId: string;
    approach: string;
    diff: string;
    outcome: 'success' | 'partial' | 'failed' | 'budgetExceeded';
    confidence: number;
    tokensUsed: number;
    tokenEstimateSource?: 'runtime-estimate' | 'reported' | 'diff-estimate' | 'none';
    budgetExceeded?: boolean;
    learnings: string[];
    testsPassing?: number;
}
export interface GhostReport {
    taskId: string;
    riskAreas: string[];
    workerAssignments: WorkerTask[];
    totalEstimatedTokens: number;
    readingPlan: ReadingPlan;
}
export interface MergeDecision {
    action: 'apply' | 'synthesize' | 'reject';
    winner?: WorkerResult;
    synthesized?: string;
    rationale: string;
    confidence: number;
    learnings: string[];
    conflicts: string[];
    recommendedStrategy: string;
}
export declare class GhostPass {
    private tokenEngine;
    private repoRoot;
    constructor(repoRoot?: string);
    /**
     * Analyze the codebase WITHOUT touching anything.
     * Returns a reading plan + worker assignments.
     */
    analyze(goal: string, targetFiles: FileRef[], numWorkers?: number): Promise<GhostReport>;
    private detectRiskAreas;
    private generateApproaches;
}
export declare class PhantomWorker {
    private workerId;
    private repoRoot;
    private worktreeDir;
    private skipDoctor;
    constructor(repoRoot?: string, options?: {
        skipDoctor?: boolean;
    });
    get id(): string;
    /** Sync a finding to the POD Network mid-execution */
    broadcast(content: string, confidence?: number, tags?: string[]): PodMessage;
    /** Receive relevant findings from other workers from the POD */
    receive(tags?: string[]): PodMessage[];
    /**
     * Spawn this worker in an isolated git worktree.
     * The executor function receives the worktree path and operates within it.
     */
    spawn(task: WorkerTask, executor: (worktreeDir: string, task: WorkerTask, worker: PhantomWorker) => Promise<{
        learnings: string[];
        confidence: number;
        tokensUsed?: number;
        tokenEstimateSource?: 'runtime-estimate' | 'reported' | 'diff-estimate';
    }>): Promise<WorkerResult>;
    private createWorktree;
    private captureDiff;
    private cleanup;
    private estimateTokensUsed;
    /** List all active phantom worktrees (for test/debug verification) */
    static getWorktreeList(repoRoot?: string): Promise<string[]>;
    /** Force-remove any leftover phantom worktrees (emergency cleanup) */
    static purgeOrphanedWorktrees(repoRoot?: string): Promise<number>;
}
export declare class PhantomOrchestrator {
    private ghost;
    private oracle;
    private repoRoot;
    constructor(memory: MemoryEngine, repoRoot?: string);
    /**
     * Full phantom run: Ghost → Workers → Oracle → Decision
     *
     * @param goal      What to accomplish
     * @param files     Files relevant to the task
     * @param executor  Function that executes in a worker's isolated worktree
     * @param nWorkers  Number of parallel workers (default 3)
     */
    run(goal: string, files: FileRef[], executor: (worktreeDir: string, task: WorkerTask, worker: PhantomWorker) => Promise<{
        learnings: string[];
        confidence: number;
        tokensUsed?: number;
        tokenEstimateSource?: 'runtime-estimate' | 'reported' | 'diff-estimate';
    }>, nWorkers?: number): Promise<{
        report: GhostReport;
        decision: MergeDecision;
    }>;
}
export interface HotFunction {
    name: string;
    sourceFile: string;
    callCount: number;
    failureRate: number;
    avgTokensWasted: number;
}
export declare class LiveNexus {
    private hotFunctions;
    private memory;
    private orchestrator;
    private repoRoot;
    constructor(memory: MemoryEngine, repoRoot?: string);
    /** Record a function call outcome for monitoring */
    record(fnName: string, sourceFile: string, success: boolean, tokensWasted?: number): void;
    /** Get functions that need improvement */
    getCandidatesForEvolution(): HotFunction[];
    /** Check if evolution should trigger, store report to memory */
    checkAndEvolve(): Promise<void>;
}
export { SubAgentRuntime, createSubAgentRuntime, summarizeExecution, executionStats, } from './runtime.js';
export type { BackendSelection, CommandRecord, ExecutionMode, ExecutionRun, ExecutionState, ExecutionTask, PlannerResult, PromotionDecision, RuntimeWorkerResult, SkillPolicy, PromotionPolicy, DerivationPolicy, WorkerManifest, WorkerRole, WorkerSkillOverlay, WorkerVerification, } from './runtime.js';
