@moxt-ai/mobius 0.0.170 → 0.0.173

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 (68) hide show
  1. package/dist/acp/agent-session.d.ts.map +1 -1
  2. package/dist/acp/agent-session.js +141 -42
  3. package/dist/acp/agent-session.js.map +1 -1
  4. package/dist/acp/codex/agent.d.ts.map +1 -1
  5. package/dist/acp/codex/agent.js +45 -12
  6. package/dist/acp/codex/agent.js.map +1 -1
  7. package/dist/acp/run-prompt.d.ts.map +1 -1
  8. package/dist/acp/run-prompt.js +7 -1
  9. package/dist/acp/run-prompt.js.map +1 -1
  10. package/dist/acp/session-contracts.d.ts +9 -4
  11. package/dist/acp/session-contracts.d.ts.map +1 -1
  12. package/dist/acp/session-contracts.js +1 -1
  13. package/dist/acp/session-contracts.js.map +1 -1
  14. package/dist/acp/session-history.d.ts +6 -3
  15. package/dist/acp/session-history.d.ts.map +1 -1
  16. package/dist/acp/session-history.js +41 -17
  17. package/dist/acp/session-history.js.map +1 -1
  18. package/dist/acp/session-interactions.d.ts +2 -0
  19. package/dist/acp/session-interactions.d.ts.map +1 -1
  20. package/dist/acp/session-interactions.js +36 -8
  21. package/dist/acp/session-interactions.js.map +1 -1
  22. package/dist/acp/session-store.d.ts +0 -13
  23. package/dist/acp/session-store.d.ts.map +1 -1
  24. package/dist/acp/session-store.js +3 -65
  25. package/dist/acp/session-store.js.map +1 -1
  26. package/dist/cli.js +419 -521
  27. package/dist/cli.js.map +4 -4
  28. package/dist/daemon-command-handler.js +1 -1
  29. package/dist/daemon-command-handler.js.map +1 -1
  30. package/dist/daemon-history-commands.d.ts +2 -1
  31. package/dist/daemon-history-commands.d.ts.map +1 -1
  32. package/dist/daemon-history-commands.js +9 -20
  33. package/dist/daemon-history-commands.js.map +1 -1
  34. package/dist/daemon-observers.d.ts +3 -3
  35. package/dist/daemon-observers.d.ts.map +1 -1
  36. package/dist/daemon-observers.js +2 -18
  37. package/dist/daemon-observers.js.map +1 -1
  38. package/dist/daemon-prompt-executor.d.ts.map +1 -1
  39. package/dist/daemon-prompt-executor.js +3 -1
  40. package/dist/daemon-prompt-executor.js.map +1 -1
  41. package/dist/daemon-turn-registry.d.ts +13 -13
  42. package/dist/generated/acp-session-store-migrations.d.ts +3 -0
  43. package/dist/generated/acp-session-store-migrations.d.ts.map +1 -1
  44. package/dist/generated/acp-session-store-migrations.js +5 -1
  45. package/dist/generated/acp-session-store-migrations.js.map +1 -1
  46. package/dist/index.js +411 -507
  47. package/dist/index.js.map +4 -4
  48. package/dist/relay-connection/session-event-publisher.d.ts +1 -6
  49. package/dist/relay-connection/session-event-publisher.d.ts.map +1 -1
  50. package/dist/relay-connection/session-event-publisher.js +2 -7
  51. package/dist/relay-connection/session-event-publisher.js.map +1 -1
  52. package/dist/run-daemon.js +2 -2
  53. package/dist/run-daemon.js.map +1 -1
  54. package/dist/runtime.js +402 -504
  55. package/dist/runtime.js.map +4 -4
  56. package/dist/schema/acp-session-store/index.d.ts +0 -1
  57. package/dist/schema/acp-session-store/index.d.ts.map +1 -1
  58. package/dist/schema/acp-session-store/index.js +0 -1
  59. package/dist/schema/acp-session-store/index.js.map +1 -1
  60. package/dist/session-event-log-v2.d.ts +18 -9
  61. package/dist/session-event-log-v2.d.ts.map +1 -1
  62. package/dist/session-event-log-v2.js +39 -156
  63. package/dist/session-event-log-v2.js.map +1 -1
  64. package/package.json +1 -1
  65. package/dist/schema/acp-session-store/session-event-v2.d.ts +0 -72
  66. package/dist/schema/acp-session-store/session-event-v2.d.ts.map +0 -1
  67. package/dist/schema/acp-session-store/session-event-v2.js +0 -11
  68. package/dist/schema/acp-session-store/session-event-v2.js.map +0 -1
package/dist/cli.js CHANGED
@@ -2340,11 +2340,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
2340
2340
  };
2341
2341
  this._checkNumberOfArguments();
2342
2342
  const processedArgs = [];
