@dev-anywhere/proxy 0.9.1 → 0.9.2

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 (71) hide show
  1. package/README.md +25 -3
  2. package/dist/autostart-C3RNQ65S.js +292 -0
  3. package/dist/autostart-C3RNQ65S.js.map +1 -0
  4. package/dist/chunk-2YUDGRJ6.js +379 -0
  5. package/dist/chunk-2YUDGRJ6.js.map +1 -0
  6. package/dist/chunk-74HWO753.js +285 -0
  7. package/dist/chunk-74HWO753.js.map +1 -0
  8. package/dist/chunk-77QVUYU7.js +42 -0
  9. package/dist/chunk-77QVUYU7.js.map +1 -0
  10. package/dist/chunk-DAFUSBKJ.js +299 -0
  11. package/dist/chunk-DAFUSBKJ.js.map +1 -0
  12. package/dist/{chunk-HLN3NOD2.js → chunk-GFDOVLGL.js} +70 -1
  13. package/dist/chunk-GFDOVLGL.js.map +1 -0
  14. package/dist/{chunk-SEMZ7GW7.js → chunk-GYL5JKWQ.js} +3 -3
  15. package/dist/{chunk-57LA2LWY.js → chunk-HYDXGNKA.js} +2 -2
  16. package/dist/chunk-ICSO3ZIS.js +658 -0
  17. package/dist/chunk-ICSO3ZIS.js.map +1 -0
  18. package/dist/chunk-JZ7MWN24.js +22 -0
  19. package/dist/chunk-JZ7MWN24.js.map +1 -0
  20. package/dist/chunk-KINQESTO.js +145 -0
  21. package/dist/chunk-KINQESTO.js.map +1 -0
  22. package/dist/{chunk-ZNMJH7BK.js → chunk-KWODOJBK.js} +3 -3
  23. package/dist/chunk-MLE2OKCM.js +116 -0
  24. package/dist/chunk-MLE2OKCM.js.map +1 -0
  25. package/dist/{chunk-UJEZAG57.js → chunk-PCF2R2TG.js} +3 -1
  26. package/dist/{chunk-UJEZAG57.js.map → chunk-PCF2R2TG.js.map} +1 -1
  27. package/dist/{chunk-NTL4CXBA.js → chunk-V4HDLUAQ.js} +27 -42
  28. package/dist/chunk-V4HDLUAQ.js.map +1 -0
  29. package/dist/{chunk-DZ4GXMP5.js → chunk-VHMAUU72.js} +56 -68
  30. package/dist/chunk-VHMAUU72.js.map +1 -0
  31. package/dist/{chunk-OFD4UVPB.js → chunk-XADKKDUV.js} +29 -153
  32. package/dist/chunk-XADKKDUV.js.map +1 -0
  33. package/dist/{chunk-WRU3BXW6.js → chunk-YK2XKOP4.js} +26 -10
  34. package/dist/chunk-YK2XKOP4.js.map +1 -0
  35. package/dist/index.js +130 -343
  36. package/dist/index.js.map +1 -1
  37. package/dist/logger-24TGGN76.js +10 -0
  38. package/dist/logger-24TGGN76.js.map +1 -0
  39. package/dist/logger-B7B64O4P.js +14 -0
  40. package/dist/logger-B7B64O4P.js.map +1 -0
  41. package/dist/{quick-tunnel-RI62V2RH.js → quick-tunnel-ZIFTYUUD.js} +3 -3
  42. package/dist/{relay-token-ZP3PAZD2.js → relay-token-N3BSBURG.js} +5 -5
  43. package/dist/serve.js +1158 -380
  44. package/dist/serve.js.map +1 -1
  45. package/dist/session-worker.js +91 -76
  46. package/dist/session-worker.js.map +1 -1
  47. package/dist/{terminal-BEXDQ5WK.js → terminal-7JY6J3XN.js} +88 -36
  48. package/dist/terminal-7JY6J3XN.js.map +1 -0
  49. package/dist/terminal-worker.js +93 -44
  50. package/dist/terminal-worker.js.map +1 -1
  51. package/dist/update-runner.js +86 -61
  52. package/dist/update-runner.js.map +1 -1
  53. package/package.json +9 -6
  54. package/scripts/postinstall.cjs +22 -0
  55. package/dist/chunk-7SYT65DN.js +0 -155
  56. package/dist/chunk-7SYT65DN.js.map +0 -1
  57. package/dist/chunk-DZ4GXMP5.js.map +0 -1
  58. package/dist/chunk-HLN3NOD2.js.map +0 -1
  59. package/dist/chunk-KGTYU4WO.js +0 -36
  60. package/dist/chunk-KGTYU4WO.js.map +0 -1
  61. package/dist/chunk-NTL4CXBA.js.map +0 -1
  62. package/dist/chunk-OFD4UVPB.js.map +0 -1
  63. package/dist/chunk-WC3KEY7N.js +0 -158
  64. package/dist/chunk-WC3KEY7N.js.map +0 -1
  65. package/dist/chunk-WRU3BXW6.js.map +0 -1
  66. package/dist/terminal-BEXDQ5WK.js.map +0 -1
  67. /package/dist/{chunk-SEMZ7GW7.js.map → chunk-GYL5JKWQ.js.map} +0 -0
  68. /package/dist/{chunk-57LA2LWY.js.map → chunk-HYDXGNKA.js.map} +0 -0
  69. /package/dist/{chunk-ZNMJH7BK.js.map → chunk-KWODOJBK.js.map} +0 -0
  70. /package/dist/{quick-tunnel-RI62V2RH.js.map → quick-tunnel-ZIFTYUUD.js.map} +0 -0
  71. /package/dist/{relay-token-ZP3PAZD2.js.map → relay-token-N3BSBURG.js.map} +0 -0
