{"version":3,"file":"exceptions.mjs","names":[],"sources":["../../../../src/batteries/llm/claude_code_cli/exceptions.ts"],"sourcesContent":["/**\n * Battery-scoped exception constructors for the Claude Code CLI adapter.\n *\n * @module @nhtio/adk/batteries/llm/claude_code_cli/exceptions\n *\n * @remarks\n * Battery-scoped exception classes minted via `createException` from `@nhtio/adk/factories`.\n * Malformed NDJSON frames (either the wrapper's own inbound-command reader, or its translation of\n * Claude's stream-json) are explicitly NOT a distinct exception — they are swallowed and surfaced\n * via `helpers.log.trace`, matching the Ollama battery's malformed-line policy.\n */\n\nimport { createException } from '@nhtio/adk/factories'\n\n/**\n * Thrown when the resolved adapter options (constructor, executor overrides, or per-dispatch\n * `stash.claudeCodeCli`) fail validation — including `extraArgs` security-flag rejection, the\n * `apiKey`/`authToken` XOR violation, and the POSIX-only platform guard.\n */\nexport const E_INVALID_CLAUDE_CODE_CLI_OPTIONS = createException<[string]>(\n  'E_INVALID_CLAUDE_CODE_CLI_OPTIONS',\n  'Invalid Claude Code CLI adapter options: %s',\n  'E_INVALID_CLAUDE_CODE_CLI_OPTIONS',\n  529,\n  true\n)\n\n/** Thrown when the `claude` binary cannot be located/spawned. */\nexport const E_CLAUDE_CODE_CLI_BINARY_NOT_FOUND = createException<[string]>(\n  'E_CLAUDE_CODE_CLI_BINARY_NOT_FOUND',\n  'Claude Code CLI binary not found: %s',\n  'E_CLAUDE_CODE_CLI_BINARY_NOT_FOUND',\n  500,\n  true\n)\n\n/** Thrown when the wrapper process itself fails to spawn. */\nexport const E_CLAUDE_CODE_CLI_WRAPPER_SPAWN_ERROR = createException<[string]>(\n  'E_CLAUDE_CODE_CLI_WRAPPER_SPAWN_ERROR',\n  'Failed to spawn the Claude Code CLI wrapper process: %s',\n  'E_CLAUDE_CODE_CLI_WRAPPER_SPAWN_ERROR',\n  500,\n  true\n)\n\n/** Thrown when the wrapper process crashes or exits abnormally mid-dispatch. */\nexport const E_CLAUDE_CODE_CLI_WRAPPER_CRASHED = createException<[string]>(\n  'E_CLAUDE_CODE_CLI_WRAPPER_CRASHED',\n  'Claude Code CLI wrapper process crashed: %s',\n  'E_CLAUDE_CODE_CLI_WRAPPER_CRASHED',\n  500,\n  false\n)\n\n/** Thrown when the wrapper process exits with no terminal `result`/`error` event observed. */\nexport const E_CLAUDE_CODE_CLI_PROCESS_EXITED_NONZERO = createException<[number, string]>(\n  'E_CLAUDE_CODE_CLI_PROCESS_EXITED_NONZERO',\n  'Claude Code CLI wrapper process exited (code %d) with no terminal event observed: %s',\n  'E_CLAUDE_CODE_CLI_PROCESS_EXITED_NONZERO',\n  502,\n  false\n)\n\n/** Thrown on a transport-level stream failure between the adapter and the wrapper. */\nexport const E_CLAUDE_CODE_CLI_STREAM_ERROR = createException<[string]>(\n  'E_CLAUDE_CODE_CLI_STREAM_ERROR',\n  'Claude Code CLI stream error: %s',\n  'E_CLAUDE_CODE_CLI_STREAM_ERROR',\n  502,\n  false\n)\n\n/** Thrown when the wrapper's stdout goes idle for longer than `streamIdleTimeoutMs`. */\nexport const E_CLAUDE_CODE_CLI_STREAM_STALLED = createException<[number]>(\n  'E_CLAUDE_CODE_CLI_STREAM_STALLED',\n  'Claude Code CLI stream stalled (no output for %dms)',\n  'E_CLAUDE_CODE_CLI_STREAM_STALLED',\n  504,\n  false\n)\n\n/** Thrown when the wrapper does not signal `ready` and Claude's `system/init` within `startupTimeoutMs`. */\nexport const E_CLAUDE_CODE_CLI_STARTUP_TIMEOUT = createException<[number]>(\n  'E_CLAUDE_CODE_CLI_STARTUP_TIMEOUT',\n  'Claude Code CLI wrapper did not complete startup within %dms',\n  'E_CLAUDE_CODE_CLI_STARTUP_TIMEOUT',\n  504,\n  false\n)\n\n/**\n * Thrown when the wrapper's own MCP bridge server fails to start, OR Claude's `system/init`\n * reports an `mcp_server_errors` entry naming the bridge, OR the `@modelcontextprotocol/sdk`\n * optional peer is missing at wrapper startup.\n */\nexport const E_CLAUDE_CODE_CLI_MCP_BRIDGE_STARTUP_FAILED = createException<[string]>(\n  'E_CLAUDE_CODE_CLI_MCP_BRIDGE_STARTUP_FAILED',\n  'Claude Code CLI MCP bridge failed to start: %s',\n  'E_CLAUDE_CODE_CLI_MCP_BRIDGE_STARTUP_FAILED',\n  500,\n  false\n)\n\n/**\n * Thrown when the assembled request exceeds the configured `contextWindow` during the pre-flight\n * context-window guard. Only raised when `tokenEncoding` is non-null. Carries `{ total,\n * contextWindow, tokenEncoding, perBucket }` in the message so middleware can target shedding.\n *\n * @remarks\n * This is the ADK-side token-budget guard and refuses the request before the Claude Code CLI\n * wrapper is spawned. The rendered prompt and append-system prompt are measured exactly; it is\n * an honest floor only because Claude Code injects additional vendor-owned content (the Agent SDK\n * preamble, CWD/Date, billing header, built-in tool schemas, and MCP declaration envelope).\n */\nexport const E_CLAUDE_CODE_CLI_CONTEXT_OVERFLOW = createException<[number, number, string, string]>(\n  'E_CLAUDE_CODE_CLI_CONTEXT_OVERFLOW',\n  'Claude Code CLI request token weight (%d) exceeds context window (%d) under encoding %s. Per-bucket breakdown: %s',\n  'E_CLAUDE_CODE_CLI_CONTEXT_OVERFLOW',\n  529,\n  true\n)\n\n/**\n * Thrown when Claude's terminal `result` reports `isError: true` for a terminal error subtype\n * other than `error_max_turns`, notably CLI-native budget exhaustion from `--max-budget-usd`.\n * The `error_max_turns` subtype is the normal successful completion signal for this adapter's\n * fixed single-turn dispatch contract.\n */\nexport const E_CLAUDE_CODE_CLI_TURN_FAILED = createException<[string, string]>(\n  'E_CLAUDE_CODE_CLI_TURN_FAILED',\n  'Claude Code CLI turn failed (%s): %s',\n  'E_CLAUDE_CODE_CLI_TURN_FAILED',\n  529,\n  false\n)\n\n/**\n * Thrown when a {@link @nhtio/adk!Media} whose modality cannot be represented reaches either\n * direction of this battery under the corresponding `unsupportedMediaPolicy`/\n * `unsupportedResultMediaPolicy: 'throw'` — bidirectional: inbound prompt media (a `-p` string has\n * no native image channel) and outbound tool-result media (only text/image MCP content blocks are\n * supported).\n */\nexport const E_CLAUDE_CODE_CLI_UNSUPPORTED_MEDIA_MODALITY = createException<\n  [string, string, string]\n>(\n  'E_CLAUDE_CODE_CLI_UNSUPPORTED_MEDIA_MODALITY',\n  'Claude Code CLI battery does not support media of kind %s (mime=%s, filename=%s) in this direction. Configure the relevant unsupportedMediaPolicy option to `fallback-stash` or `synthetic-description` to handle this case.',\n  'E_CLAUDE_CODE_CLI_UNSUPPORTED_MEDIA_MODALITY',\n  422,\n  true\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,IAAa,oCAAoC,gBAC/C,qCACA,+CACA,qCACA,KACA,IACF;;AAGA,IAAa,qCAAqC,gBAChD,sCACA,wCACA,sCACA,KACA,IACF;;AAGA,IAAa,wCAAwC,gBACnD,yCACA,2DACA,yCACA,KACA,IACF;;AAGA,IAAa,oCAAoC,gBAC/C,qCACA,+CACA,qCACA,KACA,KACF;;AAGA,IAAa,2CAA2C,gBACtD,4CACA,wFACA,4CACA,KACA,KACF;;AAGA,IAAa,iCAAiC,gBAC5C,kCACA,oCACA,kCACA,KACA,KACF;;AAGA,IAAa,mCAAmC,gBAC9C,oCACA,uDACA,oCACA,KACA,KACF;;AAGA,IAAa,oCAAoC,gBAC/C,qCACA,gEACA,qCACA,KACA,KACF;;;;;;AAOA,IAAa,8CAA8C,gBACzD,+CACA,kDACA,+CACA,KACA,KACF;;;;;;;;;;;;AAaA,IAAa,qCAAqC,gBAChD,sCACA,qHACA,sCACA,KACA,IACF;;;;;;;AAQA,IAAa,gCAAgC,gBAC3C,iCACA,wCACA,iCACA,KACA,KACF;;;;;;;;AASA,IAAa,+CAA+C,gBAG1D,gDACA,gOACA,gDACA,KACA,IACF"}