@dev-anywhere/proxy 0.10.2 → 0.10.4

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-KRJQU2AV.js");
313
+ const { runAutostartCommand } = await import("./autostart-LLJPWRR4.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-KRJQU2AV.js");
318
+ const { startAutostartService } = await import("./autostart-LLJPWRR4.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) {
@@ -3935,6 +3984,18 @@ var KimiAcpEventMapper = class {
3935
3984
 
3936
3985
  // src/serve/worker-registry.ts
3937
3986
  var RECONNECT_WORKER_HANDSHAKE_TIMEOUT_MS = 1e3;
3987
+ function isConversationActivityEnvelope(envelope) {
3988
+ switch (envelope.type) {
3989
+ case "assistant_message":
3990
+ case "thinking":
3991
+ case "assistant_tool_use":
3992
+ case "tool_result":
3993
+ case "user_input":
3994
+ return true;
3995
+ default:
3996
+ return false;
3997
+ }
3998
+ }
3938
3999
  var WorkerStartupError = class extends Error {
3939
4000
  constructor(message, errorCode2, nativeSessionId) {
3940
4001
  super(message);
@@ -4065,7 +4126,14 @@ var WorkerRegistry = class {
4065
4126
  const activeSession = this.deps.sessionManager.getSession(sessionId);
4066
4127
  this.delete(sessionId);
4067
4128
  if (!activeSession) return;
4068
- const result = this.deps.sessionManager.terminateSession(sessionId);
4129
+ const result = this.deps.sessionManager.terminateSession(sessionId, {
4130
+ exit: {
4131
+ reason: "process-exit",
4132
+ // The wrapper exits with 0 after forwarding worker_exit, even when the provider
4133
+ // failed. Without that IPC message its exit code cannot describe the provider.
4134
+ details: signal ? `Session worker exited after signal ${signal}; provider exit status unavailable` : "Session worker exited without reporting provider exit status"
4135
+ }
4136
+ });
4069
4137
  serviceLogger.warn(
4070
4138
  { sessionId, workerPid, code, signal, removed: result.success },
4071
4139
  "JSON worker process exited without worker_exit IPC"
@@ -4392,7 +4460,13 @@ var WorkerRegistry = class {
4392
4460
  serviceLogger.debug({ sessionId, eventType: msg.event.type }, "JSON session event");
4393
4461
  break;
4394
4462
  case "worker_exit":
4395
- this.deps.sessionManager.terminateSession(sessionId);
4463
+ this.deps.sessionManager.terminateSession(sessionId, {
4464
+ exit: {
4465
+ reason: "process-exit",
4466
+ exitCode: msg.code,
4467
+ ...msg.errorTail ? { details: msg.errorTail } : {}
4468
+ }
4469
+ });
4396
4470
  this.delete(sessionId);
4397
4471
  serviceLogger[msg.code === 0 ? "info" : "warn"](
4398
4472
  {
@@ -4543,7 +4617,9 @@ var WorkerRegistry = class {
4543
4617
  const session = this.deps.sessionManager.getSession(sessionId);
4544
4618
  if (!session || session.mode !== "json") return;
4545
4619
  const child = this.children.get(sessionId);
4546
- const result = this.deps.sessionManager.terminateSession(sessionId);
4620
+ const result = this.deps.sessionManager.terminateSession(sessionId, {
4621
+ exit: { reason: "connection-lost", details: "Worker connection failed before ready" }
4622
+ });
4547
4623
  const pid = result.pid ?? session.pid;
4548
4624
  this.delete(sessionId);
4549
4625
  this.startupFailures.delete(sessionId);
@@ -4590,7 +4666,9 @@ var WorkerRegistry = class {
4590
4666
  if (child) this.startupFailures.set(sessionId, error);
4591
4667
  else this.startupFailures.delete(sessionId);
4592
4668
  this.rejectReadyWaiters(error, sessionId);
4593
- const result = this.deps.sessionManager.terminateSession(sessionId);
4669
+ const result = this.deps.sessionManager.terminateSession(sessionId, {
4670
+ exit: { reason: "connection-lost", details: error.message }
4671
+ });
4594
4672
  socket?.destroy();
4595
4673
  let terminated = false;
4596
4674
  if (child && !child.killed) {
@@ -4707,7 +4785,6 @@ var WorkerRegistry = class {
4707
4785
  return;
4708
4786
  }
4709
4787
  const ev = parsed.data;
4710
- this.deps.touchSessionActivity?.(sessionId);
4711
4788
  const isStreamDeltaSession = true;
4712
4789
  if (ev.type === "system") {
4713
4790
  if (this.handleCompactSystemEvent(sessionId, seq, ev)) return;
@@ -4723,6 +4800,7 @@ var WorkerRegistry = class {
4723
4800
  return;
4724
4801
  }
4725
4802
  }
4803
+ let forwardedActivity = false;
4726
4804
  for (const mapped of mapClaudeStreamEvent(sessionId, seq, {
4727
4805
  event: ev,
4728
4806
  isStreamDeltaSession,
@@ -4730,14 +4808,17 @@ var WorkerRegistry = class {
4730
4808
  })) {
4731
4809
  if (mapped.kind === "assistant_text") {
4732
4810
  this.appendAssistantSnapshot(sessionId, seq, mapped.text, mapped.turnId);
4811
+ forwardedActivity = true;
4733
4812
  } else if (mapped.kind === "envelope") {
4734
4813
  if (mapped.envelope.type === "assistant_tool_use") {
4735
4814
  this.completeAssistantSnapshot(sessionId, seq);
4736
4815
  }
4737
4816
  relay.sendEnvelope(mapped.envelope);
4817
+ forwardedActivity ||= isConversationActivityEnvelope(mapped.envelope);
4738
4818
  } else if (mapped.kind === "control") {
4739
4819
  this.completeAssistantSnapshot(sessionId, seq);
4740
4820
  relay.sendRaw(mapped.raw);
4821
+ forwardedActivity ||= mapped.notifyTurnResult;
4741
4822
  if (mapped.notifyTurnResult) this.deps.jsonObserver.onTurnResult(sessionId);
4742
4823
  } else {
4743
4824
  serviceLogger.warn(
@@ -4746,42 +4827,50 @@ var WorkerRegistry = class {
4746
4827
  );
4747
4828
  }
4748
4829
  }
4830
+ if (forwardedActivity) this.deps.touchSessionActivity?.(sessionId);
4749
4831
  }
4750
4832
  forwardCodexAppServerEvent(sessionId, seq, event) {
4751
4833
  const relay = this.deps.relayConnection;
4752
- this.deps.touchSessionActivity?.(sessionId);
4834
+ let forwardedActivity = false;
4753
4835
  for (const mapped of mapCodexAppServerEvent(sessionId, seq, event)) {
4754
4836
  if (mapped.kind === "assistant_text") {
4755
4837
  this.appendAssistantSnapshot(sessionId, seq, mapped.text, mapped.turnId);
4838
+ forwardedActivity = true;
4756
4839
  } else if (mapped.kind === "envelope") {
4757
4840
  if (mapped.envelope.type === "assistant_tool_use") {
4758
4841
  this.completeAssistantSnapshot(sessionId, seq);
4759
4842
  }
4760
4843
  relay.sendEnvelope(mapped.envelope);
4844
+ forwardedActivity ||= isConversationActivityEnvelope(mapped.envelope);
4761
4845
  } else {
4762
4846
  this.completeAssistantSnapshot(sessionId, seq);
4763
4847
  relay.sendRaw(mapped.raw);
4848
+ forwardedActivity ||= mapped.notifyTurnResult;
4764
4849
  if (mapped.notifyTurnResult) this.deps.jsonObserver.onTurnResult(sessionId);
4765
4850
  }
4766
4851
  }
4852
+ if (forwardedActivity) this.deps.touchSessionActivity?.(sessionId);
4767
4853
  }
4768
4854
  forwardKimiAcpEvent(sessionId, seq, event) {
4769
4855
  const relay = this.deps.relayConnection;
4770
- this.deps.touchSessionActivity?.(sessionId);
4856
+ let forwardedActivity = false;
4771
4857
  for (const mapped of this.kimiAcpEventMapper.map(sessionId, seq, event)) {
4772
4858
  if (mapped.kind === "assistant_text") {
4773
4859
  this.appendAssistantSnapshot(sessionId, seq, mapped.text);
4860
+ forwardedActivity = true;
4774
4861
  } else if (mapped.kind === "envelope") {
4775
4862
  if (mapped.envelope.type === "assistant_tool_use" || mapped.envelope.type === "user_input") {
4776
4863
  this.completeAssistantSnapshot(sessionId, seq);
4777
4864
  }
4778
4865
  relay.sendEnvelope(mapped.envelope);
4866
+ forwardedActivity ||= isConversationActivityEnvelope(mapped.envelope);
4779
4867
  } else if (mapped.kind === "control") {
4780
4868
  if (mapped.providerCommands) {
4781
4869
  this.deps.setProviderCommands?.(sessionId, mapped.providerCommands);
4782
4870
  }
4783
4871
  if (mapped.completeAssistant !== false) this.completeAssistantSnapshot(sessionId, seq);
4784
4872
  relay.sendRaw(mapped.raw);
4873
+ forwardedActivity ||= mapped.notifyTurnResult;
4785
4874
  if (mapped.notifyTurnResult) this.deps.jsonObserver.onTurnResult(sessionId);
4786
4875
  } else {
4787
4876
  serviceLogger.warn(
@@ -4790,25 +4879,29 @@ var WorkerRegistry = class {
4790
4879
  );
4791
4880
  }
4792
4881
  }
4882
+ if (forwardedActivity) this.deps.touchSessionActivity?.(sessionId);
4793
4883
  }
4794
4884
  forwardCursorAcpEvent(sessionId, seq, event) {
4795
4885
  const relay = this.deps.relayConnection;
4796
- this.deps.touchSessionActivity?.(sessionId);
4886
+ let forwardedActivity = false;
4797
4887
  for (const mapped of this.cursorAcpEventMapper.map(sessionId, seq, event)) {
4798
4888
  if (mapped.kind === "assistant_text") {
4799
4889
  if (this.interruptedCursorSessions.has(sessionId)) continue;
4800
4890
  this.appendAssistantSnapshot(sessionId, seq, mapped.text);
4891
+ forwardedActivity = true;
4801
4892
  } else if (mapped.kind === "envelope") {
4802
4893
  if (mapped.envelope.type === "assistant_tool_use" || mapped.envelope.type === "user_input" || mapped.envelope.type === "assistant_message") {
4803
4894
  this.completeAssistantSnapshot(sessionId, seq);
4804
4895
  }
4805
4896
  relay.sendEnvelope(mapped.envelope);
4897
+ forwardedActivity ||= isConversationActivityEnvelope(mapped.envelope);
4806
4898
  } else if (mapped.kind === "control") {
4807
4899
  if (mapped.providerCommands) {
4808
4900
  this.deps.setProviderCommands?.(sessionId, mapped.providerCommands);
4809
4901
  }
4810
4902
  if (mapped.completeAssistant !== false) this.completeAssistantSnapshot(sessionId, seq);
4811
4903
  relay.sendRaw(mapped.raw);
4904
+ forwardedActivity ||= mapped.notifyTurnResult;
4812
4905
  if (mapped.notifyTurnResult) this.deps.jsonObserver.onTurnResult(sessionId);
4813
4906
  } else {
4814
4907
  serviceLogger.warn(
@@ -4817,6 +4910,7 @@ var WorkerRegistry = class {
4817
4910
  );
4818
4911
  }
4819
4912
  }
4913
+ if (forwardedActivity) this.deps.touchSessionActivity?.(sessionId);
4820
4914
  }
4821
4915
  nextAssistantTurnId(sessionId) {
4822
4916
  this.assistantTurnCounter += 1;
@@ -5018,7 +5112,9 @@ function terminateSessionByOwnership(deps, sessionId) {
5018
5112
  }
5019
5113
  }
5020
5114
  deps.terminalSockets.delete(sessionId);
5021
- const result = deps.sessionManager.terminateSession(sessionId);
5115
+ const result = deps.sessionManager.terminateSession(sessionId, {
5116
+ exit: { reason: "user-terminated" }
5117
+ });
5022
5118
  serviceLogger.info(
5023
5119
  { sessionId, success: result.success },
5024
5120
  "Terminal worker session terminated"
@@ -5032,7 +5128,8 @@ function terminateSessionByOwnership(deps, sessionId) {
5032
5128
  }
5033
5129
  deps.terminalSockets.delete(sessionId);
5034
5130
  const result = deps.sessionManager.terminateSession(sessionId, {
5035
- preserveProviderHooks: true
5131
+ preserveProviderHooks: true,
5132
+ exit: { reason: "user-terminated" }
5036
5133
  });
5037
5134
  serviceLogger.info(
5038
5135
  { sessionId, success: result.success },
@@ -5047,7 +5144,9 @@ function terminateSessionByOwnership(deps, sessionId) {
5047
5144
  } else {
5048
5145
  deps.workerRegistry.terminateProcess(sessionId);
5049
5146
  }
5050
- const result = deps.sessionManager.terminateSession(sessionId);
5147
+ const result = deps.sessionManager.terminateSession(sessionId, {
5148
+ exit: { reason: "user-terminated" }
5149
+ });
5051
5150
  serviceLogger.info(
5052
5151
  { sessionId, success: result.success, stopDelivered },
5053
5152
  "JSON worker session terminated"
@@ -8607,12 +8706,21 @@ function handleTerminalConnection(socket, deps, admission) {
8607
8706
  if (terminalSockets.has(sessionId) || terminalClaims.has(sessionId)) return;
8608
8707
  sessionManager.releasePtyBinding(sessionId, claim.session.pid);
8609
8708
  };
8610
- const discardUnregisteredClaim = () => {
8709
+ const discardUnregisteredClaim = (channelLost = false) => {
8611
8710
  if (acceptedRegistration === null || registeredSessionId !== null) return;
8612
8711
  const { sessionId, pid } = acceptedRegistration;
8613
8712
  if (terminalClaims.get(sessionId) === socket) {
8614
8713
  terminalClaims.delete(sessionId);
8615
- if (!terminalSockets.has(sessionId)) sessionManager.releasePtyBinding(sessionId, pid);
8714
+ if (!terminalSockets.has(sessionId)) {
8715
+ if (channelLost) {
8716
+ sessionManager.recordSessionExit(sessionId, { reason: "connection-lost" });
8717
+ }
8718
+ sessionManager.releasePtyBinding(sessionId, pid);
8719
+ if (channelLost) {
8720
+ broadcastSessionSync(relayConnection, sessionManager);
8721
+ broadcastSessionList(relayConnection, sessionManager);
8722
+ }
8723
+ }
8616
8724
  }
8617
8725
  acceptedRegistration = null;
8618
8726
  };
@@ -8803,6 +8911,7 @@ function handleTerminalConnection(socket, deps, admission) {
8803
8911
  terminalClaims.delete(msg.sessionId);
8804
8912
  registeredSessionId = msg.sessionId;
8805
8913
  acceptedRegistration = null;
8914
+ sessionManager.clearSessionConnectionLoss(msg.sessionId);
8806
8915
  socket.write(
8807
8916
  serializeIpc({
8808
8917
  type: "pty_approval_context",
@@ -8871,7 +8980,13 @@ function handleTerminalConnection(socket, deps, admission) {
8871
8980
  })
8872
8981
  );
8873
8982
  }
8874
- sessionManager.terminateSession(msg.sessionId);
8983
+ sessionManager.terminateSession(msg.sessionId, {
8984
+ exit: {
8985
+ reason: "process-exit",
8986
+ ...msg.exitCode !== void 0 ? { exitCode: msg.exitCode } : {},
8987
+ ...msg.errorTail ? { details: msg.errorTail } : {}
8988
+ }
8989
+ });
8875
8990
  terminalSockets.delete(msg.sessionId);
8876
8991
  registeredSessionId = null;
8877
8992
  serviceLogger[msg.exitCode === void 0 || msg.exitCode === 0 ? "info" : "warn"](
@@ -8912,8 +9027,12 @@ function handleTerminalConnection(socket, deps, admission) {
8912
9027
  },
8913
9028
  (sessionId, data, outputSeq) => {
8914
9029
  if (protocolRejected) return;
8915
- if (!ownsRegisteredSession(sessionId) || !sessionManager.getSession(sessionId)) return;
8916
- touchSessionActivity(sessionManager, relayConnection, sessionId);
9030
+ if (!ownsRegisteredSession(sessionId)) return;
9031
+ const session = sessionManager.getSession(sessionId);
9032
+ if (!session) return;
9033
+ if (data.length > 0 && (session.kind === "terminal" || session.state === SessionState.WORKING)) {
9034
+ touchSessionActivity(sessionManager, relayConnection, sessionId);
9035
+ }
8917
9036
  relayConnection.sendBinary(encodeBinaryFrame(sessionId, outputSeq, data));
8918
9037
  },
8919
9038
  (err, line) => {
@@ -8934,7 +9053,7 @@ function handleTerminalConnection(socket, deps, admission) {
8934
9053
  }
8935
9054
  );
8936
9055
  socket.on("close", () => {
8937
- discardUnregisteredClaim();
9056
+ discardUnregisteredClaim(true);
8938
9057
  for (const [sessionId, terminalSocket] of terminalSockets) {
8939
9058
  if (terminalSocket === socket) {
8940
9059
  terminalSockets.delete(sessionId);
@@ -8946,7 +9065,10 @@ function handleTerminalConnection(socket, deps, admission) {
8946
9065
  }
8947
9066
  if (session.mode === "pty" && session.pid && isProcessAlive(session.pid)) {
8948
9067
  if (!terminalClaims.has(sessionId)) {
9068
+ sessionManager.recordSessionExit(sessionId, { reason: "connection-lost" });
8949
9069
  sessionManager.releasePtyBinding(sessionId, session.pid);
9070
+ broadcastSessionSync(relayConnection, sessionManager);
9071
+ broadcastSessionList(relayConnection, sessionManager);
8950
9072
  }
8951
9073
  serviceLogger.info(
8952
9074
  { sessionId, pid: session.pid },