@dev-anywhere/proxy 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  readSessionRuntimeIpcVersions,
10
10
  sessionRuntimeIpcVersionMatches,
11
11
  stripProxyProfileArgs
12
- } from "./chunk-SGVG4V66.js";
12
+ } from "./chunk-5WDPYZLE.js";
13
13
  import {
14
14
  getErrorMessage,
15
15
  probeProcess
@@ -30,8 +30,8 @@ import "./chunk-CFO5GU5U.js";
30
30
  import {
31
31
  TERMINAL_IPC_PROTOCOL_VERSION,
32
32
  WORKER_IPC_PROTOCOL_VERSION
33
- } from "./chunk-GUNXL4C5.js";
34
- import "./chunk-E6NHFBCU.js";
33
+ } from "./chunk-N6USDSWB.js";
34
+ import "./chunk-SN2FTSOY.js";
35
35
  import "./chunk-G4QN6LOR.js";
36
36
  import "./chunk-LNSWARRW.js";
37
37
  import {
@@ -254,7 +254,7 @@ var program = new Command("dev-anywhere").description("Dev Anywhere - transparen
254
254
  console.error(err instanceof Error ? err.message : String(err));
255
255
  process.exit(1);
256
256
  }
257
- const { startTerminal } = await import("./terminal-LJSUWZ7X.js");
257
+ const { startTerminal } = await import("./terminal-BKE62DPB.js");
258
258
  const { provider, args } = invocation;
259
259
  await startTerminal(args, provider);
260
260
  });
@@ -310,12 +310,12 @@ for (const [action, description] of [
310
310
  ["status", "Show automatic startup status"]
311
311
  ]) {
312
312
  autostart.command(action).description(description).option("--system", "Use a system service that runs without desktop login").option("--now", "Start the system service now and restart Proxy (enable --system only)").action(async (options) => {
313
- const { runAutostartCommand } = await import("./autostart-MLJRJC2J.js");
313
+ const { runAutostartCommand } = await import("./autostart-ZPDRIXWW.js");
314
314
  await runAutostartCommand(action, options);
315
315
  });
316
316
  }
317
317
  autostart.command("run", { hidden: true }).option("--daemon", "Detach after service readiness (systemd login trigger)").option("--system", "Run the persistent system service host").action(async (_options, command) => {
318
- const { startAutostartService } = await import("./autostart-MLJRJC2J.js");
318
+ const { startAutostartService } = await import("./autostart-ZPDRIXWW.js");
319
319
  const options = command.optsWithGlobals();
320
320
  await startAutostartService(Boolean(options.daemon), Boolean(options.system));
321
321
  });
@@ -15,7 +15,7 @@ import {
15
15
  isPreviewControlRequest,
16
16
  readPreviewWorkerMessages,
17
17
  writePreviewWorkerMessage
18
- } from "./chunk-GK3WHOWF.js";
18
+ } from "./chunk-IBNDSXLX.js";
19
19
  import {
20
20
  acceptCurrentWorkerSocketMessage,
21
21
  readWorkerConnection,
@@ -45,7 +45,7 @@ import {
45
45
  encodeDevicePreviewFrame,
46
46
  encodeDevicePreviewH264ProxyPacket,
47
47
  serializeControl
48
- } from "./chunk-E6NHFBCU.js";
48
+ } from "./chunk-SN2FTSOY.js";
49
49
  import {
50
50
  prepareLocalIpcEndpoint,
51
51
  removeLocalIpcEndpoint,
package/dist/serve.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  sessionRuntimeIpcVersionMatches,
13
13
  stripProxyProfileArgs,
14
14
  writeSessionRuntimeIpcVersions
15
- } from "./chunk-SGVG4V66.js";
15
+ } from "./chunk-5WDPYZLE.js";
16
16
  import {
17
17
  processExistsOrIsInaccessible
18
18
  } from "./chunk-5OARBB2B.js";
