@warlock.js/ai-cli 0.0.0-stage → 5.31.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.
Files changed (139) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +21 -0
  3. package/README.md +69 -2
  4. package/cjs/index.cjs +4576 -0
  5. package/cjs/index.cjs.map +1 -0
  6. package/esm/adapters/aider.d.mts +41 -0
  7. package/esm/adapters/aider.d.mts.map +1 -0
  8. package/esm/adapters/aider.mjs +294 -0
  9. package/esm/adapters/aider.mjs.map +1 -0
  10. package/esm/adapters/amp.d.mts +33 -0
  11. package/esm/adapters/amp.d.mts.map +1 -0
  12. package/esm/adapters/amp.mjs +119 -0
  13. package/esm/adapters/amp.mjs.map +1 -0
  14. package/esm/adapters/antigravity.d.mts +37 -0
  15. package/esm/adapters/antigravity.d.mts.map +1 -0
  16. package/esm/adapters/antigravity.mjs +235 -0
  17. package/esm/adapters/antigravity.mjs.map +1 -0
  18. package/esm/adapters/claude-code.d.mts +30 -0
  19. package/esm/adapters/claude-code.d.mts.map +1 -0
  20. package/esm/adapters/claude-code.mjs +121 -0
  21. package/esm/adapters/claude-code.mjs.map +1 -0
  22. package/esm/adapters/claude-stream.d.mts +32 -0
  23. package/esm/adapters/claude-stream.d.mts.map +1 -0
  24. package/esm/adapters/claude-stream.mjs +140 -0
  25. package/esm/adapters/claude-stream.mjs.map +1 -0
  26. package/esm/adapters/codex.d.mts +37 -0
  27. package/esm/adapters/codex.d.mts.map +1 -0
  28. package/esm/adapters/codex.mjs +320 -0
  29. package/esm/adapters/codex.mjs.map +1 -0
  30. package/esm/adapters/copilot.d.mts +35 -0
  31. package/esm/adapters/copilot.d.mts.map +1 -0
  32. package/esm/adapters/copilot.mjs +244 -0
  33. package/esm/adapters/copilot.mjs.map +1 -0
  34. package/esm/adapters/cursor.d.mts +35 -0
  35. package/esm/adapters/cursor.d.mts.map +1 -0
  36. package/esm/adapters/cursor.mjs +203 -0
  37. package/esm/adapters/cursor.mjs.map +1 -0
  38. package/esm/adapters/droid.d.mts +32 -0
  39. package/esm/adapters/droid.d.mts.map +1 -0
  40. package/esm/adapters/droid.mjs +183 -0
  41. package/esm/adapters/droid.mjs.map +1 -0
  42. package/esm/adapters/grok.d.mts +32 -0
  43. package/esm/adapters/grok.d.mts.map +1 -0
  44. package/esm/adapters/grok.mjs +199 -0
  45. package/esm/adapters/grok.mjs.map +1 -0
  46. package/esm/adapters/index.d.mts +16 -0
  47. package/esm/adapters/index.mjs +18 -0
  48. package/esm/adapters/kimi.d.mts +34 -0
  49. package/esm/adapters/kimi.d.mts.map +1 -0
  50. package/esm/adapters/kimi.mjs +162 -0
  51. package/esm/adapters/kimi.mjs.map +1 -0
  52. package/esm/adapters/mistral-vibe.d.mts +32 -0
  53. package/esm/adapters/mistral-vibe.d.mts.map +1 -0
  54. package/esm/adapters/mistral-vibe.mjs +252 -0
  55. package/esm/adapters/mistral-vibe.mjs.map +1 -0
  56. package/esm/adapters/opencode.d.mts +36 -0
  57. package/esm/adapters/opencode.d.mts.map +1 -0
  58. package/esm/adapters/opencode.mjs +219 -0
  59. package/esm/adapters/opencode.mjs.map +1 -0
  60. package/esm/adapters/qwen-code.d.mts +30 -0
  61. package/esm/adapters/qwen-code.d.mts.map +1 -0
  62. package/esm/adapters/qwen-code.mjs +94 -0
  63. package/esm/adapters/qwen-code.mjs.map +1 -0
  64. package/esm/adapters/reasonix.d.mts +31 -0
  65. package/esm/adapters/reasonix.d.mts.map +1 -0
  66. package/esm/adapters/reasonix.mjs +250 -0
  67. package/esm/adapters/reasonix.mjs.map +1 -0
  68. package/esm/adapters/shared.d.mts +78 -0
  69. package/esm/adapters/shared.d.mts.map +1 -0
  70. package/esm/adapters/shared.mjs +161 -0
  71. package/esm/adapters/shared.mjs.map +1 -0
  72. package/esm/cli-agent.d.mts +40 -0
  73. package/esm/cli-agent.d.mts.map +1 -0
  74. package/esm/cli-agent.mjs +207 -0
  75. package/esm/cli-agent.mjs.map +1 -0
  76. package/esm/cli.d.mts +53 -0
  77. package/esm/cli.d.mts.map +1 -0
  78. package/esm/cli.mjs +61 -0
  79. package/esm/cli.mjs.map +1 -0
  80. package/esm/contracts/adapter.contract.d.mts +154 -0
  81. package/esm/contracts/adapter.contract.d.mts.map +1 -0
  82. package/esm/contracts/events.type.d.mts +111 -0
  83. package/esm/contracts/events.type.d.mts.map +1 -0
  84. package/esm/contracts/index.d.mts +4 -0
  85. package/esm/contracts/mcp.type.d.mts +29 -0
  86. package/esm/contracts/mcp.type.d.mts.map +1 -0
  87. package/esm/contracts/options.type.d.mts +87 -0
  88. package/esm/contracts/options.type.d.mts.map +1 -0
  89. package/esm/errors.d.mts +46 -0
  90. package/esm/errors.d.mts.map +1 -0
  91. package/esm/errors.mjs +32 -0
  92. package/esm/errors.mjs.map +1 -0
  93. package/esm/index.d.mts +31 -0
  94. package/esm/index.mjs +28 -0
  95. package/esm/model/cli-model.d.mts +48 -0
  96. package/esm/model/cli-model.d.mts.map +1 -0
  97. package/esm/model/cli-model.mjs +133 -0
  98. package/esm/model/cli-model.mjs.map +1 -0
  99. package/esm/probe/probe.d.mts +18 -0
  100. package/esm/probe/probe.d.mts.map +1 -0
  101. package/esm/probe/probe.mjs +148 -0
  102. package/esm/probe/probe.mjs.map +1 -0
  103. package/esm/session/aggregate.mjs +86 -0
  104. package/esm/session/aggregate.mjs.map +1 -0
  105. package/esm/session/environment.mjs +71 -0
  106. package/esm/session/environment.mjs.map +1 -0
  107. package/esm/session/run-directory.mjs +74 -0
  108. package/esm/session/run-directory.mjs.map +1 -0
  109. package/esm/session/session.mjs +188 -0
  110. package/esm/session/session.mjs.map +1 -0
  111. package/esm/spawn/invocation.d.mts +35 -0
  112. package/esm/spawn/invocation.d.mts.map +1 -0
  113. package/esm/spawn/invocation.mjs +76 -0
  114. package/esm/spawn/invocation.mjs.map +1 -0
  115. package/esm/spawn/process-tree.mjs +57 -0
  116. package/esm/spawn/process-tree.mjs.map +1 -0
  117. package/esm/spawn/resolve-command.d.mts +73 -0
  118. package/esm/spawn/resolve-command.d.mts.map +1 -0
  119. package/esm/spawn/resolve-command.mjs +109 -0
  120. package/esm/spawn/resolve-command.mjs.map +1 -0
  121. package/esm/stream/event-log.mjs +52 -0
  122. package/esm/stream/event-log.mjs.map +1 -0
  123. package/esm/stream/json-lines.d.mts +33 -0
  124. package/esm/stream/json-lines.d.mts.map +1 -0
  125. package/esm/stream/json-lines.mjs +65 -0
  126. package/esm/stream/json-lines.mjs.map +1 -0
  127. package/esm/stream/line-splitter.mjs +53 -0
  128. package/esm/stream/line-splitter.mjs.map +1 -0
  129. package/esm/utils/toml.d.mts +22 -0
  130. package/esm/utils/toml.d.mts.map +1 -0
  131. package/esm/utils/toml.mjs +53 -0
  132. package/esm/utils/toml.mjs.map +1 -0
  133. package/llms-full.txt +373 -0
  134. package/llms.txt +10 -0
  135. package/package.json +39 -4
  136. package/skills/README.md +13 -0
  137. package/skills/index.md +22 -0
  138. package/skills/run-cli-agents/SKILL.md +186 -0
  139. package/skills/write-a-cli-adapter/SKILL.md +173 -0
