/** * claude-runner.ts — Claude CLI process management * * Extracted from executor.ts. Handles spawning `claude -p` processes, * retry/backoff logic, concurrent execution tracking, and context compression. */ import type { ChildProcess } from "node:child_process"; import type { ChainStep } from "./types.js"; export interface ClaudeResult { stdout: string; durationMs: number; inputTokens?: number; outputTokens?: number; } export declare const MAX_CONCURRENT_EXECUTIONS: number; /** * Validates that the Claude CLI binary is available in the system PATH. * Should be called once at startup. Sets internal state so subsequent * `runClaude()` calls can skip re-validation. */ export declare function validateClaudeBinary(): void; /** * Returns the number of currently running chain executions. */ export declare function getRunningExecutionCount(): number; /** * Returns true if a new execution can be started without exceeding the * MAX_CONCURRENT_EXECUTIONS limit. */ export declare function canStartExecution(): boolean; /** * Increments the running execution counter. Call when an execution starts. */ export declare function incrementRunningCount(): void; /** * Decrements the running execution counter. Call when an execution finishes. */ export declare function decrementRunningCount(): void; /** * Optional tracker for registering/unregistering child processes, * allowing the caller (executor) to manage cancellation of active processes. */ export interface ProcessTracker { register: (id: string, child: ChildProcess) => void; unregister: (id: string, child: ChildProcess) => void; } /** * Spawns `claude -p` with the given prompt and step configuration, streaming * output chunks via `onChunk`. Returns the full result including token usage. * * @param prompt - The prompt text to send to Claude * @param step - The chain step configuration (model, tools, cwd, etc.) * @param onChunk - Callback invoked with each text chunk as it streams * @param executionId - Optional execution ID for process tracking/cancellation * @param timeoutMs - Optional per-call timeout override (defaults to CLAUDE_TIMEOUT_MS) * @param processTracker - Optional tracker to register/unregister child processes for cancellation */ export declare function runClaude(prompt: string, step: ChainStep, onChunk: (chunk: string) => void, executionId?: string, timeoutMs?: number, processTracker?: ProcessTracker): Promise; /** * Runs a chain step with retry logic including exponential backoff and * optional model fallback. Delegates to `runClaude()` for each attempt. * * @param step - The chain step configuration * @param resolvedPrompt - The prompt with variables already resolved * @param onChunk - Callback for streaming output chunks * @param executionId - The execution ID for process tracking * @param onLog - Logging callback for retry status messages * @param processTracker - Optional tracker for process cancellation */ export declare function runStepWithRetry(step: ChainStep, resolvedPrompt: string, onChunk: (chunk: string) => void, executionId: string, onLog: (message: string, level: "info" | "warn" | "error") => void, processTracker?: ProcessTracker): Promise; /** * Applies context compression strategies to variables before they are * interpolated into a step prompt. Supports "full" (no change), "summarize" * (uses Haiku to compress), and "truncate:N" (hard character limit). * * @param vars - Current variable map * @param strategy - Map of variable name to compression action * @param onLog - Logging callback * @param processTracker - Optional tracker for the summarization subprocess */ export declare function applyContextStrategy(vars: Record, strategy: Record, onLog: (message: string, level: "info" | "warn" | "error") => void, processTracker?: ProcessTracker): Promise>; /** * Auto-compress vars in-place when total chars exceed budget. * Keeps input.* vars and the N most recent step outputs intact. * Summarizes older outputs via Haiku; falls back to truncation. */ export declare function autoCompressVars(vars: Record, maxChars: number, recentKeepCount: number, onLog: (message: string, level: "info" | "warn" | "error") => void, processTracker?: ProcessTracker, /** @internal test-only: override the compression function */ _compressFn?: (text: string) => Promise): Promise;