@i14ks/ccv 0.51.0 → 0.53.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 (81) hide show
  1. package/bundle/ccv.mjs +547 -213
  2. package/package.json +1 -1
  3. package/web/assets/{MarkdownTextEditor-JS5gfhvn.js → MarkdownTextEditor-Csjw742v.js} +1 -1
  4. package/web/assets/{abnfDiagram-S7VZAUFO-NiQLnUk4.js → abnfDiagram-S7VZAUFO-CC40ZxnR.js} +1 -1
  5. package/web/assets/{architectureDiagram-YGSQEFNW-CacJXhkP.js → architectureDiagram-YGSQEFNW-CoT6fdue.js} +1 -1
  6. package/web/assets/{blockDiagram-APKKGZFW-CQmfctFs.js → blockDiagram-APKKGZFW-BJdKNsdt.js} +1 -1
  7. package/web/assets/{c4Diagram-KJ2TOQU5-BvlnxWev.js → c4Diagram-KJ2TOQU5-BEfGCdZd.js} +1 -1
  8. package/web/assets/{chunk-2Q5K7J3B-Cgc58TSE.js → chunk-2Q5K7J3B-DSGyK7k5.js} +1 -1
  9. package/web/assets/{chunk-5VM5RSS4-C1bWQfyK.js → chunk-5VM5RSS4-DhmvHA58.js} +1 -1
  10. package/web/assets/{chunk-HFQBQIA3-C7a1_mVn.js → chunk-HFQBQIA3-CWaFbKzB.js} +1 -1
  11. package/web/assets/{chunk-JWPE2WC7-C18blVa-.js → chunk-JWPE2WC7-D0xOdc1w.js} +1 -1
  12. package/web/assets/{chunk-KQLB2F66-CI40AH6D.js → chunk-KQLB2F66-gpLxChNP.js} +2 -2
  13. package/web/assets/{chunk-KS47KZWR-DqUN9A3o.js → chunk-KS47KZWR-yU-66k-1.js} +1 -1
  14. package/web/assets/{chunk-OY52VR5R-NLJNl2SH.js → chunk-OY52VR5R-C_h-f6nW.js} +1 -1
  15. package/web/assets/{chunk-TU62E6Q5-Dfc2QrQc.js → chunk-TU62E6Q5-Bsk3rqzn.js} +1 -1
  16. package/web/assets/{chunk-XXDRQBXY-BbvDRTY2.js → chunk-XXDRQBXY-Bj0wzkKQ.js} +1 -1
  17. package/web/assets/{classDiagram-v2-L25IHNXF-C70BAnHO.js → classDiagram-v2-L25IHNXF-CYwhxRk5.js} +1 -1
  18. package/web/assets/{codemirror-C9-rbUS5.js → codemirror-BQt0gYMS.js} +1 -1
  19. package/web/assets/{codemirrorImages-Ddzgh4gP.js → codemirrorImages-DQSQ54Do.js} +1 -1
  20. package/web/assets/{cose-bilkent-JH36ORCC-BpSbzUvj.js → cose-bilkent-JH36ORCC-D8zDAVat.js} +1 -1
  21. package/web/assets/{cynefin-EF2NZ3EQ-BOIqStKg.js → cynefin-EF2NZ3EQ-DqJ52vqQ.js} +1 -1
  22. package/web/assets/{cynefinDiagram-L36ESFBY-DfDb4Bbh.js → cynefinDiagram-L36ESFBY-45YrzJmY.js} +1 -1
  23. package/web/assets/{dagre-SPEB5RXH-B21shBDF.js → dagre-SPEB5RXH-rq12K6h9.js} +1 -1
  24. package/web/assets/{diagram-3B7GL73J-D5GyZahr.js → diagram-3B7GL73J-BKx4Wqbd.js} +1 -1
  25. package/web/assets/{diagram-DNEMPZML-l_jbAuYI.js → diagram-DNEMPZML-DgB5PnBT.js} +1 -1
  26. package/web/assets/{diagram-L3MUGCDN-Dxg4m10Z.js → diagram-L3MUGCDN-jED1aCKZ.js} +1 -1
  27. package/web/assets/{diagram-LA4NIPWU-Cel9qbbE.js → diagram-LA4NIPWU-f2I-Q9-6.js} +1 -1
  28. package/web/assets/{diagram-MHCOC4E2-BiOEXYq3.js → diagram-MHCOC4E2-BK3C_JNh.js} +1 -1
  29. package/web/assets/{diagram-XPFHEONP-BvK5PJyb.js → diagram-XPFHEONP-DDMR4000.js} +1 -1
  30. package/web/assets/{ebnfDiagram-UZSYDL2S-6zLeUUGj.js → ebnfDiagram-UZSYDL2S-C-FYFt2A.js} +1 -1
  31. package/web/assets/{elk-XV6XMXQE-vHNWsDBP.js → elk-XV6XMXQE-e0xW3ze0.js} +1 -1
  32. package/web/assets/{erDiagram-EYBAPDEH-B_0_-AXN.js → erDiagram-EYBAPDEH-9ze3YAAs.js} +1 -1
  33. package/web/assets/{flowDiagram-MALGAFMO-DHbDByLY.js → flowDiagram-MALGAFMO-Cn1Zwh-a.js} +1 -1
  34. package/web/assets/{ganttDiagram-23REXITY-B80CTXbo.js → ganttDiagram-23REXITY-Cf_Xky1d.js} +1 -1
  35. package/web/assets/{gitGraphDiagram-STJD7YCW-CkacpGe7.js → gitGraphDiagram-STJD7YCW-CvRsTOyZ.js} +1 -1
  36. package/web/assets/{index-C8qdu2Ys.js → index-69zmsnTJ.js} +1 -1
  37. package/web/assets/{index-CVL9Nmm_.js → index-B-hbtbZ5.js} +1 -1
  38. package/web/assets/{index-DSvz1p_2.js → index-B2lcdDOn.js} +1 -1
  39. package/web/assets/{index-Cm5B9oUk.js → index-BH0Wz2LJ.js} +1 -1
  40. package/web/assets/{index-pc3Dhu5R.js → index-BIwQqBhp.js} +1 -1
  41. package/web/assets/{index-92k3_wJu.js → index-BNncRPjt.js} +1 -1
  42. package/web/assets/{index-BWlmCdoh.js → index-BTb9yWkG.js} +1 -1
  43. package/web/assets/{index-DC0nz24L.js → index-BZxgk-Vd.js} +1 -1
  44. package/web/assets/{index-C_2wUJRx.js → index-BcL-Y30O.js} +1 -1
  45. package/web/assets/{index-C-Hx4d-f.js → index-BiIY4hJ4.js} +1 -1
  46. package/web/assets/{index-BiVTsO6O.js → index-BvVJTF87.js} +1 -1
  47. package/web/assets/{index-DmzLc_Io.css → index-C77FCeR5.css} +1 -1
  48. package/web/assets/{index-g768jR3q.js → index-CBYW5YK4.js} +1 -1
  49. package/web/assets/{index-BPYt9SZ5.js → index-CYT4TGSx.js} +1 -1
  50. package/web/assets/{index-Ea4Oi4uX.js → index-CzxfpMLy.js} +1 -1
  51. package/web/assets/{index-CuT0yXRF.js → index-DSYQzosu.js} +1 -1
  52. package/web/assets/{index-B36m2pd4.js → index-NTUQ-bNI.js} +1 -1
  53. package/web/assets/{index-kN0c62Qc.js → index-PZQOjvwf.js} +1 -1
  54. package/web/assets/{index-CIuxUzk9.js → index-iyqDWUby.js} +1 -1
  55. package/web/assets/{index-FQtowISJ.js → index-vVgw8TzF.js} +1 -1
  56. package/web/assets/index-zxn-PK7J.js +175 -0
  57. package/web/assets/{infoDiagram-KBXO4MBG-CU1EkG0-.js → infoDiagram-KBXO4MBG-uPHoxiNR.js} +1 -1
  58. package/web/assets/{ishikawaDiagram-M35NCXHK-BZmugbzW.js → ishikawaDiagram-M35NCXHK-ti2cT3zG.js} +1 -1
  59. package/web/assets/{journeyDiagram-OPLOXDXO-DDidfWhw.js → journeyDiagram-OPLOXDXO-CTRUifHX.js} +1 -1
  60. package/web/assets/{kanban-definition-BZKZHSQY-DT8uvOWy.js → kanban-definition-BZKZHSQY-DaPCeo_A.js} +1 -1
  61. package/web/assets/{mermaid.core-L3hD6CUN.js → mermaid.core-BBhQ8t05.js} +4 -4
  62. package/web/assets/{mindmap-definition-I2QAS2VK-CglnosNO.js → mindmap-definition-I2QAS2VK-B6CaWNdc.js} +1 -1
  63. package/web/assets/{pegDiagram-FD4XPPHP-Riow5Koi.js → pegDiagram-FD4XPPHP-DUYcGRAG.js} +1 -1
  64. package/web/assets/{pieDiagram-J4AKIIQI-CK0itELu.js → pieDiagram-J4AKIIQI-BMV2Qqtf.js} +1 -1
  65. package/web/assets/{quadrantDiagram-XTYBLID2-a0cZCRAm.js → quadrantDiagram-XTYBLID2-Bp7WS5Ad.js} +1 -1
  66. package/web/assets/{railroadDiagram-MRQ6NCDL-C-JOz99A.js → railroadDiagram-MRQ6NCDL-1BwzZ0-P.js} +1 -1
  67. package/web/assets/{requirementDiagram-Y7LWUY3S-C6ek4quK.js → requirementDiagram-Y7LWUY3S-CLzk9GBg.js} +1 -1
  68. package/web/assets/{sankeyDiagram-WGJFYUXA-CV0CpeMd.js → sankeyDiagram-WGJFYUXA-D2yZGauF.js} +1 -1
  69. package/web/assets/{sequenceDiagram-5NDRBG5M-UAB57p0q.js → sequenceDiagram-5NDRBG5M-BMRdwsGZ.js} +1 -1
  70. package/web/assets/{sizeCapture-INFHLROL-CEP45PjG.js → sizeCapture-INFHLROL-BHVOTD-p.js} +1 -1
  71. package/web/assets/{stateDiagram-v2-FJ4FJNEA-DtxyTD99.js → stateDiagram-v2-FJ4FJNEA-CpBUCte8.js} +1 -1
  72. package/web/assets/{swimlanes-UMQ2AFYF-D0-FWl64.js → swimlanes-UMQ2AFYF-oy_b3o0P.js} +1 -1
  73. package/web/assets/swimlanesDiagram-OMPLPG4O-DldP3xAt.js +8 -0
  74. package/web/assets/{timeline-definition-SEUHKTQE-OQG2waQW.js → timeline-definition-SEUHKTQE-DoWWl2yp.js} +1 -1
  75. package/web/assets/{usecaseDiagram-AFA6YXN4-DxTFx1Wc.js → usecaseDiagram-AFA6YXN4-Ca_T85xd.js} +1 -1
  76. package/web/assets/{vennDiagram-NNMJR3RB-1Uym6RqY.js → vennDiagram-NNMJR3RB-jVel6870.js} +1 -1
  77. package/web/assets/{wardleyDiagram-S7YFUSEH-CqeyKfQR.js → wardleyDiagram-S7YFUSEH-Bbw7mGBN.js} +1 -1
  78. package/web/assets/{xychartDiagram-GGNKY7IX-CGvFnidy.js → xychartDiagram-GGNKY7IX-Cviv2B2x.js} +1 -1
  79. package/web/index.html +2 -2
  80. package/web/assets/index-CnDNc_gM.js +0 -172
  81. package/web/assets/swimlanesDiagram-OMPLPG4O-B5BeOS4_.js +0 -8