@@ -3,7 +3,11 @@ import {
3
3
  ControlRequestEventSchema,
4
4
  SeqCounter,
5
5
  createApprovalRequestIdFactory
6
- } from "./chunk-57LA2LWY.js";
6
+ } from "./chunk-HYDXGNKA.js";
7
+ import "./chunk-NQDJ6QAM.js";
8
+ import {
9
+ terminateOwnedProcessTree
10
+ } from "./chunk-JZ7MWN24.js";
7
11
  import {
8
12
  PROXY_VERSION
9
13
  } from "./chunk-EGNWMOPC.js";
@@ -13,27 +17,32 @@ import {
13
17
  KIMI_PROVIDER,
14
18
  resolveCodexPermissionPolicy,
15
19
  resolveKimiAcpMode
16
- } from "./chunk-DZ4GXMP5.js";
20
+ } from "./chunk-VHMAUU72.js";
17
21
  import {
18
22
  ControlErrorCode,
19
23
  LineBuffer,
20
24
  WORKER_IPC_PROTOCOL_VERSION,
21
25
  createWorkerReader,
22
26
  serializeWorkerMsg
23
- } from "./chunk-NTL4CXBA.js";
27
+ } from "./chunk-V4HDLUAQ.js";
28
+ import {
29
+ prepareLocalIpcEndpoint,
30
+ removeLocalIpcEndpoint,
31
+ setLocalIpcEndpointPermissions
32
+ } from "./chunk-77QVUYU7.js";
24
33
  import {
25
34
  classifyCodexActiveWriterError,
26
35
  sanitizeProviderErrorTail
27
36
  } from "./chunk-J5V2TKSV.js";
28
- import "./chunk-NQDJ6QAM.js";
29
- import "./chunk-WRU3BXW6.js";
37
+ import {
38
+ spawnCommand
39
+ } from "./chunk-KINQESTO.js";
40
+ import "./chunk-YK2XKOP4.js";
30
41
 
31
42
  // src/session-worker.ts
32
43
  import { createServer } from "net";
33
- import { mkdirSync, unlinkSync, existsSync, chmodSync } from "fs";
34
44
 
