/**
 * PipeSessionSpawner — Spawns lightweight `claude -p` sessions for simple
 * threadline queries. Sessions auto-exit when done, reducing zombie risk
 * and session slot consumption.
 *
 * Part of RFC: Persistent Listener Daemon Architecture (Phase 2).
 *
 * Security model:
 * - Messages wrapped in <untrusted-message> XML tags (injection-hardened)
 * - Thread history LLM-summarized before injection (strips jailbreak assembly)
 * - Tool restrictions: read-only + threadline_send
 * - Path grant-list: stateDir ALWAYS excluded regardless of config
 * - IQS >= 70 required for pipe-mode eligibility
 * - 10-minute timeout with process-group kill
 */
import type { IntelligenceProvider } from '../core/types.js';
import type { IntelligenceFramework } from '../core/intelligenceProviderFactory.js';
export interface PipeSessionConfig {
    /** Model for pipe sessions (default: 'sonnet') */
    model: string;
    /** Timeout in ms (default: 600000 = 10 minutes) */
    timeoutMs: number;
    /** Warning time in ms before timeout (default: 480000 = 8 minutes) */
    warningMs: number;
    /** Max concurrent pipe sessions */
    maxConcurrent: number;
    /** Tools allowed in pipe sessions */
    allowedTools: string[];
    /** Paths allowed for file access (stateDir always excluded) */
    allowedPaths: string[];
    /** Minimum IQS band for pipe-mode (default: 70) */
    minIqsBand: number;
    /** State directory (for stateDir exclusion) */
    stateDir: string;
    /** Temp directory for prompt files */
    tmpDir: string;
    /**
     * Which framework's CLI to spawn pipe sessions in. Defaults to
     * 'claude-code' for backwards-compat. Provider-portability v1.0.0:
     * routes spawn() through buildHeadlessLaunch so Codex agents can
     * also handle pipe-mode threadline traffic.
     */
    framework: IntelligenceFramework;
    /**
     * Absolute path to the framework's CLI binary. Required when framework
     * is set explicitly; defaults to 'claude' for back-compat (PATH lookup).
     */
    binaryPath: string;
    /**
     * Per-agent Codex threadline MCP override `{command, args}` (from
     * resolveThreadlineMcpEntry). When set, a codex pipe-reply worker uses THIS
     * agent's threadline MCP instead of whichever agent last won the shared
     * ~/.codex/config.toml. Ignored for non-codex frameworks.
     */
    codexThreadlineMcp?: {
        command: string;
        args: string[];
    };
    /**
     * Live accessor for intelligence.subscriptionPath.mode
     * (june15-headless-spawn-reroute, spec Class 7 + finding S4). The pipe
     * path is structurally isolated — it shells `buildHeadlessLaunch` argv
     * directly, with no SessionManager and therefore no subscription-path
     * reroute. Under 'force' (zero `claude -p` traffic is the contract) a
     * claude-code pipe spawn must REFUSE — from inside spawn(), returning
     * `{spawned: false}`, which is the only shape where the caller falls
     * through to the normal (rerouted) A2A path instead of dropping the
     * reply. Absent (the default) or non-claude frameworks: unchanged.
     */
    getSubscriptionPathMode?: () => 'off' | 'auto' | 'force';
    /**
     * Optional subscription-quota gate (finding S1) — same seam as
     * SpawnRequestManager's. Wired to QuotaTracker.shouldSpawnSession only
     * when the subscription-path reroute is active; a quota-blocked pipe
     * spawn refuses (falls through to the gated A2A path) instead of adding
     * load to the operator's 5h window.
     */
    shouldSpawnSession?: () => {
        allowed: boolean;
        reason: string;
    };
}
export interface PipeSpawnRequest {
    threadId: string;
    messageText: string;
    fromFingerprint: string;
    fromName: string;
    trustLevel: string;
    iqsBand?: number;
    threadHistory?: string[];
}
export interface PipeSpawnResult {
    spawned: boolean;
    sessionName?: string;
    pid?: number;
    reason?: string;
}
/**
 * Classify a message as TASK (needs interactive) or QUERY (can use pipe).
 * Uses a Haiku-class LLM call wrapped in injection-resistant tags.
 *
 * Returns 'pipe' or 'interactive'.
 */
export declare function classifyIntent(messageText: string, options?: {
    timeout?: number;
    intelligence?: IntelligenceProvider;
}): Promise<'pipe' | 'interactive'>;
/**
 * Build an injection-hardened prompt for pipe sessions.
 * Messages and thread history are wrapped in XML tags with explicit
 * untrusted-content instructions.
 */
export declare function buildPipePrompt(request: PipeSpawnRequest, summarizedHistory?: string): string;
/**
 * Summarize thread history to strip instruction fragments.
 * Uses a Haiku-class LLM call.
 */
export declare function summarizeThreadHistory(history: string[], options?: {
    intelligence?: IntelligenceProvider;
}): Promise<string>;
export declare class PipeSessionSpawner {
    private config;
    private activeSessions;
    private spawnCount;
    private completedCount;
    private timedOutCount;
    constructor(config: Partial<PipeSessionConfig> & {
        stateDir: string;
    });
    /**
     * Check if a message should use pipe-mode.
     * Returns true if all eligibility checks pass.
     */
    shouldUsePipeMode(request: PipeSpawnRequest): {
        eligible: boolean;
        reason?: string;
    };
    /**
     * Check if there is already an active pipe session for this thread.
     * Prevents rapid-fire same-thread messages from killing each other's tmux sessions.
     */
    hasActiveSessionForThread(threadId: string): boolean;
    /**
     * Spawn a pipe-mode session.
     */
    spawn(request: PipeSpawnRequest, summarizedHistory?: string): Promise<PipeSpawnResult>;
    /**
     * Monitor a pipe session for completion and clean up when done.
     */
    private monitorSession;
    /**
     * Force-kill a pipe session (timeout or manual).
     */
    private killPipeSession;
    /**
     * Clean up session tracking and timers.
     */
    private cleanupSession;
    /**
     * Get metrics for observability.
     */
    getMetrics(): {
        active: number;
        spawned: number;
        completed: number;
        timedOut: number;
        sessions: Array<{
            name: string;
            threadId: string;
            runtimeMs: number;
        }>;
    };
    /**
     * Kill all active pipe sessions (for shutdown).
     */
    killAll(): void;
}
//# sourceMappingURL=PipeSessionSpawner.d.ts.map