import type { StructuredLogger } from '../logger.js'; import type { CLIAgentOptions, CLIClientSpec } from '../cli-agents.js'; import type { ModelResolver } from '../model-resolver.js'; import type { CLIProvider, CLIBuilderConfig, CLIName, DecodeResult } from './index.js'; /** * Build the Claude-provider environment overlay for a critic process. This * is the SOLE source of ANTHROPIC_* and CLAUDE_CODE_OAUTH_TOKEN in the spawned * env — the base `secureEnv` whitelist excludes all provider auth — so * isolation is total and ambient routing vars can never leak in: * - native critic / non-routed client: inherits ONLY the native auth * pair (ANTHROPIC_API_KEY, CLAUDE_CODE_OAUTH_TOKEN); NEVER ambient * ANTHROPIC_BASE_URL/MODEL/SMALL_FAST_MODEL/CONFIG_DIR — those would * silently misroute a trusted critic (A1). * - routed client: isolated by default — only its own endpoint, token, * model, small-fast-model, and config dir; native auth ONLY on an * explicit includeProcessAuth:true opt-in (A2). * Trusts normalizeClaudeClient()'s resolved fields when present; falls back * to classifyRouting() for raw (un-normalized) specs so direct adapter * unit tests stay correct (INV-10). */ export declare function buildClaudeProviderEnv(client: CLIClientSpec | undefined, procEnv: NodeJS.ProcessEnv): Record; export declare class ClaudeAdapter implements CLIProvider { readonly name: CLIName; getConfig(): CLIBuilderConfig; buildCommand(userPrompt: string, systemPrompt: string, options: CLIAgentOptions, modelResolver: ModelResolver, secureEnv: Record): Promise<{ command: string; args: string[]; input: string; env: Record; tempMcpConfigPath?: string; model?: string; }>; /** * Decode Claude's stream-json NDJSON output into plain text. * Extracts text content blocks from all 'assistant' events across all turns. * Skips system events, user events (tool results with raw file contents), and * tool_use content blocks within assistant events. * Falls back to 'result' event if no assistant text was captured. */ decodeOutput(rawOutput: string, args: string[], log?: StructuredLogger): string; decode(stdout: string, _stderr: string, args: string[], log?: StructuredLogger): DecodeResult; /** * Structured decode of stream-json output. * * Refusal classification is keyed on `result.subtype` / `is_error` — * the binary's own protocol-level signal. Quota classification looks * at anchored Anthropic markers ONLY in the error-envelope `result` * field (already scoped to a known-error pathway), never in the * accumulated assistant text. */ private decodeStream; } /** * Classify a Claude error-envelope string against anchored Anthropic * quota markers. Operates only on the `result.result` / `result.error` * field already known to be inside an error result event — never on * assistant prose. Returns 'quota' for known quota markers, 'unknown' * otherwise so the caller can decide between `refused` and `error` kinds. * * The claude binary is now a gateway client for arbitrary Anthropic- * compatible backends (e.g. GLM/Z.AI), so markers cover OpenAI-compatible * and gateway error shapes alongside Anthropic's own. Categories (checked * in order auth → model → quota): * - 'auth' — invalid/expired credentials (401/403). The gateway * rejected the token; surfaced as a refusal so it is * attributed, not mistaken for an empty critique. * - 'model' — unknown/unsupported model id at the gateway. A config * defect, not a retryable refusal → caller maps to error. * - 'quota' — rate limit / usage cap (Anthropic + gateway vocab). * - 'unknown' otherwise — let the orchestrator surface a structured * error rather than fabricating a classification. * * No fallthrough to loose substrings; all markers are anchored and only * ever run against the known-error envelope, never assistant prose. */ export declare function classifyClaudeErrorReason(envelope: string | undefined): 'quota' | 'auth' | 'model' | 'unknown'; //# sourceMappingURL=claude-adapter.d.ts.map