35
45
  // src/worker/json-session.ts
36
- import { spawn } from "child_process";
37
46
  var denyAllStrategy = async () => ({
38
47
  behavior: "deny",
39
48
  message: "Tool use denied by default policy. Remote approval not yet configured."
@@ -97,6 +106,7 @@ var JsonSession = class {
97
106
  const command = CLAUDE_PROVIDER.buildJsonCommand(
98
107
  {
99
108
  extraArgs: this.claudeArgs,
109
+ cwd: this.workDir,
100
110
  permissionMode: this.permissionMode,
101
111
  resumeSessionId,
102
112
  includePartialMessages: this.includePartialMessages,
@@ -104,7 +114,7 @@ var JsonSession = class {
104
114
  },
105
115
  process.env
106
116
  );
107
- this.child = spawn(command.command, command.args, {
117
+ this.child = spawnCommand(command.command, command.args, {
108
118
  cwd: this.workDir,
109
119
  stdio: ["pipe", "pipe", "pipe"],
110
120
  env: command.env
@@ -123,14 +133,14 @@ var JsonSession = class {
123
133
  }
124
134
  async stop(gracePeriodMs = 5e3) {
125
135
  if (!this.child || !this.isAlive()) return;
126
- this.child.kill("SIGTERM");
136
+ terminateOwnedProcessTree(this.child, "SIGTERM");
127
137
  const start = Date.now();
128
138
  while (Date.now() - start < gracePeriodMs) {
129
139
  if (!this.isAlive()) return;
130
140
  await new Promise((r) => setTimeout(r, 200));
131
141
  }
132
142
  if (this.isAlive()) {
133
- this.child.kill("SIGKILL");
143
+ terminateOwnedProcessTree(this.child, "SIGKILL");
134
144
  }
135
145
  }
136
146
  async interruptCurrentTurn(gracePeriodMs = 5e3) {
@@ -143,7 +153,7 @@ var JsonSession = class {
143
153
  const drained = new Promise((resolve) => {
144
154
  this.interruptedExitResolvers.set(child, resolve);
145
155
  });
146
- const signaled = child.kill("SIGINT");
156
+ const signaled = terminateOwnedProcessTree(child, "SIGINT");
147
157
  if (!signaled) {
148
158
  this.interruptedChildren.delete(child);
149
159
  this.interruptedExitResolvers.delete(child);
@@ -155,7 +165,7 @@ var JsonSession = class {
155
165
  await new Promise((r) => setTimeout(r, 100));
156
166
  }
157
167
  if (this.isChildAlive(child)) {
158
- child.kill("SIGKILL");
168
+ terminateOwnedProcessTree(child, "SIGKILL");
159
169
  }
160
170
  await Promise.race([drained, new Promise((resolve) => setTimeout(resolve, 1500))]);
161
171
  if (this.child === child) this.child = null;
@@ -330,7 +340,6 @@ var JsonSession = class {
330
340
  };
331
341
 
332
342
  // src/worker/codex-app-server-session.ts
333
- import { spawn as spawn2 } from "child_process";
334
343
  var CLIENT_INFO = {
335
344
  name: "dev-anywhere",
336
345
  title: "Dev Anywhere",
@@ -400,8 +409,8 @@ var CodexAppServerSession = class {
400
409
  return this.codexThreadId;
401
410
  }
402
411
  start() {
403
- const command = CODEX_PROVIDER.buildJsonCommand({}, process.env);
404
- this.child = spawn2(command.command, command.args, {
412
+ const command = CODEX_PROVIDER.buildJsonCommand({ cwd: this.workDir }, process.env);
413
+ this.child = spawnCommand(command.command, command.args, {
405
414
  cwd: this.workDir,
406
415
  stdio: ["pipe", "pipe", "pipe"],
407
416
  env: command.env
@@ -432,13 +441,13 @@ var CodexAppServerSession = class {
432
441
  }
433
442
  async stop(gracePeriodMs = 5e3) {
434
443
  if (!this.child || !this.isAlive()) return;
435
- this.child.kill("SIGTERM");
444
+ terminateOwnedProcessTree(this.child, "SIGTERM");
436
445
  const start = Date.now();
437
446
  while (Date.now() - start < gracePeriodMs) {
438
447
  if (!this.isAlive()) return;
439
448
  await new Promise((resolve) => setTimeout(resolve, 200));
440
449
  }
441
- if (this.isAlive()) this.child.kill("SIGKILL");
450
+ if (this.isAlive()) terminateOwnedProcessTree(this.child, "SIGKILL");
442
451
  }
443
452
  async interruptCurrentTurn() {
444
453
  if (!this.codexThreadId || !this.activeTurnId) return false;
@@ -682,7 +691,6 @@ function toError(err) {
682
691
  }
683
692
 
684
693
  // src/worker/kimi-acp-session.ts
685
- import { spawn as spawn3 } from "child_process";
686
694
  var CLIENT_INFO2 = {
687
695
  name: "dev-anywhere",
688
696
  title: "Dev Anywhere",
@@ -849,8 +857,8 @@ var KimiAcpSession = class {
849
857
  }
850
858
  start() {
851
859
  if (this.child) throw new Error("Kimi ACP session has already been started");
852
- const command = KIMI_PROVIDER.buildJsonCommand({}, process.env);
853
- this.child = spawn3(command.command, command.args, {
860
+ const command = KIMI_PROVIDER.buildJsonCommand({ cwd: this.workDir }, process.env);
861
+ this.child = spawnCommand(command.command, command.args, {
854
862
  cwd: this.workDir,
855
863
  stdio: ["pipe", "pipe", "pipe"],
856
864
  env: command.env
@@ -911,13 +919,13 @@ var KimiAcpSession = class {
911
919
  `);
912
920
  }
913
921
  }
914
- child.kill("SIGTERM");
922
+ terminateOwnedProcessTree(child, "SIGTERM");
915
923
  const startedAt = Date.now();
916
924
  while (Date.now() - startedAt < gracePeriodMs) {
917
925
  if (!this.isChildAlive(child)) return;
918
926
  await new Promise((resolve) => setTimeout(resolve, 200));
919
927
  }
920
- if (this.isChildAlive(child)) child.kill("SIGKILL");
928
+ if (this.isChildAlive(child)) terminateOwnedProcessTree(child, "SIGKILL");
921
929
  }
922
930
  isAlive() {
923
931
  return this.child ? this.isChildAlive(this.child) : false;
@@ -1117,7 +1125,7 @@ var KimiAcpSession = class {
1117
1125
  `);
1118
1126
  this.cancelPendingPermissions();
1119
1127
  pending.reject(error);
1120
- this.child?.kill("SIGKILL");
1128
+ if (this.child) terminateOwnedProcessTree(this.child, "SIGKILL");
1121
1129
  }
1122
1130
  handleNotification(method, rawParams) {
1123
1131
  const params = isRecord2(rawParams) ? rawParams : {};
@@ -1288,6 +1296,40 @@ var KimiAcpSession = class {
1288
1296
  };
1289
1297
 
1290
1298
  // src/worker/serve-socket-takeover.ts
1299
+ function readServeConnection(socket, sessionId2, callbacks, timeoutMs = 5e3) {
1300
+ let accepted = false;
1301
+ const timeout = setTimeout(() => socket.destroy(), timeoutMs);
1302
+ timeout.unref();
1303
+ socket.once("close", () => clearTimeout(timeout));
1304
+ createWorkerReader(
1305
+ socket,
1306
+ (message) => {
1307
+ if (socket.destroyed) return;
1308
+ if (!accepted) {
1309
+ if (message.type !== "serve_protocol_hello" || message.sessionId !== sessionId2) {
1310
+ callbacks.onError(new Error("Serve IPC protocol handshake rejected"));
1311
+ socket.destroy();
1312
+ return;
1313
+ }
1314
+ accepted = true;
1315
+ clearTimeout(timeout);
1316
+ callbacks.onAccepted();
1317
+ return;
1318
+ }
1319
+ if (message.type === "serve_protocol_hello") {
1320
+ callbacks.onError(new Error("Duplicate serve IPC protocol hello"));
1321
+ socket.destroy();
1322
+ return;
1323
+ }
1324
+ callbacks.onMessage(message);
1325
+ },
1326
+ (error) => {
1327
+ if (socket.destroyed) return;
1328
+ callbacks.onError(error);
1329
+ if (!accepted) socket.destroy();
1330
+ }
1331
+ );
1332
+ }
1291
1333
  function takeoverServeSocket(prev, next) {
1292
1334
  if (prev && prev !== next) {
1293
1335
  try {
@@ -1349,7 +1391,6 @@ var workerHook = workerHookUrl && workerHookMarker && workerHookToken && workerH
1349
1391
  token: workerHookToken
1350
1392
  } : void 0;
1351
1393
  var serveSocket = null;
1352
- var negotiatedServeSocket = null;
1353
1394
  var queuedServeMessages = [];
1354
1395
  var latestKimiCommandEvent = null;
1355
1396
  var readyMessage = null;
@@ -1377,7 +1418,7 @@ function sendToServe(msg) {
1377
1418
  }
1378
1419
  return;
1379
1420
  }
1380
- if (serveSocket?.writable && negotiatedServeSocket === serveSocket) {
1421
+ if (serveSocket?.writable) {
1381
1422
  serveSocket.write(serializeWorkerMsg(msg));
1382
1423
  return;
1383
1424
  }
@@ -1387,7 +1428,7 @@ function sendToServe(msg) {
1387
1428
  }
1388
1429
  }
1389
1430
  function flushQueuedServeMessages() {
1390
- if (!serveSocket?.writable || negotiatedServeSocket !== serveSocket) return;
1431
+ if (!serveSocket?.writable) return;
1391
1432
  while (queuedServeMessages.length > 0) {
1392
1433
  const msg = queuedServeMessages.shift();
1393
1434
  if (msg) serveSocket.write(serializeWorkerMsg(msg));
@@ -1399,7 +1440,7 @@ function reportReady(message) {
1399
1440
  replayServeState(serveSocket);
1400
1441
  }
1401
1442
  function replayServeState(socket) {
1402
- if (!socket?.writable || serveSocket !== socket || negotiatedServeSocket !== socket) return;
1443
+ if (!socket?.writable || serveSocket !== socket) return;
1403
1444
  if (!providerReady || !readyMessage) return;
1404
1445
  socket.write(serializeWorkerMsg(readyMessage));
1405
1446
  const queuedKimiTurnStart = queuedServeMessages.some(
@@ -1549,40 +1590,24 @@ var session = provider === "codex" ? new CodexAppServerSession({
1549
1590
  onExit: handleProviderExit
1550
1591
  });
1551
1592
  function handleServeConnection(socket) {
1552
- const previousServeSocket = serveSocket;
1553
- serveSocket = socket;
1554
- negotiatedServeSocket = null;
1555
- takeoverServeSocket(previousServeSocket, socket);
1556
- serveSocket.write(
1557
- serializeWorkerMsg({
1558
- type: "worker_protocol_hello",
1559
- protocolVersion: WORKER_IPC_PROTOCOL_VERSION,
1560
- sessionId,
1561
- provider,
1562
- pid: process.pid
1563
- })
1564
- );
1565
- let protocolAccepted = false;
1566
- createWorkerReader(
1567
- socket,
1568
- (msg) => {
1593
+ readServeConnection(socket, sessionId, {
1594
+ onAccepted: () => {
1595
+ const previousServeSocket = serveSocket;
1596
+ serveSocket = socket;
1597
+ takeoverServeSocket(previousServeSocket, socket);
1598
+ socket.write(
1599
+ serializeWorkerMsg({
1600
+ type: "worker_protocol_hello",
1601
+ protocolVersion: WORKER_IPC_PROTOCOL_VERSION,
1602
+ sessionId,
1603
+ provider,
1604
+ pid: process.pid
1605
+ })
1606
+ );
1607
+ replayServeState(socket);
1608
+ },
1609
+ onMessage: (msg) => {
1569
1610
  if (!acceptCurrentServeSocketMessage(serveSocket, socket)) return;
1570
- if (!protocolAccepted) {
1571
- if (msg.type !== "serve_protocol_hello" || msg.sessionId !== sessionId) {
1572
- console.error("[worker] serve IPC protocol handshake rejected");
1573
- socket.destroy();
1574
- return;
1575
- }
1576
- protocolAccepted = true;
1577
- negotiatedServeSocket = socket;
1578
- replayServeState(socket);
1579
- return;
1580
- }
1581
- if (msg.type === "serve_protocol_hello") {
1582
- console.error("[worker] duplicate serve IPC protocol hello");
1583
- socket.destroy();
1584
- return;
1585
- }
1586
1611
  if (!providerReady && msg.type !== "worker_stop") {
1587
1612
  console.error(`[worker] serve message ${msg.type} arrived before provider readiness`);
1588
1613
  socket.destroy();
@@ -1635,24 +1660,17 @@ function handleServeConnection(socket) {
1635
1660
  socket.destroy();
1636
1661
  }
1637
1662
  },
1638
- (err) => {
1639
- if (!protocolAccepted) {
1640
- console.error(`[worker] serve IPC protocol handshake rejected: ${err.message}`);
1641
- socket.destroy();
1642
- return;
1643
- }
1663
+ onError: (err) => {
1644
1664
  console.error(`[worker] serve IPC message dropped: ${err.message}`);
1645
1665
  }
1646
- );
1666
+ });
1647
1667
  socket.on("close", () => {
1648
1668
  serveSocket = releaseServeSocket(serveSocket, socket, () => {
1649
- negotiatedServeSocket = null;
1650
1669
  rejectAllPendingApprovals("Serve connection closed");
1651
1670
  });
1652
1671
  });
1653
1672
  socket.on("error", () => {
1654
1673
  serveSocket = releaseServeSocket(serveSocket, socket, () => {
1655
- negotiatedServeSocket = null;
1656
1674
  rejectAllPendingApprovals("Serve connection error");
1657
1675
  });
1658
1676
  });
@@ -1668,18 +1686,15 @@ function rejectAllPendingApprovals(reason, cancelled = false) {
1668
1686
  }
1669
1687
  pendingApprovals.clear();
1670
1688
  }
1671
- var sockDir = sockPath.substring(0, sockPath.lastIndexOf("/"));
1672
- mkdirSync(sockDir, { recursive: true });
1673
- if (existsSync(sockPath)) {
1674
- unlinkSync(sockPath);
1675
- }
1689
+ prepareLocalIpcEndpoint(sockPath);
1690
+ removeLocalIpcEndpoint(sockPath);
1676
1691
  var server = createServer((socket) => {
1677
1692
  handleServeConnection(socket);
1678
1693
  });
1679
1694
  function cleanup() {
1680
1695
  server.close();
1681
1696
  try {
1682
- unlinkSync(sockPath);
1697
+ removeLocalIpcEndpoint(sockPath);
1683
1698
  } catch {
1684
1699
  }
1685
1700
  }
@@ -1687,7 +1702,7 @@ process.on("SIGTERM", () => {
1687
1702
  session.stop();
1688
1703
  });
1689
1704
  server.listen(sockPath, () => {
1690
- chmodSync(sockPath, 384);
1705
+ setLocalIpcEndpointPermissions(sockPath);
1691
1706
  const pid = session.start();
1692
1707
  if (!Number.isFinite(pid) || pid <= 0) {
1693
1708
  console.error("[worker] provider process failed to start: missing child pid");