@@ -21,7 +21,7 @@ import {
21
21
  isPreviewControlRequest,
22
22
  readPreviewWorkerMessages,
23
23
  writePreviewWorkerMessage
24
- } from "./chunk-GK3WHOWF.js";
24
+ } from "./chunk-IBNDSXLX.js";
25
25
  import {
26
26
  ContentBlockDeltaSchema,
27
27
  IGNORED_EVENT_TYPES,
@@ -40,7 +40,7 @@ import {
40
40
  import {
41
41
  buildHostedPtyArgs,
42
42
  parseTerminalWorkerCliArgs
43
- } from "./chunk-GTG6VONI.js";
43
+ } from "./chunk-JD7Z6JTJ.js";
44
44
  import {
45
45
  ReconnectSupervisor,
46
46
  TERMINAL_ADMISSION_FRAME_MAX_BYTES,
@@ -80,7 +80,7 @@ import {
80
80
  createWorkerReader,
81
81
  serializeIpc,
82
82
  serializeWorkerMsg
83
- } from "./chunk-GUNXL4C5.js";
83
+ } from "./chunk-N6USDSWB.js";
84
84
  import "./chunk-V3JJ352Q.js";
85
85
  import {
86
86
  ControlErrorCode,
@@ -108,7 +108,7 @@ import {
108
108
  isProxyProtocolRejectDirection,
109
109
  serializeControl,
110
110
  summarizeToolActivity
111
- } from "./chunk-E6NHFBCU.js";
111
+ } from "./chunk-SN2FTSOY.js";
112
112
  import {
113
113
  localIpcEndpointMayExist,
114
114
  removeLocalIpcEndpoint,
@@ -483,6 +483,8 @@ function metadataKey(provider, nativeSessionId) {
483
483
  }
484
484
 
485
485
  // src/serve/session-manager.ts
486
+ var MAX_RECENT_EXITS = 50;
487
+ var RECENT_EXIT_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
486
488
  var PTY_TRANSITIONS = {
487
489
  [SessionState.IDLE]: [
488
490
  // 用户提交输入或 provider 发出显式 working 信号 → PTY semantic 翻 working。
@@ -570,6 +572,7 @@ function isProviderId2(value) {
570
572
  }
571
573
  var SessionManager = class {
572
574
  sessions = /* @__PURE__ */ new Map();
575
+ recentExits = /* @__PURE__ */ new Map();
573
576
  pendingPtyReconnectMetadata = /* @__PURE__ */ new Map();
574
577
  reaperTimer = null;
575
578
  persistPath;
@@ -656,6 +659,7 @@ var SessionManager = class {
656
659
  };
657
660
  }
658
661
  this.sessions.set(info.id, info);
662
+ if (pendingPtyMetadata === void 0) this.recentExits.delete(info.id);
659
663
  this.pendingPtyReconnectMetadata.delete(info.id);
660
664
  this.save();
661
665
  serviceLogger.info(
@@ -779,6 +783,7 @@ var SessionManager = class {
779
783
  return { success: false };
780
784
  }
781
785
  const pid = session.pid;
786
+ this.recordSessionExit(id, context?.exit ?? { reason: "process-exit" });
782
787
  this.sessions.delete(id);
783
788
  this.pendingPtyReconnectMetadata.delete(id);
784
789
  this.save();
@@ -797,6 +802,43 @@ var SessionManager = class {
797
802
  }
798
803
  return { success: true, pid };
799
804
  }
805
+ recordSessionExit(id, exit) {
806
+ const session = this.sessions.get(id) ?? this.pendingPtyReconnectMetadata.get(id);
807
+ if (!session) return false;
808
+ const existing = this.recentExits.get(id);
809
+ if (existing && (existing.reason !== "connection-lost" || exit.reason === "connection-lost")) {
810
+ return false;
811
+ }
812
+ const details = exit.details ? sanitizeProviderErrorTail(exit.details) : "";
813
+ this.recentExits.set(id, {
814
+ sessionId: id,
815
+ endedAt: Date.now(),
816
+ reason: exit.reason,
817
+ kind: session.kind,
818
+ provider: session.provider,
819
+ ...exit.exitCode !== void 0 ? { exitCode: exit.exitCode } : {},
820
+ ...details ? { details } : {}
821
+ });
822
+ this.pruneRecentExits();
823
+ return true;
824
+ }
825
+ listRecentExits() {
826
+ this.pruneRecentExits();
827
+ return Array.from(this.recentExits.values(), (exit) => ({ ...exit }));
828
+ }
829
+ clearSessionConnectionLoss(id) {
830
+ if (this.recentExits.get(id)?.reason !== "connection-lost") return false;
831
+ return this.recentExits.delete(id);
832
+ }
833
+ pruneRecentExits() {
834
+ const cutoff = Date.now() - RECENT_EXIT_MAX_AGE_MS;
835
+ for (const [id, exit] of this.recentExits) {
836
+ if (exit.endedAt <= cutoff) this.recentExits.delete(id);
837
+ }
838
+ while (this.recentExits.size > MAX_RECENT_EXITS) {
839
+ this.recentExits.delete(this.recentExits.keys().next().value);
840
+ }
841
+ }
800
842
  terminateAll() {
801
843
  const pids = [];
802
844
  const ids = Array.from(this.sessions.keys());
@@ -2630,7 +2672,10 @@ function broadcastSessionList(relay, sessionManager) {
2630
2672
  "session_list",
2631
2673
  null,
2632
2674
  0,
2633
- { sessions: sessionManager.listSessions().map(toSessionListPayload) },
2675
+ {
2676
+ sessions: sessionManager.listSessions().map(toSessionListPayload),
2677
+ recentExits: sessionManager.listRecentExits()
2678
+ },
2634
2679
  "proxy"
2635
2680
  );
2636
2681
  relay.sendEnvelope(envelope);
@@ -2646,7 +2691,11 @@ function broadcastSessionSync(relay, sessionManager) {
2646
2691
  function changeSessionState(sessionManager, relay, sessionId, next) {
2647
2692
  if (!sessionManager.getSession(sessionId)) return false;
2648
2693
  const changed = sessionManager.updateState(sessionId, next);
2649
- if (changed) pushSessionStatus(relay, sessionManager, sessionId);
2694
+ if (changed) {
2695
+ pushSessionStatus(relay, sessionManager, sessionId);
2696
+ const diagnosticChanged = next === SessionState.ERROR && sessionManager.recordSessionExit(sessionId, { reason: "connection-lost" });
2697
+ if (diagnosticChanged) broadcastSessionList(relay, sessionManager);
2698
+ }
2650
2699
  return changed;
2651
2700
  }
2652
2701
  function changeTerminalCwd(sessionManager, relay, sessionId, cwd) {
@@ -4065,7 +4114,14 @@ var WorkerRegistry = class {
4065
4114
  const activeSession = this.deps.sessionManager.getSession(sessionId);
4066
4115
  this.delete(sessionId);
4067
4116
  if (!activeSession) return;
4068
- const result = this.deps.sessionManager.terminateSession(sessionId);
4117
+ const result = this.deps.sessionManager.terminateSession(sessionId, {
4118
+ exit: {
4119
+ reason: "process-exit",
4120
+ // The wrapper exits with 0 after forwarding worker_exit, even when the provider
4121
+ // failed. Without that IPC message its exit code cannot describe the provider.
4122
+ details: signal ? `Session worker exited after signal ${signal}; provider exit status unavailable` : "Session worker exited without reporting provider exit status"
4123
+ }
4124
+ });
4069
4125
  serviceLogger.warn(
4070
4126
  { sessionId, workerPid, code, signal, removed: result.success },
4071
4127
  "JSON worker process exited without worker_exit IPC"
@@ -4392,7 +4448,13 @@ var WorkerRegistry = class {
4392
4448
  serviceLogger.debug({ sessionId, eventType: msg.event.type }, "JSON session event");
4393
4449
  break;
4394
4450
  case "worker_exit":
4395
- this.deps.sessionManager.terminateSession(sessionId);
4451
+ this.deps.sessionManager.terminateSession(sessionId, {
4452
+ exit: {
4453
+ reason: "process-exit",
4454
+ exitCode: msg.code,
4455
+ ...msg.errorTail ? { details: msg.errorTail } : {}
4456
+ }
4457
+ });
4396
4458
  this.delete(sessionId);
4397
4459
  serviceLogger[msg.code === 0 ? "info" : "warn"](
4398
4460
  {
@@ -4543,7 +4605,9 @@ var WorkerRegistry = class {
4543
4605
  const session = this.deps.sessionManager.getSession(sessionId);
4544
4606
  if (!session || session.mode !== "json") return;
4545
4607
  const child = this.children.get(sessionId);
4546
- const result = this.deps.sessionManager.terminateSession(sessionId);
4608
+ const result = this.deps.sessionManager.terminateSession(sessionId, {
4609
+ exit: { reason: "connection-lost", details: "Worker connection failed before ready" }
4610
+ });
4547
4611
  const pid = result.pid ?? session.pid;
4548
4612
  this.delete(sessionId);
4549
4613
  this.startupFailures.delete(sessionId);
@@ -4590,7 +4654,9 @@ var WorkerRegistry = class {
4590
4654
  if (child) this.startupFailures.set(sessionId, error);
4591
4655
  else this.startupFailures.delete(sessionId);
4592
4656
  this.rejectReadyWaiters(error, sessionId);
4593
- const result = this.deps.sessionManager.terminateSession(sessionId);
4657
+ const result = this.deps.sessionManager.terminateSession(sessionId, {
4658
+ exit: { reason: "connection-lost", details: error.message }
4659
+ });
4594
4660
  socket?.destroy();
4595
4661
  let terminated = false;
4596
4662
  if (child && !child.killed) {
@@ -5018,7 +5084,9 @@ function terminateSessionByOwnership(deps, sessionId) {
5018
5084
  }
5019
5085
  }
5020
5086
  deps.terminalSockets.delete(sessionId);
5021
- const result = deps.sessionManager.terminateSession(sessionId);
5087
+ const result = deps.sessionManager.terminateSession(sessionId, {
5088
+ exit: { reason: "user-terminated" }
5089
+ });
5022
5090
  serviceLogger.info(
5023
5091
  { sessionId, success: result.success },
5024
5092
  "Terminal worker session terminated"
@@ -5032,7 +5100,8 @@ function terminateSessionByOwnership(deps, sessionId) {
5032
5100
  }
5033
5101
  deps.terminalSockets.delete(sessionId);
5034
5102
  const result = deps.sessionManager.terminateSession(sessionId, {
5035
- preserveProviderHooks: true
5103
+ preserveProviderHooks: true,
5104
+ exit: { reason: "user-terminated" }
5036
5105
  });
5037
5106
  serviceLogger.info(
5038
5107
  { sessionId, success: result.success },
@@ -5047,7 +5116,9 @@ function terminateSessionByOwnership(deps, sessionId) {
5047
5116
  } else {
5048
5117
  deps.workerRegistry.terminateProcess(sessionId);
5049
5118
  }
5050
- const result = deps.sessionManager.terminateSession(sessionId);
5119
+ const result = deps.sessionManager.terminateSession(sessionId, {
5120
+ exit: { reason: "user-terminated" }
5121
+ });
5051
5122
  serviceLogger.info(
5052
5123
  { sessionId, success: result.success, stopDelivered },
5053
5124
  "JSON worker session terminated"
@@ -8607,12 +8678,21 @@ function handleTerminalConnection(socket, deps, admission) {
8607
8678
  if (terminalSockets.has(sessionId) || terminalClaims.has(sessionId)) return;
8608
8679
  sessionManager.releasePtyBinding(sessionId, claim.session.pid);
8609
8680
  };
8610
- const discardUnregisteredClaim = () => {
8681
+ const discardUnregisteredClaim = (channelLost = false) => {
8611
8682
  if (acceptedRegistration === null || registeredSessionId !== null) return;
8612
8683
  const { sessionId, pid } = acceptedRegistration;
8613
8684
  if (terminalClaims.get(sessionId) === socket) {
8614
8685
  terminalClaims.delete(sessionId);
8615
- if (!terminalSockets.has(sessionId)) sessionManager.releasePtyBinding(sessionId, pid);
8686
+ if (!terminalSockets.has(sessionId)) {
8687
+ if (channelLost) {
8688
+ sessionManager.recordSessionExit(sessionId, { reason: "connection-lost" });
8689
+ }
8690
+ sessionManager.releasePtyBinding(sessionId, pid);
8691
+ if (channelLost) {
8692
+ broadcastSessionSync(relayConnection, sessionManager);
8693
+ broadcastSessionList(relayConnection, sessionManager);
8694
+ }
8695
+ }
8616
8696
  }
8617
8697
  acceptedRegistration = null;
8618
8698
  };
@@ -8803,6 +8883,7 @@ function handleTerminalConnection(socket, deps, admission) {
8803
8883
  terminalClaims.delete(msg.sessionId);
8804
8884
  registeredSessionId = msg.sessionId;
8805
8885
  acceptedRegistration = null;
8886
+ sessionManager.clearSessionConnectionLoss(msg.sessionId);
8806
8887
  socket.write(
8807
8888
  serializeIpc({
8808
8889
  type: "pty_approval_context",
@@ -8871,7 +8952,13 @@ function handleTerminalConnection(socket, deps, admission) {
8871
8952
  })
8872
8953
  );
8873
8954
  }
8874
- sessionManager.terminateSession(msg.sessionId);
8955
+ sessionManager.terminateSession(msg.sessionId, {
8956
+ exit: {
8957
+ reason: "process-exit",
8958
+ ...msg.exitCode !== void 0 ? { exitCode: msg.exitCode } : {},
8959
+ ...msg.errorTail ? { details: msg.errorTail } : {}
8960
+ }
8961
+ });
8875
8962
  terminalSockets.delete(msg.sessionId);
8876
8963
  registeredSessionId = null;
8877
8964
  serviceLogger[msg.exitCode === void 0 || msg.exitCode === 0 ? "info" : "warn"](
@@ -8934,7 +9021,7 @@ function handleTerminalConnection(socket, deps, admission) {
8934
9021
  }
8935
9022
  );
8936
9023
  socket.on("close", () => {
8937
- discardUnregisteredClaim();
9024
+ discardUnregisteredClaim(true);
8938
9025
  for (const [sessionId, terminalSocket] of terminalSockets) {
8939
9026
  if (terminalSocket === socket) {
8940
9027
  terminalSockets.delete(sessionId);
@@ -8946,7 +9033,10 @@ function handleTerminalConnection(socket, deps, admission) {
8946
9033
  }
8947
9034
  if (session.mode === "pty" && session.pid && isProcessAlive(session.pid)) {
8948
9035
  if (!terminalClaims.has(sessionId)) {
9036
+ sessionManager.recordSessionExit(sessionId, { reason: "connection-lost" });
8949
9037
  sessionManager.releasePtyBinding(sessionId, session.pid);
9038
+ broadcastSessionSync(relayConnection, sessionManager);
9039
+ broadcastSessionList(relayConnection, sessionManager);
8950
9040
  }
8951
9041
  serviceLogger.info(
8952
9042
  { sessionId, pid: session.pid },
@@ -9895,6 +9985,8 @@ var EXT_MIME_MAP = {
9895
9985
  ".jpeg": "image/jpeg",
9896
9986
  ".gif": "image/gif",
9897
9987
  ".webp": "image/webp",
9988
+ ".heic": "image/heic",
9989
+ ".heif": "image/heif",
9898
9990
  ".svg": "image/svg+xml",
9899
9991
  ".bmp": "image/bmp",
9900
9992
  ".pdf": "application/pdf",