/** * Same-tick call coalescing + typed batch / sticky-serve dispatch. * * Amdahl: serial cost is process spawn + SQLite open. Sticky serve kills spawn * for the whole Code Mode program; batch coalescing kills it per Promise.all wave. */ import type { MachineEnvelope } from "../runtime/runtime.js"; import type { ConnectorHost, DispatchSurface } from "./connector.js"; export type CodemodeToolCall = { tool: string; args: Record; }; export type DispatchStats = { waves: number; calls: number; batchedCalls: number; parallelSpawnCalls: number; stickyCalls: number; wallMs: number; }; /** One settled host call: which lane carried it and how long it took. */ export type DispatchCall = { tool: string; /** Short display target: query/symbol/module/path, whichever the call used. */ target: string; lane: "sticky" | "batch" | "spawn" | "serial"; ok: boolean; ms: number; }; export type BatchResult = { results: Array<{ id: string; ok: boolean; value?: unknown; error?: string; }>; mode?: string; wall_ms?: number; all_ok?: boolean; }; export type StickyWorker = { call(tool: string, args: Record, options?: { signal?: AbortSignal; }): Promise; batch(calls: Array<{ id: string; tool: string; args: Record; }>, options?: { signal?: AbortSignal; }): Promise; end(): Promise; /** True after timeout/crash/end. Missing means "assume live". */ closed?: () => boolean; }; export type BatchCapableHost = ConnectorHost & { /** One-shot warm batch (codemode-batch). */ runBatch?(calls: Array<{ id: string; tool: string; args: Record; }>, context: { cwd: string; }, options?: { signal?: AbortSignal; }): Promise; /** Sticky NDJSON worker for the whole Code Mode program (preferred). */ sticky?: StickyWorker | null; }; export declare const MUTATING_TOOLS: ReadonlySet; /** * Wraps a host so Promise.all([asgrep.search, asgrep.defs, …]) collapses into * one microtask wave. Prefers sticky serve → one-shot batch → overlapped spawn. */ export declare function createCodemodeDispatcher(host: BatchCapableHost): { host: DispatchSurface; stats: () => DispatchStats; trace: () => DispatchCall[]; resetStats: () => void; }; export declare function argvFor(tool: string, args: Record): string[]; export declare function asEnvelope(value: unknown, command?: string): MachineEnvelope; /** One-shot batch via stdin (no tempfile) when spawn-with-stdin is available. */ export declare function runNativeBatch(run: ConnectorHost["run"], calls: Array<{ id: string; tool: string; args: Record; }>, context: { cwd: string; }, options?: { signal?: AbortSignal; }, writeBatch?: (body: string, context: { cwd: string; }, options?: { signal?: AbortSignal; }) => Promise): Promise;