2343
- this.registeredArguments.forEach((declaredArg, index2) => {
2343
+ this.registeredArguments.forEach((declaredArg, index) => {
2344
2344
  let value = declaredArg.defaultValue;
2345
2345
  if (declaredArg.variadic) {
2346
- if (index2 < this.args.length) {
2347
- value = this.args.slice(index2);
2346
+ if (index < this.args.length) {
2347
+ value = this.args.slice(index);
2348
2348
  if (declaredArg.parseArg) {
2349
2349
  value = value.reduce((processed, v) => {
2350
2350
  return myParseArg(declaredArg, v, processed);
@@ -2353,13 +2353,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2353
2353
  } else if (value === void 0) {
2354
2354
  value = [];
2355
2355
  }
2356
- } else if (index2 < this.args.length) {
2357
- value = this.args[index2];
2356
+ } else if (index < this.args.length) {
2357
+ value = this.args[index];
2358
2358
  if (declaredArg.parseArg) {
2359
2359
  value = myParseArg(declaredArg, value, declaredArg.defaultValue);
2360
2360
  }
2361
2361
  }
2362
- processedArgs[index2] = value;
2362
+ processedArgs[index] = value;
2363
2363
  });
2364
2364
  this.processedArgs = processedArgs;
2365
2365
  }
@@ -2653,10 +2653,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
2653
2653
  }
2654
2654
  }
2655
2655
  if (/^--[^=]+=/.test(arg)) {
2656
- const index2 = arg.indexOf("=");
2657
- const option = this._findOption(arg.slice(0, index2));
2656
+ const index = arg.indexOf("=");
2657
+ const option = this._findOption(arg.slice(0, index));
2658
2658
  if (option && (option.required || option.optional)) {
2659
- this.emit(`option:${option.name()}`, arg.slice(index2 + 1));
2659
+ this.emit(`option:${option.name()}`, arg.slice(index + 1));
2660
2660
  continue;
2661
2661
  }
2662
2662
  }
@@ -3381,7 +3381,7 @@ var program = new Command();
3381
3381
  // package.json
3382
3382
  var package_default = {
3383
3383
  name: "@moxt-ai/mobius",
3384
- version: "0.0.170",
3384
+ version: "0.0.173",
3385
3385
  description: "Mobius CLI for pairing and running local AI agent services.",
3386
3386
  type: "module",
3387
3387
  bin: {
@@ -8320,11 +8320,11 @@ var $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
8320
8320
  return payload;
8321
8321
  };
8322
8322
  });
8323
- function handleArrayResult(result, final, index2) {
8323
+ function handleArrayResult(result, final, index) {
8324
8324
  if (result.issues.length) {
8325
- final.issues.push(...prefixIssues(index2, result.issues));
8325
+ final.issues.push(...prefixIssues(index, result.issues));
8326
8326
  }
8327
- final.value[index2] = result.value;
8327
+ final.value[index] = result.value;
8328
8328
  }
8329
8329
  var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
8330
8330
  $ZodType.init(inst, def);
@@ -8935,14 +8935,14 @@ function mergeValues(a, b) {
8935
8935
  return { valid: false, mergeErrorPath: [] };
8936
8936
  }
8937
8937
  const newArray = [];
8938
- for (let index2 = 0; index2 < a.length; index2++) {
8939
- const itemA = a[index2];
8940
- const itemB = b[index2];
8938
+ for (let index = 0; index < a.length; index++) {
8939
+ const itemA = a[index];
8940
+ const itemB = b[index];
8941
8941
  const sharedValue = mergeValues(itemA, itemB);
8942
8942
  if (!sharedValue.valid) {
8943
8943
  return {
8944
8944
  valid: false,
8945
- mergeErrorPath: [index2, ...sharedValue.mergeErrorPath]
8945
+ mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
8946
8946
  };
8947
8947
  }
8948
8948
  newArray.push(sharedValue.data);
@@ -9093,11 +9093,11 @@ function getTupleOptStart(items, key) {
9093
9093
  }
9094
9094
  return 0;
9095
9095
  }
9096
- function handleTupleResult(result, final, index2) {
9096
+ function handleTupleResult(result, final, index) {
9097
9097
  if (result.issues.length) {
9098
- final.issues.push(...prefixIssues(index2, result.issues));
9098
+ final.issues.push(...prefixIssues(index, result.issues));
9099
9099
  }
9100
- final.value[index2] = result.value;
9100
+ final.value[index] = result.value;
9101
9101
  }
9102
9102
  function handleTupleResults(itemResults, final, items, input2, optoutStart) {
9103
9103
  for (let i = 0; i < items.length; i++) {
@@ -23778,7 +23778,7 @@ function detectVersion(schema, defaultTarget) {
23778
23778
  return defaultTarget ?? "draft-2020-12";
23779
23779
  }
23780
23780
  function applyMinItems(items, minItems) {
23781
- return items.map((item, index2) => index2 < minItems ? item : item.optional());
23781
+ return items.map((item, index) => index < minItems ? item : item.optional());
23782
23782
  }
23783
23783
  function decodeJSONPointerSegment(segment) {
23784
23784
  return segment.replace(/~1/g, "/").replace(/~0/g, "~");
@@ -25707,8 +25707,8 @@ function promptInput(prompt) {
25707
25707
  function isCompactPrompt(prompt) {
25708
25708
  return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
25709
25709
  }
25710
- function steeringPromptInput(prompt) {
25711
- const input2 = [];
25710
+ function steeringPrompt(prompt) {
25711
+ const blocks = [];
25712
25712
  for (const block of prompt) {
25713
25713
  if (typeof block !== "object" || block === null) {
25714
25714
  throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
@@ -25719,7 +25719,7 @@ function steeringPromptInput(prompt) {
25719
25719
  if (typeof text2 !== "string") {
25720
25720
  throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25721
25721
  }
25722
- input2.push({ text: text2, text_elements: [], type: "text" });
25722
+ blocks.push({ content: { text: text2, type: "text" }, input: { text: text2, text_elements: [], type: "text" } });
25723
25723
  continue;
25724
25724
  }
25725
25725
  if (type === "image") {
@@ -25728,7 +25728,10 @@ function steeringPromptInput(prompt) {
25728
25728
  if (typeof data !== "string" || typeof mimeType !== "string") {
25729
25729
  throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25730
25730
  }
25731
- input2.push({ type: "image", url: `data:${mimeType};base64,${data}` });
25731
+ blocks.push({
25732
+ content: { data, mimeType, type: "image" },
25733
+ input: { type: "image", url: `data:${mimeType};base64,${data}` }
25734
+ });
25732
25735
  continue;
25733
25736
  }
25734
25737
  if (type === "resource") {
@@ -25736,24 +25739,33 @@ function steeringPromptInput(prompt) {
25736
25739
  if (typeof resource !== "object" || resource === null) {
25737
25740
  throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25738
25741
  }
25742
+ const uri = Reflect.get(resource, "uri");
25739
25743
  const text2 = Reflect.get(resource, "text");
25740
- if (text2 !== void 0 && typeof text2 !== "string") {
25744
+ const blob2 = Reflect.get(resource, "blob");
25745
+ if (typeof uri !== "string" || typeof text2 !== "string" && typeof blob2 !== "string" || text2 !== void 0 && typeof text2 !== "string" || blob2 !== void 0 && typeof blob2 !== "string") {
25741
25746
  throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25742
25747
  }
25743
- input2.push({ text: text2 ?? "", text_elements: [], type: "text" });
25748
+ blocks.push({
25749
+ content: typeof text2 === "string" ? { resource: { text: text2, uri }, type: "resource" } : { resource: { blob: blob2, uri }, type: "resource" },
25750
+ input: { text: text2 ?? "", text_elements: [], type: "text" }
25751
+ });
25744
25752
  continue;
25745
25753
  }
25746
25754
  if (type === "resource_link") {
25755
+ const name2 = Reflect.get(block, "name");
25747
25756
  const uri = Reflect.get(block, "uri");
25748
- if (typeof uri !== "string") {
25757
+ if (typeof name2 !== "string" || typeof uri !== "string") {
25749
25758
  throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
25750
25759
  }
25751
- input2.push({ text: `Resource: ${uri}`, text_elements: [], type: "text" });
25760
+ blocks.push({
25761
+ content: { name: name2, type: "resource_link", uri },
25762
+ input: { text: `Resource: ${uri}`, text_elements: [], type: "text" }
25763
+ });
25752
25764
  continue;
25753
25765
  }
25754
25766
  throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
25755
25767
  }
25756
- return input2;
25768
+ return blocks;
25757
25769
  }
25758
25770
  function agentMessageUpdate(messageId, text2, phase) {
25759
25771
  return {
@@ -25900,6 +25912,14 @@ var CodexAcpAgent = class {
25900
25912
  if (isCompactPrompt(context.params.prompt)) {
25901
25913
  return await this.#compact(context.signal);
25902
25914
  }
25915
+ const messageId = crypto.randomUUID();
25916
+ for (const content of context.params.prompt) {
25917
+ await this.#emit({
25918
+ content,
25919
+ messageId,
25920
+ sessionUpdate: "user_message_chunk"
25921
+ });
25922
+ }
25903
25923
  return await this.#runTurn(promptInput(context.params.prompt), context.signal);
25904
25924
  }).onRequest(
25905
25925
  "_session/steering",
@@ -26381,14 +26401,22 @@ var CodexAcpAgent = class {
26381
26401
  if (sessionId !== this.#nativeSessionId || active === null || active.turn.id.length === 0) {
26382
26402
  return { outcome: "promptRequired", reason: "noRunningTurn" };
26383
26403
  }
26384
- const input2 = steeringPromptInput(prompt);
26385
- if (input2.length === 0) {
26404
+ const steering = steeringPrompt(prompt);
26405
+ if (steering.length === 0) {
26386
26406
  throw new AcpExecutionError("Codex received an empty steering request", {}, "invalid_request");
26387
26407
  }
26408
+ const messageId = crypto.randomUUID();
26409
+ for (const block of steering) {
26410
+ await this.#emit({ content: block.content, messageId, sessionUpdate: "user_message_chunk" });
26411
+ }
26388
26412
  const response = turnSteerResponseSchema.parse(
26389
26413
  await this.#appServer.request(
26390
26414
  "turn/steer",
26391
- { expectedTurnId: active.turn.id, input: input2, threadId: this.#nativeSessionId },
26415
+ {
26416
+ expectedTurnId: active.turn.id,
26417
+ input: steering.map((block) => block.input),
26418
+ threadId: this.#nativeSessionId
26419
+ },
26392
26420
  AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
26393
26421
  )
26394
26422
  );
@@ -27824,9 +27852,9 @@ function comparePrerelease(left, right) {
27824
27852
  if (left.length === 0 || right.length === 0) {
27825
27853
  return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
27826
27854
  }
27827
- for (let index2 = 0; index2 < Math.max(left.length, right.length); index2 += 1) {
27828
- const leftPart = left[index2];
27829
- const rightPart = right[index2];
27855
+ for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
27856
+ const leftPart = left[index];
27857
+ const rightPart = right[index];
27830
27858
  if (leftPart === void 0 || rightPart === void 0) {
27831
27859
  return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
27832
27860
  }
@@ -27851,8 +27879,8 @@ function compareAgentVersions(left, right) {
27851
27879
  if (parsedLeft === null || parsedRight === null) {
27852
27880
  return null;
27853
27881
  }
27854
- for (let index2 = 0; index2 < Math.max(parsedLeft.core.length, parsedRight.core.length); index2 += 1) {
27855
- const difference = (parsedLeft.core[index2] ?? 0) - (parsedRight.core[index2] ?? 0);
27882
+ for (let index = 0; index < Math.max(parsedLeft.core.length, parsedRight.core.length); index += 1) {
27883
+ const difference = (parsedLeft.core[index] ?? 0) - (parsedRight.core[index] ?? 0);
27856
27884
  if (difference !== 0) {
27857
27885
  return Math.sign(difference);
27858
27886
  }
@@ -28613,12 +28641,12 @@ var DEFAULT_AGENT_EXECUTION_CONFIGURATION = Object.freeze({
28613
28641
  });
28614
28642
  var sessionConfigurationSelectionsSchema = external_exports.array(sessionConfigurationSelectionSchema).max(100).superRefine((selections, context) => {
28615
28643
  const identifiers = /* @__PURE__ */ new Set();
28616
- for (const [index2, selection] of selections.entries()) {
28644
+ for (const [index, selection] of selections.entries()) {
28617
28645
  if (identifiers.has(selection.configId)) {
28618
28646
  context.addIssue({
28619
28647
  code: "custom",
28620
28648
  message: "Session configuration identifiers must be unique",
28621
- path: [index2, "configId"]
28649
+ path: [index, "configId"]
28622
28650
  });
28623
28651
  }
28624
28652
  identifiers.add(selection.configId);
@@ -30093,10 +30121,7 @@ var lifecycleMetadataV2Schema = external_exports.discriminatedUnion("kind", [
30093
30121
  external_exports.object({ kind: external_exports.literal("session.queue.changed") }).readonly(),
30094
30122
  external_exports.object({ event: sessionPermissionRequestedEventSchema, kind: external_exports.literal("session.permission.requested") }).readonly(),
30095
30123
  external_exports.object({ event: sessionPermissionResolvedEventSchema, kind: external_exports.literal("session.permission.resolved") }).readonly(),
30096
- external_exports.object({
30097
- event: sessionElicitationRequestedEventSchema,
30098
- kind: external_exports.literal("session.elicitation.requested")
30099
- }).readonly(),
30124
+ external_exports.object({ event: sessionElicitationRequestedEventSchema, kind: external_exports.literal("session.elicitation.requested") }).readonly(),
30100
30125
  external_exports.object({ event: sessionElicitationResolvedEventSchema, kind: external_exports.literal("session.elicitation.resolved") }).readonly(),
30101
30126
  external_exports.object({
30102
30127
  ...lifecycleBase,
@@ -30165,12 +30190,12 @@ var sessionExportV2Schema = external_exports.object({
30165
30190
  }).readonly().superRefine((session, context) => {
30166
30191
  let previousPosition = 0n;
30167
30192
  const eventIds = /* @__PURE__ */ new Set();
30168
- for (const [index2, event] of session.events.entries()) {
30193
+ for (const [index, event] of session.events.entries()) {
30169
30194
  if (event.sessionId !== session.sessionId) {
30170
30195
  context.addIssue({
30171
30196
  code: "custom",
30172
30197
  message: "Exported event belongs to a different Session",
30173
- path: ["events", index2, "sessionId"]
30198
+ path: ["events", index, "sessionId"]
30174
30199
  });
30175
30200
  }
30176
30201
  const position = BigInt(event.position);
@@ -30178,14 +30203,14 @@ var sessionExportV2Schema = external_exports.object({
30178
30203
  context.addIssue({
30179
30204
  code: "custom",
30180
30205
  message: "Exported events are not in increasing position order",
30181
- path: ["events", index2, "position"]
30206
+ path: ["events", index, "position"]
30182
30207
  });
30183
30208
  }
30184
30209
  if (eventIds.has(event.eventId)) {
30185
30210
  context.addIssue({
30186
30211
  code: "custom",
30187
30212
  message: "Exported event identities are not unique",
30188
- path: ["events", index2, "eventId"]
30213
+ path: ["events", index, "eventId"]
30189
30214
  });
30190
30215
  }
30191
30216
  previousPosition = position;
@@ -30198,6 +30223,7 @@ var mobiusSessionExportV2Schema = external_exports.object({
30198
30223
  }).readonly();
30199
30224
  var sessionEventEnvelopeV2Schema = external_exports.object({ event: sessionEventV2Schema, kind: external_exports.literal(SESSION_EVENT_V2_KIND) }).readonly();
30200
30225
  var sessionEventLogPageV2Schema = external_exports.object({
30226
+ daemonGenerationId: identifierStringSchema,
30201
30227
  events: external_exports.array(sessionEventV2Schema).max(MAX_EVENT_COUNT).readonly(),
30202
30228
  nextCursor: external_exports.string().min(1).max(512).nullable(),
30203
30229
  tailCursor: external_exports.string().max(512),
@@ -30205,17 +30231,13 @@ var sessionEventLogPageV2Schema = external_exports.object({
30205
30231
  version: external_exports.literal(2)
30206
30232
  }).readonly();
30207
30233
  var nativeEventPageRequestV2Schema = external_exports.object({ cursor: external_exports.string().min(1).max(512).nullable(), eventLimit: external_exports.number().int().min(1).max(1e4) }).readonly();
30208
- var executingPromptRequestEventLogV2Schema = external_exports.object({
30209
- attemptId: identifierStringSchema,
30234
+ var queuedPromptRequestEventLogV2Schema = external_exports.object({
30210
30235
  commandId: identifierStringSchema,
30211
- epoch: identifierStringSchema,
30212
- events: external_exports.array(sessionEventV2Schema).max(MAX_EVENT_COUNT).readonly(),
30213
- tailCursor: external_exports.string().max(512),
30214
- truncated: external_exports.boolean()
30236
+ content: external_exports.array(contentBlockV2Schema).min(1).max(100).readonly()
30215
30237
  }).readonly();
30216
30238
  var nativeSessionEventsV2Schema = external_exports.object({
30217
- executingPromptRequest: executingPromptRequestEventLogV2Schema.nullable(),
30218
- history: sessionEventLogPageV2Schema
30239
+ events: sessionEventLogPageV2Schema,
30240
+ queuedPromptRequests: external_exports.array(queuedPromptRequestEventLogV2Schema).max(MAX_COLLECTION_SIZE).readonly()
30219
30241
  }).readonly();
30220
30242
  function inputValue(value) {
30221
30243
  if (typeof value !== "string") {
@@ -30239,7 +30261,6 @@ function decode5(value, schema) {
30239
30261
  function encode4(value, schema) {
30240
30262
  return JSON.stringify(decode5(value, schema));
30241
30263
  }
30242
- var decodeSessionEventV2 = (value) => decode5(value, sessionEventV2Schema);
30243
30264
  var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelopeV2Schema);
30244
30265
  var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
30245
30266
  var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
@@ -31031,16 +31052,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
31031
31052
  };
31032
31053
  #readConnectionForChannel = async (channelId, signal) => {
31033
31054
  const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
31034
- const index2 = decodeChannelIndex(
31055
+ const index = decodeChannelIndex(
31035
31056
  await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
31036
31057
  );
31037
- if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
31058
+ if (index.applicationId !== this.applicationId || index.installationId !== this.installationId || index.channelId !== normalizedChannelId) {
31038
31059
  throw new RuntimeInstallationStoreError(
31039
31060
  "connection_owner_mismatch",
31040
31061
  "The saved Runtime connection belongs to another installation"
31041
31062
  );
31042
31063
  }
31043
- return await this.readConnection(index2.connectionId, signal);
31064
+ return await this.readConnection(index.connectionId, signal);
31044
31065
  };
31045
31066
  saveConnection = async (input2, signal) => {
31046
31067
  const stored = new VerifiedRuntimeConnection(
@@ -31235,16 +31256,16 @@ function hasExactKeys2(value, expectedKeys) {
31235
31256
  }
31236
31257
  function readSingleOption(arguments_, option) {
31237
31258
  const values = [];
31238
- for (let index2 = 0; index2 < arguments_.length; index2 += 1) {
31239
- if (arguments_[index2] !== option) {
31259
+ for (let index = 0; index < arguments_.length; index += 1) {
31260
+ if (arguments_[index] !== option) {
31240
31261
  continue;
31241
31262
  }
31242
- const value = arguments_[index2 + 1];
31263
+ const value = arguments_[index + 1];
31243
31264
  if (value === void 0 || value.startsWith("--")) {
31244
31265
  throw new PairingClientError("invalid_arguments", `${option} requires a value`);
31245
31266
  }
31246
31267
  values.push(value);
31247
- index2 += 1;
31268
+ index += 1;
31248
31269
  }
31249
31270
  if (values.length !== 1) {
31250
31271
  throw new PairingClientError("invalid_arguments", `${option} must be provided exactly once`);
@@ -31252,8 +31273,8 @@ function readSingleOption(arguments_, option) {
31252
31273
  return values[0] ?? "";
31253
31274
  }
31254
31275
  function assertKnownArguments(arguments_) {
31255
- for (let index2 = 0; index2 < arguments_.length; index2 += 2) {
31256
- const option = arguments_[index2];
31276
+ for (let index = 0; index < arguments_.length; index += 2) {
31277
+ const option = arguments_[index];
31257
31278
  if (option !== "--url" && option !== "--code" && option !== "--pairing" && option !== "--workspace") {
31258
31279
  throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${option ?? "missing option"}`);
31259
31280
  }
@@ -31530,7 +31551,7 @@ var AuditStore = class {
31530
31551
  };
31531
31552
 
31532
31553
  // src/run-daemon.ts
31533
- import { createHash as createHash8, randomUUID as randomUUID8 } from "node:crypto";
31554
+ import { createHash as createHash8, randomUUID as randomUUID9 } from "node:crypto";
31534
31555
  import { join as join19 } from "node:path";
31535
31556
  import { styleText } from "node:util";
31536
31557
 
@@ -31653,7 +31674,7 @@ function startsWith(bytes, signature, offset = 0) {
31653
31674
  if (bytes.byteLength < offset + signature.byteLength) {
31654
31675
  return false;
31655
31676
  }
31656
- return signature.every((value, index2) => bytes[offset + index2] === value);
31677
+ return signature.every((value, index) => bytes[offset + index] === value);
31657
31678
  }
31658
31679
  function sniffRasterMime(bytes) {
31659
31680
  if (startsWith(bytes, PNG_SIGNATURE)) {
@@ -31781,7 +31802,7 @@ function startsWith2(bytes, signature, offset = 0) {
31781
31802
  if (bytes.byteLength < offset + signature.byteLength) {
31782
31803
  return false;
31783
31804
  }
31784
- return signature.every((value, index2) => bytes[offset + index2] === value);
31805
+ return signature.every((value, index) => bytes[offset + index] === value);
31785
31806
  }
31786
31807
  function sniffVideoMime(bytes) {
31787
31808
  if (startsWith2(bytes, MP4_FILE_TYPE, 4)) {
@@ -31910,10 +31931,10 @@ async function replaceImageMarkers(text2, replace) {
31910
31931
  let cursor = 0;
31911
31932
  let rewritten = "";
31912
31933
  for (const match of matches) {
31913
- const index2 = match.index ?? 0;
31914
- rewritten += text2.slice(cursor, index2);
31934
+ const index = match.index ?? 0;
31935
+ rewritten += text2.slice(cursor, index);
31915
31936
  rewritten += await replace(match[1] ?? "");
31916
- cursor = index2 + match[0].length;
31937
+ cursor = index + match[0].length;
31917
31938
  }
31918
31939
  return `${rewritten}${text2.slice(cursor)}`;
31919
31940
  }
@@ -33079,7 +33100,7 @@ function sessionConfigProtocolForAgent(_agentId) {
33079
33100
 
33080
33101
  // src/acp/session-contracts.ts
33081
33102
  var NullAcpSessionObserver = class {
33082
- onAcpUpdate = (_sessionId, _update) => Promise.resolve();
33103
+ onSessionEventV2 = (_sessionId, _event, _position) => Promise.resolve();
33083
33104
  onCommands = () => Promise.resolve();
33084
33105
  onConfig = () => Promise.resolve();
33085
33106
  onContent = () => Promise.resolve();
@@ -33147,7 +33168,8 @@ function historyContentCharacters(messages) {
33147
33168
  var AcpHistoryReplay = class {
33148
33169
  #activities = /* @__PURE__ */ new Map();
33149
33170
  #messages = [];
33150
- #updates = [];
33171
+ #events = [];
33172
+ #records = [];
33151
33173
  #turnActivityIds = /* @__PURE__ */ new Set();
33152
33174
  #activityTracker = new AcpActivityTracker(
33153
33175
  async (activity2) => {
@@ -33169,8 +33191,10 @@ var AcpHistoryReplay = class {
33169
33191
  #firstMessageIndex = 0;
33170
33192
  #characters = 0;
33171
33193
  #truncated = false;
33172
- record = async (update, rawUpdate) => {
33173
- this.#updates.push(rawUpdate);
33194
+ record = async (update, rawUpdate, onRecorded = () => Promise.resolve()) => {
33195
+ this.#records.push({ kind: "acp", rawUpdate, update });
33196
+ this.#events.push({ payload: rawUpdate, type: "acp" });
33197
+ await onRecorded(this.#events.length);
33174
33198
  if (update.sessionUpdate === "agent_thought_chunk") {
33175
33199
  if (update.content.type === "text") {
33176
33200
  await this.#activityTracker.recordNarrative(
@@ -33179,30 +33203,30 @@ var AcpHistoryReplay = class {
33179
33203
  update.content.text
33180
33204
  );
33181
33205
  }
33182
- return;
33206
+ return this.#events.length;
33183
33207
  }
33184
33208
  if (update.sessionUpdate === "tool_call") {
33185
33209
  await this.#activityTracker.recordToolCall(update);
33186
- return;
33210
+ return this.#events.length;
33187
33211
  }
33188
33212
  if (update.sessionUpdate === "tool_call_update") {
33189
33213
  await this.#activityTracker.recordToolCallUpdate(update);
33190
- return;
33214
+ return this.#events.length;
33191
33215
  }
33192
33216
  if (update.sessionUpdate === "plan") {
33193
33217
  await this.#activityTracker.recordPlan(update);
33194
- return;
33218
+ return this.#events.length;
33195
33219
  }
33196
33220
  if (update.sessionUpdate === "plan_update") {
33197
33221
  await this.#activityTracker.recordPlanUpdate(update);
33198
- return;
33222
+ return this.#events.length;
33199
33223
  }
33200
33224
  if (update.sessionUpdate === "plan_removed") {
33201
33225
  await this.#activityTracker.removePlan(update);
33202
- return;
33226
+ return this.#events.length;
33203
33227
  }
33204
33228
  if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
33205
- return;
33229
+ return this.#events.length;
33206
33230
  }
33207
33231
  if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
33208
33232
  if (update.content.type === "text") {
@@ -33212,18 +33236,18 @@ var AcpHistoryReplay = class {
33212
33236
  update.content.text
33213
33237
  );
33214
33238
  }
33215
- return;
33239
+ return this.#events.length;
33216
33240
  }
33217
33241
  const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
33218
33242
  const content = update.content;
33219
33243
  if (role === "assistant" && content.type !== "text") {
33220
33244
  await this.#activityTracker.finishNarrative();
33221
33245
  this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content));
33222
- return;
33246
+ return this.#events.length;
33223
33247
  }
33224
33248
  const text2 = content.type === "text" ? content.text : content.type === "image" ? content.data.length > 0 ? `[@image](data:${content.mimeType};base64,${content.data})` : content.uri != null && content.uri.length > 0 ? `[@image](${content.uri})` : "[image attachment]" : `[${content.type} attachment]`;
33225
33249
  if (text2.length === 0) {
33226
- return;
33250
+ return this.#events.length;
33227
33251
  }
33228
33252
  const previous = this.#messages.at(-1);
33229
33253
  const id = update.messageId ?? null;
@@ -33250,10 +33274,30 @@ var AcpHistoryReplay = class {
33250
33274
  this.#characters += bounded2.length;
33251
33275
  this.#lastMessageId = id;
33252
33276
  this.trimMessages();
33277
+ return this.#events.length;
33278
+ };
33279
+ recordLifecycle = (event) => {
33280
+ if (event.type !== "lifecycle-metadata") {
33281
+ throw new Error("Lifecycle history only accepts lifecycle metadata");
33282
+ }
33283
+ this.#records.push({ event, kind: "lifecycle" });
33284
+ this.#events.push(event);
33285
+ return this.#events.length;
33286
+ };
33287
+ eventCount = () => this.#events.length;
33288
+ append = async (replay) => {
33289
+ for (const record2 of replay.#records) {
33290
+ if (record2.kind === "acp") {
33291
+ await this.record(record2.update, record2.rawUpdate);
33292
+ } else {
33293
+ this.recordLifecycle(record2.event);
33294
+ }
33295
+ }
33253
33296
  };
33254
- eventPage = (eventLimit, cursor) => {
33255
- const parsedCursor = cursor === null ? this.#updates.length : Number(cursor);
33256
- if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > this.#updates.length) {
33297
+ eventPage = (eventLimit, cursor, appended = null) => {
33298
+ const events = appended === null ? this.#events : [...this.#events, ...appended.#events];
33299
+ const parsedCursor = cursor === null ? events.length : Number(cursor);
33300
+ if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > events.length) {
33257
33301
  throw new Error("The native event cursor is invalid");
33258
33302
  }
33259
33303
  const endUpdate = parsedCursor;
@@ -33262,7 +33306,7 @@ var AcpHistoryReplay = class {
33262
33306
  nextCursor: startUpdate === 0 ? null : startUpdate.toString(),
33263
33307
  startPosition: startUpdate + 1,
33264
33308
  truncated: startUpdate > 0,
33265
- updates: this.#updates.slice(startUpdate, endUpdate)
33309
+ events: events.slice(startUpdate, endUpdate)
33266
33310
  };
33267
33311
  };
33268
33312
  snapshot = async () => {
@@ -33649,6 +33693,34 @@ var AcpSessionInteractions = class {
33649
33693
  constructor(context) {
33650
33694
  this.#context = context;
33651
33695
  }
33696
+ #notifyPermissionRequested = async (event) => {
33697
+ await this.#context.recordSessionEventV2({
33698
+ payload: { event, kind: "session.permission.requested" },
33699
+ type: "lifecycle-metadata"
33700
+ });
33701
+ await this.#context.observer().onPermission(event);
33702
+ };
33703
+ #notifyPermissionResolved = async (event) => {
33704
+ await this.#context.recordSessionEventV2({
33705
+ payload: { event, kind: "session.permission.resolved" },
33706
+ type: "lifecycle-metadata"
33707
+ });
33708
+ await this.#context.observer().onPermissionResolved(event);
33709
+ };
33710
+ #notifyElicitationRequested = async (event) => {
33711
+ await this.#context.recordSessionEventV2({
33712
+ payload: { event, kind: "session.elicitation.requested" },
33713
+ type: "lifecycle-metadata"
33714
+ });
33715
+ await this.#context.observer().onElicitation(event);
33716
+ };
33717
+ #notifyElicitationResolved = async (event) => {
33718
+ await this.#context.recordSessionEventV2({
33719
+ payload: { event, kind: "session.elicitation.resolved" },
33720
+ type: "lifecycle-metadata"
33721
+ });
33722
+ await this.#context.observer().onElicitationResolved(event);
33723
+ };
33652
33724
  respondPermission = async (options) => {
33653
33725
  const pending = this.#pendingPermissions.get(options.interactionId);
33654
33726
  if (pending === void 0) {
@@ -33674,7 +33746,7 @@ var AcpSessionInteractions = class {
33674
33746
  );
33675
33747
  }
33676
33748
  this.#pendingPermissions.delete(options.interactionId);
33677
- await this.#context.observer().onPermissionResolved({
33749
+ await this.#notifyPermissionResolved({
33678
33750
  interactionId: options.interactionId,
33679
33751
  kind: SESSION_PERMISSION_RESOLVED_KIND,
33680
33752
  optionId: options.outcome === "selected" ? options.optionId : "",
@@ -33714,7 +33786,7 @@ var AcpSessionInteractions = class {
33714
33786
  );
33715
33787
  }
33716
33788
  this.#pendingElicitations.delete(options.interactionId);
33717
- await this.#context.observer().onElicitationResolved({
33789
+ await this.#notifyElicitationResolved({
33718
33790
  action: options.action,
33719
33791
  interactionId: options.interactionId,
33720
33792
  kind: SESSION_ELICITATION_RESOLVED_KIND,
@@ -33743,7 +33815,7 @@ var AcpSessionInteractions = class {
33743
33815
  };
33744
33816
  signal.addEventListener("abort", abort, { once: true });
33745
33817
  try {
33746
- await this.#context.observer().onPermission({
33818
+ await this.#notifyPermissionRequested({
33747
33819
  commandId: this.#context.commandId(),
33748
33820
  interactionId,
33749
33821
  kind: SESSION_PERMISSION_REQUESTED_KIND,
@@ -33788,7 +33860,7 @@ var AcpSessionInteractions = class {
33788
33860
  };
33789
33861
  signal.addEventListener("abort", abort, { once: true });
33790
33862
  try {
33791
- await this.#context.observer().onElicitation({
33863
+ await this.#notifyElicitationRequested({
33792
33864
  accepted: false,
33793
33865
  commandId: this.#context.commandId(),
33794
33866
  elicitationId,
@@ -33812,7 +33884,7 @@ var AcpSessionInteractions = class {
33812
33884
  return;
33813
33885
  }
33814
33886
  this.#acceptedUrlElicitations.delete(notification.elicitationId);
33815
- await this.#context.observer().onElicitationResolved({
33887
+ await this.#notifyElicitationResolved({
33816
33888
  action: "complete",
33817
33889
  interactionId,
33818
33890
  kind: SESSION_ELICITATION_RESOLVED_KIND,
@@ -33825,7 +33897,7 @@ var AcpSessionInteractions = class {
33825
33897
  return;
33826
33898
  }
33827
33899
  this.#pendingPermissions.delete(interactionId);
33828
- await this.#context.observer().onPermissionResolved({
33900
+ await this.#notifyPermissionResolved({
33829
33901
  interactionId,
33830
33902
  kind: SESSION_PERMISSION_RESOLVED_KIND,
33831
33903
  optionId: "",
@@ -33839,7 +33911,7 @@ var AcpSessionInteractions = class {
33839
33911
  return;
33840
33912
  }
33841
33913
  this.#pendingElicitations.delete(interactionId);
33842
- await this.#context.observer().onElicitationResolved({
33914
+ await this.#notifyElicitationResolved({
33843
33915
  action: "cancel",
33844
33916
  interactionId,
33845
33917
  kind: SESSION_ELICITATION_RESOLVED_KIND,
@@ -33858,7 +33930,7 @@ var AcpSessionInteractions = class {
33858
33930
  await this.cancelElicitation(interactionId);
33859
33931
  }
33860
33932
  for (const interactionId of acceptedElicitationIds) {
33861
- await this.#context.observer().onElicitationResolved({
33933
+ await this.#notifyElicitationResolved({
33862
33934
  action: "cancel",
33863
33935
  interactionId,
33864
33936
  kind: SESSION_ELICITATION_RESOLVED_KIND,
@@ -34987,7 +35059,7 @@ function haveSameKeys(left, right) {
34987
35059
  const leftKeys = Object.keys(left);
34988
35060
  const rightKeys = Object.keys(right);
34989
35061
  if (leftKeys.length !== rightKeys.length) return false;
34990
- for (const [index2, key] of leftKeys.entries()) if (key !== rightKeys[index2]) return false;
35062
+ for (const [index, key] of leftKeys.entries()) if (key !== rightKeys[index]) return false;
34991
35063
  return true;
34992
35064
  }
34993
35065
  function mapUpdateSet(table, values) {
@@ -36493,60 +36565,6 @@ function sqliteTableWithCasing(casing) {
36493
36565
  }
36494
36566
  var sqliteTable = sqliteTableWithCasing(void 0);
36495
36567
 
36496
- // ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/indexes.js
36497
- var IndexBuilderOn = class {
36498
- static [entityKind] = "SQLiteIndexBuilderOn";
36499
- constructor(name2, unique) {
36500
- this.name = name2;
36501
- this.unique = unique;
36502
- }
36503
- on(...columns) {
36504
- return new IndexBuilder(this.name, columns, this.unique);
36505
- }
36506
- };
36507
- var IndexBuilder = class {
36508
- static [entityKind] = "SQLiteIndexBuilder";
36509
- /** @internal */
36510
- config;
36511
- constructor(name2, columns, unique) {
36512
- this.config = {
36513
- name: name2,
36514
- columns,
36515
- unique,
36516
- where: void 0
36517
- };
36518
- }
36519
- /**
36520
- * Condition for partial index.
36521
- */
36522
- where(condition) {
36523
- this.config.where = condition;
36524
- return this;
36525
- }
36526
- /** @internal */
36527
- build(table) {
36528
- return new Index(this.config, table);
36529
- }
36530
- };
36531
- var Index = class {
36532
- static [entityKind] = "SQLiteIndex";
36533
- config;
36534
- isNameExplicit;
36535
- constructor(config2, table) {
36536
- this.config = {
36537
- ...config2,
36538
- table
36539
- };
36540
- this.isNameExplicit = !!config2.name;
36541
- }
36542
- };
36543
- function index(name2) {
36544
- return new IndexBuilderOn(name2, false);
36545
- }
36546
- function uniqueIndex(name2) {
36547
- return new IndexBuilderOn(name2, true);
36548
- }
36549
-
36550
36568
  // ../../node_modules/.pnpm/drizzle-orm@1.0.0-rc.4_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6_f872c171b7e1945bb1fa42180063dab2/node_modules/drizzle-orm/sqlite-core/utils.js
36551
36569
  function extractUsedTable(table) {
36552
36570
  if (is(table, SQLiteTable)) return [`${table[Table.Symbol.BaseName]}`];
@@ -37371,8 +37389,8 @@ var SQLiteDialect = class {
37371
37389
  buildJoins(joins) {
37372
37390
  if (!joins || joins.length === 0) return;
37373
37391
  const joinsArray = [];
37374
- if (joins) for (const [index2, joinMeta] of joins.entries()) {
37375
- if (index2 === 0) joinsArray.push(sql` `);
37392
+ if (joins) for (const [index, joinMeta] of joins.entries()) {
37393
+ if (index === 0) joinsArray.push(sql` `);
37376
37394
  const table = joinMeta.table;
37377
37395
  const onSql = joinMeta.on ? sql` on ${joinMeta.on}` : void 0;
37378
37396
  if (is(table, SQLiteTable)) {
@@ -37382,7 +37400,7 @@ var SQLiteDialect = class {
37382
37400
  const alias = tableName === origTableName ? void 0 : joinMeta.alias;
37383
37401
  joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`);
37384
37402
  } else joinsArray.push(sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`);
37385
- if (index2 < joins.length - 1) joinsArray.push(sql` `);
37403
+ if (index < joins.length - 1) joinsArray.push(sql` `);
37386
37404
  }
37387
37405
  return sql.join(joinsArray);
37388
37406
  }
@@ -37391,9 +37409,9 @@ var SQLiteDialect = class {
37391
37409
  }
37392
37410
  buildOrderBy(orderBy) {
37393
37411
  const orderByList = [];
37394
- if (orderBy) for (const [index2, orderByValue] of orderBy.entries()) {
37412
+ if (orderBy) for (const [index, orderByValue] of orderBy.entries()) {
37395
37413
  orderByList.push(orderByValue);
37396
- if (index2 < orderBy.length - 1) orderByList.push(sql`, `);
37414
+ if (index < orderBy.length - 1) orderByList.push(sql`, `);
37397
37415
  }
37398
37416
  return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
37399
37417
  }
@@ -37421,9 +37439,9 @@ var SQLiteDialect = class {
37421
37439
  const whereSql = where ? sql` where ${where}` : void 0;
37422
37440
  const havingSql = having ? sql` having ${having}` : void 0;
37423
37441
  const groupByList = [];
37424
- if (groupBy) for (const [index2, groupByValue] of groupBy.entries()) {
37442
+ if (groupBy) for (const [index, groupByValue] of groupBy.entries()) {
37425
37443
  groupByList.push(groupByValue);
37426
- if (index2 < groupBy.length - 1) groupByList.push(sql`, `);
37444
+ if (index < groupBy.length - 1) groupByList.push(sql`, `);
37427
37445
  }
37428
37446
  const finalQuery = sql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupByList.length > 0 ? sql` group by ${sql.join(groupByList)}` : void 0}${havingSql}${this.buildOrderBy(orderBy)}${this.buildLimit(limit)}${offset ? sql` offset ${offset}` : void 0}`;
37429
37447
  if (setOperators.length > 0) return this.buildSetOperations(finalQuery, setOperators);
@@ -38715,6 +38733,10 @@ var acpSessionStoreMigrations = [
38715
38733
  {
38716
38734
  "name": "0002_equal_black_queen.sql",
38717
38735
  "sql": "CREATE TABLE `session_event_v2` (\n `event_id` text PRIMARY KEY NOT NULL,\n `event_json` text NOT NULL,\n `position` integer NOT NULL,\n `session_id` text NOT NULL\n);\n--> statement-breakpoint\nCREATE UNIQUE INDEX `session_event_v2_session_position_unique` ON `session_event_v2` (`session_id`,`position`);--> statement-breakpoint\nCREATE INDEX `session_event_v2_session_position_index` ON `session_event_v2` (`session_id`,`position`);"
38736
+ },
38737
+ {
38738
+ "name": "0003_silky_ravenous.sql",
38739
+ "sql": "DROP TABLE `session_event_v2`;"
38718
38740
  }
38719
38741
  ];
38720
38742
 
@@ -38736,21 +38758,6 @@ var deletedAcpSession = sqliteTable("deleted_acp_session", {
38736
38758
  sessionId: text("session_id").primaryKey()
38737
38759
  });
38738
38760
 
38739
- // src/schema/acp-session-store/session-event-v2.ts
38740
- var sessionEventV2 = sqliteTable(
38741
- "session_event_v2",
38742
- {
38743
- eventId: text("event_id").primaryKey(),
38744
- eventJson: text("event_json").notNull(),
38745
- position: integer2("position").notNull(),
38746
- sessionId: text("session_id").notNull()
38747
- },
38748
- (table) => [
38749
- uniqueIndex("session_event_v2_session_position_unique").on(table.sessionId, table.position),
38750
- index("session_event_v2_session_position_index").on(table.sessionId, table.position)
38751
- ]
38752
- );
38753
-
38754
38761
  // src/acp/session-store.ts
38755
38762
  var AcpStoredSession = class {
38756
38763
  additionalDirectories;
@@ -38793,21 +38800,9 @@ var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
38793
38800
  var MemoryAcpSessionStore = class {
38794
38801
  #sessions = /* @__PURE__ */ new Map();
38795
38802
  #deleted = /* @__PURE__ */ new Set();
38796
- #eventsV2 = /* @__PURE__ */ new Map();
38797
- appendExecutingPromptEventV2 = (event) => {
38798
- const events = this.#eventsV2.get(event.sessionId);
38799
- if (events === void 0) {
38800
- throw new Error("The executing prompt event log has not started");
38801
- }
38802
- events.push(event);
38803
- };
38804
- clearExecutingPromptEventsV2 = (sessionId) => {
38805
- this.#eventsV2.delete(sessionId);
38806
- };
38807
38803
  close = () => {
38808
38804
  this.#sessions.clear();
38809
38805
  this.#deleted.clear();
38810
- this.#eventsV2.clear();
38811
38806
  };
38812
38807
  findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
38813
38808
  (session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
@@ -38818,7 +38813,6 @@ var MemoryAcpSessionStore = class {
38818
38813
  for (const id of ids) {
38819
38814
  this.#sessions.delete(id);
38820
38815
  this.#deleted.add(id);
38821
- this.#eventsV2.delete(id);
38822
38816
  }
38823
38817
  return ids;
38824
38818
  };
@@ -38831,13 +38825,6 @@ var MemoryAcpSessionStore = class {
38831
38825
  };
38832
38826
  remove = (sessionId) => {
38833
38827
  this.#sessions.delete(sessionId);
38834
- this.#eventsV2.delete(sessionId);
38835
- };
38836
- readExecutingPromptEventsV2 = (sessionId) => [
38837
- ...this.#eventsV2.get(sessionId) ?? []
38838
- ];
38839
- startExecutingPromptEventsV2 = (sessionId, events) => {
38840
- this.#eventsV2.set(sessionId, [...events]);
38841
38828
  };
38842
38829
  write = (session) => {
38843
38830
  this.#sessions.set(session.sessionId, session);
@@ -38887,15 +38874,15 @@ var SqliteAcpSessionStore = class {
38887
38874
  this.#sqliteDatabase.close();
38888
38875
  throw new Error("The ACP Session database was created by a newer Mobius version");
38889
38876
  }
38890
- for (let index2 = version2; index2 < acpSessionStoreMigrations.length; index2 += 1) {
38891
- const migration = acpSessionStoreMigrations[index2];
38877
+ for (let index = version2; index < acpSessionStoreMigrations.length; index += 1) {
38878
+ const migration = acpSessionStoreMigrations[index];
38892
38879
  if (migration === void 0) {
38893
38880
  throw new Error("The ACP Session migration is unavailable");
38894
38881
  }
38895
38882
  this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
38896
38883
  try {
38897
38884
  this.#sqliteDatabase.exec(migration.sql);
38898
- this.#sqliteDatabase.exec(`PRAGMA user_version = ${index2 + 1}`);
38885
+ this.#sqliteDatabase.exec(`PRAGMA user_version = ${index + 1}`);
38899
38886
  this.#sqliteDatabase.exec("COMMIT");
38900
38887
  } catch (error62) {
38901
38888
  this.#sqliteDatabase.exec("ROLLBACK");
@@ -38916,30 +38903,6 @@ var SqliteAcpSessionStore = class {
38916
38903
  close = () => {
38917
38904
  this.#sqliteDatabase.close();
38918
38905
  };
38919
- appendExecutingPromptEventV2 = (event) => {
38920
- this.#database.insert(sessionEventV2).values({
38921
- eventId: event.eventId,
38922
- eventJson: JSON.stringify(event),
38923
- position: Number(event.position),
38924
- sessionId: event.sessionId
38925
- }).run();
38926
- };
38927
- clearExecutingPromptEventsV2 = (sessionId) => {
38928
- this.#database.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).run();
38929
- };
38930
- startExecutingPromptEventsV2 = (sessionId, events) => {
38931
- this.#transaction(() => {
38932
- this.#database.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).run();
38933
- for (const event of events) {
38934
- this.#database.insert(sessionEventV2).values({
38935
- eventId: event.eventId,
38936
- eventJson: JSON.stringify(event),
38937
- position: Number(event.position),
38938
- sessionId: event.sessionId
38939
- }).run();
38940
- }
38941
- });
38942
- };
38943
38906
  findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
38944
38907
  list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
38945
38908
  markDeleted = (agentId, nativeSessionId) => {
@@ -38948,7 +38911,6 @@ var SqliteAcpSessionStore = class {
38948
38911
  this.#database.delete(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).run();
38949
38912
  for (const id of ids) {
38950
38913
  this.#database.insert(deletedAcpSession).values({ sessionId: id }).onConflictDoNothing().run();
38951
- this.#database.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, id)).run();
38952
38914
  }
38953
38915
  });
38954
38916
  return ids;
@@ -38962,12 +38924,8 @@ var SqliteAcpSessionStore = class {
38962
38924
  const row = this.#database.select().from(acpSession).where(eq(acpSession.sessionId, sessionId)).get();
38963
38925
  return row === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(decodeStoredSession(row));
38964
38926
  };
38965
- readExecutingPromptEventsV2 = (sessionId) => this.#database.select({ eventJson: sessionEventV2.eventJson }).from(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).orderBy(asc(sessionEventV2.position)).all().map((row) => decodeSessionEventV2(row.eventJson));
38966
38927
  remove = (sessionId) => {
38967
- this.#transaction(() => {
38968
- this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
38969
- this.#database.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).run();
38970
- });
38928
+ this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
38971
38929
  };
38972
38930
  write = (session) => {
38973
38931
  const value = {
@@ -39000,7 +38958,7 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
39000
38958
  }
39001
38959
  };
39002
38960
  function arraysEqual(left, right) {
39003
- return left.length === right.length && left.every((value, index2) => value === right[index2]);
38961
+ return left.length === right.length && left.every((value, index) => value === right[index]);
39004
38962
  }
39005
38963
  function recordsEqual(left, right) {
39006
38964
  const leftEntries = Object.entries(left);
@@ -39037,6 +38995,7 @@ var AgentSession = class _AgentSession {
39037
38995
  #sessionTitle = null;
39038
38996
  #sessionUpdatedAt = "";
39039
38997
  #turn = new IdleAcpTurn();
38998
+ #turnHistory = null;
39040
38999
  constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store, metrics, contentExternalizer) {
39041
39000
  this.#updates = new AgentUpdateStream((notification) => this.#processUpdate(notification));
39042
39001
  this.#additionalDirectories = [...additionalDirectories];
@@ -39054,7 +39013,8 @@ var AgentSession = class _AgentSession {
39054
39013
  sessionId: () => this.#mobiusSessionId,
39055
39014
  commandId: () => this.#turn.commandId,
39056
39015
  assertNativeSession: (sessionId) => this.assertNativeSession(sessionId),
39057
- observer: getObserver
39016
+ observer: getObserver,
39017
+ recordSessionEventV2: this.#recordLifecycleEventV2
39058
39018
  });
39059
39019
  this.#connection = new AgentConnection(agent, cwd, this);
39060
39020
  this.#contentExternalizer = contentExternalizer;
@@ -39150,13 +39110,10 @@ var AgentSession = class _AgentSession {
39150
39110
  }
39151
39111
  };
39152
39112
  }
39153
- const loaded = await this.#loadSession(signal, "ACP agent exited while loading history");
39154
- return await embedLocalHistoryImages(await loaded.history.snapshot(), signal);
39113
+ const history = await this.#completedHistory(signal, "ACP agent exited while loading history");
39114
+ return await embedLocalHistoryImages(await history.snapshot(), signal);
39155
39115
  };
39156
39116
  loadHistoryEventsV2 = async (eventLimit, cursor, signal) => {
39157
- if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
39158
- return new AcpHistoryReplay().eventPage(eventLimit, cursor);
39159
- }
39160
39117
  if (!this.#capabilities.loadSession) {
39161
39118
  throw new AcpExecutionError(
39162
39119
  "This Agent restores context but does not provide message history.",
@@ -39164,9 +39121,20 @@ var AgentSession = class _AgentSession {
39164
39121
  "native_history_unsupported"
39165
39122
  );
39166
39123
  }
39167
- const loaded = await this.#loadSession(signal, "ACP agent exited while loading history");
39168
- return loaded.history.eventPage(eventLimit, cursor);
39124
+ const history = await this.#completedHistory(signal, "ACP agent exited while loading history");
39125
+ return history.eventPage(eventLimit, cursor, this.#turnHistory);
39169
39126
  };
39127
+ async #completedHistory(signal, exitMessage) {
39128
+ if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
39129
+ if (this.#sessionLoad.kind === "not-requested") {
39130
+ this.#sessionLoad = { history: new AcpHistoryReplay(), kind: "loaded", response: {} };
39131
+ }
39132
+ if (this.#sessionLoad.kind === "loaded") {
39133
+ return this.#sessionLoad.history;
39134
+ }
39135
+ }
39136
+ return (await this.#loadSession(signal, exitMessage)).history;
39137
+ }
39170
39138
  async #loadSession(signal, exitMessage) {
39171
39139
  if (this.#sessionLoad.kind === "loaded") {
39172
39140
  return this.#sessionLoad;
@@ -39650,19 +39618,7 @@ var AgentSession = class _AgentSession {
39650
39618
  if (this.#turn.running) {
39651
39619
  throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
39652
39620
  }
39653
- switch (this.#sessionLoad.kind) {
39654
- case "not-requested":
39655
- break;
39656
- case "loaded":
39657
- this.#sessionLoad = { kind: "not-requested" };
39658
- break;
39659
- case "capturing":
39660
- throw new AcpExecutionError("Session history is still loading", {}, "session_busy");
39661
- default: {
39662
- const unexpected = this.#sessionLoad;
39663
- throw new Error(`Unexpected Session load state: ${JSON.stringify(unexpected)}`);
39664
- }
39665
- }
39621
+ const completedHistory = this.#capabilities.loadSession ? await this.#completedHistory(options.signal, "ACP agent exited while loading history before a prompt") : null;
39666
39622
  const prompt = this.buildPrompt(options);
39667
39623
  if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
39668
39624
  this.#sessionTitle = truncate(options.prompt, 500);
@@ -39689,6 +39645,23 @@ var AgentSession = class _AgentSession {
39689
39645
  this.prepareAgentContent
39690
39646
  );
39691
39647
  this.#turn = running;
39648
+ this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay();
39649
+ const lifecycleV2 = options.lifecycleV2;
39650
+ if (lifecycleV2 !== void 0) {
39651
+ await this.#recordLifecycleEventV2({
39652
+ payload: { commandId: options.commandId, content: lifecycleV2.content, kind: "prompt.requested" },
39653
+ type: "lifecycle-metadata"
39654
+ });
39655
+ await this.#recordLifecycleEventV2({
39656
+ payload: {
39657
+ attemptId: lifecycleV2.attemptId,
39658
+ commandId: options.commandId,
39659
+ epoch: lifecycleV2.epoch,
39660
+ kind: "prompt.started"
39661
+ },
39662
+ type: "lifecycle-metadata"
39663
+ });
39664
+ }
39692
39665
  this.#nativePrompt = {
39693
39666
  commandId: options.commandId,
39694
39667
  previousTurnId: this.#connection.inProcessAgent?.nativeTurnId?.() ?? null
@@ -39743,16 +39716,37 @@ var AgentSession = class _AgentSession {
39743
39716
  this.#lastTerminalCommandId
39744
39717
  )
39745
39718
  );
39719
+ if (lifecycleV2 !== void 0) {
39720
+ await this.#recordLifecycleEventV2({
39721
+ payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: result.stopReason },
39722
+ type: "lifecycle-metadata"
39723
+ });
39724
+ }
39746
39725
  return result;
39747
39726
  } catch (error62) {
39748
39727
  await running.activities.finish();
39728
+ const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
39729
+ if (lifecycleV2 !== void 0) {
39730
+ await this.#recordLifecycleEventV2({
39731
+ payload: {
39732
+ attemptId: lifecycleV2.attemptId,
39733
+ code: failure2.code,
39734
+ commandId: options.commandId,
39735
+ kind: "prompt.failed",
39736
+ message: truncate(failure2.message, 500)
39737
+ },
39738
+ type: "lifecycle-metadata"
39739
+ });
39740
+ }
39749
39741
  if (error62 instanceof AcpExecutionError) {
39750
39742
  throw error62;
39751
39743
  }
39752
- throw new AcpExecutionError("ACP agent execution failed", {
39753
- cause: error62
39754
- });
39744
+ throw failure2;
39755
39745
  } finally {
39746
+ if (completedHistory !== null && this.#turnHistory !== null) {
39747
+ await completedHistory.append(this.#turnHistory);
39748
+ }
39749
+ this.#turnHistory = null;
39756
39750
  this.#turn = new IdleAcpTurn();
39757
39751
  }
39758
39752
  };
@@ -39768,41 +39762,80 @@ var AgentSession = class _AgentSession {
39768
39762
  throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
39769
39763
  }
39770
39764
  const prompt = this.buildPrompt(options);
39771
- const response = await this.race(
39772
- this.#connection.connection.agent.request("_session/steering", {
39773
- _meta: { steering: { idleBehavior: "promptRequired" } },
39774
- prompt,
39775
- sessionId: this.#updates.sessionId()
39776
- }),
39777
- "ACP agent exited during steering",
39778
- options.signal
39779
- );
39780
- if (!isRecord3(response)) {
39765
+ const lifecycleV2 = options.lifecycleV2;
39766
+ if (lifecycleV2 !== void 0) {
39767
+ await this.#recordLifecycleEventV2({
39768
+ payload: { commandId: options.commandId, content: lifecycleV2.content, kind: "prompt.requested" },
39769
+ type: "lifecycle-metadata"
39770
+ });
39771
+ await this.#recordLifecycleEventV2({
39772
+ payload: {
39773
+ attemptId: lifecycleV2.attemptId,
39774
+ commandId: options.commandId,
39775
+ epoch: lifecycleV2.epoch,
39776
+ kind: "prompt.started"
39777
+ },
39778
+ type: "lifecycle-metadata"
39779
+ });
39780
+ }
39781
+ try {
39782
+ const response = await this.race(
39783
+ this.#connection.connection.agent.request("_session/steering", {
39784
+ _meta: { steering: { idleBehavior: "promptRequired" } },
39785
+ prompt,
39786
+ sessionId: this.#updates.sessionId()
39787
+ }),
39788
+ "ACP agent exited during steering",
39789
+ options.signal
39790
+ );
39791
+ if (!isRecord3(response)) {
39792
+ throw new AcpExecutionError(
39793
+ "ACP agent returned an invalid steering response",
39794
+ {},
39795
+ "acp_invalid_steering_response"
39796
+ );
39797
+ }
39798
+ const outcome = response["outcome"];
39799
+ if (outcome === "injected" || outcome === "startedNewTurn") {
39800
+ if (lifecycleV2 !== void 0) {
39801
+ await this.#recordLifecycleEventV2({
39802
+ payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: "steered" },
39803
+ type: "lifecycle-metadata"
39804
+ });
39805
+ }
39806
+ return outcome;
39807
+ }
39808
+ if (outcome === "promptRequired") {
39809
+ throw new AcpExecutionError(
39810
+ "The target turn finished before steering could be injected",
39811
+ {},
39812
+ "steering_target_unavailable"
39813
+ );
39814
+ }
39815
+ if (outcome === "failed") {
39816
+ throw new AcpExecutionError("The Agent could not inject steering", {}, "steering_failed");
39817
+ }
39781
39818
  throw new AcpExecutionError(
39782
39819
  "ACP agent returned an invalid steering response",
39783
39820
  {},
39784
39821
  "acp_invalid_steering_response"
39785
39822
  );
39823
+ } catch (error62) {
39824
+ const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
39825
+ if (lifecycleV2 !== void 0) {
39826
+ await this.#recordLifecycleEventV2({
39827
+ payload: {
39828
+ attemptId: lifecycleV2.attemptId,
39829
+ code: failure2.code,
39830
+ commandId: options.commandId,
39831
+ kind: "prompt.failed",
39832
+ message: truncate(failure2.message, 500)
39833
+ },
39834
+ type: "lifecycle-metadata"
39835
+ });
39836
+ }
39837
+ throw failure2;
39786
39838
  }
39787
- const outcome = response["outcome"];
39788
- if (outcome === "injected" || outcome === "startedNewTurn") {
39789
- return outcome;
39790
- }
39791
- if (outcome === "promptRequired") {
39792
- throw new AcpExecutionError(
39793
- "The target turn finished before steering could be injected",
39794
- {},
39795
- "steering_target_unavailable"
39796
- );
39797
- }
39798
- if (outcome === "failed") {
39799
- throw new AcpExecutionError("The Agent could not inject steering", {}, "steering_failed");
39800
- }
39801
- throw new AcpExecutionError(
39802
- "ACP agent returned an invalid steering response",
39803
- {},
39804
- "acp_invalid_steering_response"
39805
- );
39806
39839
  };
39807
39840
  cancel = async () => {
39808
39841
  const capturedProcesses = await this.#connection.captureProcessTree();
@@ -39823,6 +39856,13 @@ var AgentSession = class _AgentSession {
39823
39856
  onElicitation = (request, signal) => this.#interactions.onElicitation(request, signal);
39824
39857
  onElicitationComplete = (notification) => this.#interactions.onElicitationComplete(notification);
39825
39858
  onUpdate = (notification) => this.#updates.receive(notification);
39859
+ #recordLifecycleEventV2 = async (event) => {
39860
+ if (event.type !== "lifecycle-metadata" || this.#sessionLoad.kind !== "loaded") {
39861
+ return;
39862
+ }
39863
+ const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#sessionLoad.history.eventCount() + this.#turnHistory.recordLifecycle(event);
39864
+ await this.#getObserver().onSessionEventV2?.(this.#mobiusSessionId, event, position);
39865
+ };
39826
39866
  selectNativeSession = (sessionId) => {
39827
39867
  this.#updates.select(sessionId);
39828
39868
  this.#nativeHistoryOwnership = { kind: "agent-owned" };
@@ -39839,9 +39879,20 @@ var AgentSession = class _AgentSession {
39839
39879
  if (this.#sessionLoad.kind === "capturing") {
39840
39880
  await this.#sessionLoad.history.record(update, rawUpdate);
39841
39881
  } else {
39842
- const onAcpUpdate = this.#getObserver().onAcpUpdate;
39843
- if (onAcpUpdate !== void 0) {
39844
- await onAcpUpdate(this.#mobiusSessionId, rawUpdate);
39882
+ const onSessionEventV2 = this.#getObserver().onSessionEventV2;
39883
+ if (this.#turnHistory !== null) {
39884
+ const completedEventCount = this.#sessionLoad.kind === "loaded" ? this.#sessionLoad.history.eventCount() : 0;
39885
+ await this.#turnHistory.record(update, rawUpdate, async (turnPosition) => {
39886
+ await onSessionEventV2?.(
39887
+ this.#mobiusSessionId,
39888
+ { payload: rawUpdate, type: "acp" },
39889
+ completedEventCount + turnPosition
39890
+ );
39891
+ });
39892
+ } else if (this.#sessionLoad.kind === "loaded") {
39893
+ await this.#sessionLoad.history.record(update, rawUpdate, async (position) => {
39894
+ await onSessionEventV2?.(this.#mobiusSessionId, { payload: rawUpdate, type: "acp" }, position);
39895
+ });
39845
39896
  }
39846
39897
  }
39847
39898
  if (this.#sessionLoad.kind === "capturing" && (update.sessionUpdate === "user_message_chunk" || update.sessionUpdate === "agent_message_chunk" || update.sessionUpdate === "agent_thought_chunk" || update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update" || update.sessionUpdate === "plan" || update.sessionUpdate === "plan_update" || update.sessionUpdate === "plan_removed")) {
@@ -40704,9 +40755,9 @@ var AcpProcessCapacityLock = class {
40704
40755
  return await waiter.completion.promise;
40705
40756
  } finally {
40706
40757
  signal.removeEventListener("abort", waiter.cancel);
40707
- const index2 = this.#waiters.indexOf(waiter);
40708
- if (index2 >= 0) {
40709
- this.#waiters.splice(index2, 1);
40758
+ const index = this.#waiters.indexOf(waiter);
40759
+ if (index >= 0) {
40760
+ this.#waiters.splice(index, 1);
40710
40761
  }
40711
40762
  }
40712
40763
  };
@@ -42620,8 +42671,8 @@ var DaemonAcpObserver = class {
42620
42671
  this.#record = record2;
42621
42672
  this.#recordV2 = recordV2;
42622
42673
  }
42623
- onAcpUpdate = (sessionId, update) => {
42624
- this.#recordV2(sessionId, { payload: update, type: "acp" });
42674
+ onSessionEventV2 = (sessionId, event, position) => {
42675
+ this.#recordV2(sessionId, event, position);
42625
42676
  return Promise.resolve();
42626
42677
  };
42627
42678
  onCommands = (event) => {
@@ -42638,18 +42689,10 @@ var DaemonAcpObserver = class {
42638
42689
  };
42639
42690
  onElicitation = (event) => {
42640
42691
  this.#record(event.sessionId, event);
42641
- this.#recordV2(event.sessionId, {
42642
- payload: { event, kind: "session.elicitation.requested" },
42643
- type: "lifecycle-metadata"
42644
- });
42645
42692
  return Promise.resolve();
42646
42693
  };
42647
42694
  onElicitationResolved = (event) => {
42648
42695
  this.#record(event.sessionId, event);
42649
- this.#recordV2(event.sessionId, {
42650
- payload: { event, kind: "session.elicitation.resolved" },
42651
- type: "lifecycle-metadata"
42652
- });
42653
42696
  return Promise.resolve();
42654
42697
  };
42655
42698
  onInfo = (event) => {
@@ -42658,18 +42701,10 @@ var DaemonAcpObserver = class {
42658
42701
  };
42659
42702
  onPermission = (event) => {
42660
42703
  this.#record(event.sessionId, event);
42661
- this.#recordV2(event.sessionId, {
42662
- payload: { event, kind: "session.permission.requested" },
42663
- type: "lifecycle-metadata"
42664
- });
42665
42704
  return Promise.resolve();
42666
42705
  };
42667
42706
  onPermissionResolved = (event) => {
42668
42707
  this.#record(event.sessionId, event);
42669
- this.#recordV2(event.sessionId, {
42670
- payload: { event, kind: "session.permission.resolved" },
42671
- type: "lifecycle-metadata"
42672
- });
42673
42708
  return Promise.resolve();
42674
42709
  };
42675
42710
  onUsage = (event) => {
@@ -42776,8 +42811,8 @@ var ACTIVE_TURN_TEXT_CHUNK_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT /
42776
42811
  function boundedRecoveryMessages(messages) {
42777
42812
  const selected = [];
42778
42813
  let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT;
42779
- for (let index2 = messages.length - 1; index2 >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index2 -= 1) {
42780
- const message = messages[index2];
42814
+ for (let index = messages.length - 1; index >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index -= 1) {
42815
+ const message = messages[index];
42781
42816
  if (message === void 0) {
42782
42817
  break;
42783
42818
  }
@@ -42918,7 +42953,7 @@ var ActiveDaemonTurn = class {
42918
42953
  ];
42919
42954
  } else {
42920
42955
  this.#timeline = this.#timeline.map(
42921
- (entry, index2) => index2 === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
42956
+ (entry, index) => index === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
42922
42957
  );
42923
42958
  }
42924
42959
  } else if (event.kind === SESSION_PERMISSION_REQUESTED_KIND || event.kind === SESSION_ELICITATION_REQUESTED_KIND) {
@@ -43944,7 +43979,7 @@ async function readAcpHistory(sessions, directories, bindingId, options, nativeS
43944
43979
  async (directory) => await directories.identify(bindingId, directory, options.signal)
43945
43980
  )
43946
43981
  );
43947
- if (primary.path !== options.cwd || additional.length !== options.additionalDirectories.length || additional.some((directory, index2) => directory.path !== options.additionalDirectories[index2])) {
43982
+ if (primary.path !== options.cwd || additional.length !== options.additionalDirectories.length || additional.some((directory, index) => directory.path !== options.additionalDirectories[index])) {
43948
43983
  throw new AcpExecutionError(
43949
43984
  "The native Session belongs to another workspace.",
43950
43985
  {},
@@ -44077,7 +44112,7 @@ var NativeSessionService = class {
44077
44112
  "native_session_not_found"
44078
44113
  );
44079
44114
  }
44080
- if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path3, index2) => path3 !== additionalDirectories[index2])) {
44115
+ if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path3, index) => path3 !== additionalDirectories[index])) {
44081
44116
  throw new AcpExecutionError(
44082
44117
  "The source conversation execution target does not match the fork request",
44083
44118
  {},
@@ -44098,8 +44133,8 @@ var NativeSessionService = class {
44098
44133
  signal.throwIfAborted();
44099
44134
  const directory = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
44100
44135
  const ready2 = {
44101
- additionalDirectories: additionalDirectories.map((path3, index2) => ({
44102
- directoryId: command.additionalDirectoryIds[index2] ?? command.directoryId,
44136
+ additionalDirectories: additionalDirectories.map((path3, index) => ({
44137
+ directoryId: command.additionalDirectoryIds[index] ?? command.directoryId,
44103
44138
  name: basename5(path3) || path3
44104
44139
  })),
44105
44140
  agentId: command.agentId,
@@ -44432,7 +44467,7 @@ var NativeSessionService = class {
44432
44467
  resolveTarget = async (command, options, selected) => {
44433
44468
  let cursor = null;
44434
44469
  const visited = /* @__PURE__ */ new Set();
44435
- for (let index2 = 0; index2 < 100; index2 += 1) {
44470
+ for (let index = 0; index < 100; index += 1) {
44436
44471
  const page = await this.#sessions.listNativeSessions(options, cursor);
44437
44472
  const info = page.sessions.find((entry) => entry.sessionId === selected.nativeSessionId);
44438
44473
  if (info !== void 0) {
@@ -44440,7 +44475,7 @@ var NativeSessionService = class {
44440
44475
  if (target === null) {
44441
44476
  throw new LocalAuthorizationError("The selected native session is not authorized");
44442
44477
  }
44443
- if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path3, index3) => path3 !== selected.additionalDirectories[index3])) {
44478
+ if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path3, index2) => path3 !== selected.additionalDirectories[index2])) {
44444
44479
  throw new AcpExecutionError(
44445
44480
  "This session's directory changed. Refresh the list before continuing.",
44446
44481
  {},
@@ -45529,9 +45564,6 @@ async function streamLocalFile(command, send2, signal, workingDirectory, externa
45529
45564
  });
45530
45565
  }
45531
45566
 
45532
- // src/daemon-history-commands.ts
45533
- import { createHash as createHash7 } from "node:crypto";
45534
-
45535
45567
  // src/authorization/resolve-session-directories.ts
45536
45568
  import { basename as basename7 } from "node:path";
45537
45569
  var ResolvedSessionDirectories = class {
@@ -45631,8 +45663,8 @@ function selectMessagesBefore(messages, endIndex, messageLimit, characterLimit)
45631
45663
  const selected = [];
45632
45664
  let remainingCharacters = characterLimit;
45633
45665
  let startIndex = endIndex;
45634
- for (let index2 = endIndex - 1; index2 >= 0 && selected.length < messageLimit; index2 -= 1) {
45635
- const message = messages[index2];
45666
+ for (let index = endIndex - 1; index >= 0 && selected.length < messageLimit; index -= 1) {
45667
+ const message = messages[index];
45636
45668
  if (message === void 0) {
45637
45669
  break;
45638
45670
  }
@@ -45642,7 +45674,7 @@ function selectMessagesBefore(messages, endIndex, messageLimit, characterLimit)
45642
45674
  }
45643
45675
  selected.unshift(message);
45644
45676
  remainingCharacters -= characters;
45645
- startIndex = index2;
45677
+ startIndex = index;
45646
45678
  }
45647
45679
  if (selected.length === 0 && endIndex > 0) {
45648
45680
  throw new AcpExecutionError(
@@ -45858,20 +45890,7 @@ async function executeSessionLiveHistoryPageLoad(socket, command, config2, direc
45858
45890
  });
45859
45891
  }
45860
45892
  }
45861
- function replayEvent(sessionId, position, update) {
45862
- const encoded = JSON.stringify(update);
45863
- const eventId = `native-${createHash7("sha256").update(sessionId).update(":").update(position.toString()).update(":").update(encoded).digest("hex")}`;
45864
- return {
45865
- eventId,
45866
- payload: update,
45867
- position: position.toString(),
45868
- provenance: { kind: "original" },
45869
- recordedAt: "1970-01-01T00:00:00.000Z",
45870
- sessionId,
45871
- type: "acp"
45872
- };
45873
- }
45874
- async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, directories, audit, diagnostics, sessions, executingPromptRequest, signal) {
45893
+ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, directories, audit, diagnostics, sessions, eventLogV2, signal) {
45875
45894
  try {
45876
45895
  const resolved = await resolveSessionDirectories(
45877
45896
  directories,
@@ -45880,20 +45899,18 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
45880
45899
  command.additionalDirectoryIds,
45881
45900
  signal
45882
45901
  );
45883
- const replay = await sessions.loadSessionEventsV2(
45884
- {
45885
- additionalDirectories: resolved.additionalDirectories,
45886
- agent: config2.catalog.find(command.agentId),
45887
- cwd: resolved.cwd,
45888
- sessionId: command.sessionId,
45889
- signal
45890
- },
45891
- command.eventLimit,
45892
- command.cursor
45893
- );
45902
+ const loadOptions = {
45903
+ additionalDirectories: resolved.additionalDirectories,
45904
+ agent: config2.catalog.find(command.agentId),
45905
+ cwd: resolved.cwd,
45906
+ sessionId: command.sessionId,
45907
+ signal
45908
+ };
45909
+ const recovery = eventLogV2.promptRequestRecovery(command.sessionId);
45910
+ const replay = await sessions.loadSessionEventsV2(loadOptions, command.eventLimit, command.cursor);
45894
45911
  signal.throwIfAborted();
45895
- const events = replay.updates.map(
45896
- (update, index2) => replayEvent(command.sessionId, replay.startPosition + index2, update)
45912
+ const events = replay.events.map(
45913
+ (event, index) => eventLogV2.event(command.sessionId, replay.startPosition + index, event, "1970-01-01T00:00:00.000Z")
45897
45914
  );
45898
45915
  const tailCursor = events.at(-1)?.eventId ?? "";
45899
45916
  audit.record({
@@ -45903,14 +45920,15 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
45903
45920
  });
45904
45921
  send(socket, {
45905
45922
  events: {
45906
- executingPromptRequest: executingPromptRequest(command.sessionId),
45907
- history: {
45923
+ events: {
45924
+ daemonGenerationId: eventLogV2.daemonGenerationId,
45908
45925
  events,
45909
45926
  nextCursor: replay.nextCursor,
45910
45927
  tailCursor,
45911
45928
  truncated: replay.truncated,
45912
45929
  version: 2
45913
- }
45930
+ },
45931
+ queuedPromptRequests: recovery.queuedPromptRequests
45914
45932
  },
45915
45933
  kind: "session.live-history.v2.page.loaded",
45916
45934
  requestId: command.requestId,
@@ -46360,7 +46378,7 @@ async function executePrompt({
46360
46378
  }
46361
46379
  }
46362
46380
  const stream = activateAttempt();
46363
- eventLogV2.started(command.sessionId, command.commandId, attemptId, stream.epoch);
46381
+ const lifecycleV2 = eventLogV2.started(command.sessionId, command.commandId, attemptId, stream.epoch);
46364
46382
  if (!prepared.prompted) {
46365
46383
  const listing = await directories.list(config2.bindingId, command.directoryId, signal);
46366
46384
  publisher.publish(command.sessionId, {
@@ -46397,6 +46415,7 @@ async function executePrompt({
46397
46415
  commandId: command.commandId,
46398
46416
  cwd: resolved.cwd,
46399
46417
  images: attachments.images,
46418
+ lifecycleV2,
46400
46419
  prompt: command.prompt,
46401
46420
  resources: attachments.resources,
46402
46421
  sessionId: command.sessionId,
@@ -46412,6 +46431,7 @@ async function executePrompt({
46412
46431
  cwd: resolved.cwd,
46413
46432
  disposition: availability.disposition,
46414
46433
  images: attachments.images,
46434
+ lifecycleV2,
46415
46435
  onActivity: events.recordActivity,
46416
46436
  onNarration: events.recordNarration,
46417
46437
  onText: events.recordText,
@@ -46826,7 +46846,7 @@ function createDaemonCommandHandler({
46826
46846
  audit,
46827
46847
  diagnostics,
46828
46848
  sessions,
46829
- eventLogV2.executingPromptRequest,
46849
+ eventLogV2,
46830
46850
  signal
46831
46851
  );
46832
46852
  return;
@@ -47499,10 +47519,6 @@ import { WebSocket as WebSocket9 } from "undici";
47499
47519
  var MAX_BUFFERED_BYTES = 32 * 1024 * 1024;
47500
47520
  var DaemonSessionEventPublisher = class {
47501
47521
  #socket = null;
47502
- #store;
47503
- constructor(store) {
47504
- this.#store = store;
47505
- }
47506
47522
  connect = (socket) => {
47507
47523
  this.#socket = socket;
47508
47524
  };
@@ -47554,7 +47570,6 @@ var DaemonSessionEventPublisher = class {
47554
47570
  }
47555
47571
  };
47556
47572
  publishV2 = (event) => {
47557
- this.#store.appendExecutingPromptEventV2(event);
47558
47573
  const socket = this.#socket;
47559
47574
  if (socket === null || socket.readyState !== WebSocket9.OPEN) {
47560
47575
  return;
@@ -47581,7 +47596,7 @@ var SystemDaemonTimer = class {
47581
47596
  var systemDaemonTimer = new SystemDaemonTimer();
47582
47597
 
47583
47598
  // src/session-event-log-v2.ts
47584
- var EXECUTING_PROMPT_EVENT_LIMIT = 1e4;
47599
+ import { createHash as createHash7, randomUUID as randomUUID8 } from "node:crypto";
47585
47600
  function promptContent(command) {
47586
47601
  const content = [];
47587
47602
  if (command.prompt.length > 0) {
@@ -47605,176 +47620,59 @@ function promptContent(command) {
47605
47620
  }
47606
47621
  return content;
47607
47622
  }
47623
+ function sessionEventV2(daemonGenerationId, sessionId, position, event, recordedAt) {
47624
+ const sessionPrefix = createHash7("sha256").update(sessionId).digest("hex").slice(0, 16);
47625
+ return {
47626
+ eventId: `event-${daemonGenerationId}-${sessionPrefix}-${position.toString().padStart(16, "0")}`,
47627
+ ...event,
47628
+ position: position.toString(),
47629
+ provenance: { kind: "original" },
47630
+ recordedAt,
47631
+ sessionId
47632
+ };
47633
+ }
47608
47634
  var DaemonSessionEventLogV2 = class {
47609
- #positions = /* @__PURE__ */ new Map();
47610
- #requests = /* @__PURE__ */ new Map();
47611
- #loadedRequestSessions = /* @__PURE__ */ new Set();
47635
+ daemonGenerationId = randomUUID8();
47612
47636
  #publisher;
47613
- #store;
47614
- constructor(publisher, store) {
47637
+ #queued = /* @__PURE__ */ new Map();
47638
+ constructor(publisher) {
47615
47639
  this.#publisher = publisher;
47616
- this.#store = store;
47617
47640
  }
47618
- #loadStoredEvents = (sessionId) => {
47619
- const stored = this.#store.readExecutingPromptEventsV2(sessionId);
47620
- const lastPosition = stored.at(-1)?.position;
47621
- if (lastPosition !== void 0) {
47622
- this.#positions.set(sessionId, Number(lastPosition));
47623
- }
47624
- return stored;
47625
- };
47626
- #loadRequests = (sessionId) => {
47627
- if (this.#loadedRequestSessions.has(sessionId)) {
47628
- return;
47629
- }
47630
- for (const event of this.#loadStoredEvents(sessionId)) {
47631
- if (event.type === "acp") {
47632
- continue;
47633
- }
47634
- const payload = event.payload;
47635
- if (payload.kind === "prompt.requested") {
47636
- this.#requests.set(payload.commandId, {
47637
- commandId: payload.commandId,
47638
- kind: "requested",
47639
- sessionId
47640
- });
47641
- continue;
47642
- }
47643
- if ("event" in payload) {
47644
- continue;
47645
- }
47646
- if (!("commandId" in payload)) {
47647
- continue;
47648
- }
47649
- const state = this.#requests.get(payload.commandId);
47650
- if (state === void 0) {
47651
- continue;
47652
- }
47653
- if (payload.kind === "prompt.started") {
47654
- this.#requests.set(payload.commandId, {
47655
- attemptId: payload.attemptId,
47656
- commandId: payload.commandId,
47657
- epoch: payload.epoch,
47658
- kind: "executing",
47659
- sessionId
47660
- });
47661
- } else if (payload.kind === "prompt.completed" || payload.kind === "prompt.failed" || payload.kind === "prompt.failed-before-start") {
47662
- this.#requests.delete(payload.commandId);
47663
- }
47664
- }
47665
- this.#loadedRequestSessions.add(sessionId);
47666
- };
47667
- #append = (sessionId, payload) => {
47668
- this.#loadRequests(sessionId);
47669
- const position = (this.#positions.get(sessionId) ?? 0) + 1;
47670
- const event = {
47671
- eventId: `event-${crypto.randomUUID()}`,
47672
- ...payload,
47673
- position: position.toString(),
47674
- provenance: { kind: "original" },
47675
- recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
47676
- sessionId
47677
- };
47678
- this.#publisher.publishV2(event);
47679
- this.#positions.set(sessionId, position);
47680
- return event;
47681
- };
47682
47641
  requested = (command) => {
47683
- const content = promptContent(command);
47684
- this.#append(command.sessionId, {
47685
- payload: { commandId: command.commandId, content, kind: "prompt.requested" },
47686
- type: "lifecycle-metadata"
47687
- });
47688
- this.#requests.set(command.commandId, {
47642
+ this.#queued.set(command.commandId, {
47689
47643
  commandId: command.commandId,
47690
- kind: "requested",
47644
+ content: promptContent(command),
47691
47645
  sessionId: command.sessionId
47692
47646
  });
47693
47647
  };
47694
47648
  started = (sessionId, commandId, attemptId, epoch) => {
47695
- this.#loadRequests(sessionId);
47696
- const request = this.#requests.get(commandId);
47697
- if (request?.sessionId !== sessionId) {
47698
- return;
47649
+ const request = this.#queued.get(commandId);
47650
+ if (request?.sessionId === sessionId) {
47651
+ this.#queued.delete(commandId);
47652
+ return { attemptId, content: request.content, epoch };
47699
47653
  }
47700
- this.#append(sessionId, {
47701
- payload: { attemptId, commandId, epoch, kind: "prompt.started" },
47702
- type: "lifecycle-metadata"
47703
- });
47704
- this.#requests.set(commandId, {
47705
- attemptId,
47706
- commandId,
47707
- epoch,
47708
- kind: "executing",
47709
- sessionId
47710
- });
47654
+ throw new Error("The executing prompt was not registered in the V2 queue");
47711
47655
  };
47712
- record = (sessionId, payload) => {
47713
- this.#loadRequests(sessionId);
47714
- this.#append(sessionId, payload);
47656
+ record = (sessionId, event, position) => {
47657
+ this.#publisher.publishV2(this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString()));
47715
47658
  };
47716
- #clearCompletedSession = (sessionId) => {
47717
- if (![...this.#requests.values()].some((request) => request.sessionId === sessionId)) {
47718
- this.#store.clearExecutingPromptEventsV2(sessionId);
47659
+ event = (sessionId, position, event, recordedAt) => sessionEventV2(this.daemonGenerationId, sessionId, position, event, recordedAt);
47660
+ queueChanged = (_sessionId) => void 0;
47661
+ completed = (sessionId, commandId, _stopReason) => {
47662
+ const request = this.#queued.get(commandId);
47663
+ if (request?.sessionId === sessionId) {
47664
+ this.#queued.delete(commandId);
47719
47665
  }
47720
47666
  };
47721
- queueChanged = (sessionId) => {
47722
- this.#append(sessionId, {
47723
- payload: { kind: "session.queue.changed" },
47724
- type: "lifecycle-metadata"
47725
- });
47726
- };
47727
- completed = (sessionId, commandId, stopReason) => {
47728
- this.#loadRequests(sessionId);
47729
- this.#append(sessionId, {
47730
- payload: { commandId, kind: "prompt.completed", stopReason },
47731
- type: "lifecycle-metadata"
47732
- });
47733
- this.#requests.delete(commandId);
47734
- this.#clearCompletedSession(sessionId);
47735
- };
47736
- failed = (sessionId, commandId, code, message) => {
47737
- this.#loadRequests(sessionId);
47738
- const request = this.#requests.get(commandId);
47739
- if (request?.kind === "executing" && request.commandId === commandId) {
47740
- this.#append(sessionId, {
47741
- payload: {
47742
- attemptId: request.attemptId,
47743
- code,
47744
- commandId,
47745
- kind: "prompt.failed",
47746
- message
47747
- },
47748
- type: "lifecycle-metadata"
47749
- });
47750
- } else {
47751
- this.#append(sessionId, {
47752
- payload: { code, commandId, kind: "prompt.failed-before-start", message },
47753
- type: "lifecycle-metadata"
47754
- });
47755
- }
47756
- this.#requests.delete(commandId);
47757
- this.#clearCompletedSession(sessionId);
47758
- };
47759
- executingPromptRequest = (sessionId) => {
47760
- this.#loadRequests(sessionId);
47761
- const request = [...this.#requests.values()].find(
47762
- (candidate) => candidate.sessionId === sessionId && candidate.kind === "executing"
47763
- );
47764
- if (request?.kind !== "executing") {
47765
- return null;
47667
+ failed = (sessionId, commandId, _code, _message) => {
47668
+ const request = this.#queued.get(commandId);
47669
+ if (request?.sessionId === sessionId) {
47670
+ this.#queued.delete(commandId);
47766
47671
  }
47767
- const requestEvents = this.#store.readExecutingPromptEventsV2(sessionId);
47768
- const events = requestEvents.slice(-EXECUTING_PROMPT_EVENT_LIMIT);
47769
- return {
47770
- attemptId: request.attemptId,
47771
- commandId: request.commandId,
47772
- epoch: request.epoch,
47773
- events,
47774
- tailCursor: events.at(-1)?.eventId ?? "",
47775
- truncated: events.length < requestEvents.length
47776
- };
47777
47672
  };
47673
+ promptRequestRecovery = (sessionId) => ({
47674
+ queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId).map(({ commandId, content }) => ({ commandId, content }))
47675
+ });
47778
47676
  };
47779
47677
 
47780
47678
  // src/run-daemon.ts
@@ -47825,7 +47723,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
47825
47723
  {
47826
47724
  agentId: agent.id,
47827
47725
  kind: AGENT_INSTALL_REQUEST_KIND,
47828
- requestId: `automatic-integration-${randomUUID8()}`
47726
+ requestId: `automatic-integration-${randomUUID9()}`
47829
47727
  },
47830
47728
  signal
47831
47729
  );
@@ -47848,8 +47746,8 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
47848
47746
  );
47849
47747
  await using externalContent = new LocalExternalContentStore(stateDirectory);
47850
47748
  const operations = new DaemonOperationState();
47851
- const publisher = new DaemonSessionEventPublisher(sessionStore);
47852
- const eventLogV2 = new DaemonSessionEventLogV2(publisher, sessionStore);
47749
+ const publisher = new DaemonSessionEventPublisher();
47750
+ const eventLogV2 = new DaemonSessionEventLogV2(publisher);
47853
47751
  const activeTurns = new DaemonTurnRegistry(operations);
47854
47752
  const recordSessionEvent = (sessionId, event) => {
47855
47753
  publisher.publish(sessionId, activeTurns.recordEvent(event));
@@ -47895,7 +47793,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
47895
47793
  options2.signal
47896
47794
  );
47897
47795
  return cwd === options2.cwd && additionalDirectories.length === options2.additionalDirectories.length && additionalDirectories.every(
47898
- (directory, index2) => directory === options2.additionalDirectories[index2]
47796
+ (directory, index) => directory === options2.additionalDirectories[index]
47899
47797
  );
47900
47798
  });
47901
47799
  }
@@ -48366,12 +48264,12 @@ var RuntimeSupervisor = class {
48366
48264
  }
48367
48265
  };
48368
48266
  function pairingIdentifier(arguments_) {
48369
- const indexes = arguments_.flatMap((argument, index3) => argument === "--pairing" ? [index3] : []);
48267
+ const indexes = arguments_.flatMap((argument, index2) => argument === "--pairing" ? [index2] : []);
48370
48268
  if (indexes.length !== 1) {
48371
48269
  return null;
48372
48270
  }
48373
- const index2 = indexes[0];
48374
- return index2 === void 0 ? null : arguments_[index2 + 1] ?? null;
48271
+ const index = indexes[0];
48272
+ return index === void 0 ? null : arguments_[index + 1] ?? null;
48375
48273
  }
48376
48274
  async function waitForReady(active, signal) {
48377
48275
  if (active.status === "online") {
@@ -48666,9 +48564,9 @@ function formatPairTable(pairs) {
48666
48564
  const headers = ["connection_id", "app_id", "runtime_id", "workspace", "status"];
48667
48565
  const rows = pairs.map((pair) => [pair.connectionId, pair.appId, pair.runtimeId, pair.workspace, pair.status]);
48668
48566
  const widths = headers.map(
48669
- (header, index2) => Math.max(header.length, ...rows.map((row) => row[index2]?.length ?? 0))
48567
+ (header, index) => Math.max(header.length, ...rows.map((row) => row[index]?.length ?? 0))
48670
48568
  );
48671
- const line = (row) => `| ${row.map((value, index2) => value.padEnd(widths[index2] ?? value.length)).join(" | ")} |`;
48569
+ const line = (row) => `| ${row.map((value, index) => value.padEnd(widths[index] ?? value.length)).join(" | ")} |`;
48672
48570
  const divider = `|-${widths.map((width) => "-".repeat(width)).join("-|-")}-|`;
48673
48571
  return `${line(headers)}
48674
48572
  ${divider}