@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/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog — @warlock.js/ai-cli
2
+
3
+ All notable changes to `@warlock.js/ai-cli` are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
6
+
7
+ ## 5.31.0 - 2026-10-18
8
+
9
+ ### Added
10
+
11
+ - First release: drive vendor coding-agent CLIs headless as agents. `cli.<vendor>(options)` (also `ai.cli.<vendor>` after importing the package) returns a CLI agent. `run(prompt, { cwd, resume, signal, timeoutMs, model, effort, permission, mcp, env, apiKey, args })` starts one session, and returns `CliSession` with `events`, `done()` and `cancel()`.
12
+ - Adapters for Claude Code, Codex, Antigravity, Qwen Code, Kimi Code, Cursor, Copilot, Grok Build, OpenCode, Amp, Factory Droid, Mistral Vibe, Aider and Reasonix. Each records the CLI version, the official sources, and whether it was verified against the real `--help` or against the docs (`adapter.verification`).
13
+ - One event model for every vendor: `session.started`, `message` (deltas and complete messages), `tool.call`, `tool.result`, `usage`, `error` and `session.ended`. `session.done()` resolves `{ status, text, messages, usage, sessionRef, exitCode, signal, error, stderr, durationMs }` and never rejects.
14
+ - Capability probe: before the first run, the CLI's `--version` and help screens are read, and every flag the launch plan relies on must be listed. A missing flag fails the run with `CliError` (`type: "capability"`), naming the flag and the installed version.
15
+ - Secrets never go to argv:
16
+ - API keys travel in the environment (`apiKey`).
17
+ - Per-run MCP servers are written as a mode-0600 file in a private per-run directory, removed after the run.
18
+ - Each run gets a private config home by default (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`, `COPILOT_HOME`, `GROK_HOME`, …). `home` also takes a path you own, or `"inherit"`.
19
+ - `permission` defaults to `"standard"`, the CLI's own non-interactive approval rules. Each vendor's approve-everything mode is used only with `permission: "bypass"`.
20
+ - Windows spawn rules:
21
+ - `PATHEXT` lookup.
22
+ - npm and pnpm `.cmd` shims are unwrapped to `node <script>` (or their native `.exe`).
23
+ - Other batch files fall back to `cmd.exe /d /v:off /s /c` with every argument quoted, refusing bytes `cmd.exe` cannot carry.
24
+ - The prompt moves to stdin or a prompt file when argv cannot carry it.
25
+ - Cancellation (`signal`, `cancel()`) and `timeoutMs` kill the CLI's whole process tree. On POSIX this is its own process group, with SIGTERM then SIGKILL; on Windows, `taskkill /T /F` on its PID.
26
+ - `agent.model(config)` / `cliModel(agent, config)` wraps a CLI agent as a `ModelContract`, so `ai.agent` and its budget, guardrail, observer and fallback middleware can drive a CLI.
27
+ - `createCliAgent(adapter, options)` / `cli.custom(adapter)` and the documented `CliAdapter` interface let apps add vendors. The building blocks are exported: `jsonLinesParser`, `createClaudeStreamParser`, `mcpServersJson`, `toToml`, `mapEffort`, `requirePrivateHome` and more.
28
+
29
+ ### Fixed
30
+
31
+ - `session.cancel()`, or aborting the run's `signal`, after the run has finished no longer signals the CLI's old process group. Once the CLI's pipes close, cancellation is a no-op, so a `finally { session.cancel() }` cannot reach an unrelated process that reused the pid. The abort listener is also removed when the run settles.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Hassan Zohdy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,70 @@
1
- # Temporary Holding Version
1
+ # @warlock.js/ai-cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Drive vendor coding-agent CLIs (Claude Code, Codex, Copilot, Cursor, Grok, …) as first-class `@warlock.js/ai` agents.
4
+
5
+ Many teams run the vendors' own agent CLIs on the subscriptions they already pay for. This package launches those CLIs headless and reduces each vendor's stream to **one event model**. You get resume, process-tree cancellation, usage, per-run MCP servers, and an `ai.agent` model adapter.
6
+
7
+ Built-in adapters, each one verified against the CLI's real `--help` or its official docs:
8
+
9
+ - Claude Code
10
+ - Codex
11
+ - Antigravity
12
+ - Qwen Code
13
+ - Kimi Code
14
+ - Cursor
15
+ - Copilot
16
+ - Grok Build
17
+ - OpenCode
18
+ - Amp
19
+ - Factory Droid
20
+ - Mistral Vibe
21
+ - Aider
22
+ - Reasonix
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ npm install @warlock.js/ai @warlock.js/ai-cli
28
+ ```
29
+
30
+ The vendor CLIs are not dependencies; install the ones you use. The package itself uses only Node built-ins (`node:child_process`, `node:fs`).
31
+
32
+ ## Quick start
33
+
34
+ ```ts
35
+ import { cli } from "@warlock.js/ai-cli";
36
+
37
+ const claude = cli.claudeCode({ model: "sonnet", apiKey: process.env.ANTHROPIC_API_KEY });
38
+ const session = await claude.run("Fix the failing test", { cwd: "/srv/acme-api" });
39
+
40
+ for await (const event of session.events) {
41
+ if (event.type === "message" && event.delta) process.stdout.write(event.text);
42
+ if (event.type === "tool.call") console.log("\n→", event.name);
43
+ }
44
+
45
+ const { status, text, usage, sessionRef, exitCode } = await session.done();
46
+ ```
47
+
48
+ Importing the package also registers `ai.cli` on the shared `ai` object. There is one factory per vendor: `cli.claudeCode`, `cli.codex`, `cli.antigravity`, `cli.qwenCode`, `cli.kimi`, `cli.cursor`, `cli.copilot`, `cli.grok`, `cli.opencode`, `cli.amp`, `cli.droid`, `cli.mistralVibe`, `cli.aider` and `cli.reasonix`. `cli.custom(adapter)` takes your own adapter.
49
+
50
+ ## What you get
51
+
52
+ - **Events:** `session.started`, `message` (deltas or complete), `tool.call`, `tool.result`, `usage`, `error`, `session.ended`.
53
+ - **Result:** `done()` resolves `{ status, text, messages, usage, sessionRef, exitCode, error, stderr }` and never rejects.
54
+ - **Resume** with `{ resume: sessionRef }`. **Cancel** with `signal`, `session.cancel()` or `timeoutMs`; the CLI's whole process tree is killed.
55
+ - **Permissions:** `"standard"` by default (the CLI's own non-interactive rules). Each vendor's approve-everything mode needs an explicit `permission: "bypass"`.
56
+ - **Secrets never in argv:** API keys travel in the environment. MCP servers are written to a 0600 file in a private per-run directory. Each run gets a private config home by default (`CLAUDE_CONFIG_DIR`, `CODEX_HOME`, `COPILOT_HOME`, …).
57
+ - **Capability probe:** the installed CLI's `--help` must list every flag the adapter uses, otherwise the run fails up front, naming the flag and the version.
58
+ - **Windows:** `PATHEXT` lookup. npm `.cmd` shims run as `node <script>`; other batch files fall back to `cmd.exe` with safe quoting. The prompt moves to stdin when argv cannot carry it.
59
+ - **`ai.agent` integration:** `cli.codex().model()` is a `ModelContract`, so budget, guardrail, observer and fallback middleware apply.
60
+
61
+ ## Documentation
62
+
63
+ - [Run coding CLIs as agents](https://warlock.js.org/v/latest/ai/cli-agents/run-cli-agents/)
64
+ - [Vendor adapters](https://warlock.js.org/v/latest/ai/cli-agents/vendors/) — flags, stream formats and verification per CLI
65
+ - [Security and platforms](https://warlock.js.org/v/latest/ai/cli-agents/security-and-platforms/)
66
+ - [Write an adapter](https://warlock.js.org/v/latest/ai/cli-agents/custom-adapter/)
67
+
68
+ ## License
69
+
70
+ MIT