@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.
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +69 -2
- package/cjs/index.cjs +4576 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/adapters/aider.d.mts +41 -0
- package/esm/adapters/aider.d.mts.map +1 -0
- package/esm/adapters/aider.mjs +294 -0
- package/esm/adapters/aider.mjs.map +1 -0
- package/esm/adapters/amp.d.mts +33 -0
- package/esm/adapters/amp.d.mts.map +1 -0
- package/esm/adapters/amp.mjs +119 -0
- package/esm/adapters/amp.mjs.map +1 -0
- package/esm/adapters/antigravity.d.mts +37 -0
- package/esm/adapters/antigravity.d.mts.map +1 -0
- package/esm/adapters/antigravity.mjs +235 -0
- package/esm/adapters/antigravity.mjs.map +1 -0
- package/esm/adapters/claude-code.d.mts +30 -0
- package/esm/adapters/claude-code.d.mts.map +1 -0
- package/esm/adapters/claude-code.mjs +121 -0
- package/esm/adapters/claude-code.mjs.map +1 -0
- package/esm/adapters/claude-stream.d.mts +32 -0
- package/esm/adapters/claude-stream.d.mts.map +1 -0
- package/esm/adapters/claude-stream.mjs +140 -0
- package/esm/adapters/claude-stream.mjs.map +1 -0
- package/esm/adapters/codex.d.mts +37 -0
- package/esm/adapters/codex.d.mts.map +1 -0
- package/esm/adapters/codex.mjs +320 -0
- package/esm/adapters/codex.mjs.map +1 -0
- package/esm/adapters/copilot.d.mts +35 -0
- package/esm/adapters/copilot.d.mts.map +1 -0
- package/esm/adapters/copilot.mjs +244 -0
- package/esm/adapters/copilot.mjs.map +1 -0
- package/esm/adapters/cursor.d.mts +35 -0
- package/esm/adapters/cursor.d.mts.map +1 -0
- package/esm/adapters/cursor.mjs +203 -0
- package/esm/adapters/cursor.mjs.map +1 -0
- package/esm/adapters/droid.d.mts +32 -0
- package/esm/adapters/droid.d.mts.map +1 -0
- package/esm/adapters/droid.mjs +183 -0
- package/esm/adapters/droid.mjs.map +1 -0
- package/esm/adapters/grok.d.mts +32 -0
- package/esm/adapters/grok.d.mts.map +1 -0
- package/esm/adapters/grok.mjs +199 -0
- package/esm/adapters/grok.mjs.map +1 -0
- package/esm/adapters/index.d.mts +16 -0
- package/esm/adapters/index.mjs +18 -0
- package/esm/adapters/kimi.d.mts +34 -0
- package/esm/adapters/kimi.d.mts.map +1 -0
- package/esm/adapters/kimi.mjs +162 -0
- package/esm/adapters/kimi.mjs.map +1 -0
- package/esm/adapters/mistral-vibe.d.mts +32 -0
- package/esm/adapters/mistral-vibe.d.mts.map +1 -0
- package/esm/adapters/mistral-vibe.mjs +252 -0
- package/esm/adapters/mistral-vibe.mjs.map +1 -0
- package/esm/adapters/opencode.d.mts +36 -0
- package/esm/adapters/opencode.d.mts.map +1 -0
- package/esm/adapters/opencode.mjs +219 -0
- package/esm/adapters/opencode.mjs.map +1 -0
- package/esm/adapters/qwen-code.d.mts +30 -0
- package/esm/adapters/qwen-code.d.mts.map +1 -0
- package/esm/adapters/qwen-code.mjs +94 -0
- package/esm/adapters/qwen-code.mjs.map +1 -0
- package/esm/adapters/reasonix.d.mts +31 -0
- package/esm/adapters/reasonix.d.mts.map +1 -0
- package/esm/adapters/reasonix.mjs +250 -0
- package/esm/adapters/reasonix.mjs.map +1 -0
- package/esm/adapters/shared.d.mts +78 -0
- package/esm/adapters/shared.d.mts.map +1 -0
- package/esm/adapters/shared.mjs +161 -0
- package/esm/adapters/shared.mjs.map +1 -0
- package/esm/cli-agent.d.mts +40 -0
- package/esm/cli-agent.d.mts.map +1 -0
- package/esm/cli-agent.mjs +207 -0
- package/esm/cli-agent.mjs.map +1 -0
- package/esm/cli.d.mts +53 -0
- package/esm/cli.d.mts.map +1 -0
- package/esm/cli.mjs +61 -0
- package/esm/cli.mjs.map +1 -0
- package/esm/contracts/adapter.contract.d.mts +154 -0
- package/esm/contracts/adapter.contract.d.mts.map +1 -0
- package/esm/contracts/events.type.d.mts +111 -0
- package/esm/contracts/events.type.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +4 -0
- package/esm/contracts/mcp.type.d.mts +29 -0
- package/esm/contracts/mcp.type.d.mts.map +1 -0
- package/esm/contracts/options.type.d.mts +87 -0
- package/esm/contracts/options.type.d.mts.map +1 -0
- package/esm/errors.d.mts +46 -0
- package/esm/errors.d.mts.map +1 -0
- package/esm/errors.mjs +32 -0
- package/esm/errors.mjs.map +1 -0
- package/esm/index.d.mts +31 -0
- package/esm/index.mjs +28 -0
- package/esm/model/cli-model.d.mts +48 -0
- package/esm/model/cli-model.d.mts.map +1 -0
- package/esm/model/cli-model.mjs +133 -0
- package/esm/model/cli-model.mjs.map +1 -0
- package/esm/probe/probe.d.mts +18 -0
- package/esm/probe/probe.d.mts.map +1 -0
- package/esm/probe/probe.mjs +148 -0
- package/esm/probe/probe.mjs.map +1 -0
- package/esm/session/aggregate.mjs +86 -0
- package/esm/session/aggregate.mjs.map +1 -0
- package/esm/session/environment.mjs +71 -0
- package/esm/session/environment.mjs.map +1 -0
- package/esm/session/run-directory.mjs +74 -0
- package/esm/session/run-directory.mjs.map +1 -0
- package/esm/session/session.mjs +188 -0
- package/esm/session/session.mjs.map +1 -0
- package/esm/spawn/invocation.d.mts +35 -0
- package/esm/spawn/invocation.d.mts.map +1 -0
- package/esm/spawn/invocation.mjs +76 -0
- package/esm/spawn/invocation.mjs.map +1 -0
- package/esm/spawn/process-tree.mjs +57 -0
- package/esm/spawn/process-tree.mjs.map +1 -0
- package/esm/spawn/resolve-command.d.mts +73 -0
- package/esm/spawn/resolve-command.d.mts.map +1 -0
- package/esm/spawn/resolve-command.mjs +109 -0
- package/esm/spawn/resolve-command.mjs.map +1 -0
- package/esm/stream/event-log.mjs +52 -0
- package/esm/stream/event-log.mjs.map +1 -0
- package/esm/stream/json-lines.d.mts +33 -0
- package/esm/stream/json-lines.d.mts.map +1 -0
- package/esm/stream/json-lines.mjs +65 -0
- package/esm/stream/json-lines.mjs.map +1 -0
- package/esm/stream/line-splitter.mjs +53 -0
- package/esm/stream/line-splitter.mjs.map +1 -0
- package/esm/utils/toml.d.mts +22 -0
- package/esm/utils/toml.d.mts.map +1 -0
- package/esm/utils/toml.mjs +53 -0
- package/esm/utils/toml.mjs.map +1 -0
- package/llms-full.txt +373 -0
- package/llms.txt +10 -0
- package/package.json +39 -4
- package/skills/README.md +13 -0
- package/skills/index.md +22 -0
- package/skills/run-cli-agents/SKILL.md +186 -0
- package/skills/write-a-cli-adapter/SKILL.md +173 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CliAdapter, CliStreamParser } from "../contracts/adapter.contract.mjs";
|
|
2
|
+
//#region ../../packages/ai-cli/src/adapters/codex.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* OpenAI Codex CLI (`codex`, npm `@openai/codex`).
|
|
5
|
+
*
|
|
6
|
+
* Verified against the real `codex exec --help` / `codex exec resume
|
|
7
|
+
* --help` of 0.163.0, the source at tag `rust-v0.163.0` (`exec_events.rs`,
|
|
8
|
+
* the JSONL event processor, `cli.rs`) and the docs (non-interactive mode,
|
|
9
|
+
* config reference), 2026-10-17.
|
|
10
|
+
*
|
|
11
|
+
* - Headless: `codex exec --json --skip-git-repo-check <prompt>` (`-` reads
|
|
12
|
+
* the prompt from stdin); resume is `codex exec resume … <thread_id>
|
|
13
|
+
* <prompt>`.
|
|
14
|
+
* - Stream: `thread.started` (`thread_id`), `item.started`/`item.completed`
|
|
15
|
+
* with `item.type` `agent_message`, `reasoning`, `command_execution`,
|
|
16
|
+
* `file_change`, `mcp_tool_call`, `web_search`, `error`; `turn.completed`
|
|
17
|
+
* with the thread's cumulative `usage` (`input_tokens` includes
|
|
18
|
+
* `cached_input_tokens`); `turn.failed` and `error` on failure. No text
|
|
19
|
+
* deltas and no cost field.
|
|
20
|
+
* - Permissions: exec never asks (approval policy "never"); `standard` keeps
|
|
21
|
+
* Codex's default **read-only** sandbox — allow edits with
|
|
22
|
+
* `args: ["-c", "sandbox_mode=workspace-write"]`. Bypass is
|
|
23
|
+
* `--dangerously-bypass-approvals-and-sandbox`.
|
|
24
|
+
* - Effort: `-c model_reasoning_effort=<level>`.
|
|
25
|
+
* - MCP: no flag. With a private home the servers go into
|
|
26
|
+
* `$CODEX_HOME/config.toml` (0600). With a caller-owned or inherited home
|
|
27
|
+
* they are passed as `-c mcp_servers.<name>.…` overrides that carry only
|
|
28
|
+
* the command, args and URL; secret `env` values and headers travel in the
|
|
29
|
+
* process environment, named through `env_vars` / `env_http_headers`.
|
|
30
|
+
* - Home `CODEX_HOME`; auth `CODEX_API_KEY`.
|
|
31
|
+
*/
|
|
32
|
+
declare const codexAdapter: CliAdapter;
|
|
33
|
+
/** Parser for `codex exec --json`. */
|
|
34
|
+
declare function createCodexParser(): CliStreamParser;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { codexAdapter, createCodexParser };
|
|
37
|
+
//# sourceMappingURL=codex.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/codex.ts"],"mappings":";;;;;AA+CA;;;;AA0FC;AAgJD;;;;AAAoD;;;;;;;;;;;;;;;;;cA1OvC,YAAA,EAAc,UA0F1B;;iBAgJe,iBAAA,IAAqB,eAAe"}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { jsonLinesParser, numberField, outputText, recordField, stringField } from "../stream/json-lines.mjs";
|
|
2
|
+
import { toToml, tomlKey } from "../utils/toml.mjs";
|
|
3
|
+
import { argvPrompt, mapEffort, unsupportedOption, usageOf } from "./shared.mjs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
//#region ../../packages/ai-cli/src/adapters/codex.ts
|
|
7
|
+
/**
|
|
8
|
+
* OpenAI Codex CLI (`codex`, npm `@openai/codex`).
|
|
9
|
+
*
|
|
10
|
+
* Verified against the real `codex exec --help` / `codex exec resume
|
|
11
|
+
* --help` of 0.163.0, the source at tag `rust-v0.163.0` (`exec_events.rs`,
|
|
12
|
+
* the JSONL event processor, `cli.rs`) and the docs (non-interactive mode,
|
|
13
|
+
* config reference), 2026-10-17.
|
|
14
|
+
*
|
|
15
|
+
* - Headless: `codex exec --json --skip-git-repo-check <prompt>` (`-` reads
|
|
16
|
+
* the prompt from stdin); resume is `codex exec resume … <thread_id>
|
|
17
|
+
* <prompt>`.
|
|
18
|
+
* - Stream: `thread.started` (`thread_id`), `item.started`/`item.completed`
|
|
19
|
+
* with `item.type` `agent_message`, `reasoning`, `command_execution`,
|
|
20
|
+
* `file_change`, `mcp_tool_call`, `web_search`, `error`; `turn.completed`
|
|
21
|
+
* with the thread's cumulative `usage` (`input_tokens` includes
|
|
22
|
+
* `cached_input_tokens`); `turn.failed` and `error` on failure. No text
|
|
23
|
+
* deltas and no cost field.
|
|
24
|
+
* - Permissions: exec never asks (approval policy "never"); `standard` keeps
|
|
25
|
+
* Codex's default **read-only** sandbox — allow edits with
|
|
26
|
+
* `args: ["-c", "sandbox_mode=workspace-write"]`. Bypass is
|
|
27
|
+
* `--dangerously-bypass-approvals-and-sandbox`.
|
|
28
|
+
* - Effort: `-c model_reasoning_effort=<level>`.
|
|
29
|
+
* - MCP: no flag. With a private home the servers go into
|
|
30
|
+
* `$CODEX_HOME/config.toml` (0600). With a caller-owned or inherited home
|
|
31
|
+
* they are passed as `-c mcp_servers.<name>.…` overrides that carry only
|
|
32
|
+
* the command, args and URL; secret `env` values and headers travel in the
|
|
33
|
+
* process environment, named through `env_vars` / `env_http_headers`.
|
|
34
|
+
* - Home `CODEX_HOME`; auth `CODEX_API_KEY`.
|
|
35
|
+
*/
|
|
36
|
+
const codexAdapter = {
|
|
37
|
+
name: "codex",
|
|
38
|
+
title: "Codex CLI",
|
|
39
|
+
command: "codex",
|
|
40
|
+
apiKeyEnv: ["CODEX_API_KEY"],
|
|
41
|
+
homeEnv: ["CODEX_HOME"],
|
|
42
|
+
transports: ["argv", "stdin"],
|
|
43
|
+
effort: true,
|
|
44
|
+
mcp: true,
|
|
45
|
+
probe: {
|
|
46
|
+
help: [["exec", "--help"], [
|
|
47
|
+
"exec",
|
|
48
|
+
"resume",
|
|
49
|
+
"--help"
|
|
50
|
+
]],
|
|
51
|
+
version: ["--version"]
|
|
52
|
+
},
|
|
53
|
+
verification: {
|
|
54
|
+
version: "0.163.0",
|
|
55
|
+
verifiedBy: "help",
|
|
56
|
+
sources: [
|
|
57
|
+
"https://developers.openai.com/codex/noninteractive",
|
|
58
|
+
"https://developers.openai.com/codex/config-reference",
|
|
59
|
+
"https://github.com/openai/codex/blob/rust-v0.163.0/codex-rs/exec/src/exec_events.rs"
|
|
60
|
+
],
|
|
61
|
+
checkedAt: "2026-10-17"
|
|
62
|
+
},
|
|
63
|
+
plan(context) {
|
|
64
|
+
const args = ["exec"];
|
|
65
|
+
const requires = [
|
|
66
|
+
"exec",
|
|
67
|
+
"--json",
|
|
68
|
+
"--skip-git-repo-check"
|
|
69
|
+
];
|
|
70
|
+
const files = [];
|
|
71
|
+
const env = {};
|
|
72
|
+
if (context.resume !== void 0) {
|
|
73
|
+
args.push("resume");
|
|
74
|
+
requires.push("resume");
|
|
75
|
+
}
|
|
76
|
+
args.push("--json", "--skip-git-repo-check", "-c", "check_for_update_on_startup=false");
|
|
77
|
+
if (context.model !== void 0) {
|
|
78
|
+
args.push("--model", context.model);
|
|
79
|
+
requires.push("--model");
|
|
80
|
+
}
|
|
81
|
+
if (context.effort !== void 0) {
|
|
82
|
+
const effort = mapEffort(context.effort, {
|
|
83
|
+
low: "low",
|
|
84
|
+
medium: "medium",
|
|
85
|
+
high: "high",
|
|
86
|
+
xhigh: "xhigh",
|
|
87
|
+
max: "max"
|
|
88
|
+
});
|
|
89
|
+
args.push("-c", `model_reasoning_effort=${effort}`);
|
|
90
|
+
requires.push("--config");
|
|
91
|
+
}
|
|
92
|
+
if (context.permission === "bypass") {
|
|
93
|
+
args.push("--dangerously-bypass-approvals-and-sandbox");
|
|
94
|
+
requires.push("--dangerously-bypass-approvals-and-sandbox");
|
|
95
|
+
}
|
|
96
|
+
if (context.mcp !== void 0) if (context.home !== void 0 && context.homeIsPrivate) files.push({
|
|
97
|
+
path: path.join(context.home, "config.toml"),
|
|
98
|
+
content: toToml({ mcp_servers: codexMcpTable(context.mcp) })
|
|
99
|
+
});
|
|
100
|
+
else {
|
|
101
|
+
args.push(...codexMcpOverrides(context.mcp, env));
|
|
102
|
+
requires.push("--config");
|
|
103
|
+
}
|
|
104
|
+
if (context.home !== void 0) env.CODEX_HOME = context.home;
|
|
105
|
+
const prompt = context.transport === "argv" ? argvPrompt(context.prompt) : "-";
|
|
106
|
+
return {
|
|
107
|
+
args,
|
|
108
|
+
tail: context.resume !== void 0 ? [context.resume, prompt] : [prompt],
|
|
109
|
+
stdin: context.transport === "stdin" ? context.prompt : void 0,
|
|
110
|
+
env,
|
|
111
|
+
files,
|
|
112
|
+
requires
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
parser: createCodexParser
|
|
116
|
+
};
|
|
117
|
+
/** `[mcp_servers.<name>]` tables for a private `config.toml`. */
|
|
118
|
+
function codexMcpTable(servers) {
|
|
119
|
+
const table = {};
|
|
120
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
121
|
+
if (server.type === "sse") throw unsupportedOption(codexAdapter, `MCP server "${name}" uses SSE; Codex supports stdio and streamable HTTP.`);
|
|
122
|
+
table[name] = server.type === "stdio" ? {
|
|
123
|
+
command: server.command,
|
|
124
|
+
args: server.args ?? [],
|
|
125
|
+
env: server.env
|
|
126
|
+
} : {
|
|
127
|
+
url: server.url,
|
|
128
|
+
http_headers: server.headers
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return table;
|
|
132
|
+
}
|
|
133
|
+
/** A TOML string for a `-c key=value` override. */
|
|
134
|
+
function tomlString(value) {
|
|
135
|
+
return JSON.stringify(value);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* `-c` overrides that carry no secret: env values and header values are put
|
|
139
|
+
* in `env` (the Codex process environment) and only their names go to argv.
|
|
140
|
+
*/
|
|
141
|
+
function codexMcpOverrides(servers, env) {
|
|
142
|
+
const overrides = [];
|
|
143
|
+
const claim = (name, value) => {
|
|
144
|
+
if (env[name] !== void 0 && env[name] !== value) throw unsupportedOption(codexAdapter, `two MCP servers set ${name} to different values; with a shared home they share one environment.`);
|
|
145
|
+
env[name] = value;
|
|
146
|
+
};
|
|
147
|
+
for (const [name, server] of Object.entries(servers)) {
|
|
148
|
+
const prefix = `mcp_servers.${tomlKey(name)}`;
|
|
149
|
+
if (server.type === "sse") throw unsupportedOption(codexAdapter, `MCP server "${name}" uses SSE; Codex supports stdio and streamable HTTP.`);
|
|
150
|
+
if (server.type === "stdio") {
|
|
151
|
+
overrides.push("-c", `${prefix}.command=${tomlString(server.command)}`);
|
|
152
|
+
overrides.push("-c", `${prefix}.args=[${(server.args ?? []).map(tomlString).join(",")}]`);
|
|
153
|
+
const names = Object.keys(server.env ?? {});
|
|
154
|
+
for (const [key, value] of Object.entries(server.env ?? {})) claim(key, value);
|
|
155
|
+
if (names.length > 0) overrides.push("-c", `${prefix}.env_vars=[${names.map(tomlString).join(",")}]`);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
overrides.push("-c", `${prefix}.url=${tomlString(server.url)}`);
|
|
159
|
+
const headers = Object.entries(server.headers ?? {});
|
|
160
|
+
if (headers.length > 0) {
|
|
161
|
+
const mapping = headers.map(([header, value], index) => {
|
|
162
|
+
const variable = `WARLOCK_MCP_${name.replace(/\W/g, "_").toUpperCase()}_HEADER_${index}`;
|
|
163
|
+
claim(variable, value);
|
|
164
|
+
return `${tomlString(header)}=${tomlString(variable)}`;
|
|
165
|
+
});
|
|
166
|
+
overrides.push("-c", `${prefix}.env_http_headers={${mapping.join(",")}}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return overrides;
|
|
170
|
+
}
|
|
171
|
+
const TOOL_ITEMS = new Set([
|
|
172
|
+
"command_execution",
|
|
173
|
+
"file_change",
|
|
174
|
+
"mcp_tool_call",
|
|
175
|
+
"web_search",
|
|
176
|
+
"collab_tool_call"
|
|
177
|
+
]);
|
|
178
|
+
function toolCall(item) {
|
|
179
|
+
switch (stringField(item, "type")) {
|
|
180
|
+
case "command_execution": return {
|
|
181
|
+
name: "shell",
|
|
182
|
+
input: { command: item.command }
|
|
183
|
+
};
|
|
184
|
+
case "file_change": return {
|
|
185
|
+
name: "apply_patch",
|
|
186
|
+
input: { changes: item.changes }
|
|
187
|
+
};
|
|
188
|
+
case "mcp_tool_call": return {
|
|
189
|
+
name: `${stringField(item, "server") ?? "mcp"}.${stringField(item, "tool") ?? "tool"}`,
|
|
190
|
+
input: item.arguments
|
|
191
|
+
};
|
|
192
|
+
case "web_search": return {
|
|
193
|
+
name: "web_search",
|
|
194
|
+
input: { query: item.query }
|
|
195
|
+
};
|
|
196
|
+
default: return {
|
|
197
|
+
name: stringField(item, "type") ?? "tool",
|
|
198
|
+
input: item
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function toolResult(item) {
|
|
203
|
+
const status = stringField(item, "status");
|
|
204
|
+
const failed = status === "failed" || status === "declined";
|
|
205
|
+
switch (stringField(item, "type")) {
|
|
206
|
+
case "command_execution": {
|
|
207
|
+
const exitCode = numberField(item, "exit_code");
|
|
208
|
+
return {
|
|
209
|
+
output: stringField(item, "aggregated_output") ?? "",
|
|
210
|
+
isError: failed || exitCode !== void 0 && exitCode !== 0
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
case "mcp_tool_call": {
|
|
214
|
+
const error = stringField(recordField(item, "error"), "message");
|
|
215
|
+
return error !== void 0 ? {
|
|
216
|
+
output: error,
|
|
217
|
+
isError: true
|
|
218
|
+
} : {
|
|
219
|
+
output: outputText(recordField(item, "result")?.content),
|
|
220
|
+
isError: failed
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
default: return {
|
|
224
|
+
output: outputText(item.changes ?? item.result ?? ""),
|
|
225
|
+
isError: failed
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/** Parser for `codex exec --json`. */
|
|
230
|
+
function createCodexParser() {
|
|
231
|
+
const announced = /* @__PURE__ */ new Set();
|
|
232
|
+
return jsonLinesParser((record) => {
|
|
233
|
+
const type = stringField(record, "type");
|
|
234
|
+
const item = recordField(record, "item");
|
|
235
|
+
const itemType = stringField(item, "type");
|
|
236
|
+
const id = stringField(item, "id") ?? "";
|
|
237
|
+
if (type === "thread.started") return [{
|
|
238
|
+
type: "session.started",
|
|
239
|
+
sessionRef: stringField(record, "thread_id"),
|
|
240
|
+
raw: record
|
|
241
|
+
}];
|
|
242
|
+
if (type === "item.started" && item !== void 0 && itemType !== void 0 && TOOL_ITEMS.has(itemType)) {
|
|
243
|
+
announced.add(id);
|
|
244
|
+
return [{
|
|
245
|
+
type: "tool.call",
|
|
246
|
+
id,
|
|
247
|
+
...toolCall(item),
|
|
248
|
+
raw: record
|
|
249
|
+
}];
|
|
250
|
+
}
|
|
251
|
+
if (type === "item.completed" && item !== void 0) {
|
|
252
|
+
if (itemType === "agent_message") {
|
|
253
|
+
const text = stringField(item, "text") ?? "";
|
|
254
|
+
return text.length > 0 ? [{
|
|
255
|
+
type: "message",
|
|
256
|
+
text,
|
|
257
|
+
delta: false,
|
|
258
|
+
raw: record
|
|
259
|
+
}] : [];
|
|
260
|
+
}
|
|
261
|
+
if (itemType === "error") return [{
|
|
262
|
+
type: "error",
|
|
263
|
+
message: stringField(item, "message") ?? "error",
|
|
264
|
+
raw: record
|
|
265
|
+
}];
|
|
266
|
+
if (itemType !== void 0 && TOOL_ITEMS.has(itemType)) {
|
|
267
|
+
const events = [];
|
|
268
|
+
if (!announced.has(id)) events.push({
|
|
269
|
+
type: "tool.call",
|
|
270
|
+
id,
|
|
271
|
+
...toolCall(item),
|
|
272
|
+
raw: record
|
|
273
|
+
});
|
|
274
|
+
events.push({
|
|
275
|
+
type: "tool.result",
|
|
276
|
+
id,
|
|
277
|
+
...toolResult(item),
|
|
278
|
+
raw: record
|
|
279
|
+
});
|
|
280
|
+
return events;
|
|
281
|
+
}
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
284
|
+
if (type === "turn.completed") {
|
|
285
|
+
const usage = recordField(record, "usage");
|
|
286
|
+
if (usage === void 0) return [];
|
|
287
|
+
const cached = numberField(usage, "cached_input_tokens");
|
|
288
|
+
const written = numberField(usage, "cache_write_input_tokens");
|
|
289
|
+
return [{
|
|
290
|
+
type: "usage",
|
|
291
|
+
cumulative: true,
|
|
292
|
+
usage: usageOf({
|
|
293
|
+
input: numberField(usage, "input_tokens"),
|
|
294
|
+
output: numberField(usage, "output_tokens"),
|
|
295
|
+
cachedTokens: cached !== void 0 && cached > 0 ? cached : void 0,
|
|
296
|
+
cacheWriteTokens: written !== void 0 && written > 0 ? written : void 0,
|
|
297
|
+
reasoningTokens: numberField(usage, "reasoning_output_tokens") || void 0
|
|
298
|
+
}),
|
|
299
|
+
raw: record
|
|
300
|
+
}];
|
|
301
|
+
}
|
|
302
|
+
if (type === "turn.failed") return [{
|
|
303
|
+
type: "error",
|
|
304
|
+
message: stringField(recordField(record, "error"), "message") ?? "Codex turn failed",
|
|
305
|
+
fatal: true,
|
|
306
|
+
raw: record
|
|
307
|
+
}];
|
|
308
|
+
if (type === "error") return [{
|
|
309
|
+
type: "error",
|
|
310
|
+
message: stringField(record, "message") ?? "Codex error",
|
|
311
|
+
fatal: true,
|
|
312
|
+
raw: record
|
|
313
|
+
}];
|
|
314
|
+
return [];
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
//#endregion
|
|
319
|
+
export { codexAdapter, createCodexParser };
|
|
320
|
+
//# sourceMappingURL=codex.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.mjs","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/codex.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, tomlKey, toToml } from \"../utils/toml\";\nimport { argvPrompt, mapEffort, unsupportedOption, usageOf } from \"./shared\";\n\n/**\n * OpenAI Codex CLI (`codex`, npm `@openai/codex`).\n *\n * Verified against the real `codex exec --help` / `codex exec resume\n * --help` of 0.163.0, the source at tag `rust-v0.163.0` (`exec_events.rs`,\n * the JSONL event processor, `cli.rs`) and the docs (non-interactive mode,\n * config reference), 2026-10-17.\n *\n * - Headless: `codex exec --json --skip-git-repo-check <prompt>` (`-` reads\n * the prompt from stdin); resume is `codex exec resume … <thread_id>\n * <prompt>`.\n * - Stream: `thread.started` (`thread_id`), `item.started`/`item.completed`\n * with `item.type` `agent_message`, `reasoning`, `command_execution`,\n * `file_change`, `mcp_tool_call`, `web_search`, `error`; `turn.completed`\n * with the thread's cumulative `usage` (`input_tokens` includes\n * `cached_input_tokens`); `turn.failed` and `error` on failure. No text\n * deltas and no cost field.\n * - Permissions: exec never asks (approval policy \"never\"); `standard` keeps\n * Codex's default **read-only** sandbox — allow edits with\n * `args: [\"-c\", \"sandbox_mode=workspace-write\"]`. Bypass is\n * `--dangerously-bypass-approvals-and-sandbox`.\n * - Effort: `-c model_reasoning_effort=<level>`.\n * - MCP: no flag. With a private home the servers go into\n * `$CODEX_HOME/config.toml` (0600). With a caller-owned or inherited home\n * they are passed as `-c mcp_servers.<name>.…` overrides that carry only\n * the command, args and URL; secret `env` values and headers travel in the\n * process environment, named through `env_vars` / `env_http_headers`.\n * - Home `CODEX_HOME`; auth `CODEX_API_KEY`.\n */\nexport const codexAdapter: CliAdapter = {\n name: \"codex\",\n title: \"Codex CLI\",\n command: \"codex\",\n apiKeyEnv: [\"CODEX_API_KEY\"],\n homeEnv: [\"CODEX_HOME\"],\n transports: [\"argv\", \"stdin\"],\n effort: true,\n mcp: true,\n probe: {\n help: [\n [\"exec\", \"--help\"],\n [\"exec\", \"resume\", \"--help\"],\n ],\n version: [\"--version\"],\n },\n verification: {\n version: \"0.163.0\",\n verifiedBy: \"help\",\n sources: [\n \"https://developers.openai.com/codex/noninteractive\",\n \"https://developers.openai.com/codex/config-reference\",\n \"https://github.com/openai/codex/blob/rust-v0.163.0/codex-rs/exec/src/exec_events.rs\",\n ],\n checkedAt: \"2026-10-17\",\n },\n plan(context) {\n const args = [\"exec\"];\n const requires = [\"exec\", \"--json\", \"--skip-git-repo-check\"];\n const files: CliLaunchFile[] = [];\n const env: Record<string, string> = {};\n\n if (context.resume !== undefined) {\n args.push(\"resume\");\n requires.push(\"resume\");\n }\n\n args.push(\"--json\", \"--skip-git-repo-check\", \"-c\", \"check_for_update_on_startup=false\");\n\n if (context.model !== undefined) {\n args.push(\"--model\", context.model);\n requires.push(\"--model\");\n }\n\n if (context.effort !== undefined) {\n const effort = mapEffort(context.effort, {\n low: \"low\",\n medium: \"medium\",\n high: \"high\",\n xhigh: \"xhigh\",\n max: \"max\",\n });\n\n args.push(\"-c\", `model_reasoning_effort=${effort}`);\n requires.push(\"--config\");\n }\n\n if (context.permission === \"bypass\") {\n args.push(\"--dangerously-bypass-approvals-and-sandbox\");\n requires.push(\"--dangerously-bypass-approvals-and-sandbox\");\n }\n\n if (context.mcp !== undefined) {\n if (context.home !== undefined && context.homeIsPrivate) {\n files.push({\n path: path.join(context.home, \"config.toml\"),\n content: toToml({ mcp_servers: codexMcpTable(context.mcp) }),\n });\n } else {\n args.push(...codexMcpOverrides(context.mcp, env));\n requires.push(\"--config\");\n }\n }\n\n if (context.home !== undefined) {\n env.CODEX_HOME = context.home;\n }\n\n const prompt = context.transport === \"argv\" ? argvPrompt(context.prompt) : \"-\";\n\n return {\n args,\n tail: context.resume !== undefined ? [context.resume, prompt] : [prompt],\n stdin: context.transport === \"stdin\" ? context.prompt : undefined,\n env,\n files,\n requires,\n };\n },\n parser: createCodexParser,\n};\n\n/** `[mcp_servers.<name>]` tables for a private `config.toml`. */\nfunction codexMcpTable(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 codexAdapter,\n `MCP server \"${name}\" uses SSE; Codex supports stdio and streamable HTTP.`,\n );\n }\n\n table[name] =\n server.type === \"stdio\"\n ? { command: server.command, args: server.args ?? [], env: server.env }\n : { url: server.url, http_headers: server.headers };\n }\n\n return table;\n}\n\n/** A TOML string for a `-c key=value` override. */\nfunction tomlString(value: string): string {\n return JSON.stringify(value);\n}\n\n/**\n * `-c` overrides that carry no secret: env values and header values are put\n * in `env` (the Codex process environment) and only their names go to argv.\n */\nfunction codexMcpOverrides(servers: CliMcpServers, env: Record<string, string>): string[] {\n const overrides: string[] = [];\n const claim = (name: string, value: string): void => {\n if (env[name] !== undefined && env[name] !== value) {\n throw unsupportedOption(\n codexAdapter,\n `two MCP servers set ${name} to different values; with a shared home they share one environment.`,\n );\n }\n\n env[name] = value;\n };\n\n for (const [name, server] of Object.entries(servers)) {\n const prefix = `mcp_servers.${tomlKey(name)}`;\n\n if (server.type === \"sse\") {\n throw unsupportedOption(\n codexAdapter,\n `MCP server \"${name}\" uses SSE; Codex supports stdio and streamable HTTP.`,\n );\n }\n\n if (server.type === \"stdio\") {\n overrides.push(\"-c\", `${prefix}.command=${tomlString(server.command)}`);\n overrides.push(\"-c\", `${prefix}.args=[${(server.args ?? []).map(tomlString).join(\",\")}]`);\n\n const names = Object.keys(server.env ?? {});\n\n for (const [key, value] of Object.entries(server.env ?? {})) {\n claim(key, value);\n }\n\n if (names.length > 0) {\n overrides.push(\"-c\", `${prefix}.env_vars=[${names.map(tomlString).join(\",\")}]`);\n }\n\n continue;\n }\n\n overrides.push(\"-c\", `${prefix}.url=${tomlString(server.url)}`);\n\n const headers = Object.entries(server.headers ?? {});\n\n if (headers.length > 0) {\n const mapping = headers.map(([header, value], index) => {\n const variable = `WARLOCK_MCP_${name.replace(/\\W/g, \"_\").toUpperCase()}_HEADER_${index}`;\n\n claim(variable, value);\n\n return `${tomlString(header)}=${tomlString(variable)}`;\n });\n\n overrides.push(\"-c\", `${prefix}.env_http_headers={${mapping.join(\",\")}}`);\n }\n }\n\n return overrides;\n}\n\nconst TOOL_ITEMS = new Set([\n \"command_execution\",\n \"file_change\",\n \"mcp_tool_call\",\n \"web_search\",\n \"collab_tool_call\",\n]);\n\nfunction toolCall(item: Record<string, unknown>): { name: string; input: unknown } {\n switch (stringField(item, \"type\")) {\n case \"command_execution\":\n return { name: \"shell\", input: { command: item.command } };\n case \"file_change\":\n return { name: \"apply_patch\", input: { changes: item.changes } };\n case \"mcp_tool_call\":\n return {\n name: `${stringField(item, \"server\") ?? \"mcp\"}.${stringField(item, \"tool\") ?? \"tool\"}`,\n input: item.arguments,\n };\n case \"web_search\":\n return { name: \"web_search\", input: { query: item.query } };\n default:\n return { name: stringField(item, \"type\") ?? \"tool\", input: item };\n }\n}\n\nfunction toolResult(item: Record<string, unknown>): { output: string; isError: boolean } {\n const status = stringField(item, \"status\");\n const failed = status === \"failed\" || status === \"declined\";\n\n switch (stringField(item, \"type\")) {\n case \"command_execution\": {\n const exitCode = numberField(item, \"exit_code\");\n\n return {\n output: stringField(item, \"aggregated_output\") ?? \"\",\n isError: failed || (exitCode !== undefined && exitCode !== 0),\n };\n }\n case \"mcp_tool_call\": {\n const error = stringField(recordField(item, \"error\"), \"message\");\n\n return error !== undefined\n ? { output: error, isError: true }\n : { output: outputText(recordField(item, \"result\")?.content), isError: failed };\n }\n default:\n return { output: outputText(item.changes ?? item.result ?? \"\"), isError: failed };\n }\n}\n\n/** Parser for `codex exec --json`. */\nexport function createCodexParser(): CliStreamParser {\n const announced = new Set<string>();\n\n return jsonLinesParser((record): CliParsedEvent[] => {\n const type = stringField(record, \"type\");\n const item = recordField(record, \"item\");\n const itemType = stringField(item, \"type\");\n const id = stringField(item, \"id\") ?? \"\";\n\n if (type === \"thread.started\") {\n return [\n { type: \"session.started\", sessionRef: stringField(record, \"thread_id\"), raw: record },\n ];\n }\n\n if (\n type === \"item.started\" &&\n item !== undefined &&\n itemType !== undefined &&\n TOOL_ITEMS.has(itemType)\n ) {\n announced.add(id);\n\n return [{ type: \"tool.call\", id, ...toolCall(item), raw: record }];\n }\n\n if (type === \"item.completed\" && item !== undefined) {\n if (itemType === \"agent_message\") {\n const text = stringField(item, \"text\") ?? \"\";\n\n return text.length > 0 ? [{ type: \"message\", text, delta: false, raw: record }] : [];\n }\n\n if (itemType === \"error\") {\n return [{ type: \"error\", message: stringField(item, \"message\") ?? \"error\", raw: record }];\n }\n\n if (itemType !== undefined && TOOL_ITEMS.has(itemType)) {\n const events: CliParsedEvent[] = [];\n\n if (!announced.has(id)) {\n events.push({ type: \"tool.call\", id, ...toolCall(item), raw: record });\n }\n\n events.push({ type: \"tool.result\", id, ...toolResult(item), raw: record });\n\n return events;\n }\n\n return [];\n }\n\n if (type === \"turn.completed\") {\n const usage = recordField(record, \"usage\");\n\n if (usage === undefined) {\n return [];\n }\n\n const cached = numberField(usage, \"cached_input_tokens\");\n const written = numberField(usage, \"cache_write_input_tokens\");\n\n return [\n {\n type: \"usage\",\n cumulative: true,\n usage: usageOf({\n input: numberField(usage, \"input_tokens\"),\n output: numberField(usage, \"output_tokens\"),\n cachedTokens: cached !== undefined && cached > 0 ? cached : undefined,\n cacheWriteTokens: written !== undefined && written > 0 ? written : undefined,\n reasoningTokens: numberField(usage, \"reasoning_output_tokens\") || undefined,\n }),\n raw: record,\n },\n ];\n }\n\n if (type === \"turn.failed\") {\n return [\n {\n type: \"error\",\n message: stringField(recordField(record, \"error\"), \"message\") ?? \"Codex turn failed\",\n fatal: true,\n raw: record,\n },\n ];\n }\n\n if (type === \"error\") {\n return [\n {\n type: \"error\",\n message: stringField(record, \"message\") ?? \"Codex error\",\n fatal: true,\n raw: record,\n },\n ];\n }\n\n return [];\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AAI,SAAS;KAC5D,kBAAkB,YAAY,UAAa,UAAU,IAAI,UAAU;KACnE,iBAAiB,YAAY,OAAO,yBAAyB,KAAK;IACpE,CAAC;IACD,KAAK;GACP,CACF;EACF;EAEA,IAAI,SAAS,eACX,OAAO,CACL;GACE,MAAM;GACN,SAAS,YAAY,YAAY,QAAQ,OAAO,GAAG,SAAS,KAAK;GACjE,OAAO;GACP,KAAK;EACP,CACF;EAGF,IAAI,SAAS,SACX,OAAO,CACL;GACE,MAAM;GACN,SAAS,YAAY,QAAQ,SAAS,KAAK;GAC3C,OAAO;GACP,KAAK;EACP,CACF;EAGF,OAAO,CAAC;CACV,CAAC;AACH"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CliAdapter, CliLaunchContext, CliStreamParser } from "../contracts/adapter.contract.mjs";
|
|
2
|
+
//#region ../../packages/ai-cli/src/adapters/copilot.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* GitHub Copilot CLI (`copilot`, npm `@github/copilot`).
|
|
5
|
+
*
|
|
6
|
+
* Verified against the real `copilot --help` of 1.0.98, the JSONL writer in
|
|
7
|
+
* the shipped CLI, the event types of `@github/copilot-sdk` 1.0.22 and the
|
|
8
|
+
* docs (`docs.github.com/copilot/how-tos/copilot-cli/…`, programmatic and
|
|
9
|
+
* command references), 2026-10-17.
|
|
10
|
+
*
|
|
11
|
+
* - Headless: `copilot -p <prompt> --output-format json --stream on`
|
|
12
|
+
* (piped stdin is the prompt when `-p` is absent). Stream lines are
|
|
13
|
+
* session events `{type,data,id,timestamp}`: `assistant.message_delta`
|
|
14
|
+
* (`deltaContent`), `assistant.message` (`content`),
|
|
15
|
+
* `tool.execution_start` (`toolCallId`, `toolName`, `arguments`),
|
|
16
|
+
* `tool.execution_complete` (`success`, `result.content`,
|
|
17
|
+
* `error.message`), `session.error`, and a final CLI-built `result`
|
|
18
|
+
* (`sessionId`, `exitCode`, premium-request usage).
|
|
19
|
+
* - Tokens are not in the stream; the adapter passes `--usage-output-file`
|
|
20
|
+
* and reads `modelMetrics.*.usage` from it when the stream ends. Billing
|
|
21
|
+
* is in premium requests, so no USD cost is reported.
|
|
22
|
+
* - Permissions: unapproved tool requests are auto-denied in `-p` mode;
|
|
23
|
+
* bypass is `--allow-all` (tools, paths and URLs). `--no-ask-user` and
|
|
24
|
+
* `--no-auto-update` are always passed.
|
|
25
|
+
* - MCP: `--additional-mcp-config @<file>` (`mcpServers`, `type`
|
|
26
|
+
* `local`/`http`/`sse`, `tools: ["*"]`), written to the run directory.
|
|
27
|
+
* - Home `COPILOT_HOME`; auth `COPILOT_GITHUB_TOKEN`. Resume with
|
|
28
|
+
* `--session-id <id>`.
|
|
29
|
+
*/
|
|
30
|
+
declare const copilotAdapter: CliAdapter;
|
|
31
|
+
/** Parser for `copilot -p … --output-format json` (plus its usage file). */
|
|
32
|
+
declare function createCopilotParser(context?: CliLaunchContext): CliStreamParser;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { copilotAdapter, createCopilotParser };
|
|
35
|
+
//# sourceMappingURL=copilot.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot.d.mts","names":[],"sources":["../../../../../../../../packages/ai-cli/src/adapters/copilot.ts"],"mappings":";;;;;AAkDA;;;;AAsFC;AAqDD;;;;;;;;AAAgF;;;;;;;;;;;cA3InE,cAAA,EAAgB,UAsF5B;;iBAqDe,mBAAA,CAAoB,OAAA,GAAU,gBAAA,GAAmB,eAAe"}
|