chatroom-cli 1.53.2 → 1.53.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
@@ -28015,7 +28015,7 @@ ${options.prompt}` : options.prompt;
28015
28015
  process.stderr.write(`${logPrefix} spawn-error] ${reason}
28016
28016
  `);
28017
28017
  } finally {
28018
- if (!session.agentClosed && !session.preserveForResume) {
28018
+ if (!session.agentClosed && session.aborted && !session.preserveForResume) {
28019
28019
  try {
28020
28020
  agent.close();
28021
28021
  session.agentClosed = true;
@@ -83819,7 +83819,7 @@ function isProcessAlive(kill, pid) {
83819
83819
  }
83820
83820
  }
83821
83821
 
83822
- // src/infrastructure/machine/stop-reason.ts
83822
+ // src/domain/agent-lifecycle/entities/stop-reason.ts
83823
83823
  function resolveStopReason(code2, signal) {
83824
83824
  if (signal !== null)
83825
83825
  return "agent_process.signal";
@@ -83828,11 +83828,59 @@ function resolveStopReason(code2, signal) {
83828
83828
  return "agent_process.crashed";
83829
83829
  }
83830
83830
 
83831
+ // src/domain/agent-lifecycle/policies/preserve-session.ts
83832
+ function shouldRetainHarnessSessionForReconnect(reason) {
83833
+ switch (reason) {
83834
+ case "user.stop":
83835
+ case "agent_process.exited_clean":
83836
+ case "agent_process.signal":
83837
+ case "agent_process.crashed":
83838
+ return true;
83839
+ default:
83840
+ return false;
83841
+ }
83842
+ }
83843
+ function shouldPreserveHarnessTeardown(reason, supportsSessionResume, hasHarnessSessionId) {
83844
+ return hasHarnessSessionId && supportsSessionResume && shouldRetainHarnessSessionForReconnect(reason);
83845
+ }
83846
+
83847
+ // src/domain/agent-lifecycle/policies/decide-resume-path.ts
83848
+ function decideResumePathOnRestart(input) {
83849
+ if (!input.supportsSessionResume) {
83850
+ return "cold";
83851
+ }
83852
+ if (input.wantResume && input.hasStoredSnapshot) {
83853
+ return "daemon_memory";
83854
+ }
83855
+ return "cold";
83856
+ }
83857
+ function shouldAutoRestartAfterProcessExit(stopReason) {
83858
+ switch (stopReason) {
83859
+ case "user.stop":
83860
+ case "platform.team_switch":
83861
+ case "daemon.shutdown":
83862
+ case "daemon.respawn":
83863
+ return false;
83864
+ default:
83865
+ return true;
83866
+ }
83867
+ }
83868
+
83869
+ // src/domain/agent-lifecycle/index.ts
83870
+ var init_agent_lifecycle = () => {};
83871
+
83831
83872
  // ../../services/backend/src/domain/entities/harness/claude.config.ts
83832
83873
  var claudeCapabilities;
83833
83874
  var init_claude_config = __esm(() => {
83834
83875
  claudeCapabilities = {
83835
- supportsSessionResume: false
83876
+ runtimeKind: "cli",
83877
+ supportsSessionResume: false,
83878
+ lifecycle: {
83879
+ turnCompleted: false,
83880
+ outputActivity: true,
83881
+ processExited: true
83882
+ },
83883
+ wireEvents: []
83836
83884
  };
83837
83885
  });
83838
83886
 
@@ -83840,7 +83888,14 @@ var init_claude_config = __esm(() => {
83840
83888
  var commandcodeCapabilities;
83841
83889
  var init_commandcode_config = __esm(() => {
83842
83890
  commandcodeCapabilities = {
83843
- supportsSessionResume: false
83891
+ runtimeKind: "cli",
83892
+ supportsSessionResume: false,
83893
+ lifecycle: {
83894
+ turnCompleted: true,
83895
+ outputActivity: true,
83896
+ processExited: true
83897
+ },
83898
+ wireEvents: ["wire.log.agent_end"]
83844
83899
  };
83845
83900
  });
83846
83901
 
@@ -83848,7 +83903,14 @@ var init_commandcode_config = __esm(() => {
83848
83903
  var copilotCapabilities;
83849
83904
  var init_copilot_config = __esm(() => {
83850
83905
  copilotCapabilities = {
83851
- supportsSessionResume: false
83906
+ runtimeKind: "cli",
83907
+ supportsSessionResume: false,
83908
+ lifecycle: {
83909
+ turnCompleted: true,
83910
+ outputActivity: true,
83911
+ processExited: true
83912
+ },
83913
+ wireEvents: ["wire.log.agent_end"]
83852
83914
  };
83853
83915
  });
83854
83916
 
@@ -83856,7 +83918,14 @@ var init_copilot_config = __esm(() => {
83856
83918
  var cursorCapabilities;
83857
83919
  var init_cursor_config = __esm(() => {
83858
83920
  cursorCapabilities = {
83859
- supportsSessionResume: false
83921
+ runtimeKind: "cli",
83922
+ supportsSessionResume: false,
83923
+ lifecycle: {
83924
+ turnCompleted: true,
83925
+ outputActivity: true,
83926
+ processExited: true
83927
+ },
83928
+ wireEvents: ["wire.log.agent_end"]
83860
83929
  };
83861
83930
  });
83862
83931
 
@@ -83864,7 +83933,14 @@ var init_cursor_config = __esm(() => {
83864
83933
  var cursorSdkCapabilities;
83865
83934
  var init_cursor_sdk_config = __esm(() => {
83866
83935
  cursorSdkCapabilities = {
83867
- supportsSessionResume: true
83936
+ runtimeKind: "sdk",
83937
+ supportsSessionResume: true,
83938
+ lifecycle: {
83939
+ turnCompleted: true,
83940
+ outputActivity: true,
83941
+ processExited: true
83942
+ },
83943
+ wireEvents: ["sdk.cursor.message", "sdk.cursor.run.completed", "wire.log.agent_end"]
83868
83944
  };
83869
83945
  });
83870
83946
 
@@ -83872,7 +83948,14 @@ var init_cursor_sdk_config = __esm(() => {
83872
83948
  var opencodeCapabilities;
83873
83949
  var init_opencode_config = __esm(() => {
83874
83950
  opencodeCapabilities = {
83875
- supportsSessionResume: false
83951
+ runtimeKind: "cli",
83952
+ supportsSessionResume: false,
83953
+ lifecycle: {
83954
+ turnCompleted: false,
83955
+ outputActivity: true,
83956
+ processExited: true
83957
+ },
83958
+ wireEvents: []
83876
83959
  };
83877
83960
  });
83878
83961
 
@@ -83880,7 +83963,14 @@ var init_opencode_config = __esm(() => {
83880
83963
  var opencodeSdkCapabilities;
83881
83964
  var init_opencode_sdk_config = __esm(() => {
83882
83965
  opencodeSdkCapabilities = {
83883
- supportsSessionResume: true
83966
+ runtimeKind: "sdk",
83967
+ supportsSessionResume: true,
83968
+ lifecycle: {
83969
+ turnCompleted: true,
83970
+ outputActivity: true,
83971
+ processExited: true
83972
+ },
83973
+ wireEvents: ["sdk.opencode.session.idle", "sdk.opencode.session.event"]
83884
83974
  };
83885
83975
  });
83886
83976
 
@@ -83888,7 +83978,22 @@ var init_opencode_sdk_config = __esm(() => {
83888
83978
  var piCapabilities;
83889
83979
  var init_pi_config = __esm(() => {
83890
83980
  piCapabilities = {
83891
- supportsSessionResume: true
83981
+ runtimeKind: "cli",
83982
+ supportsSessionResume: true,
83983
+ lifecycle: {
83984
+ turnCompleted: true,
83985
+ outputActivity: true,
83986
+ processExited: true
83987
+ },
83988
+ wireEvents: [
83989
+ "wire.ndjson.agent_start",
83990
+ "wire.ndjson.agent_end",
83991
+ "wire.ndjson.message_update",
83992
+ "wire.ndjson.tool_execution_start",
83993
+ "wire.ndjson.tool_execution_end",
83994
+ "wire.ndjson.get_state",
83995
+ "wire.log.agent_end"
83996
+ ]
83892
83997
  };
83893
83998
  });
83894
83999
 
@@ -84010,11 +84115,11 @@ class AgentProcessManager {
84010
84115
  const key = agentKey2(opts.chatroomId, opts.role);
84011
84116
  const slot = this.slots.get(key);
84012
84117
  if (slot?.resumeInFlight) {
84013
- console.log(`[AgentProcessManager] agent_end: skipping duplicate resume for ${opts.role} (resume already in flight)`);
84118
+ console.log(`[AgentProcessManager] lifecycle.turn.completed: skipping duplicate resume for ${opts.role} (resume already in flight)`);
84014
84119
  return;
84015
84120
  }
84016
84121
  const capabilities = getHarnessCapabilities(opts.harness);
84017
- console.log(`[AgentProcessManager] agent_end: role=${opts.role} pid=${opts.pid} harness=${opts.harness} supportsResume=${capabilities.supportsSessionResume}`);
84122
+ console.log(`[AgentProcessManager] lifecycle.turn.completed: role=${opts.role} pid=${opts.pid} harness=${opts.harness} supportsResume=${capabilities.supportsSessionResume}`);
84018
84123
  if (capabilities.supportsSessionResume) {
84019
84124
  const service = this.deps.agentServices.get(opts.harness);
84020
84125
  if (service?.resumeTurn) {
@@ -84082,6 +84187,18 @@ class AgentProcessManager {
84082
84187
  const harness = slot.harness;
84083
84188
  const model = slot.model;
84084
84189
  const workingDir = slot.workingDir;
84190
+ const harnessSessionId = slot.harnessSessionId;
84191
+ if (harness && harnessSessionId && getHarnessCapabilities(harness).supportsSessionResume && shouldRetainHarnessSessionForReconnect(stopReason)) {
84192
+ const service = this.deps.agentServices.get(harness);
84193
+ const harnessMeta = service ? this.readHarnessReconnectMetadata(service, opts.pid) : undefined;
84194
+ this.recordLastHarnessSession(key, {
84195
+ harnessSessionId,
84196
+ harness,
84197
+ agentName: harnessMeta?.agentName ?? "",
84198
+ workingDir: workingDir ?? "",
84199
+ model: model ?? harnessMeta?.model
84200
+ });
84201
+ }
84085
84202
  slot.state = "idle";
84086
84203
  slot.pid = undefined;
84087
84204
  slot.startedAt = undefined;
@@ -84108,13 +84225,10 @@ class AgentProcessManager {
84108
84225
  for (const service of this.deps.agentServices.values()) {
84109
84226
  service.untrack(opts.pid);
84110
84227
  }
84111
- const isIntentionalStop = stopReason === "user.stop" || stopReason === "platform.team_switch" || stopReason === "daemon.shutdown";
84112
- const isDaemonRespawn = stopReason === "daemon.respawn";
84113
- if (isIntentionalStop) {
84114
- this.deps.crashLoop.clear(opts.chatroomId, opts.role);
84115
- return;
84116
- }
84117
- if (isDaemonRespawn) {
84228
+ if (!shouldAutoRestartAfterProcessExit(stopReason)) {
84229
+ if (stopReason === "user.stop" || stopReason === "platform.team_switch" || stopReason === "daemon.shutdown") {
84230
+ this.deps.crashLoop.clear(opts.chatroomId, opts.role);
84231
+ }
84118
84232
  return;
84119
84233
  }
84120
84234
  if (!harness || !workingDir) {
@@ -84473,7 +84587,12 @@ class AgentProcessManager {
84473
84587
  return { success: false, error: `Unknown agent harness: ${opts.agentHarness}` };
84474
84588
  }
84475
84589
  let spawnResult;
84476
- if (wantResume) {
84590
+ const resumePath = decideResumePathOnRestart({
84591
+ supportsSessionResume: getHarnessCapabilities(opts.agentHarness).supportsSessionResume,
84592
+ wantResume,
84593
+ hasStoredSnapshot: this.lastHarnessSessions.has(key)
84594
+ });
84595
+ if (resumePath === "daemon_memory") {
84477
84596
  spawnResult = await this.tryDaemonMemoryResume({
84478
84597
  key,
84479
84598
  chatroomId: opts.chatroomId,
@@ -84590,7 +84709,8 @@ class AgentProcessManager {
84590
84709
  try {
84591
84710
  const harness = slot.harness;
84592
84711
  const service = harness ? this.deps.agentServices.get(harness) : undefined;
84593
- const preserveForResume = opts.reason === "user.stop" && Boolean(slot.harnessSessionId);
84712
+ const supportsResume = harness ? getHarnessCapabilities(harness).supportsSessionResume : false;
84713
+ const preserveForResume = shouldPreserveHarnessTeardown(opts.reason, supportsResume, Boolean(slot.harnessSessionId));
84594
84714
  if (harness && slot.harnessSessionId) {
84595
84715
  if (preserveForResume) {
84596
84716
  const harnessMeta = service ? this.readHarnessReconnectMetadata(service, pid) : undefined;
@@ -84668,6 +84788,7 @@ var AGENT_EXIT_RETRY_INTERVAL_MS = 1e4;
84668
84788
  var init_agent_process_manager = __esm(() => {
84669
84789
  init_orphan_tracker();
84670
84790
  init_api3();
84791
+ init_agent_lifecycle();
84671
84792
  init_types();
84672
84793
  init_generator();
84673
84794
  });
@@ -87367,4 +87488,4 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
87367
87488
  });
87368
87489
  program2.parse();
87369
87490
 
87370
- //# debugId=C18F126578765BC664756E2164756E21
87491
+ //# debugId=738F13B9B9408F0B64756E2164756E21