package/bundle/ccv.mjs CHANGED
@@ -13,6 +13,494 @@ import { constants } from "node:fs";
13
13
  import { access, readFile } from "node:fs/promises";
14
14
  import { homedir } from "node:os";
15
15
  import path from "node:path";
16
+
17
+ // ../host/dist/egress-proxy.js
18
+ import { EventEmitter as EventEmitter2 } from "node:events";
19
+ import { createServer, request as httpRequest } from "node:http";
20
+ import { connect } from "node:net";
21
+
22
+ // ../host/dist/network-guard.js
23
+ import { EventEmitter } from "node:events";
24
+ import { request } from "node:https";
25
+ import { BlockList, isIP } from "node:net";
26
+ import { networkInterfaces } from "node:os";
27
+ var TRACE_URL = "https://api.anthropic.com/cdn-cgi/trace";
28
+ var NETWORK_CHECK_MS = 5e3;
29
+ var INTERFACES_POLL_MS = 1e3;
30
+ var CHECK_TIMEOUT_MS = 4e3;
31
+ var RETRY_DELAY_MS = 1e3;
32
+ 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";
33
+ var NetworkGuard = class extends EventEmitter {
34
+ #enabled = false;
35
+ #blocked = /* @__PURE__ */ new Set();
36
+ /** Разрешённые адреса в нормальной форме, по порядку; пусто — адрес не сверяется. */
37
+ #allowedIps = [];
38
+ #allowList = null;
39
+ #state = {
40
+ status: "ok",
41
+ country: null,
42
+ ip: null,
43
+ reason: null,
44
+ checkedAt: null,
45
+ enabled: false
46
+ };
47
+ #checkTimer = null;
48
+ #interfacesTimer = null;
49
+ #interfaces = "";
50
+ #inFlight = null;
51
+ /** Когда началась идущая проверка. */
52
+ #inFlightStartedAt = 0;
53
+ /**
54
+ * Когда началась проверка, давшая текущее состояние; `null` — состояние не
55
+ * из проверки при нынешних настройках.
56
+ */
57
+ #resultStartedAt = null;
58
+ /** Растёт при каждой смене настроек: ответ проверки, начатой до неё, не применяется. */
59
+ #generation = 0;
60
+ get state() {
61
+ return { ...this.#state };
62
+ }
63
+ /** Почему агентам сейчас нельзя в сеть; `null` — можно. */
64
+ blockedReason() {
65
+ return this.#state.status === "blocked" ? this.#state.reason ?? UNCHECKED_REASON : null;
66
+ }
67
+ /**
68
+ * Применить настройки. Включение начинает с блока до первой проверки,
69
+ * выключение снимает блок сразу.
70
+ */
71
+ configure(enabled, blockedCountries, allowedIps = []) {
72
+ const countries = new Set(blockedCountries);
73
+ const ips = [
74
+ ...new Set(allowedIps.map(normalizeAllowedIp).filter((ip) => ip !== null))
75
+ ].sort();
76
+ const same = enabled === this.#enabled && countries.size === this.#blocked.size && [...countries].every((c) => this.#blocked.has(c)) && ips.join(",") === this.#allowedIps.join(",");
77
+ if (same)
78
+ return;
79
+ this.#generation += 1;
80
+ this.#resultStartedAt = null;
81
+ this.#blocked = countries;
82
+ this.#allowedIps = ips;
83
+ this.#allowList = buildAllowList(ips);
84
+ const wasEnabled = this.#enabled;
85
+ this.#enabled = enabled;
86
+ if (!enabled) {
87
+ this.#stopTimers();
88
+ this.#apply({
89
+ status: "ok",
90
+ country: this.#state.country,
91
+ ip: this.#state.ip,
92
+ reason: null,
93
+ checkedAt: null
94
+ });
95
+ return;
96
+ }
97
+ if (!wasEnabled) {
98
+ this.#apply({ status: "blocked", country: null, ip: null, reason: UNCHECKED_REASON, checkedAt: null });
99
+ this.#startTimers();
100
+ }
101
+ void this.check();
102
+ }
103
+ stop() {
104
+ this.#stopTimers();
105
+ }
106
+ /** Проверить сейчас. Параллельные вызовы делят одну проверку. */
107
+ check() {
108
+ if (!this.#enabled)
109
+ return Promise.resolve(this.state);
110
+ if (!this.#inFlight) {
111
+ const startedAt = Date.now();
112
+ this.#inFlightStartedAt = startedAt;
113
+ this.#inFlight = this.#runCheck(startedAt).finally(() => {
114
+ this.#inFlight = null;
115
+ });
116
+ }
117
+ return this.#inFlight;
118
+ }
119
+ /**
120
+ * Состояние по проверке, начатой не раньше `since`. Идущую проверку, начатую
121
+ * раньше, не переиспользуем: она могла уйти ещё по старому маршруту — ждём её
122
+ * и запускаем новую. Проверку, отменённую сменой настроек, тоже не считаем.
123
+ */
124
+ async checkSince(since) {
125
+ while (this.#enabled) {
126
+ if (this.#resultStartedAt !== null && this.#resultStartedAt >= since)
127
+ return this.state;
128
+ if (this.#inFlight && this.#inFlightStartedAt < since) {
129
+ await this.#inFlight;
130
+ continue;
131
+ }
132
+ await this.check();
133
+ }
134
+ return this.state;
135
+ }
136
+ /**
137
+ * Проверка, начатая не раньше этого вызова. Её ждёт каждое действие
138
+ * человека, поднимающее агента или отдающее ему промпт.
139
+ */
140
+ checkNow() {
141
+ return this.checkSince(Date.now());
142
+ }
143
+ async #runCheck(startedAt) {
144
+ const generation = this.#generation;
145
+ let result = await traceRoute();
146
+ if (!result.ok && generation === this.#generation) {
147
+ await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
148
+ result = await traceRoute();
149
+ }
150
+ if (generation !== this.#generation || !this.#enabled)
151
+ return this.state;
152
+ const checkedAt = Date.now();
153
+ this.#resultStartedAt = startedAt;
154
+ if (!result.ok) {
155
+ this.#apply({
156
+ status: "blocked",
157
+ country: null,
158
+ ip: null,
159
+ reason: `\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u043C\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043E Anthropic: ${result.error}`,
160
+ checkedAt
161
+ });
162
+ } else if (this.#blocked.has(result.country)) {
163
+ this.#apply({
164
+ status: "blocked",
165
+ country: result.country,
166
+ ip: result.ip,
167
+ reason: `\u0417\u0430\u043F\u0440\u043E\u0441\u044B \u043A Anthropic \u0438\u0434\u0443\u0442 \u0438\u0437 ${result.country} \u2014 \u043F\u043E\u0445\u043E\u0436\u0435, VPN \u043D\u0435 \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442`,
168
+ checkedAt
169
+ });
170
+ } else if (this.#allowList && result.ip === null) {
171
+ this.#apply({
172
+ status: "blocked",
173
+ country: result.country,
174
+ ip: null,
175
+ reason: "\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0443\u0437\u043D\u0430\u0442\u044C \u0430\u0434\u0440\u0435\u0441, \u0441 \u043A\u043E\u0442\u043E\u0440\u043E\u0433\u043E \u0438\u0434\u0443\u0442 \u0437\u0430\u043F\u0440\u043E\u0441\u044B \u043A Anthropic, \u2014 \u0441\u0432\u0435\u0440\u0438\u0442\u044C \u0435\u0433\u043E \u0441 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043D\u043D\u044B\u043C\u0438 \u043D\u0435\u043B\u044C\u0437\u044F",
176
+ checkedAt
177
+ });
178
+ } else if (this.#allowList && result.ip !== null && !ipAllowed(this.#allowList, result.ip)) {
179
+ this.#apply({
180
+ status: "blocked",
181
+ country: result.country,
182
+ ip: result.ip,
183
+ reason: `\u0417\u0430\u043F\u0440\u043E\u0441\u044B \u043A Anthropic \u0438\u0434\u0443\u0442 \u0441 \u0430\u0434\u0440\u0435\u0441\u0430 ${result.ip}, \u0430 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043D\u044B \u0442\u043E\u043B\u044C\u043A\u043E ${this.#allowedIps.join(", ")}`,
184
+ checkedAt
185
+ });
186
+ } else {
187
+ this.#apply({ status: "ok", country: result.country, ip: result.ip, reason: null, checkedAt });
188
+ }
189
+ return this.state;
190
+ }
191
+ #apply(next) {
192
+ const previous = this.#state;
193
+ this.#state = { ...next, enabled: this.#enabled };
194
+ const changed = previous.status !== next.status || previous.country !== next.country || previous.ip !== next.ip || previous.reason !== next.reason || previous.enabled !== this.#enabled;
195
+ if (changed)
196
+ this.emit("change", this.state);
197
+ }
198
+ #startTimers() {
199
+ this.#stopTimers();
200
+ this.#interfaces = interfacesSignature();
201
+ this.#checkTimer = setInterval(() => void this.check(), NETWORK_CHECK_MS);
202
+ this.#checkTimer.unref();
203
+ this.#interfacesTimer = setInterval(() => {
204
+ const signature = interfacesSignature();
205
+ if (signature === this.#interfaces)
206
+ return;
207
+ this.#interfaces = signature;
208
+ void this.check();
209
+ }, INTERFACES_POLL_MS);
210
+ this.#interfacesTimer.unref();
211
+ }
212
+ #stopTimers() {
213
+ if (this.#checkTimer)
214
+ clearInterval(this.#checkTimer);
215
+ if (this.#interfacesTimer)
216
+ clearInterval(this.#interfacesTimer);
217
+ this.#checkTimer = null;
218
+ this.#interfacesTimer = null;
219
+ }
220
+ };
221
+ var networkGuard = new NetworkGuard();
222
+ function normalizeAllowedIp(value) {
223
+ const trimmed = value.trim().toLowerCase();
224
+ const slash = trimmed.indexOf("/");
225
+ const address = slash === -1 ? trimmed : trimmed.slice(0, slash);
226
+ const family = isIP(address);
227
+ if (family === 0)
228
+ return null;
229
+ if (slash === -1)
230
+ return address;
231
+ const prefixText = trimmed.slice(slash + 1);
232
+ if (!/^\d{1,3}$/.test(prefixText))
233
+ return null;
234
+ const prefix = Number(prefixText);
235
+ if (prefix > (family === 4 ? 32 : 128))
236
+ return null;
237
+ return `${address}/${prefix}`;
238
+ }
239
+ function buildAllowList(ips) {
240
+ if (ips.length === 0)
241
+ return null;
242
+ const list = new BlockList();
243
+ for (const entry of ips) {
244
+ const [address = "", prefix] = entry.split("/");
245
+ const type = isIP(address) === 6 ? "ipv6" : "ipv4";
246
+ if (prefix === void 0)
247
+ list.addAddress(address, type);
248
+ else
249
+ list.addSubnet(address, Number(prefix), type);
250
+ }
251
+ return list;
252
+ }
253
+ function ipAllowed(list, ip) {
254
+ const family = isIP(ip);
255
+ if (family === 0)
256
+ return false;
257
+ return list.check(ip, family === 6 ? "ipv6" : "ipv4");
258
+ }
259
+ function traceRoute() {
260
+ return new Promise((resolve) => {
261
+ const req = request(TRACE_URL, { method: "GET", agent: false, timeout: CHECK_TIMEOUT_MS, headers: { "cache-control": "no-store" } }, (res) => {
262
+ let body = "";
263
+ res.setEncoding("utf8");
264
+ res.on("data", (chunk) => {
265
+ body += chunk;
266
+ if (body.length > 16e3)
267
+ req.destroy(new Error("\u0441\u043B\u0438\u0448\u043A\u043E\u043C \u0434\u043B\u0438\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442"));
268
+ });
269
+ res.on("end", () => {
270
+ const country = /^loc=([A-Z]{2})$/m.exec(body)?.[1];
271
+ const ip = /^ip=([0-9a-fA-F:.]+)$/m.exec(body)?.[1]?.toLowerCase() ?? null;
272
+ if (res.statusCode === 200 && country) {
273
+ resolve({ ok: true, country, ip: ip !== null && isIP(ip) !== 0 ? ip : null });
274
+ } else
275
+ resolve({ ok: false, error: `\u043D\u0435\u043E\u0436\u0438\u0434\u0430\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442 (HTTP ${res.statusCode ?? "\u2014"})` });
276
+ });
277
+ res.on("error", (error) => resolve({ ok: false, error: error.message }));
278
+ });
279
+ req.on("timeout", () => req.destroy(new Error("\u043D\u0435\u0442 \u043E\u0442\u0432\u0435\u0442\u0430")));
280
+ req.on("error", (error) => resolve({ ok: false, error: error.message }));
281
+ req.end();
282
+ });
283
+ }
284
+ function interfacesSignature() {
285
+ return Object.entries(networkInterfaces()).map(([name, addresses]) => `${name}:${(addresses ?? []).map((a) => a.address).sort().join(",")}`).sort().join("|");
286
+ }
287
+
288
+ // ../host/dist/egress-proxy.js
289
+ var CONNECTION_FRESH_MS = 1e3;
290
+ var UPSTREAM_CONNECT_TIMEOUT_MS = 15e3;
291
+ var PROXY_VARS = ["https_proxy", "http_proxy", "all_proxy"];
292
+ var NO_PROXY_VAR = "no_proxy";
293
+ var NO_PROXY = "localhost,127.0.0.1,::1";
294
+ var EgressProxy = class extends EventEmitter2 {
295
+ #server = null;
296
+ #port = null;
297
+ /** Все сокеты, открытые через прокси, — с обеих сторон. */
298
+ #sockets = /* @__PURE__ */ new Set();
299
+ /** Порт прокси; `null` — не запущен. */
300
+ get port() {
301
+ return this.#port;
302
+ }
303
+ /** Сколько соединений сейчас открыто через прокси (для проверок). */
304
+ get openSockets() {
305
+ return this.#sockets.size;
306
+ }
307
+ async start() {
308
+ if (this.#server)
309
+ return;
310
+ const server2 = createServer((req, res) => void this.#onRequest(req, res));
311
+ server2.on("connect", (req, socket, head) => {
312
+ void this.#onConnect(req, socket, head);
313
+ });
314
+ server2.on("clientError", (_error, socket) => socket.destroy());
315
+ await new Promise((resolve, reject) => {
316
+ server2.once("error", reject);
317
+ server2.listen(0, "127.0.0.1", () => {
318
+ server2.off("error", reject);
319
+ resolve();
320
+ });
321
+ });
322
+ server2.unref();
323
+ this.#server = server2;
324
+ this.#port = server2.address().port;
325
+ networkGuard.on("change", this.#onGuardChange);
326
+ }
327
+ stop() {
328
+ networkGuard.off("change", this.#onGuardChange);
329
+ this.closeAll();
330
+ this.#server?.close();
331
+ this.#server = null;
332
+ this.#port = null;
333
+ }
334
+ /** Оборвать все соединения, открытые через прокси. */
335
+ closeAll() {
336
+ for (const socket of this.#sockets)
337
+ socket.destroy();
338
+ this.#sockets.clear();
339
+ }
340
+ /**
341
+ * Окружение процесса агента: `base` плюс переменные прокси.
342
+ *
343
+ * Защита выключена — `base` как есть. Свой прокси у пользователя уже задан —
344
+ * тоже как есть: цепочку прокси не строим, проверка тогда только на
345
+ * отправку. Защита включена, а прокси не поднят — отказ: агент без проверки
346
+ * в сеть не идёт.
347
+ */
348
+ agentEnv(base = process.env) {
349
+ if (!networkGuard.state.enabled)
350
+ return base;
351
+ const keys = Object.keys(base);
352
+ const userProxy = keys.some((k) => PROXY_VARS.includes(k.toLowerCase()) && base[k]?.trim());
353
+ if (userProxy)
354
+ return base;
355
+ if (this.#port === null) {
356
+ throw new Error("\u041B\u043E\u043A\u0430\u043B\u044C\u043D\u044B\u0439 \u043F\u0440\u043E\u043A\u0441\u0438 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u043C\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u043D\u0435 \u0437\u0430\u043F\u0443\u0449\u0435\u043D \u2014 \u0430\u0433\u0435\u043D\u0442 \u043D\u0435 \u0437\u0430\u043F\u0443\u0449\u0435\u043D");
357
+ }
358
+ const env = {};
359
+ for (const key of keys) {
360
+ const lower = key.toLowerCase();
361
+ if (PROXY_VARS.includes(lower) || lower === NO_PROXY_VAR)
362
+ continue;
363
+ env[key] = base[key];
364
+ }
365
+ const url2 = `http://127.0.0.1:${this.#port}`;
366
+ env.HTTPS_PROXY = url2;
367
+ env.HTTP_PROXY = url2;
368
+ env.NO_PROXY = NO_PROXY;
369
+ if (process.platform !== "win32") {
370
+ env.https_proxy = url2;
371
+ env.http_proxy = url2;
372
+ env.no_proxy = NO_PROXY;
373
+ }
374
+ return env;
375
+ }
376
+ #onGuardChange = (state) => {
377
+ if (state.status === "blocked")
378
+ this.closeAll();
379
+ };
380
+ #decided(host2, port2, reason) {
381
+ const decision = { host: host2, port: port2, allowed: reason === null, reason };
382
+ this.emit("connection", decision);
383
+ }
384
+ #track(socket) {
385
+ this.#sockets.add(socket);
386
+ socket.once("close", () => this.#sockets.delete(socket));
387
+ }
388
+ /** Почему соединение нельзя открыть; `null` — можно. */
389
+ async #refusal(arrivedAt) {
390
+ if (!networkGuard.state.enabled)
391
+ return null;
392
+ const state = await networkGuard.checkSince(arrivedAt - CONNECTION_FRESH_MS);
393
+ if (!state.enabled)
394
+ return null;
395
+ return state.status === "ok" ? null : networkGuard.blockedReason() ?? "\u041C\u0430\u0440\u0448\u0440\u0443\u0442 \u043D\u0435 \u043F\u0440\u043E\u0448\u0451\u043B \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0443";
396
+ }
397
+ /** HTTPS: туннель `CONNECT host:port`. */
398
+ async #onConnect(req, client, head) {
399
+ const arrivedAt = Date.now();
400
+ this.#track(client);
401
+ client.on("error", () => client.destroy());
402
+ const target = parseAuthority(req.url ?? "");
403
+ if (!target) {
404
+ client.end(statusLine(400, "Bad Request", "\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0430\u0434\u0440\u0435\u0441 CONNECT"));
405
+ return;
406
+ }
407
+ const refusal = await this.#refusal(arrivedAt);
408
+ this.#decided(target.host, target.port, refusal);
409
+ if (client.destroyed)
410
+ return;
411
+ if (refusal) {
412
+ client.end(statusLine(403, "Forbidden", refusal));
413
+ return;
414
+ }
415
+ const upstream = connect({ host: target.host, port: target.port });
416
+ this.#track(upstream);
417
+ upstream.setTimeout(UPSTREAM_CONNECT_TIMEOUT_MS, () => upstream.destroy(new Error("timeout")));
418
+ upstream.once("connect", () => {
419
+ upstream.setTimeout(0);
420
+ if (networkGuard.blockedReason() || client.destroyed) {
421
+ upstream.destroy();
422
+ client.destroy();
423
+ return;
424
+ }
425
+ client.write("HTTP/1.1 200 Connection Established\r\n\r\n");
426
+ if (head.length > 0)
427
+ upstream.write(head);
428
+ upstream.pipe(client);
429
+ client.pipe(upstream);
430
+ });
431
+ upstream.on("error", () => {
432
+ if (!client.destroyed && client.writable && upstream.connecting) {
433
+ client.end(statusLine(502, "Bad Gateway", "\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0441\u043E\u0435\u0434\u0438\u043D\u0438\u0442\u044C\u0441\u044F \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043E\u043C"));
434
+ } else {
435
+ client.destroy();
436
+ }
437
+ });
438
+ upstream.on("close", () => client.destroy());
439
+ client.on("close", () => upstream.destroy());
440
+ }
441
+ /** Обычный HTTP: запрос с абсолютным адресом (`GET http://host/path`). */
442
+ async #onRequest(req, res) {
443
+ const arrivedAt = Date.now();
444
+ this.#track(req.socket);
445
+ let url2;
446
+ try {
447
+ url2 = new URL(req.url ?? "");
448
+ if (url2.protocol !== "http:")
449
+ throw new Error("not http");
450
+ } catch {
451
+ res.writeHead(400, { "content-type": "text/plain; charset=utf-8" }).end("\u041F\u0440\u043E\u043A\u0441\u0438 \u043F\u0440\u0438\u043D\u0438\u043C\u0430\u0435\u0442 \u0442\u043E\u043B\u044C\u043A\u043E CONNECT \u0438 http://");
452
+ return;
453
+ }
454
+ const refusal = await this.#refusal(arrivedAt);
455
+ this.#decided(url2.hostname, Number(url2.port || 80), refusal);
456
+ if (req.socket.destroyed)
457
+ return;
458
+ if (refusal) {
459
+ res.writeHead(403, { "content-type": "text/plain; charset=utf-8", connection: "close" }).end(refusal);
460
+ return;
461
+ }
462
+ const headers = { ...req.headers };
463
+ delete headers["proxy-authorization"];
464
+ delete headers["proxy-connection"];
465
+ const upstream = httpRequest(url2, { method: req.method, headers, agent: false }, (reply) => {
466
+ res.writeHead(reply.statusCode ?? 502, reply.headers);
467
+ reply.pipe(res);
468
+ });
469
+ upstream.on("socket", (socket) => this.#track(socket));
470
+ upstream.on("error", () => {
471
+ if (!res.headersSent)
472
+ res.writeHead(502).end();
473
+ else
474
+ res.destroy();
475
+ });
476
+ req.pipe(upstream);
477
+ res.on("close", () => upstream.destroy());
478
+ }
479
+ };
480
+ var egressProxy = new EgressProxy();
481
+ function agentEnv(base) {
482
+ return egressProxy.agentEnv(base);
483
+ }
484
+ function statusLine(code, text, body) {
485
+ const bytes = Buffer.byteLength(body);
486
+ return `HTTP/1.1 ${code} ${text}\r
487
+ Content-Type: text/plain; charset=utf-8\r
488
+ Content-Length: ${bytes}\r
489
+ Connection: close\r
490
+ \r
491
+ ` + body;
492
+ }
493
+ function parseAuthority(authority2) {
494
+ const match = /^(?:\[([0-9a-fA-F:.]+)\]|([^:\s/]+)):(\d{1,5})$/.exec(authority2);
495
+ if (!match)
496
+ return null;
497
+ const port2 = Number(match[3]);
498
+ if (port2 < 1 || port2 > 65535)
499
+ return null;
500
+ return { host: match[1] ?? match[2] ?? "", port: port2 };
501
+ }
502
+
503
+ // ../host/dist/claude-cli.js
16
504
  var SDK_SCRIPT_EXT = [".js", ".mjs", ".ts", ".tsx", ".jsx"];
17
505
  var BARE = { file: "claude", prefix: [] };
18
506
  var DIRECT_EXT = /* @__PURE__ */ new Set([".exe", ".com"]);
@@ -64,7 +552,8 @@ async function runClaude(args, options2) {
64
552
  timeout: options2.timeout,
65
553
  maxBuffer: options2.maxBuffer ?? 1024 * 1024,
66
554
  windowsHide: true,
67
- ...options2.env ? { env: options2.env } : {}
555
+ // Через прокси проверки маршрута: вход, плагины — тоже запросы в сеть.
556
+ env: agentEnv(options2.env ?? process.env)
68
557
  }, (error, stdout, stderr) => {
69
558
  if (!error)
70
559
  return resolve(stdout.trim());
@@ -78,7 +567,7 @@ async function runClaude(args, options2) {
78
567
  }
79
568
  async function spawnClaude(args, env) {
80
569
  const { file, prefix } = await claudeLauncher();
81
- return spawn(file, [...prefix, ...args], { windowsHide: true, ...env ? { env } : {} });
570
+ return spawn(file, [...prefix, ...args], { windowsHide: true, env: agentEnv(env ?? process.env) });
82
571
  }
83
572
  async function locate() {
84
573
  for (const dir of searchDirs()) {
@@ -145,7 +634,7 @@ function envDefaults() {
145
634
  }
146
635
 
147
636
  // ../host/dist/server.js
148
- import { createServer as createServer3 } from "node:http";
637
+ import { createServer as createServer4 } from "node:http";
149
638
  import { createReadStream as createReadStream2, existsSync as existsSync5, statSync as statSync3 } from "node:fs";
150
639
  import path34 from "node:path";
151
640
  import { homedir as homedir8 } from "node:os";
@@ -497,8 +986,7 @@ async function probeUsage(configDir) {
497
986
  if (executable.executable)
498
987
  options2.executable = executable.executable;
499
988
  }
500
- if (configDir)
501
- options2.env = accountEnv(configDir);
989
+ options2.env = agentEnv(accountEnv(configDir));
502
990
  const q = query({ prompt: inbox, options: options2 });
503
991
  let timer;
504
992
  try {
@@ -822,7 +1310,7 @@ function workspaceIdRemap(paths, sessionsOf) {
822
1310
  }
823
1311
 
824
1312
  // ../host/dist/session.js
825
- import { EventEmitter as EventEmitter2 } from "node:events";
1313
+ import { EventEmitter as EventEmitter3 } from "node:events";
826
1314
  import { randomUUID as randomUUID3 } from "node:crypto";
827
1315
  import path10 from "node:path";
828
1316
  import { query as query2, renameSession } from "@anthropic-ai/claude-agent-sdk";
@@ -1506,173 +1994,6 @@ var Journal = class {
1506
1994
  }
1507
1995
  };
1508
1996
 
1509
- // ../host/dist/network-guard.js
1510
- import { EventEmitter } from "node:events";
1511
- import { request } from "node:https";
1512
- import { networkInterfaces } from "node:os";
1513
- var TRACE_URL = "https://api.anthropic.com/cdn-cgi/trace";
1514
- var NETWORK_CHECK_MS = 5e3;
1515
- var INTERFACES_POLL_MS = 1e3;
1516
- var CHECK_TIMEOUT_MS = 4e3;
1517
- var RETRY_DELAY_MS = 1e3;
1518
- var NETWORK_FRESH_MS = 3e3;
1519
- 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";
1520
- var NetworkGuard = class extends EventEmitter {
1521
- #enabled = false;
1522
- #blocked = /* @__PURE__ */ new Set();
1523
- #state = {
1524
- status: "ok",
1525
- country: null,
1526
- reason: null,
1527
- checkedAt: null,
1528
- enabled: false
1529
- };
1530
- #checkTimer = null;
1531
- #interfacesTimer = null;
1532
- #interfaces = "";
1533
- #inFlight = null;
1534
- /** Растёт при каждой смене настроек: ответ проверки, начатой до неё, не применяется. */
1535
- #generation = 0;
1536
- get state() {
1537
- return { ...this.#state };
1538
- }
1539
- /** Почему агентам сейчас нельзя в сеть; `null` — можно. */
1540
- blockedReason() {
1541
- return this.#state.status === "blocked" ? this.#state.reason ?? UNCHECKED_REASON : null;
1542
- }
1543
- /**
1544
- * Применить настройки. Включение начинает с блока до первой проверки,
1545
- * выключение снимает блок сразу.
1546
- */
1547
- configure(enabled, blockedCountries) {
1548
- const countries = new Set(blockedCountries);
1549
- const same = enabled === this.#enabled && countries.size === this.#blocked.size && [...countries].every((c) => this.#blocked.has(c));
1550
- if (same)
1551
- return;
1552
- this.#generation += 1;
1553
- this.#blocked = countries;
1554
- const wasEnabled = this.#enabled;
1555
- this.#enabled = enabled;
1556
- if (!enabled) {
1557
- this.#stopTimers();
1558
- this.#apply({ status: "ok", country: this.#state.country, reason: null, checkedAt: null });
1559
- return;
1560
- }
1561
- if (!wasEnabled) {
1562
- this.#apply({ status: "blocked", country: null, reason: UNCHECKED_REASON, checkedAt: null });
1563
- this.#startTimers();
1564
- }
1565
- void this.check();
1566
- }
1567
- stop() {
1568
- this.#stopTimers();
1569
- }
1570
- /** Проверить сейчас. Параллельные вызовы делят одну проверку. */
1571
- check() {
1572
- if (!this.#enabled)
1573
- return Promise.resolve(this.state);
1574
- this.#inFlight ??= this.#runCheck().finally(() => {
1575
- this.#inFlight = null;
1576
- });
1577
- return this.#inFlight;
1578
- }
1579
- /** Проверить, если последняя проверка старше `NETWORK_FRESH_MS`. */
1580
- async ensureFresh() {
1581
- if (!this.#enabled)
1582
- return this.state;
1583
- const at = this.#state.checkedAt;
1584
- if (at !== null && Date.now() - at < NETWORK_FRESH_MS && !this.#inFlight)
1585
- return this.state;
1586
- return this.check();
1587
- }
1588
- async #runCheck() {
1589
- const generation = this.#generation;
1590
- let result = await traceCountry();
1591
- if (!result.ok && generation === this.#generation) {
1592
- await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
1593
- result = await traceCountry();
1594
- }
1595
- if (generation !== this.#generation || !this.#enabled)
1596
- return this.state;
1597
- const checkedAt = Date.now();
1598
- if (!result.ok) {
1599
- this.#apply({
1600
- status: "blocked",
1601
- country: null,
1602
- reason: `\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u0438\u0442\u044C \u043C\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043E Anthropic: ${result.error}`,
1603
- checkedAt
1604
- });
1605
- } else if (this.#blocked.has(result.country)) {
1606
- this.#apply({
1607
- status: "blocked",
1608
- country: result.country,
1609
- reason: `\u0417\u0430\u043F\u0440\u043E\u0441\u044B \u043A Anthropic \u0438\u0434\u0443\u0442 \u0438\u0437 ${result.country} \u2014 \u043F\u043E\u0445\u043E\u0436\u0435, VPN \u043D\u0435 \u0440\u0430\u0431\u043E\u0442\u0430\u0435\u0442`,
1610
- checkedAt
1611
- });
1612
- } else {
1613
- this.#apply({ status: "ok", country: result.country, reason: null, checkedAt });
1614
- }
1615
- return this.state;
1616
- }
1617
- #apply(next) {
1618
- const previous = this.#state;
1619
- this.#state = { ...next, enabled: this.#enabled };
1620
- const changed = previous.status !== next.status || previous.country !== next.country || previous.reason !== next.reason || previous.enabled !== this.#enabled;
1621
- if (changed)
1622
- this.emit("change", this.state);
1623
- }
1624
- #startTimers() {
1625
- this.#stopTimers();
1626
- this.#interfaces = interfacesSignature();
1627
- this.#checkTimer = setInterval(() => void this.check(), NETWORK_CHECK_MS);
1628
- this.#checkTimer.unref();
1629
- this.#interfacesTimer = setInterval(() => {
1630
- const signature = interfacesSignature();
1631
- if (signature === this.#interfaces)
1632
- return;
1633
- this.#interfaces = signature;
1634
- void this.check();
1635
- }, INTERFACES_POLL_MS);
1636
- this.#interfacesTimer.unref();
1637
- }
1638
- #stopTimers() {
1639
- if (this.#checkTimer)
1640
- clearInterval(this.#checkTimer);
1641
- if (this.#interfacesTimer)
1642
- clearInterval(this.#interfacesTimer);
1643
- this.#checkTimer = null;
1644
- this.#interfacesTimer = null;
1645
- }
1646
- };
1647
- var networkGuard = new NetworkGuard();
1648
- function traceCountry() {
1649
- return new Promise((resolve) => {
1650
- const req = request(TRACE_URL, { method: "GET", agent: false, timeout: CHECK_TIMEOUT_MS, headers: { "cache-control": "no-store" } }, (res) => {
1651
- let body = "";
1652
- res.setEncoding("utf8");
1653
- res.on("data", (chunk) => {
1654
- body += chunk;
1655
- if (body.length > 16e3)
1656
- req.destroy(new Error("\u0441\u043B\u0438\u0448\u043A\u043E\u043C \u0434\u043B\u0438\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442"));
1657
- });
1658
- res.on("end", () => {
1659
- const country = /^loc=([A-Z]{2})$/m.exec(body)?.[1];
1660
- if (res.statusCode === 200 && country)
1661
- resolve({ ok: true, country });
1662
- else
1663
- resolve({ ok: false, error: `\u043D\u0435\u043E\u0436\u0438\u0434\u0430\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442 (HTTP ${res.statusCode ?? "\u2014"})` });
1664
- });
1665
- res.on("error", (error) => resolve({ ok: false, error: error.message }));
1666
- });
1667
- req.on("timeout", () => req.destroy(new Error("\u043D\u0435\u0442 \u043E\u0442\u0432\u0435\u0442\u0430")));
1668
- req.on("error", (error) => resolve({ ok: false, error: error.message }));
1669
- req.end();
1670
- });
1671
- }
1672
- function interfacesSignature() {
1673
- return Object.entries(networkInterfaces()).map(([name, addresses]) => `${name}:${(addresses ?? []).map((a) => a.address).sort().join(",")}`).sort().join("|");
1674
- }
1675
-
1676
1997
  // ../host/dist/settings.js
1677
1998
  import { readFile as readFile4 } from "node:fs/promises";
1678
1999
  import { homedir as homedir3 } from "node:os";
@@ -2285,7 +2606,7 @@ var INTERRUPT_SETTLE_MS = 15e3;
2285
2606
  var TASK_STOP_TIMEOUT_MS = 5e3;
2286
2607
  var TASK_WAKE_MS = 5e3;
2287
2608
  var CONTEXT_MIN_INTERVAL_MS = 5e3;
2288
- var ClaudeSession = class extends EventEmitter2 {
2609
+ var ClaudeSession = class extends EventEmitter3 {
2289
2610
  id;
2290
2611
  workspaceId;
2291
2612
  cwd;
@@ -2680,8 +3001,7 @@ var ClaudeSession = class extends EventEmitter2 {
2680
3001
  if (this.#executable.executable)
2681
3002
  options2.executable = this.#executable.executable;
2682
3003
  }
2683
- if (this.#options.configDir)
2684
- options2.env = accountEnv(this.#options.configDir);
3004
+ options2.env = agentEnv(accountEnv(this.#options.configDir ?? null));
2685
3005
  if (this.#model)
2686
3006
  options2.model = this.#model;
2687
3007
  if (resumeAt !== null) {
@@ -4313,7 +4633,7 @@ function contentToText2(content) {
4313
4633
  }
4314
4634
 
4315
4635
  // ../host/dist/antigravity-session.js
4316
- import { EventEmitter as EventEmitter3 } from "node:events";
4636
+ import { EventEmitter as EventEmitter4 } from "node:events";
4317
4637
  import { spawn as spawn2, execFile as execFile3 } from "node:child_process";
4318
4638
  import { randomUUID as randomUUID4 } from "node:crypto";
4319
4639
  import { mkdir as mkdir3, writeFile as writeFile3 } from "node:fs/promises";
@@ -4353,7 +4673,7 @@ function agyModels(file) {
4353
4673
  if (modelsCache)
4354
4674
  return modelsCache;
4355
4675
  const pending = new Promise((resolve) => {
4356
- execFile2(file, ["models"], { timeout: 3e4, windowsHide: true }, (error, stdout) => {
4676
+ execFile2(file, ["models"], { timeout: 3e4, windowsHide: true, env: agentEnv() }, (error, stdout) => {
4357
4677
  if (error) {
4358
4678
  resolve([]);
4359
4679
  return;
@@ -4391,7 +4711,7 @@ function agyCommand(file, command, cwd) {
4391
4711
  timeout: 6e4,
4392
4712
  windowsHide: true,
4393
4713
  maxBuffer: 8 * 1024 * 1024,
4394
- env: { ...process.env, NO_COLOR: "1" }
4714
+ env: agentEnv({ ...process.env, NO_COLOR: "1" })
4395
4715
  }, (error, stdout) => {
4396
4716
  const line = stdout.split(/\r?\n/).map((l) => l.trim()).filter((l) => l.startsWith("{")).pop();
4397
4717
  if (line) {
@@ -4533,7 +4853,7 @@ function agyContextWindow(model) {
4533
4853
 
4534
4854
  // ../host/dist/antigravity-session.js
4535
4855
  var TRANSIENT = /* @__PURE__ */ new Set(["assistant.delta", "thinking.delta", "state"]);
4536
- var AntigravitySession = class extends EventEmitter3 {
4856
+ var AntigravitySession = class extends EventEmitter4 {
4537
4857
  id;
4538
4858
  workspaceId;
4539
4859
  cwd;
@@ -4741,7 +5061,8 @@ var AntigravitySession = class extends EventEmitter3 {
4741
5061
  child = spawn2(this.#executable, this.#args(), {
4742
5062
  cwd: this.cwd,
4743
5063
  windowsHide: true,
4744
- env: { ...process.env, NO_COLOR: "1" }
5064
+ // Через прокси проверки маршрута (egress-proxy.ts).
5065
+ env: agentEnv({ ...process.env, NO_COLOR: "1" })
4745
5066
  });
4746
5067
  } catch (error) {
4747
5068
  this.#record_({ kind: "error", message: `\u041D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0437\u0430\u043F\u0443\u0441\u0442\u0438\u0442\u044C agy: ${describe2(error)}` });
@@ -5533,14 +5854,14 @@ var AntigravityStore = class {
5533
5854
  };
5534
5855
 
5535
5856
  // ../host/dist/codex-session.js
5536
- import { EventEmitter as EventEmitter5 } from "node:events";
5857
+ import { EventEmitter as EventEmitter6 } from "node:events";
5537
5858
  import { randomUUID as randomUUID5 } from "node:crypto";
5538
5859
  import { mkdir as mkdir5, writeFile as writeFile5 } from "node:fs/promises";
5539
5860
  import { tmpdir as tmpdir3 } from "node:os";
5540
5861
  import path15 from "node:path";
5541
5862
 
5542
5863
  // ../host/dist/codex-cli.js
5543
- import { EventEmitter as EventEmitter4 } from "node:events";
5864
+ import { EventEmitter as EventEmitter5 } from "node:events";
5544
5865
  import { spawn as spawn3, execFile as execFile4 } from "node:child_process";
5545
5866
  import { existsSync as existsSync2, readdirSync } from "node:fs";
5546
5867
  import { homedir as homedir5 } from "node:os";
@@ -5605,7 +5926,7 @@ var CodexRpcError = class extends Error {
5605
5926
  this.code = error.code;
5606
5927
  }
5607
5928
  };
5608
- var CodexRpc = class extends EventEmitter4 {
5929
+ var CodexRpc = class extends EventEmitter5 {
5609
5930
  #child;
5610
5931
  #nextId = 1;
5611
5932
  #pending = /* @__PURE__ */ new Map();
@@ -5616,7 +5937,8 @@ var CodexRpc = class extends EventEmitter4 {
5616
5937
  this.#child = spawn3(executable, ["app-server"], {
5617
5938
  cwd,
5618
5939
  windowsHide: true,
5619
- env: { ...process.env, NO_COLOR: "1", RUST_LOG: process.env.RUST_LOG ?? "error" }
5940
+ // Через прокси проверки маршрута (egress-proxy.ts).
5941
+ env: agentEnv({ ...process.env, NO_COLOR: "1", RUST_LOG: process.env.RUST_LOG ?? "error" })
5620
5942
  });
5621
5943
  const lines = createInterface3({ input: this.#child.stdout });
5622
5944
  lines.on("line", (line) => this.#onLine(line));
@@ -5787,7 +6109,7 @@ var LOCAL_COMMANDS = [
5787
6109
  ];
5788
6110
  var LOCAL_NAMES = new Set(LOCAL_COMMANDS.flatMap((c) => [c.name, ...c.aliases]));
5789
6111
  var TRANSIENT2 = /* @__PURE__ */ new Set(["assistant.delta", "thinking.delta", "state"]);
5790
- var CodexSession = class extends EventEmitter5 {
6112
+ var CodexSession = class extends EventEmitter6 {
5791
6113
  id;
5792
6114
  workspaceId;
5793
6115
  cwd;
@@ -8591,7 +8913,7 @@ function isUnder(parent, child) {
8591
8913
  }
8592
8914
 
8593
8915
  // ../host/dist/site-proxy.js
8594
- import { createServer, request as httpRequest } from "node:http";
8916
+ import { createServer as createServer2, request as httpRequest2 } from "node:http";
8595
8917
  import { request as httpsRequest } from "node:https";
8596
8918
  import { connect as netConnect } from "node:net";
8597
8919
  import { connect as tlsConnect } from "node:tls";
@@ -8843,7 +9165,7 @@ var OriginProxy = class {
8843
9165
  constructor(origin) {
8844
9166
  this.origin = origin;
8845
9167
  this.#target = new URL(origin);
8846
- this.#server = createServer((req, res) => this.#handle(req, res));
9168
+ this.#server = createServer2((req, res) => this.#handle(req, res));
8847
9169
  this.#server.on("upgrade", (req, socket, head) => this.#upgrade(req, socket, head));
8848
9170
  this.#server.on("clientError", (_error, socket) => socket.destroy());
8849
9171
  }
@@ -8889,7 +9211,7 @@ var OriginProxy = class {
8889
9211
  res.end(ANNOTATE_SCRIPT);
8890
9212
  return;
8891
9213
  }
8892
- const send = this.#target.protocol === "https:" ? httpsRequest : httpRequest;
9214
+ const send = this.#target.protocol === "https:" ? httpsRequest : httpRequest2;
8893
9215
  const upstream = send({
8894
9216
  protocol: this.#target.protocol,
8895
9217
  hostname: this.#target.hostname,
@@ -9097,7 +9419,7 @@ var SiteProxies = class {
9097
9419
  // ../host/dist/video-studio.js
9098
9420
  import { execFile as execFile7, spawn as spawn4 } from "node:child_process";
9099
9421
  import { readdir as readdir7, readFile as readFile12, stat as stat6 } from "node:fs/promises";
9100
- import { createServer as createServer2 } from "node:net";
9422
+ import { createServer as createServer3 } from "node:net";
9101
9423
  import path22 from "node:path";
9102
9424
  var VIDEO_EXT = /* @__PURE__ */ new Set([".mp4", ".webm", ".mov", ".m4v", ".mkv", ".ogv", ".gif"]);
9103
9425
  var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "_deps", "vendor", "third_party", ".git", ".next", ".nuxt", ".cache", ".turbo", ".venv", "__pycache__"]);
@@ -9200,7 +9522,7 @@ async function scanVideoCatalog(root) {
9200
9522
  }
9201
9523
  function freePort() {
9202
9524
  return new Promise((resolve, reject) => {
9203
- const server2 = createServer2();
9525
+ const server2 = createServer3();
9204
9526
  server2.once("error", reject);
9205
9527
  server2.listen(0, "127.0.0.1", () => {
9206
9528
  const { port: port2 } = server2.address();
@@ -10161,7 +10483,9 @@ var DEFAULT_APP_SETTINGS = {
10161
10483
  // Включено: запрос без VPN может стоить аккаунта, а тому, у кого маршрут и
10162
10484
  // так из разрешённой страны, защита ничем не мешает.
10163
10485
  networkGuardEnabled: true,
10164
- networkGuardBlockedCountries: DEFAULT_BLOCKED_COUNTRIES
10486
+ networkGuardBlockedCountries: DEFAULT_BLOCKED_COUNTRIES,
10487
+ // Пусто: адрес не закреплён, пока пользователь сам его не укажет.
10488
+ networkGuardAllowedIps: []
10165
10489
  };
10166
10490
  var AppSettingsStore = class {
10167
10491
  #settings = { ...DEFAULT_APP_SETTINGS };
@@ -10263,6 +10587,12 @@ function sanitize2(value, fallback) {
10263
10587
  ...new Set(countries.filter((c) => typeof c === "string").map((c) => c.trim().toUpperCase()).filter((c) => /^[A-Z]{2}$/.test(c)))
10264
10588
  ];
10265
10589
  }
10590
+ const ips = record.networkGuardAllowedIps;
10591
+ if (Array.isArray(ips)) {
10592
+ result.networkGuardAllowedIps = [
10593
+ ...new Set(ips.filter((ip) => typeof ip === "string").map(normalizeAllowedIp).filter((ip) => ip !== null))
10594
+ ];
10595
+ }
10266
10596
  return result;
10267
10597
  }
10268
10598
  function claudeHome() {
@@ -10285,9 +10615,9 @@ function writableRoots(mode, cwd, workspacePaths) {
10285
10615
 
10286
10616
  // ../host/dist/prompt-queue.js
10287
10617
  import { randomUUID as randomUUID8 } from "node:crypto";
10288
- import { EventEmitter as EventEmitter6 } from "node:events";
10618
+ import { EventEmitter as EventEmitter7 } from "node:events";
10289
10619
  var EMPTY = { items: [], paused: false };
10290
- var PromptQueues = class extends EventEmitter6 {
10620
+ var PromptQueues = class extends EventEmitter7 {
10291
10621
  #queues = /* @__PURE__ */ new Map();
10292
10622
  /** Вид очереди для окон — без байтов вложений. */
10293
10623
  view(sessionId) {
@@ -10742,7 +11072,7 @@ function authorName(raw) {
10742
11072
  }
10743
11073
 
10744
11074
  // ../host/dist/auth.js
10745
- import { EventEmitter as EventEmitter7 } from "node:events";
11075
+ import { EventEmitter as EventEmitter8 } from "node:events";
10746
11076
  var QUICK_TIMEOUT_MS = 3e4;
10747
11077
  var LOGIN_TIMEOUT_MS = 10 * 6e4;
10748
11078
  var URL_RE = /https:\/\/\S*\/oauth\/authorize\S*/;
@@ -10754,7 +11084,7 @@ var IDLE = {
10754
11084
  output: "",
10755
11085
  error: null
10756
11086
  };
10757
- var AuthCli = class extends EventEmitter7 {
11087
+ var AuthCli = class extends EventEmitter8 {
10758
11088
  configDir;
10759
11089
  #child = null;
10760
11090
  #state = IDLE;
@@ -10950,7 +11280,7 @@ function describe6(error) {
10950
11280
  }
10951
11281
 
10952
11282
  // ../host/dist/relay-link.js
10953
- import { EventEmitter as EventEmitter8 } from "node:events";
11283
+ import { EventEmitter as EventEmitter9 } from "node:events";
10954
11284
  import { readFile as readFile20, writeFile as writeFile17, rm as rm6, mkdir as mkdir16 } from "node:fs/promises";
10955
11285
  import path30 from "node:path";
10956
11286
  import { hostname } from "node:os";
@@ -10969,7 +11299,7 @@ var SILENCE_TIMEOUT_MS = 95e3;
10969
11299
  function jitter(delay2) {
10970
11300
  return Math.round(delay2 * (0.8 + Math.random() * 0.4));
10971
11301
  }
10972
- var RelayLink = class extends EventEmitter8 {
11302
+ var RelayLink = class extends EventEmitter9 {
10973
11303
  #credentials = null;
10974
11304
  #socket = null;
10975
11305
  #retry = RETRY_MIN_MS;
@@ -11357,14 +11687,14 @@ function humanize(error) {
11357
11687
  }
11358
11688
 
11359
11689
  // ../host/dist/terminal.js
11360
- import { EventEmitter as EventEmitter9 } from "node:events";
11690
+ import { EventEmitter as EventEmitter10 } from "node:events";
11361
11691
  import { access as access2, constants as constants2 } from "node:fs/promises";
11362
11692
  import path31 from "node:path";
11363
11693
  import { randomUUID as randomUUID9 } from "node:crypto";
11364
11694
  var SCROLLBACK_BYTES = 256 * 1024;
11365
11695
  var FLUSH_MS = 12;
11366
11696
  var MAX_TERMINALS = 24;
11367
- var TerminalHub = class extends EventEmitter9 {
11697
+ var TerminalHub = class extends EventEmitter10 {
11368
11698
  #terminals = /* @__PURE__ */ new Map();
11369
11699
  #module = null;
11370
11700
  list(workspaceId) {
@@ -12091,6 +12421,7 @@ var HostServer = class {
12091
12421
  await this.#carryOverWorkspaceIds();
12092
12422
  await this.#settings.load();
12093
12423
  this.#wireNetworkGuard();
12424
+ await egressProxy.start();
12094
12425
  await this.#accounts.load();
12095
12426
  await this.#limitStop.load();
12096
12427
  await this.#scheduler.load();
@@ -12098,7 +12429,7 @@ var HostServer = class {
12098
12429
  await this.#github.load();
12099
12430
  await warmClaudeLauncher();
12100
12431
  void this.#finder.warm();
12101
- const httpServer = createServer3((req, res) => this.#serveHttp(req, res));
12432
+ const httpServer = createServer4((req, res) => this.#serveHttp(req, res));
12102
12433
  const wss = new WebSocketServer({ server: httpServer, path: "/ws" });
12103
12434
  wss.on("connection", (socket) => this.#onConnection(socket));
12104
12435
  let listening = false;
@@ -12136,11 +12467,12 @@ var HostServer = class {
12136
12467
  for (const session of this.#sessions.values())
12137
12468
  session.suspend(reason);
12138
12469
  });
12139
- const { networkGuardEnabled, networkGuardBlockedCountries } = this.#settings.current;
12140
- networkGuard.configure(networkGuardEnabled, networkGuardBlockedCountries);
12470
+ const { networkGuardEnabled, networkGuardBlockedCountries, networkGuardAllowedIps } = this.#settings.current;
12471
+ networkGuard.configure(networkGuardEnabled, networkGuardBlockedCountries, networkGuardAllowedIps);
12141
12472
  }
12142
12473
  async shutdown() {
12143
12474
  networkGuard.stop();
12475
+ egressProxy.stop();
12144
12476
  this.#scheduler.stop();
12145
12477
  if (this.#autoStopTimer)
12146
12478
  clearInterval(this.#autoStopTimer);
@@ -12378,7 +12710,7 @@ var HostServer = class {
12378
12710
  return;
12379
12711
  }
12380
12712
  case "workspace.find.agent":
12381
- await networkGuard.ensureFresh();
12713
+ await networkGuard.checkNow();
12382
12714
  this.#findWithAgent(frame.query);
12383
12715
  return;
12384
12716
  case "workspace.roots":
@@ -12412,6 +12744,7 @@ var HostServer = class {
12412
12744
  return;
12413
12745
  }
12414
12746
  case "session.start":
12747
+ await networkGuard.checkNow();
12415
12748
  await this.#startSession(socket, frame);
12416
12749
  return;
12417
12750
  case "session.close":
@@ -12436,6 +12769,7 @@ var HostServer = class {
12436
12769
  case "session.reconnect":
12437
12770
  if (!frame.force)
12438
12771
  this.#refuseDuringMcpAuth(frame.sessionId);
12772
+ await networkGuard.checkNow();
12439
12773
  this.#requireSession(frame.sessionId).reconnect("\u043F\u043E \u043F\u0440\u043E\u0441\u044C\u0431\u0435 \u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u0435\u043B\u044F");
12440
12774
  return;
12441
12775
  case "session.archive": {
@@ -12609,7 +12943,7 @@ var HostServer = class {
12609
12943
  return;
12610
12944
  }
12611
12945
  case "prompt.send":
12612
- await networkGuard.ensureFresh();
12946
+ await networkGuard.checkNow();
12613
12947
  this.#approveAfterLimit(frame.sessionId);
12614
12948
  this.#requireSession(frame.sessionId).sendPrompt(frame.text, frame.images, false, frame.attachments);
12615
12949
  this.#queues.resume(frame.sessionId);
@@ -12617,7 +12951,7 @@ var HostServer = class {
12617
12951
  case "queue.add": {
12618
12952
  const session = this.#requireSession(frame.sessionId);
12619
12953
  if (!BUSY_STATES2.has(session.state) && this.#queues.size(frame.sessionId) === 0) {
12620
- await networkGuard.ensureFresh();
12954
+ await networkGuard.checkNow();
12621
12955
  this.#approveAfterLimit(frame.sessionId);
12622
12956
  session.sendPrompt(frame.text, frame.images, false, frame.attachments);
12623
12957
  return;
@@ -12641,7 +12975,7 @@ var HostServer = class {
12641
12975
  if (!item)
12642
12976
  throw new Error("\u042D\u0442\u043E\u0433\u043E \u043F\u0440\u043E\u043C\u043F\u0442\u0430 \u0432 \u043E\u0447\u0435\u0440\u0435\u0434\u0438 \u0443\u0436\u0435 \u043D\u0435\u0442 \u2014 \u043E\u043D \u043E\u0442\u043F\u0440\u0430\u0432\u043B\u0435\u043D \u0438\u043B\u0438 \u0443\u0434\u0430\u043B\u0451\u043D.");
12643
12977
  try {
12644
- await networkGuard.ensureFresh();
12978
+ await networkGuard.checkNow();
12645
12979
  this.#approveAfterLimit(frame.sessionId);
12646
12980
  session.sendPrompt(item.text, item.images, false, item.attachments);
12647
12981
  } catch (error) {
@@ -12658,7 +12992,7 @@ var HostServer = class {
12658
12992
  case "prompt.edit":
12659
12993
  if (!frame.force)
12660
12994
  this.#refuseDuringMcpAuth(frame.sessionId);
12661
- await networkGuard.ensureFresh();
12995
+ await networkGuard.checkNow();
12662
12996
  this.#approveAfterLimit(frame.sessionId);
12663
12997
  await this.#requireSession(frame.sessionId).editPrompt(frame.userIndex, frame.text, frame.images, frame.attachments, frame.rewindFiles === true);
12664
12998
  return;
@@ -12668,7 +13002,7 @@ var HostServer = class {
12668
13002
  const session = this.#requireSession(frame.sessionId);
12669
13003
  if (!(session instanceof ClaudeSession))
12670
13004
  throw new Error("\u041F\u043E\u0432\u0442\u043E\u0440 \u043E\u0442\u0432\u0435\u0442\u0430 \u0435\u0441\u0442\u044C \u0442\u043E\u043B\u044C\u043A\u043E \u0443 \u0441\u0435\u0441\u0441\u0438\u0439 Claude.");
12671
- await networkGuard.ensureFresh();
13005
+ await networkGuard.checkNow();
12672
13006
  this.#approveAfterLimit(frame.sessionId);
12673
13007
  await session.retryLastPrompt();
12674
13008
  return;
@@ -12708,7 +13042,7 @@ var HostServer = class {
12708
13042
  this.#requireSession(frame.sessionId).respondPermission(frame.requestId, frame.decision, frame.reason, frame.answers, frame.annotations, frame.plan);
12709
13043
  return;
12710
13044
  case "side.ask":
12711
- await networkGuard.ensureFresh();
13045
+ await networkGuard.checkNow();
12712
13046
  this.#ensureSide(this.#requireSession(frame.sessionId)).sendPrompt(frame.text, frame.images, false, frame.attachments);
12713
13047
  return;
12714
13048
  // Поднять форк, ничего не спрашивая: клиенту нужен его id, чтобы
@@ -13272,7 +13606,7 @@ var HostServer = class {
13272
13606
  await this.#sendSessionList(workspace.id);
13273
13607
  }
13274
13608
  }
13275
- networkGuard.configure(settings.networkGuardEnabled, settings.networkGuardBlockedCountries);
13609
+ networkGuard.configure(settings.networkGuardEnabled, settings.networkGuardBlockedCountries, settings.networkGuardAllowedIps);
13276
13610
  if (before.terminalEnabled && !settings.terminalEnabled) {
13277
13611
  for (const terminal of this.#terminals.list()) {
13278
13612
  this.#terminals.close(terminal.id);
@@ -13295,7 +13629,7 @@ var HostServer = class {
13295
13629
  return;
13296
13630
  }
13297
13631
  case "auth.login": {
13298
- const blocked = (await networkGuard.ensureFresh()).status === "blocked";
13632
+ const blocked = (await networkGuard.checkNow()).status === "blocked";
13299
13633
  if (blocked)
13300
13634
  throw new Error(`${networkGuard.blockedReason()}. \u0412\u0445\u043E\u0434 \u043E\u0442\u043B\u043E\u0436\u0435\u043D.`);
13301
13635
  await this.#authFor(frame.accountId).login(frame.mode, frame.switchAccount === true);
@@ -13915,7 +14249,7 @@ var HostServer = class {
13915
14249
  if (!item)
13916
14250
  return;
13917
14251
  try {
13918
- await networkGuard.ensureFresh();
14252
+ await networkGuard.checkNow();
13919
14253
  this.#approveAfterLimit(sessionId);
13920
14254
  session.sendPrompt(item.text, item.images, false, item.attachments);
13921
14255
  } catch (error) {