@i14ks/ccv 0.25.0 → 0.27.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/README.md +18 -1
- package/bundle/ccv.mjs +1127 -186
- package/package.json +4 -2
- package/web/assets/{codemirror-BdKpW4CC.js → codemirror-E1z6J01e.js} +1 -1
- package/web/assets/{index-DXHZO0ym.js → index--avrDony.js} +1 -1
- package/web/assets/{index-yXtesgZ4.js → index-7U1ohiLA.js} +1 -1
- package/web/assets/{index-Si6no75_.js → index-B2AsV6mq.js} +1 -1
- package/web/assets/{index-DqnCWDLh.js → index-BBZwZyBc.js} +1 -1
- package/web/assets/{index-D83he8x-.js → index-BcerQq_T.js} +1 -1
- package/web/assets/{index-DPrfFlZq.js → index-BecRt4W_.js} +1 -1
- package/web/assets/{index-ChyP1fTD.js → index-Bz64IIeo.js} +1 -1
- package/web/assets/{index-C59b0_Vk.js → index-Bz_OD4bi.js} +1 -1
- package/web/assets/{index-Dd7rh20x.js → index-C9SmMjLJ.js} +1 -1
- package/web/assets/{index-CZuUjzhP.js → index-CAFnMkkM.js} +1 -1
- package/web/assets/{index-BroMLvyS.js → index-CBwg0nNm.js} +1 -1
- package/web/assets/index-CcP9R_-q.js +134 -0
- package/web/assets/{index-CRsndRFc.js → index-CsM3FfDT.js} +1 -1
- package/web/assets/index-D-zxmJYV.css +1 -0
- package/web/assets/{index-CWTFMuFd.js → index-DAXylny5.js} +1 -1
- package/web/assets/{index-UxKgaDrj.js → index-DKAqAv7f.js} +1 -1
- package/web/assets/{index-B2BGvdag.js → index-DiTx3nWx.js} +1 -1
- package/web/assets/{index-BrkwvvWk.js → index-DkLckATt.js} +1 -1
- package/web/assets/{index-YCUybqa_.js → index-DzHtRLVh.js} +1 -1
- package/web/assets/{index-D6DYiY6f.js → index-NY2_ZMtt.js} +1 -1
- package/web/assets/{index-wsSNo9PM.js → index-wDZtpqBZ.js} +1 -1
- package/web/index.html +3 -3
- package/web/assets/index-BCLbqlhA.js +0 -134
- package/web/assets/index-C6Y6TadO.css +0 -1
package/bundle/ccv.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// dist/ccv.js
|
|
4
|
-
import { spawn as
|
|
4
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
5
5
|
import { readFile as readFile17 } from "node:fs/promises";
|
|
6
|
-
import
|
|
6
|
+
import path26 from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
|
|
@@ -128,15 +128,144 @@ function reachable(file, mode) {
|
|
|
128
128
|
return access(file, mode).then(() => true, () => false);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
// ../host/dist/codex-cli.js
|
|
132
|
+
import { spawn as spawn2, execFile as execFile2 } from "node:child_process";
|
|
133
|
+
import { existsSync } from "node:fs";
|
|
134
|
+
import { homedir as homedir2 } from "node:os";
|
|
135
|
+
import path2 from "node:path";
|
|
136
|
+
import { EventEmitter } from "node:events";
|
|
137
|
+
import { createInterface } from "node:readline";
|
|
138
|
+
function codexLauncher() {
|
|
139
|
+
const forced = process.env.CCV_CODEX_PATH;
|
|
140
|
+
const dirs = (process.env.PATH ?? "").split(path2.delimiter).filter(Boolean);
|
|
141
|
+
dirs.push(path2.join(homedir2(), ".local", "bin"));
|
|
142
|
+
if (process.platform === "win32") {
|
|
143
|
+
dirs.push(path2.join(process.env.LOCALAPPDATA ?? path2.join(homedir2(), "AppData", "Local"), "Programs", "OpenAI", "Codex", "bin"));
|
|
144
|
+
dirs.push(process.env.APPDATA ? path2.join(process.env.APPDATA, "npm") : path2.join(homedir2(), "AppData", "Roaming", "npm"));
|
|
145
|
+
}
|
|
146
|
+
const names2 = process.platform === "win32" ? ["codex.exe", "codex.cmd", "codex"] : ["codex"];
|
|
147
|
+
for (const candidate of forced ? [forced] : dirs.flatMap((dir) => names2.map((name) => path2.join(dir, name)))) {
|
|
148
|
+
if (!existsSync(candidate))
|
|
149
|
+
continue;
|
|
150
|
+
if (/\.(?:cmd|ps1)$/i.test(candidate)) {
|
|
151
|
+
const js = path2.join(path2.dirname(candidate), "node_modules", "@openai", "codex", "bin", "codex.js");
|
|
152
|
+
if (existsSync(js))
|
|
153
|
+
return { file: process.execPath, args: [js] };
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (/\.(?:m?js)$/i.test(candidate))
|
|
157
|
+
return { file: process.execPath, args: [candidate] };
|
|
158
|
+
return { file: candidate, args: [] };
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
var CODEX_MISSING_HINT = "Codex CLI \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D. \u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 npm install -g @openai/codex \u0438 \u0432\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u0435 codex login (\u0438\u043B\u0438 codex login --device-auth \u0432 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0435). \u041F\u0443\u0442\u044C \u043C\u043E\u0436\u043D\u043E \u0437\u0430\u0434\u0430\u0442\u044C \u0447\u0435\u0440\u0435\u0437 CCV_CODEX_PATH.";
|
|
163
|
+
var CodexClient = class extends EventEmitter {
|
|
164
|
+
#child = null;
|
|
165
|
+
#nextId = 0;
|
|
166
|
+
#pending = /* @__PURE__ */ new Map();
|
|
167
|
+
#closed = false;
|
|
168
|
+
#exited = Promise.resolve();
|
|
169
|
+
async start(cwd) {
|
|
170
|
+
const launcher = codexLauncher();
|
|
171
|
+
if (!launcher)
|
|
172
|
+
throw new Error(CODEX_MISSING_HINT);
|
|
173
|
+
this.#closed = false;
|
|
174
|
+
const child = spawn2(launcher.file, [...launcher.args, "app-server", "--listen", "stdio://"], {
|
|
175
|
+
cwd,
|
|
176
|
+
windowsHide: true,
|
|
177
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
178
|
+
env: { ...process.env, NO_COLOR: "1" }
|
|
179
|
+
});
|
|
180
|
+
this.#child = child;
|
|
181
|
+
this.#exited = new Promise((resolve) => child.once("close", () => resolve()));
|
|
182
|
+
createInterface({ input: child.stdout, crlfDelay: Infinity }).on("line", (line) => {
|
|
183
|
+
let message;
|
|
184
|
+
try {
|
|
185
|
+
message = JSON.parse(line);
|
|
186
|
+
} catch {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (message.method) {
|
|
190
|
+
this.emit("message", message);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const pending = typeof message.id === "number" ? this.#pending.get(message.id) : void 0;
|
|
194
|
+
if (!pending)
|
|
195
|
+
return;
|
|
196
|
+
clearTimeout(pending.timer);
|
|
197
|
+
this.#pending.delete(message.id);
|
|
198
|
+
if (message.error)
|
|
199
|
+
pending.reject(new Error(message.error.message));
|
|
200
|
+
else
|
|
201
|
+
pending.resolve(message.result);
|
|
202
|
+
});
|
|
203
|
+
child.stderr.on("data", (data) => this.emit("stderr", String(data)));
|
|
204
|
+
child.stdin.on("error", (error) => this.#fail(error));
|
|
205
|
+
child.on("error", (error) => this.#fail(error));
|
|
206
|
+
child.on("exit", (code, signal) => this.#fail(new Error(`Codex \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0441\u044F (${signal ?? code ?? "unknown"})`)));
|
|
207
|
+
await this.request("initialize", { clientInfo: { name: "ccv", title: "Code Visual", version: "0.27.0" }, capabilities: { experimentalApi: true } });
|
|
208
|
+
this.notify("initialized", {});
|
|
209
|
+
}
|
|
210
|
+
request(method, params = {}) {
|
|
211
|
+
if (!this.#child || this.#closed)
|
|
212
|
+
return Promise.reject(new Error("Codex \u043D\u0435 \u043F\u043E\u0434\u043A\u043B\u044E\u0447\u0451\u043D"));
|
|
213
|
+
const id = ++this.#nextId;
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
const timer = setTimeout(() => {
|
|
216
|
+
this.#pending.delete(id);
|
|
217
|
+
reject(new Error(`Codex: \u0432\u0440\u0435\u043C\u044F \u043E\u0436\u0438\u0434\u0430\u043D\u0438\u044F ${method} \u0438\u0441\u0442\u0435\u043A\u043B\u043E`));
|
|
218
|
+
}, 6e4);
|
|
219
|
+
this.#pending.set(id, { resolve, reject, timer });
|
|
220
|
+
this.#write({ id, method, params });
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
notify(method, params) {
|
|
224
|
+
this.#write({ method, params });
|
|
225
|
+
}
|
|
226
|
+
respond(id, result) {
|
|
227
|
+
this.#write({ id, result });
|
|
228
|
+
}
|
|
229
|
+
reject(id, message) {
|
|
230
|
+
this.#write({ id, error: { code: -32601, message } });
|
|
231
|
+
}
|
|
232
|
+
#write(message) {
|
|
233
|
+
if (this.#child && !this.#closed)
|
|
234
|
+
this.#child.stdin.write(JSON.stringify(message) + "\n");
|
|
235
|
+
}
|
|
236
|
+
#fail(error) {
|
|
237
|
+
if (this.#closed)
|
|
238
|
+
return;
|
|
239
|
+
this.#closed = true;
|
|
240
|
+
for (const pending of this.#pending.values()) {
|
|
241
|
+
clearTimeout(pending.timer);
|
|
242
|
+
pending.reject(error);
|
|
243
|
+
}
|
|
244
|
+
this.#pending.clear();
|
|
245
|
+
this.emit("disconnect", error);
|
|
246
|
+
}
|
|
247
|
+
async close() {
|
|
248
|
+
this.#fail(new Error("Codex \u043E\u0442\u043A\u043B\u044E\u0447\u0451\u043D"));
|
|
249
|
+
const child = this.#child;
|
|
250
|
+
this.#child = null;
|
|
251
|
+
child?.stdin.end();
|
|
252
|
+
if (child?.pid && process.platform === "win32") {
|
|
253
|
+
await new Promise((resolve) => execFile2("taskkill", ["/pid", String(child.pid), "/T", "/F"], { windowsHide: true, timeout: 5e3 }, () => resolve()));
|
|
254
|
+
} else
|
|
255
|
+
child?.kill();
|
|
256
|
+
await this.#exited;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
131
260
|
// ../host/dist/config.js
|
|
132
261
|
import os from "node:os";
|
|
133
|
-
import
|
|
262
|
+
import path3 from "node:path";
|
|
134
263
|
function envDefaults() {
|
|
135
264
|
return {
|
|
136
265
|
port: Number(process.env.CCV_PORT ?? 8787),
|
|
137
266
|
// Только loopback. Наружу этот порт не выставляется — снаружи будет relay.
|
|
138
267
|
host: process.env.CCV_HOST ?? "127.0.0.1",
|
|
139
|
-
dataDir: process.env.CCV_DATA_DIR ??
|
|
268
|
+
dataDir: process.env.CCV_DATA_DIR ?? path3.join(os.homedir(), ".claude-code-visual"),
|
|
140
269
|
// Куда сопрягаться за удалённым доступом. Переопределяется ради своего
|
|
141
270
|
// relay — и ради прогона всей связки на одной машине.
|
|
142
271
|
relayUrl: process.env.CCV_RELAY_URL ?? "https://claudevisual.com"
|
|
@@ -145,10 +274,10 @@ function envDefaults() {
|
|
|
145
274
|
|
|
146
275
|
// ../host/dist/server.js
|
|
147
276
|
import { createServer } from "node:http";
|
|
148
|
-
import { createReadStream, existsSync as
|
|
149
|
-
import
|
|
150
|
-
import { homedir as
|
|
151
|
-
import { randomUUID as
|
|
277
|
+
import { createReadStream, existsSync as existsSync5, statSync as statSync3 } from "node:fs";
|
|
278
|
+
import path25 from "node:path";
|
|
279
|
+
import { homedir as homedir7 } from "node:os";
|
|
280
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
152
281
|
import { WebSocketServer } from "ws";
|
|
153
282
|
import { renameSession as renameSession2 } from "@anthropic-ai/claude-agent-sdk";
|
|
154
283
|
|
|
@@ -187,12 +316,12 @@ function hashText(text) {
|
|
|
187
316
|
// ../host/dist/workspace-ids.js
|
|
188
317
|
function workspaceIdRemap(paths, sessionsOf) {
|
|
189
318
|
const byLegacy = /* @__PURE__ */ new Map();
|
|
190
|
-
for (const
|
|
191
|
-
const id = workspaceIdFromPath(
|
|
192
|
-
for (const legacy of formerWorkspaceIdsFromPath(
|
|
319
|
+
for (const path27 of paths) {
|
|
320
|
+
const id = workspaceIdFromPath(path27);
|
|
321
|
+
for (const legacy of formerWorkspaceIdsFromPath(path27)) {
|
|
193
322
|
const group = byLegacy.get(legacy) ?? [];
|
|
194
323
|
if (!group.some((target) => target.id === id))
|
|
195
|
-
group.push({ id, path:
|
|
324
|
+
group.push({ id, path: path27 });
|
|
196
325
|
byLegacy.set(legacy, group);
|
|
197
326
|
}
|
|
198
327
|
}
|
|
@@ -223,9 +352,9 @@ function workspaceIdRemap(paths, sessionsOf) {
|
|
|
223
352
|
}
|
|
224
353
|
|
|
225
354
|
// ../host/dist/session.js
|
|
226
|
-
import { EventEmitter as
|
|
355
|
+
import { EventEmitter as EventEmitter3 } from "node:events";
|
|
227
356
|
import { randomUUID } from "node:crypto";
|
|
228
|
-
import
|
|
357
|
+
import path6 from "node:path";
|
|
229
358
|
import { query, renameSession } from "@anthropic-ai/claude-agent-sdk";
|
|
230
359
|
|
|
231
360
|
// ../host/dist/async-queue.js
|
|
@@ -277,7 +406,7 @@ var AsyncQueue = class {
|
|
|
277
406
|
|
|
278
407
|
// ../host/dist/files.js
|
|
279
408
|
import { cp, lstat, mkdir, readFile as readFile2, readdir, realpath, rename as renamePath, rm, stat, writeFile } from "node:fs/promises";
|
|
280
|
-
import
|
|
409
|
+
import path4 from "node:path";
|
|
281
410
|
var MAX_FILE = 4 * 1024 * 1024;
|
|
282
411
|
var MAX_MEDIA = 64 * 1024 * 1024;
|
|
283
412
|
var MEDIA_MIME = {
|
|
@@ -315,7 +444,7 @@ var ProjectFiles = class {
|
|
|
315
444
|
for (const dirent of names2) {
|
|
316
445
|
if (HIDDEN.has(dirent.name))
|
|
317
446
|
continue;
|
|
318
|
-
const full =
|
|
447
|
+
const full = path4.join(dir, dirent.name);
|
|
319
448
|
const link = dirent.isSymbolicLink();
|
|
320
449
|
const info = await stat(full).catch(() => null);
|
|
321
450
|
if (!info)
|
|
@@ -363,7 +492,7 @@ var ProjectFiles = class {
|
|
|
363
492
|
return;
|
|
364
493
|
if (SEARCH_SKIP.has(dirent.name))
|
|
365
494
|
continue;
|
|
366
|
-
const full =
|
|
495
|
+
const full = path4.join(dir, dirent.name);
|
|
367
496
|
const rel = join(relative, dirent.name);
|
|
368
497
|
const info = await stat(full).catch(() => null);
|
|
369
498
|
if (!info)
|
|
@@ -418,7 +547,7 @@ var ProjectFiles = class {
|
|
|
418
547
|
return;
|
|
419
548
|
if (SEARCH_SKIP.has(dirent.name) || dirent.isSymbolicLink())
|
|
420
549
|
continue;
|
|
421
|
-
const full =
|
|
550
|
+
const full = path4.join(dir, dirent.name);
|
|
422
551
|
const rel = join(relative, dirent.name);
|
|
423
552
|
if (dirent.isDirectory()) {
|
|
424
553
|
await walk(full, rel);
|
|
@@ -486,7 +615,7 @@ var ProjectFiles = class {
|
|
|
486
615
|
binary: false,
|
|
487
616
|
tooLarge: false
|
|
488
617
|
};
|
|
489
|
-
const mediaMime = MEDIA_MIME[
|
|
618
|
+
const mediaMime = MEDIA_MIME[path4.extname(file).toLowerCase()];
|
|
490
619
|
if (mediaMime) {
|
|
491
620
|
if (info.size > MAX_MEDIA)
|
|
492
621
|
return { ...blank, binary: true, mediaMime, mediaTooLarge: true };
|
|
@@ -517,7 +646,7 @@ var ProjectFiles = class {
|
|
|
517
646
|
*/
|
|
518
647
|
async readMedia(relative) {
|
|
519
648
|
const file = await this.#resolve(relative);
|
|
520
|
-
const mime = MEDIA_MIME[
|
|
649
|
+
const mime = MEDIA_MIME[path4.extname(file).toLowerCase()];
|
|
521
650
|
if (!mime)
|
|
522
651
|
throw new Error("\u0424\u0430\u0439\u043B \u043D\u0435 \u0440\u0430\u0441\u043F\u043E\u0437\u043D\u0430\u043D \u043A\u0430\u043A \u043A\u0430\u0440\u0442\u0438\u043D\u043A\u0430 \u0438\u043B\u0438 \u0432\u0438\u0434\u0435\u043E");
|
|
523
652
|
const info = await stat(file);
|
|
@@ -559,7 +688,7 @@ var ProjectFiles = class {
|
|
|
559
688
|
await mkdir(target, { recursive: true });
|
|
560
689
|
return;
|
|
561
690
|
}
|
|
562
|
-
await mkdir(
|
|
691
|
+
await mkdir(path4.dirname(target), { recursive: true });
|
|
563
692
|
await writeFile(target, "", { encoding: "utf8", flag: "wx" });
|
|
564
693
|
}
|
|
565
694
|
async rename(relative, to) {
|
|
@@ -569,7 +698,7 @@ var ProjectFiles = class {
|
|
|
569
698
|
return;
|
|
570
699
|
if (await exists(target))
|
|
571
700
|
throw new Error("\u041F\u043E \u043D\u043E\u0432\u043E\u043C\u0443 \u043F\u0443\u0442\u0438 \u0443\u0436\u0435 \u0447\u0442\u043E-\u0442\u043E \u0435\u0441\u0442\u044C");
|
|
572
|
-
await mkdir(
|
|
701
|
+
await mkdir(path4.dirname(target), { recursive: true });
|
|
573
702
|
await renamePath(from, target);
|
|
574
703
|
}
|
|
575
704
|
/**
|
|
@@ -602,7 +731,7 @@ var ProjectFiles = class {
|
|
|
602
731
|
if (!await exists(to))
|
|
603
732
|
break;
|
|
604
733
|
}
|
|
605
|
-
await mkdir(
|
|
734
|
+
await mkdir(path4.dirname(to), { recursive: true });
|
|
606
735
|
await cp(from, to, { recursive: true, errorOnExist: true, force: false });
|
|
607
736
|
return target;
|
|
608
737
|
}
|
|
@@ -622,15 +751,15 @@ var ProjectFiles = class {
|
|
|
622
751
|
*/
|
|
623
752
|
async #resolve(relative) {
|
|
624
753
|
const clean = normalize(relative);
|
|
625
|
-
if (
|
|
754
|
+
if (path4.isAbsolute(clean) || /^[A-Za-z]:/.test(clean)) {
|
|
626
755
|
throw new Error("\u041F\u0443\u0442\u044C \u0434\u043E\u043B\u0436\u0435\u043D \u0431\u044B\u0442\u044C \u043E\u0442\u043D\u043E\u0441\u0438\u0442\u0435\u043B\u044C\u043D\u044B\u043C \u043E\u0442 \u043A\u043E\u0440\u043D\u044F \u043F\u0440\u043E\u0435\u043A\u0442\u0430");
|
|
627
756
|
}
|
|
628
757
|
if (clean.split("/").includes("..")) {
|
|
629
758
|
throw new Error("\u0412\u044B\u0445\u043E\u0434 \u0437\u0430 \u043F\u0440\u0435\u0434\u0435\u043B\u044B \u043A\u0430\u0442\u0430\u043B\u043E\u0433\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u0437\u0430\u043F\u0440\u0435\u0449\u0451\u043D");
|
|
630
759
|
}
|
|
631
760
|
const root = this.#root ??= await realpath(this.cwd);
|
|
632
|
-
const target =
|
|
633
|
-
const probe = await exists(target) ? target :
|
|
761
|
+
const target = path4.resolve(root, clean);
|
|
762
|
+
const probe = await exists(target) ? target : path4.dirname(target);
|
|
634
763
|
const real = await realpath(probe).catch(() => probe);
|
|
635
764
|
if (!contains(root, real)) {
|
|
636
765
|
throw new Error("\u0412\u044B\u0445\u043E\u0434 \u0437\u0430 \u043F\u0440\u0435\u0434\u0435\u043B\u044B \u043A\u0430\u0442\u0430\u043B\u043E\u0433\u0430 \u043F\u0440\u043E\u0435\u043A\u0442\u0430 \u0437\u0430\u043F\u0440\u0435\u0449\u0451\u043D");
|
|
@@ -651,7 +780,7 @@ function join(dir, name) {
|
|
|
651
780
|
function contains(root, target) {
|
|
652
781
|
if (target === root)
|
|
653
782
|
return true;
|
|
654
|
-
const prefix = root.endsWith(
|
|
783
|
+
const prefix = root.endsWith(path4.sep) ? root : root + path4.sep;
|
|
655
784
|
return process.platform === "win32" ? target.toLowerCase().startsWith(prefix.toLowerCase()) : target.startsWith(prefix);
|
|
656
785
|
}
|
|
657
786
|
async function exists(file) {
|
|
@@ -788,7 +917,7 @@ var Journal = class {
|
|
|
788
917
|
};
|
|
789
918
|
|
|
790
919
|
// ../host/dist/network-guard.js
|
|
791
|
-
import { EventEmitter } from "node:events";
|
|
920
|
+
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
792
921
|
import { request } from "node:https";
|
|
793
922
|
import { networkInterfaces } from "node:os";
|
|
794
923
|
var TRACE_URL = "https://api.anthropic.com/cdn-cgi/trace";
|
|
@@ -798,7 +927,7 @@ var CHECK_TIMEOUT_MS = 4e3;
|
|
|
798
927
|
var RETRY_DELAY_MS = 1e3;
|
|
799
928
|
var NETWORK_FRESH_MS = 3e3;
|
|
800
929
|
var UNCHECKED_REASON = "\u041C\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043E Anthropic \u0435\u0449\u0451 \u043D\u0435 \u043F\u0440\u043E\u0432\u0435\u0440\u0435\u043D";
|
|
801
|
-
var NetworkGuard = class extends
|
|
930
|
+
var NetworkGuard = class extends EventEmitter2 {
|
|
802
931
|
#enabled = false;
|
|
803
932
|
#blocked = /* @__PURE__ */ new Set();
|
|
804
933
|
#state = {
|
|
@@ -956,15 +1085,15 @@ function interfacesSignature() {
|
|
|
956
1085
|
|
|
957
1086
|
// ../host/dist/settings.js
|
|
958
1087
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
959
|
-
import { homedir as
|
|
960
|
-
import
|
|
961
|
-
var USER_SETTINGS =
|
|
962
|
-
var PROJECT_SETTINGS =
|
|
963
|
-
var LOCAL_SETTINGS =
|
|
1088
|
+
import { homedir as homedir3 } from "node:os";
|
|
1089
|
+
import path5 from "node:path";
|
|
1090
|
+
var USER_SETTINGS = path5.join(homedir3(), ".claude", "settings.json");
|
|
1091
|
+
var PROJECT_SETTINGS = path5.join(".claude", "settings.json");
|
|
1092
|
+
var LOCAL_SETTINGS = path5.join(".claude", "settings.local.json");
|
|
964
1093
|
function managedSettingsPath() {
|
|
965
1094
|
switch (process.platform) {
|
|
966
1095
|
case "win32":
|
|
967
|
-
return
|
|
1096
|
+
return path5.join(process.env.PROGRAMDATA ?? "C:\\ProgramData", "ClaudeCode", "managed-settings.json");
|
|
968
1097
|
case "darwin":
|
|
969
1098
|
return "/Library/Application Support/ClaudeCode/managed-settings.json";
|
|
970
1099
|
default:
|
|
@@ -975,8 +1104,8 @@ var EFFORT_LEVELS = ["low", "medium", "high", "xhigh", "max"];
|
|
|
975
1104
|
async function readConfiguredDefaults(cwd) {
|
|
976
1105
|
const files = [
|
|
977
1106
|
USER_SETTINGS,
|
|
978
|
-
|
|
979
|
-
|
|
1107
|
+
path5.join(cwd, PROJECT_SETTINGS),
|
|
1108
|
+
path5.join(cwd, LOCAL_SETTINGS),
|
|
980
1109
|
managedSettingsPath()
|
|
981
1110
|
];
|
|
982
1111
|
const result = {
|
|
@@ -1343,7 +1472,7 @@ var INTERRUPT_SETTLE_MS = 15e3;
|
|
|
1343
1472
|
var TASK_STOP_TIMEOUT_MS = 5e3;
|
|
1344
1473
|
var TASK_WAKE_MS = 5e3;
|
|
1345
1474
|
var CONTEXT_MIN_INTERVAL_MS = 5e3;
|
|
1346
|
-
var ClaudeSession = class extends
|
|
1475
|
+
var ClaudeSession = class extends EventEmitter3 {
|
|
1347
1476
|
id;
|
|
1348
1477
|
workspaceId;
|
|
1349
1478
|
cwd;
|
|
@@ -2506,7 +2635,7 @@ var ClaudeSession = class extends EventEmitter2 {
|
|
|
2506
2635
|
const target = writeTarget(input.tool_input);
|
|
2507
2636
|
if (!target)
|
|
2508
2637
|
return pass;
|
|
2509
|
-
const absolute =
|
|
2638
|
+
const absolute = path6.resolve(this.cwd, target);
|
|
2510
2639
|
if (roots.some((root) => contains(root, absolute)))
|
|
2511
2640
|
return pass;
|
|
2512
2641
|
return {
|
|
@@ -3132,35 +3261,35 @@ function contentToText2(content) {
|
|
|
3132
3261
|
}
|
|
3133
3262
|
|
|
3134
3263
|
// ../host/dist/antigravity-session.js
|
|
3135
|
-
import { EventEmitter as
|
|
3136
|
-
import { spawn as
|
|
3264
|
+
import { EventEmitter as EventEmitter4 } from "node:events";
|
|
3265
|
+
import { spawn as spawn3, execFile as execFile4 } from "node:child_process";
|
|
3137
3266
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3138
3267
|
import { mkdir as mkdir2, writeFile as writeFile2 } from "node:fs/promises";
|
|
3139
3268
|
import { tmpdir } from "node:os";
|
|
3140
|
-
import
|
|
3141
|
-
import { createInterface } from "node:readline";
|
|
3269
|
+
import path8 from "node:path";
|
|
3270
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
3142
3271
|
|
|
3143
3272
|
// ../host/dist/antigravity-cli.js
|
|
3144
|
-
import { execFile as
|
|
3145
|
-
import { existsSync } from "node:fs";
|
|
3146
|
-
import { homedir as
|
|
3147
|
-
import
|
|
3273
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
3274
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
3275
|
+
import { homedir as homedir4 } from "node:os";
|
|
3276
|
+
import path7 from "node:path";
|
|
3148
3277
|
function agyExecutable() {
|
|
3149
3278
|
const forced = process.env.CCV_AGY_PATH;
|
|
3150
|
-
if (forced &&
|
|
3279
|
+
if (forced && existsSync2(forced))
|
|
3151
3280
|
return forced;
|
|
3152
3281
|
const names2 = process.platform === "win32" ? ["agy.exe", "agy"] : ["agy"];
|
|
3153
|
-
const dirs = (process.env.PATH ?? "").split(
|
|
3282
|
+
const dirs = (process.env.PATH ?? "").split(path7.delimiter).filter(Boolean);
|
|
3154
3283
|
if (process.platform === "win32") {
|
|
3155
|
-
const local = process.env.LOCALAPPDATA ??
|
|
3156
|
-
dirs.push(
|
|
3284
|
+
const local = process.env.LOCALAPPDATA ?? path7.join(homedir4(), "AppData", "Local");
|
|
3285
|
+
dirs.push(path7.join(local, "agy", "bin"));
|
|
3157
3286
|
} else {
|
|
3158
|
-
dirs.push(
|
|
3287
|
+
dirs.push(path7.join(homedir4(), ".local", "bin"), "/usr/local/bin", "/opt/homebrew/bin");
|
|
3159
3288
|
}
|
|
3160
3289
|
for (const dir of dirs) {
|
|
3161
3290
|
for (const name of names2) {
|
|
3162
|
-
const candidate =
|
|
3163
|
-
if (
|
|
3291
|
+
const candidate = path7.join(dir, name);
|
|
3292
|
+
if (existsSync2(candidate))
|
|
3164
3293
|
return candidate;
|
|
3165
3294
|
}
|
|
3166
3295
|
}
|
|
@@ -3172,7 +3301,7 @@ function agyModels(file) {
|
|
|
3172
3301
|
if (modelsCache)
|
|
3173
3302
|
return modelsCache;
|
|
3174
3303
|
const pending = new Promise((resolve) => {
|
|
3175
|
-
|
|
3304
|
+
execFile3(file, ["models"], { timeout: 3e4, windowsHide: true }, (error, stdout) => {
|
|
3176
3305
|
if (error) {
|
|
3177
3306
|
resolve([]);
|
|
3178
3307
|
return;
|
|
@@ -3205,7 +3334,7 @@ function agyModels(file) {
|
|
|
3205
3334
|
}
|
|
3206
3335
|
function agyCommand(file, command, cwd) {
|
|
3207
3336
|
return new Promise((resolve) => {
|
|
3208
|
-
|
|
3337
|
+
execFile3(file, ["--output-format", "json", "-p", command], {
|
|
3209
3338
|
cwd,
|
|
3210
3339
|
timeout: 6e4,
|
|
3211
3340
|
windowsHide: true,
|
|
@@ -3352,7 +3481,7 @@ function agyContextWindow(model) {
|
|
|
3352
3481
|
|
|
3353
3482
|
// ../host/dist/antigravity-session.js
|
|
3354
3483
|
var TRANSIENT = /* @__PURE__ */ new Set(["assistant.delta", "thinking.delta", "state"]);
|
|
3355
|
-
var AntigravitySession = class extends
|
|
3484
|
+
var AntigravitySession = class extends EventEmitter4 {
|
|
3356
3485
|
id;
|
|
3357
3486
|
workspaceId;
|
|
3358
3487
|
cwd;
|
|
@@ -3556,7 +3685,7 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
3556
3685
|
return;
|
|
3557
3686
|
let child;
|
|
3558
3687
|
try {
|
|
3559
|
-
child =
|
|
3688
|
+
child = spawn3(this.#executable, this.#args(), {
|
|
3560
3689
|
cwd: this.cwd,
|
|
3561
3690
|
windowsHide: true,
|
|
3562
3691
|
env: { ...process.env, NO_COLOR: "1" }
|
|
@@ -3571,7 +3700,7 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
3571
3700
|
this.#texts.clear();
|
|
3572
3701
|
this.#thinking.clear();
|
|
3573
3702
|
this.#tools.clear();
|
|
3574
|
-
const lines =
|
|
3703
|
+
const lines = createInterface2({ input: child.stdout });
|
|
3575
3704
|
lines.on("line", (line) => {
|
|
3576
3705
|
if (this.#child !== child)
|
|
3577
3706
|
return;
|
|
@@ -3629,7 +3758,7 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
3629
3758
|
} catch {
|
|
3630
3759
|
}
|
|
3631
3760
|
if (process.platform === "win32" && child.pid) {
|
|
3632
|
-
|
|
3761
|
+
execFile4("taskkill", ["/pid", String(child.pid), "/T", "/F"], { windowsHide: true }, () => {
|
|
3633
3762
|
if (child.exitCode === null)
|
|
3634
3763
|
child.kill();
|
|
3635
3764
|
});
|
|
@@ -3825,12 +3954,12 @@ var AntigravitySession = class extends EventEmitter3 {
|
|
|
3825
3954
|
async #composePrompt(text, images) {
|
|
3826
3955
|
if (!images || images.length === 0)
|
|
3827
3956
|
return text;
|
|
3828
|
-
const dir =
|
|
3957
|
+
const dir = path8.join(tmpdir(), "ccv-antigravity", this.id);
|
|
3829
3958
|
await mkdir2(dir, { recursive: true });
|
|
3830
3959
|
const paths = [];
|
|
3831
3960
|
for (const image of images) {
|
|
3832
3961
|
const ext = image.mediaType.split("/")[1] === "jpeg" ? "jpg" : image.mediaType.split("/")[1];
|
|
3833
|
-
const file =
|
|
3962
|
+
const file = path8.join(dir, `${randomUUID2()}.${ext}`);
|
|
3834
3963
|
await writeFile2(file, Buffer.from(image.data, "base64"));
|
|
3835
3964
|
paths.push(file);
|
|
3836
3965
|
}
|
|
@@ -4217,18 +4346,713 @@ function describe2(error) {
|
|
|
4217
4346
|
return error instanceof Error ? error.message : String(error);
|
|
4218
4347
|
}
|
|
4219
4348
|
|
|
4349
|
+
// ../host/dist/codex-session.js
|
|
4350
|
+
import { EventEmitter as EventEmitter5 } from "node:events";
|
|
4351
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
4352
|
+
var TRANSIENT2 = /* @__PURE__ */ new Set(["assistant.delta", "thinking.delta", "state"]);
|
|
4353
|
+
var COMMANDS = [
|
|
4354
|
+
["help", "\u041A\u043E\u043C\u0430\u043D\u0434\u044B Codex"],
|
|
4355
|
+
["status", "\u0410\u043A\u043A\u0430\u0443\u043D\u0442 \u0438 \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438"],
|
|
4356
|
+
["login", "\u0412\u043E\u0439\u0442\u0438 \u0432 ChatGPT \u043F\u043E \u043A\u043E\u0434\u0443 \u0441 \u0442\u0435\u043B\u0435\u0444\u043E\u043D\u0430"],
|
|
4357
|
+
["model", "\u0412\u044B\u0431\u0440\u0430\u0442\u044C \u043C\u043E\u0434\u0435\u043B\u044C"],
|
|
4358
|
+
["effort", "\u0423\u0440\u043E\u0432\u0435\u043D\u044C \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043D\u0438\u044F"],
|
|
4359
|
+
["compact", "\u0421\u0436\u0430\u0442\u044C \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442"],
|
|
4360
|
+
["mcp", "\u041F\u043E\u0434\u043A\u043B\u044E\u0447\u0451\u043D\u043D\u044B\u0435 MCP-\u0441\u0435\u0440\u0432\u0435\u0440\u044B"],
|
|
4361
|
+
["skills", "\u041D\u0430\u0432\u044B\u043A\u0438 \u043F\u0440\u043E\u0435\u043A\u0442\u0430"],
|
|
4362
|
+
["fork", "\u041F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442\u044C \u0432 \u043E\u0442\u0434\u0435\u043B\u044C\u043D\u043E\u0439 \u0432\u0435\u0442\u043A\u0435 \u0440\u0430\u0437\u0433\u043E\u0432\u043E\u0440\u0430"]
|
|
4363
|
+
];
|
|
4364
|
+
var CodexSession = class extends EventEmitter5 {
|
|
4365
|
+
provider = "codex";
|
|
4366
|
+
id;
|
|
4367
|
+
workspaceId;
|
|
4368
|
+
cwd;
|
|
4369
|
+
journal = new Journal();
|
|
4370
|
+
parentSessionId = null;
|
|
4371
|
+
#options;
|
|
4372
|
+
#store;
|
|
4373
|
+
#record;
|
|
4374
|
+
#client = null;
|
|
4375
|
+
#closing = Promise.resolve();
|
|
4376
|
+
#state = "starting";
|
|
4377
|
+
#lastTurn = null;
|
|
4378
|
+
#capabilities = null;
|
|
4379
|
+
#usage = null;
|
|
4380
|
+
#context = null;
|
|
4381
|
+
#history;
|
|
4382
|
+
#ready = Promise.resolve();
|
|
4383
|
+
#queue = Promise.resolve();
|
|
4384
|
+
#generation = 0;
|
|
4385
|
+
#turnId = null;
|
|
4386
|
+
#interruptRequested = false;
|
|
4387
|
+
#forkPending;
|
|
4388
|
+
#turnDone = null;
|
|
4389
|
+
#startedAt = 0;
|
|
4390
|
+
#permissions = /* @__PURE__ */ new Map();
|
|
4391
|
+
#texts = /* @__PURE__ */ new Map();
|
|
4392
|
+
#thinking = /* @__PURE__ */ new Map();
|
|
4393
|
+
#tools = /* @__PURE__ */ new Set();
|
|
4394
|
+
constructor(options2) {
|
|
4395
|
+
super();
|
|
4396
|
+
this.#options = options2;
|
|
4397
|
+
this.#forkPending = options2.fork ?? false;
|
|
4398
|
+
this.#store = options2.store;
|
|
4399
|
+
const now = Date.now();
|
|
4400
|
+
this.#record = options2.record ? { ...options2.record } : {
|
|
4401
|
+
id: randomUUID3(),
|
|
4402
|
+
conversationId: null,
|
|
4403
|
+
workspaceId: options2.workspaceId,
|
|
4404
|
+
cwd: options2.cwd,
|
|
4405
|
+
title: options2.defaultTitle ?? null,
|
|
4406
|
+
model: options2.model ?? null,
|
|
4407
|
+
permissionMode: options2.permissionMode ?? "default",
|
|
4408
|
+
effort: null,
|
|
4409
|
+
createdAt: now,
|
|
4410
|
+
updatedAt: now
|
|
4411
|
+
};
|
|
4412
|
+
if (options2.fork)
|
|
4413
|
+
this.#record = { ...this.#record, id: randomUUID3(), createdAt: now, updatedAt: now };
|
|
4414
|
+
if (options2.model)
|
|
4415
|
+
this.#record.model = options2.model;
|
|
4416
|
+
if (options2.permissionMode)
|
|
4417
|
+
this.#record.permissionMode = options2.permissionMode;
|
|
4418
|
+
this.id = this.#record.id;
|
|
4419
|
+
this.workspaceId = options2.workspaceId;
|
|
4420
|
+
this.cwd = options2.cwd;
|
|
4421
|
+
this.#history = options2.record ? this.#store.readEvents(options2.record.id) : Promise.resolve([]);
|
|
4422
|
+
}
|
|
4423
|
+
get state() {
|
|
4424
|
+
return this.#state;
|
|
4425
|
+
}
|
|
4426
|
+
get claudeSessionId() {
|
|
4427
|
+
return this.id;
|
|
4428
|
+
}
|
|
4429
|
+
get capabilities() {
|
|
4430
|
+
return this.#capabilities;
|
|
4431
|
+
}
|
|
4432
|
+
get usage() {
|
|
4433
|
+
return this.#usage;
|
|
4434
|
+
}
|
|
4435
|
+
get context() {
|
|
4436
|
+
return this.#context;
|
|
4437
|
+
}
|
|
4438
|
+
async history() {
|
|
4439
|
+
await this.#ready;
|
|
4440
|
+
return this.#history;
|
|
4441
|
+
}
|
|
4442
|
+
summary() {
|
|
4443
|
+
return {
|
|
4444
|
+
id: this.id,
|
|
4445
|
+
provider: "codex",
|
|
4446
|
+
claudeSessionId: this.id,
|
|
4447
|
+
workspaceId: this.workspaceId,
|
|
4448
|
+
cwd: this.cwd,
|
|
4449
|
+
parentSessionId: null,
|
|
4450
|
+
title: this.#record.title,
|
|
4451
|
+
state: this.#state,
|
|
4452
|
+
lastTurn: this.#lastTurn,
|
|
4453
|
+
backgroundWork: false,
|
|
4454
|
+
tasks: [],
|
|
4455
|
+
model: this.#record.model,
|
|
4456
|
+
permissionMode: this.#record.permissionMode,
|
|
4457
|
+
effort: this.#record.effort,
|
|
4458
|
+
ultracode: false,
|
|
4459
|
+
thinking: true,
|
|
4460
|
+
switchModelsOnFlag: false,
|
|
4461
|
+
createdAt: this.#record.createdAt,
|
|
4462
|
+
updatedAt: this.#record.updatedAt,
|
|
4463
|
+
lastSeq: this.journal.lastSeq,
|
|
4464
|
+
totalCostUsd: 0
|
|
4465
|
+
};
|
|
4466
|
+
}
|
|
4467
|
+
start() {
|
|
4468
|
+
this.#ready = this.#connect().catch((error) => this.#fail(error));
|
|
4469
|
+
}
|
|
4470
|
+
async #connect() {
|
|
4471
|
+
const client = new CodexClient();
|
|
4472
|
+
this.#client = client;
|
|
4473
|
+
client.on("message", (message) => {
|
|
4474
|
+
if (this.#client !== client)
|
|
4475
|
+
return;
|
|
4476
|
+
try {
|
|
4477
|
+
this.#message(message);
|
|
4478
|
+
} catch (error) {
|
|
4479
|
+
this.#fail(error);
|
|
4480
|
+
}
|
|
4481
|
+
});
|
|
4482
|
+
client.on("stderr", (data) => this.emit("stderr", data));
|
|
4483
|
+
client.on("disconnect", (error) => {
|
|
4484
|
+
if (this.#client === client && this.#state !== "closed")
|
|
4485
|
+
this.#fail(error);
|
|
4486
|
+
});
|
|
4487
|
+
await client.start(this.cwd);
|
|
4488
|
+
const policy = this.#policy();
|
|
4489
|
+
const forking = this.#forkPending;
|
|
4490
|
+
const params = {
|
|
4491
|
+
cwd: this.cwd,
|
|
4492
|
+
...this.#record.model ? { model: this.#record.model } : {},
|
|
4493
|
+
approvalPolicy: policy.approvalPolicy,
|
|
4494
|
+
sandbox: policy.sandbox,
|
|
4495
|
+
approvalsReviewer: "user"
|
|
4496
|
+
};
|
|
4497
|
+
let response;
|
|
4498
|
+
let recreatedEmpty = false;
|
|
4499
|
+
try {
|
|
4500
|
+
response = await client.request(this.#record.conversationId ? forking ? "thread/fork" : "thread/resume" : "thread/start", {
|
|
4501
|
+
...params,
|
|
4502
|
+
...this.#record.conversationId ? { threadId: this.#record.conversationId } : {}
|
|
4503
|
+
});
|
|
4504
|
+
} catch (error) {
|
|
4505
|
+
const history = await this.#history;
|
|
4506
|
+
const hasModelTurns = history.some(({ event }) => event.kind === "result" || event.kind === "tool.use" || event.kind === "user.message" && !event.text.startsWith("/"));
|
|
4507
|
+
if (!this.#record.conversationId || hasModelTurns || !/no rollout found|thread.*not found/i.test(String(error)))
|
|
4508
|
+
throw error;
|
|
4509
|
+
response = await client.request("thread/start", params);
|
|
4510
|
+
recreatedEmpty = true;
|
|
4511
|
+
}
|
|
4512
|
+
if (this.#client !== client || this.#state === "closed")
|
|
4513
|
+
return;
|
|
4514
|
+
this.#record.conversationId = response.thread.id;
|
|
4515
|
+
this.#forkPending = false;
|
|
4516
|
+
this.#record.model = response.model;
|
|
4517
|
+
this.#record.effort ??= this.#effort(response.reasoningEffort);
|
|
4518
|
+
if (this.#record.conversationId && (await this.#history).length === 0) {
|
|
4519
|
+
const imported = [];
|
|
4520
|
+
const add = (event) => imported.push({ seq: imported.length + 1, ts: this.#record.createdAt, event });
|
|
4521
|
+
let items = (response.thread.turns ?? []).flatMap((turn) => turn.items ?? []);
|
|
4522
|
+
if (items.length === 0 && this.#options.record && !recreatedEmpty) {
|
|
4523
|
+
let cursor = null;
|
|
4524
|
+
do {
|
|
4525
|
+
const page = await client.request("thread/items/list", { threadId: this.#record.conversationId, cursor, limit: 100, sortDirection: "asc" });
|
|
4526
|
+
items.push(...(page.data ?? []).map((entry) => entry.item));
|
|
4527
|
+
cursor = page.nextCursor ?? null;
|
|
4528
|
+
} while (cursor);
|
|
4529
|
+
}
|
|
4530
|
+
for (const item of items) {
|
|
4531
|
+
if (item.type === "userMessage") {
|
|
4532
|
+
const content = item.content ?? [];
|
|
4533
|
+
const images = content.filter((v) => v.type === "image" && /^data:image\//.test(v.url)).flatMap((v) => {
|
|
4534
|
+
const match = /^data:(image\/(?:png|jpeg|webp|gif));base64,(.+)$/.exec(v.url);
|
|
4535
|
+
return match ? [{ mediaType: match[1], data: match[2] }] : [];
|
|
4536
|
+
});
|
|
4537
|
+
add({ kind: "user.message", text: content.filter((v) => v.type === "text").map((v) => v.text).join("\n"), ...images.length ? { images } : {} });
|
|
4538
|
+
} else if (item.type === "agentMessage" || item.type === "plan")
|
|
4539
|
+
add({ kind: "assistant.text", text: item.text, blockId: item.id });
|
|
4540
|
+
else if (item.type === "reasoning")
|
|
4541
|
+
add({ kind: "assistant.thinking", text: [...item.summary ?? [], ...item.content ?? []].join("\n"), blockId: `${item.id}:thinking` });
|
|
4542
|
+
else if (item.type === "commandExecution") {
|
|
4543
|
+
add({ kind: "tool.use", toolUseId: item.id, name: "Bash", input: { command: item.command } });
|
|
4544
|
+
add({ kind: "tool.result", toolUseId: item.id, content: item.aggregatedOutput ?? "", isError: item.status === "failed" || item.exitCode != null && item.exitCode !== 0 });
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
if (imported.length) {
|
|
4548
|
+
this.#history = Promise.resolve(imported);
|
|
4549
|
+
if (!forking)
|
|
4550
|
+
await this.#store.appendEvents(this.id, imported);
|
|
4551
|
+
}
|
|
4552
|
+
}
|
|
4553
|
+
await this.#store.save(this.#record);
|
|
4554
|
+
if (forking) {
|
|
4555
|
+
const events = await this.#history;
|
|
4556
|
+
await this.#store.appendEvents(this.id, events);
|
|
4557
|
+
}
|
|
4558
|
+
const catalog = await client.request("model/list", {}).catch(() => ({ data: [] }));
|
|
4559
|
+
const models = (catalog.data ?? []).filter((m) => !m.hidden).map((m) => ({
|
|
4560
|
+
value: m.model,
|
|
4561
|
+
resolvedModel: m.model,
|
|
4562
|
+
displayName: m.displayName,
|
|
4563
|
+
description: m.description ?? "",
|
|
4564
|
+
supportsEffort: (m.supportedReasoningEfforts ?? []).some((e) => this.#effort(e.reasoningEffort)),
|
|
4565
|
+
effortLevels: (m.supportedReasoningEfforts ?? []).map((e) => this.#effort(e.reasoningEffort)).filter(Boolean),
|
|
4566
|
+
supportsThinking: false,
|
|
4567
|
+
supportsAutoMode: false
|
|
4568
|
+
}));
|
|
4569
|
+
this.#capabilities = {
|
|
4570
|
+
cwd: this.cwd,
|
|
4571
|
+
model: this.#record.model ?? "",
|
|
4572
|
+
permissionMode: this.#record.permissionMode,
|
|
4573
|
+
slashCommands: COMMANDS.map(([name]) => name),
|
|
4574
|
+
commands: COMMANDS.map(([name, description]) => ({ name, description, argumentHint: "", aliases: [] })),
|
|
4575
|
+
models,
|
|
4576
|
+
tools: ["shell", "apply_patch", "web_search", "mcp"],
|
|
4577
|
+
agents: [],
|
|
4578
|
+
mcpServers: [],
|
|
4579
|
+
flags: ["codex-app-server"]
|
|
4580
|
+
};
|
|
4581
|
+
this.emit("capabilities");
|
|
4582
|
+
this.#setState("idle");
|
|
4583
|
+
void this.refreshUsage().catch(() => {
|
|
4584
|
+
});
|
|
4585
|
+
}
|
|
4586
|
+
#effort(value) {
|
|
4587
|
+
return ["low", "medium", "high", "xhigh", "max"].includes(String(value)) ? value : null;
|
|
4588
|
+
}
|
|
4589
|
+
#policy() {
|
|
4590
|
+
const mode = this.#record.permissionMode;
|
|
4591
|
+
if (mode === "bypassPermissions")
|
|
4592
|
+
return { approvalPolicy: "never", sandbox: "danger-full-access", sandboxPolicy: { type: "dangerFullAccess" } };
|
|
4593
|
+
if (mode === "plan" || mode === "default")
|
|
4594
|
+
return { approvalPolicy: "on-request", sandbox: "read-only", sandboxPolicy: { type: "readOnly", networkAccess: false } };
|
|
4595
|
+
const roots = this.#options.writableRoots?.();
|
|
4596
|
+
return {
|
|
4597
|
+
approvalPolicy: mode === "dontAsk" ? "never" : "on-request",
|
|
4598
|
+
sandbox: "workspace-write",
|
|
4599
|
+
sandboxPolicy: { type: "workspaceWrite", writableRoots: roots ?? [this.cwd], networkAccess: false, excludeTmpdirEnvVar: false, excludeSlashTmp: false }
|
|
4600
|
+
};
|
|
4601
|
+
}
|
|
4602
|
+
sendPrompt(text, images) {
|
|
4603
|
+
if (this.#state === "closed")
|
|
4604
|
+
throw new Error("\u0421\u0435\u0441\u0441\u0438\u044F Codex \u0437\u0430\u043A\u0440\u044B\u0442\u0430");
|
|
4605
|
+
const generation = this.#generation;
|
|
4606
|
+
this.#queue = this.#queue.then(async () => {
|
|
4607
|
+
await this.#ready;
|
|
4608
|
+
if (generation !== this.#generation || this.#state === "closed")
|
|
4609
|
+
return;
|
|
4610
|
+
if (this.#state === "error")
|
|
4611
|
+
throw new Error("\u041F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u0435 \u0441\u0435\u0441\u0441\u0438\u044E Codex");
|
|
4612
|
+
const blocked = networkGuard.blockedReason();
|
|
4613
|
+
if (blocked)
|
|
4614
|
+
throw new Error(blocked);
|
|
4615
|
+
if (text.startsWith("/") && !images?.length) {
|
|
4616
|
+
try {
|
|
4617
|
+
await this.#command(text);
|
|
4618
|
+
} catch (error) {
|
|
4619
|
+
this.#recordEvent({ kind: "error", message: error instanceof Error ? error.message : String(error) });
|
|
4620
|
+
}
|
|
4621
|
+
return;
|
|
4622
|
+
}
|
|
4623
|
+
this.#interruptRequested = false;
|
|
4624
|
+
this.#recordEvent({ kind: "user.message", text, ...images?.length ? { images } : {} });
|
|
4625
|
+
if (this.#record.title === this.#options.defaultTitle || !this.#record.title)
|
|
4626
|
+
this.setTitle(text.trim().slice(0, 70));
|
|
4627
|
+
this.#startedAt = Date.now();
|
|
4628
|
+
this.#setState("running");
|
|
4629
|
+
const done = new Promise((resolve) => {
|
|
4630
|
+
this.#turnDone = resolve;
|
|
4631
|
+
});
|
|
4632
|
+
const policy = this.#policy();
|
|
4633
|
+
const response = await this.#client.request("turn/start", {
|
|
4634
|
+
threadId: this.#record.conversationId,
|
|
4635
|
+
input: [
|
|
4636
|
+
{ type: "text", text, text_elements: [] },
|
|
4637
|
+
...(images ?? []).map((img) => ({ type: "image", url: `data:${img.mediaType};base64,${img.data}` }))
|
|
4638
|
+
],
|
|
4639
|
+
cwd: this.cwd,
|
|
4640
|
+
approvalPolicy: policy.approvalPolicy,
|
|
4641
|
+
sandboxPolicy: policy.sandboxPolicy,
|
|
4642
|
+
approvalsReviewer: "user",
|
|
4643
|
+
...this.#record.model ? { model: this.#record.model } : {},
|
|
4644
|
+
...this.#record.effort ? { effort: this.#record.effort } : {}
|
|
4645
|
+
});
|
|
4646
|
+
if (this.#turnDone) {
|
|
4647
|
+
this.#turnId = response.turn.id;
|
|
4648
|
+
if (this.#interruptRequested)
|
|
4649
|
+
await this.#interruptTurn();
|
|
4650
|
+
}
|
|
4651
|
+
await done;
|
|
4652
|
+
}).catch((error) => this.#fail(error));
|
|
4653
|
+
}
|
|
4654
|
+
async #command(text) {
|
|
4655
|
+
const [name, ...args] = text.trim().slice(1).split(/\s+/);
|
|
4656
|
+
const arg = args.join(" ");
|
|
4657
|
+
let reply;
|
|
4658
|
+
switch (name) {
|
|
4659
|
+
case "model":
|
|
4660
|
+
if (arg)
|
|
4661
|
+
await this.setModel(arg);
|
|
4662
|
+
reply = `\u041C\u043E\u0434\u0435\u043B\u044C: ${this.#record.model}`;
|
|
4663
|
+
break;
|
|
4664
|
+
case "effort":
|
|
4665
|
+
if (arg)
|
|
4666
|
+
await this.setEffort(arg);
|
|
4667
|
+
reply = `\u0423\u0441\u0438\u043B\u0438\u0435: ${this.#record.effort ?? "\u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E"}`;
|
|
4668
|
+
break;
|
|
4669
|
+
case "compact":
|
|
4670
|
+
await this.#client.request("thread/compact/start", { threadId: this.#record.conversationId });
|
|
4671
|
+
reply = "Codex \u043D\u0430\u0447\u0430\u043B \u0441\u0436\u0430\u0442\u0438\u0435 \u043A\u043E\u043D\u0442\u0435\u043A\u0441\u0442\u0430.";
|
|
4672
|
+
break;
|
|
4673
|
+
case "status":
|
|
4674
|
+
reply = JSON.stringify(await this.#client.request("account/read", {}), null, 2);
|
|
4675
|
+
break;
|
|
4676
|
+
case "login": {
|
|
4677
|
+
const login = await this.#client.request("account/login/start", { type: "chatgptDeviceCode" });
|
|
4678
|
+
reply = `\u0412\u0445\u043E\u0434 \u0432 Codex: ${login.verificationUrl ?? login.authUrl ?? ""}
|
|
4679
|
+
\u041A\u043E\u0434: ${login.userCode ?? ""}`;
|
|
4680
|
+
break;
|
|
4681
|
+
}
|
|
4682
|
+
case "mcp":
|
|
4683
|
+
reply = JSON.stringify(await this.#client.request("mcpServerStatus/list", {}), null, 2);
|
|
4684
|
+
break;
|
|
4685
|
+
case "skills":
|
|
4686
|
+
reply = JSON.stringify(await this.#client.request("skills/list", { cwds: [this.cwd] }), null, 2);
|
|
4687
|
+
break;
|
|
4688
|
+
default:
|
|
4689
|
+
reply = COMMANDS.map(([command, description]) => `/${command} \u2014 ${description}`).join("\n");
|
|
4690
|
+
}
|
|
4691
|
+
this.#recordEvent({ kind: "user.message", text });
|
|
4692
|
+
this.#recordEvent({ kind: "assistant.text", text: reply, blockId: randomUUID3() });
|
|
4693
|
+
}
|
|
4694
|
+
#message(message) {
|
|
4695
|
+
const p = message.params ?? {};
|
|
4696
|
+
if (p.threadId && this.#record.conversationId && p.threadId !== this.#record.conversationId)
|
|
4697
|
+
return;
|
|
4698
|
+
if (message.id !== void 0 && message.method) {
|
|
4699
|
+
this.#request(message.id, message.method, p);
|
|
4700
|
+
return;
|
|
4701
|
+
}
|
|
4702
|
+
switch (message.method) {
|
|
4703
|
+
case "turn/started":
|
|
4704
|
+
this.#turnId = p.turn.id;
|
|
4705
|
+
this.#setState("running");
|
|
4706
|
+
if (this.#interruptRequested)
|
|
4707
|
+
void this.#interruptTurn().catch((error) => this.#fail(error));
|
|
4708
|
+
break;
|
|
4709
|
+
case "item/agentMessage/delta": {
|
|
4710
|
+
this.#texts.set(p.itemId, (this.#texts.get(p.itemId) ?? "") + p.delta);
|
|
4711
|
+
this.#recordEvent({ kind: "assistant.delta", text: p.delta, blockId: p.itemId });
|
|
4712
|
+
break;
|
|
4713
|
+
}
|
|
4714
|
+
case "item/reasoning/summaryTextDelta":
|
|
4715
|
+
case "item/reasoning/textDelta": {
|
|
4716
|
+
this.#thinking.set(p.itemId, (this.#thinking.get(p.itemId) ?? "") + p.delta);
|
|
4717
|
+
this.#recordEvent({ kind: "thinking.delta", text: p.delta, blockId: `${p.itemId}:thinking` });
|
|
4718
|
+
break;
|
|
4719
|
+
}
|
|
4720
|
+
case "item/started":
|
|
4721
|
+
this.#item(p.item, false);
|
|
4722
|
+
break;
|
|
4723
|
+
case "item/completed":
|
|
4724
|
+
this.#item(p.item, true);
|
|
4725
|
+
break;
|
|
4726
|
+
case "turn/plan/updated":
|
|
4727
|
+
this.#recordEvent({ kind: "system", subtype: "codex.plan", data: p });
|
|
4728
|
+
break;
|
|
4729
|
+
case "thread/tokenUsage/updated": {
|
|
4730
|
+
const u = p.tokenUsage;
|
|
4731
|
+
if (u?.modelContextWindow) {
|
|
4732
|
+
this.#context = { tokens: u.last.totalTokens, maxTokens: u.modelContextWindow, fetchedAt: Date.now() };
|
|
4733
|
+
this.emit("context", this.#context);
|
|
4734
|
+
}
|
|
4735
|
+
break;
|
|
4736
|
+
}
|
|
4737
|
+
case "account/rateLimits/updated":
|
|
4738
|
+
this.#rateLimits(p.rateLimits);
|
|
4739
|
+
break;
|
|
4740
|
+
case "account/login/completed":
|
|
4741
|
+
this.#recordEvent({ kind: "assistant.text", blockId: randomUUID3(), text: p.success ? "\u0412\u0445\u043E\u0434 \u0432 Codex \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D." : `\u0412\u0445\u043E\u0434 \u043D\u0435 \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D: ${p.error ?? ""}` });
|
|
4742
|
+
break;
|
|
4743
|
+
case "error":
|
|
4744
|
+
this.#recordEvent({ kind: "error", message: p.error?.message ?? "\u041E\u0448\u0438\u0431\u043A\u0430 Codex" });
|
|
4745
|
+
break;
|
|
4746
|
+
case "turn/completed": {
|
|
4747
|
+
this.#flush();
|
|
4748
|
+
const status = p.turn.status;
|
|
4749
|
+
this.#lastTurn = status === "completed" ? "completed" : status === "interrupted" ? "interrupted" : "failed";
|
|
4750
|
+
if (p.turn.error)
|
|
4751
|
+
this.#recordEvent({ kind: "error", message: p.turn.error.message });
|
|
4752
|
+
this.#recordEvent({ kind: "result", subtype: this.#lastTurn, isError: this.#lastTurn === "failed", durationMs: Date.now() - this.#startedAt, costUsd: null, usage: null, contextTokens: this.#context?.tokens ?? null, text: null });
|
|
4753
|
+
this.#clearPermissions();
|
|
4754
|
+
this.#turnId = null;
|
|
4755
|
+
this.#interruptRequested = false;
|
|
4756
|
+
this.#turnDone?.();
|
|
4757
|
+
this.#turnDone = null;
|
|
4758
|
+
this.#setState("idle");
|
|
4759
|
+
break;
|
|
4760
|
+
}
|
|
4761
|
+
}
|
|
4762
|
+
}
|
|
4763
|
+
#item(item, completed) {
|
|
4764
|
+
if (!item?.id)
|
|
4765
|
+
return;
|
|
4766
|
+
const id = item.id;
|
|
4767
|
+
if (item.type === "agentMessage" || item.type === "plan") {
|
|
4768
|
+
if (completed) {
|
|
4769
|
+
this.#texts.delete(id);
|
|
4770
|
+
this.#recordEvent({ kind: "assistant.text", text: item.text ?? "", blockId: id });
|
|
4771
|
+
}
|
|
4772
|
+
return;
|
|
4773
|
+
}
|
|
4774
|
+
if (item.type === "reasoning") {
|
|
4775
|
+
if (completed) {
|
|
4776
|
+
const text = this.#thinking.get(id) ?? [...item.summary ?? [], ...item.content ?? []].join("\n");
|
|
4777
|
+
this.#thinking.delete(id);
|
|
4778
|
+
if (text)
|
|
4779
|
+
this.#recordEvent({ kind: "assistant.thinking", text, blockId: `${id}:thinking` });
|
|
4780
|
+
}
|
|
4781
|
+
return;
|
|
4782
|
+
}
|
|
4783
|
+
if (["userMessage", "contextCompaction"].includes(item.type))
|
|
4784
|
+
return;
|
|
4785
|
+
if (!this.#tools.has(id)) {
|
|
4786
|
+
this.#tools.add(id);
|
|
4787
|
+
const name = item.type === "commandExecution" ? "Bash" : item.type === "fileChange" ? "apply_patch" : item.tool ?? item.type;
|
|
4788
|
+
this.#recordEvent({ kind: "tool.use", toolUseId: id, name, input: item.type === "commandExecution" ? { command: item.command, cwd: item.cwd } : item.arguments ?? item });
|
|
4789
|
+
}
|
|
4790
|
+
if (completed) {
|
|
4791
|
+
this.#tools.delete(id);
|
|
4792
|
+
this.#recordEvent({ kind: "tool.result", toolUseId: id, content: item.aggregatedOutput ?? JSON.stringify(item.result ?? item.changes ?? item), isError: ["failed", "declined"].includes(item.status) || typeof item.exitCode === "number" && item.exitCode !== 0 });
|
|
4793
|
+
}
|
|
4794
|
+
}
|
|
4795
|
+
#request(id, method, params) {
|
|
4796
|
+
if (!["item/commandExecution/requestApproval", "item/fileChange/requestApproval", "item/permissions/requestApproval", "item/tool/requestUserInput"].includes(method)) {
|
|
4797
|
+
this.#client?.reject(id, `Unsupported client request: ${method}`);
|
|
4798
|
+
return;
|
|
4799
|
+
}
|
|
4800
|
+
const requestId = `codex:${String(id)}`;
|
|
4801
|
+
this.#permissions.set(requestId, { id, method, params });
|
|
4802
|
+
const questions = method === "item/tool/requestUserInput" ? (params.questions ?? []).map((q) => ({ question: q.question, header: q.header, options: q.options ?? [], multiSelect: false })) : void 0;
|
|
4803
|
+
this.#recordEvent({ kind: "permission.request", requestId, toolName: questions ? "AskUserQuestion" : method.includes("commandExecution") ? "Bash" : method.includes("fileChange") ? "apply_patch" : "Codex permissions", input: params, ...params.reason ? { reason: params.reason } : {}, ...params.itemId ? { toolUseId: params.itemId } : {}, ...questions ? { questions } : {} });
|
|
4804
|
+
this.#setState("waiting_permission");
|
|
4805
|
+
}
|
|
4806
|
+
respondPermission(requestId, decision, reason, answers) {
|
|
4807
|
+
const pending = this.#permissions.get(requestId);
|
|
4808
|
+
if (!pending)
|
|
4809
|
+
return;
|
|
4810
|
+
let response = { decision: decision === "allow" ? "accept" : "decline" };
|
|
4811
|
+
if (pending.method === "item/tool/requestUserInput")
|
|
4812
|
+
response = { answers: Object.fromEntries((pending.params.questions ?? []).map((q) => [q.id, { answers: decision === "allow" ? [answers?.[q.question] ?? ""] : ["\u041F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u0435\u043B\u044C \u043E\u0442\u043A\u043B\u043E\u043D\u0438\u043B \u0432\u043E\u043F\u0440\u043E\u0441"] }])) };
|
|
4813
|
+
if (pending.method === "item/permissions/requestApproval")
|
|
4814
|
+
response = { permissions: decision === "allow" ? Object.fromEntries(Object.entries(pending.params.permissions ?? {}).filter(([, value]) => value != null)) : {}, scope: "turn" };
|
|
4815
|
+
this.#client?.respond(pending.id, response);
|
|
4816
|
+
this.#permissions.delete(requestId);
|
|
4817
|
+
this.#recordEvent({ kind: "permission.resolved", requestId, decision, ...reason ? { reason } : {}, ...answers ? { answers } : {} });
|
|
4818
|
+
this.#setState(this.#permissions.size ? "waiting_permission" : "running");
|
|
4819
|
+
}
|
|
4820
|
+
#clearPermissions() {
|
|
4821
|
+
for (const requestId of this.#permissions.keys())
|
|
4822
|
+
this.#recordEvent({ kind: "permission.resolved", requestId, decision: "deny", reason: "\u0425\u043E\u0434 \u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043D" });
|
|
4823
|
+
this.#permissions.clear();
|
|
4824
|
+
}
|
|
4825
|
+
#flush() {
|
|
4826
|
+
for (const [blockId, text] of this.#texts)
|
|
4827
|
+
this.#recordEvent({ kind: "assistant.text", blockId, text });
|
|
4828
|
+
for (const [id, text] of this.#thinking)
|
|
4829
|
+
this.#recordEvent({ kind: "assistant.thinking", blockId: `${id}:thinking`, text });
|
|
4830
|
+
for (const toolUseId of this.#tools)
|
|
4831
|
+
this.#recordEvent({ kind: "tool.result", toolUseId, content: "\u0412\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u0435 \u043F\u0440\u0435\u0440\u0432\u0430\u043D\u043E", isError: true });
|
|
4832
|
+
this.#texts.clear();
|
|
4833
|
+
this.#thinking.clear();
|
|
4834
|
+
this.#tools.clear();
|
|
4835
|
+
}
|
|
4836
|
+
#recordEvent(event) {
|
|
4837
|
+
const entry = this.journal.append(event);
|
|
4838
|
+
this.#record.updatedAt = entry.ts;
|
|
4839
|
+
if (!TRANSIENT2.has(event.kind))
|
|
4840
|
+
void this.#store.appendEvents(this.id, [entry]).catch((e) => this.emit("stderr", String(e)));
|
|
4841
|
+
this.emit("event", entry);
|
|
4842
|
+
}
|
|
4843
|
+
#setState(state) {
|
|
4844
|
+
this.#state = state;
|
|
4845
|
+
this.#recordEvent({ kind: "state", state });
|
|
4846
|
+
this.emit("summary", this.summary());
|
|
4847
|
+
void this.#store.save(this.#record).catch((e) => this.emit("stderr", String(e)));
|
|
4848
|
+
}
|
|
4849
|
+
#fail(error) {
|
|
4850
|
+
if (this.#state === "closed" || this.#state === "error")
|
|
4851
|
+
return;
|
|
4852
|
+
const client = this.#client;
|
|
4853
|
+
this.#client = null;
|
|
4854
|
+
if (client)
|
|
4855
|
+
this.#closing = client.close();
|
|
4856
|
+
this.#flush();
|
|
4857
|
+
this.#clearPermissions();
|
|
4858
|
+
this.#turnDone?.();
|
|
4859
|
+
this.#turnDone = null;
|
|
4860
|
+
this.#turnId = null;
|
|
4861
|
+
this.#recordEvent({ kind: "error", message: error instanceof Error ? error.message : String(error) });
|
|
4862
|
+
this.#lastTurn = "failed";
|
|
4863
|
+
this.#setState("error");
|
|
4864
|
+
}
|
|
4865
|
+
async interrupt() {
|
|
4866
|
+
this.#generation++;
|
|
4867
|
+
this.#interruptRequested = true;
|
|
4868
|
+
await this.#interruptTurn();
|
|
4869
|
+
}
|
|
4870
|
+
async #interruptTurn() {
|
|
4871
|
+
if (!this.#turnId || !this.#interruptRequested)
|
|
4872
|
+
return;
|
|
4873
|
+
this.#interruptRequested = false;
|
|
4874
|
+
await this.#client?.request("turn/interrupt", { threadId: this.#record.conversationId, turnId: this.#turnId });
|
|
4875
|
+
}
|
|
4876
|
+
async close(_reason = "closed by client") {
|
|
4877
|
+
this.#generation++;
|
|
4878
|
+
const client = this.#client;
|
|
4879
|
+
this.#client = null;
|
|
4880
|
+
this.#flush();
|
|
4881
|
+
this.#clearPermissions();
|
|
4882
|
+
this.#turnDone?.();
|
|
4883
|
+
this.#turnDone = null;
|
|
4884
|
+
this.#setState("closed");
|
|
4885
|
+
await client?.close();
|
|
4886
|
+
await this.#closing;
|
|
4887
|
+
await this.#store.save(this.#record);
|
|
4888
|
+
}
|
|
4889
|
+
suspend(reason) {
|
|
4890
|
+
if (this.#state === "closed")
|
|
4891
|
+
return;
|
|
4892
|
+
const client = this.#client;
|
|
4893
|
+
this.#client = null;
|
|
4894
|
+
client?.close();
|
|
4895
|
+
this.#generation++;
|
|
4896
|
+
this.#fail(new Error(reason));
|
|
4897
|
+
}
|
|
4898
|
+
reconnect(_reason) {
|
|
4899
|
+
if (this.#state === "closed")
|
|
4900
|
+
return;
|
|
4901
|
+
const client = this.#client;
|
|
4902
|
+
this.#client = null;
|
|
4903
|
+
client?.close();
|
|
4904
|
+
this.#generation++;
|
|
4905
|
+
this.#flush();
|
|
4906
|
+
this.#clearPermissions();
|
|
4907
|
+
this.#turnDone?.();
|
|
4908
|
+
this.#turnDone = null;
|
|
4909
|
+
this.#setState("reconnecting");
|
|
4910
|
+
this.start();
|
|
4911
|
+
}
|
|
4912
|
+
async setPermissionMode(mode) {
|
|
4913
|
+
this.#record.permissionMode = mode;
|
|
4914
|
+
this.#changed();
|
|
4915
|
+
}
|
|
4916
|
+
async setModel(model) {
|
|
4917
|
+
if (this.#capabilities && !this.#capabilities.models.some((m) => m.value === model))
|
|
4918
|
+
throw new Error(`\u041C\u043E\u0434\u0435\u043B\u044C Codex \u043D\u0435\u0434\u043E\u0441\u0442\u0443\u043F\u043D\u0430: ${model}`);
|
|
4919
|
+
this.#record.model = model;
|
|
4920
|
+
const supported = this.#capabilities?.models.find((m) => m.value === model)?.effortLevels;
|
|
4921
|
+
if (this.#record.effort && supported && !supported.includes(this.#record.effort))
|
|
4922
|
+
this.#record.effort = null;
|
|
4923
|
+
this.#changed();
|
|
4924
|
+
}
|
|
4925
|
+
async setEffort(effort) {
|
|
4926
|
+
const levels = this.#capabilities?.models.find((m) => m.value === this.#record.model)?.effortLevels ?? [];
|
|
4927
|
+
if (!levels.includes(effort))
|
|
4928
|
+
throw new Error(`\u041C\u043E\u0434\u0435\u043B\u044C \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0443\u0441\u0438\u043B\u0438\u0435 ${effort}`);
|
|
4929
|
+
this.#record.effort = effort;
|
|
4930
|
+
this.#changed();
|
|
4931
|
+
}
|
|
4932
|
+
#changed() {
|
|
4933
|
+
if (this.#capabilities) {
|
|
4934
|
+
this.#capabilities.model = this.#record.model ?? "";
|
|
4935
|
+
this.#capabilities.permissionMode = this.#record.permissionMode;
|
|
4936
|
+
this.emit("capabilities");
|
|
4937
|
+
}
|
|
4938
|
+
this.emit("summary", this.summary());
|
|
4939
|
+
void this.#store.save(this.#record).catch((e) => this.emit("stderr", String(e)));
|
|
4940
|
+
}
|
|
4941
|
+
setTitle(title) {
|
|
4942
|
+
this.#record.title = title;
|
|
4943
|
+
this.#changed();
|
|
4944
|
+
if (this.#record.conversationId)
|
|
4945
|
+
void this.#client?.request("thread/name/set", { threadId: this.#record.conversationId, name: title }).catch(() => {
|
|
4946
|
+
});
|
|
4947
|
+
}
|
|
4948
|
+
#rateLimits(limits) {
|
|
4949
|
+
if (!limits)
|
|
4950
|
+
return;
|
|
4951
|
+
const window = (w) => w ? { utilization: w.usedPercent, resetsAt: w.resetsAt ? new Date(w.resetsAt * 1e3).toISOString() : "" } : null;
|
|
4952
|
+
this.#usage = {
|
|
4953
|
+
available: !!(limits.primary || limits.secondary),
|
|
4954
|
+
plan: limits.planType ?? "",
|
|
4955
|
+
fiveHour: null,
|
|
4956
|
+
sevenDay: null,
|
|
4957
|
+
sevenDayOpus: null,
|
|
4958
|
+
fetchedAt: Date.now(),
|
|
4959
|
+
buckets: [limits.primary, limits.secondary].flatMap((w, i) => w ? [{ id: `codex-${i}`, label: w.windowDurationMins ? `${w.windowDurationMins / 60} \u0447` : i === 0 ? "\u041E\u0441\u043D\u043E\u0432\u043D\u043E\u0439" : "\u0414\u043E\u043F\u043E\u043B\u043D\u0438\u0442\u0435\u043B\u044C\u043D\u044B\u0439", title: limits.limitName ?? "Codex", description: "", period: "", window: window(w) }] : [])
|
|
4960
|
+
};
|
|
4961
|
+
this.emit("usage", this.#usage);
|
|
4962
|
+
}
|
|
4963
|
+
async refreshUsage(_force = false) {
|
|
4964
|
+
if (this.#client)
|
|
4965
|
+
this.#rateLimits((await this.#client.request("account/rateLimits/read", {})).rateLimits);
|
|
4966
|
+
}
|
|
4967
|
+
async refreshContext(_force = false) {
|
|
4968
|
+
if (this.#context)
|
|
4969
|
+
this.emit("context", this.#context);
|
|
4970
|
+
}
|
|
4971
|
+
async editPrompt(userIndex, text, images) {
|
|
4972
|
+
await this.#ready;
|
|
4973
|
+
const blocked = networkGuard.blockedReason();
|
|
4974
|
+
if (blocked)
|
|
4975
|
+
throw new Error(blocked);
|
|
4976
|
+
if (!this.#client || this.#state === "closed" || this.#state === "error")
|
|
4977
|
+
throw new Error("\u041F\u0435\u0440\u0435\u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u0435 \u0441\u0435\u0441\u0441\u0438\u044E Codex");
|
|
4978
|
+
await this.interrupt();
|
|
4979
|
+
await this.#queue;
|
|
4980
|
+
const events = await this.#store.readEvents(this.id);
|
|
4981
|
+
const messages = events.filter((entry) => entry.event.kind === "user.message");
|
|
4982
|
+
const target = messages[userIndex];
|
|
4983
|
+
if (!target || target.event.kind !== "user.message")
|
|
4984
|
+
throw new Error("\u0420\u0435\u043F\u043B\u0438\u043A\u0430 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430");
|
|
4985
|
+
if (target.event.text.startsWith("/"))
|
|
4986
|
+
throw new Error("\u0421\u043B\u0443\u0436\u0435\u0431\u043D\u0443\u044E \u043A\u043E\u043C\u0430\u043D\u0434\u0443 \u043D\u0435\u043B\u044C\u0437\u044F \u043E\u0442\u0440\u0435\u0434\u0430\u043A\u0442\u0438\u0440\u043E\u0432\u0430\u0442\u044C; \u043E\u0442\u043F\u0440\u0430\u0432\u044C\u0442\u0435 \u0435\u0451 \u0437\u0430\u043D\u043E\u0432\u043E");
|
|
4987
|
+
const modelIndex = messages.slice(0, userIndex).filter((entry) => entry.event.kind === "user.message" && !entry.event.text.startsWith("/")).length;
|
|
4988
|
+
const nativeMessages = [];
|
|
4989
|
+
let cursor = null;
|
|
4990
|
+
do {
|
|
4991
|
+
const page = await this.#client.request("thread/items/list", { threadId: this.#record.conversationId, cursor, limit: 100, sortDirection: "asc" });
|
|
4992
|
+
nativeMessages.push(...(page.data ?? []).filter((entry) => entry.item.type === "userMessage"));
|
|
4993
|
+
cursor = page.nextCursor ?? null;
|
|
4994
|
+
} while (cursor && nativeMessages.length <= modelIndex);
|
|
4995
|
+
const beforeTurnId = nativeMessages[modelIndex]?.turnId;
|
|
4996
|
+
if (!beforeTurnId)
|
|
4997
|
+
throw new Error("Codex \u043D\u0435 \u043D\u0430\u0448\u0451\u043B \u0445\u043E\u0434 \u0434\u043B\u044F \u044D\u0442\u043E\u0439 \u0440\u0435\u043F\u043B\u0438\u043A\u0438");
|
|
4998
|
+
await this.#client.request("thread/revert", { threadId: this.#record.conversationId, beforeTurnId });
|
|
4999
|
+
await this.#store.replaceEvents(this.id, events.slice(0, events.indexOf(target)));
|
|
5000
|
+
this.#history = Promise.resolve(await this.#store.readEvents(this.id));
|
|
5001
|
+
this.journal.clear();
|
|
5002
|
+
this.#recordEvent({ kind: "rewound", toUserIndex: userIndex });
|
|
5003
|
+
this.#context = null;
|
|
5004
|
+
this.sendPrompt(text, images);
|
|
5005
|
+
}
|
|
5006
|
+
async setUltracode() {
|
|
5007
|
+
throw new Error("\u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 \u0443\u0441\u0438\u043B\u0438\u0435 \u0432 \u043C\u0435\u043D\u044E \u043C\u043E\u0434\u0435\u043B\u0438 Codex");
|
|
5008
|
+
}
|
|
5009
|
+
async setThinking() {
|
|
5010
|
+
throw new Error("\u0412\u044B\u0431\u0435\u0440\u0438\u0442\u0435 \u0443\u0441\u0438\u043B\u0438\u0435 \u0432 \u043C\u0435\u043D\u044E \u043C\u043E\u0434\u0435\u043B\u0438 Codex");
|
|
5011
|
+
}
|
|
5012
|
+
async setSwitchModelsOnFlag() {
|
|
5013
|
+
throw new Error("\u041D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0430 \u043E\u0442\u043D\u043E\u0441\u0438\u0442\u0441\u044F \u043A Claude Code");
|
|
5014
|
+
}
|
|
5015
|
+
async reloadPlugins() {
|
|
5016
|
+
await this.#client?.request("config/mcpServer/reload", {});
|
|
5017
|
+
}
|
|
5018
|
+
async mcpServerStatus() {
|
|
5019
|
+
return [];
|
|
5020
|
+
}
|
|
5021
|
+
async addMcpServer() {
|
|
5022
|
+
throw new Error("\u041D\u0430\u0441\u0442\u0440\u043E\u0439\u0442\u0435 MCP \u0432 ~/.codex/config.toml \u0438\u043B\u0438 \u0447\u0435\u0440\u0435\u0437 codex mcp \u0432 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0435");
|
|
5023
|
+
}
|
|
5024
|
+
async removeMcpServer() {
|
|
5025
|
+
throw new Error("\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 codex mcp remove \u0432 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0435");
|
|
5026
|
+
}
|
|
5027
|
+
async reconnectMcpServer() {
|
|
5028
|
+
await this.reloadPlugins();
|
|
5029
|
+
}
|
|
5030
|
+
async toggleMcpServer() {
|
|
5031
|
+
throw new Error("\u041D\u0430\u0441\u0442\u0440\u043E\u0439\u0442\u0435 MCP \u0432 ~/.codex/config.toml");
|
|
5032
|
+
}
|
|
5033
|
+
async authenticateMcpServer() {
|
|
5034
|
+
throw new Error("\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 codex mcp login \u0432 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0435");
|
|
5035
|
+
}
|
|
5036
|
+
async submitMcpOAuthCallback() {
|
|
5037
|
+
throw new Error("\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 codex mcp login \u0432 \u0442\u0435\u0440\u043C\u0438\u043D\u0430\u043B\u0435");
|
|
5038
|
+
}
|
|
5039
|
+
};
|
|
5040
|
+
|
|
5041
|
+
// ../host/dist/codex-store.js
|
|
5042
|
+
import path10 from "node:path";
|
|
5043
|
+
|
|
4220
5044
|
// ../host/dist/antigravity-store.js
|
|
4221
5045
|
import { appendFile, mkdir as mkdir3, readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "node:fs/promises";
|
|
4222
|
-
import
|
|
5046
|
+
import path9 from "node:path";
|
|
4223
5047
|
var AntigravityStore = class {
|
|
4224
5048
|
#dir;
|
|
4225
5049
|
#file;
|
|
4226
5050
|
#records = /* @__PURE__ */ new Map();
|
|
4227
5051
|
#loaded = null;
|
|
4228
5052
|
#writing = Promise.resolve();
|
|
4229
|
-
constructor(dataDir) {
|
|
4230
|
-
this.#dir =
|
|
4231
|
-
this.#file =
|
|
5053
|
+
constructor(dataDir, provider = "antigravity") {
|
|
5054
|
+
this.#dir = path9.join(dataDir, provider);
|
|
5055
|
+
this.#file = path9.join(this.#dir, "sessions.json");
|
|
4232
5056
|
}
|
|
4233
5057
|
#load() {
|
|
4234
5058
|
this.#loaded ??= (async () => {
|
|
@@ -4303,6 +5127,14 @@ var AntigravityStore = class {
|
|
|
4303
5127
|
await appendFile(this.#eventsFile(id), lines, "utf8");
|
|
4304
5128
|
});
|
|
4305
5129
|
}
|
|
5130
|
+
/** Replace the durable prefix after a successful native conversation rewind. */
|
|
5131
|
+
replaceEvents(id, events) {
|
|
5132
|
+
const lines = events.map((entry) => JSON.stringify(entry)).join("\n");
|
|
5133
|
+
return this.#enqueue(async () => {
|
|
5134
|
+
await mkdir3(this.#dir, { recursive: true });
|
|
5135
|
+
await writeFile3(this.#eventsFile(id), lines ? lines + "\n" : "", "utf8");
|
|
5136
|
+
});
|
|
5137
|
+
}
|
|
4306
5138
|
/** Лента сессии как история: `seq` — позиция, от 1 по порядку. */
|
|
4307
5139
|
async readEvents(id) {
|
|
4308
5140
|
await this.#writing;
|
|
@@ -4325,7 +5157,7 @@ var AntigravityStore = class {
|
|
|
4325
5157
|
return entries;
|
|
4326
5158
|
}
|
|
4327
5159
|
#eventsFile(id) {
|
|
4328
|
-
return
|
|
5160
|
+
return path9.join(this.#dir, `${id.replace(/[^\w-]/g, "_")}.jsonl`);
|
|
4329
5161
|
}
|
|
4330
5162
|
#persist() {
|
|
4331
5163
|
const snapshot = JSON.stringify([...this.#records.values()], null, 2);
|
|
@@ -4344,11 +5176,63 @@ var AntigravityStore = class {
|
|
|
4344
5176
|
}
|
|
4345
5177
|
};
|
|
4346
5178
|
|
|
5179
|
+
// ../host/dist/codex-store.js
|
|
5180
|
+
var CodexStore = class extends AntigravityStore {
|
|
5181
|
+
#scans = /* @__PURE__ */ new Map();
|
|
5182
|
+
constructor(dataDir) {
|
|
5183
|
+
super(dataDir, "codex");
|
|
5184
|
+
}
|
|
5185
|
+
discover(workspaceId, cwd) {
|
|
5186
|
+
const cached = this.#scans.get(workspaceId);
|
|
5187
|
+
if (cached && Date.now() - cached.at < 3e4)
|
|
5188
|
+
return cached.pending;
|
|
5189
|
+
const pending = this.#discover(workspaceId, cwd).catch((error) => {
|
|
5190
|
+
console.error("[codex-discovery]", error instanceof Error ? error.message : error);
|
|
5191
|
+
});
|
|
5192
|
+
this.#scans.set(workspaceId, { at: Date.now(), pending });
|
|
5193
|
+
return pending;
|
|
5194
|
+
}
|
|
5195
|
+
async #discover(workspaceId, cwd) {
|
|
5196
|
+
if (!codexLauncher())
|
|
5197
|
+
return;
|
|
5198
|
+
const client = new CodexClient();
|
|
5199
|
+
try {
|
|
5200
|
+
await client.start(cwd);
|
|
5201
|
+
const records = await this.list(workspaceId);
|
|
5202
|
+
const known = new Set(records.map((r) => r.conversationId));
|
|
5203
|
+
let cursor = null;
|
|
5204
|
+
do {
|
|
5205
|
+
const page = await client.request("thread/list", { cwd, cursor, limit: 100, sortKey: "updated_at", modelProviders: [] });
|
|
5206
|
+
for (const thread of page.data ?? []) {
|
|
5207
|
+
if (known.has(thread.id) || path10.resolve(thread.cwd) !== path10.resolve(cwd) || thread.parentThreadId)
|
|
5208
|
+
continue;
|
|
5209
|
+
await this.save({
|
|
5210
|
+
id: `codex-${thread.id}`,
|
|
5211
|
+
conversationId: thread.id,
|
|
5212
|
+
workspaceId,
|
|
5213
|
+
cwd,
|
|
5214
|
+
title: thread.name || thread.preview?.slice(0, 100) || null,
|
|
5215
|
+
model: thread.model ?? null,
|
|
5216
|
+
effort: ["low", "medium", "high", "xhigh", "max"].includes(thread.reasoningEffort) ? thread.reasoningEffort : null,
|
|
5217
|
+
permissionMode: "default",
|
|
5218
|
+
createdAt: thread.createdAt * 1e3,
|
|
5219
|
+
updatedAt: thread.updatedAt * 1e3
|
|
5220
|
+
});
|
|
5221
|
+
known.add(thread.id);
|
|
5222
|
+
}
|
|
5223
|
+
cursor = page.nextCursor ?? null;
|
|
5224
|
+
} while (cursor);
|
|
5225
|
+
} finally {
|
|
5226
|
+
await client.close();
|
|
5227
|
+
}
|
|
5228
|
+
}
|
|
5229
|
+
};
|
|
5230
|
+
|
|
4347
5231
|
// ../host/dist/git.js
|
|
4348
|
-
import { execFile as
|
|
5232
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
4349
5233
|
import { mkdtemp, readFile as readFile5, rm as rm3, writeFile as writeFile4 } from "node:fs/promises";
|
|
4350
5234
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
4351
|
-
import
|
|
5235
|
+
import path11 from "node:path";
|
|
4352
5236
|
var TIMEOUT_MS = 2e4;
|
|
4353
5237
|
var NET_TIMEOUT_MS = 5 * 6e4;
|
|
4354
5238
|
var MAX_BUFFER = 32 * 1024 * 1024;
|
|
@@ -4664,7 +5548,7 @@ var GitRepo = class {
|
|
|
4664
5548
|
* важнее всего (см. `checkIgnored`).
|
|
4665
5549
|
*/
|
|
4666
5550
|
async #withoutRepo(args) {
|
|
4667
|
-
const dir = await mkdtemp(
|
|
5551
|
+
const dir = await mkdtemp(path11.join(tmpdir2(), "ccv-git-"));
|
|
4668
5552
|
try {
|
|
4669
5553
|
await this.#run(["init", "--bare", "--quiet", dir]);
|
|
4670
5554
|
return await this.#soft([`--git-dir=${dir}`, `--work-tree=${this.cwd}`, ...args]);
|
|
@@ -4710,7 +5594,7 @@ var GitRepo = class {
|
|
|
4710
5594
|
* исключил. Повторы отсеиваются, чтобы файл не рос от каждой публикации.
|
|
4711
5595
|
*/
|
|
4712
5596
|
async #appendGitignore(paths) {
|
|
4713
|
-
const file =
|
|
5597
|
+
const file = path11.join(this.cwd, ".gitignore");
|
|
4714
5598
|
const existing = await readFile5(file, "utf8").catch(() => "");
|
|
4715
5599
|
const known = new Set(existing.split(/\r?\n/).map((line) => line.trim()));
|
|
4716
5600
|
const lines = paths.map(ignorePattern).filter((line) => !known.has(line));
|
|
@@ -4735,7 +5619,7 @@ var GitRepo = class {
|
|
|
4735
5619
|
#run(args, options2 = {}) {
|
|
4736
5620
|
const token = options2.token ?? "";
|
|
4737
5621
|
return new Promise((resolve, reject) => {
|
|
4738
|
-
const child =
|
|
5622
|
+
const child = execFile5(
|
|
4739
5623
|
"git",
|
|
4740
5624
|
// core.quotepath=false — иначе кириллические пути приезжают в виде
|
|
4741
5625
|
// «\320\277\321\200…» и в панели читаются как мусор.
|
|
@@ -4916,9 +5800,9 @@ function parsePatch(raw) {
|
|
|
4916
5800
|
body = "";
|
|
4917
5801
|
}
|
|
4918
5802
|
total += body.length;
|
|
4919
|
-
const
|
|
5803
|
+
const path27 = status === "deleted" ? oldPath : newPath || oldPath;
|
|
4920
5804
|
files.push({
|
|
4921
|
-
path:
|
|
5805
|
+
path: path27,
|
|
4922
5806
|
oldPath: status === "renamed" ? oldPath : "",
|
|
4923
5807
|
status,
|
|
4924
5808
|
added: count(body, "+"),
|
|
@@ -4930,10 +5814,10 @@ function parsePatch(raw) {
|
|
|
4930
5814
|
return { files, truncated };
|
|
4931
5815
|
}
|
|
4932
5816
|
function stripPrefix(value) {
|
|
4933
|
-
const
|
|
4934
|
-
if (
|
|
5817
|
+
const path27 = unquote(value.trim());
|
|
5818
|
+
if (path27 === "/dev/null")
|
|
4935
5819
|
return "";
|
|
4936
|
-
return
|
|
5820
|
+
return path27.replace(/^[ab]\//, "");
|
|
4937
5821
|
}
|
|
4938
5822
|
function count(body, mark) {
|
|
4939
5823
|
let n = 0;
|
|
@@ -4945,9 +5829,9 @@ function count(body, mark) {
|
|
|
4945
5829
|
}
|
|
4946
5830
|
|
|
4947
5831
|
// ../host/dist/github.js
|
|
4948
|
-
import { execFile as
|
|
5832
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
4949
5833
|
import { mkdir as mkdir4, readFile as readFile6, writeFile as writeFile5 } from "node:fs/promises";
|
|
4950
|
-
import
|
|
5834
|
+
import path12 from "node:path";
|
|
4951
5835
|
var API = "https://api.github.com";
|
|
4952
5836
|
var API_VERSION = "2022-11-28";
|
|
4953
5837
|
var API_TIMEOUT_MS = 2e4;
|
|
@@ -4968,7 +5852,7 @@ var GitHubAccount = class {
|
|
|
4968
5852
|
*/
|
|
4969
5853
|
#ghInstalled = null;
|
|
4970
5854
|
constructor(dataDir) {
|
|
4971
|
-
this.#storePath =
|
|
5855
|
+
this.#storePath = path12.join(dataDir, "github.json");
|
|
4972
5856
|
}
|
|
4973
5857
|
async load() {
|
|
4974
5858
|
try {
|
|
@@ -4982,7 +5866,7 @@ var GitHubAccount = class {
|
|
|
4982
5866
|
/** Сохранить токен или стереть его пустой строкой. */
|
|
4983
5867
|
async setToken(token) {
|
|
4984
5868
|
this.#token = token.trim();
|
|
4985
|
-
await mkdir4(
|
|
5869
|
+
await mkdir4(path12.dirname(this.#storePath), { recursive: true });
|
|
4986
5870
|
await writeFile5(this.#storePath, JSON.stringify({ token: this.#token }, null, 2), {
|
|
4987
5871
|
encoding: "utf8",
|
|
4988
5872
|
mode: 384
|
|
@@ -5134,7 +6018,7 @@ var GitHubAccount = class {
|
|
|
5134
6018
|
};
|
|
5135
6019
|
function gh(args) {
|
|
5136
6020
|
return new Promise((resolve, reject) => {
|
|
5137
|
-
|
|
6021
|
+
execFile6("gh", args, { timeout: GH_TIMEOUT_MS, windowsHide: true, encoding: "utf8" }, (error, stdout, stderr) => {
|
|
5138
6022
|
if (error)
|
|
5139
6023
|
return reject(new Error(stderr.trim() || error.message));
|
|
5140
6024
|
resolve(stdout);
|
|
@@ -5175,10 +6059,10 @@ function describe4(error) {
|
|
|
5175
6059
|
}
|
|
5176
6060
|
|
|
5177
6061
|
// ../host/dist/finder.js
|
|
5178
|
-
import { existsSync as
|
|
6062
|
+
import { existsSync as existsSync3, statSync } from "node:fs";
|
|
5179
6063
|
import { readdir as readdir2 } from "node:fs/promises";
|
|
5180
6064
|
import os2 from "node:os";
|
|
5181
|
-
import
|
|
6065
|
+
import path13 from "node:path";
|
|
5182
6066
|
import { listSessions } from "@anthropic-ai/claude-agent-sdk";
|
|
5183
6067
|
var CACHE_TTL = 6e4;
|
|
5184
6068
|
var FIND_LIMIT = 50;
|
|
@@ -5217,7 +6101,7 @@ var ProjectFinder = class {
|
|
|
5217
6101
|
if (needles.length === 0)
|
|
5218
6102
|
return { candidates: [], truncated: false };
|
|
5219
6103
|
const open = new Map(this.registry.list().map((workspace) => [workspace.path.toLowerCase(), workspace]));
|
|
5220
|
-
const byName = this.#dirs.filter((dir) => matches(
|
|
6104
|
+
const byName = this.#dirs.filter((dir) => matches(path13.basename(dir.path), needles));
|
|
5221
6105
|
const matched = byName.length > 0 ? byName : this.#dirs.filter((dir) => matches(dir.path, needles));
|
|
5222
6106
|
const sorted = [...matched].sort((a, b) => {
|
|
5223
6107
|
const aOpen = open.has(a.path.toLowerCase());
|
|
@@ -5228,7 +6112,7 @@ var ProjectFinder = class {
|
|
|
5228
6112
|
return a.sessions > 0 ? -1 : 1;
|
|
5229
6113
|
if (a.lastUsedAt !== b.lastUsedAt)
|
|
5230
6114
|
return b.lastUsedAt - a.lastUsedAt;
|
|
5231
|
-
return
|
|
6115
|
+
return path13.basename(a.path).localeCompare(path13.basename(b.path), void 0, {
|
|
5232
6116
|
numeric: true,
|
|
5233
6117
|
sensitivity: "base"
|
|
5234
6118
|
});
|
|
@@ -5236,7 +6120,7 @@ var ProjectFinder = class {
|
|
|
5236
6120
|
return {
|
|
5237
6121
|
candidates: sorted.slice(0, FIND_LIMIT).map((dir) => ({
|
|
5238
6122
|
path: dir.path,
|
|
5239
|
-
name:
|
|
6123
|
+
name: path13.basename(dir.path) || dir.path,
|
|
5240
6124
|
sessions: dir.sessions,
|
|
5241
6125
|
lastUsedAt: dir.lastUsedAt || null,
|
|
5242
6126
|
open: open.has(dir.path.toLowerCase()),
|
|
@@ -5260,7 +6144,7 @@ var ProjectFinder = class {
|
|
|
5260
6144
|
const candidates = [];
|
|
5261
6145
|
for (const entry of named) {
|
|
5262
6146
|
const absolute = entry.path.trim();
|
|
5263
|
-
if (!absolute || !
|
|
6147
|
+
if (!absolute || !path13.isAbsolute(absolute))
|
|
5264
6148
|
continue;
|
|
5265
6149
|
const key = absolute.toLowerCase();
|
|
5266
6150
|
if (seen.has(key))
|
|
@@ -5271,7 +6155,7 @@ var ProjectFinder = class {
|
|
|
5271
6155
|
const record = known.get(key);
|
|
5272
6156
|
candidates.push({
|
|
5273
6157
|
path: record?.path ?? absolute,
|
|
5274
|
-
name:
|
|
6158
|
+
name: path13.basename(absolute) || absolute,
|
|
5275
6159
|
sessions: record?.sessions ?? 0,
|
|
5276
6160
|
lastUsedAt: record?.lastUsedAt || null,
|
|
5277
6161
|
open: open.has(key),
|
|
@@ -5328,7 +6212,7 @@ var ProjectFinder = class {
|
|
|
5328
6212
|
if (!dirent.isDirectory() || SKIP_NAMES.has(dirent.name) || dirent.name.startsWith(".")) {
|
|
5329
6213
|
continue;
|
|
5330
6214
|
}
|
|
5331
|
-
const full =
|
|
6215
|
+
const full = path13.join(parent, dirent.name);
|
|
5332
6216
|
const key = full.toLowerCase();
|
|
5333
6217
|
if (dirs.has(key))
|
|
5334
6218
|
continue;
|
|
@@ -5349,7 +6233,7 @@ var ProjectFinder = class {
|
|
|
5349
6233
|
#parents(dirs) {
|
|
5350
6234
|
const counted = /* @__PURE__ */ new Map();
|
|
5351
6235
|
for (const dir of dirs) {
|
|
5352
|
-
const parent =
|
|
6236
|
+
const parent = path13.dirname(dir.path);
|
|
5353
6237
|
if (parent === dir.path || !usable(parent))
|
|
5354
6238
|
continue;
|
|
5355
6239
|
const key = parent.toLowerCase();
|
|
@@ -5363,7 +6247,7 @@ var ProjectFinder = class {
|
|
|
5363
6247
|
}
|
|
5364
6248
|
};
|
|
5365
6249
|
function usable(dir) {
|
|
5366
|
-
return !contains(os2.tmpdir(), dir) &&
|
|
6250
|
+
return !contains(os2.tmpdir(), dir) && existsSync3(dir);
|
|
5367
6251
|
}
|
|
5368
6252
|
function tokens(query2) {
|
|
5369
6253
|
return query2.toLowerCase().split(/[^a-z0-9а-яё]+/i).filter(Boolean);
|
|
@@ -5460,15 +6344,15 @@ function fromText(text) {
|
|
|
5460
6344
|
}
|
|
5461
6345
|
|
|
5462
6346
|
// ../host/dist/workspaces.js
|
|
5463
|
-
import { existsSync as
|
|
6347
|
+
import { existsSync as existsSync4, statSync as statSync2 } from "node:fs";
|
|
5464
6348
|
import { mkdir as mkdir5, readFile as readFile7, writeFile as writeFile6 } from "node:fs/promises";
|
|
5465
|
-
import
|
|
6349
|
+
import path14 from "node:path";
|
|
5466
6350
|
import { listSessions as listSessions2 } from "@anthropic-ai/claude-agent-sdk";
|
|
5467
6351
|
var WorkspaceRegistry = class {
|
|
5468
6352
|
#entries = [];
|
|
5469
6353
|
#storePath;
|
|
5470
6354
|
constructor(dataDir) {
|
|
5471
|
-
this.#storePath =
|
|
6355
|
+
this.#storePath = path14.join(dataDir, "workspaces.json");
|
|
5472
6356
|
}
|
|
5473
6357
|
async load() {
|
|
5474
6358
|
try {
|
|
@@ -5484,13 +6368,13 @@ var WorkspaceRegistry = class {
|
|
|
5484
6368
|
if (isEntry(item))
|
|
5485
6369
|
return item;
|
|
5486
6370
|
return null;
|
|
5487
|
-
}).filter((e) => e !== null &&
|
|
6371
|
+
}).filter((e) => e !== null && existsSync4(e.path));
|
|
5488
6372
|
} catch {
|
|
5489
6373
|
this.#entries = [];
|
|
5490
6374
|
}
|
|
5491
6375
|
}
|
|
5492
6376
|
async #persist() {
|
|
5493
|
-
await mkdir5(
|
|
6377
|
+
await mkdir5(path14.dirname(this.#storePath), { recursive: true });
|
|
5494
6378
|
await writeFile6(this.#storePath, JSON.stringify(this.#entries, null, 2), "utf8");
|
|
5495
6379
|
}
|
|
5496
6380
|
/** Активные проекты. */
|
|
@@ -5510,8 +6394,8 @@ var WorkspaceRegistry = class {
|
|
|
5510
6394
|
return entry ? toInfo(entry) : void 0;
|
|
5511
6395
|
}
|
|
5512
6396
|
async open(rawPath) {
|
|
5513
|
-
const absolute =
|
|
5514
|
-
if (!
|
|
6397
|
+
const absolute = path14.resolve(rawPath);
|
|
6398
|
+
if (!existsSync4(absolute)) {
|
|
5515
6399
|
throw new Error(`\u041A\u0430\u0442\u0430\u043B\u043E\u0433 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${absolute}`);
|
|
5516
6400
|
}
|
|
5517
6401
|
const existing = this.#entries.find((e) => e.path === absolute);
|
|
@@ -5577,24 +6461,32 @@ var WorkspaceRegistry = class {
|
|
|
5577
6461
|
async create(parentRaw, nameRaw, init) {
|
|
5578
6462
|
const name = nameRaw.trim();
|
|
5579
6463
|
requireName(name);
|
|
5580
|
-
const parent =
|
|
5581
|
-
if (!
|
|
6464
|
+
const parent = path14.resolve(parentRaw.trim());
|
|
6465
|
+
if (!existsSync4(parent)) {
|
|
5582
6466
|
throw new Error(`\u041A\u0430\u0442\u0430\u043B\u043E\u0433 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${parent}`);
|
|
5583
6467
|
}
|
|
5584
6468
|
if (!statSync2(parent).isDirectory()) {
|
|
5585
6469
|
throw new Error(`\u042D\u0442\u043E \u043D\u0435 \u043A\u0430\u0442\u0430\u043B\u043E\u0433: ${parent}`);
|
|
5586
6470
|
}
|
|
5587
|
-
const target =
|
|
5588
|
-
if (
|
|
6471
|
+
const target = path14.join(parent, name);
|
|
6472
|
+
if (existsSync4(target)) {
|
|
5589
6473
|
throw new Error(`\u0423\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442: ${target} \u2014 \u043E\u0442\u043A\u0440\u043E\u0439\u0442\u0435 \u0435\u0433\u043E \u043A\u0430\u043A \u043F\u0440\u043E\u0435\u043A\u0442`);
|
|
5590
6474
|
}
|
|
5591
6475
|
await mkdir5(target);
|
|
5592
6476
|
const warnings = [];
|
|
6477
|
+
if (init.agentsMd) {
|
|
6478
|
+
await step(warnings, "AGENTS.md", () => writeFile6(path14.join(target, "AGENTS.md"), `# ${name}
|
|
6479
|
+
|
|
6480
|
+
## \u0418\u043D\u0441\u0442\u0440\u0443\u043A\u0446\u0438\u0438 \u043F\u0440\u043E\u0435\u043A\u0442\u0430
|
|
6481
|
+
|
|
6482
|
+
\u041E\u043F\u0438\u0448\u0438\u0442\u0435 \u0437\u0434\u0435\u0441\u044C \u0443\u0441\u0442\u0440\u043E\u0439\u0441\u0442\u0432\u043E \u043F\u0440\u043E\u0435\u043A\u0442\u0430, \u043A\u043E\u043C\u0430\u043D\u0434\u044B \u0441\u0431\u043E\u0440\u043A\u0438 \u0438 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438, \u043F\u0440\u0430\u0432\u0438\u043B\u0430 \u0440\u0430\u0431\u043E\u0442\u044B.
|
|
6483
|
+
`, "utf8"));
|
|
6484
|
+
}
|
|
5593
6485
|
if (init.claudeMd) {
|
|
5594
|
-
await step(warnings, "CLAUDE.md", () => writeFile6(
|
|
6486
|
+
await step(warnings, "CLAUDE.md", () => writeFile6(path14.join(target, "CLAUDE.md"), claudeMdStub(name), "utf8"));
|
|
5595
6487
|
}
|
|
5596
6488
|
if (init.readme) {
|
|
5597
|
-
await step(warnings, "README.md", () => writeFile6(
|
|
6489
|
+
await step(warnings, "README.md", () => writeFile6(path14.join(target, "README.md"), readmeStub(name), "utf8"));
|
|
5598
6490
|
}
|
|
5599
6491
|
if (init.git) {
|
|
5600
6492
|
await step(warnings, "git init", () => new GitRepo(target).init());
|
|
@@ -5666,8 +6558,8 @@ function toInfo(entry) {
|
|
|
5666
6558
|
return {
|
|
5667
6559
|
id: workspaceIdFromPath(absolute),
|
|
5668
6560
|
path: absolute,
|
|
5669
|
-
name:
|
|
5670
|
-
hasClaudeMd:
|
|
6561
|
+
name: path14.basename(absolute) || absolute,
|
|
6562
|
+
hasClaudeMd: existsSync4(path14.join(absolute, "CLAUDE.md")),
|
|
5671
6563
|
...archivedAt ? { archivedAt } : {}
|
|
5672
6564
|
};
|
|
5673
6565
|
}
|
|
@@ -5677,13 +6569,13 @@ function isEntry(value) {
|
|
|
5677
6569
|
|
|
5678
6570
|
// ../host/dist/archive.js
|
|
5679
6571
|
import { mkdir as mkdir6, readFile as readFile8, writeFile as writeFile7 } from "node:fs/promises";
|
|
5680
|
-
import
|
|
6572
|
+
import path15 from "node:path";
|
|
5681
6573
|
var SessionArchive = class {
|
|
5682
6574
|
#archived = /* @__PURE__ */ new Map();
|
|
5683
6575
|
#restored = /* @__PURE__ */ new Map();
|
|
5684
6576
|
#storePath;
|
|
5685
6577
|
constructor(dataDir) {
|
|
5686
|
-
this.#storePath =
|
|
6578
|
+
this.#storePath = path15.join(dataDir, "session-archive.json");
|
|
5687
6579
|
}
|
|
5688
6580
|
async load() {
|
|
5689
6581
|
try {
|
|
@@ -5795,7 +6687,7 @@ var SessionArchive = class {
|
|
|
5795
6687
|
archived: Object.fromEntries(this.#archived),
|
|
5796
6688
|
restored: Object.fromEntries(this.#restored)
|
|
5797
6689
|
};
|
|
5798
|
-
await mkdir6(
|
|
6690
|
+
await mkdir6(path15.dirname(this.#storePath), { recursive: true });
|
|
5799
6691
|
await writeFile7(this.#storePath, JSON.stringify(file, null, 2), "utf8");
|
|
5800
6692
|
}
|
|
5801
6693
|
};
|
|
@@ -5805,7 +6697,7 @@ function isRecord(value) {
|
|
|
5805
6697
|
|
|
5806
6698
|
// ../host/dist/pins.js
|
|
5807
6699
|
import { mkdir as mkdir7, readFile as readFile9, writeFile as writeFile8 } from "node:fs/promises";
|
|
5808
|
-
import
|
|
6700
|
+
import path16 from "node:path";
|
|
5809
6701
|
var SessionPins = class {
|
|
5810
6702
|
#pinned = /* @__PURE__ */ new Map();
|
|
5811
6703
|
/**
|
|
@@ -5820,7 +6712,7 @@ var SessionPins = class {
|
|
|
5820
6712
|
#moved = /* @__PURE__ */ new Map();
|
|
5821
6713
|
#storePath;
|
|
5822
6714
|
constructor(dataDir) {
|
|
5823
|
-
this.#storePath =
|
|
6715
|
+
this.#storePath = path16.join(dataDir, "session-pins.json");
|
|
5824
6716
|
}
|
|
5825
6717
|
async load() {
|
|
5826
6718
|
try {
|
|
@@ -5977,7 +6869,7 @@ var SessionPins = class {
|
|
|
5977
6869
|
pinned: Object.fromEntries(this.#pinned),
|
|
5978
6870
|
...this.#moved.size > 0 ? { moved: Object.fromEntries(this.#moved) } : {}
|
|
5979
6871
|
};
|
|
5980
|
-
await mkdir7(
|
|
6872
|
+
await mkdir7(path16.dirname(this.#storePath), { recursive: true });
|
|
5981
6873
|
await writeFile8(this.#storePath, JSON.stringify(file, null, 2), "utf8");
|
|
5982
6874
|
}
|
|
5983
6875
|
};
|
|
@@ -5987,12 +6879,12 @@ function isRecord2(value) {
|
|
|
5987
6879
|
|
|
5988
6880
|
// ../host/dist/order.js
|
|
5989
6881
|
import { mkdir as mkdir8, readFile as readFile10, writeFile as writeFile9 } from "node:fs/promises";
|
|
5990
|
-
import
|
|
6882
|
+
import path17 from "node:path";
|
|
5991
6883
|
var ListOrderStore = class {
|
|
5992
6884
|
#order = emptyOrder();
|
|
5993
6885
|
#storePath;
|
|
5994
6886
|
constructor(dataDir) {
|
|
5995
|
-
this.#storePath =
|
|
6887
|
+
this.#storePath = path17.join(dataDir, "list-order.json");
|
|
5996
6888
|
}
|
|
5997
6889
|
async load() {
|
|
5998
6890
|
try {
|
|
@@ -6068,7 +6960,7 @@ var ListOrderStore = class {
|
|
|
6068
6960
|
return changed;
|
|
6069
6961
|
}
|
|
6070
6962
|
async #persist() {
|
|
6071
|
-
await mkdir8(
|
|
6963
|
+
await mkdir8(path17.dirname(this.#storePath), { recursive: true });
|
|
6072
6964
|
await writeFile9(this.#storePath, JSON.stringify(this.#order, null, 2), "utf8");
|
|
6073
6965
|
}
|
|
6074
6966
|
};
|
|
@@ -6099,8 +6991,8 @@ function sanitize(value) {
|
|
|
6099
6991
|
|
|
6100
6992
|
// ../host/dist/folders.js
|
|
6101
6993
|
import { mkdir as mkdir9, readFile as readFile11, writeFile as writeFile10 } from "node:fs/promises";
|
|
6102
|
-
import
|
|
6103
|
-
import { randomUUID as
|
|
6994
|
+
import path18 from "node:path";
|
|
6995
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
6104
6996
|
var COLOR_PATTERN = /^#[0-9a-f]{6}$/i;
|
|
6105
6997
|
var Folders = class {
|
|
6106
6998
|
#workspaceFolders = /* @__PURE__ */ new Map();
|
|
@@ -6111,7 +7003,7 @@ var Folders = class {
|
|
|
6111
7003
|
#pinnedAssignments = /* @__PURE__ */ new Map();
|
|
6112
7004
|
#storePath;
|
|
6113
7005
|
constructor(dataDir) {
|
|
6114
|
-
this.#storePath =
|
|
7006
|
+
this.#storePath = path18.join(dataDir, "folders.json");
|
|
6115
7007
|
}
|
|
6116
7008
|
async load() {
|
|
6117
7009
|
try {
|
|
@@ -6200,19 +7092,19 @@ var Folders = class {
|
|
|
6200
7092
|
};
|
|
6201
7093
|
}
|
|
6202
7094
|
async createWorkspaceFolder(name) {
|
|
6203
|
-
const id =
|
|
7095
|
+
const id = randomUUID4();
|
|
6204
7096
|
this.#workspaceFolders.set(id, { name });
|
|
6205
7097
|
await this.#persist();
|
|
6206
7098
|
return id;
|
|
6207
7099
|
}
|
|
6208
7100
|
async createSessionFolder(workspaceId, name) {
|
|
6209
|
-
const id =
|
|
7101
|
+
const id = randomUUID4();
|
|
6210
7102
|
this.#sessionFolders.set(id, { name, workspaceId });
|
|
6211
7103
|
await this.#persist();
|
|
6212
7104
|
return id;
|
|
6213
7105
|
}
|
|
6214
7106
|
async createPinnedFolder(name) {
|
|
6215
|
-
const id =
|
|
7107
|
+
const id = randomUUID4();
|
|
6216
7108
|
this.#pinnedFolders.set(id, { name });
|
|
6217
7109
|
await this.#persist();
|
|
6218
7110
|
return id;
|
|
@@ -6392,7 +7284,7 @@ var Folders = class {
|
|
|
6392
7284
|
sessionAssignments: Object.fromEntries(this.#sessionAssignments),
|
|
6393
7285
|
pinnedAssignments: Object.fromEntries(this.#pinnedAssignments)
|
|
6394
7286
|
};
|
|
6395
|
-
await mkdir9(
|
|
7287
|
+
await mkdir9(path18.dirname(this.#storePath), { recursive: true });
|
|
6396
7288
|
await writeFile10(this.#storePath, JSON.stringify(file, null, 2), "utf8");
|
|
6397
7289
|
}
|
|
6398
7290
|
};
|
|
@@ -6415,8 +7307,8 @@ function isPinnedFolder(value) {
|
|
|
6415
7307
|
|
|
6416
7308
|
// ../host/dist/app-settings.js
|
|
6417
7309
|
import { mkdir as mkdir10, readFile as readFile12, writeFile as writeFile11 } from "node:fs/promises";
|
|
6418
|
-
import { homedir as
|
|
6419
|
-
import
|
|
7310
|
+
import { homedir as homedir5 } from "node:os";
|
|
7311
|
+
import path19 from "node:path";
|
|
6420
7312
|
var DEFAULT_AUTO_ARCHIVE_AFTER_MS = 2 * 24 * 60 * 60 * 1e3;
|
|
6421
7313
|
var MIN_AUTO_ARCHIVE_AFTER_MS = 60 * 60 * 1e3;
|
|
6422
7314
|
var DEFAULT_AUTO_STOP_AFTER_MS = 10 * 60 * 1e3;
|
|
@@ -6424,7 +7316,7 @@ var MIN_AUTO_STOP_AFTER_MS = 60 * 1e3;
|
|
|
6424
7316
|
var MIN_AUTO_SAVE_AFTER_PAUSE_MS = 500;
|
|
6425
7317
|
var DEFAULT_BLOCKED_COUNTRIES = ["RU", "BY", "CN", "IR", "KP", "SY", "CU"];
|
|
6426
7318
|
var FOLDER_ACCESS = ["all", "projects", "project"];
|
|
6427
|
-
var PROVIDERS = ["claude", "antigravity"];
|
|
7319
|
+
var PROVIDERS = ["claude", "antigravity", "codex"];
|
|
6428
7320
|
var PERMISSION_MODES = [
|
|
6429
7321
|
"default",
|
|
6430
7322
|
"acceptEdits",
|
|
@@ -6458,8 +7350,7 @@ var DEFAULT_APP_SETTINGS = {
|
|
|
6458
7350
|
// несколько дней, и терять их из-за пары процентов жалко.
|
|
6459
7351
|
limitStopFiveHourPct: 95,
|
|
6460
7352
|
limitStopSevenDayPct: 99,
|
|
6461
|
-
|
|
6462
|
-
enabledProviders: ["claude", "antigravity"],
|
|
7353
|
+
enabledProviders: ["claude", "antigravity", "codex"],
|
|
6463
7354
|
// Включено: запрос без VPN может стоить аккаунта, а тому, у кого маршрут и
|
|
6464
7355
|
// так из разрешённой страны, защита ничем не мешает.
|
|
6465
7356
|
networkGuardEnabled: true,
|
|
@@ -6469,7 +7360,7 @@ var AppSettingsStore = class {
|
|
|
6469
7360
|
#settings = { ...DEFAULT_APP_SETTINGS };
|
|
6470
7361
|
#storePath;
|
|
6471
7362
|
constructor(dataDir) {
|
|
6472
|
-
this.#storePath =
|
|
7363
|
+
this.#storePath = path19.join(dataDir, "app-settings.json");
|
|
6473
7364
|
}
|
|
6474
7365
|
async load() {
|
|
6475
7366
|
try {
|
|
@@ -6493,7 +7384,7 @@ var AppSettingsStore = class {
|
|
|
6493
7384
|
async update(patch) {
|
|
6494
7385
|
const next = sanitize2(patch, this.#settings);
|
|
6495
7386
|
this.#settings = next;
|
|
6496
|
-
await mkdir10(
|
|
7387
|
+
await mkdir10(path19.dirname(this.#storePath), { recursive: true });
|
|
6497
7388
|
await writeFile11(this.#storePath, JSON.stringify(next, null, 2), "utf8");
|
|
6498
7389
|
return this.current;
|
|
6499
7390
|
}
|
|
@@ -6560,7 +7451,7 @@ function sanitize2(value, fallback) {
|
|
|
6560
7451
|
return result;
|
|
6561
7452
|
}
|
|
6562
7453
|
function claudeHome() {
|
|
6563
|
-
return
|
|
7454
|
+
return path19.join(homedir5(), ".claude");
|
|
6564
7455
|
}
|
|
6565
7456
|
function writableRoots(mode, cwd, workspacePaths) {
|
|
6566
7457
|
if (mode === "all")
|
|
@@ -6570,7 +7461,7 @@ function writableRoots(mode, cwd, workspacePaths) {
|
|
|
6570
7461
|
return [...roots];
|
|
6571
7462
|
for (const workspace of [cwd, ...workspacePaths]) {
|
|
6572
7463
|
roots.add(workspace);
|
|
6573
|
-
const parent =
|
|
7464
|
+
const parent = path19.dirname(workspace);
|
|
6574
7465
|
if (parent !== workspace)
|
|
6575
7466
|
roots.add(parent);
|
|
6576
7467
|
}
|
|
@@ -6579,11 +7470,11 @@ function writableRoots(mode, cwd, workspacePaths) {
|
|
|
6579
7470
|
|
|
6580
7471
|
// ../host/dist/handoff-store.js
|
|
6581
7472
|
import { mkdir as mkdir11, readFile as readFile13, readdir as readdir3, rm as rm4, writeFile as writeFile12 } from "node:fs/promises";
|
|
6582
|
-
import
|
|
7473
|
+
import path20 from "node:path";
|
|
6583
7474
|
var HandoffStore = class {
|
|
6584
7475
|
#dir;
|
|
6585
7476
|
constructor(dataDir) {
|
|
6586
|
-
this.#dir =
|
|
7477
|
+
this.#dir = path20.join(dataDir, "handoffs");
|
|
6587
7478
|
}
|
|
6588
7479
|
async get(sessionId) {
|
|
6589
7480
|
const file = this.#file(sessionId);
|
|
@@ -6620,7 +7511,7 @@ var HandoffStore = class {
|
|
|
6620
7511
|
#file(sessionId) {
|
|
6621
7512
|
if (!/^[\w-]{1,128}$/.test(sessionId))
|
|
6622
7513
|
return null;
|
|
6623
|
-
return
|
|
7514
|
+
return path20.join(this.#dir, `${sessionId}.json`);
|
|
6624
7515
|
}
|
|
6625
7516
|
};
|
|
6626
7517
|
var SAME_WINDOW_MS = 5 * 6e4;
|
|
@@ -6628,7 +7519,7 @@ var LimitStopState = class {
|
|
|
6628
7519
|
#fired = {};
|
|
6629
7520
|
#storePath;
|
|
6630
7521
|
constructor(dataDir) {
|
|
6631
|
-
this.#storePath =
|
|
7522
|
+
this.#storePath = path20.join(dataDir, "limit-stop.json");
|
|
6632
7523
|
}
|
|
6633
7524
|
async load() {
|
|
6634
7525
|
try {
|
|
@@ -6664,7 +7555,7 @@ var LimitStopState = class {
|
|
|
6664
7555
|
/** Запомнить срабатывание до `until` (момент сброса окна). */
|
|
6665
7556
|
async mark(limit, until) {
|
|
6666
7557
|
this.#fired[limit] = until;
|
|
6667
|
-
await mkdir11(
|
|
7558
|
+
await mkdir11(path20.dirname(this.#storePath), { recursive: true });
|
|
6668
7559
|
await writeFile12(this.#storePath, JSON.stringify(this.#fired, null, 2), "utf8");
|
|
6669
7560
|
}
|
|
6670
7561
|
};
|
|
@@ -6770,8 +7661,8 @@ function capitalize(text) {
|
|
|
6770
7661
|
|
|
6771
7662
|
// ../host/dist/plugins.js
|
|
6772
7663
|
import { readFile as readFile14 } from "node:fs/promises";
|
|
6773
|
-
import { homedir as
|
|
6774
|
-
import
|
|
7664
|
+
import { homedir as homedir6 } from "node:os";
|
|
7665
|
+
import path21 from "node:path";
|
|
6775
7666
|
var TIMEOUT_MS2 = 12e4;
|
|
6776
7667
|
var SAFE_ARG = /^[A-Za-z0-9][A-Za-z0-9._@/-]*$/;
|
|
6777
7668
|
var PluginCli = class {
|
|
@@ -6870,10 +7761,10 @@ async function readCatalog(markets, installed) {
|
|
|
6870
7761
|
return lists.flat().sort((a, b) => a.name.localeCompare(b.name));
|
|
6871
7762
|
}
|
|
6872
7763
|
async function readMarketplace(market, installed) {
|
|
6873
|
-
const root = market.installLocation ||
|
|
7764
|
+
const root = market.installLocation || path21.join(homedir6(), ".claude", "plugins", "marketplaces", market.name);
|
|
6874
7765
|
let manifest;
|
|
6875
7766
|
try {
|
|
6876
|
-
const text = await readFile14(
|
|
7767
|
+
const text = await readFile14(path21.join(root, ".claude-plugin", "marketplace.json"), "utf8");
|
|
6877
7768
|
manifest = JSON.parse(text);
|
|
6878
7769
|
} catch {
|
|
6879
7770
|
return [];
|
|
@@ -6916,7 +7807,7 @@ function authorName(raw) {
|
|
|
6916
7807
|
}
|
|
6917
7808
|
|
|
6918
7809
|
// ../host/dist/auth.js
|
|
6919
|
-
import { EventEmitter as
|
|
7810
|
+
import { EventEmitter as EventEmitter6 } from "node:events";
|
|
6920
7811
|
var QUICK_TIMEOUT_MS = 3e4;
|
|
6921
7812
|
var LOGIN_TIMEOUT_MS = 10 * 6e4;
|
|
6922
7813
|
var URL_RE = /https:\/\/\S*\/oauth\/authorize\S*/;
|
|
@@ -6928,7 +7819,7 @@ var IDLE = {
|
|
|
6928
7819
|
output: "",
|
|
6929
7820
|
error: null
|
|
6930
7821
|
};
|
|
6931
|
-
var AuthCli = class extends
|
|
7822
|
+
var AuthCli = class extends EventEmitter6 {
|
|
6932
7823
|
#child = null;
|
|
6933
7824
|
#state = IDLE;
|
|
6934
7825
|
#timer = null;
|
|
@@ -7113,9 +8004,9 @@ function describe5(error) {
|
|
|
7113
8004
|
}
|
|
7114
8005
|
|
|
7115
8006
|
// ../host/dist/relay-link.js
|
|
7116
|
-
import { EventEmitter as
|
|
8007
|
+
import { EventEmitter as EventEmitter7 } from "node:events";
|
|
7117
8008
|
import { readFile as readFile15, writeFile as writeFile13, rm as rm5, mkdir as mkdir12 } from "node:fs/promises";
|
|
7118
|
-
import
|
|
8009
|
+
import path22 from "node:path";
|
|
7119
8010
|
import { hostname } from "node:os";
|
|
7120
8011
|
import WebSocket from "ws";
|
|
7121
8012
|
|
|
@@ -7132,7 +8023,7 @@ var SILENCE_TIMEOUT_MS = 95e3;
|
|
|
7132
8023
|
function jitter(delay2) {
|
|
7133
8024
|
return Math.round(delay2 * (0.8 + Math.random() * 0.4));
|
|
7134
8025
|
}
|
|
7135
|
-
var RelayLink = class extends
|
|
8026
|
+
var RelayLink = class extends EventEmitter7 {
|
|
7136
8027
|
#credentials = null;
|
|
7137
8028
|
#socket = null;
|
|
7138
8029
|
#retry = RETRY_MIN_MS;
|
|
@@ -7170,7 +8061,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7170
8061
|
#log;
|
|
7171
8062
|
constructor(options2) {
|
|
7172
8063
|
super();
|
|
7173
|
-
this.#file =
|
|
8064
|
+
this.#file = path22.join(options2.dataDir, "relay.json");
|
|
7174
8065
|
this.#defaultUrl = options2.defaultUrl.replace(/\/+$/, "");
|
|
7175
8066
|
this.#log = options2.log ?? ((msg) => console.log(`[relay] ${msg}`));
|
|
7176
8067
|
}
|
|
@@ -7264,7 +8155,7 @@ var RelayLink = class extends EventEmitter5 {
|
|
|
7264
8155
|
}
|
|
7265
8156
|
}
|
|
7266
8157
|
async #write(credentials) {
|
|
7267
|
-
await mkdir12(
|
|
8158
|
+
await mkdir12(path22.dirname(this.#file), { recursive: true });
|
|
7268
8159
|
await writeFile13(this.#file, `${JSON.stringify(credentials, null, 2)}
|
|
7269
8160
|
`, {
|
|
7270
8161
|
encoding: "utf8",
|
|
@@ -7520,14 +8411,14 @@ function humanize(error) {
|
|
|
7520
8411
|
}
|
|
7521
8412
|
|
|
7522
8413
|
// ../host/dist/terminal.js
|
|
7523
|
-
import { EventEmitter as
|
|
8414
|
+
import { EventEmitter as EventEmitter8 } from "node:events";
|
|
7524
8415
|
import { access as access2, constants as constants2 } from "node:fs/promises";
|
|
7525
|
-
import
|
|
7526
|
-
import { randomUUID as
|
|
8416
|
+
import path23 from "node:path";
|
|
8417
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
7527
8418
|
var SCROLLBACK_BYTES = 256 * 1024;
|
|
7528
8419
|
var FLUSH_MS = 12;
|
|
7529
8420
|
var MAX_TERMINALS = 24;
|
|
7530
|
-
var TerminalHub = class extends
|
|
8421
|
+
var TerminalHub = class extends EventEmitter8 {
|
|
7531
8422
|
#terminals = /* @__PURE__ */ new Map();
|
|
7532
8423
|
#module = null;
|
|
7533
8424
|
list(workspaceId) {
|
|
@@ -7560,7 +8451,7 @@ var TerminalHub = class extends EventEmitter6 {
|
|
|
7560
8451
|
env: environment()
|
|
7561
8452
|
});
|
|
7562
8453
|
const info = {
|
|
7563
|
-
id:
|
|
8454
|
+
id: randomUUID5(),
|
|
7564
8455
|
workspaceId: options2.workspaceId,
|
|
7565
8456
|
title: shell.title,
|
|
7566
8457
|
shell: shell.file,
|
|
@@ -7692,22 +8583,22 @@ async function defaultShell() {
|
|
|
7692
8583
|
if (pwsh)
|
|
7693
8584
|
return { file: pwsh, args: [], title: "pwsh" };
|
|
7694
8585
|
const system = process.env.SystemRoot ?? "C:\\Windows";
|
|
7695
|
-
const powershell =
|
|
8586
|
+
const powershell = path23.join(system, "System32/WindowsPowerShell/v1.0/powershell.exe");
|
|
7696
8587
|
if (await exists2(powershell))
|
|
7697
8588
|
return { file: powershell, args: [], title: "powershell" };
|
|
7698
8589
|
return { file: process.env.COMSPEC ?? "cmd.exe", args: [], title: "cmd" };
|
|
7699
8590
|
}
|
|
7700
8591
|
const shell = process.env.SHELL;
|
|
7701
8592
|
if (shell && await exists2(shell))
|
|
7702
|
-
return { file: shell, args: [], title:
|
|
8593
|
+
return { file: shell, args: [], title: path23.basename(shell) };
|
|
7703
8594
|
if (await exists2("/bin/bash"))
|
|
7704
8595
|
return { file: "/bin/bash", args: [], title: "bash" };
|
|
7705
8596
|
return { file: "/bin/sh", args: [], title: "sh" };
|
|
7706
8597
|
}
|
|
7707
8598
|
async function findOnPath(name) {
|
|
7708
|
-
const dirs = (process.env.PATH ?? "").split(
|
|
8599
|
+
const dirs = (process.env.PATH ?? "").split(path23.delimiter).filter(Boolean);
|
|
7709
8600
|
for (const dir of dirs) {
|
|
7710
|
-
const candidate =
|
|
8601
|
+
const candidate = path23.join(dir, name);
|
|
7711
8602
|
if (await exists2(candidate))
|
|
7712
8603
|
return candidate;
|
|
7713
8604
|
}
|
|
@@ -7719,9 +8610,9 @@ function exists2(file) {
|
|
|
7719
8610
|
|
|
7720
8611
|
// ../host/dist/mcp-config.js
|
|
7721
8612
|
import { readFile as readFile16, writeFile as writeFile14, mkdir as mkdir13 } from "node:fs/promises";
|
|
7722
|
-
import
|
|
8613
|
+
import path24 from "node:path";
|
|
7723
8614
|
var MCP_FILE = ".mcp.json";
|
|
7724
|
-
var LOCAL_SETTINGS2 =
|
|
8615
|
+
var LOCAL_SETTINGS2 = path24.join(".claude", "settings.local.json");
|
|
7725
8616
|
var queues = /* @__PURE__ */ new Map();
|
|
7726
8617
|
function serialize(cwd, work) {
|
|
7727
8618
|
const previous = queues.get(cwd) ?? Promise.resolve();
|
|
@@ -7730,7 +8621,7 @@ function serialize(cwd, work) {
|
|
|
7730
8621
|
return next;
|
|
7731
8622
|
}
|
|
7732
8623
|
async function readProjectServers(cwd) {
|
|
7733
|
-
const file = await readJson(
|
|
8624
|
+
const file = await readJson(path24.join(cwd, MCP_FILE));
|
|
7734
8625
|
const servers = file?.mcpServers;
|
|
7735
8626
|
if (!servers || typeof servers !== "object")
|
|
7736
8627
|
return {};
|
|
@@ -7738,23 +8629,23 @@ async function readProjectServers(cwd) {
|
|
|
7738
8629
|
}
|
|
7739
8630
|
function addProjectServer(cwd, name, config) {
|
|
7740
8631
|
return serialize(cwd, async () => {
|
|
7741
|
-
const file = await readJson(
|
|
8632
|
+
const file = await readJson(path24.join(cwd, MCP_FILE)) ?? {};
|
|
7742
8633
|
const servers = file.mcpServers ?? {};
|
|
7743
8634
|
servers[name] = config;
|
|
7744
8635
|
file.mcpServers = servers;
|
|
7745
|
-
await writeJson(
|
|
8636
|
+
await writeJson(path24.join(cwd, MCP_FILE), file);
|
|
7746
8637
|
await approve(cwd, name);
|
|
7747
8638
|
});
|
|
7748
8639
|
}
|
|
7749
8640
|
function removeProjectServer(cwd, name) {
|
|
7750
8641
|
return serialize(cwd, async () => {
|
|
7751
|
-
const file = await readJson(
|
|
8642
|
+
const file = await readJson(path24.join(cwd, MCP_FILE));
|
|
7752
8643
|
const servers = file?.mcpServers;
|
|
7753
8644
|
if (!servers || !(name in servers))
|
|
7754
8645
|
return false;
|
|
7755
8646
|
delete servers[name];
|
|
7756
|
-
await writeJson(
|
|
7757
|
-
const settingsPath =
|
|
8647
|
+
await writeJson(path24.join(cwd, MCP_FILE), file);
|
|
8648
|
+
const settingsPath = path24.join(cwd, LOCAL_SETTINGS2);
|
|
7758
8649
|
const settings = await readJson(settingsPath);
|
|
7759
8650
|
const enabled = settings?.enabledMcpjsonServers;
|
|
7760
8651
|
if (settings && Array.isArray(enabled) && enabled.includes(name)) {
|
|
@@ -7765,7 +8656,7 @@ function removeProjectServer(cwd, name) {
|
|
|
7765
8656
|
});
|
|
7766
8657
|
}
|
|
7767
8658
|
async function approve(cwd, name) {
|
|
7768
|
-
const file =
|
|
8659
|
+
const file = path24.join(cwd, LOCAL_SETTINGS2);
|
|
7769
8660
|
const settings = await readJson(file) ?? {};
|
|
7770
8661
|
const enabled = Array.isArray(settings.enabledMcpjsonServers) ? settings.enabledMcpjsonServers : [];
|
|
7771
8662
|
if (!enabled.includes(name))
|
|
@@ -7811,13 +8702,13 @@ async function readJson(file) {
|
|
|
7811
8702
|
if (error.code === "ENOENT")
|
|
7812
8703
|
return null;
|
|
7813
8704
|
if (error instanceof SyntaxError) {
|
|
7814
|
-
throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u0442\u044C ${
|
|
8705
|
+
throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u0442\u044C ${path24.basename(file)}: ${error.message}`);
|
|
7815
8706
|
}
|
|
7816
8707
|
throw error;
|
|
7817
8708
|
}
|
|
7818
8709
|
}
|
|
7819
8710
|
async function writeJson(file, data) {
|
|
7820
|
-
await mkdir13(
|
|
8711
|
+
await mkdir13(path24.dirname(file), { recursive: true });
|
|
7821
8712
|
await writeFile14(file, `${JSON.stringify(data, null, 2)}
|
|
7822
8713
|
`, "utf8");
|
|
7823
8714
|
}
|
|
@@ -7848,6 +8739,7 @@ var HostServer = class {
|
|
|
7848
8739
|
/** Опросы статуса для идущих OAuth-входов MCP, ключ — сессия и сервер. */
|
|
7849
8740
|
#mcpAuthWatch = /* @__PURE__ */ new Map();
|
|
7850
8741
|
#antigravity;
|
|
8742
|
+
#codex;
|
|
7851
8743
|
/** Боковые сессии («вопрос на полях») по id родителя — не больше одной на разговор. */
|
|
7852
8744
|
#sides = /* @__PURE__ */ new Map();
|
|
7853
8745
|
/**
|
|
@@ -7895,7 +8787,7 @@ var HostServer = class {
|
|
|
7895
8787
|
#limitHandoffBusy = /* @__PURE__ */ new Set();
|
|
7896
8788
|
/** Живые id сессий, у которых сейчас пишется ручной хэндофф. */
|
|
7897
8789
|
#handoffBusy = /* @__PURE__ */ new Set();
|
|
7898
|
-
#hostId =
|
|
8790
|
+
#hostId = randomUUID6();
|
|
7899
8791
|
#plugins = new PluginCli();
|
|
7900
8792
|
#auth = new AuthCli();
|
|
7901
8793
|
#relay;
|
|
@@ -7919,6 +8811,7 @@ var HostServer = class {
|
|
|
7919
8811
|
this.#folders = new Folders(options2.dataDir);
|
|
7920
8812
|
this.#settings = new AppSettingsStore(options2.dataDir);
|
|
7921
8813
|
this.#antigravity = new AntigravityStore(options2.dataDir);
|
|
8814
|
+
this.#codex = new CodexStore(options2.dataDir);
|
|
7922
8815
|
this.#handoffs = new HandoffStore(options2.dataDir);
|
|
7923
8816
|
this.#limitStop = new LimitStopState(options2.dataDir);
|
|
7924
8817
|
this.#finder = new ProjectFinder(this.#workspaces);
|
|
@@ -7945,9 +8838,11 @@ var HostServer = class {
|
|
|
7945
8838
|
const id = workspaceIdFromPath(dir);
|
|
7946
8839
|
const onDisk = await this.#workspaces.sessionsOnDisk(id);
|
|
7947
8840
|
const antigravity = await this.#antigravity.list(id);
|
|
7948
|
-
|
|
8841
|
+
const codex = await this.#codex.list(id);
|
|
8842
|
+
return [...onDisk.map((s) => s.sessionId), ...antigravity.map((r) => r.id), ...codex.map((r) => r.id)];
|
|
7949
8843
|
});
|
|
7950
8844
|
await this.#antigravity.remapWorkspaceIds(remap);
|
|
8845
|
+
await this.#codex.remapWorkspaceIds(remap);
|
|
7951
8846
|
await this.#archive.remapWorkspaceIds(remap);
|
|
7952
8847
|
await this.#pins.remapWorkspaceIds(remap);
|
|
7953
8848
|
await this.#order.remapWorkspaceIds(remap);
|
|
@@ -9419,7 +10314,40 @@ var HostServer = class {
|
|
|
9419
10314
|
throw new Error(`\u0412\u043E\u0440\u043A\u0441\u043F\u0435\u0439\u0441 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${frame.workspaceId}`);
|
|
9420
10315
|
const provider = frame.provider ?? "claude";
|
|
9421
10316
|
if (!frame.resume && !this.#settings.current.enabledProviders.includes(provider)) {
|
|
9422
|
-
throw new Error(`${provider === "antigravity" ? "Antigravity" : "Claude"} \u0432\u044B\u043A\u043B\u044E\u0447\u0435\u043D \u0432 \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0430\u0445`);
|
|
10317
|
+
throw new Error(`${provider === "codex" ? "Codex" : provider === "antigravity" ? "Antigravity" : "Claude"} \u0432\u044B\u043A\u043B\u044E\u0447\u0435\u043D \u0432 \u043D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0430\u0445`);
|
|
10318
|
+
}
|
|
10319
|
+
const codexRecord = frame.resume ? await this.#codex.find(frame.resume) : null;
|
|
10320
|
+
if (codexRecord || provider === "codex") {
|
|
10321
|
+
if (frame.resume && !codexRecord)
|
|
10322
|
+
throw new Error("\u0421\u0435\u0441\u0441\u0438\u044F Codex \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430");
|
|
10323
|
+
if (codexRecord && codexRecord.workspaceId !== workspace.id)
|
|
10324
|
+
throw new Error("\u0421\u0435\u0441\u0441\u0438\u044F \u043F\u0440\u0438\u043D\u0430\u0434\u043B\u0435\u0436\u0438\u0442 \u0434\u0440\u0443\u0433\u043E\u043C\u0443 \u043F\u0440\u043E\u0435\u043A\u0442\u0443");
|
|
10325
|
+
const existing = codexRecord && !frame.fork ? this.#sessions.get(codexRecord.id) : null;
|
|
10326
|
+
if (existing && existing.state !== "closed" && existing.state !== "error") {
|
|
10327
|
+
this.#send(socket, { type: "session.summary", session: existing.summary() });
|
|
10328
|
+
return;
|
|
10329
|
+
}
|
|
10330
|
+
if (existing)
|
|
10331
|
+
await existing.close();
|
|
10332
|
+
if (codexRecord)
|
|
10333
|
+
await this.#archive.unarchive([codexRecord.id]);
|
|
10334
|
+
const session2 = new CodexSession({
|
|
10335
|
+
workspaceId: workspace.id,
|
|
10336
|
+
cwd: workspace.path,
|
|
10337
|
+
store: this.#codex,
|
|
10338
|
+
...codexRecord ? { record: codexRecord } : {},
|
|
10339
|
+
fork: frame.fork,
|
|
10340
|
+
permissionMode: frame.permissionMode ?? codexRecord?.permissionMode ?? "default",
|
|
10341
|
+
...frame.model ? { model: frame.model } : {},
|
|
10342
|
+
defaultTitle: workspace.name,
|
|
10343
|
+
writableRoots: () => this.#writableRoots(workspace.path)
|
|
10344
|
+
});
|
|
10345
|
+
this.#wire(session2);
|
|
10346
|
+
this.#sessions.set(session2.id, session2);
|
|
10347
|
+
session2.start();
|
|
10348
|
+
this.#sendLive();
|
|
10349
|
+
this.#send(socket, { type: "session.summary", session: session2.summary() });
|
|
10350
|
+
return;
|
|
9423
10351
|
}
|
|
9424
10352
|
const agyRecord = frame.resume ? await this.#antigravity.find(frame.resume) : null;
|
|
9425
10353
|
if (agyRecord || !frame.resume && frame.provider === "antigravity") {
|
|
@@ -9583,7 +10511,7 @@ var HostServer = class {
|
|
|
9583
10511
|
this.#broadcast({ type: "context.state", sessionId: session.id, context });
|
|
9584
10512
|
});
|
|
9585
10513
|
session.on("stderr", (data) => {
|
|
9586
|
-
const tag = session instanceof AntigravitySession ? "agy" : "claude";
|
|
10514
|
+
const tag = session instanceof CodexSession ? "codex" : session instanceof AntigravitySession ? "agy" : "claude";
|
|
9587
10515
|
process.stderr.write(`[${tag} ${session.id.slice(0, 8)}] ${data}`);
|
|
9588
10516
|
});
|
|
9589
10517
|
}
|
|
@@ -9603,7 +10531,7 @@ var HostServer = class {
|
|
|
9603
10531
|
* разговора пока и не было.
|
|
9604
10532
|
*/
|
|
9605
10533
|
#ensureSide(parent) {
|
|
9606
|
-
if (parent instanceof
|
|
10534
|
+
if (!(parent instanceof ClaudeSession)) {
|
|
9607
10535
|
throw new Error("\u0412\u043E\u043F\u0440\u043E\u0441 \u043D\u0430 \u043F\u043E\u043B\u044F\u0445 \u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D \u0442\u043E\u043B\u044C\u043A\u043E \u0432 \u0441\u0435\u0441\u0441\u0438\u044F\u0445 Claude");
|
|
9608
10536
|
}
|
|
9609
10537
|
const existing = this.#sides.get(parent.id);
|
|
@@ -9661,7 +10589,7 @@ var HostServer = class {
|
|
|
9661
10589
|
*/
|
|
9662
10590
|
#roots() {
|
|
9663
10591
|
const roots = this.#finder.roots();
|
|
9664
|
-
return roots.length > 0 ? roots : [
|
|
10592
|
+
return roots.length > 0 ? roots : [homedir7()];
|
|
9665
10593
|
}
|
|
9666
10594
|
/**
|
|
9667
10595
|
* Где сессии этого каталога разрешено писать без вопроса.
|
|
@@ -9903,7 +10831,7 @@ var HostServer = class {
|
|
|
9903
10831
|
live.setTitle(title);
|
|
9904
10832
|
return;
|
|
9905
10833
|
}
|
|
9906
|
-
if (await this.#antigravity.rename(sessionId, title)) {
|
|
10834
|
+
if (await this.#codex.rename(sessionId, title) || await this.#antigravity.rename(sessionId, title)) {
|
|
9907
10835
|
if (workspaceId)
|
|
9908
10836
|
await this.#sendSessionList(workspaceId);
|
|
9909
10837
|
return;
|
|
@@ -9960,6 +10888,12 @@ var HostServer = class {
|
|
|
9960
10888
|
continue;
|
|
9961
10889
|
historical.push(antigravitySummary(record));
|
|
9962
10890
|
}
|
|
10891
|
+
if (workspacePath && this.#settings.current.enabledProviders.includes("codex"))
|
|
10892
|
+
await this.#codex.discover(workspaceId, workspacePath);
|
|
10893
|
+
for (const record of await this.#codex.list(workspaceId)) {
|
|
10894
|
+
if (!liveIds.has(record.id))
|
|
10895
|
+
historical.push({ ...antigravitySummary(record), provider: "codex" });
|
|
10896
|
+
}
|
|
9963
10897
|
const known = /* @__PURE__ */ new Set([...liveIds, ...historical.map((s) => s.id)]);
|
|
9964
10898
|
await this.#archive.sweep(workspaceId, historical.filter((s) => !this.#pins.has(s.id)).map((s) => ({ id: s.id, updatedAt: s.updatedAt })), known, this.#settings.current.autoArchiveAfterMs);
|
|
9965
10899
|
await this.#pins.sweep(workspaceId, known);
|
|
@@ -10006,15 +10940,15 @@ var HostServer = class {
|
|
|
10006
10940
|
}
|
|
10007
10941
|
#serveStatic(req, res) {
|
|
10008
10942
|
const webRoot = this.#options.webRoot;
|
|
10009
|
-
if (!webRoot || !
|
|
10943
|
+
if (!webRoot || !existsSync5(webRoot)) {
|
|
10010
10944
|
res.writeHead(200, { "content-type": "text/plain; charset=utf-8" });
|
|
10011
10945
|
res.end("CCV host is running. UI is served by the Vite dev server.\n");
|
|
10012
10946
|
return;
|
|
10013
10947
|
}
|
|
10014
10948
|
const url2 = new URL(req.url ?? "/", "http://localhost");
|
|
10015
|
-
const requested =
|
|
10016
|
-
const target = requested.startsWith(webRoot) &&
|
|
10017
|
-
if (!
|
|
10949
|
+
const requested = path25.join(webRoot, path25.normalize(url2.pathname));
|
|
10950
|
+
const target = requested.startsWith(webRoot) && existsSync5(requested) && statSync3(requested).isFile() ? requested : path25.join(webRoot, "index.html");
|
|
10951
|
+
if (!existsSync5(target)) {
|
|
10018
10952
|
res.writeHead(404).end("not found");
|
|
10019
10953
|
return;
|
|
10020
10954
|
}
|
|
@@ -10039,7 +10973,7 @@ function contentType(file) {
|
|
|
10039
10973
|
".svg": "image/svg+xml",
|
|
10040
10974
|
".woff2": "font/woff2"
|
|
10041
10975
|
};
|
|
10042
|
-
return types[
|
|
10976
|
+
return types[path25.extname(file)] ?? "application/octet-stream";
|
|
10043
10977
|
}
|
|
10044
10978
|
function antigravitySummary(record) {
|
|
10045
10979
|
return {
|
|
@@ -10068,8 +11002,8 @@ function antigravitySummary(record) {
|
|
|
10068
11002
|
}
|
|
10069
11003
|
|
|
10070
11004
|
// dist/ccv.js
|
|
10071
|
-
var HERE =
|
|
10072
|
-
var PACKAGE_ROOT =
|
|
11005
|
+
var HERE = path26.dirname(fileURLToPath(import.meta.url));
|
|
11006
|
+
var PACKAGE_ROOT = path26.resolve(HERE, "..");
|
|
10073
11007
|
var USAGE = `ccv \u2014 Claude Code Visual: \u043B\u043E\u043A\u0430\u043B\u044C\u043D\u044B\u0439 \u0445\u043E\u0441\u0442 Claude Code \u0441 \u0438\u043D\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043E\u043C \u0432 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0435.
|
|
10074
11008
|
|
|
10075
11009
|
\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u0438\u0435:
|
|
@@ -10080,17 +11014,19 @@ var USAGE = `ccv \u2014 Claude Code Visual: \u043B\u043E\u043A\u0430\u043B\u044C
|
|
|
10080
11014
|
--host <\u0430\u0434\u0440\u0435\u0441> \u0430\u0434\u0440\u0435\u0441 \u043F\u0440\u043E\u0441\u043B\u0443\u0448\u0438\u0432\u0430\u043D\u0438\u044F (\u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E 127.0.0.1)
|
|
10081
11015
|
--no-open \u043D\u0435 \u043E\u0442\u043A\u0440\u044B\u0432\u0430\u0442\u044C \u0431\u0440\u0430\u0443\u0437\u0435\u0440
|
|
10082
11016
|
--claude \u0447\u0435\u043C \u0431\u0443\u0434\u0443\u0442 \u043F\u043E\u0434\u043D\u0438\u043C\u0430\u0442\u044C\u0441\u044F \u0441\u0435\u0441\u0441\u0438\u0438, \u0438 \u0432\u044B\u0439\u0442\u0438
|
|
11017
|
+
--codex \u043F\u0443\u0442\u044C \u043A Codex CLI, \u0438 \u0432\u044B\u0439\u0442\u0438
|
|
10083
11018
|
-v, --version \u0432\u0435\u0440\u0441\u0438\u044F
|
|
10084
11019
|
-h, --help \u044D\u0442\u0430 \u0441\u043F\u0440\u0430\u0432\u043A\u0430
|
|
10085
11020
|
|
|
10086
11021
|
\u041E\u043A\u0440\u0443\u0436\u0435\u043D\u0438\u0435: CCV_PORT, CCV_HOST, CCV_DATA_DIR, CCV_WEB_ROOT, CCV_RELAY_URL,
|
|
10087
|
-
CCV_CLAUDE_PATH, CCV_BUNDLED_CLAUDE.
|
|
11022
|
+
CCV_CLAUDE_PATH, CCV_BUNDLED_CLAUDE, CCV_CODEX_PATH.
|
|
10088
11023
|
\u0424\u043B\u0430\u0433 \u0432\u0430\u0436\u043D\u0435\u0435 \u043F\u0435\u0440\u0435\u043C\u0435\u043D\u043D\u043E\u0439 \u043E\u043A\u0440\u0443\u0436\u0435\u043D\u0438\u044F, \u043F\u0435\u0440\u0435\u043C\u0435\u043D\u043D\u0430\u044F \u0432\u0430\u0436\u043D\u0435\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u044F \u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E.`;
|
|
10089
11024
|
var options = {
|
|
10090
11025
|
port: { type: "string", short: "p" },
|
|
10091
11026
|
host: { type: "string" },
|
|
10092
11027
|
open: { type: "boolean", default: true },
|
|
10093
11028
|
claude: { type: "boolean" },
|
|
11029
|
+
codex: { type: "boolean" },
|
|
10094
11030
|
version: { type: "boolean", short: "v" },
|
|
10095
11031
|
help: { type: "boolean", short: "h" }
|
|
10096
11032
|
};
|
|
@@ -10114,6 +11050,11 @@ if (values.version) {
|
|
|
10114
11050
|
}
|
|
10115
11051
|
if (values.claude)
|
|
10116
11052
|
process.exit(await reportClaude());
|
|
11053
|
+
if (values.codex) {
|
|
11054
|
+
const launcher = codexLauncher();
|
|
11055
|
+
console.log(launcher ? `Codex CLI: ${launcher.file}${launcher.args.length ? " " + launcher.args.join(" ") : ""}` : CODEX_MISSING_HINT);
|
|
11056
|
+
process.exit(launcher ? 0 : 1);
|
|
11057
|
+
}
|
|
10117
11058
|
var defaults = envDefaults();
|
|
10118
11059
|
var port = values.port === void 0 ? defaults.port : Number(values.port);
|
|
10119
11060
|
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
@@ -10136,7 +11077,7 @@ var server = new HostServer({
|
|
|
10136
11077
|
dataDir: defaults.dataDir,
|
|
10137
11078
|
// UI лежит в пакете рядом с бандлом — это и есть разница между установленной
|
|
10138
11079
|
// утилитой и запуском из репозитория, где сборка живёт в `apps/web/dist`.
|
|
10139
|
-
webRoot: process.env.CCV_WEB_ROOT ??
|
|
11080
|
+
webRoot: process.env.CCV_WEB_ROOT ?? path26.join(PACKAGE_ROOT, "web"),
|
|
10140
11081
|
version,
|
|
10141
11082
|
relayUrl: defaults.relayUrl
|
|
10142
11083
|
});
|
|
@@ -10165,7 +11106,7 @@ for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
|
10165
11106
|
}
|
|
10166
11107
|
async function packageVersion() {
|
|
10167
11108
|
try {
|
|
10168
|
-
const text = await readFile17(
|
|
11109
|
+
const text = await readFile17(path26.join(PACKAGE_ROOT, "package.json"), "utf8");
|
|
10169
11110
|
return JSON.parse(text).version ?? "0.0.0";
|
|
10170
11111
|
} catch {
|
|
10171
11112
|
return "0.0.0";
|
|
@@ -10209,7 +11150,7 @@ function openBrowser(target) {
|
|
|
10209
11150
|
return;
|
|
10210
11151
|
}
|
|
10211
11152
|
const command = process.platform === "win32" ? { file: "cmd", args: ["/c", "start", "", target] } : process.platform === "darwin" ? { file: "open", args: [target] } : { file: "xdg-open", args: [target] };
|
|
10212
|
-
const child =
|
|
11153
|
+
const child = spawn4(command.file, command.args, {
|
|
10213
11154
|
stdio: "ignore",
|
|
10214
11155
|
detached: true,
|
|
10215
11156
|
windowsHide: true
|