@warlock.js/ai-cli 5.53.1 → 5.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/cjs/index.cjs +42 -3
- package/cjs/index.cjs.map +1 -1
- package/esm/adapters/aider.d.mts.map +1 -1
- package/esm/adapters/aider.mjs +8 -0
- package/esm/adapters/aider.mjs.map +1 -1
- package/esm/adapters/amp.mjs +1 -0
- package/esm/adapters/amp.mjs.map +1 -1
- package/esm/adapters/antigravity.d.mts.map +1 -1
- package/esm/adapters/antigravity.mjs +1 -0
- package/esm/adapters/antigravity.mjs.map +1 -1
- package/esm/adapters/claude-code.mjs +5 -0
- package/esm/adapters/claude-code.mjs.map +1 -1
- package/esm/adapters/codex.d.mts.map +1 -1
- package/esm/adapters/codex.mjs +1 -0
- package/esm/adapters/codex.mjs.map +1 -1
- package/esm/adapters/copilot.d.mts.map +1 -1
- package/esm/adapters/copilot.mjs +1 -0
- package/esm/adapters/copilot.mjs.map +1 -1
- package/esm/adapters/cursor.d.mts.map +1 -1
- package/esm/adapters/cursor.mjs +1 -0
- package/esm/adapters/cursor.mjs.map +1 -1
- package/esm/adapters/droid.d.mts.map +1 -1
- package/esm/adapters/droid.mjs +1 -0
- package/esm/adapters/droid.mjs.map +1 -1
- package/esm/adapters/grok.d.mts.map +1 -1
- package/esm/adapters/grok.mjs +1 -0
- package/esm/adapters/grok.mjs.map +1 -1
- package/esm/adapters/kimi.d.mts.map +1 -1
- package/esm/adapters/kimi.mjs +5 -0
- package/esm/adapters/kimi.mjs.map +1 -1
- package/esm/adapters/mistral-vibe.d.mts.map +1 -1
- package/esm/adapters/mistral-vibe.mjs +1 -0
- package/esm/adapters/mistral-vibe.mjs.map +1 -1
- package/esm/adapters/opencode.d.mts.map +1 -1
- package/esm/adapters/opencode.mjs +6 -0
- package/esm/adapters/opencode.mjs.map +1 -1
- package/esm/adapters/qwen-code.mjs +6 -0
- package/esm/adapters/qwen-code.mjs.map +1 -1
- package/esm/adapters/reasonix.d.mts.map +1 -1
- package/esm/adapters/reasonix.mjs +1 -0
- package/esm/adapters/reasonix.mjs.map +1 -1
- package/esm/cli-agent.mjs +2 -2
- package/esm/cli-agent.mjs.map +1 -1
- package/esm/contracts/adapter.contract.d.mts +6 -0
- package/esm/contracts/adapter.contract.d.mts.map +1 -1
- package/esm/contracts/options.type.d.mts +2 -1
- package/esm/contracts/options.type.d.mts.map +1 -1
- package/esm/session/environment.mjs +1 -1
- package/esm/session/environment.mjs.map +1 -1
- package/llms-full.txt +2 -1
- package/package.json +2 -2
- package/skills/run-cli-agents/SKILL.md +1 -1
- package/skills/write-a-cli-adapter/SKILL.md +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"droid.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/droid.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { CliAdapter, CliLaunchFile, CliParsedEvent, CliStreamParser } from \"../contracts\";\nimport { jsonLinesParser, outputText, recordField, stringField } from \"../stream/json-lines\";\nimport {\n anthropicUsage,\n argvPrompt,\n jsonFile,\n mcpServersJson,\n promptFile,\n requirePrivateHome,\n} from \"./shared\";\n\n/**\n * Factory Droid (`droid`, npm `droid` / `@factory/cli`).\n *\n * Verified against the real `droid exec --help` of 0.244.0, a real\n * `droid exec` run without credentials (init and error lines), the field\n * names in the shipped code and the docs (`docs.factory.ai/cli/droid-exec`,\n * `/cli/configuration/mcp`), 2026-10-17.\n *\n * - Headless: `droid exec -o stream-json <prompt>` (or `-f <file>`).\n * - Stream: `system/init` (`session_id`, `model`), whole `message` records\n * (`role`, `text`), `tool_call` (`id`, `toolName`, `parameters`),\n * `tool_result` (`id`, `isError`, `value` | `error.message`), a final\n * `completion` (`finalText`, `usage` with Anthropic-style\n * `input_tokens`/`cache_read_input_tokens`/`cache_creation_input_tokens`,\n * read with Anthropic semantics) and `error` (`source`, `message`).\n * Billing is in Factory credits; no USD cost is reported.\n * - Permissions: `standard` is Droid's default **read-only** autonomy; raise\n * it with `args: [\"--auto\", \"medium\"]` (low | medium | high). Bypass is\n * `--skip-permissions-unsafe`. Blocked actions end the run non-zero.\n * - MCP: `<home>/.factory/mcp.json` (`mcpServers`); the home is relocated\n * with `FACTORY_HOME_OVERRIDE` (found in the shipped code and confirmed\n * with `droid mcp list`), so per-run MCP needs a private home.\n * - Auth: `FACTORY_API_KEY`.\n */\nexport const droidAdapter: CliAdapter = {\n name: \"droid\",\n title: \"Factory Droid\",\n command: \"droid\",\n apiKeyEnv: [\"FACTORY_API_KEY\"],\n homeEnv: [\"FACTORY_HOME_OVERRIDE\"],\n transports: [\"argv\", \"file\"],\n effort: true,\n mcp: true,\n probe: { help: [[\"exec\", \"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"0.244.0\",\n verifiedBy: \"help\",\n sources: [\n \"https://docs.factory.ai/cli/droid-exec/overview\",\n \"https://docs.factory.ai/cli/configuration/mcp\",\n \"https://www.npmjs.com/package/droid\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"exec\", \"--output-format\", \"stream-json\", \"--cwd\", context.cwd];\n const requires = [\"--output-format\", \"stream-json\", \"--cwd\"];\n const files: CliLaunchFile[] = [];\n let tail: string[];\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.effort !== undefined) {\n // Accepted per model from off | none | minimal | low | medium | high | xhigh | max.\n args.push(\"--reasoning-effort\", context.effort);\n requires.push(\"--reasoning-effort\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--session-id\", context.resume);\n requires.push(\"--session-id\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--skip-permissions-unsafe\");\n requires.push(\"--skip-permissions-unsafe\");\n }\n\n if (context.mcp !== undefined) {\n const home = requirePrivateHome(context, droidAdapter, \"MCP servers\");\n\n files.push({\n path: path.join(home, \".factory\", \"mcp.json\"),\n content: jsonFile({ mcpServers: mcpServersJson(context.mcp, { typeField: true }) }),\n });\n }\n\n if (context.transport === \"file\") {\n const prompt = promptFile(context);\n\n files.push(prompt);\n tail = [\"--file\", prompt.path];\n requires.push(\"--file\");\n } else {\n tail = [argvPrompt(context.prompt)];\n }\n\n return {\n args,\n tail,\n env: {\n ...(context.home !== undefined ? { FACTORY_HOME_OVERRIDE: context.home } : {}),\n FACTORY_DROID_AUTO_UPDATE_ENABLED: \"false\",\n },\n files,\n requires,\n };\n },\n parser: createDroidParser,\n};\n\n/** Parser for `droid exec -o stream-json`. */\nexport function createDroidParser(): CliStreamParser {\n return jsonLinesParser((record): CliParsedEvent[] => {\n switch (stringField(record, \"type\")) {\n case \"system\":\n return stringField(record, \"subtype\") === \"init\"\n ? [\n {\n type: \"session.started\",\n sessionRef: stringField(record, \"session_id\"),\n model: stringField(record, \"model\"),\n raw: record,\n },\n ]\n : [];\n case \"message\": {\n const text = stringField(record, \"text\") ?? \"\";\n\n return stringField(record, \"role\") === \"assistant\" && text.length > 0\n ? [{ type: \"message\", text, delta: false, raw: record }]\n : [];\n }\n case \"tool_call\":\n return [\n {\n type: \"tool.call\",\n id: stringField(record, \"id\") ?? \"\",\n name: stringField(record, \"toolName\") ?? stringField(record, \"toolId\") ?? \"\",\n input: record.parameters,\n raw: record,\n },\n ];\n case \"tool_result\": {\n const error = recordField(record, \"error\");\n const isError = record.isError === true || error !== undefined;\n\n return [\n {\n type: \"tool.result\",\n id: stringField(record, \"id\") ?? \"\",\n output:\n isError && error !== undefined\n ? (stringField(error, \"message\") ?? \"\")\n : outputText(record.value),\n isError,\n raw: record,\n },\n ];\n }\n case \"completion\": {\n const events: CliParsedEvent[] = [];\n const usage = anthropicUsage(recordField(record, \"usage\"));\n\n if (usage !== undefined) {\n const thinking = recordField(record, \"usage\")?.thinking_tokens;\n\n if (typeof thinking === \"number\" && thinking > 0) {\n usage.reasoningTokens = thinking;\n }\n\n events.push({ type: \"usage\", usage, cumulative: true, raw: record });\n }\n\n const text = stringField(record, \"finalText\") ?? \"\";\n\n if (text.length > 0) {\n events.push({ type: \"message\", text, delta: false, final: true, raw: record });\n }\n\n return events;\n }\n case \"error\":\n return [\n {\n type: \"error\",\n message: stringField(record, \"message\") ?? \"Droid reported an error\",\n fatal: true,\n raw: record,\n },\n ];\n default:\n return [];\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,eAA2B;CACtC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,iBAAiB;CAC7B,SAAS,CAAC,uBAAuB;CACjC,YAAY,CAAC,QAAQ,MAAM;CAC3B,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,QAAQ,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CAC5D,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS;GACP;GACA;GACA;EACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,MAAM,OAAO;GAAC;GAAQ;GAAmB;GAAe;GAAS,QAAQ;EAAG;EAC5E,MAAM,WAAW;GAAC;GAAmB;GAAe;EAAO;EAC3D,MAAM,QAAyB,CAAC;EAChC,IAAI;EAEJ,IAAI,QAAQ,UAAU,QAAW;GAC/B,KAAK,KAAK,WAAW,QAAQ,KAAK;GAClC,SAAS,KAAK,SAAS;EACzB;EAEA,IAAI,QAAQ,WAAW,QAAW;GAEhC,KAAK,KAAK,sBAAsB,QAAQ,MAAM;GAC9C,SAAS,KAAK,oBAAoB;EACpC;EAEA,IAAI,QAAQ,WAAW,QAAW;GAChC,KAAK,KAAK,gBAAgB,QAAQ,MAAM;GACxC,SAAS,KAAK,cAAc;EAC9B;EAEA,IAAI,QAAQ,eAAe,UAAU;GACnC,KAAK,KAAK,2BAA2B;GACrC,SAAS,KAAK,2BAA2B;EAC3C;EAEA,IAAI,QAAQ,QAAQ,QAAW;GAC7B,MAAM,OAAO,mBAAmB,SAAS,cAAc,aAAa;GAEpE,MAAM,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UAAU;IAErD,OAAO,CACL;KACE,MAAM;KACN,IAAI,YAAY,QAAQ,IAAI,KAAK;KACjC,QACE,WAAW,UAAU,SAChB,YAAY,OAAO,SAAS,KAAK,KAClC,WAAW,OAAO,KAAK;KAC7B;KACA,KAAK;IACP,CACF;GACF;GACA,KAAK,cAAc;IACjB,MAAM,SAA2B,CAAC;IAClC,MAAM,QAAQ,eAAe,YAAY,QAAQ,OAAO,CAAC;IAEzD,IAAI,UAAU,QAAW;KACvB,MAAM,WAAW,YAAY,QAAQ,OAAO,CAAC,EAAE;KAE/C,IAAI,OAAO,aAAa,YAAY,WAAW,GAC7C,MAAM,kBAAkB;KAG1B,OAAO,KAAK;MAAE,MAAM;MAAS;MAAO,YAAY;MAAM,KAAK;KAAO,CAAC;IACrE;IAEA,MAAM,OAAO,YAAY,QAAQ,WAAW,KAAK;IAEjD,IAAI,KAAK,SAAS,GAChB,OAAO,KAAK;KAAE,MAAM;KAAW;KAAM,OAAO;KAAO,OAAO;KAAM,KAAK;IAAO,CAAC;IAG/E,OAAO;GACT;GACA,KAAK,SACH,OAAO,CACL;IACE,MAAM;IACN,SAAS,YAAY,QAAQ,SAAS,KAAK;IAC3C,OAAO;IACP,KAAK;GACP,CACF;GACF,SACE,OAAO,CAAC;EACZ;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"droid.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/droid.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { CliAdapter, CliLaunchFile, CliParsedEvent, CliStreamParser } from \"../contracts\";\nimport { jsonLinesParser, outputText, recordField, stringField } from \"../stream/json-lines\";\nimport {\n anthropicUsage,\n argvPrompt,\n jsonFile,\n mcpServersJson,\n promptFile,\n requirePrivateHome,\n} from \"./shared\";\n\n/**\n * Factory Droid (`droid`, npm `droid` / `@factory/cli`).\n *\n * Verified against the real `droid exec --help` of 0.244.0, a real\n * `droid exec` run without credentials (init and error lines), the field\n * names in the shipped code and the docs (`docs.factory.ai/cli/droid-exec`,\n * `/cli/configuration/mcp`), 2026-10-17.\n *\n * - Headless: `droid exec -o stream-json <prompt>` (or `-f <file>`).\n * - Stream: `system/init` (`session_id`, `model`), whole `message` records\n * (`role`, `text`), `tool_call` (`id`, `toolName`, `parameters`),\n * `tool_result` (`id`, `isError`, `value` | `error.message`), a final\n * `completion` (`finalText`, `usage` with Anthropic-style\n * `input_tokens`/`cache_read_input_tokens`/`cache_creation_input_tokens`,\n * read with Anthropic semantics) and `error` (`source`, `message`).\n * Billing is in Factory credits; no USD cost is reported.\n * - Permissions: `standard` is Droid's default **read-only** autonomy; raise\n * it with `args: [\"--auto\", \"medium\"]` (low | medium | high). Bypass is\n * `--skip-permissions-unsafe`. Blocked actions end the run non-zero.\n * - MCP: `<home>/.factory/mcp.json` (`mcpServers`); the home is relocated\n * with `FACTORY_HOME_OVERRIDE` (found in the shipped code and confirmed\n * with `droid mcp list`), so per-run MCP needs a private home.\n * - Auth: `FACTORY_API_KEY`.\n */\nexport const droidAdapter: CliAdapter = {\n name: \"droid\",\n title: \"Factory Droid\",\n command: \"droid\",\n apiKeyEnv: [\"FACTORY_API_KEY\"],\n passEnv: [],\n homeEnv: [\"FACTORY_HOME_OVERRIDE\"],\n transports: [\"argv\", \"file\"],\n effort: true,\n mcp: true,\n probe: { help: [[\"exec\", \"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"0.244.0\",\n verifiedBy: \"help\",\n sources: [\n \"https://docs.factory.ai/cli/droid-exec/overview\",\n \"https://docs.factory.ai/cli/configuration/mcp\",\n \"https://www.npmjs.com/package/droid\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"exec\", \"--output-format\", \"stream-json\", \"--cwd\", context.cwd];\n const requires = [\"--output-format\", \"stream-json\", \"--cwd\"];\n const files: CliLaunchFile[] = [];\n let tail: string[];\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.effort !== undefined) {\n // Accepted per model from off | none | minimal | low | medium | high | xhigh | max.\n args.push(\"--reasoning-effort\", context.effort);\n requires.push(\"--reasoning-effort\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--session-id\", context.resume);\n requires.push(\"--session-id\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--skip-permissions-unsafe\");\n requires.push(\"--skip-permissions-unsafe\");\n }\n\n if (context.mcp !== undefined) {\n const home = requirePrivateHome(context, droidAdapter, \"MCP servers\");\n\n files.push({\n path: path.join(home, \".factory\", \"mcp.json\"),\n content: jsonFile({ mcpServers: mcpServersJson(context.mcp, { typeField: true }) }),\n });\n }\n\n if (context.transport === \"file\") {\n const prompt = promptFile(context);\n\n files.push(prompt);\n tail = [\"--file\", prompt.path];\n requires.push(\"--file\");\n } else {\n tail = [argvPrompt(context.prompt)];\n }\n\n return {\n args,\n tail,\n env: {\n ...(context.home !== undefined ? { FACTORY_HOME_OVERRIDE: context.home } : {}),\n FACTORY_DROID_AUTO_UPDATE_ENABLED: \"false\",\n },\n files,\n requires,\n };\n },\n parser: createDroidParser,\n};\n\n/** Parser for `droid exec -o stream-json`. */\nexport function createDroidParser(): CliStreamParser {\n return jsonLinesParser((record): CliParsedEvent[] => {\n switch (stringField(record, \"type\")) {\n case \"system\":\n return stringField(record, \"subtype\") === \"init\"\n ? [\n {\n type: \"session.started\",\n sessionRef: stringField(record, \"session_id\"),\n model: stringField(record, \"model\"),\n raw: record,\n },\n ]\n : [];\n case \"message\": {\n const text = stringField(record, \"text\") ?? \"\";\n\n return stringField(record, \"role\") === \"assistant\" && text.length > 0\n ? [{ type: \"message\", text, delta: false, raw: record }]\n : [];\n }\n case \"tool_call\":\n return [\n {\n type: \"tool.call\",\n id: stringField(record, \"id\") ?? \"\",\n name: stringField(record, \"toolName\") ?? stringField(record, \"toolId\") ?? \"\",\n input: record.parameters,\n raw: record,\n },\n ];\n case \"tool_result\": {\n const error = recordField(record, \"error\");\n const isError = record.isError === true || error !== undefined;\n\n return [\n {\n type: \"tool.result\",\n id: stringField(record, \"id\") ?? \"\",\n output:\n isError && error !== undefined\n ? (stringField(error, \"message\") ?? \"\")\n : outputText(record.value),\n isError,\n raw: record,\n },\n ];\n }\n case \"completion\": {\n const events: CliParsedEvent[] = [];\n const usage = anthropicUsage(recordField(record, \"usage\"));\n\n if (usage !== undefined) {\n const thinking = recordField(record, \"usage\")?.thinking_tokens;\n\n if (typeof thinking === \"number\" && thinking > 0) {\n usage.reasoningTokens = thinking;\n }\n\n events.push({ type: \"usage\", usage, cumulative: true, raw: record });\n }\n\n const text = stringField(record, \"finalText\") ?? \"\";\n\n if (text.length > 0) {\n events.push({ type: \"message\", text, delta: false, final: true, raw: record });\n }\n\n return events;\n }\n case \"error\":\n return [\n {\n type: \"error\",\n message: stringField(record, \"message\") ?? \"Droid reported an error\",\n fatal: true,\n raw: record,\n },\n ];\n default:\n return [];\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,eAA2B;CACtC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,iBAAiB;CAC7B,SAAS,CAAC;CACV,SAAS,CAAC,uBAAuB;CACjC,YAAY,CAAC,QAAQ,MAAM;CAC3B,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,QAAQ,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CAC5D,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS;GACP;GACA;GACA;EACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,MAAM,OAAO;GAAC;GAAQ;GAAmB;GAAe;GAAS,QAAQ;EAAG;EAC5E,MAAM,WAAW;GAAC;GAAmB;GAAe;EAAO;EAC3D,MAAM,QAAyB,CAAC;EAChC,IAAI;EAEJ,IAAI,QAAQ,UAAU,QAAW;GAC/B,KAAK,KAAK,WAAW,QAAQ,KAAK;GAClC,SAAS,KAAK,SAAS;EACzB;EAEA,IAAI,QAAQ,W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ts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/grok.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgDa,aAAa;;
|
|
1
|
+
{"version":3,"file":"grok.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/grok.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;qBAgDa,aAAa;;wBAuGV,oBAAoB"}
|
package/esm/adapters/grok.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grok.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/grok.ts"],"sourcesContent":["import path from \"node:path\";\nimport type {\n CliAdapter,\n CliLaunchFile,\n CliMcpServers,\n CliParsedEvent,\n CliStreamParser,\n} from \"../contracts\";\nimport {\n jsonLinesParser,\n numberField,\n outputText,\n recordField,\n stringField,\n} from \"../stream/json-lines\";\nimport { type TomlTable, toToml } from \"../utils/toml\";\nimport {\n anthropicUsage,\n argvPrompt,\n promptFile,\n requirePrivateHome,\n unsupportedOption,\n} from \"./shared\";\n\n/**\n * Grok Build (`grok`) — xAI's official coding-agent CLI, installed by the\n * `x.ai/cli/install.sh` script (no npm package).\n *\n * Verified against the docs and source only (the binary is distributed by\n * a curl installer, which was not run): the repo user guide\n * `crates/codegen/xai-grok-pager/docs/user-guide/{14-headless-mode,\n * 07-mcp-servers,05-configuration,22-permissions-and-safety}.md`, the clap\n * definitions in `xai-grok-pager/src/app/cli.rs` and the headless reducer\n * `headless/reducer/acp.rs`, at source version 1.0.45; latest stable 1.0.62\n * (2026-10-17). The capability probe checks every flag against the\n * installed binary's `--help` before the first run.\n *\n * - Headless: `grok -p <prompt>` or `--prompt-file <path>`; piped stdin is\n * not read. `--output-format streaming-json` prints `type`-tagged lines:\n * `text`, `thought`, `tool_call`, `tool_call_update`, `usage` (per model\n * response, `input_tokens` uncached) and a final `end` (session id, totals,\n * `total_cost_usd`); failures print `{\"type\":\"error\",\"message\"}`.\n * - Permissions: headless mode answers every approval request with\n * \"cancelled\" (auto-deny); bypass is `--always-approve`.\n * - MCP: no flag; `[mcp_servers.<name>]` in `$GROK_HOME/config.toml`.\n * - Auth: `XAI_API_KEY`. Update checks are disabled with\n * `GROK_DISABLE_AUTOUPDATER=1`.\n */\nexport const grokAdapter: CliAdapter = {\n name: \"grok\",\n title: \"Grok Build\",\n command: \"grok\",\n apiKeyEnv: [\"XAI_API_KEY\"],\n homeEnv: [\"GROK_HOME\"],\n transports: [\"argv\", \"file\"],\n effort: true,\n mcp: true,\n probe: { help: [[\"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"1.0.62\",\n verifiedBy: \"docs\",\n sources: [\n \"https://docs.x.ai/build/cli/headless-scripting\",\n \"https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-pager/docs/user-guide/14-headless-mode.md\",\n \"https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-pager/docs/user-guide/07-mcp-servers.md\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"--output-format\", \"streaming-json\"];\n const requires = [\"--output-format\", \"streaming-json\"];\n const files: CliLaunchFile[] = [];\n let tail: string[];\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.effort !== undefined) {\n // Grok accepts the framework scale verbatim (none … max, model-dependent).\n args.push(\"--reasoning-effort\", context.effort);\n requires.push(\"--reasoning-effort\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--resume\", context.resume);\n requires.push(\"--resume\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--always-approve\");\n requires.push(\"--always-approve\");\n }\n\n if (context.mcp !== undefined) {\n const home = requirePrivateHome(context, grokAdapter, \"MCP servers\");\n\n files.push({\n path: path.join(home, \"config.toml\"),\n content: toToml({ mcp_servers: grokMcp(context.mcp) }),\n });\n }\n\n if (context.transport === \"file\") {\n const prompt = promptFile(context);\n\n files.push(prompt);\n tail = [\"--prompt-file\", prompt.path];\n requires.push(\"--prompt-file\");\n } else {\n tail = [\"-p\", argvPrompt(context.prompt)];\n requires.push(\"-p\");\n }\n\n return {\n args,\n tail,\n env: {\n ...(context.home !== undefined ? { GROK_HOME: context.home } : {}),\n GROK_DISABLE_AUTOUPDATER: \"1\",\n },\n files,\n requires,\n };\n },\n parser: createGrokParser,\n};\n\nfunction grokMcp(servers: CliMcpServers): TomlTable {\n const table: TomlTable = {};\n\n for (const [name, server] of Object.entries(servers)) {\n if (server.type === \"sse\") {\n throw unsupportedOption(\n grokAdapter,\n `MCP server \"${name}\" uses SSE; Grok Build supports stdio and HTTP servers.`,\n );\n }\n\n table[name] =\n server.type === \"stdio\"\n ? { command: server.command, args: server.args ?? [], env: server.env }\n : { url: server.url, headers: server.headers };\n }\n\n return table;\n}\n\n/** Parser for `grok -p … --output-format streaming-json`. */\nexport function createGrokParser(): CliStreamParser {\n let started = false;\n let sessionRef: string | undefined;\n\n const parser = jsonLinesParser((record): CliParsedEvent[] => {\n const events: CliParsedEvent[] = [];\n\n if (!started) {\n started = true;\n events.push({ type: \"session.started\" });\n }\n\n switch (stringField(record, \"type\")) {\n case \"text\": {\n const text = stringField(record, \"data\") ?? \"\";\n\n if (text.length > 0) {\n events.push({ type: \"message\", text, delta: true, raw: record });\n }\n break;\n }\n case \"tool_call\":\n events.push({\n type: \"tool.call\",\n id: stringField(record, \"toolCallId\") ?? \"\",\n name: stringField(record, \"toolName\") ?? stringField(record, \"title\") ?? \"\",\n input: record.rawInput,\n raw: record,\n });\n break;\n case \"tool_call_update\": {\n const status = stringField(record, \"status\");\n\n if (status === \"completed\" || status === \"failed\") {\n events.push({\n type: \"tool.result\",\n id: stringField(record, \"toolCallId\") ?? \"\",\n output: outputText(record.rawOutput ?? record.content),\n isError: status === \"failed\",\n raw: record,\n });\n }\n break;\n }\n case \"usage\": {\n const usage = anthropicUsage(recordField(record, \"usage\"));\n\n if (usage !== undefined) {\n events.push({ type: \"usage\", usage, cumulative: false, raw: record });\n }\n break;\n }\n case \"end\": {\n sessionRef = stringField(record, \"sessionId\") ?? sessionRef;\n\n const usage = anthropicUsage(\n recordField(record, \"usage\"),\n numberField(record, \"total_cost_usd\"),\n );\n\n if (usage !== undefined) {\n events.push({ type: \"usage\", usage, cumulative: true, raw: record });\n }\n break;\n }\n case \"error\":\n events.push({\n type: \"error\",\n message: stringField(record, \"message\") ?? \"Grok Build reported an error\",\n fatal: true,\n raw: record,\n });\n break;\n }\n\n return events;\n });\n\n return { ...parser, sessionRef: () => sessionRef };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,cAA0B;CACrC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,aAAa;CACzB,SAAS,CAAC,WAAW;CACrB,YAAY,CAAC,QAAQ,MAAM;CAC3B,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CACpD,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS;GACP;GACA;GACA;EACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,MAAM,OAAO,CAAC,mBAAmB,gBAAgB;EACjD,MAAM,WAAW,CAAC,mBAAmB,gBAAgB;EACrD,MAAM,QAAyB,CAAC;EAChC,IAAI;EAEJ,IAAI,QAAQ,UAAU,QAAW;GAC/B,KAAK,KAAK,WAAW,QAAQ,KAAK;GAClC,SAAS,KAAK,SAAS;EACzB;EAEA,IAAI,QAAQ,WAAW,QAAW;GAEhC,KAAK,KAAK,sBAAsB,QAAQ,MAAM;GAC9C,SAAS,KAAK,oBAAoB;EACpC;EAEA,IAAI,QAAQ,WAAW,QAAW;GAChC,KAAK,KAAK,YAAY,QAAQ,MAAM;GACpC,SAAS,KAAK,UAAU;EAC1B;EAEA,IAAI,QAAQ,eAAe,UAAU;GACnC,KAAK,KAAK,kBAAkB;GAC5B,SAAS,KAAK,kBAAkB;EAClC;EAEA,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ts"],"sourcesContent":["import path from \"node:path\";\nimport type {\n CliAdapter,\n CliLaunchFile,\n CliMcpServers,\n CliParsedEvent,\n CliStreamParser,\n} from \"../contracts\";\nimport {\n jsonLinesParser,\n numberField,\n outputText,\n recordField,\n stringField,\n} from \"../stream/json-lines\";\nimport { type TomlTable, toToml } from \"../utils/toml\";\nimport {\n anthropicUsage,\n argvPrompt,\n promptFile,\n requirePrivateHome,\n unsupportedOption,\n} from \"./shared\";\n\n/**\n * Grok Build (`grok`) — xAI's official coding-agent CLI, installed by the\n * `x.ai/cli/install.sh` script (no npm package).\n *\n * Verified against the docs and source only (the binary is distributed by\n * a curl installer, which was not run): the repo user guide\n * `crates/codegen/xai-grok-pager/docs/user-guide/{14-headless-mode,\n * 07-mcp-servers,05-configuration,22-permissions-and-safety}.md`, the clap\n * definitions in `xai-grok-pager/src/app/cli.rs` and the headless reducer\n * `headless/reducer/acp.rs`, at source version 1.0.45; latest stable 1.0.62\n * (2026-10-17). The capability probe checks every flag against the\n * installed binary's `--help` before the first run.\n *\n * - Headless: `grok -p <prompt>` or `--prompt-file <path>`; piped stdin is\n * not read. `--output-format streaming-json` prints `type`-tagged lines:\n * `text`, `thought`, `tool_call`, `tool_call_update`, `usage` (per model\n * response, `input_tokens` uncached) and a final `end` (session id, totals,\n * `total_cost_usd`); failures print `{\"type\":\"error\",\"message\"}`.\n * - Permissions: headless mode answers every approval request with\n * \"cancelled\" (auto-deny); bypass is `--always-approve`.\n * - MCP: no flag; `[mcp_servers.<name>]` in `$GROK_HOME/config.toml`.\n * - Auth: `XAI_API_KEY`. Update checks are disabled with\n * `GROK_DISABLE_AUTOUPDATER=1`.\n */\nexport const grokAdapter: CliAdapter = {\n name: \"grok\",\n title: \"Grok Build\",\n command: \"grok\",\n apiKeyEnv: [\"XAI_API_KEY\"],\n passEnv: [],\n homeEnv: [\"GROK_HOME\"],\n transports: [\"argv\", \"file\"],\n effort: true,\n mcp: true,\n probe: { help: [[\"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"1.0.62\",\n verifiedBy: \"docs\",\n sources: [\n \"https://docs.x.ai/build/cli/headless-scripting\",\n \"https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-pager/docs/user-guide/14-headless-mode.md\",\n \"https://github.com/xai-org/grok-build/blob/main/crates/codegen/xai-grok-pager/docs/user-guide/07-mcp-servers.md\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"--output-format\", \"streaming-json\"];\n const requires = [\"--output-format\", \"streaming-json\"];\n const files: CliLaunchFile[] = [];\n let tail: string[];\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.effort !== undefined) {\n // Grok accepts the framework scale verbatim (none … max, model-dependent).\n args.push(\"--reasoning-effort\", context.effort);\n requires.push(\"--reasoning-effort\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--resume\", context.resume);\n requires.push(\"--resume\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--always-approve\");\n requires.push(\"--always-approve\");\n }\n\n if (context.mcp !== undefined) {\n const home = requirePrivateHome(context, grokAdapter, \"MCP servers\");\n\n files.push({\n path: path.join(home, \"config.toml\"),\n content: toToml({ mcp_servers: grokMcp(context.mcp) }),\n });\n }\n\n if (context.transport === \"file\") {\n const prompt = promptFile(context);\n\n files.push(prompt);\n tail = [\"--prompt-file\", prompt.path];\n requires.push(\"--prompt-file\");\n } else {\n tail = [\"-p\", argvPrompt(context.prompt)];\n requires.push(\"-p\");\n }\n\n return {\n args,\n tail,\n env: {\n ...(context.home !== undefined ? { GROK_HOME: context.home } : {}),\n GROK_DISABLE_AUTOUPDATER: \"1\",\n },\n files,\n requires,\n };\n },\n parser: createGrokParser,\n};\n\nfunction grokMcp(servers: CliMcpServers): TomlTable {\n const table: TomlTable = {};\n\n for (const [name, server] of Object.entries(servers)) {\n if (server.type === \"sse\") {\n throw unsupportedOption(\n grokAdapter,\n `MCP server \"${name}\" uses SSE; Grok Build supports stdio and HTTP servers.`,\n );\n }\n\n table[name] =\n server.type === \"stdio\"\n ? { command: server.command, args: server.args ?? [], env: server.env }\n : { url: server.url, headers: server.headers };\n }\n\n return table;\n}\n\n/** Parser for `grok -p … --output-format streaming-json`. */\nexport function createGrokParser(): CliStreamParser {\n let started = false;\n let sessionRef: string | undefined;\n\n const parser = jsonLinesParser((record): CliParsedEvent[] => {\n const events: CliParsedEvent[] = [];\n\n if (!started) {\n started = true;\n events.push({ type: \"session.started\" });\n }\n\n switch (stringField(record, \"type\")) {\n case \"text\": {\n const text = stringField(record, \"data\") ?? \"\";\n\n if (text.length > 0) {\n events.push({ type: \"message\", text, delta: true, raw: record });\n }\n break;\n }\n case \"tool_call\":\n events.push({\n type: \"tool.call\",\n id: stringField(record, \"toolCallId\") ?? \"\",\n name: stringField(record, \"toolName\") ?? stringField(record, \"title\") ?? \"\",\n input: record.rawInput,\n raw: record,\n });\n break;\n case \"tool_call_update\": {\n const status = stringField(record, \"status\");\n\n if (status === \"completed\" || status === \"failed\") {\n events.push({\n type: \"tool.result\",\n id: stringField(record, \"toolCallId\") ?? \"\",\n output: outputText(record.rawOutput ?? record.content),\n isError: status === \"failed\",\n raw: record,\n });\n }\n break;\n }\n case \"usage\": {\n const usage = anthropicUsage(recordField(record, \"usage\"));\n\n if (usage !== undefined) {\n events.push({ type: \"usage\", usage, cumulative: false, raw: record });\n }\n break;\n }\n case \"end\": {\n sessionRef = stringField(record, \"sessionId\") ?? sessionRef;\n\n const usage = anthropicUsage(\n recordField(record, \"usage\"),\n numberField(record, \"total_cost_usd\"),\n );\n\n if (usage !== undefined) {\n events.push({ type: \"usage\", usage, cumulative: true, raw: record });\n }\n break;\n }\n case \"error\":\n events.push({\n type: \"error\",\n message: stringField(record, \"message\") ?? \"Grok Build reported an error\",\n fatal: true,\n raw: record,\n });\n break;\n }\n\n return events;\n });\n\n return { ...parser, sessionRef: () => sessionRef };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;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KACvB,MAAM,SAAS,YAAY,QAAQ,QAAQ;KAE3C,IAAI,WAAW,eAAe,WAAW,UACvC,OAAO,KAAK;MACV,MAAM;MACN,IAAI,YAAY,QAAQ,YAAY,KAAK;MACzC,QAAQ,WAAW,OAAO,aAAa,OAAO,OAAO;MACrD,SAAS,WAAW;MACpB,KAAK;KACP,CAAC;KAEH;IACF;IACA,KAAK,SAAS;KACZ,MAAM,QAAQ,eAAe,YAAY,QAAQ,OAAO,CAAC;KAEzD,IAAI,UAAU,QACZ,OAAO,KAAK;MAAE,MAAM;MAAS;MAAO,YAAY;MAAO,KAAK;KAAO,CAAC;KAEtE;IACF;IACA,KAAK,OAAO;KACV,aAAa,YAAY,QAAQ,WAAW,KAAK;KAEjD,MAAM,QAAQ,eACZ,YAAY,QAAQ,OAAO,GAC3B,YAAY,QAAQ,gBAAgB,CACtC;KAEA,IAAI,UAAU,QACZ,OAAO,KAAK;MAAE,MAAM;MAAS;MAAO,YAAY;MAAM,KAAK;KAAO,CAAC;KAErE;IACF;IACA,KAAK,SACH,OAAO,KAAK;KACV,MAAM;KACN,SAAS,YAAY,QAAQ,SAAS,KAAK;KAC3C,OAAO;KACP,KAAK;IACP,CAAC;GAEL;GAEA,OAAO;EACT,CAEiB;EAAG,kBAAkB;CAAW;AACnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kimi.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/kimi.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA4Ca,aAAa;;
|
|
1
|
+
{"version":3,"file":"kimi.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/kimi.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA4Ca,aAAa;;wBAmFV,oBAAoB"}
|
package/esm/adapters/kimi.mjs
CHANGED
|
@@ -34,6 +34,11 @@ const kimiAdapter = {
|
|
|
34
34
|
title: "Kimi Code",
|
|
35
35
|
command: "kimi",
|
|
36
36
|
apiKeyEnv: ["KIMI_MODEL_API_KEY"],
|
|
37
|
+
passEnv: [
|
|
38
|
+
"KIMI_MODEL_NAME",
|
|
39
|
+
"KIMI_MODEL_PROVIDER_TYPE",
|
|
40
|
+
"KIMI_MODEL_BASE_URL"
|
|
41
|
+
],
|
|
37
42
|
homeEnv: ["KIMI_CODE_HOME"],
|
|
38
43
|
transports: ["argv"],
|
|
39
44
|
effort: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kimi.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/kimi.ts"],"sourcesContent":["import path from \"node:path\";\nimport type {\n CliAdapter,\n CliLaunchFile,\n CliMcpServers,\n CliParsedEvent,\n CliStreamParser,\n} from \"../contracts\";\nimport { asArray, asRecord, jsonLinesParser, outputText, stringField } from \"../stream/json-lines\";\nimport {\n argvPrompt,\n jsonFile,\n mcpServersJson,\n parseArguments,\n requirePrivateHome,\n unsupportedOption,\n} from \"./shared\";\n\n/**\n * Kimi Code CLI (`kimi`, npm `@moonshot-ai/kimi-code`) — Moonshot AI's\n * coding agent, the successor of the archived Python `kimi-cli`.\n *\n * Verified against the real `kimi --help` of 2.2.0 and the docs/source at\n * that tag (`docs/en/reference/kimi-command.md`, `apps/kimi-code/src/cli/\n * {options.ts,prompt-render.ts,v2/run-v2-print.ts}`), 2026-10-17.\n *\n * - Headless: `kimi -p <prompt> --output-format stream-json`; the prompt is\n * an argv value only (print mode never reads stdin).\n * - Stream: OpenAI-chat-shaped messages, one per line, never deltas:\n * `{\"role\":\"assistant\",\"content\",\"tool_calls\"}`, `{\"role\":\"tool\",\n * \"tool_call_id\",\"content\"}`, and `{\"role\":\"meta\",\"type\":…}` records. The\n * session id appears only in the final `session.resume_hint` record.\n * No token usage is printed.\n * - Permissions: print mode always runs in \"Never Ask\" mode (every tool call\n * runs; only static deny rules apply) and rejects `--yolo`/`--plan`, so\n * there is no standard mode to choose. The adapter refuses\n * `permission: \"standard\"` instead of pretending to enforce it; pass\n * `\"bypass\"` to accept the CLI's behaviour.\n * - MCP: no flag; `$KIMI_CODE_HOME/mcp.json` (`mcpServers`), so per-run MCP\n * needs a private home.\n * - Auth: shell `KIMI_API_KEY`/`MOONSHOT_API_KEY` are not read. For an API\n * key set `KIMI_MODEL_NAME` (and optionally `KIMI_MODEL_PROVIDER_TYPE`,\n * `KIMI_MODEL_BASE_URL`) in `env`; `apiKey` becomes `KIMI_MODEL_API_KEY`.\n */\nexport const kimiAdapter: CliAdapter = {\n name: \"kimi\",\n title: \"Kimi Code\",\n command: \"kimi\",\n apiKeyEnv: [\"KIMI_MODEL_API_KEY\"],\n homeEnv: [\"KIMI_CODE_HOME\"],\n transports: [\"argv\"],\n effort: false,\n mcp: true,\n probe: { help: [[\"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"2.2.0\",\n verifiedBy: \"help\",\n sources: [\n \"https://moonshotai.github.io/kimi-code/\",\n \"https://github.com/MoonshotAI/kimi-code/blob/%40moonshot-ai/kimi-code%402.2.0/docs/en/reference/kimi-command.md\",\n \"https://github.com/MoonshotAI/kimi-code/blob/%40moonshot-ai/kimi-code%402.2.0/docs/en/customization/mcp.md\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n if (context.permission !== \"bypass\") {\n throw unsupportedOption(\n kimiAdapter,\n 'print mode runs every tool call without asking and has no standard approval mode; pass `permission: \"bypass\"` to run it.',\n );\n }\n\n const args = [\"--output-format\", \"stream-json\"];\n const requires = [\"-p\", \"--output-format\", \"stream-json\"];\n const files: CliLaunchFile[] = [];\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--session\", context.resume);\n requires.push(\"--session\");\n }\n\n if (context.mcp !== undefined) {\n const home = requirePrivateHome(context, kimiAdapter, \"MCP servers\");\n\n files.push({\n path: path.join(home, \"mcp.json\"),\n content: jsonFile({ mcpServers: kimiMcp(context.mcp) }),\n });\n }\n\n return {\n args,\n tail: [\"-p\", argvPrompt(context.prompt)],\n env: {\n ...(context.home !== undefined ? { KIMI_CODE_HOME: context.home } : {}),\n KIMI_CODE_NO_AUTO_UPDATE: \"1\",\n KIMI_DISABLE_TELEMETRY: \"1\",\n },\n files,\n requires,\n };\n },\n parser: createKimiParser,\n};\n\n/** Kimi's `mcpServers`: SSE servers are marked with `transport: \"sse\"`. */\nfunction kimiMcp(servers: CliMcpServers): Record<string, unknown> {\n const rendered = mcpServersJson(servers);\n\n for (const [name, server] of Object.entries(servers)) {\n const entry = rendered[name];\n\n if (server.type === \"sse\" && entry !== undefined) {\n entry.transport = \"sse\";\n }\n }\n\n return rendered;\n}\n\n/** Parser for `kimi -p … --output-format stream-json`. */\nexport function createKimiParser(): CliStreamParser {\n let sessionRef: string | undefined;\n\n const parser = jsonLinesParser((record): CliParsedEvent[] => {\n const role = stringField(record, \"role\");\n\n if (role === \"meta\") {\n const type = stringField(record, \"type\");\n\n if (type === \"system.version\") {\n return [{ type: \"session.started\", raw: record }];\n }\n\n if (type === \"session.resume_hint\") {\n sessionRef = stringField(record, \"session_id\");\n\n return [];\n }\n\n if (type === \"turn.step.retrying\") {\n return [\n {\n type: \"error\",\n message: `retrying after ${stringField(record, \"error_name\") ?? \"error\"}: ${stringField(record, \"error_message\") ?? \"\"}`,\n raw: record,\n },\n ];\n }\n\n return [];\n }\n\n if (role === \"assistant\") {\n const events: CliParsedEvent[] = [];\n const content = stringField(record, \"content\");\n\n if (content !== undefined && content.length > 0) {\n events.push({ type: \"message\", text: content, delta: false, raw: record });\n }\n\n for (const item of asArray(record.tool_calls)) {\n const call = asRecord(item);\n const fn = asRecord(call?.function);\n\n events.push({\n type: \"tool.call\",\n id: stringField(call, \"id\") ?? \"\",\n name: stringField(fn, \"name\") ?? \"\",\n input: parseArguments(fn?.arguments),\n raw: item,\n });\n }\n\n return events;\n }\n\n if (role === \"tool\") {\n return [\n {\n type: \"tool.result\",\n id: stringField(record, \"tool_call_id\") ?? \"\",\n output: outputText(record.content),\n isError: false,\n raw: record,\n },\n ];\n }\n\n return [];\n });\n\n return { ...parser, sessionRef: () => sessionRef };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,cAA0B;CACrC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,oBAAoB;CAChC,SAAS,CAAC,gBAAgB;CAC1B,YAAY,CAAC,MAAM;CACnB,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CACpD,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS;GACP;GACA;GACA;EACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,IAAI,QAAQ,eAAe,UACzB,MAAM,kBACJ,aACA,4HACF;EAGF,MAAM,OAAO,CAAC,mBAAmB,aAAa;EAC9C,MAAM,WAAW;GAAC;GAAM;GAAmB;EAAa;EACxD,MAAM,QAAyB,CAAC;EAEhC,IAAI,QAAQ,UAAU,QAAW;GAC/B,KAAK,KAAK,WAAW,QAAQ,KAAK;GAClC,SAAS,KAAK,SAAS;EACzB;EAEA,IAAI,QAAQ,WAAW,QAAW;GAChC,KAAK,KAAK,aAAa,QAAQ,MAAM;GACrC,SAAS,KAAK,WAAW;EAC3B;EAEA,IAAI,QAAQ,QAAQ,QAAW;GAC7B,MAAM,OAAO,mBAAmB,SAAS,aAAa,aAAa;GAEnE,MAAM,KAAK;IACT,MAAM,KAAK,KAAK,MAAM,UAAU;IAChC,SAAS,SAAS,EAAE,YAAY,QAAQ,QAAQ,GAAG,EAAE,CAAC;GACxD,CAAC;EACH;EAEA,OAAO;GACL;GACA,MAAM,CAAC,MAAM,WAAW,QAAQ,MAAM,CAAC;GACvC,KAAK;IACH,GAAI,QAAQ,SAAS,SAAY,EAAE,gBAAgB,QAAQ,KAAK,IAAI,CAAC;IACrE,0BAA0B;IAC1B,w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AAI,SAAS;MACnC,KAAK;KACP,CAAC;IACH;IAEA,OAAO;GACT;GAEA,IAAI,SAAS,QACX,OAAO,CACL;IACE,MAAM;IACN,IAAI,YAAY,QAAQ,cAAc,KAAK;IAC3C,QAAQ,WAAW,OAAO,OAAO;IACjC,SAAS;IACT,KAAK;GACP,CACF;GAGF,OAAO,CAAC;EACV,CAEiB;EAAG,kBAAkB;CAAW;AACnD"}
|
|
1
|
+
{"version":3,"file":"kimi.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/kimi.ts"],"sourcesContent":["import path from \"node:path\";\nimport type {\n CliAdapter,\n CliLaunchFile,\n CliMcpServers,\n CliParsedEvent,\n CliStreamParser,\n} from \"../contracts\";\nimport { asArray, asRecord, jsonLinesParser, outputText, stringField } from \"../stream/json-lines\";\nimport {\n argvPrompt,\n jsonFile,\n mcpServersJson,\n parseArguments,\n requirePrivateHome,\n unsupportedOption,\n} from \"./shared\";\n\n/**\n * Kimi Code CLI (`kimi`, npm `@moonshot-ai/kimi-code`) — Moonshot AI's\n * coding agent, the successor of the archived Python `kimi-cli`.\n *\n * Verified against the real `kimi --help` of 2.2.0 and the docs/source at\n * that tag (`docs/en/reference/kimi-command.md`, `apps/kimi-code/src/cli/\n * {options.ts,prompt-render.ts,v2/run-v2-print.ts}`), 2026-10-17.\n *\n * - Headless: `kimi -p <prompt> --output-format stream-json`; the prompt is\n * an argv value only (print mode never reads stdin).\n * - Stream: OpenAI-chat-shaped messages, one per line, never deltas:\n * `{\"role\":\"assistant\",\"content\",\"tool_calls\"}`, `{\"role\":\"tool\",\n * \"tool_call_id\",\"content\"}`, and `{\"role\":\"meta\",\"type\":…}` records. The\n * session id appears only in the final `session.resume_hint` record.\n * No token usage is printed.\n * - Permissions: print mode always runs in \"Never Ask\" mode (every tool call\n * runs; only static deny rules apply) and rejects `--yolo`/`--plan`, so\n * there is no standard mode to choose. The adapter refuses\n * `permission: \"standard\"` instead of pretending to enforce it; pass\n * `\"bypass\"` to accept the CLI's behaviour.\n * - MCP: no flag; `$KIMI_CODE_HOME/mcp.json` (`mcpServers`), so per-run MCP\n * needs a private home.\n * - Auth: shell `KIMI_API_KEY`/`MOONSHOT_API_KEY` are not read. For an API\n * key set `KIMI_MODEL_NAME` (and optionally `KIMI_MODEL_PROVIDER_TYPE`,\n * `KIMI_MODEL_BASE_URL`) in `env`; `apiKey` becomes `KIMI_MODEL_API_KEY`.\n */\nexport const kimiAdapter: CliAdapter = {\n name: \"kimi\",\n title: \"Kimi Code\",\n command: \"kimi\",\n apiKeyEnv: [\"KIMI_MODEL_API_KEY\"],\n passEnv: [\"KIMI_MODEL_NAME\", \"KIMI_MODEL_PROVIDER_TYPE\", \"KIMI_MODEL_BASE_URL\"],\n homeEnv: [\"KIMI_CODE_HOME\"],\n transports: [\"argv\"],\n effort: false,\n mcp: true,\n probe: { help: [[\"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"2.2.0\",\n verifiedBy: \"help\",\n sources: [\n \"https://moonshotai.github.io/kimi-code/\",\n \"https://github.com/MoonshotAI/kimi-code/blob/%40moonshot-ai/kimi-code%402.2.0/docs/en/reference/kimi-command.md\",\n \"https://github.com/MoonshotAI/kimi-code/blob/%40moonshot-ai/kimi-code%402.2.0/docs/en/customization/mcp.md\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n if (context.permission !== \"bypass\") {\n throw unsupportedOption(\n kimiAdapter,\n 'print mode runs every tool call without asking and has no standard approval mode; pass `permission: \"bypass\"` to run it.',\n );\n }\n\n const args = [\"--output-format\", \"stream-json\"];\n const requires = [\"-p\", \"--output-format\", \"stream-json\"];\n const files: CliLaunchFile[] = [];\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--session\", context.resume);\n requires.push(\"--session\");\n }\n\n if (context.mcp !== undefined) {\n const home = requirePrivateHome(context, kimiAdapter, \"MCP servers\");\n\n files.push({\n path: path.join(home, \"mcp.json\"),\n content: jsonFile({ mcpServers: kimiMcp(context.mcp) }),\n });\n }\n\n return {\n args,\n tail: [\"-p\", argvPrompt(context.prompt)],\n env: {\n ...(context.home !== undefined ? { KIMI_CODE_HOME: context.home } : {}),\n KIMI_CODE_NO_AUTO_UPDATE: \"1\",\n KIMI_DISABLE_TELEMETRY: \"1\",\n },\n files,\n requires,\n };\n },\n parser: createKimiParser,\n};\n\n/** Kimi's `mcpServers`: SSE servers are marked with `transport: \"sse\"`. */\nfunction kimiMcp(servers: CliMcpServers): Record<string, unknown> {\n const rendered = mcpServersJson(servers);\n\n for (const [name, server] of Object.entries(servers)) {\n const entry = rendered[name];\n\n if (server.type === \"sse\" && entry !== undefined) {\n entry.transport = \"sse\";\n }\n }\n\n return rendered;\n}\n\n/** Parser for `kimi -p … --output-format stream-json`. */\nexport function createKimiParser(): CliStreamParser {\n let sessionRef: string | undefined;\n\n const parser = jsonLinesParser((record): CliParsedEvent[] => {\n const role = stringField(record, \"role\");\n\n if (role === \"meta\") {\n const type = stringField(record, \"type\");\n\n if (type === \"system.version\") {\n return [{ type: \"session.started\", raw: record }];\n }\n\n if (type === \"session.resume_hint\") {\n sessionRef = stringField(record, \"session_id\");\n\n return [];\n }\n\n if (type === \"turn.step.retrying\") {\n return [\n {\n type: \"error\",\n message: `retrying after ${stringField(record, \"error_name\") ?? \"error\"}: ${stringField(record, \"error_message\") ?? \"\"}`,\n raw: record,\n },\n ];\n }\n\n return [];\n }\n\n if (role === \"assistant\") {\n const events: CliParsedEvent[] = [];\n const content = stringField(record, \"content\");\n\n if (content !== undefined && content.length > 0) {\n events.push({ type: \"message\", text: content, delta: false, raw: record });\n }\n\n for (const item of asArray(record.tool_calls)) {\n const call = asRecord(item);\n const fn = asRecord(call?.function);\n\n events.push({\n type: \"tool.call\",\n id: stringField(call, \"id\") ?? \"\",\n name: stringField(fn, \"name\") ?? \"\",\n input: parseArguments(fn?.arguments),\n raw: item,\n });\n }\n\n return events;\n }\n\n if (role === \"tool\") {\n return [\n {\n type: \"tool.result\",\n id: stringField(record, \"tool_call_id\") ?? \"\",\n output: outputText(record.content),\n isError: false,\n raw: record,\n },\n ];\n }\n\n return [];\n });\n\n return { ...parser, sessionRef: () => sessionRef };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAa,cAA0B;CACrC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,oBAAoB;CAChC,SAAS;EAAC;EAAmB;EAA4B;CAAqB;CAC9E,SAAS,CAAC,gBAAgB;CAC1B,YAAY,CAAC,MAAM;CACnB,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CACpD,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS;GACP;GACA;GACA;EACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,IAAI,QAAQ,eAAe,UACzB,MAAM,kBACJ,aACA,4HACF;EAGF,MAAM,OAAO,CAAC,mBAAmB,aAAa;EAC9C,MAAM,WAAW;GAAC;GAAM;GAAmB;EAAa;EACxD,MAAM,QAAyB,CAAC;EAEhC,IAAI,QAAQ,UAAU,QAAW;GAC/B,KAAK,KAAK,WAAW,QAAQ,KAAK;GAClC,SAAS,KAAK,SAAS;EACzB;EAEA,IAAI,QAAQ,WAAW,QAAW;GAChC,KAAK,KAAK,aAAa,QAAQ,MAAM;GACrC,SAAS,KAAK,WAAW;EAC3B;EAEA,IAAI,QAAQ,QAAQ,QAAW;GAC7B,MAAM,OAAO,mBAAmB,SAAS,aAAa,aAAa;GAEnE,MAAM,KAAK;IACT,MAAM,KAAK,KAAK,MAAM,UAAU;IAChC,SAAS,SAAS,EAAE,YAAY,QAAQ,QAAQ,GAAG,EAAE,CAAC;GACxD,CAAC;EACH;EAEA,OAAO;GACL;GACA,MAAM,CAAC,MAAM,WAAW,QAAQ,MAAM,CAAC;GACvC,KAAK;IACH,GAAI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I,YAAY,MAAM,IAAI,KAAK;MAC/B,MAAM,YAAY,IAAI,MAAM,KAAK;MACjC,OAAO,eAAe,IAAI,SAAS;MACnC,KAAK;KACP,CAAC;IACH;IAEA,OAAO;GACT;GAEA,IAAI,SAAS,QACX,OAAO,CACL;IACE,MAAM;IACN,IAAI,YAAY,QAAQ,cAAc,KAAK;IAC3C,QAAQ,WAAW,OAAO,OAAO;IACjC,SAAS;IACT,KAAK;GACP,CACF;GAGF,OAAO,CAAC;EACV,CAEiB;EAAG,kBAAkB;CAAW;AACnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mistral-vibe.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/mistral-vibe.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkDa,oBAAoB;;
|
|
1
|
+
{"version":3,"file":"mistral-vibe.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/mistral-vibe.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;qBAkDa,oBAAoB;;wBAyJjB,iBAAiB,UAAU,mBAAmB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mistral-vibe.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/mistral-vibe.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n CliAdapter,\n CliLaunchContext,\n CliLaunchFile,\n CliMcpServers,\n CliParsedEvent,\n CliStreamParser,\n} from \"../contracts\";\nimport {\n asArray,\n asRecord,\n jsonLinesParser,\n numberField,\n outputText,\n parseJsonLine,\n recordField,\n stringField,\n} from \"../stream/json-lines\";\nimport { type TomlTable, toToml } from \"../utils/toml\";\nimport { argvPrompt, promptFile, requirePrivateHome, usageOf } from \"./shared\";\n\n/** Folder (inside the run directory) Vibe writes `export.json` to. */\nconst EXPORT_DIR = \"vibe-output\";\n\n/**\n * Mistral Vibe (`vibe`, PyPI `mistral-vibe`).\n *\n * Verified against the official repo at tag v2.26.1 only (README,\n * `vibe/cli/entrypoint.py`, `vibe/cli/programmatic.py`,\n * `vibe/app_server/run_export.py`, `vibe/core/config/*`); Vibe needs Python\n * 3.12, so no real `--help` was run, 2026-10-17. The capability probe checks\n * every flag against the installed `--help`.\n *\n * - Headless: `vibe -p <prompt> --output streaming` (or `--prompt-file`;\n * `-p` with no value reads stdin). The stream is NDJSON of completed\n * history entries (camelCase): `message` (`role`, `content[].text`), and\n * `effect` — a tool call and its result in one line (`detail.toolName`,\n * `detail.input`, `state.status`, `state.outputText`/`state.error`).\n * There is no usage, cost or final record in the stream, so the adapter\n * adds `--output-dir` and reads usage, cost, session id and outcome from\n * `export.json` when the stream ends.\n * - Model: no flag; `VIBE_ACTIVE_MODEL=<alias>` (set from `model`). Effort\n * is a per-model config field, so `effort` is refused.\n * - Permissions: headless auto-denies every approval (the default agent\n * only auto-approves file edits); bypass is `--auto-approve`.\n * - MCP: `[[mcp_servers]]` in `$VIBE_HOME/config.toml` (private home).\n * - Auth: `MISTRAL_API_KEY`; home `VIBE_HOME`.\n */\nexport const mistralVibeAdapter: CliAdapter = {\n name: \"mistral-vibe\",\n title: \"Mistral Vibe\",\n command: \"vibe\",\n apiKeyEnv: [\"MISTRAL_API_KEY\"],\n homeEnv: [\"VIBE_HOME\"],\n transports: [\"argv\", \"file\", \"stdin\"],\n effort: false,\n mcp: true,\n probe: { help: [[\"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"2.26.1\",\n verifiedBy: \"docs\",\n sources: [\n \"https://github.com/mistralai/mistral-vibe/blob/v2.26.1/README.md\",\n \"https://github.com/mistralai/mistral-vibe/blob/v2.26.1/vibe/cli/entrypoint.py\",\n \"https://github.com/mistralai/mistral-vibe/blob/v2.26.1/vibe/cli/programmatic.py\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"--output\", \"streaming\", \"--output-dir\", path.join(context.runDir, EXPORT_DIR)];\n const requires = [\"--output\", \"streaming\", \"--output-dir\"];\n const files: CliLaunchFile[] = [];\n const env: Record<string, string> = {};\n\n if (context.model !== undefined) {\n env.VIBE_ACTIVE_MODEL = context.model;\n }\n\n if (context.resume !== undefined) {\n args.push(\"--resume\", context.resume);\n requires.push(\"--resume\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--auto-approve\");\n requires.push(\"--auto-approve\");\n }\n\n if (context.mcp !== undefined) {\n const home = requirePrivateHome(context, mistralVibeAdapter, \"MCP servers\");\n\n files.push({\n path: path.join(home, \"config.toml\"),\n content: toToml({ mcp_servers: vibeMcp(context.mcp) }),\n });\n }\n\n if (context.home !== undefined) {\n env.VIBE_HOME = context.home;\n }\n\n if (context.transport === \"file\") {\n const prompt = promptFile(context);\n\n files.push(prompt);\n requires.push(\"--prompt-file\");\n\n return { args, tail: [\"--prompt-file\", prompt.path], env, files, requires };\n }\n\n requires.push(\"-p\");\n\n if (context.transport === \"stdin\") {\n return { args, tail: [\"-p\"], stdin: context.prompt, env, files, requires };\n }\n\n return { args, tail: [\"-p\", argvPrompt(context.prompt)], env, files, requires };\n },\n parser: createVibeParser,\n};\n\nfunction vibeMcp(servers: CliMcpServers): TomlTable[] {\n return Object.entries(servers).map(([name, server]): TomlTable =>\n server.type === \"stdio\"\n ? {\n name,\n transport: \"stdio\",\n command: server.command,\n args: server.args ?? [],\n env: server.env,\n }\n : {\n name,\n transport: server.type === \"http\" ? \"streamable-http\" : \"http\",\n url: server.url,\n auth:\n server.headers !== undefined ? { type: \"static\", headers: server.headers } : undefined,\n },\n );\n}\n\n/** Read Vibe's `export.json`: usage, cost, session id and outcome of the run. */\nfunction exportEvents(context: CliLaunchContext | undefined): {\n events: CliParsedEvent[];\n sessionRef?: string;\n} {\n if (context === undefined) {\n return { events: [] };\n }\n\n let report: Record<string, unknown> | undefined;\n\n try {\n report = parseJsonLine(\n readFileSync(path.join(context.runDir, EXPORT_DIR, \"export.json\"), \"utf8\"),\n );\n } catch {\n return { events: [] };\n }\n\n if (report === undefined) {\n return { events: [] };\n }\n\n const events: CliParsedEvent[] = [];\n const usage = recordField(report, \"usage\");\n\n if (usage !== undefined) {\n const cached = numberField(usage, \"cached_input_tokens\");\n\n events.push({\n type: \"usage\",\n cumulative: true,\n usage: usageOf({\n input: numberField(usage, \"input_tokens\"),\n output: numberField(usage, \"output_tokens\"),\n total: numberField(usage, \"total_tokens\"),\n cachedTokens: cached !== undefined && cached > 0 ? cached : undefined,\n costUSD: numberField(report, \"cost_usd\"),\n }),\n raw: report,\n });\n }\n\n const outcome = stringField(report, \"outcome\");\n\n if (outcome !== undefined && outcome !== \"finished\") {\n events.push({\n type: \"error\",\n message:\n stringField(recordField(report, \"error\"), \"message\") ?? `Mistral Vibe stopped: ${outcome}`,\n fatal: true,\n raw: report,\n });\n }\n\n return { events, sessionRef: stringField(report, \"session_id\") };\n}\n\n/** Parser for `vibe -p … --output streaming` (plus the run's `export.json`). */\nexport function createVibeParser(context?: CliLaunchContext): CliStreamParser {\n let started = false;\n let sessionRef: string | undefined;\n\n const parser = jsonLinesParser(\n (record): CliParsedEvent[] => {\n const events: CliParsedEvent[] = [];\n const session = stringField(record, \"sessionId\");\n\n if (session !== undefined) {\n sessionRef = session;\n }\n\n if (!started) {\n started = true;\n events.push({ type: \"session.started\", sessionRef: session, raw: record });\n }\n\n switch (stringField(record, \"type\")) {\n case \"message\": {\n if (stringField(record, \"role\") !== \"assistant\") {\n break;\n }\n\n const text = asArray(record.content)\n .map((block) => stringField(asRecord(block), \"text\") ?? \"\")\n .join(\"\");\n\n if (text.length > 0) {\n events.push({ type: \"message\", text, delta: false, raw: record });\n }\n break;\n }\n case \"effect\": {\n const detail = recordField(record, \"detail\");\n const state = recordField(record, \"state\");\n const status = stringField(state, \"status\");\n const id = stringField(record, \"id\") ?? \"\";\n\n events.push({\n type: \"tool.call\",\n id,\n name: stringField(detail, \"toolName\") ?? stringField(record, \"title\") ?? \"\",\n input: detail?.input,\n raw: record,\n });\n\n if (\n status === \"completed\" ||\n status === \"failed\" ||\n status === \"cancelled\" ||\n status === \"skipped\"\n ) {\n const error = stringField(recordField(state, \"error\"), \"message\");\n\n events.push({\n type: \"tool.result\",\n id,\n output: error ?? stringField(state, \"outputText\") ?? outputText(state?.output),\n isError: status !== \"completed\",\n raw: record,\n });\n }\n break;\n }\n case \"notice\":\n if (stringField(record, \"level\") === \"error\") {\n events.push({\n type: \"error\",\n message: stringField(record, \"message\") ?? \"error\",\n raw: record,\n });\n }\n break;\n }\n\n return events;\n },\n () => {\n const exported = exportEvents(context);\n\n sessionRef = exported.sessionRef ?? sessionRef;\n\n return exported.events;\n },\n );\n\n return { ...parser, sessionRef: () => sessionRef };\n}\n"],"mappings":";;;;;;;;AAwBA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;AA0BnB,MAAa,qBAAiC;CAC5C,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,iBAAiB;CAC7B,SAAS,CAAC,WAAW;CACrB,YAAY;EAAC;EAAQ;EAAQ;CAAO;CACpC,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CACpD,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS;GACP;GACA;GACA;EACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,MAAM,OAAO;GAAC;GAAY;GAAa;GAAgB,KAAK,KAAK,QAAQ,QAAQ,UAAU;EAAC;EAC5F,MAAM,WAAW;GAAC;GAAY;GAAa;EAAc;EACzD,MAAM,QAAyB,CAAC;EAChC,MAAM,MAA8B,CAAC;EAErC,IAAI,QAAQ,UAAU,QACpB,IAAI,oBAAoB,QAAQ;EAGlC,IAAI,QAAQ,WAAW,QAAW;GAChC,KAAK,KAAK,YAAY,QAAQ,MAAM;GACpC,SAAS,KAAK,UAAU;EAC1B;EAEA,IAAI,QAAQ,eAAe,UAAU;GACnC,KAAK,KAAK,gBAAgB;GAC1B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AQ,OAAO,OAAO,CAAC,CACjC,KAAK,UAAU,YAAY,SAAS,KAAK,GAAG,MAAM,KAAK,EAAE,CAAC,CAC1D,KAAK,EAAE;KAEV,IAAI,KAAK,SAAS,GAChB,OAAO,KAAK;MAAE,MAAM;MAAW;MAAM,OAAO;MAAO,KAAK;KAAO,CAAC;KAElE;IACF;IACA,KAAK,UAAU;KACb,MAAM,SAAS,YAAY,QAAQ,QAAQ;KAC3C,MAAM,QAAQ,YAAY,QAAQ,OAAO;KACzC,MAAM,SAAS,YAAY,OAAO,QAAQ;KAC1C,MAAM,KAAK,YAAY,QAAQ,IAAI,KAAK;KAExC,OAAO,KAAK;MACV,MAAM;MACN;MACA,MAAM,YAAY,QAAQ,UAAU,KAAK,YAAY,QAAQ,OAAO,KAAK;MACzE,OAAO,QAAQ;MACf,KAAK;KACP,CAAC;KAED,IACE,WAAW,eACX,WAAW,YACX,WAAW,eACX,WAAW,WACX;MACA,MAAM,QAAQ,YAAY,YAAY,OAAO,OAAO,GAAG,SAAS;MAEhE,OAAO,KAAK;OACV,MAAM;OACN;OACA,QAAQ,SAAS,YAAY,OAAO,YAAY,KAAK,WAAW,OAAO,MAAM;OAC7E,SAAS,WAAW;OACpB,KAAK;MACP,CAAC;KACH;KACA;IACF;IACA,KAAK,UACH,IAAI,YAAY,QAAQ,OAAO,MAAM,SACnC,OAAO,KAAK;KACV,MAAM;KACN,SAAS,YAAY,QAAQ,SAAS,KAAK;KAC3C,KAAK;IACP,CAAC;GAGP;GAEA,OAAO;EACT,SACM;GACJ,MAAM,WAAW,aAAa,OAAO;GAErC,aAAa,SAAS,cAAc;GAEpC,OAAO,SAAS;EAClB,CAGe;EAAG,kBAAkB;CAAW;AACnD"}
|
|
1
|
+
{"version":3,"file":"mistral-vibe.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/mistral-vibe.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n CliAdapter,\n CliLaunchContext,\n CliLaunchFile,\n CliMcpServers,\n CliParsedEvent,\n CliStreamParser,\n} from \"../contracts\";\nimport {\n asArray,\n asRecord,\n jsonLinesParser,\n numberField,\n outputText,\n parseJsonLine,\n recordField,\n stringField,\n} from \"../stream/json-lines\";\nimport { type TomlTable, toToml } from \"../utils/toml\";\nimport { argvPrompt, promptFile, requirePrivateHome, usageOf } from \"./shared\";\n\n/** Folder (inside the run directory) Vibe writes `export.json` to. */\nconst EXPORT_DIR = \"vibe-output\";\n\n/**\n * Mistral Vibe (`vibe`, PyPI `mistral-vibe`).\n *\n * Verified against the official repo at tag v2.26.1 only (README,\n * `vibe/cli/entrypoint.py`, `vibe/cli/programmatic.py`,\n * `vibe/app_server/run_export.py`, `vibe/core/config/*`); Vibe needs Python\n * 3.12, so no real `--help` was run, 2026-10-17. The capability probe checks\n * every flag against the installed `--help`.\n *\n * - Headless: `vibe -p <prompt> --output streaming` (or `--prompt-file`;\n * `-p` with no value reads stdin). The stream is NDJSON of completed\n * history entries (camelCase): `message` (`role`, `content[].text`), and\n * `effect` — a tool call and its result in one line (`detail.toolName`,\n * `detail.input`, `state.status`, `state.outputText`/`state.error`).\n * There is no usage, cost or final record in the stream, so the adapter\n * adds `--output-dir` and reads usage, cost, session id and outcome from\n * `export.json` when the stream ends.\n * - Model: no flag; `VIBE_ACTIVE_MODEL=<alias>` (set from `model`). Effort\n * is a per-model config field, so `effort` is refused.\n * - Permissions: headless auto-denies every approval (the default agent\n * only auto-approves file edits); bypass is `--auto-approve`.\n * - MCP: `[[mcp_servers]]` in `$VIBE_HOME/config.toml` (private home).\n * - Auth: `MISTRAL_API_KEY`; home `VIBE_HOME`.\n */\nexport const mistralVibeAdapter: CliAdapter = {\n name: \"mistral-vibe\",\n title: \"Mistral Vibe\",\n command: \"vibe\",\n apiKeyEnv: [\"MISTRAL_API_KEY\"],\n passEnv: [],\n homeEnv: [\"VIBE_HOME\"],\n transports: [\"argv\", \"file\", \"stdin\"],\n effort: false,\n mcp: true,\n probe: { help: [[\"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"2.26.1\",\n verifiedBy: \"docs\",\n sources: [\n \"https://github.com/mistralai/mistral-vibe/blob/v2.26.1/README.md\",\n \"https://github.com/mistralai/mistral-vibe/blob/v2.26.1/vibe/cli/entrypoint.py\",\n \"https://github.com/mistralai/mistral-vibe/blob/v2.26.1/vibe/cli/programmatic.py\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"--output\", \"streaming\", \"--output-dir\", path.join(context.runDir, EXPORT_DIR)];\n const requires = [\"--output\", \"streaming\", \"--output-dir\"];\n const files: CliLaunchFile[] = [];\n const env: Record<string, string> = {};\n\n if (context.model !== undefined) {\n env.VIBE_ACTIVE_MODEL = context.model;\n }\n\n if (context.resume !== undefined) {\n args.push(\"--resume\", context.resume);\n requires.push(\"--resume\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--auto-approve\");\n requires.push(\"--auto-approve\");\n }\n\n if (context.mcp !== undefined) {\n const home = requirePrivateHome(context, mistralVibeAdapter, \"MCP servers\");\n\n files.push({\n path: path.join(home, \"config.toml\"),\n content: toToml({ mcp_servers: vibeMcp(context.mcp) }),\n });\n }\n\n if (context.home !== undefined) {\n env.VIBE_HOME = context.home;\n }\n\n if (context.transport === \"file\") {\n const prompt = promptFile(context);\n\n files.push(prompt);\n requires.push(\"--prompt-file\");\n\n return { args, tail: [\"--prompt-file\", prompt.path], env, files, requires };\n }\n\n requires.push(\"-p\");\n\n if (context.transport === \"stdin\") {\n return { args, tail: [\"-p\"], stdin: context.prompt, env, files, requires };\n }\n\n return { args, tail: [\"-p\", argvPrompt(context.prompt)], env, files, requires };\n },\n parser: createVibeParser,\n};\n\nfunction vibeMcp(servers: CliMcpServers): TomlTable[] {\n return Object.entries(servers).map(([name, server]): TomlTable =>\n server.type === \"stdio\"\n ? {\n name,\n transport: \"stdio\",\n command: server.command,\n args: server.args ?? [],\n env: server.env,\n }\n : {\n name,\n transport: server.type === \"http\" ? \"streamable-http\" : \"http\",\n url: server.url,\n auth:\n server.headers !== undefined ? { type: \"static\", headers: server.headers } : undefined,\n },\n );\n}\n\n/** Read Vibe's `export.json`: usage, cost, session id and outcome of the run. */\nfunction exportEvents(context: CliLaunchContext | undefined): {\n events: CliParsedEvent[];\n sessionRef?: string;\n} {\n if (context === undefined) {\n return { events: [] };\n }\n\n let report: Record<string, unknown> | undefined;\n\n try {\n report = parseJsonLine(\n readFileSync(path.join(context.runDir, EXPORT_DIR, \"export.json\"), \"utf8\"),\n );\n } catch {\n return { events: [] };\n }\n\n if (report === undefined) {\n return { events: [] };\n }\n\n const events: CliParsedEvent[] = [];\n const usage = recordField(report, \"usage\");\n\n if (usage !== undefined) {\n const cached = numberField(usage, \"cached_input_tokens\");\n\n events.push({\n type: \"usage\",\n cumulative: true,\n usage: usageOf({\n input: numberField(usage, \"input_tokens\"),\n output: numberField(usage, \"output_tokens\"),\n total: numberField(usage, \"total_tokens\"),\n cachedTokens: cached !== undefined && cached > 0 ? cached : undefined,\n costUSD: numberField(report, \"cost_usd\"),\n }),\n raw: report,\n });\n }\n\n const outcome = stringField(report, \"outcome\");\n\n if (outcome !== undefined && outcome !== \"finished\") {\n events.push({\n type: \"error\",\n message:\n stringField(recordField(report, \"error\"), \"message\") ?? `Mistral Vibe stopped: ${outcome}`,\n fatal: true,\n raw: report,\n });\n }\n\n return { events, sessionRef: stringField(report, \"session_id\") };\n}\n\n/** Parser for `vibe -p … --output streaming` (plus the run's `export.json`). */\nexport function createVibeParser(context?: CliLaunchContext): CliStreamParser {\n let started = false;\n let sessionRef: string | undefined;\n\n const parser = jsonLinesParser(\n (record): CliParsedEvent[] => {\n const events: CliParsedEvent[] = [];\n const session = stringField(record, \"sessionId\");\n\n if (session !== undefined) {\n sessionRef = session;\n }\n\n if (!started) {\n started = true;\n events.push({ type: \"session.started\", sessionRef: session, raw: record });\n }\n\n switch (stringField(record, \"type\")) {\n case \"message\": {\n if (stringField(record, \"role\") !== \"assistant\") {\n break;\n }\n\n const text = asArray(record.content)\n .map((block) => stringField(asRecord(block), \"text\") ?? \"\")\n .join(\"\");\n\n if (text.length > 0) {\n events.push({ type: \"message\", text, delta: false, raw: record });\n }\n break;\n }\n case \"effect\": {\n const detail = recordField(record, \"detail\");\n const state = recordField(record, \"state\");\n const status = stringField(state, \"status\");\n const id = stringField(record, \"id\") ?? \"\";\n\n events.push({\n type: \"tool.call\",\n id,\n name: stringField(detail, \"toolName\") ?? stringField(record, \"title\") ?? \"\",\n input: detail?.input,\n raw: record,\n });\n\n if (\n status === \"completed\" ||\n status === \"failed\" ||\n status === \"cancelled\" ||\n status === \"skipped\"\n ) {\n const error = stringField(recordField(state, \"error\"), \"message\");\n\n events.push({\n type: \"tool.result\",\n id,\n output: error ?? stringField(state, \"outputText\") ?? outputText(state?.output),\n isError: status !== \"completed\",\n raw: record,\n });\n }\n break;\n }\n case \"notice\":\n if (stringField(record, \"level\") === \"error\") {\n events.push({\n type: \"error\",\n message: stringField(record, \"message\") ?? \"error\",\n raw: record,\n });\n }\n break;\n }\n\n return events;\n },\n () => {\n const exported = exportEvents(context);\n\n sessionRef = exported.sessionRef ?? sessionRef;\n\n return exported.events;\n },\n );\n\n return { ...parser, sessionRef: () => sessionRef };\n}\n"],"mappings":";;;;;;;;AAwBA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;AA0BnB,MAAa,qBAAiC;CAC5C,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,iBAAiB;CAC7B,SAAS,CAAC;CACV,SAAS,CAAC,WAAW;CACrB,YAAY;EAAC;EAAQ;EAAQ;CAAO;CACpC,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CACpD,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS;GACP;GACA;GACA;EACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,MAAM,OAAO;GAAC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KACN,SAAS,YAAY,QAAQ,SAAS,KAAK;KAC3C,KAAK;IACP,CAAC;GAGP;GAEA,OAAO;EACT,SACM;GACJ,MAAM,WAAW,aAAa,OAAO;GAErC,aAAa,SAAS,cAAc;GAEpC,OAAO,SAAS;EAClB,CAGe;EAAG,kBAAkB;CAAW;AACnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opencode.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/opencode.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA6Ca,iBAAiB;;
|
|
1
|
+
{"version":3,"file":"opencode.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/opencode.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA6Ca,iBAAiB;;wBAyGd,wBAAwB"}
|
|
@@ -36,6 +36,12 @@ const opencodeAdapter = {
|
|
|
36
36
|
title: "OpenCode",
|
|
37
37
|
command: "opencode",
|
|
38
38
|
apiKeyEnv: [],
|
|
39
|
+
passEnv: [
|
|
40
|
+
"ANTHROPIC_API_KEY",
|
|
41
|
+
"OPENAI_API_KEY",
|
|
42
|
+
"GEMINI_API_KEY",
|
|
43
|
+
"OPENROUTER_API_KEY"
|
|
44
|
+
],
|
|
39
45
|
homeEnv: [
|
|
40
46
|
"XDG_CONFIG_HOME",
|
|
41
47
|
"XDG_DATA_HOME",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opencode.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/opencode.ts"],"sourcesContent":["import path from \"node:path\";\nimport type {\n CliAdapter,\n CliLaunchFile,\n CliMcpServers,\n CliParsedEvent,\n CliStreamParser,\n} from \"../contracts\";\nimport {\n asRecord,\n jsonLinesParser,\n numberField,\n recordField,\n stringField,\n} from \"../stream/json-lines\";\nimport { argvPrompt, jsonFile, usageOf } from \"./shared\";\n\n/**\n * OpenCode (`opencode`, npm `opencode-ai`).\n *\n * Verified against the real `opencode --help` / `opencode run --help` of\n * 1.19.3, the CLI source at that tag (`packages/opencode/src/cli/cmd/run.ts`)\n * and the docs (`cli.mdx`, `config.mdx`, `mcp-servers.mdx`,\n * `permissions.mdx`), 2026-10-17.\n *\n * - Headless: `opencode run --format json <message..>`; with no message,\n * piped stdin is the prompt.\n * - Stream: `{\"type\",\"timestamp\",\"sessionID\",\"part\"|\"error\"}` lines of six\n * types: `step_start`, `text` (whole text blocks, no deltas), `reasoning`,\n * `tool_use` (emitted once the tool finished — call and result together,\n * `state.status` `completed`/`error`), `step_finish` (per-step `cost` in\n * USD and `tokens{input,output,reasoning,cache{read,write}}`, input net of\n * cache) and `error{error:{name,data:{message}}}`. No init or final record.\n * - Permissions: `standard` keeps OpenCode's own rules (permissive by\n * default; anything that would ask is auto-rejected in `run`); bypass is\n * `--auto`.\n * - MCP: the `mcp` key of a config file named by `OPENCODE_CONFIG`, written\n * to the run directory — works with any home.\n * - Home: OpenCode follows XDG; a private/owned home sets `XDG_CONFIG_HOME`,\n * `XDG_DATA_HOME` (auth lives here), `XDG_STATE_HOME` and `XDG_CACHE_HOME`\n * beneath it. Provider keys use the provider's own variable\n * (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, …) — pass them through `env`.\n * - The working directory is passed with `--dir`, because OpenCode prefers a\n * (possibly stale) `PWD` over the process cwd.\n */\nexport const opencodeAdapter: CliAdapter = {\n name: \"opencode\",\n title: \"OpenCode\",\n command: \"opencode\",\n apiKeyEnv: [],\n homeEnv: [\"XDG_CONFIG_HOME\", \"XDG_DATA_HOME\", \"XDG_STATE_HOME\", \"XDG_CACHE_HOME\"],\n transports: [\"argv\", \"stdin\"],\n effort: true,\n mcp: true,\n probe: { help: [[\"run\", \"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"1.19.3\",\n verifiedBy: \"help\",\n sources: [\n \"https://opencode.ai/docs/cli/\",\n \"https://opencode.ai/docs/mcp-servers/\",\n \"https://opencode.ai/docs/permissions/\",\n \"https://github.com/anomalyco/opencode/blob/v1.19.3/packages/opencode/src/cli/cmd/run.ts\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"run\", \"--format\", \"json\", \"--dir\", context.cwd];\n const requires = [\"--format\", \"--dir\"];\n const files: CliLaunchFile[] = [];\n const env: Record<string, string> = { OPENCODE_DISABLE_AUTOUPDATE: \"1\" };\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.effort !== undefined) {\n // `--variant` is provider-specific (\"high, max, minimal\"); the level is passed as-is.\n args.push(\"--variant\", context.effort);\n requires.push(\"--variant\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--session\", context.resume);\n requires.push(\"--session\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--auto\");\n requires.push(\"--auto\");\n }\n\n if (context.mcp !== undefined) {\n const file = path.join(context.runDir, \"opencode.json\");\n\n files.push({\n path: file,\n content: jsonFile({\n $schema: \"https://opencode.ai/config.json\",\n mcp: opencodeMcp(context.mcp),\n }),\n });\n env.OPENCODE_CONFIG = file;\n }\n\n if (context.home !== undefined) {\n env.XDG_CONFIG_HOME = path.join(context.home, \"config\");\n env.XDG_DATA_HOME = path.join(context.home, \"data\");\n env.XDG_STATE_HOME = path.join(context.home, \"state\");\n env.XDG_CACHE_HOME = path.join(context.home, \"cache\");\n }\n\n return {\n args,\n tail: context.transport === \"argv\" ? [argvPrompt(context.prompt)] : [],\n stdin: context.transport === \"stdin\" ? context.prompt : undefined,\n env,\n files,\n requires,\n };\n },\n parser: createOpencodeParser,\n};\n\nfunction opencodeMcp(servers: CliMcpServers): Record<string, unknown> {\n const rendered: Record<string, unknown> = {};\n\n for (const [name, server] of Object.entries(servers)) {\n rendered[name] =\n server.type === \"stdio\"\n ? {\n type: \"local\",\n command: [server.command, ...(server.args ?? [])],\n ...(server.env !== undefined ? { environment: server.env } : {}),\n enabled: true,\n }\n : {\n type: \"remote\",\n url: server.url,\n ...(server.headers !== undefined ? { headers: server.headers } : {}),\n enabled: true,\n };\n }\n\n return rendered;\n}\n\n/** Parser for `opencode run --format json`. */\nexport function createOpencodeParser(): CliStreamParser {\n let started = false;\n\n return jsonLinesParser((record): CliParsedEvent[] => {\n const events: CliParsedEvent[] = [];\n const part = recordField(record, \"part\");\n\n if (!started) {\n started = true;\n events.push({\n type: \"session.started\",\n sessionRef: stringField(record, \"sessionID\"),\n raw: record,\n });\n }\n\n switch (stringField(record, \"type\")) {\n case \"text\": {\n const text = stringField(part, \"text\") ?? \"\";\n\n if (text.length > 0) {\n events.push({ type: \"message\", text, delta: false, raw: record });\n }\n break;\n }\n case \"tool_use\": {\n const state = recordField(part, \"state\");\n const id = stringField(part, \"callID\") ?? stringField(part, \"id\") ?? \"\";\n const failed = stringField(state, \"status\") === \"error\";\n\n events.push(\n {\n type: \"tool.call\",\n id,\n name: stringField(part, \"tool\") ?? \"\",\n input: state?.input,\n raw: record,\n },\n {\n type: \"tool.result\",\n id,\n output: (failed ? stringField(state, \"error\") : stringField(state, \"output\")) ?? \"\",\n isError: failed,\n raw: record,\n },\n );\n break;\n }\n case \"step_finish\": {\n const tokens = recordField(part, \"tokens\");\n const cache = recordField(tokens, \"cache\");\n\n if (tokens !== undefined) {\n const uncached = numberField(tokens, \"input\") ?? 0;\n const cacheRead = numberField(cache, \"read\") ?? 0;\n const cacheWrite = numberField(cache, \"write\") ?? 0;\n\n events.push({\n type: \"usage\",\n cumulative: false,\n usage: usageOf({\n input: uncached + cacheRead + cacheWrite,\n output: numberField(tokens, \"output\"),\n cachedTokens: cacheRead > 0 ? cacheRead : undefined,\n cacheWriteTokens: cacheWrite > 0 ? cacheWrite : undefined,\n reasoningTokens: numberField(tokens, \"reasoning\") || undefined,\n costUSD: numberField(part, \"cost\"),\n }),\n raw: record,\n });\n }\n break;\n }\n case \"error\": {\n const error = asRecord(record.error);\n const name = stringField(error, \"name\") ?? \"Error\";\n const message = stringField(recordField(error, \"data\"), \"message\") ?? name;\n\n events.push({ type: \"error\", message: `${name}: ${message}`, fatal: true, raw: record });\n break;\n }\n }\n\n return events;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,kBAA8B;CACzC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC;CACZ,SAAS;EAAC;EAAmB;EAAiB;EAAkB;CAAgB;CAChF,YAAY,CAAC,QAAQ,OAAO;CAC5B,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,OAAO,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CAC3D,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS;GACP;GACA;GACA;GACA;EACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,MAAM,OAAO;GAAC;GAAO;GAAY;GAAQ;GAAS,QAAQ;EAAG;EAC7D,MAAM,WAAW,CAAC,YAAY,OAAO;EACrC,MAAM,QAAyB,CAAC;EAChC,MAAM,MAA8B,EAAE,6BAA6B,IAAI;EAEvE,IAAI,QAAQ,UAAU,QAAW;GAC/B,KAAK,KAAK,WAAW,QAAQ,KAAK;GAClC,SAAS,KAAK,SAAS;EACzB;EAEA,IAAI,QAAQ,WAAW,QAAW;GAEhC,KAAK,KAAK,aAAa,QAAQ,MAAM;GACrC,SAAS,KAAK,WAAW;EAC3B;EAEA,IAAI,QAAQ,WAAW,QAAW;GAChC,KAAK,KAAK,aAAa,QAAQ,MAAM;GACrC,SAAS,KAAK,WAAW;EAC3B;EAEA,IAAI,QAAQ,eAAe,UAAU;GACnC,KAAK,KAAK,QAAQ;GAClB,SAAS,KAAK,QAAQ;EACxB;EAEA,IAAI,QAAQ,QAAQ,QAAW;GAC7B,MAAM,OAAO,KAAK,KAAK,QAAQ,QAAQ,eAAe;GAEtD,MAAM,KAAK;IACT,MAAM;IACN,SAAS,SAAS;KAChB,SAAS;KACT,KAAK,YAAY,QAAQ,GAAG;IA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tE,OAAO,KAAK;KAAE,MAAM;KAAS,SAAS,GAAG,KAAK,IAAI;KAAW,OAAO;KAAM,KAAK;IAAO,CAAC;IACvF;GACF;EACF;EAEA,OAAO;CACT,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"opencode.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/opencode.ts"],"sourcesContent":["import path from \"node:path\";\nimport type {\n CliAdapter,\n CliLaunchFile,\n CliMcpServers,\n CliParsedEvent,\n CliStreamParser,\n} from \"../contracts\";\nimport {\n asRecord,\n jsonLinesParser,\n numberField,\n recordField,\n stringField,\n} from \"../stream/json-lines\";\nimport { argvPrompt, jsonFile, usageOf } from \"./shared\";\n\n/**\n * OpenCode (`opencode`, npm `opencode-ai`).\n *\n * Verified against the real `opencode --help` / `opencode run --help` of\n * 1.19.3, the CLI source at that tag (`packages/opencode/src/cli/cmd/run.ts`)\n * and the docs (`cli.mdx`, `config.mdx`, `mcp-servers.mdx`,\n * `permissions.mdx`), 2026-10-17.\n *\n * - Headless: `opencode run --format json <message..>`; with no message,\n * piped stdin is the prompt.\n * - Stream: `{\"type\",\"timestamp\",\"sessionID\",\"part\"|\"error\"}` lines of six\n * types: `step_start`, `text` (whole text blocks, no deltas), `reasoning`,\n * `tool_use` (emitted once the tool finished — call and result together,\n * `state.status` `completed`/`error`), `step_finish` (per-step `cost` in\n * USD and `tokens{input,output,reasoning,cache{read,write}}`, input net of\n * cache) and `error{error:{name,data:{message}}}`. No init or final record.\n * - Permissions: `standard` keeps OpenCode's own rules (permissive by\n * default; anything that would ask is auto-rejected in `run`); bypass is\n * `--auto`.\n * - MCP: the `mcp` key of a config file named by `OPENCODE_CONFIG`, written\n * to the run directory — works with any home.\n * - Home: OpenCode follows XDG; a private/owned home sets `XDG_CONFIG_HOME`,\n * `XDG_DATA_HOME` (auth lives here), `XDG_STATE_HOME` and `XDG_CACHE_HOME`\n * beneath it. Provider keys use the provider's own variable\n * (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, …) — pass them through `env`.\n * - The working directory is passed with `--dir`, because OpenCode prefers a\n * (possibly stale) `PWD` over the process cwd.\n */\nexport const opencodeAdapter: CliAdapter = {\n name: \"opencode\",\n title: \"OpenCode\",\n command: \"opencode\",\n apiKeyEnv: [],\n passEnv: [\"ANTHROPIC_API_KEY\", \"OPENAI_API_KEY\", \"GEMINI_API_KEY\", \"OPENROUTER_API_KEY\"],\n homeEnv: [\"XDG_CONFIG_HOME\", \"XDG_DATA_HOME\", \"XDG_STATE_HOME\", \"XDG_CACHE_HOME\"],\n transports: [\"argv\", \"stdin\"],\n effort: true,\n mcp: true,\n probe: { help: [[\"run\", \"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"1.19.3\",\n verifiedBy: \"help\",\n sources: [\n \"https://opencode.ai/docs/cli/\",\n \"https://opencode.ai/docs/mcp-servers/\",\n \"https://opencode.ai/docs/permissions/\",\n \"https://github.com/anomalyco/opencode/blob/v1.19.3/packages/opencode/src/cli/cmd/run.ts\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"run\", \"--format\", \"json\", \"--dir\", context.cwd];\n const requires = [\"--format\", \"--dir\"];\n const files: CliLaunchFile[] = [];\n const env: Record<string, string> = { OPENCODE_DISABLE_AUTOUPDATE: \"1\" };\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.effort !== undefined) {\n // `--variant` is provider-specific (\"high, max, minimal\"); the level is passed as-is.\n args.push(\"--variant\", context.effort);\n requires.push(\"--variant\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--session\", context.resume);\n requires.push(\"--session\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--auto\");\n requires.push(\"--auto\");\n }\n\n if (context.mcp !== undefined) {\n const file = path.join(context.runDir, \"opencode.json\");\n\n files.push({\n path: file,\n content: jsonFile({\n $schema: \"https://opencode.ai/config.json\",\n mcp: opencodeMcp(context.mcp),\n }),\n });\n env.OPENCODE_CONFIG = file;\n }\n\n if (context.home !== undefined) {\n env.XDG_CONFIG_HOME = path.join(context.home, \"config\");\n env.XDG_DATA_HOME = path.join(context.home, \"data\");\n env.XDG_STATE_HOME = path.join(context.home, \"state\");\n env.XDG_CACHE_HOME = path.join(context.home, \"cache\");\n }\n\n return {\n args,\n tail: context.transport === \"argv\" ? [argvPrompt(context.prompt)] : [],\n stdin: context.transport === \"stdin\" ? context.prompt : undefined,\n env,\n files,\n requires,\n };\n },\n parser: createOpencodeParser,\n};\n\nfunction opencodeMcp(servers: CliMcpServers): Record<string, unknown> {\n const rendered: Record<string, unknown> = {};\n\n for (const [name, server] of Object.entries(servers)) {\n rendered[name] =\n server.type === \"stdio\"\n ? {\n type: \"local\",\n command: [server.command, ...(server.args ?? [])],\n ...(server.env !== undefined ? { environment: server.env } : {}),\n enabled: true,\n }\n : {\n type: \"remote\",\n url: server.url,\n ...(server.headers !== undefined ? { headers: server.headers } : {}),\n enabled: true,\n };\n }\n\n return rendered;\n}\n\n/** Parser for `opencode run --format json`. */\nexport function createOpencodeParser(): CliStreamParser {\n let started = false;\n\n return jsonLinesParser((record): CliParsedEvent[] => {\n const events: CliParsedEvent[] = [];\n const part = recordField(record, \"part\");\n\n if (!started) {\n started = true;\n events.push({\n type: \"session.started\",\n sessionRef: stringField(record, \"sessionID\"),\n raw: record,\n });\n }\n\n switch (stringField(record, \"type\")) {\n case \"text\": {\n const text = stringField(part, \"text\") ?? \"\";\n\n if (text.length > 0) {\n events.push({ type: \"message\", text, delta: false, raw: record });\n }\n break;\n }\n case \"tool_use\": {\n const state = recordField(part, \"state\");\n const id = stringField(part, \"callID\") ?? stringField(part, \"id\") ?? \"\";\n const failed = stringField(state, \"status\") === \"error\";\n\n events.push(\n {\n type: \"tool.call\",\n id,\n name: stringField(part, \"tool\") ?? \"\",\n input: state?.input,\n raw: record,\n },\n {\n type: \"tool.result\",\n id,\n output: (failed ? stringField(state, \"error\") : stringField(state, \"output\")) ?? \"\",\n isError: failed,\n raw: record,\n },\n );\n break;\n }\n case \"step_finish\": {\n const tokens = recordField(part, \"tokens\");\n const cache = recordField(tokens, \"cache\");\n\n if (tokens !== undefined) {\n const uncached = numberField(tokens, \"input\") ?? 0;\n const cacheRead = numberField(cache, \"read\") ?? 0;\n const cacheWrite = numberField(cache, \"write\") ?? 0;\n\n events.push({\n type: \"usage\",\n cumulative: false,\n usage: usageOf({\n input: uncached + cacheRead + cacheWrite,\n output: numberField(tokens, \"output\"),\n cachedTokens: cacheRead > 0 ? cacheRead : undefined,\n cacheWriteTokens: cacheWrite > 0 ? cacheWrite : undefined,\n reasoningTokens: numberField(tokens, \"reasoning\") || undefined,\n costUSD: numberField(part, \"cost\"),\n }),\n raw: record,\n });\n }\n break;\n }\n case \"error\": {\n const error = asRecord(record.error);\n const name = stringField(error, \"name\") ?? \"Error\";\n const message = stringField(recordField(error, \"data\"), \"message\") ?? name;\n\n events.push({ type: \"error\", message: `${name}: ${message}`, fatal: true, raw: record });\n break;\n }\n }\n\n return events;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,kBAA8B;CACzC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC;CACZ,SAAS;EAAC;EAAqB;EAAkB;EAAkB;CAAoB;CACvF,SAAS;EAAC;EAAmB;EAAiB;EAAkB;CAAgB;CAChF,YAAY,CAAC,QAAQ,OAAO;CAC5B,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,OAAO,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CAC3D,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS;GACP;GACA;GACA;GACA;EACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,MAAM,OAAO;GAAC;GAAO;GAAY;GAAQ;GAAS,QAAQ;EAAG;EAC7D,MAAM,WAAW,CAAC,YAAY,OAAO;EACrC,MAAM,QAAyB,CAAC;EAChC,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WAAW,QAAW;KACxB,MAAM,WAAW,YAAY,QAAQ,OAAO,KAAK;KACjD,MAAM,YAAY,YAAY,OAAO,MAAM,KAAK;KAChD,MAAM,aAAa,YAAY,OAAO,OAAO,KAAK;KAElD,OAAO,KAAK;MACV,MAAM;MACN,YAAY;MACZ,OAAO,QAAQ;OACb,OAAO,WAAW,YAAY;OAC9B,QAAQ,YAAY,QAAQ,QAAQ;OACpC,cAAc,YAAY,IAAI,YAAY;OAC1C,kBAAkB,aAAa,IAAI,aAAa;OAChD,iBAAiB,YAAY,QAAQ,WAAW,KAAK;OACrD,SAAS,YAAY,MAAM,MAAM;MACnC,CAAC;MACD,KAAK;KACP,CAAC;IACH;IACA;GACF;GACA,KAAK,SAAS;IACZ,MAAM,QAAQ,SAAS,OAAO,KAAK;IACnC,MAAM,OAAO,YAAY,OAAO,MAAM,KAAK;IAC3C,MAAM,UAAU,YAAY,YAAY,OAAO,MAAM,GAAG,SAAS,KAAK;IAEtE,OAAO,KAAK;KAAE,MAAM;KAAS,SAAS,GAAG,KAAK,IAAI;KAAW,OAAO;KAAM,KAAK;IAAO,CAAC;IACvF;GACF;EACF;EAEA,OAAO;CACT,CAAC;AACH"}
|
|
@@ -32,6 +32,12 @@ const qwenCodeAdapter = {
|
|
|
32
32
|
title: "Qwen Code",
|
|
33
33
|
command: "qwen",
|
|
34
34
|
apiKeyEnv: ["OPENAI_API_KEY"],
|
|
35
|
+
passEnv: [
|
|
36
|
+
"OPENAI_BASE_URL",
|
|
37
|
+
"OPENAI_MODEL",
|
|
38
|
+
"ANTHROPIC_API_KEY",
|
|
39
|
+
"GEMINI_API_KEY"
|
|
40
|
+
],
|
|
35
41
|
homeEnv: ["QWEN_HOME"],
|
|
36
42
|
transports: ["argv", "stdin"],
|
|
37
43
|
effort: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qwen-code.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/qwen-code.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { CliAdapter, CliLaunchFile } from \"../contracts\";\nimport { createClaudeStreamParser } from \"./claude-stream\";\nimport { argvPrompt, jsonFile, mcpServersJson } from \"./shared\";\n\n/**\n * Qwen Code (`qwen`, npm `@qwen-code/qwen-code`), a Gemini CLI fork.\n *\n * Verified against the real `qwen --help` of 0.25.2 and the docs/source at\n * tag v0.25.2 (`docs/users/features/headless.md`, `nonInteractive/types.ts`),\n * 2026-10-17.\n *\n * - Headless: positional prompt (`-p` is deprecated) with\n * `--output-format stream-json`; piped stdin is used as the prompt when no\n * positional prompt is given.\n * - Stream: the Claude Code `stream-json` shape (`system/init`, `assistant`,\n * `user` tool results, `result`), with `input_tokens` that already include\n * cached tokens and no cost field.\n * - Permissions: headless auto-denies tools that need confirmation (the tool\n * result says so and `permission_denials` lists it); bypass is `--yolo`.\n * - MCP: `--mcp-config <file>` with `{\"mcpServers\":…}` — written to the run\n * directory, so it works with any home. Remote servers use `httpUrl`\n * (streamable HTTP) or `url` (SSE).\n * - Home: `QWEN_HOME`. Auth depends on the auth type: `OPENAI_API_KEY`\n * (default for `apiKey`), or `ANTHROPIC_API_KEY` / `GEMINI_API_KEY` with\n * `--auth-type` in `args`.\n * - Effort has no flag (it is the `model.reasoningEffort` setting), so\n * `effort` is refused.\n */\nexport const qwenCodeAdapter: CliAdapter = {\n name: \"qwen-code\",\n title: \"Qwen Code\",\n command: \"qwen\",\n apiKeyEnv: [\"OPENAI_API_KEY\"],\n homeEnv: [\"QWEN_HOME\"],\n transports: [\"argv\", \"stdin\"],\n effort: false,\n mcp: true,\n probe: { help: [[\"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"0.25.2\",\n verifiedBy: \"help\",\n sources: [\n \"https://qwenlm.github.io/qwen-code-docs/\",\n \"https://github.com/QwenLM/qwen-code/blob/v0.25.2/docs/users/features/headless.md\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"--output-format\", \"stream-json\"];\n const requires = [\"--output-format\", \"stream-json\"];\n const files: CliLaunchFile[] = [];\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--resume\", context.resume);\n requires.push(\"--resume\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--yolo\");\n requires.push(\"--yolo\");\n }\n\n if (context.mcp !== undefined) {\n const file = path.join(context.runDir, \"mcp.json\");\n\n files.push({\n path: file,\n content: jsonFile({ mcpServers: mcpServersJson(context.mcp, { httpUrlKey: \"httpUrl\" }) }),\n });\n args.push(\"--mcp-config\", file);\n requires.push(\"--mcp-config\");\n }\n\n return {\n args,\n tail: context.transport === \"argv\" ? [argvPrompt(context.prompt)] : [],\n stdin: context.transport === \"stdin\" ? context.prompt : undefined,\n env: {\n ...(context.home !== undefined ? { QWEN_HOME: context.home } : {}),\n QWEN_CODE_SUPPRESS_YOLO_WARNING: \"1\",\n },\n files,\n requires,\n };\n },\n parser: () => createClaudeStreamParser({ usage: \"inclusive\", vendor: \"Qwen Code\" }),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,kBAA8B;CACzC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,gBAAgB;CAC5B,SAAS,CAAC,WAAW;CACrB,YAAY,CAAC,QAAQ,OAAO;CAC5B,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CACpD,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS,CACP,4CACA,kFACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,MAAM,OAAO,CAAC,mBAAmB,aAAa;EAC9C,MAAM,WAAW,CAAC,mBAAmB,aAAa;EAClD,MAAM,QAAyB,CAAC;EAEhC,IAAI,QAAQ,UAAU,QAAW;GAC/B,KAAK,KAAK,WAAW,QAAQ,KAAK;GAClC,SAAS,KAAK,SAAS;EACzB;EAEA,IAAI,QAAQ,WAAW,QAAW;GAChC,KAAK,KAAK,YAAY,QAAQ,MAAM;GACpC,SAAS,KAAK,UAAU;EAC1B;EAEA,IAAI,QAAQ,eAAe,UAAU;GACnC,KAAK,KAAK,QAAQ;GAClB,SAAS,KAAK,QAAQ;EACxB;EAEA,IAAI,QAAQ,QAAQ,QAAW;GAC7B,MAAM,OAAO,KAAK,KAAK,QAAQ,QAAQ,UAAU;GAEjD,MAAM,KAAK;IACT,MAAM;IACN,SAAS,SAAS,EAAE,YAAY,eAAe,QAAQ,KAAK,EAAE,YAAY,UAAU,CAAC,EAAE,CAAC;GAC1F,CAAC;GACD,KAAK,KAAK,gBAAgB,IAAI;GAC9B,SAAS,KAAK,cAAc;EAC9B;EAEA,OAAO;GACL;GACA,MAAM,QAAQ,cAAc,SAAS,CAAC,WAAW,QAAQ,MAAM,CAAC,IAAI,CAAC;GACrE,OAAO,QAAQ,cAAc,UAAU,QAAQ,SAAS;GACxD,KAAK;IACH,GAAI,QAAQ,SAAS,SAAY,EAAE,WAAW,QAAQ,KAAK,IAAI,CAAC;IAChE,iCAAiC;GACnC;GACA;GACA;EACF;CACF;CACA,cAAc,yBAAyB;EAAE,OAAO;EAAa,QAAQ;CAAY,CAAC;AACpF"}
|
|
1
|
+
{"version":3,"file":"qwen-code.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/qwen-code.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { CliAdapter, CliLaunchFile } from \"../contracts\";\nimport { createClaudeStreamParser } from \"./claude-stream\";\nimport { argvPrompt, jsonFile, mcpServersJson } from \"./shared\";\n\n/**\n * Qwen Code (`qwen`, npm `@qwen-code/qwen-code`), a Gemini CLI fork.\n *\n * Verified against the real `qwen --help` of 0.25.2 and the docs/source at\n * tag v0.25.2 (`docs/users/features/headless.md`, `nonInteractive/types.ts`),\n * 2026-10-17.\n *\n * - Headless: positional prompt (`-p` is deprecated) with\n * `--output-format stream-json`; piped stdin is used as the prompt when no\n * positional prompt is given.\n * - Stream: the Claude Code `stream-json` shape (`system/init`, `assistant`,\n * `user` tool results, `result`), with `input_tokens` that already include\n * cached tokens and no cost field.\n * - Permissions: headless auto-denies tools that need confirmation (the tool\n * result says so and `permission_denials` lists it); bypass is `--yolo`.\n * - MCP: `--mcp-config <file>` with `{\"mcpServers\":…}` — written to the run\n * directory, so it works with any home. Remote servers use `httpUrl`\n * (streamable HTTP) or `url` (SSE).\n * - Home: `QWEN_HOME`. Auth depends on the auth type: `OPENAI_API_KEY`\n * (default for `apiKey`), or `ANTHROPIC_API_KEY` / `GEMINI_API_KEY` with\n * `--auth-type` in `args`.\n * - Effort has no flag (it is the `model.reasoningEffort` setting), so\n * `effort` is refused.\n */\nexport const qwenCodeAdapter: CliAdapter = {\n name: \"qwen-code\",\n title: \"Qwen Code\",\n command: \"qwen\",\n apiKeyEnv: [\"OPENAI_API_KEY\"],\n passEnv: [\"OPENAI_BASE_URL\", \"OPENAI_MODEL\", \"ANTHROPIC_API_KEY\", \"GEMINI_API_KEY\"],\n homeEnv: [\"QWEN_HOME\"],\n transports: [\"argv\", \"stdin\"],\n effort: false,\n mcp: true,\n probe: { help: [[\"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"0.25.2\",\n verifiedBy: \"help\",\n sources: [\n \"https://qwenlm.github.io/qwen-code-docs/\",\n \"https://github.com/QwenLM/qwen-code/blob/v0.25.2/docs/users/features/headless.md\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"--output-format\", \"stream-json\"];\n const requires = [\"--output-format\", \"stream-json\"];\n const files: CliLaunchFile[] = [];\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--resume\", context.resume);\n requires.push(\"--resume\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--yolo\");\n requires.push(\"--yolo\");\n }\n\n if (context.mcp !== undefined) {\n const file = path.join(context.runDir, \"mcp.json\");\n\n files.push({\n path: file,\n content: jsonFile({ mcpServers: mcpServersJson(context.mcp, { httpUrlKey: \"httpUrl\" }) }),\n });\n args.push(\"--mcp-config\", file);\n requires.push(\"--mcp-config\");\n }\n\n return {\n args,\n tail: context.transport === \"argv\" ? [argvPrompt(context.prompt)] : [],\n stdin: context.transport === \"stdin\" ? context.prompt : undefined,\n env: {\n ...(context.home !== undefined ? { QWEN_HOME: context.home } : {}),\n QWEN_CODE_SUPPRESS_YOLO_WARNING: \"1\",\n },\n files,\n requires,\n };\n },\n parser: () => createClaudeStreamParser({ usage: \"inclusive\", vendor: \"Qwen Code\" }),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,kBAA8B;CACzC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,gBAAgB;CAC5B,SAAS;EAAC;EAAmB;EAAgB;EAAqB;CAAgB;CAClF,SAAS,CAAC,WAAW;CACrB,YAAY,CAAC,QAAQ,OAAO;CAC5B,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CACpD,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS,CACP,4CACA,kFACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,MAAM,OAAO,CAAC,mBAAmB,aAAa;EAC9C,MAAM,WAAW,CAAC,mBAAmB,aAAa;EAClD,MAAM,QAAyB,CAAC;EAEhC,IAAI,QAAQ,UAAU,QAAW;GAC/B,KAAK,KAAK,WAAW,QAAQ,KAAK;GAClC,SAAS,KAAK,SAAS;EACzB;EAEA,IAAI,QAAQ,WAAW,QAAW;GAChC,KAAK,KAAK,YAAY,QAAQ,MAAM;GACpC,SAAS,KAAK,UAAU;EAC1B;EAEA,IAAI,QAAQ,eAAe,UAAU;GACnC,KAAK,KAAK,QAAQ;GAClB,SAAS,KAAK,QAAQ;EACxB;EAEA,IAAI,QAAQ,QAAQ,QAAW;GAC7B,MAAM,OAAO,KAAK,KAAK,QAAQ,QAAQ,UAAU;GAEjD,MAAM,KAAK;IACT,MAAM;IACN,SAAS,SAAS,EAAE,YAAY,eAAe,QAAQ,KAAK,EAAE,YAAY,UAAU,CAAC,EAAE,CAAC;GAC1F,CAAC;GACD,KAAK,KAAK,gBAAgB,IAAI;GAC9B,SAAS,KAAK,cAAc;EAC9B;EAEA,OAAO;GACL;GACA,MAAM,QAAQ,cAAc,SAAS,CAAC,WAAW,QAAQ,MAAM,CAAC,IAAI,CAAC;GACrE,OAAO,QAAQ,cAAc,UAAU,QAAQ,SAAS;GACxD,KAAK;IACH,GAAI,QAAQ,SAAS,SAAY,EAAE,WAAW,QAAQ,KAAK,IAAI,CAAC;IAChE,iCAAiC;GACnC;GACA;GACA;EACF;CACF;CACA,cAAc,yBAAyB;EAAE,OAAO;EAAa,QAAQ;CAAY,CAAC;AACpF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reasonix.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/reasonix.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;qBAkDa,iBAAiB;;
|
|
1
|
+
{"version":3,"file":"reasonix.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/reasonix.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;qBAkDa,iBAAiB;;wBA8Gd,wBAAwB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reasonix.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/reasonix.ts"],"sourcesContent":["import path from \"node:path\";\nimport type {\n CliAdapter,\n CliLaunchFile,\n CliMcpServers,\n CliParsedEvent,\n CliStreamParser,\n CliUsage,\n} from \"../contracts\";\nimport {\n asRecord,\n jsonLinesParser,\n numberField,\n recordField,\n stringField,\n type JsonRecord,\n} from \"../stream/json-lines\";\nimport { type TomlTable, toToml } from \"../utils/toml\";\nimport {\n argvPrompt,\n dotenvFile,\n mapEffort,\n parseArguments,\n requirePrivateHome,\n usageOf,\n} from \"./shared\";\n\n/**\n * Reasonix (`reasonix`, npm `reasonix`) — a cache-first coding agent built\n * around DeepSeek (now multi-provider); the npm package launches a prebuilt\n * Go binary.\n *\n * Verified against the real `reasonix run --help` / `--version` of 2.43.0,\n * real stream-json output (captured against a local fake model server) and\n * the docs at that tag (`docs/CLI.md`, `docs/CONFIG_PATHS.md`), 2026-10-17.\n *\n * - Headless: `reasonix run --output-format stream-json <task>`; with no\n * positional task, piped stdin is the prompt.\n * - Stream: every line has `kind` (`text` deltas, `message` full text,\n * `tool_dispatch`/`tool_started`/`tool_result` with a `tool` object whose\n * non-empty `err` marks a failure, `usage` per model call, `turn_done`) plus\n * `sessionId`; the final line is `{\"type\":\"result\",…}` with totals.\n * - Permissions: headless \"ask\" mode refuses writes (listed in\n * `permission_denials`; exit 4 in an untrusted folder); bypass is `--yolo`.\n * - MCP: no flag; `[[plugins]]` in `$REASONIX_HOME/config.toml`.\n * - Auth: provider keys are read only from `$REASONIX_HOME/.env`, never the\n * shell environment, so `apiKey` is written there (0600) as\n * `DEEPSEEK_API_KEY` — this needs a private home. For another provider,\n * put its variable in that file yourself via a caller-owned home.\n */\nexport const reasonixAdapter: CliAdapter = {\n name: \"reasonix\",\n title: \"Reasonix\",\n command: \"reasonix\",\n apiKeyEnv: [\"DEEPSEEK_API_KEY\"],\n homeEnv: [\"REASONIX_HOME\"],\n transports: [\"argv\", \"stdin\"],\n effort: true,\n mcp: true,\n probe: { help: [[\"run\", \"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"2.43.0\",\n verifiedBy: \"help\",\n sources: [\n \"https://github.com/esengine/DeepSeek-Reasonix/blob/v2.43.0/docs/CLI.md\",\n \"https://github.com/esengine/DeepSeek-Reasonix/blob/v2.43.0/docs/CONFIG_PATHS.md\",\n \"https://www.npmjs.com/package/reasonix\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"run\", \"--output-format\", \"stream-json\"];\n const requires = [\"--output-format\", \"stream-json\"];\n const files: CliLaunchFile[] = [];\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.effort !== undefined) {\n // DeepSeek levels per docs/REASONING_PROVIDERS.md: auto | disabled | low | high | max.\n args.push(\n \"--effort\",\n mapEffort(context.effort, { none: \"disabled\", low: \"low\", high: \"high\", max: \"max\" }),\n );\n requires.push(\"--effort\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--resume\", context.resume);\n requires.push(\"--resume\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--yolo\");\n requires.push(\"--yolo\");\n }\n\n if (context.mcp !== undefined) {\n const home = requirePrivateHome(context, reasonixAdapter, \"MCP servers\");\n\n files.push({\n path: path.join(home, \"config.toml\"),\n content: toToml({ plugins: reasonixPlugins(context.mcp) }),\n });\n }\n\n if (context.apiKey !== undefined) {\n const home = requirePrivateHome(context, reasonixAdapter, \"API keys (its .env file)\");\n\n files.push({\n path: path.join(home, \".env\"),\n content: dotenvFile({ DEEPSEEK_API_KEY: context.apiKey }),\n });\n }\n\n return {\n args,\n tail: context.transport === \"argv\" ? [argvPrompt(context.prompt)] : [],\n stdin: context.transport === \"stdin\" ? context.prompt : undefined,\n env: {\n ...(context.home !== undefined ? { REASONIX_HOME: context.home } : {}),\n REASONIX_TELEMETRY: \"off\",\n },\n files,\n requires,\n };\n },\n parser: createReasonixParser,\n};\n\nfunction reasonixPlugins(servers: CliMcpServers): TomlTable[] {\n return Object.entries(servers).map(([name, server]): TomlTable =>\n server.type === \"stdio\"\n ? { name, type: \"stdio\", command: server.command, args: server.args ?? [], env: server.env }\n : { name, type: server.type, url: server.url, headers: server.headers },\n );\n}\n\n/** Reasonix per-call usage (`promptTokens` includes cache hits). */\nfunction callUsage(usage: JsonRecord | undefined): CliUsage | undefined {\n if (usage === undefined) {\n return undefined;\n }\n\n const cacheHit = numberField(usage, \"cacheHitTokens\");\n\n return usageOf({\n input: numberField(usage, \"promptTokens\"),\n output: numberField(usage, \"completionTokens\"),\n total: numberField(usage, \"totalTokens\"),\n cachedTokens: cacheHit !== undefined && cacheHit > 0 ? cacheHit : undefined,\n reasoningTokens: numberField(usage, \"reasoningTokens\"),\n costUSD: numberField(usage, \"costUsd\"),\n });\n}\n\n/** Parser for `reasonix run --output-format stream-json`. */\nexport function createReasonixParser(): CliStreamParser {\n let started = false;\n let sessionRef: string | undefined;\n\n return {\n ...jsonLinesParser((record): CliParsedEvent[] => {\n const events: CliParsedEvent[] = [];\n const recordSession = stringField(record, \"sessionId\") ?? stringField(record, \"session_id\");\n\n if (recordSession !== undefined) {\n sessionRef = recordSession;\n }\n\n if (!started && recordSession !== undefined) {\n started = true;\n events.push({ type: \"session.started\", sessionRef: recordSession, raw: record });\n }\n\n if (stringField(record, \"type\") === \"result\") {\n const usage = recordField(record, \"usage\");\n\n if (usage !== undefined) {\n events.push({\n type: \"usage\",\n cumulative: true,\n usage: usageOf({\n input: numberField(usage, \"input_tokens\"),\n output: numberField(usage, \"output_tokens\"),\n cachedTokens: numberField(usage, \"cache_read_input_tokens\") || undefined,\n costUSD: numberField(record, \"total_cost_usd\"),\n }),\n raw: record,\n });\n }\n\n const result = stringField(record, \"result\") ?? \"\";\n\n if (record.is_error === true) {\n events.push({\n type: \"error\",\n message: result || \"Reasonix run failed\",\n fatal: true,\n raw: record,\n });\n } else if (result.length > 0) {\n events.push({ type: \"message\", text: result, delta: false, final: true, raw: record });\n }\n\n return events;\n }\n\n const tool = asRecord(record.tool);\n\n switch (stringField(record, \"kind\")) {\n case \"text\": {\n const text = stringField(record, \"text\") ?? \"\";\n\n if (text.length > 0) {\n events.push({ type: \"message\", text, delta: true, raw: record });\n }\n break;\n }\n case \"message\":\n events.push({\n type: \"message\",\n text: stringField(record, \"text\") ?? \"\",\n delta: false,\n raw: record,\n });\n break;\n case \"tool_dispatch\":\n // The first dispatch streams arguments (`partial: true`); report the complete one.\n if (tool !== undefined && tool.partial !== true) {\n events.push({\n type: \"tool.call\",\n id: stringField(tool, \"id\") ?? \"\",\n name: stringField(tool, \"name\") ?? \"\",\n input: parseArguments(tool.args),\n raw: record,\n });\n }\n break;\n case \"tool_result\": {\n const error = stringField(tool, \"err\") ?? \"\";\n\n events.push({\n type: \"tool.result\",\n id: stringField(tool, \"id\") ?? \"\",\n output: error.length > 0 ? error : (stringField(tool, \"output\") ?? \"\"),\n isError: error.length > 0,\n raw: record,\n });\n break;\n }\n case \"usage\": {\n const usage = callUsage(recordField(record, \"usage\"));\n\n if (usage !== undefined) {\n events.push({ type: \"usage\", usage, cumulative: false, raw: record });\n }\n break;\n }\n case \"turn_done\":\n if (stringField(record, \"status\") === \"failed\") {\n events.push({\n type: \"error\",\n message: stringField(record, \"err\") ?? \"Reasonix turn failed\",\n fatal: true,\n raw: record,\n });\n }\n break;\n }\n\n return events;\n }),\n sessionRef: () => sessionRef,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,MAAa,kBAA8B;CACzC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,kBAAkB;CAC9B,SAAS,CAAC,eAAe;CACzB,YAAY,CAAC,QAAQ,OAAO;CAC5B,QAAQ;CACR,KAAK;CACL,OAAO;EAAE,MAAM,CAAC,CAAC,OAAO,QAAQ,CAAC;EAAG,SAAS,CAAC,WAAW;CAAE;CAC3D,cAAc;EACZ,SAAS;EACT,YAAY;EACZ,SAAS;GACP;GACA;GACA;EACF;EACA,WAAW;CACb;CACA,KAAK,SAAS;EACZ,MAAM,OAAO;GAAC;GAAO;GAAmB;EAAa;EACrD,MAAM,WAAW,CAAC,mBAAmB,aAAa;EAClD,MAAM,QAAyB,CAAC;EAEhC,IAAI,QAAQ,UAAU,QAAW;GAC/B,KAAK,KAAK,WAAW,QAAQ,KAAK;GAClC,SAAS,KAAK,SAAS;EACzB;EAEA,IAAI,QAAQ,WAAW,QA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vC,OAAO;KACP,KAAK;IACP,CAAC;GAGP;GAEA,OAAO;EACT,CAAC;EACD,kBAAkB;CACpB;AACF"}
|
|
1
|
+
{"version":3,"file":"reasonix.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/reasonix.ts"],"sourcesContent":["import path from \"node:path\";\nimport type {\n CliAdapter,\n CliLaunchFile,\n CliMcpServers,\n CliParsedEvent,\n CliStreamParser,\n CliUsage,\n} from \"../contracts\";\nimport {\n asRecord,\n jsonLinesParser,\n numberField,\n recordField,\n stringField,\n type JsonRecord,\n} from \"../stream/json-lines\";\nimport { type TomlTable, toToml } from \"../utils/toml\";\nimport {\n argvPrompt,\n dotenvFile,\n mapEffort,\n parseArguments,\n requirePrivateHome,\n usageOf,\n} from \"./shared\";\n\n/**\n * Reasonix (`reasonix`, npm `reasonix`) — a cache-first coding agent built\n * around DeepSeek (now multi-provider); the npm package launches a prebuilt\n * Go binary.\n *\n * Verified against the real `reasonix run --help` / `--version` of 2.43.0,\n * real stream-json output (captured against a local fake model server) and\n * the docs at that tag (`docs/CLI.md`, `docs/CONFIG_PATHS.md`), 2026-10-17.\n *\n * - Headless: `reasonix run --output-format stream-json <task>`; with no\n * positional task, piped stdin is the prompt.\n * - Stream: every line has `kind` (`text` deltas, `message` full text,\n * `tool_dispatch`/`tool_started`/`tool_result` with a `tool` object whose\n * non-empty `err` marks a failure, `usage` per model call, `turn_done`) plus\n * `sessionId`; the final line is `{\"type\":\"result\",…}` with totals.\n * - Permissions: headless \"ask\" mode refuses writes (listed in\n * `permission_denials`; exit 4 in an untrusted folder); bypass is `--yolo`.\n * - MCP: no flag; `[[plugins]]` in `$REASONIX_HOME/config.toml`.\n * - Auth: provider keys are read only from `$REASONIX_HOME/.env`, never the\n * shell environment, so `apiKey` is written there (0600) as\n * `DEEPSEEK_API_KEY` — this needs a private home. For another provider,\n * put its variable in that file yourself via a caller-owned home.\n */\nexport const reasonixAdapter: CliAdapter = {\n name: \"reasonix\",\n title: \"Reasonix\",\n command: \"reasonix\",\n apiKeyEnv: [\"DEEPSEEK_API_KEY\"],\n passEnv: [],\n homeEnv: [\"REASONIX_HOME\"],\n transports: [\"argv\", \"stdin\"],\n effort: true,\n mcp: true,\n probe: { help: [[\"run\", \"--help\"]], version: [\"--version\"] },\n verification: {\n version: \"2.43.0\",\n verifiedBy: \"help\",\n sources: [\n \"https://github.com/esengine/DeepSeek-Reasonix/blob/v2.43.0/docs/CLI.md\",\n \"https://github.com/esengine/DeepSeek-Reasonix/blob/v2.43.0/docs/CONFIG_PATHS.md\",\n \"https://www.npmjs.com/package/reasonix\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"run\", \"--output-format\", \"stream-json\"];\n const requires = [\"--output-format\", \"stream-json\"];\n const files: CliLaunchFile[] = [];\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.effort !== undefined) {\n // DeepSeek levels per docs/REASONING_PROVIDERS.md: auto | disabled | low | high | max.\n args.push(\n \"--effort\",\n mapEffort(context.effort, { none: \"disabled\", low: \"low\", high: \"high\", max: \"max\" }),\n );\n requires.push(\"--effort\");\n }\n\n if (context.resume !== undefined) {\n args.push(\"--resume\", context.resume);\n requires.push(\"--resume\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--yolo\");\n requires.push(\"--yolo\");\n }\n\n if (context.mcp !== undefined) {\n const home = requirePrivateHome(context, reasonixAdapter, \"MCP servers\");\n\n files.push({\n path: path.join(home, \"config.toml\"),\n content: toToml({ plugins: reasonixPlugins(context.mcp) }),\n });\n }\n\n if (context.apiKey !== undefined) {\n const home = requirePrivateHome(context, reasonixAdapter, \"API keys (its .env file)\");\n\n files.push({\n path: path.join(home, \".env\"),\n content: dotenvFile({ DEEPSEEK_API_KEY: context.apiKey }),\n });\n }\n\n return {\n args,\n tail: context.transport === \"argv\" ? [argvPrompt(context.prompt)] : [],\n stdin: context.transport === \"stdin\" ? context.prompt : undefined,\n env: {\n ...(context.home !== undefined ? { REASONIX_HOME: context.home } : {}),\n REASONIX_TELEMETRY: \"off\",\n },\n files,\n requires,\n };\n },\n parser: createReasonixParser,\n};\n\nfunction reasonixPlugins(servers: CliMcpServers): TomlTable[] {\n return Object.entries(servers).map(([name, server]): TomlTable =>\n server.type === \"stdio\"\n ? { name, type: \"stdio\", command: server.command, args: server.args ?? [], env: server.env }\n : { name, type: server.type, url: server.url, headers: server.headers },\n );\n}\n\n/** Reasonix per-call usage (`promptTokens` includes cache hits). */\nfunction callUsage(usage: JsonRecord | undefined): CliUsage | undefined {\n if (usage === undefined) {\n return undefined;\n }\n\n const cacheHit = numberField(usage, \"cacheHitTokens\");\n\n return usageOf({\n input: numberField(usage, \"promptTokens\"),\n output: numberField(usage, \"completionTokens\"),\n total: numberField(usage, \"totalTokens\"),\n cachedTokens: cacheHit !== undefined && cacheHit > 0 ? cacheHit : undefined,\n reasoningTokens: numberField(usage, \"reasoningTokens\"),\n costUSD: numberField(usage, \"costUsd\"),\n });\n}\n\n/** Parser for `reasonix run --output-format stream-json`. */\nexport function createReasonixParser(): CliStreamParser {\n let started = false;\n let sessionRef: string | undefined;\n\n return {\n ...jsonLinesParser((record): CliParsedEvent[] => {\n const events: CliParsedEvent[] = [];\n const recordSession = stringField(record, \"sessionId\") ?? stringField(record, \"session_id\");\n\n if (recordSession !== undefined) {\n sessionRef = recordSession;\n }\n\n if (!started && recordSession !== undefined) {\n started = true;\n events.push({ type: \"session.started\", sessionRef: recordSession, raw: record });\n }\n\n if (stringField(record, \"type\") === \"result\") {\n const usage = recordField(record, \"usage\");\n\n if (usage !== undefined) {\n events.push({\n type: \"usage\",\n cumulative: true,\n usage: usageOf({\n input: numberField(usage, \"input_tokens\"),\n output: numberField(usage, \"output_tokens\"),\n cachedTokens: numberField(usage, \"cache_read_input_tokens\") || undefined,\n costUSD: numberField(record, \"total_cost_usd\"),\n }),\n raw: record,\n });\n }\n\n const result = stringField(record, \"result\") ?? \"\";\n\n if (record.is_error === true) {\n events.push({\n type: \"error\",\n message: result || \"Reasonix run failed\",\n fatal: true,\n raw: record,\n });\n } else if (result.length > 0) {\n events.push({ type: \"message\", text: result, delta: false, final: true, raw: record });\n }\n\n return events;\n }\n\n const tool = asRecord(record.tool);\n\n switch (stringField(record, \"kind\")) {\n case \"text\": {\n const text = stringField(record, \"text\") ?? \"\";\n\n if (text.length > 0) {\n events.push({ type: \"message\", text, delta: true, raw: record });\n }\n break;\n }\n case \"message\":\n events.push({\n type: \"message\",\n text: stringField(record, \"text\") ?? \"\",\n delta: false,\n raw: record,\n });\n break;\n case \"tool_dispatch\":\n // The first dispatch streams arguments (`partial: true`); report the complete one.\n if (tool !== undefined && tool.partial !== true) {\n events.push({\n type: \"tool.call\",\n id: stringField(tool, \"id\") ?? \"\",\n name: stringField(tool, \"name\") ?? \"\",\n input: parseArguments(tool.args),\n raw: record,\n });\n }\n break;\n case \"tool_result\": {\n const error = stringField(tool, \"err\") ?? \"\";\n\n events.push({\n type: \"tool.result\",\n id: stringField(tool, \"id\") ?? \"\",\n output: error.length > 0 ? error : (stringField(tool, \"output\") ?? \"\"),\n isError: error.length > 0,\n raw: record,\n });\n break;\n }\n case \"usage\": {\n const usage = callUsage(recordField(record, \"usage\"));\n\n if (usage !== undefined) {\n events.push({ type: \"usage\", usage, cumulative: false, raw: record });\n }\n break;\n }\n case \"turn_done\":\n if (stringField(record, \"status\") === \"failed\") {\n events.push({\n type: \"error\",\n message: stringField(record, \"err\") ?? \"Reasonix turn failed\",\n fatal: true,\n raw: record,\n });\n }\n break;\n }\n\n return events;\n }),\n sessionRef: () => sessionRef,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,MAAa,kBAA8B;CACzC,MAAM;CACN,OAAO;CACP,SAAS;CACT,WAAW,CAAC,kBAAkB;CAC9B,SAAS,CAAC;CACV,SAAS,CAAC,eAAe;CACzB,YAAY,CAAC,QAAQ,OAAO;CAC5B,QAAQ;CACR,KAAK;C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IAAI,KAAK;MAC/B,QAAQ,MAAM,SAAS,IAAI,QAAS,YAAY,MAAM,QAAQ,KAAK;MACnE,SAAS,MAAM,SAAS;MACxB,KAAK;KACP,CAAC;KACD;IACF;IACA,KAAK,SAAS;KACZ,MAAM,QAAQ,UAAU,YAAY,QAAQ,OAAO,CAAC;KAEpD,IAAI,UAAU,QACZ,OAAO,KAAK;MAAE,MAAM;MAAS;MAAO,YAAY;MAAO,KAAK;KAAO,CAAC;KAEtE;IACF;IACA,KAAK,aACH,IAAI,YAAY,QAAQ,QAAQ,MAAM,UACpC,OAAO,KAAK;KACV,MAAM;KACN,SAAS,YAAY,QAAQ,KAAK,KAAK;KACvC,OAAO;KACP,KAAK;IACP,CAAC;GAGP;GAEA,OAAO;EACT,CAAC;EACD,kBAAkB;CACpB;AACF"}
|
package/esm/cli-agent.mjs
CHANGED
|
@@ -67,7 +67,7 @@ function createCliAgent(adapter, options = {}, host = currentHost()) {
|
|
|
67
67
|
const probeEnvironment = () => buildEnvironment({
|
|
68
68
|
source: host.env,
|
|
69
69
|
inherit: options.inheritEnv ?? true,
|
|
70
|
-
credentials: adapter.apiKeyEnv,
|
|
70
|
+
credentials: [...adapter.apiKeyEnv, ...adapter.passEnv ?? []],
|
|
71
71
|
managed: [],
|
|
72
72
|
user: options.env,
|
|
73
73
|
platform: host.platform
|
|
@@ -163,7 +163,7 @@ function createCliAgent(adapter, options = {}, host = currentHost()) {
|
|
|
163
163
|
const env = buildEnvironment({
|
|
164
164
|
source: host.env,
|
|
165
165
|
inherit: options.inheritEnv ?? true,
|
|
166
|
-
credentials: adapter.apiKeyEnv,
|
|
166
|
+
credentials: [...adapter.apiKeyEnv, ...adapter.passEnv ?? []],
|
|
167
167
|
managed: home === "inherit" ? [] : adapter.homeEnv,
|
|
168
168
|
plan: host.platform === "win32" ? chosen.plan.env : {
|
|
169
169
|
PWD: cwd,
|
package/esm/cli-agent.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-agent.mjs","names":[],"sources":["../../../../../../../packages/ai-cli/src/cli-agent.ts"],"sourcesContent":["import { accessSync, constants, readFileSync, statSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n CliAdapter,\n CliAgentOptions,\n CliLaunchContext,\n CliLaunchPlan,\n CliProbeResult,\n CliRunOptions,\n CliSession,\n} from \"./contracts\";\nimport type { ModelContract } from \"@warlock.js/ai\";\nimport { CliError } from \"./errors\";\nimport { type CliModelConfig, cliModel } from \"./model/cli-model\";\nimport { assertCapabilities, probeCli } from \"./probe/probe\";\nimport { buildEnvironment, warnInheritedEnvironment } from \"./session/environment\";\nimport { createRunDirectories, writeLaunchFiles } from \"./session/run-directory\";\nimport { cancelledSession, startSession } from \"./session/session\";\nimport { buildInvocation, fitsCommandLine, type Invocation } from \"./spawn/invocation\";\nimport {\n type CommandLookup,\n readEnv,\n resolveSpawnTarget,\n type SpawnTarget,\n} from \"./spawn/resolve-command\";\n\n/** A configured coding CLI: run prompts, probe the binary, or use it as an `ai.agent` model. */\nexport type CliAgent = {\n readonly adapter: CliAdapter;\n readonly options: Readonly<CliAgentOptions>;\n /**\n * Start a session. Rejects (with {@link CliError}) only for setup problems\n * — executable not found, a flag missing from `--help`, an unsupported\n * option; the run's own outcome is reported by `session.done()`.\n */\n run(prompt: string, options?: CliRunOptions): Promise<CliSession>;\n /** Run (or reuse) the capability probe: resolved executable, version and help text. */\n probe(): Promise<CliProbeResult>;\n /** This CLI as an `ai.agent` model (see {@link cliModel}). */\n model(config?: CliModelConfig): ModelContract;\n};\n\n/** Host facts, injectable for tests. */\nexport type CliHost = CommandLookup & { comspec: string };\n\nfunction isRunnableFile(filePath: string, platform: NodeJS.Platform): boolean {\n try {\n if (!statSync(filePath).isFile()) {\n return false;\n }\n\n if (platform !== \"win32\") {\n accessSync(filePath, constants.X_OK);\n }\n\n return true;\n } catch {\n return false;\n }\n}\n\n/** The current machine as a {@link CliHost}. */\nexport function currentHost(): CliHost {\n const platform = process.platform;\n\n return {\n platform,\n env: process.env,\n isFile: (filePath) => isRunnableFile(filePath, platform),\n readFile: (filePath) => {\n try {\n return readFileSync(filePath, \"utf8\");\n } catch {\n return undefined;\n }\n },\n execPath: process.execPath,\n comspec: readEnv(process.env, \"ComSpec\", platform) ?? \"cmd.exe\",\n };\n}\n\nfunction unsupported(adapter: CliAdapter, message: string): CliError {\n return new CliError(`${adapter.title}: ${message}`, {\n type: \"unsupported-option\",\n adapter: adapter.name,\n });\n}\n\n/**\n * Create a CLI agent from an adapter. The vendor factories\n * (`cli.claudeCode(...)`, `cli.codex(...)`, …) call this with their\n * built-in adapter; call it directly with your own {@link CliAdapter}.\n *\n * @example\n * const agent = createCliAgent(myAdapter, { model: \"fast\", permission: \"standard\" });\n * const session = await agent.run(\"Summarize README.md\", { cwd: \"/srv/repo\" });\n * console.log((await session.done()).text);\n */\nexport function createCliAgent(\n adapter: CliAdapter,\n options: CliAgentOptions = {},\n host: CliHost = currentHost(),\n): CliAgent {\n const probes = new Map<string, Promise<CliProbeResult>>();\n const command = options.command ?? adapter.command;\n\n const resolveTarget = (): SpawnTarget => {\n const target = resolveSpawnTarget(command, host);\n\n if (target === undefined) {\n throw new CliError(\n `${adapter.title}: could not find \"${command}\" on PATH. Install the CLI or pass its absolute path as \\`command\\`.`,\n { type: \"not-found\", adapter: adapter.name },\n );\n }\n\n return target;\n };\n\n const probeEnvironment = (): Record<string, string> =>\n buildEnvironment({\n source: host.env,\n inherit: options.inheritEnv ?? true,\n credentials: adapter.apiKeyEnv,\n managed: [],\n user: options.env,\n platform: host.platform,\n });\n\n const probeTarget = (target: SpawnTarget): Promise<CliProbeResult> => {\n const cached = probes.get(target.executable);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const pending = probeCli({\n adapter,\n target,\n env: probeEnvironment(),\n cwd: path.resolve(options.cwd ?? process.cwd()),\n comspec: host.comspec,\n platform: host.platform,\n });\n\n probes.set(target.executable, pending);\n // A failed probe is retried on the next run instead of being cached.\n pending.catch(() => probes.delete(target.executable));\n\n return pending;\n };\n\n const run = async (prompt: string, runOptions: CliRunOptions = {}): Promise<CliSession> => {\n const merged: CliRunOptions = {\n ...options,\n ...runOptions,\n env: { ...options.env, ...runOptions.env },\n args: [...(options.args ?? []), ...(runOptions.args ?? [])],\n mcp: runOptions.mcp ?? options.mcp,\n };\n const permission = merged.permission ?? \"standard\";\n\n if (permission !== \"standard\" && permission !== \"bypass\") {\n throw unsupported(\n adapter,\n `unknown permission \"${String(permission)}\" (use \"standard\" or \"bypass\").`,\n );\n }\n\n if (merged.effort !== undefined && adapter.effort !== true) {\n throw unsupported(adapter, \"this CLI has no reasoning-effort control; drop `effort`.\");\n }\n\n const mcp =\n merged.mcp !== undefined && Object.keys(merged.mcp).length > 0 ? merged.mcp : undefined;\n\n if (mcp !== undefined && adapter.mcp !== true) {\n throw unsupported(adapter, \"this CLI cannot attach per-run MCP servers; drop `mcp`.\");\n }\n\n if (merged.apiKey !== undefined && adapter.apiKeyEnv.length === 0) {\n throw unsupported(adapter, \"this CLI reads no API key from the environment; drop `apiKey`.\");\n }\n\n const home = options.home ?? \"private\";\n\n if (home !== \"inherit\" && adapter.homeEnv.length === 0) {\n throw unsupported(\n adapter,\n 'this CLI cannot relocate its config home; use `home: \"inherit\"`.',\n );\n }\n\n const cwd = path.resolve(merged.cwd ?? process.cwd());\n const target = resolveTarget();\n const probe = options.probe === false ? undefined : await probeTarget(target);\n\n if (merged.signal?.aborted) {\n return cancelledSession(adapter.name, merged.resume);\n }\n\n const directories = await createRunDirectories(home, cwd);\n\n try {\n let chosen:\n | { plan: CliLaunchPlan; invocation: Invocation; context: CliLaunchContext }\n | undefined;\n const reasons: string[] = [];\n\n for (const transport of adapter.transports) {\n const context: CliLaunchContext = {\n prompt,\n transport,\n cwd,\n model: merged.model,\n effort: merged.effort,\n permission,\n resume: merged.resume,\n mcp,\n apiKey: merged.apiKey,\n home: directories.home,\n homeIsPrivate: directories.homeIsPrivate,\n runDir: directories.runDir,\n platform: host.platform,\n };\n const plan = adapter.plan(context);\n\n if (probe !== undefined) {\n assertCapabilities(adapter, probe, plan.requires);\n }\n\n const invocation = buildInvocation(\n target,\n [...plan.args, ...(merged.args ?? []), ...(plan.tail ?? [])],\n host.comspec,\n );\n\n if (\"refused\" in invocation) {\n reasons.push(`${transport}: ${invocation.refused}`);\n continue;\n }\n\n if (!fitsCommandLine(invocation, host.platform)) {\n reasons.push(`${transport}: the command line exceeds the platform limit`);\n continue;\n }\n\n chosen = { plan, invocation, context };\n break;\n }\n\n if (chosen === undefined) {\n throw new CliError(\n `${adapter.title}: the prompt cannot be passed to \"${target.executable}\" (${reasons.join(\"; \")}).`,\n { type: \"prompt-transport\", adapter: adapter.name, executable: target.executable },\n );\n }\n\n await writeLaunchFiles(chosen.plan.files ?? [], directories);\n\n const apiKeyEnv = adapter.apiKeyEnv[0];\n warnInheritedEnvironment(adapter.title, options.inheritEnv, host.env);\n const env = buildEnvironment({\n source: host.env,\n inherit: options.inheritEnv ?? true,\n credentials: adapter.apiKeyEnv,\n managed: home === \"inherit\" ? [] : adapter.homeEnv,\n // A CLI that prefers $PWD over its real cwd must not see the host's.\n plan: host.platform === \"win32\" ? chosen.plan.env : { PWD: cwd, ...chosen.plan.env },\n user: merged.env,\n apiKey:\n merged.apiKey !== undefined && apiKeyEnv !== undefined\n ? { name: apiKeyEnv, value: merged.apiKey }\n : undefined,\n platform: host.platform,\n });\n\n return startSession({\n adapter: adapter.name,\n invocation: chosen.invocation,\n cwd,\n env,\n stdin: chosen.plan.stdin,\n parser: adapter.parser(chosen.context),\n signal: merged.signal,\n timeoutMs: merged.timeoutMs,\n killGraceMs: options.killGraceMs ?? 2000,\n platform: host.platform,\n resume: merged.resume,\n cleanup: directories.dispose,\n });\n } catch (error) {\n await directories.dispose();\n throw error;\n }\n };\n\n const agent: CliAgent = {\n adapter,\n options,\n run,\n probe: () => probeTarget(resolveTarget()),\n model: (config) => cliModel(agent, config),\n };\n\n return agent;\n}\n"],"mappings":";;;;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AC3B,QAAQ,KAAK;IACb,SAAS,QAAQ,cAAc;IAC/B,aAAa,QAAQ;IACrB,SAAS,SAAS,YAAY,CAAC,IAAI,QAAQ;IAE3C,MAAM,KAAK,aAAa,UAAU,OAAO,KAAK,MAAM;KAAE,KAAK;KAAK,GAAG,OAAO,KAAK;IAAI;IACnF,MAAM,OAAO;IACb,QACE,OAAO,WAAW,UAAa,cAAc,SACzC;KAAE,MAAM;KAAW,OAAO,OAAO;IAAO,IACxC;IACN,UAAU,KAAK;GACjB,CAAC;GAED,OAAO,aAAa;IAClB,SAAS,QAAQ;IACjB,YAAY,OAAO;IACnB;IACA;IACA,OAAO,OAAO,KAAK;IACnB,QAAQ,QAAQ,OAAO,OAAO,OAAO;IACrC,QAAQ,OAAO;IACf,WAAW,OAAO;IAClB,aAAa,QAAQ,eAAe;IACpC,UAAU,KAAK;IACf,QAAQ,OAAO;IACf,SAAS,YAAY;GACvB,CAAC;EACH,SAAS,OAAO;GACd,MAAM,YAAY,QAAQ;GAC1B,MAAM;EACR;CACF;CAEA,MAAM,QAAkB;EACtB;EACA;EACA;EACA,aAAa,YAAY,cAAc,CAAC;EACxC,QAAQ,WAAW,SAAS,OAAO,MAAM;CAC3C;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"cli-agent.mjs","names":[],"sources":["../../../../../../../packages/ai-cli/src/cli-agent.ts"],"sourcesContent":["import { accessSync, constants, readFileSync, statSync } from \"node:fs\";\nimport path from \"node:path\";\nimport type {\n CliAdapter,\n CliAgentOptions,\n CliLaunchContext,\n CliLaunchPlan,\n CliProbeResult,\n CliRunOptions,\n CliSession,\n} from \"./contracts\";\nimport type { ModelContract } from \"@warlock.js/ai\";\nimport { CliError } from \"./errors\";\nimport { type CliModelConfig, cliModel } from \"./model/cli-model\";\nimport { assertCapabilities, probeCli } from \"./probe/probe\";\nimport { buildEnvironment, warnInheritedEnvironment } from \"./session/environment\";\nimport { createRunDirectories, writeLaunchFiles } from \"./session/run-directory\";\nimport { cancelledSession, startSession } from \"./session/session\";\nimport { buildInvocation, fitsCommandLine, type Invocation } from \"./spawn/invocation\";\nimport {\n type CommandLookup,\n readEnv,\n resolveSpawnTarget,\n type SpawnTarget,\n} from \"./spawn/resolve-command\";\n\n/** A configured coding CLI: run prompts, probe the binary, or use it as an `ai.agent` model. */\nexport type CliAgent = {\n readonly adapter: CliAdapter;\n readonly options: Readonly<CliAgentOptions>;\n /**\n * Start a session. Rejects (with {@link CliError}) only for setup problems\n * — executable not found, a flag missing from `--help`, an unsupported\n * option; the run's own outcome is reported by `session.done()`.\n */\n run(prompt: string, options?: CliRunOptions): Promise<CliSession>;\n /** Run (or reuse) the capability probe: resolved executable, version and help text. */\n probe(): Promise<CliProbeResult>;\n /** This CLI as an `ai.agent` model (see {@link cliModel}). */\n model(config?: CliModelConfig): ModelContract;\n};\n\n/** Host facts, injectable for tests. */\nexport type CliHost = CommandLookup & { comspec: string };\n\nfunction isRunnableFile(filePath: string, platform: NodeJS.Platform): boolean {\n try {\n if (!statSync(filePath).isFile()) {\n return false;\n }\n\n if (platform !== \"win32\") {\n accessSync(filePath, constants.X_OK);\n }\n\n return true;\n } catch {\n return false;\n }\n}\n\n/** The current machine as a {@link CliHost}. */\nexport function currentHost(): CliHost {\n const platform = process.platform;\n\n return {\n platform,\n env: process.env,\n isFile: (filePath) => isRunnableFile(filePath, platform),\n readFile: (filePath) => {\n try {\n return readFileSync(filePath, \"utf8\");\n } catch {\n return undefined;\n }\n },\n execPath: process.execPath,\n comspec: readEnv(process.env, \"ComSpec\", platform) ?? \"cmd.exe\",\n };\n}\n\nfunction unsupported(adapter: CliAdapter, message: string): CliError {\n return new CliError(`${adapter.title}: ${message}`, {\n type: \"unsupported-option\",\n adapter: adapter.name,\n });\n}\n\n/**\n * Create a CLI agent from an adapter. The vendor factories\n * (`cli.claudeCode(...)`, `cli.codex(...)`, …) call this with their\n * built-in adapter; call it directly with your own {@link CliAdapter}.\n *\n * @example\n * const agent = createCliAgent(myAdapter, { model: \"fast\", permission: \"standard\" });\n * const session = await agent.run(\"Summarize README.md\", { cwd: \"/srv/repo\" });\n * console.log((await session.done()).text);\n */\nexport function createCliAgent(\n adapter: CliAdapter,\n options: CliAgentOptions = {},\n host: CliHost = currentHost(),\n): CliAgent {\n const probes = new Map<string, Promise<CliProbeResult>>();\n const command = options.command ?? adapter.command;\n\n const resolveTarget = (): SpawnTarget => {\n const target = resolveSpawnTarget(command, host);\n\n if (target === undefined) {\n throw new CliError(\n `${adapter.title}: could not find \"${command}\" on PATH. Install the CLI or pass its absolute path as \\`command\\`.`,\n { type: \"not-found\", adapter: adapter.name },\n );\n }\n\n return target;\n };\n\n const probeEnvironment = (): Record<string, string> =>\n buildEnvironment({\n source: host.env,\n inherit: options.inheritEnv ?? true,\n credentials: [...adapter.apiKeyEnv, ...(adapter.passEnv ?? [])],\n managed: [],\n user: options.env,\n platform: host.platform,\n });\n\n const probeTarget = (target: SpawnTarget): Promise<CliProbeResult> => {\n const cached = probes.get(target.executable);\n\n if (cached !== undefined) {\n return cached;\n }\n\n const pending = probeCli({\n adapter,\n target,\n env: probeEnvironment(),\n cwd: path.resolve(options.cwd ?? process.cwd()),\n comspec: host.comspec,\n platform: host.platform,\n });\n\n probes.set(target.executable, pending);\n // A failed probe is retried on the next run instead of being cached.\n pending.catch(() => probes.delete(target.executable));\n\n return pending;\n };\n\n const run = async (prompt: string, runOptions: CliRunOptions = {}): Promise<CliSession> => {\n const merged: CliRunOptions = {\n ...options,\n ...runOptions,\n env: { ...options.env, ...runOptions.env },\n args: [...(options.args ?? []), ...(runOptions.args ?? [])],\n mcp: runOptions.mcp ?? options.mcp,\n };\n const permission = merged.permission ?? \"standard\";\n\n if (permission !== \"standard\" && permission !== \"bypass\") {\n throw unsupported(\n adapter,\n `unknown permission \"${String(permission)}\" (use \"standard\" or \"bypass\").`,\n );\n }\n\n if (merged.effort !== undefined && adapter.effort !== true) {\n throw unsupported(adapter, \"this CLI has no reasoning-effort control; drop `effort`.\");\n }\n\n const mcp =\n merged.mcp !== undefined && Object.keys(merged.mcp).length > 0 ? merged.mcp : undefined;\n\n if (mcp !== undefined && adapter.mcp !== true) {\n throw unsupported(adapter, \"this CLI cannot attach per-run MCP servers; drop `mcp`.\");\n }\n\n if (merged.apiKey !== undefined && adapter.apiKeyEnv.length === 0) {\n throw unsupported(adapter, \"this CLI reads no API key from the environment; drop `apiKey`.\");\n }\n\n const home = options.home ?? \"private\";\n\n if (home !== \"inherit\" && adapter.homeEnv.length === 0) {\n throw unsupported(\n adapter,\n 'this CLI cannot relocate its config home; use `home: \"inherit\"`.',\n );\n }\n\n const cwd = path.resolve(merged.cwd ?? process.cwd());\n const target = resolveTarget();\n const probe = options.probe === false ? undefined : await probeTarget(target);\n\n if (merged.signal?.aborted) {\n return cancelledSession(adapter.name, merged.resume);\n }\n\n const directories = await createRunDirectories(home, cwd);\n\n try {\n let chosen:\n | { plan: CliLaunchPlan; invocation: Invocation; context: CliLaunchContext }\n | undefined;\n const reasons: string[] = [];\n\n for (const transport of adapter.transports) {\n const context: CliLaunchContext = {\n prompt,\n transport,\n cwd,\n model: merged.model,\n effort: merged.effort,\n permission,\n resume: merged.resume,\n mcp,\n apiKey: merged.apiKey,\n home: directories.home,\n homeIsPrivate: directories.homeIsPrivate,\n runDir: directories.runDir,\n platform: host.platform,\n };\n const plan = adapter.plan(context);\n\n if (probe !== undefined) {\n assertCapabilities(adapter, probe, plan.requires);\n }\n\n const invocation = buildInvocation(\n target,\n [...plan.args, ...(merged.args ?? []), ...(plan.tail ?? [])],\n host.comspec,\n );\n\n if (\"refused\" in invocation) {\n reasons.push(`${transport}: ${invocation.refused}`);\n continue;\n }\n\n if (!fitsCommandLine(invocation, host.platform)) {\n reasons.push(`${transport}: the command line exceeds the platform limit`);\n continue;\n }\n\n chosen = { plan, invocation, context };\n break;\n }\n\n if (chosen === undefined) {\n throw new CliError(\n `${adapter.title}: the prompt cannot be passed to \"${target.executable}\" (${reasons.join(\"; \")}).`,\n { type: \"prompt-transport\", adapter: adapter.name, executable: target.executable },\n );\n }\n\n await writeLaunchFiles(chosen.plan.files ?? [], directories);\n\n const apiKeyEnv = adapter.apiKeyEnv[0];\n warnInheritedEnvironment(adapter.title, options.inheritEnv, host.env);\n const env = buildEnvironment({\n source: host.env,\n inherit: options.inheritEnv ?? true,\n credentials: [...adapter.apiKeyEnv, ...(adapter.passEnv ?? [])],\n managed: home === \"inherit\" ? [] : adapter.homeEnv,\n // A CLI that prefers $PWD over its real cwd must not see the host's.\n plan: host.platform === \"win32\" ? chosen.plan.env : { PWD: cwd, ...chosen.plan.env },\n user: merged.env,\n apiKey:\n merged.apiKey !== undefined && apiKeyEnv !== undefined\n ? { name: apiKeyEnv, value: merged.apiKey }\n : undefined,\n platform: host.platform,\n });\n\n return startSession({\n adapter: adapter.name,\n invocation: chosen.invocation,\n cwd,\n env,\n stdin: chosen.plan.stdin,\n parser: adapter.parser(chosen.context),\n signal: merged.signal,\n timeoutMs: merged.timeoutMs,\n killGraceMs: options.killGraceMs ?? 2000,\n platform: host.platform,\n resume: merged.resume,\n cleanup: directories.dispose,\n });\n } catch (error) {\n await directories.dispose();\n throw error;\n }\n };\n\n const agent: CliAgent = {\n adapter,\n options,\n run,\n probe: () => probeTarget(resolveTarget()),\n model: (config) => cliModel(agent, config),\n };\n\n return agent;\n}\n"],"mappings":";;;;;;;;;;;;AA6CA,SAAS,eAAe,UAAkB,UAAoC;CAC5E,IAAI;EACF,IAAI,CAAC,SAAS,QAAQ,CAAC,CAAC,OAAO,GAC7B,OAAO;EAGT,IAAI,aAAa,SACf,WAAW,UAAU,UAAU,IAAI;EAGrC,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;AAGA,SAAgB,cAAuB;CACrC,MAAM,WAAW,QAAQ;CAEzB,OAAO;EACL;EACA,KAAK,QAAQ;EACb,SAAS,aAAa,eAAe,UAAU,QAAQ;EACvD,WAAW,aAAa;GACtB,IAAI;IACF,OAAO,aAAa,UAAU,MAAM;GACtC,QA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C;IACN,UAAU,KAAK;GACjB,CAAC;GAED,OAAO,aAAa;IAClB,SAAS,QAAQ;IACjB,YAAY,OAAO;IACnB;IACA;IACA,OAAO,OAAO,KAAK;IACnB,QAAQ,QAAQ,OAAO,OAAO,OAAO;IACrC,QAAQ,OAAO;IACf,WAAW,OAAO;IAClB,aAAa,QAAQ,eAAe;IACpC,UAAU,KAAK;IACf,QAAQ,OAAO;IACf,SAAS,YAAY;GACvB,CAAC;EACH,SAAS,OAAO;GACd,MAAM,YAAY,QAAQ;GAC1B,MAAM;EACR;CACF;CAEA,MAAM,QAAkB;EACtB;EACA;EACA;EACA,aAAa,YAAY,cAAc,CAAC;EACxC,QAAQ,WAAW,SAAS,OAAO,MAAM;CAC3C;CAEA,OAAO;AACT"}
|
|
@@ -149,6 +149,12 @@ export type CliAdapter = {
|
|
|
149
149
|
readonly command: string;
|
|
150
150
|
/** Environment variables that receive an API key (the first is used for the `apiKey` option). */
|
|
151
151
|
readonly apiKeyEnv: readonly string[];
|
|
152
|
+
/**
|
|
153
|
+
* Further variables the CLI reads to work (base URLs, provider keys, auth
|
|
154
|
+
* tokens other than `apiKeyEnv`). `inheritEnv: "curated"` passes them from
|
|
155
|
+
* the host together with `apiKeyEnv`; nothing else from the host reaches the CLI.
|
|
156
|
+
*/
|
|
157
|
+
readonly passEnv?: readonly string[];
|
|
152
158
|
/**
|
|
153
159
|
* Environment variables pointed at the config home. Empty when the CLI
|
|
154
160
|
* cannot relocate its config, in which case `home` other than `"inherit"`
|