wide-cli 0.5.1611261726 → 0.6.191126
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/data/osv-bundle.json +1 -1
- package/data/rules.json +1 -1
- package/dist/agent/index.d.ts +25 -3
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +117 -18
- package/dist/agent/index.js.map +1 -1
- package/dist/completion.js +5 -5
- package/dist/completion.js.map +1 -1
- package/dist/config/index.d.ts +4 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +9 -2
- package/dist/config/index.js.map +1 -1
- package/dist/fix.d.ts +25 -0
- package/dist/fix.d.ts.map +1 -0
- package/dist/fix.js +197 -0
- package/dist/fix.js.map +1 -0
- package/dist/hook.d.ts +31 -0
- package/dist/hook.d.ts.map +1 -0
- package/dist/hook.js +152 -0
- package/dist/hook.js.map +1 -0
- package/dist/index.js +168 -5
- package/dist/index.js.map +1 -1
- package/dist/providers/antigravity.d.ts +46 -0
- package/dist/providers/antigravity.d.ts.map +1 -0
- package/dist/providers/antigravity.js +496 -0
- package/dist/providers/antigravity.js.map +1 -0
- package/dist/providers/claude-code.d.ts +60 -0
- package/dist/providers/claude-code.d.ts.map +1 -0
- package/dist/providers/claude-code.js +973 -0
- package/dist/providers/claude-code.js.map +1 -0
- package/dist/providers/codex.d.ts +52 -0
- package/dist/providers/codex.d.ts.map +1 -0
- package/dist/providers/codex.js +742 -0
- package/dist/providers/codex.js.map +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +33 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/repl/commands.d.ts.map +1 -1
- package/dist/repl/commands.js +53 -3
- package/dist/repl/commands.js.map +1 -1
- package/dist/repl/index.d.ts +3 -0
- package/dist/repl/index.d.ts.map +1 -1
- package/dist/repl/index.js +11 -6
- package/dist/repl/index.js.map +1 -1
- package/dist/repl/setup.d.ts.map +1 -1
- package/dist/repl/setup.js +16 -4
- package/dist/repl/setup.js.map +1 -1
- package/dist/security/crawler.d.ts +90 -0
- package/dist/security/crawler.d.ts.map +1 -0
- package/dist/security/crawler.js +622 -0
- package/dist/security/crawler.js.map +1 -0
- package/dist/security/fuzzer.d.ts +1 -0
- package/dist/security/fuzzer.d.ts.map +1 -1
- package/dist/security/fuzzer.js +25 -1
- package/dist/security/fuzzer.js.map +1 -1
- package/dist/security/inspect/evasion-decode.d.ts +41 -0
- package/dist/security/inspect/evasion-decode.d.ts.map +1 -0
- package/dist/security/inspect/evasion-decode.js +316 -0
- package/dist/security/inspect/evasion-decode.js.map +1 -0
- package/dist/security/inspect/http-conformance.d.ts +51 -0
- package/dist/security/inspect/http-conformance.d.ts.map +1 -0
- package/dist/security/inspect/http-conformance.js +389 -0
- package/dist/security/inspect/http-conformance.js.map +1 -0
- package/dist/security/inspect/lexical-sqli.d.ts +7 -0
- package/dist/security/inspect/lexical-sqli.d.ts.map +1 -0
- package/dist/security/inspect/lexical-sqli.js +986 -0
- package/dist/security/inspect/lexical-sqli.js.map +1 -0
- package/dist/security/inspect/lexical-xss.d.ts +10 -0
- package/dist/security/inspect/lexical-xss.d.ts.map +1 -0
- package/dist/security/inspect/lexical-xss.js +654 -0
- package/dist/security/inspect/lexical-xss.js.map +1 -0
- package/dist/security/inspect/libinjection-tables.d.ts +6 -0
- package/dist/security/inspect/libinjection-tables.d.ts.map +1 -0
- package/dist/security/inspect/libinjection-tables.js +6 -0
- package/dist/security/inspect/libinjection-tables.js.map +1 -0
- package/dist/security/inspect/safe-pattern.d.ts +62 -0
- package/dist/security/inspect/safe-pattern.d.ts.map +1 -0
- package/dist/security/inspect/safe-pattern.js +640 -0
- package/dist/security/inspect/safe-pattern.js.map +1 -0
- package/dist/security/inspect/score-policy.d.ts +82 -0
- package/dist/security/inspect/score-policy.d.ts.map +1 -0
- package/dist/security/inspect/score-policy.js +241 -0
- package/dist/security/inspect/score-policy.js.map +1 -0
- package/dist/security/inspect.d.ts +7 -0
- package/dist/security/inspect.d.ts.map +1 -0
- package/dist/security/inspect.js +7 -0
- package/dist/security/inspect.js.map +1 -0
- package/dist/security/loader.d.ts.map +1 -1
- package/dist/security/loader.js +12 -2
- package/dist/security/loader.js.map +1 -1
- package/dist/security/payloads.d.ts.map +1 -1
- package/dist/security/payloads.js +19 -0
- package/dist/security/payloads.js.map +1 -1
- package/dist/security/scanner.d.ts +2 -0
- package/dist/security/scanner.d.ts.map +1 -1
- package/dist/security/scanner.js +31 -26
- package/dist/security/scanner.js.map +1 -1
- package/dist/tools/article.d.ts +18 -0
- package/dist/tools/article.d.ts.map +1 -0
- package/dist/tools/article.js +193 -0
- package/dist/tools/article.js.map +1 -0
- package/dist/tools/browser.d.ts +8 -2
- package/dist/tools/browser.d.ts.map +1 -1
- package/dist/tools/browser.js +76 -10
- package/dist/tools/browser.js.map +1 -1
- package/dist/tools/docx.d.ts +11 -0
- package/dist/tools/docx.d.ts.map +1 -0
- package/dist/tools/docx.js +149 -0
- package/dist/tools/docx.js.map +1 -0
- package/dist/tools/fs.d.ts +2 -0
- package/dist/tools/fs.d.ts.map +1 -1
- package/dist/tools/fs.js +96 -7
- package/dist/tools/fs.js.map +1 -1
- package/dist/tools/http.d.ts.map +1 -1
- package/dist/tools/http.js +125 -48
- package/dist/tools/http.js.map +1 -1
- package/dist/tools/index.d.ts +21 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +137 -14
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/resilience.d.ts +78 -0
- package/dist/tools/resilience.d.ts.map +1 -0
- package/dist/tools/resilience.js +211 -0
- package/dist/tools/resilience.js.map +1 -0
- package/dist/tools/security.d.ts +2 -0
- package/dist/tools/security.d.ts.map +1 -1
- package/dist/tools/security.js +79 -1
- package/dist/tools/security.js.map +1 -1
- package/dist/tools/types.d.ts +4 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/ui/banner.d.ts.map +1 -1
- package/dist/ui/banner.js +2 -2
- package/dist/ui/banner.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,742 @@
|
|
|
1
|
+
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { filterCliToolsForClaudeMcp, startCliToolBridge } from "./claude-code.js";
|
|
6
|
+
const EFFORT_SUFFIX_RE = /^(.*?)-(minimal|low|medium|high|xhigh|max|ultra)$/i;
|
|
7
|
+
const CODEX_STRIPPED_ENV_KEYS = new Set([
|
|
8
|
+
"OPENAI_API_KEY",
|
|
9
|
+
"OPENAI_BASE_URL",
|
|
10
|
+
"OPENAI_ORG_ID",
|
|
11
|
+
"OPENAI_PROJECT_ID",
|
|
12
|
+
"CODEX_API_KEY",
|
|
13
|
+
]);
|
|
14
|
+
const CODEX_RPC_TIMEOUT_MS = 15000;
|
|
15
|
+
export function sanitizeCodexEnv(baseEnv = process.env) {
|
|
16
|
+
const out = {};
|
|
17
|
+
for (const [key, value] of Object.entries(baseEnv)) {
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
continue;
|
|
20
|
+
if (CODEX_STRIPPED_ENV_KEYS.has(key.toUpperCase()))
|
|
21
|
+
continue;
|
|
22
|
+
out[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
export function parseCodexModelAndEffort(rawModel) {
|
|
27
|
+
const clean = String(rawModel ?? "").trim();
|
|
28
|
+
if (!clean || clean.toLowerCase() === "default") {
|
|
29
|
+
return { model: "" };
|
|
30
|
+
}
|
|
31
|
+
const match = EFFORT_SUFFIX_RE.exec(clean);
|
|
32
|
+
if (match && match[1]) {
|
|
33
|
+
return {
|
|
34
|
+
model: match[1],
|
|
35
|
+
effort: match[2].toLowerCase(),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return { model: clean };
|
|
39
|
+
}
|
|
40
|
+
export class CodexStreamAccumulator {
|
|
41
|
+
resultText = "";
|
|
42
|
+
isError = false;
|
|
43
|
+
errorMessage = "";
|
|
44
|
+
chunks = [];
|
|
45
|
+
streamedItems = new Set();
|
|
46
|
+
resetTurn() {
|
|
47
|
+
this.resultText = "";
|
|
48
|
+
this.isError = false;
|
|
49
|
+
this.errorMessage = "";
|
|
50
|
+
this.chunks = [];
|
|
51
|
+
this.streamedItems.clear();
|
|
52
|
+
}
|
|
53
|
+
getFullText() {
|
|
54
|
+
return this.chunks.join("") || this.resultText;
|
|
55
|
+
}
|
|
56
|
+
feedNotification(method, params = {}, onChunk = () => { }) {
|
|
57
|
+
if (method === "item/agentMessage/delta") {
|
|
58
|
+
const itemId = String(params.itemId ?? "");
|
|
59
|
+
const delta = typeof params.delta === "string" ? params.delta : "";
|
|
60
|
+
if (itemId)
|
|
61
|
+
this.streamedItems.add(itemId);
|
|
62
|
+
if (delta) {
|
|
63
|
+
this.chunks.push(delta);
|
|
64
|
+
onChunk(delta);
|
|
65
|
+
}
|
|
66
|
+
return { done: false, sessionNotFound: false, isError: false };
|
|
67
|
+
}
|
|
68
|
+
if (method === "item/completed") {
|
|
69
|
+
const item = params.item && typeof params.item === "object" ? params.item : null;
|
|
70
|
+
if (item && item.type === "agentMessage") {
|
|
71
|
+
const itemId = String(item.id ?? "");
|
|
72
|
+
const text = typeof item.text === "string" ? item.text : "";
|
|
73
|
+
if (text && (!itemId || !this.streamedItems.has(itemId))) {
|
|
74
|
+
this.chunks.push(text);
|
|
75
|
+
onChunk(text);
|
|
76
|
+
}
|
|
77
|
+
if (text) {
|
|
78
|
+
this.resultText = text;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { done: false, sessionNotFound: false, isError: false };
|
|
82
|
+
}
|
|
83
|
+
if (method === "turn/completed") {
|
|
84
|
+
const turn = params.turn && typeof params.turn === "object" ? params.turn : {};
|
|
85
|
+
const status = String(turn.status ?? "completed").toLowerCase();
|
|
86
|
+
if (status === "failed") {
|
|
87
|
+
const err = turn.error && typeof turn.error === "object" ? turn.error : {};
|
|
88
|
+
const msg = String(err.message || err.additionalDetails || "Codex turn failed.").trim() ||
|
|
89
|
+
"Codex turn failed.";
|
|
90
|
+
this.isError = true;
|
|
91
|
+
this.errorMessage = msg;
|
|
92
|
+
const lower = msg.toLowerCase();
|
|
93
|
+
const sessionNotFound = lower.includes("thread not found") ||
|
|
94
|
+
lower.includes("no rollout found") ||
|
|
95
|
+
(lower.includes("thread") && lower.includes("not found")) ||
|
|
96
|
+
(lower.includes("session") && lower.includes("not found"));
|
|
97
|
+
return { done: true, sessionNotFound, isError: true, errorMessage: msg };
|
|
98
|
+
}
|
|
99
|
+
return { done: true, sessionNotFound: false, isError: false };
|
|
100
|
+
}
|
|
101
|
+
if (method === "error") {
|
|
102
|
+
const err = params.error && typeof params.error === "object" ? params.error : {};
|
|
103
|
+
const msg = String(err.message || params.message || "Codex CLI error.").trim() || "Codex CLI error.";
|
|
104
|
+
this.isError = true;
|
|
105
|
+
this.errorMessage = msg;
|
|
106
|
+
const lower = msg.toLowerCase();
|
|
107
|
+
const sessionNotFound = lower.includes("thread not found") ||
|
|
108
|
+
lower.includes("no rollout found") ||
|
|
109
|
+
(lower.includes("thread") && lower.includes("not found")) ||
|
|
110
|
+
(lower.includes("session") && lower.includes("not found"));
|
|
111
|
+
return { done: true, sessionNotFound, isError: true, errorMessage: msg };
|
|
112
|
+
}
|
|
113
|
+
return { done: false, sessionNotFound: false, isError: false };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function whereExecutable(name) {
|
|
117
|
+
const locator = process.platform === "win32" ? "where.exe" : "which";
|
|
118
|
+
return new Promise((resolveLocate) => {
|
|
119
|
+
execFile(locator, [name], { timeout: 4000, windowsHide: true }, (err, stdout) => {
|
|
120
|
+
if (err || !stdout)
|
|
121
|
+
return resolveLocate("");
|
|
122
|
+
const lines = String(stdout)
|
|
123
|
+
.split(/\r?\n/)
|
|
124
|
+
.map((line) => line.trim())
|
|
125
|
+
.filter(Boolean);
|
|
126
|
+
if (lines.length === 0)
|
|
127
|
+
return resolveLocate("");
|
|
128
|
+
if (process.platform === "win32") {
|
|
129
|
+
const preferred = lines.find((line) => /\.(cmd|exe)$/i.test(line)) ||
|
|
130
|
+
lines.find((line) => /\.(js|mjs|cjs)$/i.test(line));
|
|
131
|
+
return resolveLocate(preferred || lines[0]);
|
|
132
|
+
}
|
|
133
|
+
return resolveLocate(lines[0]);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
export async function codexBinaryPath() {
|
|
138
|
+
const override = String(process.env.WIDE_CODEX_PATH ?? "").trim();
|
|
139
|
+
if (override) {
|
|
140
|
+
try {
|
|
141
|
+
if (statSync(override).isFile())
|
|
142
|
+
return override;
|
|
143
|
+
}
|
|
144
|
+
catch { }
|
|
145
|
+
}
|
|
146
|
+
const home = homedir();
|
|
147
|
+
const candidates = process.platform === "win32"
|
|
148
|
+
? [
|
|
149
|
+
process.env.APPDATA ? join(process.env.APPDATA, "npm", "codex.cmd") : "",
|
|
150
|
+
process.env.APPDATA ? join(process.env.APPDATA, "npm", "codex.exe") : "",
|
|
151
|
+
process.env.LOCALAPPDATA ? join(process.env.LOCALAPPDATA, "Programs", "codex", "codex.exe") : "",
|
|
152
|
+
join(home, ".codex", "bin", "codex.exe"),
|
|
153
|
+
join(home, ".local", "bin", "codex.exe"),
|
|
154
|
+
]
|
|
155
|
+
: [
|
|
156
|
+
join(home, ".local", "bin", "codex"),
|
|
157
|
+
join(home, ".codex", "bin", "codex"),
|
|
158
|
+
"/opt/homebrew/bin/codex",
|
|
159
|
+
"/usr/local/bin/codex",
|
|
160
|
+
"/usr/bin/codex",
|
|
161
|
+
];
|
|
162
|
+
for (const candidate of candidates) {
|
|
163
|
+
if (candidate && existsSync(candidate)) {
|
|
164
|
+
try {
|
|
165
|
+
if (statSync(candidate).isFile())
|
|
166
|
+
return candidate;
|
|
167
|
+
}
|
|
168
|
+
catch { }
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const found = await whereExecutable(process.platform === "win32" ? "codex.cmd" : "codex");
|
|
172
|
+
if (found && existsSync(found))
|
|
173
|
+
return found;
|
|
174
|
+
if (process.platform === "win32") {
|
|
175
|
+
const exeFound = await whereExecutable("codex.exe");
|
|
176
|
+
if (exeFound && existsSync(exeFound))
|
|
177
|
+
return exeFound;
|
|
178
|
+
}
|
|
179
|
+
return "";
|
|
180
|
+
}
|
|
181
|
+
function resolveCmdShim(binPath) {
|
|
182
|
+
if (process.platform !== "win32" || !/\.(cmd|bat)$/i.test(binPath))
|
|
183
|
+
return "";
|
|
184
|
+
try {
|
|
185
|
+
const raw = readFileSync(binPath, "utf8");
|
|
186
|
+
const match = /"%~dp0\\([^"\r\n]+\.(?:js|mjs|cjs))"/i.exec(raw);
|
|
187
|
+
if (!match)
|
|
188
|
+
return "";
|
|
189
|
+
const target = resolve(dirname(binPath), match[1]);
|
|
190
|
+
if (existsSync(target))
|
|
191
|
+
return target;
|
|
192
|
+
}
|
|
193
|
+
catch { }
|
|
194
|
+
return "";
|
|
195
|
+
}
|
|
196
|
+
function buildSpawnSpec(binPath, args) {
|
|
197
|
+
if (/\.(js|mjs|cjs)$/i.test(binPath)) {
|
|
198
|
+
return { command: process.execPath, args: [binPath, ...args], shell: false };
|
|
199
|
+
}
|
|
200
|
+
if (process.platform === "win32" && /\.(cmd|bat)$/i.test(binPath)) {
|
|
201
|
+
const script = resolveCmdShim(binPath);
|
|
202
|
+
if (script) {
|
|
203
|
+
return { command: process.execPath, args: [script, ...args], shell: false };
|
|
204
|
+
}
|
|
205
|
+
return { command: "cmd.exe", args: ["/d", "/c", binPath, ...args], shell: false };
|
|
206
|
+
}
|
|
207
|
+
return { command: binPath, args, shell: false };
|
|
208
|
+
}
|
|
209
|
+
export class CodexProvider {
|
|
210
|
+
name = "codex";
|
|
211
|
+
model;
|
|
212
|
+
proc = null;
|
|
213
|
+
bridge = null;
|
|
214
|
+
activeTools = [];
|
|
215
|
+
threadId = "";
|
|
216
|
+
syncedMessageCount = 0;
|
|
217
|
+
workerSignature = "";
|
|
218
|
+
nextRpcId = 1;
|
|
219
|
+
pendingRpc = new Map();
|
|
220
|
+
stdoutBuf = "";
|
|
221
|
+
activeStderr = [];
|
|
222
|
+
activeAccumulator = new CodexStreamAccumulator();
|
|
223
|
+
activeChunkCb = () => { };
|
|
224
|
+
activeTurnFinish = null;
|
|
225
|
+
constructor(model = "default") {
|
|
226
|
+
this.model = model || "default";
|
|
227
|
+
}
|
|
228
|
+
dispose() {
|
|
229
|
+
for (const entry of this.pendingRpc.values()) {
|
|
230
|
+
clearTimeout(entry.timer);
|
|
231
|
+
entry.reject(new Error("Codex worker disposed."));
|
|
232
|
+
}
|
|
233
|
+
this.pendingRpc.clear();
|
|
234
|
+
if (this.proc) {
|
|
235
|
+
try {
|
|
236
|
+
this.proc.stdin.end();
|
|
237
|
+
}
|
|
238
|
+
catch { }
|
|
239
|
+
try {
|
|
240
|
+
this.proc.kill("SIGKILL");
|
|
241
|
+
}
|
|
242
|
+
catch { }
|
|
243
|
+
this.proc = null;
|
|
244
|
+
}
|
|
245
|
+
if (this.bridge) {
|
|
246
|
+
this.bridge.close();
|
|
247
|
+
this.bridge = null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
formatPrompt(systemPrompt, messages, lastUserIdx, includeHistory) {
|
|
251
|
+
const sections = [];
|
|
252
|
+
if (includeHistory && systemPrompt.trim()) {
|
|
253
|
+
sections.push(systemPrompt.trim());
|
|
254
|
+
}
|
|
255
|
+
if (includeHistory && lastUserIdx > 0) {
|
|
256
|
+
const historyLines = [];
|
|
257
|
+
for (const msg of messages.slice(0, lastUserIdx)) {
|
|
258
|
+
if (msg.role === "system" || !msg.content.trim())
|
|
259
|
+
continue;
|
|
260
|
+
historyLines.push(`${msg.role === "assistant" ? "Assistant" : "User"}: ${msg.content.trim().slice(0, 2000)}`);
|
|
261
|
+
}
|
|
262
|
+
if (historyLines.length > 0) {
|
|
263
|
+
sections.push(`[Previous conversation context]\n${historyLines.join("\n\n")}\n[End of previous context]`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const lastUserText = lastUserIdx >= 0 ? messages[lastUserIdx].content : messages.map((m) => m.content).join("\n");
|
|
267
|
+
sections.push(lastUserText);
|
|
268
|
+
return sections.join("\n\n");
|
|
269
|
+
}
|
|
270
|
+
rpcWrite(payload, proc = this.proc) {
|
|
271
|
+
if (!proc || !proc.stdin.writable) {
|
|
272
|
+
throw new Error("Codex worker stdin is closed.");
|
|
273
|
+
}
|
|
274
|
+
proc.stdin.write(`${JSON.stringify(payload)}\n`);
|
|
275
|
+
}
|
|
276
|
+
rpcCall(method, params = {}, timeoutMs = CODEX_RPC_TIMEOUT_MS) {
|
|
277
|
+
const id = this.nextRpcId++;
|
|
278
|
+
return new Promise((resolveCall, rejectCall) => {
|
|
279
|
+
const timer = setTimeout(() => {
|
|
280
|
+
this.pendingRpc.delete(id);
|
|
281
|
+
rejectCall(new Error(`Codex RPC '${method}' timed out.`));
|
|
282
|
+
}, timeoutMs);
|
|
283
|
+
this.pendingRpc.set(id, { resolve: resolveCall, reject: rejectCall, timer });
|
|
284
|
+
try {
|
|
285
|
+
this.rpcWrite({ jsonrpc: "2.0", id, method, params });
|
|
286
|
+
}
|
|
287
|
+
catch (err) {
|
|
288
|
+
this.pendingRpc.delete(id);
|
|
289
|
+
clearTimeout(timer);
|
|
290
|
+
rejectCall(err instanceof Error ? err : new Error(String(err)));
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
spawnWorker(binPath, sig, allowDiskWrites) {
|
|
295
|
+
this.workerSignature = sig;
|
|
296
|
+
this.stdoutBuf = "";
|
|
297
|
+
const cliArgs = ["app-server", "--listen", "stdio://"];
|
|
298
|
+
if (this.bridge) {
|
|
299
|
+
cliArgs.push("-c", `mcp_servers.wide.url="${this.bridge.mcpUrl}"`, "-c", `mcp_servers.wide.bearer_token_env_var="WIDE_CODEX_MCP_TOKEN"`);
|
|
300
|
+
}
|
|
301
|
+
const spec = buildSpawnSpec(binPath, cliArgs);
|
|
302
|
+
const workerEnv = {
|
|
303
|
+
...sanitizeCodexEnv(process.env),
|
|
304
|
+
...(this.bridge ? { WIDE_CODEX_MCP_TOKEN: this.bridge.token } : {}),
|
|
305
|
+
};
|
|
306
|
+
this.proc = spawn(spec.command, spec.args, {
|
|
307
|
+
cwd: process.cwd(),
|
|
308
|
+
env: workerEnv,
|
|
309
|
+
windowsHide: true,
|
|
310
|
+
shell: spec.shell,
|
|
311
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
312
|
+
});
|
|
313
|
+
const handleLine = (raw) => {
|
|
314
|
+
const trimmed = raw.trim();
|
|
315
|
+
if (!trimmed)
|
|
316
|
+
return;
|
|
317
|
+
let msg;
|
|
318
|
+
try {
|
|
319
|
+
msg = JSON.parse(trimmed);
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (!msg || typeof msg !== "object")
|
|
325
|
+
return;
|
|
326
|
+
if (msg.id !== undefined && msg.id !== null && typeof msg.method !== "string") {
|
|
327
|
+
const entry = this.pendingRpc.get(Number(msg.id));
|
|
328
|
+
if (!entry)
|
|
329
|
+
return;
|
|
330
|
+
this.pendingRpc.delete(Number(msg.id));
|
|
331
|
+
clearTimeout(entry.timer);
|
|
332
|
+
if (msg.error) {
|
|
333
|
+
const errMsg = typeof msg.error === "object" ? msg.error.message || JSON.stringify(msg.error) : String(msg.error);
|
|
334
|
+
entry.reject(new Error(errMsg));
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
entry.resolve(msg.result ?? {});
|
|
338
|
+
}
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (msg.id !== undefined && msg.id !== null && typeof msg.method === "string") {
|
|
342
|
+
try {
|
|
343
|
+
this.rpcWrite({
|
|
344
|
+
jsonrpc: "2.0",
|
|
345
|
+
id: msg.id,
|
|
346
|
+
result: msg.method.includes("requestApproval")
|
|
347
|
+
? { decision: allowDiskWrites ? "accept" : "decline" }
|
|
348
|
+
: {},
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
catch { }
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (typeof msg.method === "string" && this.activeTurnFinish) {
|
|
355
|
+
const outcome = this.activeAccumulator.feedNotification(msg.method, (msg.params && typeof msg.params === "object" ? msg.params : {}), this.activeChunkCb);
|
|
356
|
+
if (outcome.done) {
|
|
357
|
+
const finish = this.activeTurnFinish;
|
|
358
|
+
this.activeTurnFinish = null;
|
|
359
|
+
if (outcome.sessionNotFound) {
|
|
360
|
+
finish({ content: "", retryFresh: true, error: outcome.errorMessage });
|
|
361
|
+
}
|
|
362
|
+
else if (outcome.isError) {
|
|
363
|
+
finish({ content: "", error: outcome.errorMessage || "Codex CLI execution failed." });
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
finish({ content: this.activeAccumulator.getFullText() });
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
this.proc.stdout.on("data", (chunk) => {
|
|
372
|
+
this.stdoutBuf += chunk.toString("utf8");
|
|
373
|
+
const lines = this.stdoutBuf.split(/\r?\n/);
|
|
374
|
+
this.stdoutBuf = lines.pop() ?? "";
|
|
375
|
+
for (const line of lines) {
|
|
376
|
+
if (line.trim())
|
|
377
|
+
handleLine(line);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
this.proc.stderr.on("data", (chunk) => {
|
|
381
|
+
this.activeStderr.push(chunk.toString("utf8"));
|
|
382
|
+
});
|
|
383
|
+
this.proc.on("close", (code) => {
|
|
384
|
+
if (this.stdoutBuf.trim()) {
|
|
385
|
+
handleLine(this.stdoutBuf);
|
|
386
|
+
this.stdoutBuf = "";
|
|
387
|
+
}
|
|
388
|
+
for (const entry of this.pendingRpc.values()) {
|
|
389
|
+
clearTimeout(entry.timer);
|
|
390
|
+
entry.reject(new Error(`Codex exited unexpectedly (code ${code ?? "unknown"}).`));
|
|
391
|
+
}
|
|
392
|
+
this.pendingRpc.clear();
|
|
393
|
+
if (this.activeTurnFinish) {
|
|
394
|
+
const finish = this.activeTurnFinish;
|
|
395
|
+
this.activeTurnFinish = null;
|
|
396
|
+
const errText = this.activeStderr.join("").trim() || `Codex exited unexpectedly (code ${code ?? "unknown"}).`;
|
|
397
|
+
const lower = errText.toLowerCase();
|
|
398
|
+
finish({
|
|
399
|
+
content: "",
|
|
400
|
+
retryFresh: lower.includes("thread not found") ||
|
|
401
|
+
lower.includes("no rollout found") ||
|
|
402
|
+
(lower.includes("thread") && lower.includes("not found")) ||
|
|
403
|
+
(lower.includes("session") && lower.includes("not found")),
|
|
404
|
+
error: errText,
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
this.proc = null;
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
async initializeWorkerAndThread(allowDiskWrites, systemPrompt, tryResumeId) {
|
|
411
|
+
const { model } = parseCodexModelAndEffort(this.model);
|
|
412
|
+
await this.rpcCall("initialize", {
|
|
413
|
+
clientInfo: { name: "wide-cli", version: "1.0.0" },
|
|
414
|
+
capabilities: { experimentalApi: true },
|
|
415
|
+
});
|
|
416
|
+
this.rpcWrite({ jsonrpc: "2.0", method: "initialized", params: {} });
|
|
417
|
+
const accountRes = await this.rpcCall("account/read", { refreshToken: false });
|
|
418
|
+
const accType = String(accountRes?.account?.type ?? "").trim();
|
|
419
|
+
if (accType !== "chatgpt") {
|
|
420
|
+
throw new Error("OpenAI Codex CLI is not signed in with a ChatGPT subscription. Run 'codex login' to sign in.");
|
|
421
|
+
}
|
|
422
|
+
const sandbox = allowDiskWrites ? "workspace-write" : "read-only";
|
|
423
|
+
if (tryResumeId) {
|
|
424
|
+
try {
|
|
425
|
+
const resumed = await this.rpcCall("thread/resume", {
|
|
426
|
+
threadId: tryResumeId,
|
|
427
|
+
cwd: process.cwd(),
|
|
428
|
+
...(model ? { model } : {}),
|
|
429
|
+
approvalPolicy: "never",
|
|
430
|
+
sandbox,
|
|
431
|
+
});
|
|
432
|
+
this.threadId = String(resumed?.thread?.id || tryResumeId).trim();
|
|
433
|
+
return { usedResume: true };
|
|
434
|
+
}
|
|
435
|
+
catch (err) {
|
|
436
|
+
const lower = String(err?.message || err).toLowerCase();
|
|
437
|
+
if (!lower.includes("not found") && !lower.includes("no rollout")) {
|
|
438
|
+
throw err;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
const mcpTools = filterCliToolsForClaudeMcp(this.activeTools);
|
|
443
|
+
const mcpHint = mcpTools.length > 0
|
|
444
|
+
? `Additional Wide CLI / Security / Browser / DB tools are attached on MCP server "wide": ${mcpTools.map((t) => t.name).join(", ")}.`
|
|
445
|
+
: "";
|
|
446
|
+
const devInstructions = [systemPrompt.trim(), mcpHint].filter(Boolean).join("\n\n");
|
|
447
|
+
const started = await this.rpcCall("thread/start", {
|
|
448
|
+
cwd: process.cwd(),
|
|
449
|
+
...(model ? { model } : {}),
|
|
450
|
+
approvalPolicy: "never",
|
|
451
|
+
sandbox,
|
|
452
|
+
...(devInstructions ? { developerInstructions: devInstructions } : {}),
|
|
453
|
+
});
|
|
454
|
+
const newId = String(started?.thread?.id || "").trim();
|
|
455
|
+
if (!newId) {
|
|
456
|
+
throw new Error("Codex app-server did not return a thread ID.");
|
|
457
|
+
}
|
|
458
|
+
this.threadId = newId;
|
|
459
|
+
return { usedResume: false };
|
|
460
|
+
}
|
|
461
|
+
sendTurn(promptText, onChunk, signal) {
|
|
462
|
+
const { model, effort } = parseCodexModelAndEffort(this.model);
|
|
463
|
+
return new Promise((resolveTurn) => {
|
|
464
|
+
if (!this.proc || !this.proc.stdin.writable || !this.threadId) {
|
|
465
|
+
resolveTurn({ content: "", error: "Codex worker process is not running." });
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
this.activeAccumulator.resetTurn();
|
|
469
|
+
this.activeChunkCb = onChunk;
|
|
470
|
+
this.activeStderr = [];
|
|
471
|
+
const cleanup = () => {
|
|
472
|
+
if (signal)
|
|
473
|
+
signal.removeEventListener("abort", onAbort);
|
|
474
|
+
};
|
|
475
|
+
const onAbort = () => {
|
|
476
|
+
if (this.activeTurnFinish) {
|
|
477
|
+
const finish = this.activeTurnFinish;
|
|
478
|
+
this.activeTurnFinish = null;
|
|
479
|
+
cleanup();
|
|
480
|
+
this.dispose();
|
|
481
|
+
finish({ content: "", error: "Aborted" });
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
if (signal) {
|
|
485
|
+
if (signal.aborted) {
|
|
486
|
+
onAbort();
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
490
|
+
}
|
|
491
|
+
this.activeTurnFinish = (res) => {
|
|
492
|
+
cleanup();
|
|
493
|
+
resolveTurn(res);
|
|
494
|
+
};
|
|
495
|
+
this.rpcCall("turn/start", {
|
|
496
|
+
threadId: this.threadId,
|
|
497
|
+
input: [{ type: "text", text: promptText || "Continue.", text_elements: [] }],
|
|
498
|
+
...(model ? { model } : {}),
|
|
499
|
+
...(effort ? { effort } : {}),
|
|
500
|
+
cwd: process.cwd(),
|
|
501
|
+
approvalPolicy: "never",
|
|
502
|
+
}).catch((err) => {
|
|
503
|
+
if (this.activeTurnFinish) {
|
|
504
|
+
const finish = this.activeTurnFinish;
|
|
505
|
+
this.activeTurnFinish = null;
|
|
506
|
+
const msg = String(err?.message || err);
|
|
507
|
+
const lower = msg.toLowerCase();
|
|
508
|
+
finish({
|
|
509
|
+
content: "",
|
|
510
|
+
retryFresh: lower.includes("not found") || lower.includes("no rollout"),
|
|
511
|
+
error: msg,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
async runOneShot(binPath, promptText, onChunk, signal) {
|
|
518
|
+
const spec = buildSpawnSpec(binPath, ["app-server", "--listen", "stdio://"]);
|
|
519
|
+
const { model, effort } = parseCodexModelAndEffort(this.model);
|
|
520
|
+
const pending = new Map();
|
|
521
|
+
let rpcSeq = 1;
|
|
522
|
+
let buf = "";
|
|
523
|
+
let stderr = "";
|
|
524
|
+
let settled = false;
|
|
525
|
+
const child = spawn(spec.command, spec.args, {
|
|
526
|
+
cwd: process.cwd(),
|
|
527
|
+
env: sanitizeCodexEnv(process.env),
|
|
528
|
+
windowsHide: true,
|
|
529
|
+
shell: spec.shell,
|
|
530
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
531
|
+
});
|
|
532
|
+
const acc = new CodexStreamAccumulator();
|
|
533
|
+
return await new Promise((resolveShot, rejectShot) => {
|
|
534
|
+
const finish = (err) => {
|
|
535
|
+
if (settled)
|
|
536
|
+
return;
|
|
537
|
+
settled = true;
|
|
538
|
+
if (signal)
|
|
539
|
+
signal.removeEventListener("abort", onAbort);
|
|
540
|
+
for (const entry of pending.values()) {
|
|
541
|
+
clearTimeout(entry.timer);
|
|
542
|
+
entry.reject(err || new Error("Codex closed"));
|
|
543
|
+
}
|
|
544
|
+
pending.clear();
|
|
545
|
+
try {
|
|
546
|
+
child.stdin.end();
|
|
547
|
+
}
|
|
548
|
+
catch { }
|
|
549
|
+
try {
|
|
550
|
+
child.kill("SIGKILL");
|
|
551
|
+
}
|
|
552
|
+
catch { }
|
|
553
|
+
if (err)
|
|
554
|
+
return rejectShot(err);
|
|
555
|
+
if (acc.isError)
|
|
556
|
+
return rejectShot(new Error(acc.errorMessage || "Codex CLI execution failed."));
|
|
557
|
+
return resolveShot({ content: acc.getFullText() });
|
|
558
|
+
};
|
|
559
|
+
const call = (method, params = {}) => {
|
|
560
|
+
const id = rpcSeq++;
|
|
561
|
+
return new Promise((res, rej) => {
|
|
562
|
+
const timer = setTimeout(() => {
|
|
563
|
+
pending.delete(id);
|
|
564
|
+
rej(new Error(`Codex RPC '${method}' timed out.`));
|
|
565
|
+
}, CODEX_RPC_TIMEOUT_MS);
|
|
566
|
+
pending.set(id, { resolve: res, reject: rej, timer });
|
|
567
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}\n`);
|
|
568
|
+
});
|
|
569
|
+
};
|
|
570
|
+
const onAbort = () => finish(new Error("Aborted"));
|
|
571
|
+
if (signal) {
|
|
572
|
+
if (signal.aborted) {
|
|
573
|
+
onAbort();
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
577
|
+
}
|
|
578
|
+
const handleLine = (raw) => {
|
|
579
|
+
const trimmed = raw.trim();
|
|
580
|
+
if (!trimmed)
|
|
581
|
+
return;
|
|
582
|
+
let msg;
|
|
583
|
+
try {
|
|
584
|
+
msg = JSON.parse(trimmed);
|
|
585
|
+
}
|
|
586
|
+
catch {
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
if (msg.id !== undefined && msg.id !== null && typeof msg.method !== "string") {
|
|
590
|
+
const entry = pending.get(Number(msg.id));
|
|
591
|
+
if (!entry)
|
|
592
|
+
return;
|
|
593
|
+
pending.delete(Number(msg.id));
|
|
594
|
+
clearTimeout(entry.timer);
|
|
595
|
+
if (msg.error) {
|
|
596
|
+
entry.reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
entry.resolve(msg.result ?? {});
|
|
600
|
+
}
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
if (msg.id !== undefined && msg.id !== null && typeof msg.method === "string") {
|
|
604
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id: msg.id, result: { decision: "decline" } })}\n`);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
if (typeof msg.method === "string") {
|
|
608
|
+
const out = acc.feedNotification(msg.method, (msg.params && typeof msg.params === "object" ? msg.params : {}), onChunk);
|
|
609
|
+
if (out.done)
|
|
610
|
+
finish();
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
child.stdout.on("data", (chunk) => {
|
|
614
|
+
buf += chunk.toString("utf8");
|
|
615
|
+
const lines = buf.split(/\r?\n/);
|
|
616
|
+
buf = lines.pop() ?? "";
|
|
617
|
+
for (const line of lines) {
|
|
618
|
+
if (line.trim())
|
|
619
|
+
handleLine(line);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
child.stderr.on("data", (chunk) => {
|
|
623
|
+
stderr += chunk.toString("utf8");
|
|
624
|
+
});
|
|
625
|
+
child.on("error", (err) => finish(err));
|
|
626
|
+
child.on("close", (code) => {
|
|
627
|
+
if (buf.trim())
|
|
628
|
+
handleLine(buf);
|
|
629
|
+
if (!settled) {
|
|
630
|
+
finish(new Error(stderr.trim() || `Codex exited with code ${code ?? "unknown"}`));
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
(async () => {
|
|
634
|
+
await call("initialize", {
|
|
635
|
+
clientInfo: { name: "wide-cli", version: "1.0.0" },
|
|
636
|
+
capabilities: { experimentalApi: true },
|
|
637
|
+
});
|
|
638
|
+
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", method: "initialized", params: {} })}\n`);
|
|
639
|
+
const accountRes = await call("account/read", { refreshToken: false });
|
|
640
|
+
if (String(accountRes?.account?.type ?? "").trim() !== "chatgpt") {
|
|
641
|
+
throw new Error("OpenAI Codex CLI is not signed in with a ChatGPT subscription. Run 'codex login' to sign in.");
|
|
642
|
+
}
|
|
643
|
+
const started = await call("thread/start", {
|
|
644
|
+
cwd: process.cwd(),
|
|
645
|
+
...(model ? { model } : {}),
|
|
646
|
+
approvalPolicy: "never",
|
|
647
|
+
sandbox: "read-only",
|
|
648
|
+
ephemeral: true,
|
|
649
|
+
});
|
|
650
|
+
const threadId = String(started?.thread?.id || "").trim();
|
|
651
|
+
if (!threadId)
|
|
652
|
+
throw new Error("Codex app-server did not return a thread ID.");
|
|
653
|
+
await call("turn/start", {
|
|
654
|
+
threadId,
|
|
655
|
+
input: [{ type: "text", text: promptText || "Continue.", text_elements: [] }],
|
|
656
|
+
...(model ? { model } : {}),
|
|
657
|
+
...(effort ? { effort } : {}),
|
|
658
|
+
cwd: process.cwd(),
|
|
659
|
+
approvalPolicy: "never",
|
|
660
|
+
});
|
|
661
|
+
})().catch((err) => finish(err instanceof Error ? err : new Error(String(err))));
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
async chatStream(messages, tools, onChunk, signal) {
|
|
665
|
+
const binPath = await codexBinaryPath();
|
|
666
|
+
if (!binPath) {
|
|
667
|
+
throw new Error("OpenAI Codex CLI is not installed. Run 'npm install -g @openai/codex' and 'codex login' to sign in.");
|
|
668
|
+
}
|
|
669
|
+
const systemMsg = messages.find((m) => m.role === "system")?.content || "";
|
|
670
|
+
let lastUserIdx = -1;
|
|
671
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
672
|
+
if (messages[i].role === "user") {
|
|
673
|
+
lastUserIdx = i;
|
|
674
|
+
break;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
if (tools.length === 0) {
|
|
678
|
+
const promptText = this.formatPrompt(systemMsg, messages, lastUserIdx, true);
|
|
679
|
+
return await this.runOneShot(binPath, promptText, onChunk, signal);
|
|
680
|
+
}
|
|
681
|
+
const allowDiskWrites = tools.some((t) => t.name === "write_file" || t.name === "edit_file");
|
|
682
|
+
this.activeTools = tools;
|
|
683
|
+
const mcpTools = filterCliToolsForClaudeMcp(tools);
|
|
684
|
+
const sig = JSON.stringify([this.model.trim(), allowDiskWrites, mcpTools.map((t) => t.name)]);
|
|
685
|
+
if (messages.length <= this.syncedMessageCount && this.syncedMessageCount > 0) {
|
|
686
|
+
this.dispose();
|
|
687
|
+
this.threadId = "";
|
|
688
|
+
this.syncedMessageCount = 0;
|
|
689
|
+
}
|
|
690
|
+
if (!this.proc || !this.proc.stdin.writable || this.workerSignature !== sig) { // wide-ignore wide/timing-secret-nonconst-eq
|
|
691
|
+
this.dispose();
|
|
692
|
+
const useResume = Boolean(this.threadId && this.syncedMessageCount > 0);
|
|
693
|
+
if (mcpTools.length > 0) {
|
|
694
|
+
this.bridge = await startCliToolBridge(() => this.activeTools);
|
|
695
|
+
}
|
|
696
|
+
this.spawnWorker(binPath, sig, allowDiskWrites);
|
|
697
|
+
const { usedResume } = await this.initializeWorkerAndThread(allowDiskWrites, systemMsg, useResume ? this.threadId : "");
|
|
698
|
+
const firstPrompt = this.formatPrompt(systemMsg, messages, lastUserIdx, !usedResume);
|
|
699
|
+
const res = await this.sendTurn(firstPrompt, onChunk, signal);
|
|
700
|
+
if (res.retryFresh) {
|
|
701
|
+
this.dispose();
|
|
702
|
+
this.threadId = "";
|
|
703
|
+
this.syncedMessageCount = 0;
|
|
704
|
+
if (mcpTools.length > 0) {
|
|
705
|
+
this.bridge = await startCliToolBridge(() => this.activeTools);
|
|
706
|
+
}
|
|
707
|
+
this.spawnWorker(binPath, sig, allowDiskWrites);
|
|
708
|
+
await this.initializeWorkerAndThread(allowDiskWrites, systemMsg, "");
|
|
709
|
+
const retryPrompt = this.formatPrompt(systemMsg, messages, lastUserIdx, true);
|
|
710
|
+
const retryRes = await this.sendTurn(retryPrompt, onChunk, signal);
|
|
711
|
+
if (retryRes.error)
|
|
712
|
+
throw new Error(retryRes.error);
|
|
713
|
+
this.syncedMessageCount = messages.length + 1;
|
|
714
|
+
return { content: retryRes.content };
|
|
715
|
+
}
|
|
716
|
+
if (res.error)
|
|
717
|
+
throw new Error(res.error);
|
|
718
|
+
this.syncedMessageCount = messages.length + 1;
|
|
719
|
+
return { content: res.content };
|
|
720
|
+
}
|
|
721
|
+
const nextPrompt = lastUserIdx >= 0 ? messages[lastUserIdx].content : messages.map((m) => m.content).join("\n");
|
|
722
|
+
const res = await this.sendTurn(nextPrompt, onChunk, signal);
|
|
723
|
+
if (res.retryFresh) {
|
|
724
|
+
this.dispose();
|
|
725
|
+
this.threadId = "";
|
|
726
|
+
this.syncedMessageCount = 0;
|
|
727
|
+
this.spawnWorker(binPath, sig, allowDiskWrites);
|
|
728
|
+
await this.initializeWorkerAndThread(allowDiskWrites, systemMsg, "");
|
|
729
|
+
const retryPrompt = this.formatPrompt(systemMsg, messages, lastUserIdx, true);
|
|
730
|
+
const retryRes = await this.sendTurn(retryPrompt, onChunk, signal);
|
|
731
|
+
if (retryRes.error)
|
|
732
|
+
throw new Error(retryRes.error);
|
|
733
|
+
this.syncedMessageCount = messages.length + 1;
|
|
734
|
+
return { content: retryRes.content };
|
|
735
|
+
}
|
|
736
|
+
if (res.error)
|
|
737
|
+
throw new Error(res.error);
|
|
738
|
+
this.syncedMessageCount = messages.length + 1;
|
|
739
|
+
return { content: res.content };
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
//# sourceMappingURL=codex.js.map
|