@moxt-ai/mobius 0.0.320 → 0.0.322

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 (59) hide show
  1. package/dist/acp/adapter/claude/agent-connection.d.ts.map +1 -1
  2. package/dist/acp/adapter/claude/agent-connection.js +3 -1
  3. package/dist/acp/adapter/claude/agent-connection.js.map +1 -1
  4. package/dist/acp/adapter/session-events.d.ts.map +1 -1
  5. package/dist/acp/adapter/session-events.js.map +1 -1
  6. package/dist/acp/agent/in-process-endpoint.d.ts +3 -2
  7. package/dist/acp/agent/in-process-endpoint.d.ts.map +1 -1
  8. package/dist/acp/agent/in-process-endpoint.js.map +1 -1
  9. package/dist/acp/connection/agent-update-stream.d.ts +1 -1
  10. package/dist/acp/connection/agent-update-stream.d.ts.map +1 -1
  11. package/dist/acp/connection/agent-update-stream.js.map +1 -1
  12. package/dist/acp/connection/create-client.d.ts +3 -2
  13. package/dist/acp/connection/create-client.d.ts.map +1 -1
  14. package/dist/acp/connection/create-client.js +0 -3
  15. package/dist/acp/connection/create-client.js.map +1 -1
  16. package/dist/acp/connection/session-notification.d.ts +12 -0
  17. package/dist/acp/connection/session-notification.d.ts.map +1 -0
  18. package/dist/acp/connection/session-notification.js +2 -0
  19. package/dist/acp/connection/session-notification.js.map +1 -0
  20. package/dist/acp/harness/claude/endpoint.d.ts +5 -1
  21. package/dist/acp/harness/claude/endpoint.d.ts.map +1 -1
  22. package/dist/acp/harness/claude/endpoint.js.map +1 -1
  23. package/dist/acp/harness/codex/agent.d.ts +3 -2
  24. package/dist/acp/harness/codex/agent.d.ts.map +1 -1
  25. package/dist/acp/harness/codex/agent.js.map +1 -1
  26. package/dist/acp/harness/codex/borrowed-agent.d.ts +3 -2
  27. package/dist/acp/harness/codex/borrowed-agent.d.ts.map +1 -1
  28. package/dist/acp/harness/codex/borrowed-agent.js +2 -2
  29. package/dist/acp/harness/codex/borrowed-agent.js.map +1 -1
  30. package/dist/acp/harness/codex/history.d.ts +2 -2
  31. package/dist/acp/harness/codex/history.d.ts.map +1 -1
  32. package/dist/acp/harness/codex/history.js.map +1 -1
  33. package/dist/acp/harness/codex/owned-agent.d.ts +4 -3
  34. package/dist/acp/harness/codex/owned-agent.d.ts.map +1 -1
  35. package/dist/acp/harness/codex/owned-agent.js +3 -7
  36. package/dist/acp/harness/codex/owned-agent.js.map +1 -1
  37. package/dist/acp/harness/codex/session-update.d.ts +17 -0
  38. package/dist/acp/harness/codex/session-update.d.ts.map +1 -0
  39. package/dist/acp/harness/codex/session-update.js +2 -0
  40. package/dist/acp/harness/codex/session-update.js.map +1 -0
  41. package/dist/cli.js +170 -88
  42. package/dist/cli.js.map +3 -3
  43. package/dist/daemon/lifecycle/manager.d.ts.map +1 -1
  44. package/dist/daemon/lifecycle/manager.js +2 -0
  45. package/dist/daemon/lifecycle/manager.js.map +1 -1
  46. package/dist/daemon/upgrades/data.d.ts +1 -0
  47. package/dist/daemon/upgrades/data.d.ts.map +1 -1
  48. package/dist/daemon/upgrades/data.js +6 -1
  49. package/dist/daemon/upgrades/data.js.map +1 -1
  50. package/dist/runtime.js +140 -79
  51. package/dist/runtime.js.map +3 -3
  52. package/dist/session/manager/session-manager.d.ts.map +1 -1
  53. package/dist/session/manager/session-manager.js +8 -6
  54. package/dist/session/manager/session-manager.js.map +1 -1
  55. package/dist/storage/daemon/version-data.d.ts +5 -0
  56. package/dist/storage/daemon/version-data.d.ts.map +1 -1
  57. package/dist/storage/daemon/version-data.js +22 -0
  58. package/dist/storage/daemon/version-data.js.map +1 -1
  59. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -2086,7 +2086,7 @@ var init_package = __esm({
2086
2086
  "package.json"() {
2087
2087
  package_default = {
2088
2088
  name: "@moxt-ai/mobius",
2089
- version: "0.0.320",
2089
+ version: "0.0.322",
2090
2090
  description: "Mobius CLI for pairing and running local AI agent services.",
2091
2091
  type: "module",
2092
2092
  bin: {
@@ -5955,9 +5955,7 @@ var init_create_client = __esm({
5955
5955
  ).onRequest(
5956
5956
  methods.client.elicitation.create,
5957
5957
  async (context) => await handler.onElicitation(context.params, context.signal)
5958
- ).onNotification(methods.client.session.update, async (context) => {
5959
- await handler.onUpdate(context.params);
5960
- }).onNotification(methods.client.elicitation.complete, async (context) => {
5958
+ ).onNotification(methods.client.elicitation.complete, async (context) => {
5961
5959
  await handler.onElicitationComplete(context.params);
5962
5960
  });
5963
5961
  }
@@ -65333,6 +65331,7 @@ var init_settings = __esm({
65333
65331
  });
65334
65332
 
65335
65333
  // src/acp/harness/claude/upstream/dist/session-mode.js
65334
+ import { randomUUID as randomUUID4 } from "node:crypto";
65336
65335
  import { RequestError as RequestError3 } from "@agentclientprotocol/sdk";
65337
65336
  var MODE_CONFIG_ID, AUTO_MODE_FALLBACK, AUTO_MODE_FALLBACK_NOTICE, SessionModeManager;
65338
65337
  var init_session_mode = __esm({
@@ -65461,11 +65460,13 @@ var init_session_mode = __esm({
65461
65460
  return;
65462
65461
  }
65463
65462
  session.autoModeFallbackWarningShown = true;
65463
+ const messageId = randomUUID4();
65464
65464
  try {
65465
65465
  await this.options.sessionUpdate({
65466
65466
  sessionId,
65467
65467
  update: {
65468
65468
  sessionUpdate: "agent_message_chunk",
65469
+ messageId,
65469
65470
  content: { type: "text", text: AUTO_MODE_FALLBACK_NOTICE }
65470
65471
  }
65471
65472
  });
@@ -65557,7 +65558,7 @@ var init_session_mode = __esm({
65557
65558
 
65558
65559
  // src/acp/harness/claude/upstream/dist/acp-agent.js
65559
65560
  import { execFile } from "node:child_process";
65560
- import { randomUUID as randomUUID4 } from "node:crypto";
65561
+ import { randomUUID as randomUUID5 } from "node:crypto";
65561
65562
  import { existsSync as existsSync3 } from "node:fs";
65562
65563
  import * as fs4 from "node:fs/promises";
65563
65564
  import * as os3 from "node:os";
@@ -65833,7 +65834,7 @@ async function authenticateMcpServer(host, sessionId, query, serverName) {
65833
65834
  if (!login.authUrl) {
65834
65835
  throw new Error("Claude Code requested user action without returning an authorization URL");
65835
65836
  }
65836
- const elicitationId = `mcp-oauth-${randomUUID4()}`;
65837
+ const elicitationId = `mcp-oauth-${randomUUID5()}`;
65837
65838
  const flowAbort = new AbortController();
65838
65839
  const abortFlow = () => flowAbort.abort(session.abortController.signal.reason);
65839
65840
  session.abortController.signal.addEventListener("abort", abortFlow, { once: true });
@@ -66579,17 +66580,12 @@ ${chunk.resource.text}
66579
66580
  function messageIdForGrouping(message) {
66580
66581
  if (message.type === "assistant") {
66581
66582
  const inner = message.message;
66582
- const apiId = inner && typeof inner === "object" && "id" in inner ? inner.id : void 0;
66583
+ const apiId = inner !== null && typeof inner === "object" ? Reflect.get(inner, "id") : void 0;
66583
66584
  if (typeof apiId === "string" && apiId.length > 0) {
66584
66585
  return apiId;
66585
66586
  }
66586
66587
  }
66587
- return typeof message.uuid === "string" && message.uuid.length > 0 ? message.uuid : void 0;
66588
- }
66589
- function applyMessageId(update, messageId) {
66590
- if (messageId && (update.sessionUpdate === "agent_message_chunk" || update.sessionUpdate === "user_message_chunk" || update.sessionUpdate === "agent_thought_chunk")) {
66591
- update.messageId = messageId;
66592
- }
66588
+ return message.uuid;
66593
66589
  }
66594
66590
  function isTaskTool(toolName) {
66595
66591
  return toolName === "TaskCreate" || toolName === "TaskUpdate" || toolName === "TaskList" || toolName === "TaskGet";
@@ -66680,14 +66676,15 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, client2, log
66680
66676
  if (content.length === 0) {
66681
66677
  return [];
66682
66678
  }
66679
+ const messageId = options.messageId;
66683
66680
  const update = {
66684
66681
  sessionUpdate: role === "assistant" ? "agent_message_chunk" : "user_message_chunk",
66682
+ messageId,
66685
66683
  content: {
66686
66684
  type: "text",
66687
66685
  text: content
66688
66686
  }
66689
66687
  };
66690
- applyMessageId(update, options?.messageId);
66691
66688
  if (options?.parentToolUseId) {
66692
66689
  update._meta = {
66693
66690
  ...update._meta,
@@ -66708,8 +66705,10 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, client2, log
66708
66705
  case "text":
66709
66706
  case "text_delta": {
66710
66707
  if (chunk.text) {
66708
+ const messageId = options.messageId;
66711
66709
  update = {
66712
66710
  sessionUpdate: role === "assistant" ? "agent_message_chunk" : "user_message_chunk",
66711
+ messageId,
66713
66712
  content: {
66714
66713
  type: "text",
66715
66714
  text: chunk.text
@@ -66718,9 +66717,11 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, client2, log
66718
66717
  }
66719
66718
  break;
66720
66719
  }
66721
- case "image":
66720
+ case "image": {
66721
+ const messageId = options.messageId;
66722
66722
  update = {
66723
66723
  sessionUpdate: role === "assistant" ? "agent_message_chunk" : "user_message_chunk",
66724
+ messageId,
66724
66725
  content: {
66725
66726
  type: "image",
66726
66727
  data: chunk.source.type === "base64" ? chunk.source.data : "",
@@ -66729,11 +66730,14 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, client2, log
66729
66730
  }
66730
66731
  };
66731
66732
  break;
66733
+ }
66732
66734
  case "thinking":
66733
66735
  case "thinking_delta": {
66734
66736
  if (chunk.thinking) {
66737
+ const messageId = options.messageId;
66735
66738
  update = {
66736
66739
  sessionUpdate: "agent_thought_chunk",
66740
+ messageId,
66737
66741
  content: {
66738
66742
  type: "text",
66739
66743
  text: chunk.thinking
@@ -66948,7 +66952,6 @@ function toAcpNotifications(content, role, sessionId, toolUseCache, client2, log
66948
66952
  }
66949
66953
  };
66950
66954
  }
66951
- applyMessageId(update, options?.messageId);
66952
66955
  output2.push({ sessionId, update });
66953
66956
  }
66954
66957
  }
@@ -67028,7 +67031,6 @@ function streamEventToAcpNotifications(message, sessionId, toolUseCache, client2
67028
67031
  }
67029
67032
  };
67030
67033
  }
67031
- applyMessageId(update, options?.messageId);
67032
67034
  return [{ sessionId, update }];
67033
67035
  }
67034
67036
  return toAcpNotifications([event.delta], "assistant", sessionId, toolUseCache, client2, logger, forwardedOptions);
@@ -67688,7 +67690,7 @@ var init_acp_agent = __esm({
67688
67690
  await this.publishTaskPlan(params.sessionId, session.taskState);
67689
67691
  }
67690
67692
  const userMessage = promptToClaude(params);
67691
- const promptUuid = randomUUID4();
67693
+ const promptUuid = randomUUID5();
67692
67694
  userMessage.uuid = promptUuid;
67693
67695
  const firstText = params.prompt[0]?.type === "text" ? params.prompt[0].text : "";
67694
67696
  const isLocalOnlyCommand = firstText.startsWith("/") && LOCAL_ONLY_COMMANDS.has(firstText.split(" ", 1)[0]);
@@ -67840,7 +67842,7 @@ var init_acp_agent = __esm({
67840
67842
  prompt: params.prompt
67841
67843
  };
67842
67844
  const userMessage = promptToClaude(promptRequest);
67843
- const steeredUuid = randomUUID4();
67845
+ const steeredUuid = randomUUID5();
67844
67846
  userMessage.uuid = steeredUuid;
67845
67847
  userMessage.priority = (session.pendingUserInputCount ?? 0) > 0 ? STEER_PRIORITY_LATER : STEER_PRIORITY_NOW;
67846
67848
  turnInFlight.steeredEchoes ??= /* @__PURE__ */ new Set();
@@ -68233,7 +68235,7 @@ var init_acp_agent = __esm({
68233
68235
  case "status": {
68234
68236
  if (message.status === "compacting") {
68235
68237
  if (compaction === null) {
68236
- compaction = { id: randomUUID4() };
68238
+ compaction = { id: randomUUID5() };
68237
68239
  await sendUpdate({
68238
68240
  sessionId: message.session_id,
68239
68241
  update: {
@@ -68290,6 +68292,7 @@ var init_acp_agent = __esm({
68290
68292
  sessionId: message.session_id,
68291
68293
  update: {
68292
68294
  sessionUpdate: "agent_message_chunk",
68295
+ messageId: message.uuid,
68293
68296
  content: { type: "text", text: message.content }
68294
68297
  }
68295
68298
  });
@@ -68406,6 +68409,7 @@ var init_acp_agent = __esm({
68406
68409
  sessionId: message.session_id,
68407
68410
  update: {
68408
68411
  sessionUpdate: "agent_message_chunk",
68412
+ messageId: message.uuid,
68409
68413
  content: { type: "text", text: text2 }
68410
68414
  }
68411
68415
  });
@@ -68503,6 +68507,7 @@ ${message.api_refusal_explanation}` : "";
68503
68507
  sessionId: message.session_id,
68504
68508
  update: {
68505
68509
  sessionUpdate: "agent_message_chunk",
68510
+ messageId: message.uuid,
68506
68511
  content: {
68507
68512
  type: "text",
68508
68513
  text: `**Model fallback:** ${message.original_model} declined this request${category}; retried with ${message.fallback_model}. ${outcome}${explanation}`
@@ -68654,6 +68659,7 @@ ${message.api_refusal_explanation}` : "";
68654
68659
  sessionId: params.sessionId,
68655
68660
  update: {
68656
68661
  sessionUpdate: "agent_message_chunk",
68662
+ messageId: message.uuid,
68657
68663
  content: { type: "text", text: lastRefusalExplanation }
68658
68664
  }
68659
68665
  });
@@ -68677,7 +68683,7 @@ ${message.api_refusal_explanation}` : "";
68677
68683
  break;
68678
68684
  }
68679
68685
  if (session.activeTurn?.isLocalOnlyCommand || !deliveredAssistantText && (message.usage.output_tokens ?? 0) === 0) {
68680
- for (const notification of toAcpNotifications(message.result, "assistant", params.sessionId, session.toolUseCache, this.client, this.logger)) {
68686
+ for (const notification of toAcpNotifications(message.result, "assistant", params.sessionId, session.toolUseCache, this.client, this.logger, { messageId: message.uuid })) {
68681
68687
  await sendUpdate(notification);
68682
68688
  }
68683
68689
  }
@@ -68797,6 +68803,12 @@ ${message.api_refusal_explanation}` : "";
68797
68803
  });
68798
68804
  }
68799
68805
  }
68806
+ if (currentStreamMessageId === void 0) {
68807
+ if (message.event.type !== "content_block_start" && message.event.type !== "content_block_delta") {
68808
+ break;
68809
+ }
68810
+ throw RequestError4.internalError({ code: "invalid_message_boundary" });
68811
+ }
68800
68812
  for (const notification of streamEventToAcpNotifications(message, params.sessionId, session.toolUseCache, this.client, this.logger, {
68801
68813
  clientCapabilities: this.clientCapabilities,
68802
68814
  cwd: session.cwd,
@@ -68827,10 +68839,14 @@ ${message.api_refusal_explanation}` : "";
68827
68839
  if (message.parent_tool_use_id !== null && !(session.forwardSubagentText || supportsSubagentTranscript(this.clientCapabilities))) {
68828
68840
  break;
68829
68841
  }
68830
- const mappedMessageId = messageIdForGrouping(message);
68831
- if (mappedMessageId && typeof message.uuid === "string" && message.uuid.length > 0) {
68832
- session.messageIdToUuid.set(mappedMessageId, message.uuid);
68842
+ if (message.uuid === void 0) {
68843
+ throw RequestError4.internalError({ code: "invalid_source_message" });
68833
68844
  }
68845
+ const mappedMessageId = messageIdForGrouping({
68846
+ type: message.type,
68847
+ uuid: message.uuid,
68848
+ message: message.message
68849
+ });
68834
68850
  if (message.type === "user" && "uuid" in message && message.uuid) {
68835
68851
  if (session.pendingGoalUpdate?.commandUuid === message.uuid) {
68836
68852
  session.pendingGoalUpdate.started = true;
@@ -68897,7 +68913,7 @@ ${message.api_refusal_explanation}` : "";
68897
68913
  parentToolUseId: message.parent_tool_use_id,
68898
68914
  cwd: session.cwd,
68899
68915
  taskState: session.taskState,
68900
- messageId: messageIdForGrouping(message)
68916
+ messageId: mappedMessageId
68901
68917
  })) {
68902
68918
  await sendUpdate(notification);
68903
68919
  }
@@ -68963,7 +68979,7 @@ ${message.api_refusal_explanation}` : "";
68963
68979
  cwd: session.cwd,
68964
68980
  taskState: session.taskState,
68965
68981
  emittedToolCalls: session.emittedToolCalls,
68966
- messageId: messageIdForGrouping(message),
68982
+ messageId: mappedMessageId,
68967
68983
  toolUseResult: message.type === "user" ? message.tool_use_result : void 0,
68968
68984
  // On the wire since CLI 2.1.216 but not in SDKUserMessage's
68969
68985
  // type, hence the cast. Validated by parseToolResultMeta.
@@ -69312,10 +69328,6 @@ ${message.api_refusal_explanation}` : "";
69312
69328
  }
69313
69329
  }
69314
69330
  const replayMessageId = messageIdForGrouping(message);
69315
- const replaySession = this.sessions[sessionId];
69316
- if (replaySession && replayMessageId && message.uuid) {
69317
- replaySession.messageIdToUuid.set(replayMessageId, message.uuid);
69318
- }
69319
69331
  const parentToolUseId = parentToolUseIdOf(message);
69320
69332
  if (parentToolUseId !== null && !forwardSubagentText) {
69321
69333
  continue;
@@ -69789,10 +69801,12 @@ ${message.api_refusal_explanation}` : "";
69789
69801
  session.fastModeDisabledReason = nextReason;
69790
69802
  this.refreshFastModeOption(session, enabled);
69791
69803
  if (explain) {
69804
+ const messageId = randomUUID5();
69792
69805
  await this.client.sessionUpdate({
69793
69806
  sessionId,
69794
69807
  update: {
69795
69808
  sessionUpdate: "agent_message_chunk",
69809
+ messageId,
69796
69810
  content: {
69797
69811
  type: "text",
69798
69812
  text: `**Fast mode turned off:** ${FAST_MODE_UNAVAILABLE_EXPLANATIONS[nextReason]}.`
@@ -69863,7 +69877,7 @@ ${message.api_refusal_explanation}` : "";
69863
69877
  } else if (creationOpts.resume) {
69864
69878
  sessionId = creationOpts.resume;
69865
69879
  } else {
69866
- sessionId = randomUUID4();
69880
+ sessionId = randomUUID5();
69867
69881
  }
69868
69882
  const input2 = new Pushable();
69869
69883
  const settingsManager = new SettingsManager(params.cwd, {
@@ -70061,7 +70075,7 @@ ${message.api_refusal_explanation}` : "";
70061
70075
  ...acpAdditionalDirectories
70062
70076
  ];
70063
70077
  if (creationOpts?.resume === void 0) {
70064
- options.sessionId = creationOpts.publicSessionId ? randomUUID4() : sessionId;
70078
+ options.sessionId = creationOpts.publicSessionId ? randomUUID5() : sessionId;
70065
70079
  }
70066
70080
  if (abortController?.signal.aborted) {
70067
70081
  throw new Error("Cancelled");
@@ -70156,8 +70170,7 @@ ${message.api_refusal_explanation}` : "";
70156
70170
  emittedToolCalls: /* @__PURE__ */ new Set(),
70157
70171
  liveBackgroundTasks: /* @__PURE__ */ new Map(),
70158
70172
  emittedAssistantText: false,
70159
- idleBoundary: { kind: "unaccounted" },
70160
- messageIdToUuid: /* @__PURE__ */ new Map()
70173
+ idleBoundary: { kind: "unaccounted" }
70161
70174
  };
70162
70175
  return {
70163
70176
  sessionId,
@@ -70316,7 +70329,9 @@ var init_agent_connection = __esm({
70316
70329
  command: options.command,
70317
70330
  cwd: options.cwd,
70318
70331
  environment: options.environment,
70319
- onSessionUpdate: options.client.onUpdate,
70332
+ onSessionUpdate: async (notification) => {
70333
+ await options.client.onUpdate(notification);
70334
+ },
70320
70335
  onBackgroundActivity: (active) => options.onBackgroundActivity?.(active)
70321
70336
  });
70322
70337
  super(endpoint, options.client);
@@ -72130,7 +72145,7 @@ var init_items = __esm({
72130
72145
  });
72131
72146
 
72132
72147
  // src/acp/harness/codex/borrowed-agent.ts
72133
- import { randomUUID as randomUUID5 } from "node:crypto";
72148
+ import { randomUUID as randomUUID6 } from "node:crypto";
72134
72149
  import { setTimeout as setTimeout2 } from "node:timers/promises";
72135
72150
  var REQUEST_TIMEOUT, POLL_INTERVAL, queueResponseSchema, queuePageSchema, CodexBorrowedAcpAgent;
72136
72151
  var init_borrowed_agent = __esm({
@@ -72240,7 +72255,7 @@ var init_borrowed_agent = __esm({
72240
72255
  if (!baseline && !this.#seen.has(key) && clientId !== this.#pending?.clientId && text2.length > 0) {
72241
72256
  await this.#emit({
72242
72257
  sessionUpdate: "user_message_chunk",
72243
- messageId: key,
72258
+ messageId: item.id,
72244
72259
  content: { type: "text", text: text2 }
72245
72260
  });
72246
72261
  }
@@ -72258,7 +72273,7 @@ var init_borrowed_agent = __esm({
72258
72273
  if (text2.length > 0) {
72259
72274
  await this.#emit({
72260
72275
  sessionUpdate: item.type === "agentMessage" ? "agent_message_chunk" : "agent_thought_chunk",
72261
- messageId: key,
72276
+ messageId: item.id,
72262
72277
  content: { type: "text", text: text2 }
72263
72278
  });
72264
72279
  }
@@ -72298,7 +72313,7 @@ var init_borrowed_agent = __esm({
72298
72313
  if (this.#pending !== null) {
72299
72314
  throw new AcpExecutionError("Another prompt is already running", {}, "session_busy");
72300
72315
  }
72301
- const pending = { clientId: randomUUID5(), completion: Promise.withResolvers() };
72316
+ const pending = { clientId: randomUUID6(), completion: Promise.withResolvers() };
72302
72317
  this.#pending = pending;
72303
72318
  void pending.completion.promise.catch(() => {
72304
72319
  });
@@ -72694,7 +72709,7 @@ var init_history_images = __esm({
72694
72709
  });
72695
72710
 
72696
72711
  // src/acp/harness/codex/owned-agent.ts
72697
- import { randomUUID as randomUUID6 } from "node:crypto";
72712
+ import { randomUUID as randomUUID7 } from "node:crypto";
72698
72713
  import { setTimeout as delay } from "node:timers/promises";
72699
72714
  import { methods as methods3 } from "@agentclientprotocol/sdk";
72700
72715
  function permissionDecision(optionId) {
@@ -72924,7 +72939,7 @@ var init_owned_agent = __esm({
72924
72939
  signal.throwIfAborted();
72925
72940
  const open7 = this.#settleCompaction("failed", cause instanceof Error ? cause.message : String(cause));
72926
72941
  if (open7 === null && !this.#turnSettledCompaction) {
72927
- const compactionId = randomUUID6();
72942
+ const compactionId = randomUUID7();
72928
72943
  await this.#enqueue(async () => {
72929
72944
  await this.#context.emit({
72930
72945
  compactionId,
@@ -72946,13 +72961,9 @@ var init_owned_agent = __esm({
72946
72961
  };
72947
72962
  /** Pushes the current settings so a mode change Codex applied reaches the Run settings panel. */
72948
72963
  #emitConfigOptionsUpdate = async () => {
72949
- const connection = this.#context.connection();
72950
- if (connection === null || this.#context.threadId().length === 0) {
72951
- return;
72952
- }
72953
- await connection.client.notify(methods3.client.session.update, {
72954
- sessionId: this.#context.threadId(),
72955
- update: { configOptions: this.#settings.configOptions(), sessionUpdate: "config_option_update" }
72964
+ await this.#context.emit({
72965
+ configOptions: this.#settings.configOptions(),
72966
+ sessionUpdate: "config_option_update"
72956
72967
  });
72957
72968
  };
72958
72969
  // Notifications are serialized so two app-server items cannot interleave into one ACP update
@@ -78332,7 +78343,7 @@ var init_pi_tools = __esm({
78332
78343
  });
78333
78344
 
78334
78345
  // src/acp/harness/pi/upstream/dist/acp/session.js
78335
- import { randomUUID as randomUUID7 } from "node:crypto";
78346
+ import { randomUUID as randomUUID8 } from "node:crypto";
78336
78347
  import { readFileSync as readFileSync7 } from "node:fs";
78337
78348
  import { isAbsolute as isAbsolute11, resolve as resolvePath } from "node:path";
78338
78349
  import { RequestError as RequestError7 } from "@agentclientprotocol/sdk";
@@ -78611,13 +78622,13 @@ var init_session = __esm({
78611
78622
  return settled;
78612
78623
  }
78613
78624
  if (this.activeCompactionId === null) {
78614
- this.activeCompactionId = randomUUID7();
78625
+ this.activeCompactionId = randomUUID8();
78615
78626
  }
78616
78627
  return this.activeCompactionId;
78617
78628
  }
78618
78629
  /** Opening half of compactionId: always returns an id. */
78619
78630
  openCompactionId() {
78620
- return this.compactionId(true) ?? randomUUID7();
78631
+ return this.compactionId(true) ?? randomUUID8();
78621
78632
  }
78622
78633
  constructor(opts) {
78623
78634
  this.sessionId = opts.sessionId;
@@ -78627,7 +78638,11 @@ var init_session = __esm({
78627
78638
  this.conn = opts.conn;
78628
78639
  this.fileCommands = opts.fileCommands ?? [];
78629
78640
  this.extensionQuestions = new PiExtensionQuestions(this.sessionId, this.conn, this.proc, async (text2) => {
78630
- this.emit({ sessionUpdate: "agent_message_chunk", content: { type: "text", text: text2 } });
78641
+ this.emit({
78642
+ sessionUpdate: "agent_message_chunk",
78643
+ messageId: randomUUID8(),
78644
+ content: { type: "text", text: text2 }
78645
+ });
78631
78646
  await this.flushEmits();
78632
78647
  });
78633
78648
  this.proc.signal.addEventListener("abort", () => {
@@ -78674,6 +78689,7 @@ var init_session = __esm({
78674
78689
  this.startupInfoSent = true;
78675
78690
  this.emit({
78676
78691
  sessionUpdate: "agent_message_chunk",
78692
+ messageId: randomUUID8(),
78677
78693
  content: { type: "text", text: this.startupInfo }
78678
78694
  });
78679
78695
  }
@@ -78685,6 +78701,7 @@ var init_session = __esm({
78685
78701
  this.turnQueue.push(queued);
78686
78702
  this.emit({
78687
78703
  sessionUpdate: "agent_message_chunk",
78704
+ messageId: randomUUID8(),
78688
78705
  content: {
78689
78706
  type: "text",
78690
78707
  text: `Queued message (position ${this.turnQueue.length}).`
@@ -78751,6 +78768,7 @@ var init_session = __esm({
78751
78768
  }
78752
78769
  this.emit({
78753
78770
  sessionUpdate: "agent_message_chunk",
78771
+ messageId: randomUUID8(),
78754
78772
  content: { type: "text", text: "Cleared queued prompts." }
78755
78773
  });
78756
78774
  this.emit({
@@ -78823,6 +78841,7 @@ var init_session = __esm({
78823
78841
  if (next) {
78824
78842
  this.emit({
78825
78843
  sessionUpdate: "agent_message_chunk",
78844
+ messageId: randomUUID8(),
78826
78845
  content: { type: "text", text: `Starting queued message. (${this.turnQueue.length} remaining)` }
78827
78846
  });
78828
78847
  this.startTurn(next);
@@ -78890,24 +78909,41 @@ var init_session = __esm({
78890
78909
  void err;
78891
78910
  });
78892
78911
  }
78912
+ streamedMessage = {
78913
+ kind: "idle"
78914
+ };
78893
78915
  handlePiEvent(ev2) {
78894
78916
  const type = String(ev2.type ?? "");
78895
78917
  switch (type) {
78918
+ case "message_start":
78919
+ this.streamedMessage = { kind: "active", messageId: randomUUID8() };
78920
+ break;
78921
+ case "message_end":
78922
+ this.streamedMessage = { kind: "idle" };
78923
+ break;
78896
78924
  case "message_update": {
78897
78925
  const ame2 = ev2.assistantMessageEvent;
78898
78926
  if (this.turnRetryFailure !== null && (ame2?.type === "text_delta" || ame2?.type === "thinking_delta" || ame2?.type === "toolcall_start")) {
78899
78927
  this.turnRetryFailure = null;
78900
78928
  }
78901
78929
  if (ame2?.type === "text_delta" && typeof ame2.delta === "string") {
78930
+ if (this.streamedMessage.kind !== "active") {
78931
+ throw RequestError7.internalError({ code: "invalid_message_boundary" });
78932
+ }
78902
78933
  this.emit({
78903
78934
  sessionUpdate: "agent_message_chunk",
78935
+ messageId: this.streamedMessage.messageId,
78904
78936
  content: { type: "text", text: ame2.delta }
78905
78937
  });
78906
78938
  break;
78907
78939
  }
78908
78940
  if (ame2?.type === "thinking_delta" && typeof ame2.delta === "string") {
78941
+ if (this.streamedMessage.kind !== "active") {
78942
+ throw RequestError7.internalError({ code: "invalid_message_boundary" });
78943
+ }
78909
78944
  this.emit({
78910
78945
  sessionUpdate: "agent_thought_chunk",
78946
+ messageId: this.streamedMessage.messageId,
78911
78947
  content: { type: "text", text: ame2.delta }
78912
78948
  });
78913
78949
  break;
@@ -79114,6 +79150,7 @@ var init_session = __esm({
79114
79150
  if (ev2.method === "notify") {
79115
79151
  this.emit({
79116
79152
  sessionUpdate: "agent_message_chunk",
79153
+ messageId: randomUUID8(),
79117
79154
  content: { type: "text", text: stringProp(ev2, "message") ?? "Pi notification" },
79118
79155
  _meta: { piAcp: { notify: { level: stringProp(ev2, "notifyType") ?? "info" } } }
79119
79156
  });
@@ -79258,7 +79295,7 @@ var init_prompt = __esm({
79258
79295
 
79259
79296
  // src/acp/harness/pi/upstream/dist/acp/agent.js
79260
79297
  import { spawnSync } from "node:child_process";
79261
- import { randomUUID as randomUUID8 } from "node:crypto";
79298
+ import { randomUUID as randomUUID9 } from "node:crypto";
79262
79299
  import { existsSync as existsSync7, readdirSync as readdirSync6, readFileSync as readFileSync8, realpathSync as realpathSync3, statSync as statSync3, unlinkSync as unlinkSync2 } from "node:fs";
79263
79300
  import { basename as basename6, dirname as dirname9, isAbsolute as isAbsolute12, join as join20 } from "node:path";
79264
79301
  import { RequestError as RequestError8 } from "@agentclientprotocol/sdk";
@@ -79952,7 +79989,7 @@ var init_agent2 = __esm({
79952
79989
  const args = parseCommandArgs(argsString);
79953
79990
  if (cmd === "compact") {
79954
79991
  const customInstructions = args.join(" ").trim() || void 0;
79955
- const compactionId = randomUUID8();
79992
+ const compactionId = randomUUID9();
79956
79993
  await this.conn.sessionUpdate({
79957
79994
  sessionId: session.sessionId,
79958
79995
  update: {
@@ -80041,6 +80078,7 @@ ${JSON.stringify(stats, null, 2)}`;
80041
80078
  sessionId: session.sessionId,
80042
80079
  update: {
80043
80080
  sessionUpdate: "agent_message_chunk",
80081
+ messageId: randomUUID9(),
80044
80082
  content: { type: "text", text: text2 }
80045
80083
  }
80046
80084
  });
@@ -80053,6 +80091,7 @@ ${JSON.stringify(stats, null, 2)}`;
80053
80091
  sessionId: session.sessionId,
80054
80092
  update: {
80055
80093
  sessionUpdate: "agent_message_chunk",
80094
+ messageId: randomUUID9(),
80056
80095
  content: { type: "text", text: "Usage: /name <name>" }
80057
80096
  }
80058
80097
  });
@@ -80067,6 +80106,7 @@ ${JSON.stringify(stats, null, 2)}`;
80067
80106
  sessionId: session.sessionId,
80068
80107
  update: {
80069
80108
  sessionUpdate: "agent_message_chunk",
80109
+ messageId: randomUUID9(),
80070
80110
  content: { type: "text", text: `Failed to set session name: ${msg}${hint}` }
80071
80111
  }
80072
80112
  });
@@ -80084,6 +80124,7 @@ ${JSON.stringify(stats, null, 2)}`;
80084
80124
  sessionId: session.sessionId,
80085
80125
  update: {
80086
80126
  sessionUpdate: "agent_message_chunk",
80127
+ messageId: randomUUID9(),
80087
80128
  content: { type: "text", text: `Session name set: ${name2}` }
80088
80129
  }
80089
80130
  });
@@ -80098,6 +80139,7 @@ ${JSON.stringify(stats, null, 2)}`;
80098
80139
  sessionId: session.sessionId,
80099
80140
  update: {
80100
80141
  sessionUpdate: "agent_message_chunk",
80142
+ messageId: randomUUID9(),
80101
80143
  content: {
80102
80144
  type: "text",
80103
80145
  text: `Steering mode: ${current || "unknown"}`
@@ -80111,6 +80153,7 @@ ${JSON.stringify(stats, null, 2)}`;
80111
80153
  sessionId: session.sessionId,
80112
80154
  update: {
80113
80155
  sessionUpdate: "agent_message_chunk",
80156
+ messageId: randomUUID9(),
80114
80157
  content: {
80115
80158
  type: "text",
80116
80159
  text: "Usage: /steering all | /steering one-at-a-time"
@@ -80124,6 +80167,7 @@ ${JSON.stringify(stats, null, 2)}`;
80124
80167
  sessionId: session.sessionId,
80125
80168
  update: {
80126
80169
  sessionUpdate: "agent_message_chunk",
80170
+ messageId: randomUUID9(),
80127
80171
  content: { type: "text", text: `Steering mode set to: ${modeRaw}` }
80128
80172
  }
80129
80173
  });
@@ -80138,6 +80182,7 @@ ${JSON.stringify(stats, null, 2)}`;
80138
80182
  sessionId: session.sessionId,
80139
80183
  update: {
80140
80184
  sessionUpdate: "agent_message_chunk",
80185
+ messageId: randomUUID9(),
80141
80186
  content: {
80142
80187
  type: "text",
80143
80188
  text: `Follow-up mode: ${current || "unknown"}`
@@ -80151,6 +80196,7 @@ ${JSON.stringify(stats, null, 2)}`;
80151
80196
  sessionId: session.sessionId,
80152
80197
  update: {
80153
80198
  sessionUpdate: "agent_message_chunk",
80199
+ messageId: randomUUID9(),
80154
80200
  content: {
80155
80201
  type: "text",
80156
80202
  text: "Usage: /follow-up all | /follow-up one-at-a-time"
@@ -80164,6 +80210,7 @@ ${JSON.stringify(stats, null, 2)}`;
80164
80210
  sessionId: session.sessionId,
80165
80211
  update: {
80166
80212
  sessionUpdate: "agent_message_chunk",
80213
+ messageId: randomUUID9(),
80167
80214
  content: { type: "text", text: `Follow-up mode set to: ${modeRaw}` }
80168
80215
  }
80169
80216
  });
@@ -80204,6 +80251,7 @@ ${JSON.stringify(stats, null, 2)}`;
80204
80251
  sessionId: session.sessionId,
80205
80252
  update: {
80206
80253
  sessionUpdate: "agent_message_chunk",
80254
+ messageId: randomUUID9(),
80207
80255
  content: { type: "text", text: "Changelog not found (couldn't locate pi installation)." }
80208
80256
  }
80209
80257
  });
@@ -80217,6 +80265,7 @@ ${JSON.stringify(stats, null, 2)}`;
80217
80265
  sessionId: session.sessionId,
80218
80266
  update: {
80219
80267
  sessionUpdate: "agent_message_chunk",
80268
+ messageId: randomUUID9(),
80220
80269
  content: { type: "text", text: `Failed to read changelog: ${String(e?.message ?? e)}` }
80221
80270
  }
80222
80271
  });
@@ -80232,6 +80281,7 @@ ${JSON.stringify(stats, null, 2)}`;
80232
80281
  sessionId: session.sessionId,
80233
80282
  update: {
80234
80283
  sessionUpdate: "agent_message_chunk",
80284
+ messageId: randomUUID9(),
80235
80285
  content: { type: "text", text: text2 }
80236
80286
  }
80237
80287
  });
@@ -80246,6 +80296,7 @@ ${JSON.stringify(stats, null, 2)}`;
80246
80296
  sessionId: session.sessionId,
80247
80297
  update: {
80248
80298
  sessionUpdate: "agent_message_chunk",
80299
+ messageId: randomUUID9(),
80249
80300
  content: {
80250
80301
  type: "text",
80251
80302
  text: "Nothing to export yet (no session messages). Send a prompt first."
@@ -80261,6 +80312,7 @@ ${JSON.stringify(stats, null, 2)}`;
80261
80312
  sessionId: session.sessionId,
80262
80313
  update: {
80263
80314
  sessionUpdate: "agent_message_chunk",
80315
+ messageId: randomUUID9(),
80264
80316
  content: {
80265
80317
  type: "text",
80266
80318
  text: "Nothing to export yet (empty session file). Send a prompt first."
@@ -80274,6 +80326,7 @@ ${JSON.stringify(stats, null, 2)}`;
80274
80326
  sessionId: session.sessionId,
80275
80327
  update: {
80276
80328
  sessionUpdate: "agent_message_chunk",
80329
+ messageId: randomUUID9(),
80277
80330
  content: {
80278
80331
  type: "text",
80279
80332
  text: "Couldn't read session file for export. Try sending a prompt first."
@@ -80293,6 +80346,7 @@ ${JSON.stringify(stats, null, 2)}`;
80293
80346
  sessionId: session.sessionId,
80294
80347
  update: {
80295
80348
  sessionUpdate: "agent_message_chunk",
80349
+ messageId: randomUUID9(),
80296
80350
  content: {
80297
80351
  type: "text",
80298
80352
  text: `Export failed: ${String(e?.message ?? e)}`
@@ -80306,6 +80360,7 @@ ${JSON.stringify(stats, null, 2)}`;
80306
80360
  sessionId: session.sessionId,
80307
80361
  update: {
80308
80362
  sessionUpdate: "agent_message_chunk",
80363
+ messageId: randomUUID9(),
80309
80364
  content: {
80310
80365
  type: "text",
80311
80366
  text: "Export failed: no output path returned by pi."
@@ -80315,10 +80370,12 @@ ${JSON.stringify(stats, null, 2)}`;
80315
80370
  return { stopReason: "end_turn" };
80316
80371
  }
80317
80372
  const uri = `file://${resultPath}`;
80373
+ const messageId = randomUUID9();
80318
80374
  await this.conn.sessionUpdate({
80319
80375
  sessionId: session.sessionId,
80320
80376
  update: {
80321
80377
  sessionUpdate: "agent_message_chunk",
80378
+ messageId,
80322
80379
  content: {
80323
80380
  type: "text",
80324
80381
  text: "Session exported: "
@@ -80329,6 +80386,7 @@ ${JSON.stringify(stats, null, 2)}`;
80329
80386
  sessionId: session.sessionId,
80330
80387
  update: {
80331
80388
  sessionUpdate: "agent_message_chunk",
80389
+ messageId,
80332
80390
  content: {
80333
80391
  type: "resource_link",
80334
80392
  name: `pi-session-${safeSessionId}.html`,
@@ -80358,6 +80416,7 @@ ${JSON.stringify(stats, null, 2)}`;
80358
80416
  sessionId: session.sessionId,
80359
80417
  update: {
80360
80418
  sessionUpdate: "agent_message_chunk",
80419
+ messageId: randomUUID9(),
80361
80420
  content: {
80362
80421
  type: "text",
80363
80422
  text: `Auto-compaction ${enabled ? "enabled" : "disabled"}.`
@@ -80593,6 +80652,7 @@ ${JSON.stringify(stats, null, 2)}`;
80593
80652
  sessionId: session.sessionId,
80594
80653
  update: {
80595
80654
  sessionUpdate: "user_message_chunk",
80655
+ messageId: randomUUID9(),
80596
80656
  content: { type: "text", text: text2 }
80597
80657
  }
80598
80658
  });
@@ -80605,6 +80665,7 @@ ${JSON.stringify(stats, null, 2)}`;
80605
80665
  sessionId: session.sessionId,
80606
80666
  update: {
80607
80667
  sessionUpdate: "agent_message_chunk",
80668
+ messageId: randomUUID9(),
80608
80669
  content: { type: "text", text: text2 }
80609
80670
  }
80610
80671
  });
@@ -82892,7 +82953,7 @@ var init_session_event_id_allocator = __esm({
82892
82953
  });
82893
82954
 
82894
82955
  // src/session/history/session-event-store.ts
82895
- import { randomUUID as randomUUID9 } from "node:crypto";
82956
+ import { randomUUID as randomUUID10 } from "node:crypto";
82896
82957
  function liveEvent(sessionId, sessionGenerationId, eventId, position, event, recordedAt = (/* @__PURE__ */ new Date()).toISOString()) {
82897
82958
  return {
82898
82959
  eventId,
@@ -83049,7 +83110,7 @@ var init_session_event_store = __esm({
83049
83110
  this.#eventIds = eventIds;
83050
83111
  }
83051
83112
  #session = (sessionId) => {
83052
- const sessionGenerationId = randomUUID9();
83113
+ const sessionGenerationId = randomUUID10();
83053
83114
  const session = this.#events.get(sessionId) ?? new SessionEvents(sessionGenerationId);
83054
83115
  this.#events.set(sessionId, session);
83055
83116
  return session;
@@ -83114,7 +83175,7 @@ var init_session_event_store = __esm({
83114
83175
  this.#events.delete(sessionId);
83115
83176
  };
83116
83177
  reset = (sessionId) => {
83117
- const sessionGenerationId = randomUUID9();
83178
+ const sessionGenerationId = randomUUID10();
83118
83179
  this.#events.set(sessionId, new SessionEvents(sessionGenerationId));
83119
83180
  };
83120
83181
  };
@@ -83130,7 +83191,7 @@ var init_session_event_store = __esm({
83130
83191
  this.#cacheTable = cacheTable;
83131
83192
  }
83132
83193
  #session = (sessionId) => {
83133
- const sessionGenerationId = randomUUID9();
83194
+ const sessionGenerationId = randomUUID10();
83134
83195
  const session = this.#sessions.get(sessionId) ?? new SessionEvents(sessionGenerationId);
83135
83196
  this.#sessions.set(sessionId, session);
83136
83197
  return session;
@@ -83256,7 +83317,7 @@ var init_session_event_store = __esm({
83256
83317
  reset = (sessionId) => {
83257
83318
  const previous = this.#sessions.get(sessionId);
83258
83319
  this.#deletePersisted(sessionId, previous?.sessionGenerationId);
83259
- const sessionGenerationId = randomUUID9();
83320
+ const sessionGenerationId = randomUUID10();
83260
83321
  this.#sessions.set(sessionId, new SessionEvents(sessionGenerationId));
83261
83322
  };
83262
83323
  materializedEventCount = (sessionId) => this.#sessions.get(sessionId)?.materializedCount ?? 0;
@@ -90594,7 +90655,7 @@ var init_runtime_connection = __esm({
90594
90655
  });
90595
90656
 
90596
90657
  // src/runtime/connection/runtime-installation-store.ts
90597
- import { randomUUID as randomUUID10 } from "node:crypto";
90658
+ import { randomUUID as randomUUID11 } from "node:crypto";
90598
90659
  import { resolve as resolve15 } from "node:path";
90599
90660
  function isRecord7(value) {
90600
90661
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -90657,10 +90718,10 @@ function parseRelayOrigin(value) {
90657
90718
  return origin;
90658
90719
  }
90659
90720
  function connectionId() {
90660
- return `mcn_${randomUUID10().replaceAll("-", "")}`;
90721
+ return `mcn_${randomUUID11().replaceAll("-", "")}`;
90661
90722
  }
90662
90723
  function installationId() {
90663
- return `min_${randomUUID10().replaceAll("-", "")}`;
90724
+ return `min_${randomUUID11().replaceAll("-", "")}`;
90664
90725
  }
90665
90726
  function decodeInstallationPointer(value) {
90666
90727
  if (!isRecord7(value) || !hasExactKeys(value, INSTALLATION_POINTER_KEYS) || value["version"] !== 1) {
@@ -91055,7 +91116,7 @@ var init_runtime_installation_store = __esm({
91055
91116
  });
91056
91117
 
91057
91118
  // src/storage/daemon/version-data.ts
91058
- import { randomUUID as randomUUID11 } from "node:crypto";
91119
+ import { randomUUID as randomUUID12 } from "node:crypto";
91059
91120
  import { cp as cp2, lstat as lstat4, mkdtemp, readFile as readFile7, rename as rename4, rm as rm3, writeFile as writeFile2 } from "node:fs/promises";
91060
91121
  import { join as join25, relative as relative2, sep as sep5 } from "node:path";
91061
91122
  async function readCurrentDataVersion(root, signal) {
@@ -91129,10 +91190,26 @@ async function copyVersionData(root, sourceVersion, targetVersion, signal) {
91129
91190
  await rm3(staging, { recursive: true, force: true });
91130
91191
  }
91131
91192
  }
91193
+ async function discardVersionData(root, version2, signal) {
91194
+ if (await readCurrentDataVersion(root, signal) === version2 || !await versionDataExists(root, version2, signal)) {
91195
+ return;
91196
+ }
91197
+ const versions = join25(root, STATE_ROOT_LAYOUT.versions);
91198
+ const discarded = join25(versions, `.${version2}-discarded-${randomUUID12()}`);
91199
+ try {
91200
+ await rename4(join25(versions, version2), discarded);
91201
+ } catch (cause) {
91202
+ if (isNodeError(cause, "ENOENT")) {
91203
+ return;
91204
+ }
91205
+ throw cause;
91206
+ }
91207
+ await rm3(discarded, { recursive: true, force: true });
91208
+ }
91132
91209
  async function writeCurrentDataVersion(root, version2, signal) {
91133
91210
  await validateLocalPath(root, true, true, signal);
91134
91211
  await validateLocalPath(join25(root, STATE_ROOT_LAYOUT.versions, version2), true, true, signal);
91135
- const temporary = join25(root, `.current-data-${randomUUID11()}.txt`);
91212
+ const temporary = join25(root, `.current-data-${randomUUID12()}.txt`);
91136
91213
  try {
91137
91214
  await writeFile2(temporary, `versions/${version2}
91138
91215
  `, { mode: 384, flag: "wx", signal });
@@ -91369,6 +91446,9 @@ async function prepareVersionData(version2, signal, environment = process.env, f
91369
91446
  );
91370
91447
  }
91371
91448
  }
91449
+ async function discardRolledBackData(version2, signal) {
91450
+ await discardVersionData(readStateDirectory(), runtimeUpgradeVersionSchema.parse(version2), signal);
91451
+ }
91372
91452
  async function recordCurrentData(version2, signal) {
91373
91453
  await writeCurrentDataVersion(readStateDirectory(), runtimeUpgradeVersionSchema.parse(version2), signal);
91374
91454
  }
@@ -92624,6 +92704,7 @@ async function runManager(stateDirectory, signal) {
92624
92704
  retryAfter: Date.now() + 8 * 36e5
92625
92705
  };
92626
92706
  await start(transition2.previous);
92707
+ await discardRolledBackData(transition2.next.version, combined);
92627
92708
  }
92628
92709
  };
92629
92710
  const handle = async (value, requestSignal) => {
@@ -92728,6 +92809,7 @@ var init_manager = __esm({
92728
92809
  init_manager_lock();
92729
92810
  init_local_server();
92730
92811
  init_protocol2();
92812
+ init_data();
92731
92813
  init_unhandled_rejection();
92732
92814
  init_worker_lifecycle_log();
92733
92815
  init_worker_process();
@@ -95979,22 +96061,13 @@ var init_session_manager = __esm({
95979
96061
  throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
95980
96062
  }
95981
96063
  const linked = this.#store.findNative(options2.agent.id, origin.nativeSessionId);
95982
- if (linked.some(
95983
- (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
95984
- )) {
95985
- throw new AcpExecutionError(
95986
- "Wait for the native session's running operation to finish",
95987
- {},
95988
- "session_busy"
95989
- );
95990
- }
95991
96064
  const existing = linked[0];
95992
96065
  if (origin.kind === "import" && existing !== void 0) {
95993
96066
  return await this.#executionProcesses.use(existing.sessionId, async () => {
95994
96067
  this.#closedSessions.delete(existing.sessionId);
95995
96068
  const target2 = await this.#nativeTargetOptions(options2, existing.sessionId, resolveAgent);
95996
96069
  const runtime = await this.ensureSession(target2);
95997
- if (this.#executions.command(existing.sessionId) !== void 0 || this.#nativeOperations.has(key)) {
96070
+ if (this.#nativeOperations.has(key)) {
95998
96071
  throw new AcpExecutionError(
95999
96072
  "Wait for the native session's running operation to finish",
96000
96073
  {},
@@ -96013,6 +96086,15 @@ var init_session_manager = __esm({
96013
96086
  }
96014
96087
  });
96015
96088
  }
96089
+ if (linked.some(
96090
+ (entry) => this.#executions.command(entry.sessionId) !== void 0 || this.#executionProcesses.pending(entry.sessionId) !== void 0
96091
+ )) {
96092
+ throw new AcpExecutionError(
96093
+ "Wait for the native session's running operation to finish",
96094
+ {},
96095
+ "session_busy"
96096
+ );
96097
+ }
96016
96098
  const target = await this.#nativeTargetOptions(options2, options2.sessionId, resolveAgent);
96017
96099
  if (this.#executionProcesses.get(options2.sessionId) !== void 0 || this.#executionProcesses.pending(options2.sessionId) !== void 0 || this.#store.read(options2.sessionId) instanceof FoundStoredSession) {
96018
96100
  throw new AcpExecutionError(
@@ -96073,7 +96155,7 @@ var init_local_authorization_error = __esm({
96073
96155
  });
96074
96156
 
96075
96157
  // src/session/native/native-session-browser.ts
96076
- import { randomUUID as randomUUID12 } from "node:crypto";
96158
+ import { randomUUID as randomUUID13 } from "node:crypto";
96077
96159
  function nextForkTitle(sourceTitle, sessions) {
96078
96160
  let highest = 0;
96079
96161
  for (const session of sessions) {
@@ -96181,7 +96263,7 @@ var init_native_session_browser = __esm({
96181
96263
  if (authorized === null) {
96182
96264
  return null;
96183
96265
  }
96184
- const entryId = decodeIdentifier(randomUUID12());
96266
+ const entryId = decodeIdentifier(randomUUID13());
96185
96267
  if (this.#entries.size >= 5e3) {
96186
96268
  this.#entries.clear();
96187
96269
  }
@@ -96237,7 +96319,7 @@ var init_native_session_browser = __esm({
96237
96319
  "invalid_native_session_response"
96238
96320
  );
96239
96321
  }
96240
- nextCursor = decodeIdentifier(randomUUID12());
96322
+ nextCursor = decodeIdentifier(randomUUID13());
96241
96323
  if (this.#cursors.size >= 500) {
96242
96324
  this.#cursors.clear();
96243
96325
  }
@@ -96608,7 +96690,7 @@ var init_prompt_lifecycle = __esm({
96608
96690
  });
96609
96691
 
96610
96692
  // src/session/turn/execution-receipts.ts
96611
- import { createHash as createHash7, randomUUID as randomUUID13 } from "node:crypto";
96693
+ import { createHash as createHash7, randomUUID as randomUUID14 } from "node:crypto";
96612
96694
  function isTerminal(state) {
96613
96695
  return state === "succeeded" || state === "failed" || state === "cancelled";
96614
96696
  }
@@ -96743,7 +96825,7 @@ var init_execution_receipts = __esm({
96743
96825
  outcome: this.#recoveredCommands.has(commandId) ? this.outcome(commandId) : void 0
96744
96826
  };
96745
96827
  }
96746
- const attemptId = randomUUID13();
96828
+ const attemptId = randomUUID14();
96747
96829
  this.#save(commandId, {
96748
96830
  attemptId,
96749
96831
  commandHash,
@@ -96875,7 +96957,7 @@ var init_runtime_turn_activity = __esm({
96875
96957
  });
96876
96958
 
96877
96959
  // src/session/turn/active-turn.ts
96878
- import { randomUUID as randomUUID14 } from "node:crypto";
96960
+ import { randomUUID as randomUUID15 } from "node:crypto";
96879
96961
  var ActiveRuntimeTurn;
96880
96962
  var init_active_turn = __esm({
96881
96963
  "src/session/turn/active-turn.ts"() {
@@ -96890,7 +96972,7 @@ var init_active_turn = __esm({
96890
96972
  #dispatch;
96891
96973
  #sequence = 0;
96892
96974
  #interaction = null;
96893
- #epoch = decodeIdentifier(randomUUID14());
96975
+ #epoch = decodeIdentifier(randomUUID15());
96894
96976
  constructor(command, attemptId) {
96895
96977
  this.attemptId = attemptId;
96896
96978
  this.command = command;
@@ -97491,11 +97573,11 @@ var init_session_layer = __esm({
97491
97573
  });
97492
97574
 
97493
97575
  // src/storage/files/scratch-directory.ts
97494
- import { randomUUID as randomUUID15 } from "node:crypto";
97576
+ import { randomUUID as randomUUID16 } from "node:crypto";
97495
97577
  import { lstat as lstat6, mkdir as mkdir5, readdir as readdir7, realpath as realpath9, rename as rename5, rm as rm4, stat as stat8, utimes, writeFile as writeFile5 } from "node:fs/promises";
97496
97578
  import { dirname as dirname12, join as join34 } from "node:path";
97497
97579
  async function atomicWrite(path8, bytes, signal) {
97498
- const temporary = `${path8}.${randomUUID15()}.tmp`;
97580
+ const temporary = `${path8}.${randomUUID16()}.tmp`;
97499
97581
  try {
97500
97582
  await writeFile5(temporary, bytes, { mode: 384, signal });
97501
97583
  signal.throwIfAborted();
@@ -97511,7 +97593,7 @@ var init_scratch_directory = __esm({
97511
97593
  ScratchDirectory = class {
97512
97594
  #root;
97513
97595
  constructor(parent) {
97514
- this.#root = join34(parent, randomUUID15());
97596
+ this.#root = join34(parent, randomUUID16());
97515
97597
  }
97516
97598
  /** Refreshes this directory's lease and removes sibling directories whose lease is older than `leaseMilliseconds`. */
97517
97599
  refreshLease = async (leaseMilliseconds) => {
@@ -99590,7 +99672,7 @@ var init_native_sessions = __esm({
99590
99672
  });
99591
99673
 
99592
99674
  // src/session/prompt/apply-session-configuration.ts
99593
- import { randomUUID as randomUUID16 } from "node:crypto";
99675
+ import { randomUUID as randomUUID17 } from "node:crypto";
99594
99676
  function invalidSessionConfiguration(message) {
99595
99677
  return new AcpExecutionError(message, {}, "invalid_session_configuration");
99596
99678
  }
@@ -99728,7 +99810,7 @@ async function applySessionConfigurationSelection(sessions, options, selection,
99728
99810
  booleanValue: selection.booleanValue,
99729
99811
  configId: selection.configId,
99730
99812
  cwd,
99731
- requestId: `cfg_${randomUUID16()}`,
99813
+ requestId: `cfg_${randomUUID17()}`,
99732
99814
  sessionId,
99733
99815
  signal,
99734
99816
  value: selection.value,
@@ -101715,7 +101797,7 @@ var init_engine = __esm({
101715
101797
  });
101716
101798
 
101717
101799
  // src/daemon/upgrades/upgrade.ts
101718
- import { randomUUID as randomUUID17 } from "node:crypto";
101800
+ import { randomUUID as randomUUID18 } from "node:crypto";
101719
101801
  import { setInterval as setInterval2, setTimeout as setTimeout4 } from "node:timers/promises";
101720
101802
  async function reportDaemonUpgradeAvailability(send2, signal) {
101721
101803
  if (!process.connected) {
@@ -101774,7 +101856,7 @@ async function requestDaemonReleaseUpgrade(stateDirectory, currentVersion, signa
101774
101856
  return await requestInstalledDaemonReleaseSwitch(stateDirectory, launch, signal);
101775
101857
  }
101776
101858
  async function requestInstalledDaemonReleaseSwitch(stateDirectory, launch, signal) {
101777
- const id = randomUUID17();
101859
+ const id = randomUUID18();
101778
101860
  const response = lifecycleResponse.parse(
101779
101861
  await sendLocalRequest(stateDirectory, "manager", { kind: "switch", id, context: "npm", launch }, signal)
101780
101862
  );