@i14ks/ccv 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +30 -2
  2. package/bundle/ccv.mjs +1305 -214
  3. package/package.json +4 -2
  4. package/web/apple-touch-icon.png +0 -0
  5. package/web/assets/{codemirror-BtJ9Kw6s.js → codemirror-Jn-nlEEo.js} +1 -1
  6. package/web/assets/{index-B9YW7yGO.js → index-BP4uDvBo.js} +1 -1
  7. package/web/assets/{index-BwiSzzXj.js → index-Bt0SR_BE.js} +1 -1
  8. package/web/assets/{index-Dm_hwn8g.js → index-C6yiLJP6.js} +1 -1
  9. package/web/assets/{index-CNOLHL_4.js → index-CB9Ecmwu.js} +1 -1
  10. package/web/assets/{index-DHwxEPqa.js → index-CaVGDL0G.js} +1 -1
  11. package/web/assets/{index-CWKatwuc.js → index-CckLujnN.js} +1 -1
  12. package/web/assets/{index-DvfkEh9E.js → index-CfBtWXkv.js} +1 -1
  13. package/web/assets/index-Cjq5qPxL.css +1 -0
  14. package/web/assets/{index-Ccp0JT8x.js → index-DIt15fZq.js} +1 -1
  15. package/web/assets/{index-C8QQfurN.js → index-DP1WFH_k.js} +1 -1
  16. package/web/assets/{index-BlUJ9mDA.js → index-DdG4EILc.js} +1 -1
  17. package/web/assets/{index-BAlM5PeU.js → index-DdTtoxsO.js} +1 -1
  18. package/web/assets/{index-DWr0O8ZE.js → index-DkcdGFc4.js} +1 -1
  19. package/web/assets/{index-Dc4p-U2p.js → index-OpaL2d_i.js} +1 -1
  20. package/web/assets/{index-BpAEaXJC.js → index-P-Bcy60v.js} +1 -1
  21. package/web/assets/{index-BDq5JNDx.js → index-SnbL_sGM.js} +1 -1
  22. package/web/assets/{index-McXNmpFb.js → index-aEpkBsNa.js} +1 -1
  23. package/web/assets/{index-Ba1mAYRn.js → index-aFwgvegU.js} +1 -1
  24. package/web/assets/{index-yIku6ofv.js → index-hFxJfMy0.js} +1 -1
  25. package/web/assets/{index-C3Ai8_SG.js → index-n7R3xkAJ.js} +1 -1
  26. package/web/assets/index-rXb9w15o.js +143 -0
  27. package/web/favicon.ico +0 -0
  28. package/web/favicon.png +0 -0
  29. package/web/favicon.svg +4 -2
  30. package/web/index.html +8 -5
  31. package/web/assets/index-C6Y6TadO.css +0 -1
  32. package/web/assets/index-DYqdo2vo.js +0 -134
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 spawn3 } from "node:child_process";
5
- import { readFile as readFile17 } from "node:fs/promises";
6
- import path24 from "node:path";
4
+ import { spawn as spawn4 } from "node:child_process";
5
+ import { readFile as readFile18 } from "node:fs/promises";
6
+ import path27 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: "\u042D\u0444\u0438\u0440", version: "0.28.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 path2 from "node:path";
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 ?? path2.join(os.homedir(), ".claude-code-visual"),
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 existsSync4, statSync as statSync3 } from "node:fs";
149
- import path23 from "node:path";
150
- import { homedir as homedir6 } from "node:os";
151
- import { randomUUID as randomUUID5 } from "node:crypto";
277
+ import { createReadStream, existsSync as existsSync5, statSync as statSync3 } from "node:fs";
278
+ import path26 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 path25 of paths) {
191
- const id = workspaceIdFromPath(path25);
192
- for (const legacy of formerWorkspaceIdsFromPath(path25)) {
319
+ for (const path28 of paths) {
320
+ const id = workspaceIdFromPath(path28);
321
+ for (const legacy of formerWorkspaceIdsFromPath(path28)) {
193
322
  const group = byLegacy.get(legacy) ?? [];
194
323
  if (!group.some((target) => target.id === id))
195
- group.push({ id, path: path25 });
324
+ group.push({ id, path: path28 });
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 EventEmitter2 } from "node:events";
355
+ import { EventEmitter as EventEmitter3 } from "node:events";
227
356
  import { randomUUID } from "node:crypto";
228
- import path5 from "node:path";
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 path3 from "node:path";
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 = path3.join(dir, dirent.name);
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 = path3.join(dir, dirent.name);
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 = path3.join(dir, dirent.name);
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[path3.extname(file).toLowerCase()];
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[path3.extname(file).toLowerCase()];
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(path3.dirname(target), { recursive: true });
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(path3.dirname(target), { recursive: true });
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(path3.dirname(to), { recursive: true });
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 (path3.isAbsolute(clean) || /^[A-Za-z]:/.test(clean)) {
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 = path3.resolve(root, clean);
633
- const probe = await exists(target) ? target : path3.dirname(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(path3.sep) ? root : root + path3.sep;
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 EventEmitter {
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 homedir2 } from "node:os";
960
- import path4 from "node:path";
961
- var USER_SETTINGS = path4.join(homedir2(), ".claude", "settings.json");
962
- var PROJECT_SETTINGS = path4.join(".claude", "settings.json");
963
- var LOCAL_SETTINGS = path4.join(".claude", "settings.local.json");
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 path4.join(process.env.PROGRAMDATA ?? "C:\\ProgramData", "ClaudeCode", "managed-settings.json");
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
- path4.join(cwd, PROJECT_SETTINGS),
979
- path4.join(cwd, LOCAL_SETTINGS),
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 EventEmitter2 {
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 = path5.resolve(this.cwd, target);
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 EventEmitter3 } from "node:events";
3136
- import { spawn as spawn2, execFile as execFile3 } from "node:child_process";
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 path7 from "node:path";
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 execFile2 } from "node:child_process";
3145
- import { existsSync } from "node:fs";
3146
- import { homedir as homedir3 } from "node:os";
3147
- import path6 from "node:path";
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 && existsSync(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(path6.delimiter).filter(Boolean);
3282
+ const dirs = (process.env.PATH ?? "").split(path7.delimiter).filter(Boolean);
3154
3283
  if (process.platform === "win32") {
3155
- const local = process.env.LOCALAPPDATA ?? path6.join(homedir3(), "AppData", "Local");
3156
- dirs.push(path6.join(local, "agy", "bin"));
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(path6.join(homedir3(), ".local", "bin"), "/usr/local/bin", "/opt/homebrew/bin");
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 = path6.join(dir, name);
3163
- if (existsSync(candidate))
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
- execFile2(file, ["models"], { timeout: 3e4, windowsHide: true }, (error, stdout) => {
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
- execFile2(file, ["--output-format", "json", "-p", command], {
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 EventEmitter3 {
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 = spawn2(this.#executable, this.#args(), {
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 = createInterface({ input: child.stdout });
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
- execFile3("taskkill", ["/pid", String(child.pid), "/T", "/F"], { windowsHide: true }, () => {
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 = path7.join(tmpdir(), "ccv-antigravity", this.id);
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 = path7.join(dir, `${randomUUID2()}.${ext}`);
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 path8 from "node:path";
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 = path8.join(dataDir, "antigravity");
4231
- this.#file = path8.join(this.#dir, "sessions.json");
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 path8.join(this.#dir, `${id.replace(/[^\w-]/g, "_")}.jsonl`);
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 execFile4 } from "node:child_process";
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 path9 from "node:path";
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(path9.join(tmpdir2(), "ccv-git-"));
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 = path9.join(this.cwd, ".gitignore");
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 = execFile4(
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 path25 = status === "deleted" ? oldPath : newPath || oldPath;
5803
+ const path28 = status === "deleted" ? oldPath : newPath || oldPath;
4920
5804
  files.push({
4921
- path: path25,
5805
+ path: path28,
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 path25 = unquote(value.trim());
4934
- if (path25 === "/dev/null")
5817
+ const path28 = unquote(value.trim());
5818
+ if (path28 === "/dev/null")
4935
5819
  return "";
4936
- return path25.replace(/^[ab]\//, "");
5820
+ return path28.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 execFile5 } from "node:child_process";
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 path10 from "node:path";
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 = path10.join(dataDir, "github.json");
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(path10.dirname(this.#storePath), { recursive: true });
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
- execFile5("gh", args, { timeout: GH_TIMEOUT_MS, windowsHide: true, encoding: "utf8" }, (error, stdout, stderr) => {
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 existsSync2, statSync } from "node:fs";
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 path11 from "node:path";
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(path11.basename(dir.path), needles));
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 path11.basename(a.path).localeCompare(path11.basename(b.path), void 0, {
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: path11.basename(dir.path) || dir.path,
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 || !path11.isAbsolute(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: path11.basename(absolute) || absolute,
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 = path11.join(parent, dirent.name);
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 = path11.dirname(dir.path);
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) && existsSync2(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 existsSync3, statSync as statSync2 } from "node:fs";
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 path12 from "node:path";
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 = path12.join(dataDir, "workspaces.json");
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 && existsSync3(e.path));
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(path12.dirname(this.#storePath), { recursive: true });
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 = path12.resolve(rawPath);
5514
- if (!existsSync3(absolute)) {
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 = path12.resolve(parentRaw.trim());
5581
- if (!existsSync3(parent)) {
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 = path12.join(parent, name);
5588
- if (existsSync3(target)) {
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(path12.join(target, "CLAUDE.md"), claudeMdStub(name), "utf8"));
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(path12.join(target, "README.md"), readmeStub(name), "utf8"));
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: path12.basename(absolute) || absolute,
5670
- hasClaudeMd: existsSync3(path12.join(absolute, "CLAUDE.md")),
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 path13 from "node:path";
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 = path13.join(dataDir, "session-archive.json");
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(path13.dirname(this.#storePath), { recursive: true });
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 path14 from "node:path";
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 = path14.join(dataDir, "session-pins.json");
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(path14.dirname(this.#storePath), { recursive: true });
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
  };
@@ -5985,18 +6877,107 @@ function isRecord2(value) {
5985
6877
  return typeof value === "object" && value !== null && typeof value.workspaceId === "string" && typeof value.at === "number";
5986
6878
  }
5987
6879
 
6880
+ // ../host/dist/session-links.js
6881
+ import { mkdir as mkdir8, readFile as readFile10, rename, writeFile as writeFile9 } from "node:fs/promises";
6882
+ import path17 from "node:path";
6883
+ var STAGES = /* @__PURE__ */ new Set(["research", "implementation", "review", "other"]);
6884
+ var validId = (id) => typeof id === "string" && id.length > 0 && id.length <= 512;
6885
+ var SessionLinks = class {
6886
+ #links = /* @__PURE__ */ new Map();
6887
+ #queue = Promise.resolve();
6888
+ #file;
6889
+ constructor(dataDir) {
6890
+ this.#file = path17.join(dataDir, "session-links.json");
6891
+ }
6892
+ async load() {
6893
+ try {
6894
+ const parsed = JSON.parse(await readFile10(this.#file, "utf8"));
6895
+ if (!Array.isArray(parsed))
6896
+ return;
6897
+ for (const value of parsed) {
6898
+ if (!value || typeof value !== "object")
6899
+ continue;
6900
+ const r = value;
6901
+ if (!validId(r.sessionId) || !validId(r.workspaceId) || !(r.parentId === null || validId(r.parentId)) || !STAGES.has(r.stage) || !["fork", "continuation", "linked"].includes(r.kind) || !Number.isFinite(r.createdAt))
6902
+ continue;
6903
+ this.#links.set(r.sessionId, { ...r });
6904
+ }
6905
+ } catch (error) {
6906
+ if (error.code !== "ENOENT")
6907
+ throw error;
6908
+ }
6909
+ }
6910
+ get all() {
6911
+ return [...this.#links.values()].map((r) => ({ ...r }));
6912
+ }
6913
+ set(link) {
6914
+ return this.#update(() => {
6915
+ if (!validId(link.sessionId) || !validId(link.workspaceId) || !STAGES.has(link.stage))
6916
+ throw new Error("\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u0430\u044F \u0441\u0432\u044F\u0437\u044C \u0441\u0435\u0441\u0441\u0438\u0439");
6917
+ if (link.parentId !== null && !validId(link.parentId))
6918
+ throw new Error("\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u0430\u044F \u0440\u043E\u0434\u0438\u0442\u0435\u043B\u044C\u0441\u043A\u0430\u044F \u0441\u0435\u0441\u0441\u0438\u044F");
6919
+ const seen = /* @__PURE__ */ new Set([link.sessionId]);
6920
+ let parent = link.parentId;
6921
+ while (parent) {
6922
+ if (seen.has(parent))
6923
+ throw new Error("\u041D\u0435\u043B\u044C\u0437\u044F \u0437\u0430\u043C\u043A\u043D\u0443\u0442\u044C \u0446\u0435\u043F\u043E\u0447\u043A\u0443 \u0441\u0435\u0441\u0441\u0438\u0439 \u0432 \u043A\u0440\u0443\u0433");
6924
+ seen.add(parent);
6925
+ const next = this.#links.get(parent);
6926
+ if (next && next.workspaceId !== link.workspaceId)
6927
+ throw new Error("\u042D\u0442\u0430\u043F\u044B \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043E\u043B\u0436\u043D\u044B \u043F\u0440\u0438\u043D\u0430\u0434\u043B\u0435\u0436\u0430\u0442\u044C \u043E\u0434\u043D\u043E\u043C\u0443 \u043F\u0440\u043E\u0435\u043A\u0442\u0443");
6928
+ parent = next?.parentId ?? null;
6929
+ }
6930
+ this.#links.set(link.sessionId, { ...link, createdAt: this.#links.get(link.sessionId)?.createdAt ?? link.createdAt });
6931
+ });
6932
+ }
6933
+ migrate(from, to) {
6934
+ return this.#update(() => {
6935
+ if (from === to)
6936
+ return;
6937
+ const link = this.#links.get(from);
6938
+ if (link) {
6939
+ this.#links.delete(from);
6940
+ this.#links.set(to, { ...link, sessionId: to, parentId: link.parentId === to ? null : link.parentId });
6941
+ }
6942
+ for (const [id, r] of this.#links) {
6943
+ if (r.parentId === from)
6944
+ this.#links.set(id, { ...r, parentId: id === to ? null : to });
6945
+ }
6946
+ });
6947
+ }
6948
+ #update(change) {
6949
+ const operation = this.#queue.then(async () => {
6950
+ const before = new Map(this.#links);
6951
+ try {
6952
+ change();
6953
+ const next = JSON.stringify(this.all, null, 2);
6954
+ if (next === JSON.stringify([...before.values()], null, 2))
6955
+ return;
6956
+ await mkdir8(path17.dirname(this.#file), { recursive: true });
6957
+ await writeFile9(this.#file + ".tmp", next, "utf8");
6958
+ await rename(this.#file + ".tmp", this.#file);
6959
+ } catch (error) {
6960
+ this.#links = before;
6961
+ throw error;
6962
+ }
6963
+ });
6964
+ this.#queue = operation.catch(() => void 0);
6965
+ return operation;
6966
+ }
6967
+ };
6968
+
5988
6969
  // ../host/dist/order.js
5989
- import { mkdir as mkdir8, readFile as readFile10, writeFile as writeFile9 } from "node:fs/promises";
5990
- import path15 from "node:path";
6970
+ import { mkdir as mkdir9, readFile as readFile11, writeFile as writeFile10 } from "node:fs/promises";
6971
+ import path18 from "node:path";
5991
6972
  var ListOrderStore = class {
5992
6973
  #order = emptyOrder();
5993
6974
  #storePath;
5994
6975
  constructor(dataDir) {
5995
- this.#storePath = path15.join(dataDir, "list-order.json");
6976
+ this.#storePath = path18.join(dataDir, "list-order.json");
5996
6977
  }
5997
6978
  async load() {
5998
6979
  try {
5999
- const raw = await readFile10(this.#storePath, "utf8");
6980
+ const raw = await readFile11(this.#storePath, "utf8");
6000
6981
  this.#order = sanitize(JSON.parse(raw));
6001
6982
  } catch {
6002
6983
  this.#order = emptyOrder();
@@ -6068,8 +7049,8 @@ var ListOrderStore = class {
6068
7049
  return changed;
6069
7050
  }
6070
7051
  async #persist() {
6071
- await mkdir8(path15.dirname(this.#storePath), { recursive: true });
6072
- await writeFile9(this.#storePath, JSON.stringify(this.#order, null, 2), "utf8");
7052
+ await mkdir9(path18.dirname(this.#storePath), { recursive: true });
7053
+ await writeFile10(this.#storePath, JSON.stringify(this.#order, null, 2), "utf8");
6073
7054
  }
6074
7055
  };
6075
7056
  function emptyOrder() {
@@ -6098,9 +7079,9 @@ function sanitize(value) {
6098
7079
  }
6099
7080
 
6100
7081
  // ../host/dist/folders.js
6101
- import { mkdir as mkdir9, readFile as readFile11, writeFile as writeFile10 } from "node:fs/promises";
6102
- import path16 from "node:path";
6103
- import { randomUUID as randomUUID3 } from "node:crypto";
7082
+ import { mkdir as mkdir10, readFile as readFile12, writeFile as writeFile11 } from "node:fs/promises";
7083
+ import path19 from "node:path";
7084
+ import { randomUUID as randomUUID4 } from "node:crypto";
6104
7085
  var COLOR_PATTERN = /^#[0-9a-f]{6}$/i;
6105
7086
  var Folders = class {
6106
7087
  #workspaceFolders = /* @__PURE__ */ new Map();
@@ -6111,11 +7092,11 @@ var Folders = class {
6111
7092
  #pinnedAssignments = /* @__PURE__ */ new Map();
6112
7093
  #storePath;
6113
7094
  constructor(dataDir) {
6114
- this.#storePath = path16.join(dataDir, "folders.json");
7095
+ this.#storePath = path19.join(dataDir, "folders.json");
6115
7096
  }
6116
7097
  async load() {
6117
7098
  try {
6118
- const raw = await readFile11(this.#storePath, "utf8");
7099
+ const raw = await readFile12(this.#storePath, "utf8");
6119
7100
  const parsed = JSON.parse(raw);
6120
7101
  this.#workspaceFolders = new Map(Object.entries(parsed.workspaceFolders ?? {}).filter(([, r]) => isWorkspaceFolder(r)).map(([id, r]) => [id, withValidColor(r)]));
6121
7102
  this.#sessionFolders = new Map(Object.entries(parsed.sessionFolders ?? {}).filter(([, r]) => isSessionFolder(r)).map(([id, r]) => [id, withValidColor(r)]));
@@ -6200,19 +7181,19 @@ var Folders = class {
6200
7181
  };
6201
7182
  }
6202
7183
  async createWorkspaceFolder(name) {
6203
- const id = randomUUID3();
7184
+ const id = randomUUID4();
6204
7185
  this.#workspaceFolders.set(id, { name });
6205
7186
  await this.#persist();
6206
7187
  return id;
6207
7188
  }
6208
7189
  async createSessionFolder(workspaceId, name) {
6209
- const id = randomUUID3();
7190
+ const id = randomUUID4();
6210
7191
  this.#sessionFolders.set(id, { name, workspaceId });
6211
7192
  await this.#persist();
6212
7193
  return id;
6213
7194
  }
6214
7195
  async createPinnedFolder(name) {
6215
- const id = randomUUID3();
7196
+ const id = randomUUID4();
6216
7197
  this.#pinnedFolders.set(id, { name });
6217
7198
  await this.#persist();
6218
7199
  return id;
@@ -6392,8 +7373,8 @@ var Folders = class {
6392
7373
  sessionAssignments: Object.fromEntries(this.#sessionAssignments),
6393
7374
  pinnedAssignments: Object.fromEntries(this.#pinnedAssignments)
6394
7375
  };
6395
- await mkdir9(path16.dirname(this.#storePath), { recursive: true });
6396
- await writeFile10(this.#storePath, JSON.stringify(file, null, 2), "utf8");
7376
+ await mkdir10(path19.dirname(this.#storePath), { recursive: true });
7377
+ await writeFile11(this.#storePath, JSON.stringify(file, null, 2), "utf8");
6397
7378
  }
6398
7379
  };
6399
7380
  function withValidColor(record) {
@@ -6414,9 +7395,9 @@ function isPinnedFolder(value) {
6414
7395
  }
6415
7396
 
6416
7397
  // ../host/dist/app-settings.js
6417
- import { mkdir as mkdir10, readFile as readFile12, writeFile as writeFile11 } from "node:fs/promises";
6418
- import { homedir as homedir4 } from "node:os";
6419
- import path17 from "node:path";
7398
+ import { mkdir as mkdir11, readFile as readFile13, writeFile as writeFile12 } from "node:fs/promises";
7399
+ import { homedir as homedir5 } from "node:os";
7400
+ import path20 from "node:path";
6420
7401
  var DEFAULT_AUTO_ARCHIVE_AFTER_MS = 2 * 24 * 60 * 60 * 1e3;
6421
7402
  var MIN_AUTO_ARCHIVE_AFTER_MS = 60 * 60 * 1e3;
6422
7403
  var DEFAULT_AUTO_STOP_AFTER_MS = 10 * 60 * 1e3;
@@ -6424,7 +7405,7 @@ var MIN_AUTO_STOP_AFTER_MS = 60 * 1e3;
6424
7405
  var MIN_AUTO_SAVE_AFTER_PAUSE_MS = 500;
6425
7406
  var DEFAULT_BLOCKED_COUNTRIES = ["RU", "BY", "CN", "IR", "KP", "SY", "CU"];
6426
7407
  var FOLDER_ACCESS = ["all", "projects", "project"];
6427
- var PROVIDERS = ["claude", "antigravity"];
7408
+ var PROVIDERS = ["claude", "antigravity", "codex"];
6428
7409
  var PERMISSION_MODES = [
6429
7410
  "default",
6430
7411
  "acceptEdits",
@@ -6458,8 +7439,7 @@ var DEFAULT_APP_SETTINGS = {
6458
7439
  // несколько дней, и терять их из-за пары процентов жалко.
6459
7440
  limitStopFiveHourPct: 95,
6460
7441
  limitStopSevenDayPct: 99,
6461
- // Оба: до появления настройки приложение предлагало обоих агентов.
6462
- enabledProviders: ["claude", "antigravity"],
7442
+ enabledProviders: ["claude", "antigravity", "codex"],
6463
7443
  // Включено: запрос без VPN может стоить аккаунта, а тому, у кого маршрут и
6464
7444
  // так из разрешённой страны, защита ничем не мешает.
6465
7445
  networkGuardEnabled: true,
@@ -6469,11 +7449,11 @@ var AppSettingsStore = class {
6469
7449
  #settings = { ...DEFAULT_APP_SETTINGS };
6470
7450
  #storePath;
6471
7451
  constructor(dataDir) {
6472
- this.#storePath = path17.join(dataDir, "app-settings.json");
7452
+ this.#storePath = path20.join(dataDir, "app-settings.json");
6473
7453
  }
6474
7454
  async load() {
6475
7455
  try {
6476
- const raw = await readFile12(this.#storePath, "utf8");
7456
+ const raw = await readFile13(this.#storePath, "utf8");
6477
7457
  this.#settings = sanitize2(JSON.parse(raw), DEFAULT_APP_SETTINGS);
6478
7458
  } catch {
6479
7459
  this.#settings = { ...DEFAULT_APP_SETTINGS };
@@ -6493,8 +7473,8 @@ var AppSettingsStore = class {
6493
7473
  async update(patch) {
6494
7474
  const next = sanitize2(patch, this.#settings);
6495
7475
  this.#settings = next;
6496
- await mkdir10(path17.dirname(this.#storePath), { recursive: true });
6497
- await writeFile11(this.#storePath, JSON.stringify(next, null, 2), "utf8");
7476
+ await mkdir11(path20.dirname(this.#storePath), { recursive: true });
7477
+ await writeFile12(this.#storePath, JSON.stringify(next, null, 2), "utf8");
6498
7478
  return this.current;
6499
7479
  }
6500
7480
  };
@@ -6560,7 +7540,7 @@ function sanitize2(value, fallback) {
6560
7540
  return result;
6561
7541
  }
6562
7542
  function claudeHome() {
6563
- return path17.join(homedir4(), ".claude");
7543
+ return path20.join(homedir5(), ".claude");
6564
7544
  }
6565
7545
  function writableRoots(mode, cwd, workspacePaths) {
6566
7546
  if (mode === "all")
@@ -6570,7 +7550,7 @@ function writableRoots(mode, cwd, workspacePaths) {
6570
7550
  return [...roots];
6571
7551
  for (const workspace of [cwd, ...workspacePaths]) {
6572
7552
  roots.add(workspace);
6573
- const parent = path17.dirname(workspace);
7553
+ const parent = path20.dirname(workspace);
6574
7554
  if (parent !== workspace)
6575
7555
  roots.add(parent);
6576
7556
  }
@@ -6578,19 +7558,19 @@ function writableRoots(mode, cwd, workspacePaths) {
6578
7558
  }
6579
7559
 
6580
7560
  // ../host/dist/handoff-store.js
6581
- import { mkdir as mkdir11, readFile as readFile13, readdir as readdir3, rm as rm4, writeFile as writeFile12 } from "node:fs/promises";
6582
- import path18 from "node:path";
7561
+ import { mkdir as mkdir12, readFile as readFile14, readdir as readdir3, rm as rm4, writeFile as writeFile13 } from "node:fs/promises";
7562
+ import path21 from "node:path";
6583
7563
  var HandoffStore = class {
6584
7564
  #dir;
6585
7565
  constructor(dataDir) {
6586
- this.#dir = path18.join(dataDir, "handoffs");
7566
+ this.#dir = path21.join(dataDir, "handoffs");
6587
7567
  }
6588
7568
  async get(sessionId) {
6589
7569
  const file = this.#file(sessionId);
6590
7570
  if (!file)
6591
7571
  return null;
6592
7572
  try {
6593
- const parsed = JSON.parse(await readFile13(file, "utf8"));
7573
+ const parsed = JSON.parse(await readFile14(file, "utf8"));
6594
7574
  return typeof parsed.text === "string" ? parsed : null;
6595
7575
  } catch {
6596
7576
  return null;
@@ -6600,8 +7580,8 @@ var HandoffStore = class {
6600
7580
  const file = this.#file(handoff.sessionId);
6601
7581
  if (!file)
6602
7582
  return;
6603
- await mkdir11(this.#dir, { recursive: true });
6604
- await writeFile12(file, JSON.stringify(handoff, null, 2), "utf8");
7583
+ await mkdir12(this.#dir, { recursive: true });
7584
+ await writeFile13(file, JSON.stringify(handoff, null, 2), "utf8");
6605
7585
  }
6606
7586
  async remove(sessionId) {
6607
7587
  const file = this.#file(sessionId);
@@ -6620,7 +7600,7 @@ var HandoffStore = class {
6620
7600
  #file(sessionId) {
6621
7601
  if (!/^[\w-]{1,128}$/.test(sessionId))
6622
7602
  return null;
6623
- return path18.join(this.#dir, `${sessionId}.json`);
7603
+ return path21.join(this.#dir, `${sessionId}.json`);
6624
7604
  }
6625
7605
  };
6626
7606
  var SAME_WINDOW_MS = 5 * 6e4;
@@ -6628,11 +7608,11 @@ var LimitStopState = class {
6628
7608
  #fired = {};
6629
7609
  #storePath;
6630
7610
  constructor(dataDir) {
6631
- this.#storePath = path18.join(dataDir, "limit-stop.json");
7611
+ this.#storePath = path21.join(dataDir, "limit-stop.json");
6632
7612
  }
6633
7613
  async load() {
6634
7614
  try {
6635
- const parsed = JSON.parse(await readFile13(this.#storePath, "utf8"));
7615
+ const parsed = JSON.parse(await readFile14(this.#storePath, "utf8"));
6636
7616
  this.#fired = {};
6637
7617
  for (const key of ["fiveHour", "sevenDay"]) {
6638
7618
  const until = parsed[key];
@@ -6664,8 +7644,8 @@ var LimitStopState = class {
6664
7644
  /** Запомнить срабатывание до `until` (момент сброса окна). */
6665
7645
  async mark(limit, until) {
6666
7646
  this.#fired[limit] = until;
6667
- await mkdir11(path18.dirname(this.#storePath), { recursive: true });
6668
- await writeFile12(this.#storePath, JSON.stringify(this.#fired, null, 2), "utf8");
7647
+ await mkdir12(path21.dirname(this.#storePath), { recursive: true });
7648
+ await writeFile13(this.#storePath, JSON.stringify(this.#fired, null, 2), "utf8");
6669
7649
  }
6670
7650
  };
6671
7651
 
@@ -6769,9 +7749,9 @@ function capitalize(text) {
6769
7749
  }
6770
7750
 
6771
7751
  // ../host/dist/plugins.js
6772
- import { readFile as readFile14 } from "node:fs/promises";
6773
- import { homedir as homedir5 } from "node:os";
6774
- import path19 from "node:path";
7752
+ import { readFile as readFile15 } from "node:fs/promises";
7753
+ import { homedir as homedir6 } from "node:os";
7754
+ import path22 from "node:path";
6775
7755
  var TIMEOUT_MS2 = 12e4;
6776
7756
  var SAFE_ARG = /^[A-Za-z0-9][A-Za-z0-9._@/-]*$/;
6777
7757
  var PluginCli = class {
@@ -6870,10 +7850,10 @@ async function readCatalog(markets, installed) {
6870
7850
  return lists.flat().sort((a, b) => a.name.localeCompare(b.name));
6871
7851
  }
6872
7852
  async function readMarketplace(market, installed) {
6873
- const root = market.installLocation || path19.join(homedir5(), ".claude", "plugins", "marketplaces", market.name);
7853
+ const root = market.installLocation || path22.join(homedir6(), ".claude", "plugins", "marketplaces", market.name);
6874
7854
  let manifest;
6875
7855
  try {
6876
- const text = await readFile14(path19.join(root, ".claude-plugin", "marketplace.json"), "utf8");
7856
+ const text = await readFile15(path22.join(root, ".claude-plugin", "marketplace.json"), "utf8");
6877
7857
  manifest = JSON.parse(text);
6878
7858
  } catch {
6879
7859
  return [];
@@ -6916,7 +7896,7 @@ function authorName(raw) {
6916
7896
  }
6917
7897
 
6918
7898
  // ../host/dist/auth.js
6919
- import { EventEmitter as EventEmitter4 } from "node:events";
7899
+ import { EventEmitter as EventEmitter6 } from "node:events";
6920
7900
  var QUICK_TIMEOUT_MS = 3e4;
6921
7901
  var LOGIN_TIMEOUT_MS = 10 * 6e4;
6922
7902
  var URL_RE = /https:\/\/\S*\/oauth\/authorize\S*/;
@@ -6928,7 +7908,7 @@ var IDLE = {
6928
7908
  output: "",
6929
7909
  error: null
6930
7910
  };
6931
- var AuthCli = class extends EventEmitter4 {
7911
+ var AuthCli = class extends EventEmitter6 {
6932
7912
  #child = null;
6933
7913
  #state = IDLE;
6934
7914
  #timer = null;
@@ -7113,9 +8093,9 @@ function describe5(error) {
7113
8093
  }
7114
8094
 
7115
8095
  // ../host/dist/relay-link.js
7116
- import { EventEmitter as EventEmitter5 } from "node:events";
7117
- import { readFile as readFile15, writeFile as writeFile13, rm as rm5, mkdir as mkdir12 } from "node:fs/promises";
7118
- import path20 from "node:path";
8096
+ import { EventEmitter as EventEmitter7 } from "node:events";
8097
+ import { readFile as readFile16, writeFile as writeFile14, rm as rm5, mkdir as mkdir13 } from "node:fs/promises";
8098
+ import path23 from "node:path";
7119
8099
  import { hostname } from "node:os";
7120
8100
  import WebSocket from "ws";
7121
8101
 
@@ -7132,7 +8112,7 @@ var SILENCE_TIMEOUT_MS = 95e3;
7132
8112
  function jitter(delay2) {
7133
8113
  return Math.round(delay2 * (0.8 + Math.random() * 0.4));
7134
8114
  }
7135
- var RelayLink = class extends EventEmitter5 {
8115
+ var RelayLink = class extends EventEmitter7 {
7136
8116
  #credentials = null;
7137
8117
  #socket = null;
7138
8118
  #retry = RETRY_MIN_MS;
@@ -7170,7 +8150,7 @@ var RelayLink = class extends EventEmitter5 {
7170
8150
  #log;
7171
8151
  constructor(options2) {
7172
8152
  super();
7173
- this.#file = path20.join(options2.dataDir, "relay.json");
8153
+ this.#file = path23.join(options2.dataDir, "relay.json");
7174
8154
  this.#defaultUrl = options2.defaultUrl.replace(/\/+$/, "");
7175
8155
  this.#log = options2.log ?? ((msg) => console.log(`[relay] ${msg}`));
7176
8156
  }
@@ -7251,7 +8231,7 @@ var RelayLink = class extends EventEmitter5 {
7251
8231
  }
7252
8232
  async #read() {
7253
8233
  try {
7254
- const raw = await readFile15(this.#file, "utf8");
8234
+ const raw = await readFile16(this.#file, "utf8");
7255
8235
  const parsed = JSON.parse(raw);
7256
8236
  if (typeof parsed !== "object" || parsed === null)
7257
8237
  return null;
@@ -7264,8 +8244,8 @@ var RelayLink = class extends EventEmitter5 {
7264
8244
  }
7265
8245
  }
7266
8246
  async #write(credentials) {
7267
- await mkdir12(path20.dirname(this.#file), { recursive: true });
7268
- await writeFile13(this.#file, `${JSON.stringify(credentials, null, 2)}
8247
+ await mkdir13(path23.dirname(this.#file), { recursive: true });
8248
+ await writeFile14(this.#file, `${JSON.stringify(credentials, null, 2)}
7269
8249
  `, {
7270
8250
  encoding: "utf8",
7271
8251
  mode: 384
@@ -7520,14 +8500,14 @@ function humanize(error) {
7520
8500
  }
7521
8501
 
7522
8502
  // ../host/dist/terminal.js
7523
- import { EventEmitter as EventEmitter6 } from "node:events";
8503
+ import { EventEmitter as EventEmitter8 } from "node:events";
7524
8504
  import { access as access2, constants as constants2 } from "node:fs/promises";
7525
- import path21 from "node:path";
7526
- import { randomUUID as randomUUID4 } from "node:crypto";
8505
+ import path24 from "node:path";
8506
+ import { randomUUID as randomUUID5 } from "node:crypto";
7527
8507
  var SCROLLBACK_BYTES = 256 * 1024;
7528
8508
  var FLUSH_MS = 12;
7529
8509
  var MAX_TERMINALS = 24;
7530
- var TerminalHub = class extends EventEmitter6 {
8510
+ var TerminalHub = class extends EventEmitter8 {
7531
8511
  #terminals = /* @__PURE__ */ new Map();
7532
8512
  #module = null;
7533
8513
  list(workspaceId) {
@@ -7560,7 +8540,7 @@ var TerminalHub = class extends EventEmitter6 {
7560
8540
  env: environment()
7561
8541
  });
7562
8542
  const info = {
7563
- id: randomUUID4(),
8543
+ id: randomUUID5(),
7564
8544
  workspaceId: options2.workspaceId,
7565
8545
  title: shell.title,
7566
8546
  shell: shell.file,
@@ -7692,22 +8672,22 @@ async function defaultShell() {
7692
8672
  if (pwsh)
7693
8673
  return { file: pwsh, args: [], title: "pwsh" };
7694
8674
  const system = process.env.SystemRoot ?? "C:\\Windows";
7695
- const powershell = path21.join(system, "System32/WindowsPowerShell/v1.0/powershell.exe");
8675
+ const powershell = path24.join(system, "System32/WindowsPowerShell/v1.0/powershell.exe");
7696
8676
  if (await exists2(powershell))
7697
8677
  return { file: powershell, args: [], title: "powershell" };
7698
8678
  return { file: process.env.COMSPEC ?? "cmd.exe", args: [], title: "cmd" };
7699
8679
  }
7700
8680
  const shell = process.env.SHELL;
7701
8681
  if (shell && await exists2(shell))
7702
- return { file: shell, args: [], title: path21.basename(shell) };
8682
+ return { file: shell, args: [], title: path24.basename(shell) };
7703
8683
  if (await exists2("/bin/bash"))
7704
8684
  return { file: "/bin/bash", args: [], title: "bash" };
7705
8685
  return { file: "/bin/sh", args: [], title: "sh" };
7706
8686
  }
7707
8687
  async function findOnPath(name) {
7708
- const dirs = (process.env.PATH ?? "").split(path21.delimiter).filter(Boolean);
8688
+ const dirs = (process.env.PATH ?? "").split(path24.delimiter).filter(Boolean);
7709
8689
  for (const dir of dirs) {
7710
- const candidate = path21.join(dir, name);
8690
+ const candidate = path24.join(dir, name);
7711
8691
  if (await exists2(candidate))
7712
8692
  return candidate;
7713
8693
  }
@@ -7718,10 +8698,10 @@ function exists2(file) {
7718
8698
  }
7719
8699
 
7720
8700
  // ../host/dist/mcp-config.js
7721
- import { readFile as readFile16, writeFile as writeFile14, mkdir as mkdir13 } from "node:fs/promises";
7722
- import path22 from "node:path";
8701
+ import { readFile as readFile17, writeFile as writeFile15, mkdir as mkdir14 } from "node:fs/promises";
8702
+ import path25 from "node:path";
7723
8703
  var MCP_FILE = ".mcp.json";
7724
- var LOCAL_SETTINGS2 = path22.join(".claude", "settings.local.json");
8704
+ var LOCAL_SETTINGS2 = path25.join(".claude", "settings.local.json");
7725
8705
  var queues = /* @__PURE__ */ new Map();
7726
8706
  function serialize(cwd, work) {
7727
8707
  const previous = queues.get(cwd) ?? Promise.resolve();
@@ -7730,7 +8710,7 @@ function serialize(cwd, work) {
7730
8710
  return next;
7731
8711
  }
7732
8712
  async function readProjectServers(cwd) {
7733
- const file = await readJson(path22.join(cwd, MCP_FILE));
8713
+ const file = await readJson(path25.join(cwd, MCP_FILE));
7734
8714
  const servers = file?.mcpServers;
7735
8715
  if (!servers || typeof servers !== "object")
7736
8716
  return {};
@@ -7738,23 +8718,23 @@ async function readProjectServers(cwd) {
7738
8718
  }
7739
8719
  function addProjectServer(cwd, name, config) {
7740
8720
  return serialize(cwd, async () => {
7741
- const file = await readJson(path22.join(cwd, MCP_FILE)) ?? {};
8721
+ const file = await readJson(path25.join(cwd, MCP_FILE)) ?? {};
7742
8722
  const servers = file.mcpServers ?? {};
7743
8723
  servers[name] = config;
7744
8724
  file.mcpServers = servers;
7745
- await writeJson(path22.join(cwd, MCP_FILE), file);
8725
+ await writeJson(path25.join(cwd, MCP_FILE), file);
7746
8726
  await approve(cwd, name);
7747
8727
  });
7748
8728
  }
7749
8729
  function removeProjectServer(cwd, name) {
7750
8730
  return serialize(cwd, async () => {
7751
- const file = await readJson(path22.join(cwd, MCP_FILE));
8731
+ const file = await readJson(path25.join(cwd, MCP_FILE));
7752
8732
  const servers = file?.mcpServers;
7753
8733
  if (!servers || !(name in servers))
7754
8734
  return false;
7755
8735
  delete servers[name];
7756
- await writeJson(path22.join(cwd, MCP_FILE), file);
7757
- const settingsPath = path22.join(cwd, LOCAL_SETTINGS2);
8736
+ await writeJson(path25.join(cwd, MCP_FILE), file);
8737
+ const settingsPath = path25.join(cwd, LOCAL_SETTINGS2);
7758
8738
  const settings = await readJson(settingsPath);
7759
8739
  const enabled = settings?.enabledMcpjsonServers;
7760
8740
  if (settings && Array.isArray(enabled) && enabled.includes(name)) {
@@ -7765,7 +8745,7 @@ function removeProjectServer(cwd, name) {
7765
8745
  });
7766
8746
  }
7767
8747
  async function approve(cwd, name) {
7768
- const file = path22.join(cwd, LOCAL_SETTINGS2);
8748
+ const file = path25.join(cwd, LOCAL_SETTINGS2);
7769
8749
  const settings = await readJson(file) ?? {};
7770
8750
  const enabled = Array.isArray(settings.enabledMcpjsonServers) ? settings.enabledMcpjsonServers : [];
7771
8751
  if (!enabled.includes(name))
@@ -7804,21 +8784,21 @@ function describeConfig(config) {
7804
8784
  }
7805
8785
  async function readJson(file) {
7806
8786
  try {
7807
- const raw = await readFile16(file, "utf8");
8787
+ const raw = await readFile17(file, "utf8");
7808
8788
  const parsed = JSON.parse(raw);
7809
8789
  return parsed && typeof parsed === "object" ? parsed : null;
7810
8790
  } catch (error) {
7811
8791
  if (error.code === "ENOENT")
7812
8792
  return null;
7813
8793
  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 ${path22.basename(file)}: ${error.message}`);
8794
+ throw new Error(`\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0440\u0430\u0437\u043E\u0431\u0440\u0430\u0442\u044C ${path25.basename(file)}: ${error.message}`);
7815
8795
  }
7816
8796
  throw error;
7817
8797
  }
7818
8798
  }
7819
8799
  async function writeJson(file, data) {
7820
- await mkdir13(path22.dirname(file), { recursive: true });
7821
- await writeFile14(file, `${JSON.stringify(data, null, 2)}
8800
+ await mkdir14(path25.dirname(file), { recursive: true });
8801
+ await writeFile15(file, `${JSON.stringify(data, null, 2)}
7822
8802
  `, "utf8");
7823
8803
  }
7824
8804
 
@@ -7840,6 +8820,7 @@ var HostServer = class {
7840
8820
  #workspaces;
7841
8821
  #archive;
7842
8822
  #pins;
8823
+ #sessionLinks;
7843
8824
  #order;
7844
8825
  #folders;
7845
8826
  #settings;
@@ -7848,6 +8829,7 @@ var HostServer = class {
7848
8829
  /** Опросы статуса для идущих OAuth-входов MCP, ключ — сессия и сервер. */
7849
8830
  #mcpAuthWatch = /* @__PURE__ */ new Map();
7850
8831
  #antigravity;
8832
+ #codex;
7851
8833
  /** Боковые сессии («вопрос на полях») по id родителя — не больше одной на разговор. */
7852
8834
  #sides = /* @__PURE__ */ new Map();
7853
8835
  /**
@@ -7895,7 +8877,7 @@ var HostServer = class {
7895
8877
  #limitHandoffBusy = /* @__PURE__ */ new Set();
7896
8878
  /** Живые id сессий, у которых сейчас пишется ручной хэндофф. */
7897
8879
  #handoffBusy = /* @__PURE__ */ new Set();
7898
- #hostId = randomUUID5();
8880
+ #hostId = randomUUID6();
7899
8881
  #plugins = new PluginCli();
7900
8882
  #auth = new AuthCli();
7901
8883
  #relay;
@@ -7915,10 +8897,12 @@ var HostServer = class {
7915
8897
  this.#workspaces = new WorkspaceRegistry(options2.dataDir);
7916
8898
  this.#archive = new SessionArchive(options2.dataDir);
7917
8899
  this.#pins = new SessionPins(options2.dataDir);
8900
+ this.#sessionLinks = new SessionLinks(options2.dataDir);
7918
8901
  this.#order = new ListOrderStore(options2.dataDir);
7919
8902
  this.#folders = new Folders(options2.dataDir);
7920
8903
  this.#settings = new AppSettingsStore(options2.dataDir);
7921
8904
  this.#antigravity = new AntigravityStore(options2.dataDir);
8905
+ this.#codex = new CodexStore(options2.dataDir);
7922
8906
  this.#handoffs = new HandoffStore(options2.dataDir);
7923
8907
  this.#limitStop = new LimitStopState(options2.dataDir);
7924
8908
  this.#finder = new ProjectFinder(this.#workspaces);
@@ -7945,9 +8929,11 @@ var HostServer = class {
7945
8929
  const id = workspaceIdFromPath(dir);
7946
8930
  const onDisk = await this.#workspaces.sessionsOnDisk(id);
7947
8931
  const antigravity = await this.#antigravity.list(id);
7948
- return [...onDisk.map((s) => s.sessionId), ...antigravity.map((r) => r.id)];
8932
+ const codex = await this.#codex.list(id);
8933
+ return [...onDisk.map((s) => s.sessionId), ...antigravity.map((r) => r.id), ...codex.map((r) => r.id)];
7949
8934
  });
7950
8935
  await this.#antigravity.remapWorkspaceIds(remap);
8936
+ await this.#codex.remapWorkspaceIds(remap);
7951
8937
  await this.#archive.remapWorkspaceIds(remap);
7952
8938
  await this.#pins.remapWorkspaceIds(remap);
7953
8939
  await this.#order.remapWorkspaceIds(remap);
@@ -7957,6 +8943,7 @@ var HostServer = class {
7957
8943
  await this.#workspaces.load();
7958
8944
  await this.#archive.load();
7959
8945
  await this.#pins.load();
8946
+ await this.#sessionLinks.load();
7960
8947
  await this.#order.load();
7961
8948
  await this.#folders.load();
7962
8949
  await this.#carryOverWorkspaceIds();
@@ -8125,7 +9112,8 @@ var HostServer = class {
8125
9112
  client.send({
8126
9113
  type: "error",
8127
9114
  message: error instanceof Error ? error.message : String(error),
8128
- context: frame.type
9115
+ context: frame.type,
9116
+ ..."requestId" in frame && typeof frame.requestId === "string" ? { requestId: frame.requestId } : {}
8129
9117
  });
8130
9118
  });
8131
9119
  }
@@ -8168,10 +9156,12 @@ var HostServer = class {
8168
9156
  protocol: PROTOCOL_VERSION,
8169
9157
  hostId: this.#hostId,
8170
9158
  hostVersion: this.#options.version,
8171
- platform: process.platform
9159
+ platform: process.platform,
9160
+ features: ["session-routing", "session-links"]
8172
9161
  });
8173
9162
  this.#send(socket, { type: "workspace.list", ...this.#workspaceLists() });
8174
9163
  this.#sendFolders(socket);
9164
+ this.#send(socket, { type: "session.links", links: this.#sessionLinks.all });
8175
9165
  this.#send(socket, { type: "order.state", order: this.#order.current });
8176
9166
  this.#sendLive(socket);
8177
9167
  this.#auth.status().then((status) => this.#send(socket, { type: "auth.status", status })).catch(() => void 0);
@@ -8248,6 +9238,27 @@ var HostServer = class {
8248
9238
  case "session.start":
8249
9239
  await this.#startSession(socket, frame);
8250
9240
  return;
9241
+ case "session.links.get":
9242
+ this.#send(socket, { type: "session.links", links: this.#sessionLinks.all });
9243
+ return;
9244
+ case "session.link": {
9245
+ const { sessions, archived } = await this.#listSessions(frame.workspaceId);
9246
+ const find = (id) => [...sessions, ...archived].find((s) => s.id === id || s.claudeSessionId === id);
9247
+ const child = find(frame.sessionId);
9248
+ const parent = frame.parentId === null ? null : find(frame.parentId);
9249
+ if (!child || frame.parentId !== null && !parent)
9250
+ throw new Error("\u0421\u0435\u0441\u0441\u0438\u044F \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430 \u0432 \u044D\u0442\u043E\u043C \u043F\u0440\u043E\u0435\u043A\u0442\u0435");
9251
+ await this.#sessionLinks.set({
9252
+ workspaceId: frame.workspaceId,
9253
+ sessionId: child.claudeSessionId ?? child.id,
9254
+ parentId: parent ? parent.claudeSessionId ?? parent.id : null,
9255
+ stage: frame.stage,
9256
+ kind: "linked",
9257
+ createdAt: Date.now()
9258
+ });
9259
+ this.#broadcast({ type: "session.links", links: this.#sessionLinks.all });
9260
+ return;
9261
+ }
8251
9262
  case "session.close":
8252
9263
  await this.#dropSession(frame.sessionId, "closed by client");
8253
9264
  return;
@@ -9119,6 +10130,8 @@ var HostServer = class {
9119
10130
  return false;
9120
10131
  await this.#closeSide(sessionId);
9121
10132
  await session.close(reason);
10133
+ if (this.#sessions.get(sessionId) !== session)
10134
+ return true;
9122
10135
  this.#sessions.delete(sessionId);
9123
10136
  this.#limitApproved.delete(sessionId);
9124
10137
  this.#broadcast({ type: "session.closed", sessionId, reason });
@@ -9417,9 +10430,47 @@ var HostServer = class {
9417
10430
  const workspace = this.#workspaces.find(frame.workspaceId);
9418
10431
  if (!workspace)
9419
10432
  throw new Error(`\u0412\u043E\u0440\u043A\u0441\u043F\u0435\u0439\u0441 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D: ${frame.workspaceId}`);
10433
+ if (frame.taskParent) {
10434
+ const list = await this.#listSessions(workspace.id);
10435
+ if (![...list.sessions, ...list.archived].some((s) => s.id === frame.taskParent || s.claudeSessionId === frame.taskParent))
10436
+ throw new Error("\u0420\u043E\u0434\u0438\u0442\u0435\u043B\u044C\u0441\u043A\u0430\u044F \u0441\u0435\u0441\u0441\u0438\u044F \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430 \u0432 \u044D\u0442\u043E\u043C \u043F\u0440\u043E\u0435\u043A\u0442\u0435");
10437
+ }
9420
10438
  const provider = frame.provider ?? "claude";
9421
10439
  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`);
10440
+ 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`);
10441
+ }
10442
+ const codexRecord = frame.resume ? await this.#codex.find(frame.resume) : null;
10443
+ if (codexRecord || provider === "codex") {
10444
+ if (frame.resume && !codexRecord)
10445
+ throw new Error("\u0421\u0435\u0441\u0441\u0438\u044F Codex \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430");
10446
+ if (codexRecord && codexRecord.workspaceId !== workspace.id)
10447
+ 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");
10448
+ const existing = codexRecord && !frame.fork ? this.#sessions.get(codexRecord.id) : null;
10449
+ if (existing && existing.state !== "closed" && existing.state !== "error") {
10450
+ await this.#announceStarted(socket, frame, existing);
10451
+ return;
10452
+ }
10453
+ if (existing)
10454
+ await existing.close();
10455
+ if (codexRecord)
10456
+ await this.#archive.unarchive([codexRecord.id]);
10457
+ const session2 = new CodexSession({
10458
+ workspaceId: workspace.id,
10459
+ cwd: workspace.path,
10460
+ store: this.#codex,
10461
+ ...codexRecord ? { record: codexRecord } : {},
10462
+ fork: frame.fork,
10463
+ permissionMode: frame.permissionMode ?? codexRecord?.permissionMode ?? "default",
10464
+ ...frame.model ? { model: frame.model } : {},
10465
+ defaultTitle: workspace.name,
10466
+ writableRoots: () => this.#writableRoots(workspace.path)
10467
+ });
10468
+ this.#wire(session2);
10469
+ this.#sessions.set(session2.id, session2);
10470
+ session2.start();
10471
+ this.#sendLive();
10472
+ await this.#announceStarted(socket, frame, session2);
10473
+ return;
9423
10474
  }
9424
10475
  const agyRecord = frame.resume ? await this.#antigravity.find(frame.resume) : null;
9425
10476
  if (agyRecord || !frame.resume && frame.provider === "antigravity") {
@@ -9438,7 +10489,7 @@ var HostServer = class {
9438
10489
  this.#sessions.set(session2.id, session2);
9439
10490
  session2.start();
9440
10491
  this.#sendLive();
9441
- this.#send(socket, { type: "session.summary", session: session2.summary() });
10492
+ await this.#announceStarted(socket, frame, session2);
9442
10493
  return;
9443
10494
  }
9444
10495
  const resumed = frame.resume && !frame.fork ? (await this.#workspaces.sessionsOnDisk(workspace.id)).find((info) => info.sessionId === frame.resume) : void 0;
@@ -9463,13 +10514,31 @@ var HostServer = class {
9463
10514
  this.#sessions.set(session.id, session);
9464
10515
  session.start();
9465
10516
  this.#sendLive();
9466
- this.#send(socket, { type: "session.summary", session: session.summary() });
10517
+ await this.#announceStarted(socket, frame, session);
9467
10518
  if (!frame.continuesFrom)
9468
10519
  return;
9469
10520
  await this.#carryPin(workspace.id, frame.continuesFrom, session.id);
9470
10521
  if (frame.fromHandoff)
9471
10522
  await this.#markHandoffContinued(frame.continuesFrom);
9472
10523
  }
10524
+ async #announceStarted(socket, frame, session) {
10525
+ const summary = session.summary();
10526
+ const parent = frame.taskParent ?? (frame.fork ? frame.resume : frame.continuesFrom);
10527
+ if (parent && (!frame.resume || frame.fork)) {
10528
+ await this.#sessionLinks.set({
10529
+ workspaceId: frame.workspaceId,
10530
+ sessionId: summary.claudeSessionId ?? summary.id,
10531
+ parentId: parent,
10532
+ stage: frame.taskStage ?? "other",
10533
+ kind: frame.fork ? "fork" : "continuation",
10534
+ createdAt: Date.now()
10535
+ });
10536
+ this.#broadcast({ type: "session.links", links: this.#sessionLinks.all });
10537
+ }
10538
+ this.#send(socket, { type: "session.summary", session: summary });
10539
+ if (frame.requestId)
10540
+ this.#send(socket, { type: "session.started", requestId: frame.requestId, session: summary });
10541
+ }
9473
10542
  /**
9474
10543
  * Отметить хэндофф продолженным — и сказать об этом всем окнам. Он остаётся
9475
10544
  * лежать у прежней сессии, пока его не скроют, и без отметки её баннер звал
@@ -9553,11 +10622,19 @@ var HostServer = class {
9553
10622
  });
9554
10623
  session.on("summary", (summary) => {
9555
10624
  this.#broadcast({ type: "session.summary", session: summary });
10625
+ if (summary.claudeSessionId && summary.claudeSessionId !== summary.id && this.#sessionLinks.all.some((r) => r.sessionId === summary.id || r.parentId === summary.id)) {
10626
+ void this.#sessionLinks.migrate(summary.id, summary.claudeSessionId).then(() => {
10627
+ this.#broadcast({ type: "session.links", links: this.#sessionLinks.all });
10628
+ }).catch((error) => console.error("[session.links]", error));
10629
+ }
9556
10630
  if (!summary.claudeSessionId || !this.#pins.has(summary.id))
9557
10631
  return;
9558
10632
  void this.#migratePin(summary.id, summary.claudeSessionId);
9559
10633
  });
9560
10634
  session.on("claudeSessionId", ({ from, to }) => {
10635
+ void this.#sessionLinks.migrate(from, to).then(() => {
10636
+ this.#broadcast({ type: "session.links", links: this.#sessionLinks.all });
10637
+ }).catch((error) => console.error("[session.links]", error));
9561
10638
  if (!this.#pins.has(from))
9562
10639
  return;
9563
10640
  void this.#migratePin(from, to);
@@ -9583,7 +10660,7 @@ var HostServer = class {
9583
10660
  this.#broadcast({ type: "context.state", sessionId: session.id, context });
9584
10661
  });
9585
10662
  session.on("stderr", (data) => {
9586
- const tag = session instanceof AntigravitySession ? "agy" : "claude";
10663
+ const tag = session instanceof CodexSession ? "codex" : session instanceof AntigravitySession ? "agy" : "claude";
9587
10664
  process.stderr.write(`[${tag} ${session.id.slice(0, 8)}] ${data}`);
9588
10665
  });
9589
10666
  }
@@ -9603,7 +10680,7 @@ var HostServer = class {
9603
10680
  * разговора пока и не было.
9604
10681
  */
9605
10682
  #ensureSide(parent) {
9606
- if (parent instanceof AntigravitySession) {
10683
+ if (!(parent instanceof ClaudeSession)) {
9607
10684
  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
10685
  }
9609
10686
  const existing = this.#sides.get(parent.id);
@@ -9661,7 +10738,7 @@ var HostServer = class {
9661
10738
  */
9662
10739
  #roots() {
9663
10740
  const roots = this.#finder.roots();
9664
- return roots.length > 0 ? roots : [homedir6()];
10741
+ return roots.length > 0 ? roots : [homedir7()];
9665
10742
  }
9666
10743
  /**
9667
10744
  * Где сессии этого каталога разрешено писать без вопроса.
@@ -9903,7 +10980,7 @@ var HostServer = class {
9903
10980
  live.setTitle(title);
9904
10981
  return;
9905
10982
  }
9906
- if (await this.#antigravity.rename(sessionId, title)) {
10983
+ if (await this.#codex.rename(sessionId, title) || await this.#antigravity.rename(sessionId, title)) {
9907
10984
  if (workspaceId)
9908
10985
  await this.#sendSessionList(workspaceId);
9909
10986
  return;
@@ -9960,17 +11037,24 @@ var HostServer = class {
9960
11037
  continue;
9961
11038
  historical.push(antigravitySummary(record));
9962
11039
  }
11040
+ if (workspacePath && this.#settings.current.enabledProviders.includes("codex"))
11041
+ await this.#codex.discover(workspaceId, workspacePath);
11042
+ for (const record of await this.#codex.list(workspaceId)) {
11043
+ if (!liveIds.has(record.id))
11044
+ historical.push({ ...antigravitySummary(record), provider: "codex" });
11045
+ }
9963
11046
  const known = /* @__PURE__ */ new Set([...liveIds, ...historical.map((s) => s.id)]);
9964
11047
  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
11048
  await this.#pins.sweep(workspaceId, known);
9966
11049
  const sessions = [];
9967
11050
  const archived = [];
9968
11051
  for (const base of [...live, ...historical].sort((a, b) => b.updatedAt - a.updatedAt)) {
11052
+ const current = this.#sessions.get(base.id)?.summary() ?? base;
9969
11053
  const pin = this.#pins.find(base.claudeSessionId ?? base.id);
9970
11054
  const folderId = this.#folders.folderIdForSession(base.claudeSessionId ?? base.id);
9971
11055
  const pinnedFolderId = this.#folders.folderIdForPinnedSession(base.claudeSessionId ?? base.id);
9972
11056
  const summary = {
9973
- ...base,
11057
+ ...current,
9974
11058
  ...pin ? { pinned: true, pinnedAt: pin.at } : {},
9975
11059
  ...folderId ? { folderId } : {},
9976
11060
  ...pinnedFolderId ? { pinnedFolderId } : {}
@@ -10006,15 +11090,15 @@ var HostServer = class {
10006
11090
  }
10007
11091
  #serveStatic(req, res) {
10008
11092
  const webRoot = this.#options.webRoot;
10009
- if (!webRoot || !existsSync4(webRoot)) {
11093
+ if (!webRoot || !existsSync5(webRoot)) {
10010
11094
  res.writeHead(200, { "content-type": "text/plain; charset=utf-8" });
10011
11095
  res.end("CCV host is running. UI is served by the Vite dev server.\n");
10012
11096
  return;
10013
11097
  }
10014
11098
  const url2 = new URL(req.url ?? "/", "http://localhost");
10015
- const requested = path23.join(webRoot, path23.normalize(url2.pathname));
10016
- const target = requested.startsWith(webRoot) && existsSync4(requested) && statSync3(requested).isFile() ? requested : path23.join(webRoot, "index.html");
10017
- if (!existsSync4(target)) {
11099
+ const requested = path26.join(webRoot, path26.normalize(url2.pathname));
11100
+ const target = requested.startsWith(webRoot) && existsSync5(requested) && statSync3(requested).isFile() ? requested : path26.join(webRoot, "index.html");
11101
+ if (!existsSync5(target)) {
10018
11102
  res.writeHead(404).end("not found");
10019
11103
  return;
10020
11104
  }
@@ -10039,7 +11123,7 @@ function contentType(file) {
10039
11123
  ".svg": "image/svg+xml",
10040
11124
  ".woff2": "font/woff2"
10041
11125
  };
10042
- return types[path23.extname(file)] ?? "application/octet-stream";
11126
+ return types[path26.extname(file)] ?? "application/octet-stream";
10043
11127
  }
10044
11128
  function antigravitySummary(record) {
10045
11129
  return {
@@ -10068,8 +11152,8 @@ function antigravitySummary(record) {
10068
11152
  }
10069
11153
 
10070
11154
  // dist/ccv.js
10071
- var HERE = path24.dirname(fileURLToPath(import.meta.url));
10072
- var PACKAGE_ROOT = path24.resolve(HERE, "..");
11155
+ var HERE = path27.dirname(fileURLToPath(import.meta.url));
11156
+ var PACKAGE_ROOT = path27.resolve(HERE, "..");
10073
11157
  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
11158
 
10075
11159
  \u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u0438\u0435:
@@ -10080,17 +11164,19 @@ var USAGE = `ccv \u2014 Claude Code Visual: \u043B\u043E\u043A\u0430\u043B\u044C
10080
11164
  --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
11165
  --no-open \u043D\u0435 \u043E\u0442\u043A\u0440\u044B\u0432\u0430\u0442\u044C \u0431\u0440\u0430\u0443\u0437\u0435\u0440
10082
11166
  --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
11167
+ --codex \u043F\u0443\u0442\u044C \u043A Codex CLI, \u0438 \u0432\u044B\u0439\u0442\u0438
10083
11168
  -v, --version \u0432\u0435\u0440\u0441\u0438\u044F
10084
11169
  -h, --help \u044D\u0442\u0430 \u0441\u043F\u0440\u0430\u0432\u043A\u0430
10085
11170
 
10086
11171
  \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.
11172
+ CCV_CLAUDE_PATH, CCV_BUNDLED_CLAUDE, CCV_CODEX_PATH.
10088
11173
  \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
11174
  var options = {
10090
11175
  port: { type: "string", short: "p" },
10091
11176
  host: { type: "string" },
10092
11177
  open: { type: "boolean", default: true },
10093
11178
  claude: { type: "boolean" },
11179
+ codex: { type: "boolean" },
10094
11180
  version: { type: "boolean", short: "v" },
10095
11181
  help: { type: "boolean", short: "h" }
10096
11182
  };
@@ -10114,6 +11200,11 @@ if (values.version) {
10114
11200
  }
10115
11201
  if (values.claude)
10116
11202
  process.exit(await reportClaude());
11203
+ if (values.codex) {
11204
+ const launcher = codexLauncher();
11205
+ console.log(launcher ? `Codex CLI: ${launcher.file}${launcher.args.length ? " " + launcher.args.join(" ") : ""}` : CODEX_MISSING_HINT);
11206
+ process.exit(launcher ? 0 : 1);
11207
+ }
10117
11208
  var defaults = envDefaults();
10118
11209
  var port = values.port === void 0 ? defaults.port : Number(values.port);
10119
11210
  if (!Number.isInteger(port) || port < 1 || port > 65535) {
@@ -10136,7 +11227,7 @@ var server = new HostServer({
10136
11227
  dataDir: defaults.dataDir,
10137
11228
  // UI лежит в пакете рядом с бандлом — это и есть разница между установленной
10138
11229
  // утилитой и запуском из репозитория, где сборка живёт в `apps/web/dist`.
10139
- webRoot: process.env.CCV_WEB_ROOT ?? path24.join(PACKAGE_ROOT, "web"),
11230
+ webRoot: process.env.CCV_WEB_ROOT ?? path27.join(PACKAGE_ROOT, "web"),
10140
11231
  version,
10141
11232
  relayUrl: defaults.relayUrl
10142
11233
  });
@@ -10165,7 +11256,7 @@ for (const signal of ["SIGINT", "SIGTERM"]) {
10165
11256
  }
10166
11257
  async function packageVersion() {
10167
11258
  try {
10168
- const text = await readFile17(path24.join(PACKAGE_ROOT, "package.json"), "utf8");
11259
+ const text = await readFile18(path27.join(PACKAGE_ROOT, "package.json"), "utf8");
10169
11260
  return JSON.parse(text).version ?? "0.0.0";
10170
11261
  } catch {
10171
11262
  return "0.0.0";
@@ -10209,7 +11300,7 @@ function openBrowser(target) {
10209
11300
  return;
10210
11301
  }
10211
11302
  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 = spawn3(command.file, command.args, {
11303
+ const child = spawn4(command.file, command.args, {
10213
11304
  stdio: "ignore",
10214
11305
  detached: true,
10215
11306
  windowsHide: true