package/esm/cli.mjs ADDED
@@ -0,0 +1,61 @@
1
+ import { cliModel } from "./model/cli-model.mjs";
2
+ import { createCliAgent } from "./cli-agent.mjs";
3
+ import { aiderAdapter } from "./adapters/aider.mjs";
4
+ import { ampAdapter } from "./adapters/amp.mjs";
5
+ import { antigravityAdapter } from "./adapters/antigravity.mjs";
6
+ import { claudeCodeAdapter } from "./adapters/claude-code.mjs";
7
+ import { codexAdapter } from "./adapters/codex.mjs";
8
+ import { copilotAdapter } from "./adapters/copilot.mjs";
9
+ import { cursorAdapter } from "./adapters/cursor.mjs";
10
+ import { droidAdapter } from "./adapters/droid.mjs";
11
+ import { grokAdapter } from "./adapters/grok.mjs";
12
+ import { kimiAdapter } from "./adapters/kimi.mjs";
13
+ import { mistralVibeAdapter } from "./adapters/mistral-vibe.mjs";
14
+ import { opencodeAdapter } from "./adapters/opencode.mjs";
15
+ import { qwenCodeAdapter } from "./adapters/qwen-code.mjs";
16
+ import { reasonixAdapter } from "./adapters/reasonix.mjs";
17
+ import { ai } from "@warlock.js/ai";
18
+
19
+ //#region ../../packages/ai-cli/src/cli.ts
20
+ /** Every built-in adapter, keyed by its factory name. */
21
+ const cliAdapters = {
22
+ claudeCode: claudeCodeAdapter,
23
+ codex: codexAdapter,
24
+ antigravity: antigravityAdapter,
25
+ qwenCode: qwenCodeAdapter,
26
+ kimi: kimiAdapter,
27
+ cursor: cursorAdapter,
28
+ copilot: copilotAdapter,
29
+ grok: grokAdapter,
30
+ opencode: opencodeAdapter,
31
+ amp: ampAdapter,
32
+ droid: droidAdapter,
33
+ mistralVibe: mistralVibeAdapter,
34
+ aider: aiderAdapter,
35
+ reasonix: reasonixAdapter
36
+ };
37
+ const factories = Object.fromEntries(Object.entries(cliAdapters).map(([vendor, adapter]) => [vendor, (options) => createCliAgent(adapter, options)]));
38
+ /**
39
+ * The CLI-agent namespace: one factory per vendor, `custom()` for your own
40
+ * adapter, `model()` to hand a CLI agent to `ai.agent`. Also available as
41
+ * `ai.cli` once the package is imported.
42
+ *
43
+ * @example
44
+ * import { cli } from "@warlock.js/ai-cli";
45
+ *
46
+ * const claude = cli.claudeCode({ model: "sonnet", cwd: "/srv/repo" });
47
+ * const session = await claude.run("Fix the failing test");
48
+ * for await (const event of session.events) console.log(event.type);
49
+ * const { text, usage, sessionRef } = await session.done();
50
+ */
51
+ const cli = {
52
+ ...factories,
53
+ custom: (adapter, options) => createCliAgent(adapter, options),
54
+ model: cliModel,
55
+ adapters: cliAdapters
56
+ };
57
+ ai.cli = cli;
58
+
59
+ //#endregion
60
+ export { cli, cliAdapters };
61
+ //# sourceMappingURL=cli.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.mjs","names":[],"sources":["../../../../../../../packages/ai-cli/src/cli.ts"],"sourcesContent":["import { ai } from \"@warlock.js/ai\";\nimport { aiderAdapter } from \"./adapters/aider\";\nimport { ampAdapter } from \"./adapters/amp\";\nimport { antigravityAdapter } from \"./adapters/antigravity\";\nimport { claudeCodeAdapter } from \"./adapters/claude-code\";\nimport { codexAdapter } from \"./adapters/codex\";\nimport { copilotAdapter } from \"./adapters/copilot\";\nimport { cursorAdapter } from \"./adapters/cursor\";\nimport { droidAdapter } from \"./adapters/droid\";\nimport { grokAdapter } from \"./adapters/grok\";\nimport { kimiAdapter } from \"./adapters/kimi\";\nimport { mistralVibeAdapter } from \"./adapters/mistral-vibe\";\nimport { opencodeAdapter } from \"./adapters/opencode\";\nimport { qwenCodeAdapter } from \"./adapters/qwen-code\";\nimport { reasonixAdapter } from \"./adapters/reasonix\";\nimport { type CliAgent, createCliAgent } from \"./cli-agent\";\nimport type { CliAdapter, CliAgentOptions } from \"./contracts\";\nimport { cliModel } from \"./model/cli-model\";\n\n/** Every built-in adapter, keyed by its factory name. */\nexport const cliAdapters = {\n claudeCode: claudeCodeAdapter,\n codex: codexAdapter,\n antigravity: antigravityAdapter,\n qwenCode: qwenCodeAdapter,\n kimi: kimiAdapter,\n cursor: cursorAdapter,\n copilot: copilotAdapter,\n grok: grokAdapter,\n opencode: opencodeAdapter,\n amp: ampAdapter,\n droid: droidAdapter,\n mistralVibe: mistralVibeAdapter,\n aider: aiderAdapter,\n reasonix: reasonixAdapter,\n} as const;\n\n/** Name of a built-in adapter factory. */\nexport type CliVendor = keyof typeof cliAdapters;\n\ntype VendorFactories = { [Vendor in CliVendor]: (options?: CliAgentOptions) => CliAgent };\n\nconst factories = Object.fromEntries(\n Object.entries(cliAdapters).map(([vendor, adapter]) => [\n vendor,\n (options?: CliAgentOptions) => createCliAgent(adapter, options),\n ]),\n) as VendorFactories;\n\n/**\n * The CLI-agent namespace: one factory per vendor, `custom()` for your own\n * adapter, `model()` to hand a CLI agent to `ai.agent`. Also available as\n * `ai.cli` once the package is imported.\n *\n * @example\n * import { cli } from \"@warlock.js/ai-cli\";\n *\n * const claude = cli.claudeCode({ model: \"sonnet\", cwd: \"/srv/repo\" });\n * const session = await claude.run(\"Fix the failing test\");\n * for await (const event of session.events) console.log(event.type);\n * const { text, usage, sessionRef } = await session.done();\n */\nexport const cli: VendorFactories & {\n /** A CLI agent for an adapter you wrote. */\n custom(adapter: CliAdapter, options?: CliAgentOptions): CliAgent;\n /** A CLI agent as an `ai.agent` model. */\n model: typeof cliModel;\n /** The built-in adapters, for inspection or extension. */\n adapters: typeof cliAdapters;\n} = {\n ...factories,\n custom: (adapter, options) => createCliAgent(adapter, options),\n model: cliModel,\n adapters: cliAdapters,\n};\n\ndeclare module \"@warlock.js/ai\" {\n interface Ai {\n /** Drive vendor coding CLIs (Claude Code, Codex, Copilot, …) as agents. */\n cli: typeof cli;\n }\n}\n\n// Runtime registration: importing the package attaches `cli` to the shared `ai` object.\nai.cli = cli;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,cAAc;CACzB,YAAY;CACZ,OAAO;CACP,aAAa;CACb,UAAU;CACV,MAAM;CACN,QAAQ;CACR,SAAS;CACT,MAAM;CACN,UAAU;CACV,KAAK;CACL,OAAO;CACP,aAAa;CACb,OAAO;CACP,UAAU;AACZ;AAOA,MAAM,YAAY,OAAO,YACvB,OAAO,QAAQ,WAAW,CAAC,CAAC,KAAK,CAAC,QAAQ,aAAa,CACrD,SACC,YAA8B,eAAe,SAAS,OAAO,CAChE,CAAC,CACH;;;;;;;;;;;;;;AAeA,MAAa,MAOT;CACF,GAAG;CACH,SAAS,SAAS,YAAY,eAAe,SAAS,OAAO;CAC7D,OAAO;CACP,UAAU;AACZ;AAUA,GAAG,MAAM"}
@@ -0,0 +1,154 @@
1
+ import { CliParsedEvent } from "./events.type.mjs";
2
+ import { CliMcpServers } from "./mcp.type.mjs";
3
+ import { ReasoningEffort } from "@warlock.js/ai";
4
+
5
+ //#region ../../packages/ai-cli/src/contracts/adapter.contract.d.ts
6
+ /**
7
+ * Permission mode for a run.
8
+ *
9
+ * - `standard` (default) — the CLI's own non-interactive approval rules: tools
10
+ * that would need a human approval are refused, never auto-approved.
11
+ * - `bypass` — every tool call is approved without asking (each vendor's
12
+ * "yolo"/"dangerously skip permissions" switch). Opt in per agent or per run.
13
+ */
14
+ type CliPermission = "standard" | "bypass";
15
+ /**
16
+ * How the prompt reaches the CLI: as an argv element, written to stdin, or
17
+ * written to a file in the run directory whose path is passed (for CLIs
18
+ * with a `--prompt-file` flag).
19
+ */
20
+ type CliPromptTransport = "argv" | "stdin" | "file";
21
+ /**
22
+ * Everything an adapter needs to build one launch. Built by the runner;
23
+ * adapters only read it.
24
+ */
25
+ type CliLaunchContext = {
26
+ prompt: string; /** Where the prompt must go for this plan. */
27
+ transport: CliPromptTransport; /** Absolute working directory of the run. */
28
+ cwd: string;
29
+ model?: string; /** Requested reasoning effort; the adapter maps it to the vendor's scale. */
30
+ effort?: ReasoningEffort;
31
+ permission: CliPermission; /** Session reference to resume (from a previous `session.started` / `done().sessionRef`). */
32
+ resume?: string;
33
+ mcp?: CliMcpServers;
34
+ /**
35
+ * The run's API key. The runner already exports it as the adapter's first
36
+ * `apiKeyEnv` variable; an adapter only reads it when its CLI insists on a
37
+ * key file (written into a private home, mode 0600).
38
+ */
39
+ apiKey?: string;
40
+ /**
41
+ * The CLI's config home for this run, or `undefined` when the run uses
42
+ * the CLI's normal home (`home: "inherit"`).
43
+ */
44
+ home?: string;
45
+ /**
46
+ * `true` when `home` was created for this run and is deleted afterwards —
47
+ * the adapter may write home-level config files (for example Codex's
48
+ * `config.toml`) into it. `false` for a caller-owned or inherited home.
49
+ */
50
+ homeIsPrivate: boolean; /** A private directory (mode 0700) for run-scoped files; deleted after the run. */
51
+ runDir: string;
52
+ platform: NodeJS.Platform;
53
+ };
54
+ /** A file the runner writes (mode 0600, parent directories 0700) before spawning. */
55
+ type CliLaunchFile = {
56
+ /** Absolute path, inside `context.runDir` or a private `context.home`. */path: string;
57
+ content: string;
58
+ };
59
+ /** What an adapter returns for one launch. */
60
+ type CliLaunchPlan = {
61
+ /** argv after the executable (subcommand and flags). */args: string[];
62
+ /**
63
+ * argv that must come last, after any caller `args` — typically the
64
+ * positional prompt (`transport: "argv"`).
65
+ */
66
+ tail?: string[]; /** Text written to stdin before it is closed (the prompt, for `transport: "stdin"`). */
67
+ stdin?: string; /** Environment the CLI needs on top of the inherited one (config home variables, …). */
68
+ env?: Record<string, string>; /** Files to write before spawning (MCP config, …). */
69
+ files?: CliLaunchFile[];
70
+ /**
71
+ * The flags (and subcommands) this plan relies on, spelled as `--help`
72
+ * prints them. The capability probe requires each one; a missing entry
73
+ * fails the run before anything is spawned.
74
+ */
75
+ requires: string[];
76
+ };
77
+ /** How the capability probe reads the CLI's help and version. */
78
+ type CliProbeSpec = {
79
+ /** Each entry is one help invocation; their outputs are searched together. */help: string[][]; /** Version invocation. */
80
+ version: string[];
81
+ };
82
+ /** Where an adapter's flags and stream format were verified, recorded per adapter. */
83
+ type CliAdapterVerification = {
84
+ /** CLI version the adapter was checked against. */version: string; /** `help` — checked against the real `--help` output; `docs` — official docs/source only. */
85
+ verifiedBy: "help" | "docs"; /** Official documentation / source URLs. */
86
+ sources: string[]; /** ISO date of the check. */
87
+ checkedAt: string;
88
+ };
89
+ /**
90
+ * A stateful parser for one session's stdout. The runner feeds it complete
91
+ * lines (without the trailing newline) and calls `end()` once stdout closes.
92
+ */
93
+ type CliStreamParser = {
94
+ line(line: string): CliParsedEvent[];
95
+ end(): CliParsedEvent[];
96
+ /**
97
+ * The session reference, for CLIs that reveal it only at the end of the
98
+ * stream (after `session.started` was emitted). Read once the stream
99
+ * closes; wins over a ref from `session.started`.
100
+ */
101
+ sessionRef?(): string | undefined;
102
+ };
103
+ /**
104
+ * A vendor adapter: the launch plan and the stream parser for one coding
105
+ * CLI. Implement this to drive a CLI the package does not ship.
106
+ *
107
+ * @example
108
+ * const myCli: CliAdapter = {
109
+ * name: "my-cli",
110
+ * title: "My CLI",
111
+ * command: "my-cli",
112
+ * apiKeyEnv: ["MY_CLI_API_KEY"],
113
+ * homeEnv: ["MY_CLI_HOME"],
114
+ * transports: ["argv"],
115
+ * probe: { help: [["--help"]], version: ["--version"] },
116
+ * verification: { version: "1.2.0", verifiedBy: "help", sources: ["https://example.com/docs"], checkedAt: "2026-10-17" },
117
+ * plan: (context) => ({
118
+ * args: ["--print", "--json"],
119
+ * tail: [context.prompt],
120
+ * env: context.home ? { MY_CLI_HOME: context.home } : undefined,
121
+ * requires: ["--print", "--json"],
122
+ * }),
123
+ * parser: () => jsonLinesParser((record) =>
124
+ * record.type === "text" ? [{ type: "message", text: String(record.text), delta: false }] : [],
125
+ * ),
126
+ * };
127
+ */
128
+ type CliAdapter = {
129
+ /** Stable id, e.g. `"claude-code"`. Used in errors and as the model provider name. */readonly name: string; /** Human name, e.g. `"Claude Code"`. */
130
+ readonly title: string; /** Default executable name looked up on `PATH`. */
131
+ readonly command: string; /** Environment variables that receive an API key (the first is used for the `apiKey` option). */
132
+ readonly apiKeyEnv: readonly string[];
133
+ /**
134
+ * Environment variables pointed at the config home. Empty when the CLI
135
+ * cannot relocate its config, in which case `home` other than `"inherit"`
136
+ * is refused for it.
137
+ */
138
+ readonly homeEnv: readonly string[]; /** Prompt transports the CLI accepts, in order of preference. */
139
+ readonly transports: readonly CliPromptTransport[]; /** Whether the adapter maps `effort` to a vendor flag. */
140
+ readonly effort?: boolean; /** Whether the adapter can attach per-run MCP servers. */
141
+ readonly mcp?: boolean;
142
+ readonly probe: CliProbeSpec;
143
+ readonly verification: CliAdapterVerification;
144
+ plan(context: CliLaunchContext): CliLaunchPlan;
145
+ /**
146
+ * A fresh parser for one session. Receives the launch context of the
147
+ * chosen plan, so a parser can read a file the CLI writes into
148
+ * `context.runDir` when its stream ends.
149
+ */
150
+ parser(context: CliLaunchContext): CliStreamParser;
151
+ };
152
+ //#endregion
153
+ export { CliAdapter, CliAdapterVerification, CliLaunchContext, CliLaunchFile, CliLaunchPlan, CliPermission, CliProbeSpec, CliPromptTransport, CliStreamParser };
154
+ //# sourceMappingURL=adapter.contract.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.contract.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/contracts/adapter.contract.ts"],"mappings":";;;;;;;AAYA;;;;AAAyB;AAOzB;KAPY,aAAA;;;AAOkB;AAM9B;;KANY,kBAAA;;;;;KAMA,gBAAA;EACV,MAAA,UA+ByB;EA7BzB,SAAA,EAAW,kBAAA,EAAX;EAEA,GAAA;EACA,KAAA;EAEA,MAAA,GAAS,eAAA;EACT,UAAA,EAAY,aAAA,EAAZ;EAEA,MAAA;EACA,GAAA,GAAM,aAAA;EAAN;;;;;EAMA,MAAA;EAcA;;;;EATA,IAAA;EAaU;;;;AAGH;EAVP,aAAA,WAcuB;EAZvB,MAAA;EACA,QAAA,EAAU,MAAA,CAAO,QAAA;AAAA;;KAIP,aAAA;EAkBV,0EAhBA,IAAA;EACA,OAAO;AAAA;;KAIG,aAAA;EAmBF,wDAjBR,IAAA;EAqBsB;;;AAIf;EApBP,IAAA,aAwBgC;EAtBhC,KAAA,WAsBgC;EApBhC,GAAA,GAAM,MAAA,kBAwBN;EAtBA,KAAA,GAAQ,aAAa;EA0BrB;;AAAS;AAOX;;EA3BE,QAAA;AAAA;;KAIU,YAAA;EAwBU,8EAtBpB,IAAA,cAuBO;EArBP,OAAO;AAAA;AA2BG;AAAA,KAvBA,sBAAA;EAmDU,mDAjDpB,OAAA,UAiE8B;EA/D9B,UAAA,mBAqEuB;EAnEvB,OAAA,YAoEiC;EAlEjC,SAAA;AAAA;;;;;KAOU,eAAA;EACV,IAAA,CAAK,IAAA,WAAe,cAAA;EACpB,GAAA,IAAO,cAAc;EAkDZ;;;;;EA5CT,UAAA;AAAA;;;;;;;;;;;AAyDkD;;;;;;;;;;;;;;;KA7BxC,UAAA;iGAED,IAAA;WAEA,KAAA;WAEA,OAAA;WAEA,SAAA;;;;;;WAMA,OAAA;WAEA,UAAA,WAAqB,kBAAA;WAErB,MAAA;WAEA,GAAA;EAAA,SACA,KAAA,EAAO,YAAA;EAAA,SACP,YAAA,EAAc,sBAAA;EACvB,IAAA,CAAK,OAAA,EAAS,gBAAA,GAAmB,aAAA;;;;;;EAMjC,MAAA,CAAO,OAAA,EAAS,gBAAA,GAAmB,eAAA;AAAA"}
@@ -0,0 +1,111 @@
1
+ //#region ../../packages/ai-cli/src/contracts/events.type.d.ts
2
+ /**
3
+ * Token usage a CLI session reported, normalized across vendors.
4
+ *
5
+ * Every field except `input`/`output`/`total` is optional because vendors
6
+ * report different subsets: Claude Code reports cache reads/writes and a
7
+ * USD cost, Codex reports cached and reasoning tokens, Aider reports a
8
+ * cost line, some CLIs report nothing at all.
9
+ *
10
+ * @example
11
+ * const usage: CliUsage = { input: 1200, output: 340, total: 1540, cachedTokens: 800 };
12
+ */
13
+ type CliUsage = {
14
+ /** Input/prompt tokens (includes `cachedTokens` when the vendor counts them together). */input: number; /** Output/completion tokens. */
15
+ output: number; /** `input + output`. */
16
+ total: number; /** Input tokens served from the vendor's prompt cache. */
17
+ cachedTokens?: number; /** Input tokens written to the vendor's prompt cache. */
18
+ cacheWriteTokens?: number; /** Output tokens spent on reasoning, when the vendor reports them. */
19
+ reasoningTokens?: number; /** Cost in USD as reported by the CLI itself (never computed by this package). */
20
+ costUSD?: number;
21
+ };
22
+ /**
23
+ * How a CLI session ended.
24
+ *
25
+ * - `completed` — the process exited 0 and the stream reported no fatal error.
26
+ * - `failed` — non-zero exit, a spawn failure, or a fatal error in the stream.
27
+ * - `cancelled` — the run's `signal` aborted (or `session.cancel()` was called).
28
+ * - `timeout` — `timeoutMs` elapsed and the process tree was killed.
29
+ */
30
+ type CliEndStatus = "completed" | "failed" | "cancelled" | "timeout";
31
+ /** A session started; carries the vendor's session/thread id when it reported one. */
32
+ type CliSessionStartedEvent = {
33
+ type: "session.started"; /** Reference to pass back as `resume` to continue this session. */
34
+ sessionRef?: string; /** Model the CLI reported it is using. */
35
+ model?: string; /** The vendor's original record, for debugging. */
36
+ raw?: unknown;
37
+ };
38
+ /**
39
+ * Assistant text. `delta: true` is a streamed fragment of the message being
40
+ * written; `delta: false` is a complete message. `final: true` marks the
41
+ * vendor's own "final answer" record (for example Claude Code's `result`).
42
+ */
43
+ type CliMessageEvent = {
44
+ type: "message";
45
+ text: string;
46
+ delta: boolean;
47
+ final?: boolean;
48
+ raw?: unknown;
49
+ };
50
+ /** The CLI invoked one of its tools (or an MCP tool). */
51
+ type CliToolCallEvent = {
52
+ type: "tool.call"; /** Vendor call id, used to pair the call with its `tool.result`. */
53
+ id: string;
54
+ name: string;
55
+ input: unknown;
56
+ raw?: unknown;
57
+ };
58
+ /** A tool finished. `output` is the tool's text output (stringified when structured). */
59
+ type CliToolResultEvent = {
60
+ type: "tool.result";
61
+ id: string;
62
+ output: string;
63
+ isError: boolean;
64
+ raw?: unknown;
65
+ };
66
+ /**
67
+ * Token usage. `cumulative: true` replaces the running total (the vendor
68
+ * reported totals for the whole session so far); `cumulative: false` adds
69
+ * to it (the vendor reported one turn).
70
+ */
71
+ type CliUsageEvent = {
72
+ type: "usage";
73
+ usage: CliUsage;
74
+ cumulative: boolean;
75
+ raw?: unknown;
76
+ };
77
+ /**
78
+ * Something went wrong. `fatal: true` means the vendor reported the run as
79
+ * failed; the session then ends `failed` even when the process exits 0.
80
+ */
81
+ type CliErrorEvent = {
82
+ type: "error";
83
+ message: string;
84
+ fatal?: boolean;
85
+ raw?: unknown;
86
+ };
87
+ /** The process exited and the stream is drained. Always the last event. */
88
+ type CliSessionEndedEvent = {
89
+ type: "session.ended";
90
+ status: CliEndStatus; /** Process exit code; `null` when the process never started or died by signal. */
91
+ exitCode: number | null; /** Terminating signal, when the process died by one. */
92
+ signal: string | null;
93
+ sessionRef?: string;
94
+ durationMs: number;
95
+ };
96
+ /**
97
+ * The unified event model every adapter's stream is reduced to.
98
+ * Discriminate on `type`.
99
+ *
100
+ * @example
101
+ * for await (const event of session.events) {
102
+ * if (event.type === "message" && event.delta) process.stdout.write(event.text);
103
+ * if (event.type === "tool.call") console.log("→", event.name, event.input);
104
+ * }
105
+ */
106
+ type CliEvent = CliSessionStartedEvent | CliMessageEvent | CliToolCallEvent | CliToolResultEvent | CliUsageEvent | CliErrorEvent | CliSessionEndedEvent;
107
+ /** Events an adapter's stream parser may emit (`session.ended` is emitted by the runner). */
108
+ type CliParsedEvent = Exclude<CliEvent, CliSessionEndedEvent>;
109
+ //#endregion
110
+ export { CliEndStatus, CliErrorEvent, CliEvent, CliMessageEvent, CliParsedEvent, CliSessionEndedEvent, CliSessionStartedEvent, CliToolCallEvent, CliToolResultEvent, CliUsage, CliUsageEvent };
111
+ //# sourceMappingURL=events.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/contracts/events.type.ts"],"mappings":";;AAWA;;;;;;;;;;KAAY,QAAA;EAcH,0FAZP,KAAA,UAuBU;EArBV,MAAA;EAEA,KAAA,UAmBsB;EAjBtB,YAAA,WAoBgC;EAlBhC,gBAAA,WAkBgC;EAhBhC,eAAA,WAmBA;EAjBA,OAAA;AAAA;;AAqBG;AAQL;;;;;;KAlBY,YAAA;;KAGA,sBAAA;EACV,IAAA,qBAmBG;EAjBH,UAAA,WAqB0B;EAnB1B,KAAA,WAmB0B;EAjB1B,GAAA;AAAA;;;;;AAuBG;KAfO,eAAA;EACV,IAAA;EACA,IAAA;EACA,KAAA;EACA,KAAA;EACA,GAAA;AAAA;;KAIU,gBAAA;EACV,IAAA,eAcG;EAZH,EAAA;EACA,IAAA;EACA,KAAA;EACA,GAAA;AAAA;;KAIU,kBAAA;EACV,IAAA;EACA,EAAA;EACA,MAAA;EACA,OAAA;EACA,GAAA;AAAA;;;;;;KAQU,aAAA;EACV,IAAA;EACA,KAAA,EAAO,QAAQ;EACf,UAAA;EACA,GAAA;AAAA;;;;;KAOU,aAAA;EACV,IAAA;EACA,OAAA;EACA,KAAA;EACA,GAAA;AAAA;AAyBF;AAAA,KArBY,oBAAA;EACV,IAAA;EACA,MAAA,EAAQ,YAAY,EAqBlB;EAnBF,QAAA,iBAqBE;EAnBF,MAAA;EACA,UAAA;EACA,UAAA;AAAA;;;;;;;;;;AAoBsB;KAPZ,QAAA,GACR,sBAAA,GACA,eAAA,GACA,gBAAA,GACA,kBAAA,GACA,aAAA,GACA,aAAA,GACA,oBAAA;;KAGQ,cAAA,GAAiB,OAAA,CAAQ,QAAA,EAAU,oBAAA"}
@@ -0,0 +1,4 @@
1
+ import { CliEndStatus, CliErrorEvent, CliEvent, CliMessageEvent, CliParsedEvent, CliSessionEndedEvent, CliSessionStartedEvent, CliToolCallEvent, CliToolResultEvent, CliUsage, CliUsageEvent } from "./events.type.mjs";
2
+ import { CliMcpRemoteServer, CliMcpServer, CliMcpServers, CliMcpStdioServer } from "./mcp.type.mjs";
3
+ import { CliAdapter, CliAdapterVerification, CliLaunchContext, CliLaunchFile, CliLaunchPlan, CliPermission, CliProbeSpec, CliPromptTransport, CliStreamParser } from "./adapter.contract.mjs";
4
+ import { CliAgentOptions, CliHome, CliProbeResult, CliResult, CliRunOptions, CliSession } from "./options.type.mjs";
@@ -0,0 +1,29 @@
1
+ //#region ../../packages/ai-cli/src/contracts/mcp.type.d.ts
2
+ /**
3
+ * An MCP server started by the CLI as a child process (stdio transport).
4
+ * `env` values usually hold tokens — they are written only into a 0600
5
+ * config file inside the run's private directory, never into argv.
6
+ */
7
+ type CliMcpStdioServer = {
8
+ type: "stdio";
9
+ command: string;
10
+ args?: string[];
11
+ env?: Record<string, string>;
12
+ };
13
+ /**
14
+ * A remote MCP server (streamable HTTP, or the older SSE transport).
15
+ * `headers` usually hold an `Authorization` token — written only into the
16
+ * run's 0600 config file, never into argv.
17
+ */
18
+ type CliMcpRemoteServer = {
19
+ type: "http" | "sse";
20
+ url: string;
21
+ headers?: Record<string, string>;
22
+ };
23
+ /** One MCP server, in the vendor-neutral shape every adapter renders to its own config format. */
24
+ type CliMcpServer = CliMcpStdioServer | CliMcpRemoteServer;
25
+ /** MCP servers for a run, keyed by the server name the CLI will show. */
26
+ type CliMcpServers = Record<string, CliMcpServer>;
27
+ //#endregion
28
+ export { CliMcpRemoteServer, CliMcpServer, CliMcpServers, CliMcpStdioServer };
29
+ //# sourceMappingURL=mcp.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/contracts/mcp.type.ts"],"mappings":";;AAKA;;;;KAAY,iBAAA;EACV,IAAA;EACA,OAAA;EACA,IAAA;EACA,GAAA,GAAM,MAAM;AAAA;AAAA;AAQd;;;;AARc,KAQF,kBAAA;EACV,IAAA;EACA,GAAA;EACA,OAAA,GAAU,MAAM;AAAA;AAAA;AAAA,KAIN,YAAA,GAAe,iBAAA,GAAoB,kBAAkB;;KAGrD,aAAA,GAAgB,MAAM,SAAS,YAAA"}
@@ -0,0 +1,87 @@
1
+ import { CliEndStatus, CliEvent, CliUsage } from "./events.type.mjs";
2
+ import { CliMcpServers } from "./mcp.type.mjs";
3
+ import { CliPermission } from "./adapter.contract.mjs";
4
+ import { ReasoningEffort } from "@warlock.js/ai";
5
+
6
+ //#region ../../packages/ai-cli/src/contracts/options.type.d.ts
7
+ /**
8
+ * Where the CLI keeps its config for a run.
9
+ *
10
+ * - `"private"` (default) — a fresh directory (mode 0700) created for the run
11
+ * and deleted after it. Nothing from your own login leaks in or out;
12
+ * authenticate with `apiKey` / `env`.
13
+ * - an absolute path — a home you own and keep (for example one you logged
14
+ * in to once with `CLAUDE_CONFIG_DIR=/srv/claude claude`). The adapter
15
+ * points its home variable at it; run-scoped files still go to a private
16
+ * per-run directory.
17
+ * - `"inherit"` — the CLI's normal home of the current user.
18
+ */
19
+ type CliHome = "private" | "inherit" | (string & {});
20
+ /** Options shared by a CLI agent's defaults and a single run. */
21
+ type CliRunOptions = {
22
+ /** Working directory of the run. Default: `process.cwd()`. */cwd?: string; /** Session reference to resume (`done().sessionRef` of an earlier run). */
23
+ resume?: string; /** Cancels the run and kills the CLI's whole process tree. */
24
+ signal?: AbortSignal; /** Kills the process tree after this many milliseconds (status `timeout`). */
25
+ timeoutMs?: number; /** Vendor model id or alias, passed to the CLI's model flag. */
26
+ model?: string; /** Reasoning effort, mapped to the vendor's scale. Refused for CLIs without an effort control. */
27
+ effort?: ReasoningEffort; /** `"standard"` (default) or `"bypass"` (approve every tool call — opt in only). */
28
+ permission?: CliPermission; /** Per-run MCP servers, written to a 0600 config file — never argv. */
29
+ mcp?: CliMcpServers; /** Extra environment for the CLI (wins over inherited variables). */
30
+ env?: Record<string, string>; /** API key, exported as the adapter's first `apiKeyEnv` variable. Never placed in argv. */
31
+ apiKey?: string; /** Extra argv appended after the adapter's own flags. Do not put secrets here. */
32
+ args?: string[];
33
+ };
34
+ /** Configuration of a CLI agent (`cli.claudeCode({...})`). */
35
+ type CliAgentOptions = CliRunOptions & {
36
+ /** Executable to run instead of the adapter's default (a name on `PATH` or an absolute path). */command?: string; /** Config home. Default `"private"`. */
37
+ home?: CliHome;
38
+ /**
39
+ * Which of the current process's environment variables the CLI inherits.
40
+ * `true` (default) inherits everything except the adapter's own home
41
+ * variables; `false` passes only a minimal system set (PATH, HOME, TEMP,
42
+ * locale, proxy and Windows system variables); a list passes the minimal
43
+ * set plus those names.
44
+ */
45
+ inheritEnv?: boolean | string[];
46
+ /**
47
+ * Run the capability probe (`--help`/`--version`) before the first run.
48
+ * Default `true`. Turning it off skips the flag check — a CLI version
49
+ * whose flags changed then fails at run time instead of up front.
50
+ */
51
+ probe?: boolean; /** Grace period between SIGTERM and SIGKILL when a run is cancelled (POSIX). Default 2000 ms. */
52
+ killGraceMs?: number;
53
+ };
54
+ /** What `session.done()` resolves to. */
55
+ type CliResult = {
56
+ status: CliEndStatus; /** The final answer: the vendor's final record, else the last assistant message. */
57
+ text: string; /** Every complete assistant message, in order. */
58
+ messages: string[]; /** Accumulated usage, or `undefined` when the CLI reported none. */
59
+ usage?: CliUsage; /** Pass as `resume` to continue this session. */
60
+ sessionRef?: string;
61
+ exitCode: number | null;
62
+ signal: string | null; /** First fatal error, or a summary of stderr when the run failed. */
63
+ error?: string; /** The last 64 KiB of stderr. */
64
+ stderr: string;
65
+ durationMs: number;
66
+ };
67
+ /** A running CLI session. */
68
+ type CliSession = {
69
+ /** Adapter name, e.g. `"claude-code"`. */readonly adapter: string; /** Process id of the spawned CLI. */
70
+ readonly pid: number | undefined;
71
+ /**
72
+ * The normalized event stream. Every iteration replays from the first
73
+ * event, so several consumers may read it; it ends after `session.ended`.
74
+ */
75
+ readonly events: AsyncIterable<CliEvent>; /** Resolves once the process exits and the stream is drained. Never rejects. */
76
+ done(): Promise<CliResult>; /** Cancel the run (kills the process tree); `done()` then resolves `cancelled`. */
77
+ cancel(): void;
78
+ };
79
+ /** Result of the capability probe. */
80
+ type CliProbeResult = {
81
+ /** Resolved executable path. */executable: string; /** First version-looking token of `--version`, or the trimmed output. */
82
+ version: string; /** Concatenated help output the required flags are checked against. */
83
+ help: string;
84
+ };
85
+ //#endregion
86
+ export { CliAgentOptions, CliHome, CliProbeResult, CliResult, CliRunOptions, CliSession };
87
+ //# sourceMappingURL=options.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/contracts/options.type.ts"],"mappings":";;;;;;;;AAiBA;;;;AAAmB;AAGnB;;;;;KAHY,OAAA;;KAGA,aAAA;EAkBE,8DAhBZ,GAAA;EAEA,MAAA,WAEA;EAAA,MAAA,GAAS,WAAA,EAET;EAAA,SAAA,WAIA;EAFA,KAAA,WAIA;EAFA,MAAA,GAAS,eAAA,EAIT;EAFA,UAAA,GAAa,aAAA,EAIb;EAFA,GAAA,GAAM,aAAA,EAIN;EAFA,GAAA,GAAM,MAAA,kBAIF;EAFJ,MAAA,WAMU;EAJV,IAAA;AAAA;;KAIU,eAAA,GAAkB,aAAA;EAE5B,iGAAA,OAAA,WAEO;EAAP,IAAA,GAAO,OAAO;EAcd;;;AAEW;AAIb;;;EAZE,UAAA;EAaA;;;;;EAPA,KAAA,YAeA;EAbA,WAAA;AAAA;;KAIU,SAAA;EACV,MAAA,EAAQ,YAAA,EAeE;EAbV,IAAA,UAiBU;EAfV,QAAA;EAEA,KAAA,GAAQ,QAAQ,EAsBC;EApBjB,UAAA;EACA,QAAA;EACA,MAAA,iBAoBe;EAlBf,KAAA,WAWS;EATT,MAAA;EACA,UAAA;AAAA;;KAIU,UAAA;EAWM,mDATP,OAAA,UAWH;EAAA,SATG,GAAA;EAaC;;;;EAAA,SARD,MAAA,EAAQ,aAAA,CAAc,QAAA,GAY/B;EAVA,IAAA,IAAQ,OAAA,CAAQ,SAAA,GAYZ;EAVJ,MAAA;AAAA;;KAIU,cAAA;kCAEV,UAAA;EAEA,OAAA;EAEA,IAAA;AAAA"}
@@ -0,0 +1,46 @@
1
+ import { AIErrorOptions, ProviderError } from "@warlock.js/ai";
2
+
3
+ //#region ../../packages/ai-cli/src/errors.d.ts
4
+ /**
5
+ * Why a CLI agent refused or failed a run.
6
+ *
7
+ * - `not-found` — the executable is not on `PATH` (or the given path does not exist).
8
+ * - `capability` — the installed CLI's `--help` does not list a flag the run needs.
9
+ * - `probe-failed` — `--help`/`--version` could not be run.
10
+ * - `unsupported-option` — the adapter has no way to honour an option (effort, MCP, home, …).
11
+ * - `prompt-transport` — the prompt fits neither argv nor stdin for this CLI and platform.
12
+ * - `run-failed` — the session ended `failed` or `timeout` (raised by the model adapter).
13
+ */
14
+ type CliErrorType = "not-found" | "capability" | "probe-failed" | "unsupported-option" | "prompt-transport" | "run-failed";
15
+ type CliErrorOptions = AIErrorOptions & {
16
+ type: CliErrorType; /** Adapter name, e.g. `"codex"`. */
17
+ adapter: string; /** The missing flag, for `capability`. */
18
+ flag?: string; /** Detected CLI version, when known. */
19
+ version?: string; /** Resolved executable, when known. */
20
+ executable?: string;
21
+ };
22
+ /**
23
+ * A CLI agent error. Extends the framework `ProviderError`, so agents,
24
+ * fallbacks and observers treat it like any other provider failure; branch
25
+ * on `error.type` for the specific reason.
26
+ *
27
+ * @example
28
+ * try {
29
+ * await claude.run("hi");
30
+ * } catch (error) {
31
+ * if (error instanceof CliError && error.type === "capability") {
32
+ * console.error(`Upgrade ${error.adapter}: missing ${error.flag} in ${error.version}`);
33
+ * }
34
+ * }
35
+ */
36
+ declare class CliError extends ProviderError {
37
+ readonly type: CliErrorType;
38
+ readonly adapter: string;
39
+ readonly flag?: string;
40
+ readonly version?: string;
41
+ readonly executable?: string;
42
+ constructor(message: string, options: CliErrorOptions);
43
+ }
44
+ //#endregion
45
+ export { CliError, CliErrorOptions, CliErrorType };
46
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../../../../../../../packages/ai-cli/src/errors.ts"],"mappings":";;;;;AAYA;;;;AAAwB;AAQxB;;;KARY,YAAA;AAAA,KAQA,eAAA,GAAkB,cAAA;EAC5B,IAAA,EAAM,YAAY,EAAZ;EAEN,OAAA,UAEA;EAAA,IAAA,WAIA;EAFA,OAAA,WAEU;EAAV,UAAA;AAAA;;;;;;;;;;;;;;;cAiBW,QAAA,SAAiB,aAAA;EAAA,SACZ,IAAA,EAAM,YAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA;EAAA,SACA,UAAA;cAEG,OAAA,UAAiB,OAAA,EAAS,eAAA;AAAA"}
package/esm/errors.mjs ADDED
@@ -0,0 +1,32 @@
1
+ import { ProviderError } from "@warlock.js/ai";
2
+
3
+ //#region ../../packages/ai-cli/src/errors.ts
4
+ /**
5
+ * A CLI agent error. Extends the framework `ProviderError`, so agents,
6
+ * fallbacks and observers treat it like any other provider failure; branch
7
+ * on `error.type` for the specific reason.
8
+ *
9
+ * @example
10
+ * try {
11
+ * await claude.run("hi");
12
+ * } catch (error) {
13
+ * if (error instanceof CliError && error.type === "capability") {
14
+ * console.error(`Upgrade ${error.adapter}: missing ${error.flag} in ${error.version}`);
15
+ * }
16
+ * }
17
+ */
18
+ var CliError = class extends ProviderError {
19
+ constructor(message, options) {
20
+ super(message, options, options.type === "unsupported-option" || options.type === "prompt-transport" ? "PROVIDER_INVALID_REQUEST" : "PROVIDER_ERROR");
21
+ this.name = "CliError";
22
+ this.type = options.type;
23
+ this.adapter = options.adapter;
24
+ this.flag = options.flag;
25
+ this.version = options.version;
26
+ this.executable = options.executable;
27
+ }
28
+ };
29
+
30
+ //#endregion
31
+ export { CliError };
32
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../packages/ai-cli/src/errors.ts"],"sourcesContent":["import { type AIErrorOptions, ProviderError } from \"@warlock.js/ai\";\n\n/**\n * Why a CLI agent refused or failed a run.\n *\n * - `not-found` — the executable is not on `PATH` (or the given path does not exist).\n * - `capability` — the installed CLI's `--help` does not list a flag the run needs.\n * - `probe-failed` — `--help`/`--version` could not be run.\n * - `unsupported-option` — the adapter has no way to honour an option (effort, MCP, home, …).\n * - `prompt-transport` — the prompt fits neither argv nor stdin for this CLI and platform.\n * - `run-failed` — the session ended `failed` or `timeout` (raised by the model adapter).\n */\nexport type CliErrorType =\n | \"not-found\"\n | \"capability\"\n | \"probe-failed\"\n | \"unsupported-option\"\n | \"prompt-transport\"\n | \"run-failed\";\n\nexport type CliErrorOptions = AIErrorOptions & {\n type: CliErrorType;\n /** Adapter name, e.g. `\"codex\"`. */\n adapter: string;\n /** The missing flag, for `capability`. */\n flag?: string;\n /** Detected CLI version, when known. */\n version?: string;\n /** Resolved executable, when known. */\n executable?: string;\n};\n\n/**\n * A CLI agent error. Extends the framework `ProviderError`, so agents,\n * fallbacks and observers treat it like any other provider failure; branch\n * on `error.type` for the specific reason.\n *\n * @example\n * try {\n * await claude.run(\"hi\");\n * } catch (error) {\n * if (error instanceof CliError && error.type === \"capability\") {\n * console.error(`Upgrade ${error.adapter}: missing ${error.flag} in ${error.version}`);\n * }\n * }\n */\nexport class CliError extends ProviderError {\n public readonly type: CliErrorType;\n public readonly adapter: string;\n public readonly flag?: string;\n public readonly version?: string;\n public readonly executable?: string;\n\n public constructor(message: string, options: CliErrorOptions) {\n super(\n message,\n options,\n options.type === \"unsupported-option\" || options.type === \"prompt-transport\"\n ? \"PROVIDER_INVALID_REQUEST\"\n : \"PROVIDER_ERROR\",\n );\n\n this.name = \"CliError\";\n this.type = options.type;\n this.adapter = options.adapter;\n this.flag = options.flag;\n this.version = options.version;\n this.executable = options.executable;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8CA,IAAa,WAAb,cAA8B,cAAc;CAO1C,AAAO,YAAY,SAAiB,SAA0B;EAC5D,MACE,SACA,SACA,QAAQ,SAAS,wBAAwB,QAAQ,SAAS,qBACtD,6BACA,gBACN;EAEA,KAAK,OAAO;EACZ,KAAK,OAAO,QAAQ;EACpB,KAAK,UAAU,QAAQ;EACvB,KAAK,OAAO,QAAQ;EACpB,KAAK,UAAU,QAAQ;EACvB,KAAK,aAAa,QAAQ;CAC5B;AACF"}
@@ -0,0 +1,31 @@
1
+ import { CliEndStatus, CliErrorEvent, CliEvent, CliMessageEvent, CliParsedEvent, CliSessionEndedEvent, CliSessionStartedEvent, CliToolCallEvent, CliToolResultEvent, CliUsage, CliUsageEvent } from "./contracts/events.type.mjs";
2
+ import { CliMcpRemoteServer, CliMcpServer, CliMcpServers, CliMcpStdioServer } from "./contracts/mcp.type.mjs";
3
+ import { CliAdapter, CliAdapterVerification, CliLaunchContext, CliLaunchFile, CliLaunchPlan, CliPermission, CliProbeSpec, CliPromptTransport, CliStreamParser } from "./contracts/adapter.contract.mjs";
4
+ import { CliAgentOptions, CliHome, CliProbeResult, CliResult, CliRunOptions, CliSession } from "./contracts/options.type.mjs";
5
+ import { CliError, CliErrorOptions, CliErrorType } from "./errors.mjs";
6
+ import { CliModelConfig, cliModel, renderPrompt, toUsage } from "./model/cli-model.mjs";
7
+ import { CmdShimTarget, CommandLookup, SpawnTarget, findExecutable, parseCmdShim, resolveSpawnTarget } from "./spawn/resolve-command.mjs";
8
+ import { CliAgent, CliHost, createCliAgent, currentHost } from "./cli-agent.mjs";
9
+ import { JsonRecord, asArray, asRecord, jsonLinesParser, numberField, outputText, parseJsonLine, recordField, stringField } from "./stream/json-lines.mjs";
10
+ import { TomlTable, TomlValue, toToml } from "./utils/toml.mjs";
11
+ import { helpLists, missingFlags, parseVersion } from "./probe/probe.mjs";
12
+ import { Invocation, buildInvocation, fitsCommandLine, quoteForCmd } from "./spawn/invocation.mjs";
13
+ import { aiderAdapter, createAiderParser, parseAiderCount } from "./adapters/aider.mjs";
14
+ import { ampAdapter } from "./adapters/amp.mjs";
15
+ import { antigravityAdapter, createAntigravityParser } from "./adapters/antigravity.mjs";
16
+ import { claudeCodeAdapter } from "./adapters/claude-code.mjs";
17
+ import { ClaudeStreamUsage, createClaudeStreamParser } from "./adapters/claude-stream.mjs";
18
+ import { codexAdapter, createCodexParser } from "./adapters/codex.mjs";
19
+ import { copilotAdapter, createCopilotParser } from "./adapters/copilot.mjs";
20
+ import { createCursorParser, cursorAdapter } from "./adapters/cursor.mjs";
21
+ import { createDroidParser, droidAdapter } from "./adapters/droid.mjs";
22
+ import { createGrokParser, grokAdapter } from "./adapters/grok.mjs";
23
+ import { createKimiParser, kimiAdapter } from "./adapters/kimi.mjs";
24
+ import { createVibeParser, mistralVibeAdapter } from "./adapters/mistral-vibe.mjs";
25
+ import { createOpencodeParser, opencodeAdapter } from "./adapters/opencode.mjs";
26
+ import { qwenCodeAdapter } from "./adapters/qwen-code.mjs";
27
+ import { createReasonixParser, reasonixAdapter } from "./adapters/reasonix.mjs";
28
+ import { anthropicUsage, argvPrompt, dotenvFile, jsonFile, mapEffort, mcpServersJson, parseArguments, promptFile, requirePrivateHome, unsupportedOption, usageOf } from "./adapters/shared.mjs";
29
+ import { CliVendor, cli, cliAdapters } from "./cli.mjs";
30
+ export { type ClaudeStreamUsage, type CliAdapter, type CliAdapterVerification, type CliAgent, type CliAgentOptions, type CliEndStatus, CliError, type CliErrorEvent, type CliErrorOptions, type CliErrorType, type CliEvent, type CliHome, type CliHost, type CliLaunchContext, type CliLaunchFile, type CliLaunchPlan, type CliMcpRemoteServer, type CliMcpServer, type CliMcpServers, type CliMcpStdioServer, type CliMessageEvent, type CliModelConfig, type CliParsedEvent, type CliPermission, type CliProbeResult, type CliProbeSpec, type CliPromptTransport, type CliResult, type CliRunOptions, type CliSession, type CliSessionEndedEvent, type CliSessionStartedEvent, type CliStreamParser, type CliToolCallEvent, type CliToolResultEvent, type CliUsage, type CliUsageEvent, type CliVendor, type CmdShimTarget, type CommandLookup, type Invocation, type JsonRecord, type SpawnTarget, type TomlTable, type TomlValue, aiderAdapter, ampAdapter, anthropicUsage, antigravityAdapter, argvPrompt, asArray, asRecord, buildInvocation, claudeCodeAdapter, cli, cliAdapters, cliModel, codexAdapter, copilotAdapter, createAiderParser, createAntigravityParser, createClaudeStreamParser, createCliAgent, createCodexParser, createCopilotParser, createCursorParser, createDroidParser, createGrokParser, createKimiParser, createOpencodeParser, createReasonixParser, createVibeParser, currentHost, cursorAdapter, dotenvFile, droidAdapter, findExecutable, fitsCommandLine, grokAdapter, helpLists, jsonFile, jsonLinesParser, kimiAdapter, mapEffort, mcpServersJson, missingFlags, mistralVibeAdapter, numberField, opencodeAdapter, outputText, parseAiderCount, parseArguments, parseCmdShim, parseJsonLine, parseVersion, promptFile, quoteForCmd, qwenCodeAdapter, reasonixAdapter, recordField, renderPrompt, requirePrivateHome, resolveSpawnTarget, stringField, toToml, toUsage, unsupportedOption, usageOf };
31
+ import "./cli.mjs";
package/esm/index.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import { CliError } from "./errors.mjs";
2
+ import { cliModel, renderPrompt, toUsage } from "./model/cli-model.mjs";
3
+ import { buildInvocation, fitsCommandLine, quoteForCmd } from "./spawn/invocation.mjs";
4
+ import { helpLists, missingFlags, parseVersion } from "./probe/probe.mjs";
5
+ import { findExecutable, parseCmdShim, resolveSpawnTarget } from "./spawn/resolve-command.mjs";
6
+ import { createCliAgent, currentHost } from "./cli-agent.mjs";
7
+ import { asArray, asRecord, jsonLinesParser, numberField, outputText, parseJsonLine, recordField, stringField } from "./stream/json-lines.mjs";
8
+ import { toToml } from "./utils/toml.mjs";
9
+ import { anthropicUsage, argvPrompt, dotenvFile, jsonFile, mapEffort, mcpServersJson, parseArguments, promptFile, requirePrivateHome, unsupportedOption, usageOf } from "./adapters/shared.mjs";
10
+ import { aiderAdapter, createAiderParser, parseAiderCount } from "./adapters/aider.mjs";
11
+ import { createClaudeStreamParser } from "./adapters/claude-stream.mjs";
12
+ import { ampAdapter } from "./adapters/amp.mjs";
13
+ import { antigravityAdapter, createAntigravityParser } from "./adapters/antigravity.mjs";
14
+ import { claudeCodeAdapter } from "./adapters/claude-code.mjs";
15
+ import { codexAdapter, createCodexParser } from "./adapters/codex.mjs";
16
+ import { copilotAdapter, createCopilotParser } from "./adapters/copilot.mjs";
17
+ import { createCursorParser, cursorAdapter } from "./adapters/cursor.mjs";
18
+ import { createDroidParser, droidAdapter } from "./adapters/droid.mjs";
19
+ import { createGrokParser, grokAdapter } from "./adapters/grok.mjs";
20
+ import { createKimiParser, kimiAdapter } from "./adapters/kimi.mjs";
21
+ import { createVibeParser, mistralVibeAdapter } from "./adapters/mistral-vibe.mjs";
22
+ import { createOpencodeParser, opencodeAdapter } from "./adapters/opencode.mjs";
23
+ import { qwenCodeAdapter } from "./adapters/qwen-code.mjs";
24
+ import { createReasonixParser, reasonixAdapter } from "./adapters/reasonix.mjs";
25
+ import "./adapters/index.mjs";
26
+ import { cli, cliAdapters } from "./cli.mjs";
27
+
28
+ export { CliError, aiderAdapter, ampAdapter, anthropicUsage, antigravityAdapter, argvPrompt, asArray, asRecord, buildInvocation, claudeCodeAdapter, cli, cliAdapters, cliModel, codexAdapter, copilotAdapter, createAiderParser, createAntigravityParser, createClaudeStreamParser, createCliAgent, createCodexParser, createCopilotParser, createCursorParser, createDroidParser, createGrokParser, createKimiParser, createOpencodeParser, createReasonixParser, createVibeParser, currentHost, cursorAdapter, dotenvFile, droidAdapter, findExecutable, fitsCommandLine, grokAdapter, helpLists, jsonFile, jsonLinesParser, kimiAdapter, mapEffort, mcpServersJson, missingFlags, mistralVibeAdapter, numberField, opencodeAdapter, outputText, parseAiderCount, parseArguments, parseCmdShim, parseJsonLine, parseVersion, promptFile, quoteForCmd, qwenCodeAdapter, reasonixAdapter, recordField, renderPrompt, requirePrivateHome, resolveSpawnTarget, stringField, toToml, toUsage, unsupportedOption, usageOf };