@moxt-ai/mobius 0.0.154 → 0.0.156

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 (78) hide show
  1. package/dist/acp/agent-query-processes.d.ts +2 -1
  2. package/dist/acp/agent-query-processes.d.ts.map +1 -1
  3. package/dist/acp/agent-query-processes.js +7 -1
  4. package/dist/acp/agent-query-processes.js.map +1 -1
  5. package/dist/acp/agent-runtime-manager.d.ts +4 -2
  6. package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
  7. package/dist/acp/agent-runtime-manager.js +19 -0
  8. package/dist/acp/agent-runtime-manager.js.map +1 -1
  9. package/dist/acp/agent-session.d.ts +2 -1
  10. package/dist/acp/agent-session.d.ts.map +1 -1
  11. package/dist/acp/agent-session.js +16 -2
  12. package/dist/acp/agent-session.js.map +1 -1
  13. package/dist/acp/session-contracts.d.ts +9 -1
  14. package/dist/acp/session-contracts.d.ts.map +1 -1
  15. package/dist/acp/session-contracts.js +1 -0
  16. package/dist/acp/session-contracts.js.map +1 -1
  17. package/dist/acp/session-history.d.ts +3 -2
  18. package/dist/acp/session-history.d.ts.map +1 -1
  19. package/dist/acp/session-history.js +17 -1
  20. package/dist/acp/session-history.js.map +1 -1
  21. package/dist/acp/session-store.d.ts +7 -0
  22. package/dist/acp/session-store.d.ts.map +1 -1
  23. package/dist/acp/session-store.js +34 -3
  24. package/dist/acp/session-store.js.map +1 -1
  25. package/dist/cli.js +1050 -402
  26. package/dist/cli.js.map +4 -4
  27. package/dist/daemon-command-handler.d.ts +3 -1
  28. package/dist/daemon-command-handler.d.ts.map +1 -1
  29. package/dist/daemon-command-handler.js +9 -3
  30. package/dist/daemon-command-handler.js.map +1 -1
  31. package/dist/daemon-history-commands.d.ts +2 -1
  32. package/dist/daemon-history-commands.d.ts.map +1 -1
  33. package/dist/daemon-history-commands.js +64 -1
  34. package/dist/daemon-history-commands.js.map +1 -1
  35. package/dist/daemon-observers.d.ts +3 -2
  36. package/dist/daemon-observers.d.ts.map +1 -1
  37. package/dist/daemon-observers.js +7 -1
  38. package/dist/daemon-observers.js.map +1 -1
  39. package/dist/daemon-prompt-executor.d.ts +3 -1
  40. package/dist/daemon-prompt-executor.d.ts.map +1 -1
  41. package/dist/daemon-prompt-executor.js +9 -3
  42. package/dist/daemon-prompt-executor.js.map +1 -1
  43. package/dist/generated/acp-session-store-migrations.d.ts +3 -0
  44. package/dist/generated/acp-session-store-migrations.d.ts.map +1 -1
  45. package/dist/generated/acp-session-store-migrations.js +5 -1
  46. package/dist/generated/acp-session-store-migrations.js.map +1 -1
  47. package/dist/index.js +1033 -385
  48. package/dist/index.js.map +4 -4
  49. package/dist/relay-connection/run-relay-connection.d.ts +3 -1
  50. package/dist/relay-connection/run-relay-connection.d.ts.map +1 -1
  51. package/dist/relay-connection/run-relay-connection.js +4 -16
  52. package/dist/relay-connection/run-relay-connection.js.map +1 -1
  53. package/dist/relay-connection/session-event-publisher.d.ts +5 -9
  54. package/dist/relay-connection/session-event-publisher.d.ts.map +1 -1
  55. package/dist/relay-connection/session-event-publisher.js +34 -131
  56. package/dist/relay-connection/session-event-publisher.js.map +1 -1
  57. package/dist/run-daemon.d.ts.map +1 -1
  58. package/dist/run-daemon.js +5 -2
  59. package/dist/run-daemon.js.map +1 -1
  60. package/dist/runtime.js +1032 -384
  61. package/dist/runtime.js.map +4 -4
  62. package/dist/schema/acp-session-store/index.d.ts +1 -0
  63. package/dist/schema/acp-session-store/index.d.ts.map +1 -1
  64. package/dist/schema/acp-session-store/index.js +1 -0
  65. package/dist/schema/acp-session-store/index.js.map +1 -1
  66. package/dist/schema/acp-session-store/session-event-v2.d.ts +82 -0
  67. package/dist/schema/acp-session-store/session-event-v2.d.ts.map +1 -0
  68. package/dist/schema/acp-session-store/session-event-v2.js +11 -0
  69. package/dist/schema/acp-session-store/session-event-v2.js.map +1 -0
  70. package/dist/session-event-log-v2.d.ts +15 -0
  71. package/dist/session-event-log-v2.d.ts.map +1 -0
  72. package/dist/session-event-log-v2.js +238 -0
  73. package/dist/session-event-log-v2.js.map +1 -0
  74. package/package.json +1 -1
  75. package/dist/relay-connection/session-event-queue.d.ts +0 -14
  76. package/dist/relay-connection/session-event-queue.d.ts.map +0 -1
  77. package/dist/relay-connection/session-event-queue.js +0 -75
  78. package/dist/relay-connection/session-event-queue.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, index) => {
2343
+ this.registeredArguments.forEach((declaredArg, index2) => {
2344
2344
  let value = declaredArg.defaultValue;
2345
2345
  if (declaredArg.variadic) {
2346
- if (index < this.args.length) {
2347
- value = this.args.slice(index);
2346
+ if (index2 < this.args.length) {
2347
+ value = this.args.slice(index2);
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 (index < this.args.length) {
2357
- value = this.args[index];
2356
+ } else if (index2 < this.args.length) {
2357
+ value = this.args[index2];
2358
2358
  if (declaredArg.parseArg) {
2359
2359
  value = myParseArg(declaredArg, value, declaredArg.defaultValue);
2360
2360
  }
2361
2361
  }
2362
- processedArgs[index] = value;
2362
+ processedArgs[index2] = 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 index = arg.indexOf("=");
2657
- const option = this._findOption(arg.slice(0, index));
2656
+ const index2 = arg.indexOf("=");
2657
+ const option = this._findOption(arg.slice(0, index2));
2658
2658
  if (option && (option.required || option.optional)) {
2659
- this.emit(`option:${option.name()}`, arg.slice(index + 1));
2659
+ this.emit(`option:${option.name()}`, arg.slice(index2 + 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.154",
3384
+ version: "0.0.156",
3385
3385
  description: "Mobius CLI for pairing and running local AI agent services.",
3386
3386
  type: "module",
3387
3387
  bin: {
@@ -8316,11 +8316,11 @@ var $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
8316
8316
  return payload;
8317
8317
  };
8318
8318
  });
8319
- function handleArrayResult(result, final, index) {
8319
+ function handleArrayResult(result, final, index2) {
8320
8320
  if (result.issues.length) {
8321
- final.issues.push(...prefixIssues(index, result.issues));
8321
+ final.issues.push(...prefixIssues(index2, result.issues));
8322
8322
  }
8323
- final.value[index] = result.value;
8323
+ final.value[index2] = result.value;
8324
8324
  }
8325
8325
  var $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
8326
8326
  $ZodType.init(inst, def);
@@ -8931,14 +8931,14 @@ function mergeValues(a, b) {
8931
8931
  return { valid: false, mergeErrorPath: [] };
8932
8932
  }
8933
8933
  const newArray = [];
8934
- for (let index = 0; index < a.length; index++) {
8935
- const itemA = a[index];
8936
- const itemB = b[index];
8934
+ for (let index2 = 0; index2 < a.length; index2++) {
8935
+ const itemA = a[index2];
8936
+ const itemB = b[index2];
8937
8937
  const sharedValue = mergeValues(itemA, itemB);
8938
8938
  if (!sharedValue.valid) {
8939
8939
  return {
8940
8940
  valid: false,
8941
- mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
8941
+ mergeErrorPath: [index2, ...sharedValue.mergeErrorPath]
8942
8942
  };
8943
8943
  }
8944
8944
  newArray.push(sharedValue.data);
@@ -9089,11 +9089,11 @@ function getTupleOptStart(items, key) {
9089
9089
  }
9090
9090
  return 0;
9091
9091
  }
9092
- function handleTupleResult(result, final, index) {
9092
+ function handleTupleResult(result, final, index2) {
9093
9093
  if (result.issues.length) {
9094
- final.issues.push(...prefixIssues(index, result.issues));
9094
+ final.issues.push(...prefixIssues(index2, result.issues));
9095
9095
  }
9096
- final.value[index] = result.value;
9096
+ final.value[index2] = result.value;
9097
9097
  }
9098
9098
  function handleTupleResults(itemResults, final, items, input2, optoutStart) {
9099
9099
  for (let i = 0; i < items.length; i++) {
@@ -23774,7 +23774,7 @@ function detectVersion(schema, defaultTarget) {
23774
23774
  return defaultTarget ?? "draft-2020-12";
23775
23775
  }
23776
23776
  function applyMinItems(items, minItems) {
23777
- return items.map((item, index) => index < minItems ? item : item.optional());
23777
+ return items.map((item, index2) => index2 < minItems ? item : item.optional());
23778
23778
  }
23779
23779
  function decodeJSONPointerSegment(segment) {
23780
23780
  return segment.replace(/~1/g, "/").replace(/~0/g, "~");
@@ -27822,9 +27822,9 @@ function comparePrerelease(left, right) {
27822
27822
  if (left.length === 0 || right.length === 0) {
27823
27823
  return left.length === right.length ? 0 : left.length === 0 ? 1 : -1;
27824
27824
  }
27825
- for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
27826
- const leftPart = left[index];
27827
- const rightPart = right[index];
27825
+ for (let index2 = 0; index2 < Math.max(left.length, right.length); index2 += 1) {
27826
+ const leftPart = left[index2];
27827
+ const rightPart = right[index2];
27828
27828
  if (leftPart === void 0 || rightPart === void 0) {
27829
27829
  return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
27830
27830
  }
@@ -27849,8 +27849,8 @@ function compareAgentVersions(left, right) {
27849
27849
  if (parsedLeft === null || parsedRight === null) {
27850
27850
  return null;
27851
27851
  }
27852
- for (let index = 0; index < Math.max(parsedLeft.core.length, parsedRight.core.length); index += 1) {
27853
- const difference = (parsedLeft.core[index] ?? 0) - (parsedRight.core[index] ?? 0);
27852
+ for (let index2 = 0; index2 < Math.max(parsedLeft.core.length, parsedRight.core.length); index2 += 1) {
27853
+ const difference = (parsedLeft.core[index2] ?? 0) - (parsedRight.core[index2] ?? 0);
27854
27854
  if (difference !== 0) {
27855
27855
  return Math.sign(difference);
27856
27856
  }
@@ -28597,12 +28597,12 @@ var DEFAULT_AGENT_EXECUTION_CONFIGURATION = Object.freeze({
28597
28597
  });
28598
28598
  var sessionConfigurationSelectionsSchema = external_exports.array(sessionConfigurationSelectionSchema).max(100).superRefine((selections, context) => {
28599
28599
  const identifiers = /* @__PURE__ */ new Set();
28600
- for (const [index, selection] of selections.entries()) {
28600
+ for (const [index2, selection] of selections.entries()) {
28601
28601
  if (identifiers.has(selection.configId)) {
28602
28602
  context.addIssue({
28603
28603
  code: "custom",
28604
28604
  message: "Session configuration identifiers must be unique",
28605
- path: [index, "configId"]
28605
+ path: [index2, "configId"]
28606
28606
  });
28607
28607
  }
28608
28608
  identifiers.add(selection.configId);
@@ -29338,16 +29338,8 @@ function decodeSessionQueuedEvent(encoded) {
29338
29338
  function decodeRuntimeLivenessReadyEvent(encoded) {
29339
29339
  const value = parseJson2(encoded);
29340
29340
  assertKind(value, RUNTIME_LIVENESS_READY_KIND);
29341
- if (value["sessionEventDelivery"] === void 0) {
29342
- assertExactKeys(value, ["kind"]);
29343
- return { kind: RUNTIME_LIVENESS_READY_KIND };
29344
- }
29345
- assertExactKeys(value, ["kind", "sessionEventDelivery"]);
29346
- const sessionEventDelivery = readString2(value, "sessionEventDelivery", 32);
29347
- if (sessionEventDelivery !== "reliable-v1") {
29348
- throw new ProtocolMessageError("Unsupported Session event delivery mode");
29349
- }
29350
- return { kind: RUNTIME_LIVENESS_READY_KIND, sessionEventDelivery };
29341
+ assertExactKeys(value, ["kind"]);
29342
+ return { kind: RUNTIME_LIVENESS_READY_KIND };
29351
29343
  }
29352
29344
  function decodeRuntimeHeartbeatEvent(encoded) {
29353
29345
  const value = parseJson2(encoded);
@@ -29812,60 +29804,390 @@ var encodeNativeSessionResult = (value) => JSON.stringify(nativeSessionResultSch
29812
29804
  var decodeNativeSessionCancel = (encoded) => decode4(nativeSessionCancelSchema, encoded);
29813
29805
  var encodeNativeSessionCancel = (value) => JSON.stringify(nativeSessionCancelSchema.parse(value));
29814
29806
 
29815
- // ../protocol/src/session-events.ts
29816
- var SESSION_EVENT_KIND = "session.event";
29817
- var SESSION_EVENT_ACK_KIND = "session.event.ack";
29818
- var SESSION_EVENT_DEFERRED_KIND = "session.event.deferred";
29819
- var SESSION_EVENT_REJECTED_KIND = "session.event.rejected";
29820
- var SESSION_FORKED_KIND = "session.forked";
29821
- var SessionEventRejectionCode = {
29822
- IdempotencyConflict: "idempotency_conflict",
29823
- InvalidEvent: "invalid_event",
29824
- RecordingRejected: "recording_rejected"
29825
- };
29826
- var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
29827
- var ephemeralEventEnvelopeSchema = external_exports.strictObject({
29828
- kind: external_exports.literal(SESSION_EVENT_KIND),
29829
- payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
29830
- sessionId: identifierStringSchema
29807
+ // ../protocol/src/session-event-log-v2.ts
29808
+ var MAX_EVENT_COUNT = 1e4;
29809
+ var MAX_COLLECTION_SIZE = 1e3;
29810
+ var MAX_CONTENT_LENGTH = 1e6;
29811
+ var MAX_JSON_DEPTH = 16;
29812
+ var MAX_JSON_KEYS = 1e3;
29813
+ var SESSION_EVENT_V2_KIND = "session.event.v2";
29814
+ var boundedString = external_exports.string().max(MAX_CONTENT_LENGTH);
29815
+ var shortString = external_exports.string().max(2048);
29816
+ function boundedJsonIssue(value, depth = 0) {
29817
+ if (depth > MAX_JSON_DEPTH) {
29818
+ return "JSON nesting exceeds the maximum depth";
29819
+ }
29820
+ if (typeof value === "string") {
29821
+ return value.length <= MAX_CONTENT_LENGTH ? null : "JSON string exceeds the maximum length";
29822
+ }
29823
+ if (typeof value === "number") {
29824
+ return Number.isFinite(value) ? null : "JSON number must be finite";
29825
+ }
29826
+ if (typeof value === "boolean" || value === null) {
29827
+ return null;
29828
+ }
29829
+ if (Array.isArray(value)) {
29830
+ if (value.length > MAX_COLLECTION_SIZE) {
29831
+ return "JSON array exceeds the maximum length";
29832
+ }
29833
+ for (const item of value) {
29834
+ const issue2 = boundedJsonIssue(item, depth + 1);
29835
+ if (issue2 !== null) {
29836
+ return issue2;
29837
+ }
29838
+ }
29839
+ return null;
29840
+ }
29841
+ if (typeof value === "object" && value !== void 0) {
29842
+ const entries = Object.entries(value);
29843
+ if (entries.length > MAX_JSON_KEYS) {
29844
+ return "JSON object exceeds the maximum key count";
29845
+ }
29846
+ for (const [key, item] of entries) {
29847
+ if (key.length > 255) {
29848
+ return "JSON key exceeds the maximum length";
29849
+ }
29850
+ const issue2 = boundedJsonIssue(item, depth + 1);
29851
+ if (issue2 !== null) {
29852
+ return issue2;
29853
+ }
29854
+ }
29855
+ return null;
29856
+ }
29857
+ return "Value is not bounded JSON";
29858
+ }
29859
+ var boundedJsonSchema = external_exports.unknown().superRefine((value, context) => {
29860
+ const issue2 = boundedJsonIssue(value);
29861
+ if (issue2 !== null) {
29862
+ context.addIssue({ code: "custom", message: issue2 });
29863
+ }
29864
+ });
29865
+ var metadataSchema = external_exports.record(external_exports.string().max(255), boundedJsonSchema).readonly();
29866
+ var optionalMetadata = metadataSchema.nullable().optional();
29867
+ var annotationsSchema = external_exports.strictObject({
29868
+ _meta: optionalMetadata,
29869
+ audience: external_exports.array(external_exports.enum(["assistant", "user"])).max(2).readonly().nullable().optional(),
29870
+ lastModified: shortString.nullable().optional(),
29871
+ priority: external_exports.number().finite().nullable().optional()
29831
29872
  }).readonly();
29832
- var reliableDeliverySchema = external_exports.strictObject({
29833
- eventId: identifierStringSchema,
29834
- kind: external_exports.literal("reliable"),
29835
- sourceSeq: external_exports.string().regex(/^(?:0|[1-9][0-9]*)$/u).max(40),
29836
- streamId: identifierStringSchema
29873
+ var contentFields = { _meta: optionalMetadata, annotations: annotationsSchema.nullable().optional() };
29874
+ var textContentSchema = external_exports.strictObject({ ...contentFields, text: boundedString, type: external_exports.literal("text") }).readonly();
29875
+ var imageContentSchema = external_exports.strictObject({
29876
+ ...contentFields,
29877
+ data: boundedString,
29878
+ mimeType: shortString,
29879
+ type: external_exports.literal("image"),
29880
+ uri: boundedString.nullable().optional()
29837
29881
  }).readonly();
29838
- var reliableSessionEventEnvelopeSchema = external_exports.strictObject({
29839
- delivery: reliableDeliverySchema,
29840
- kind: external_exports.literal(SESSION_EVENT_KIND),
29841
- payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
29842
- sessionId: identifierStringSchema
29882
+ var audioContentSchema = external_exports.strictObject({ ...contentFields, data: boundedString, mimeType: shortString, type: external_exports.literal("audio") }).readonly();
29883
+ var resourceLinkSchema = external_exports.strictObject({
29884
+ ...contentFields,
29885
+ description: boundedString.nullable().optional(),
29886
+ mimeType: shortString.nullable().optional(),
29887
+ name: shortString,
29888
+ size: external_exports.number().int().nonnegative().safe().nullable().optional(),
29889
+ title: shortString.nullable().optional(),
29890
+ type: external_exports.literal("resource_link"),
29891
+ uri: boundedString
29892
+ }).readonly();
29893
+ var textResourceSchema = external_exports.strictObject({
29894
+ _meta: optionalMetadata,
29895
+ mimeType: shortString.nullable().optional(),
29896
+ text: boundedString,
29897
+ uri: boundedString
29898
+ }).readonly();
29899
+ var blobResourceSchema = external_exports.strictObject({
29900
+ _meta: optionalMetadata,
29901
+ blob: boundedString,
29902
+ mimeType: shortString.nullable().optional(),
29903
+ uri: boundedString
29904
+ }).readonly();
29905
+ var embeddedResourceSchema = external_exports.strictObject({
29906
+ ...contentFields,
29907
+ resource: external_exports.union([textResourceSchema, blobResourceSchema]),
29908
+ type: external_exports.literal("resource")
29909
+ }).readonly();
29910
+ var contentBlockV2Schema = external_exports.discriminatedUnion("type", [
29911
+ textContentSchema,
29912
+ imageContentSchema,
29913
+ audioContentSchema,
29914
+ resourceLinkSchema,
29915
+ embeddedResourceSchema
29916
+ ]);
29917
+ var toolCallContentSchema = external_exports.discriminatedUnion("type", [
29918
+ external_exports.strictObject({ _meta: optionalMetadata, content: contentBlockV2Schema, type: external_exports.literal("content") }).readonly(),
29919
+ external_exports.strictObject({
29920
+ _meta: optionalMetadata,
29921
+ newText: boundedString,
29922
+ oldText: boundedString.nullable().optional(),
29923
+ path: boundedString,
29924
+ type: external_exports.literal("diff")
29925
+ }).readonly(),
29926
+ external_exports.strictObject({ _meta: optionalMetadata, terminalId: shortString, type: external_exports.literal("terminal") }).readonly()
29927
+ ]);
29928
+ var toolCallLocationSchema = external_exports.strictObject({
29929
+ _meta: optionalMetadata,
29930
+ line: external_exports.number().int().nonnegative().safe().nullable().optional(),
29931
+ path: boundedString
29932
+ }).readonly();
29933
+ var toolKindSchema = external_exports.enum([
29934
+ "read",
29935
+ "edit",
29936
+ "delete",
29937
+ "move",
29938
+ "search",
29939
+ "execute",
29940
+ "think",
29941
+ "fetch",
29942
+ "switch_mode",
29943
+ "other"
29944
+ ]);
29945
+ var toolStatusSchema = external_exports.enum(["pending", "in_progress", "completed", "failed"]);
29946
+ var toolPatchFields = {
29947
+ _meta: optionalMetadata,
29948
+ content: external_exports.array(toolCallContentSchema).max(MAX_COLLECTION_SIZE).readonly().nullable().optional(),
29949
+ kind: toolKindSchema.nullable().optional(),
29950
+ locations: external_exports.array(toolCallLocationSchema).max(MAX_COLLECTION_SIZE).readonly().nullable().optional(),
29951
+ name: shortString.nullable().optional(),
29952
+ rawInput: boundedJsonSchema.optional(),
29953
+ rawOutput: boundedJsonSchema.optional(),
29954
+ status: toolStatusSchema.nullable().optional(),
29955
+ title: boundedString.nullable().optional()
29956
+ };
29957
+ var planEntrySchema = external_exports.strictObject({
29958
+ _meta: optionalMetadata,
29959
+ content: boundedString,
29960
+ priority: external_exports.enum(["high", "medium", "low"]),
29961
+ status: external_exports.enum(["pending", "in_progress", "completed"])
29962
+ }).readonly();
29963
+ var planContentSchema = external_exports.discriminatedUnion("type", [
29964
+ external_exports.strictObject({
29965
+ _meta: optionalMetadata,
29966
+ entries: external_exports.array(planEntrySchema).max(MAX_COLLECTION_SIZE).readonly(),
29967
+ planId: shortString,
29968
+ type: external_exports.literal("items")
29969
+ }).readonly(),
29970
+ external_exports.strictObject({ _meta: optionalMetadata, planId: shortString, type: external_exports.literal("file"), uri: boundedString }).readonly(),
29971
+ external_exports.strictObject({
29972
+ _meta: optionalMetadata,
29973
+ content: boundedString,
29974
+ planId: shortString,
29975
+ type: external_exports.literal("markdown")
29976
+ }).readonly()
29977
+ ]);
29978
+ var commandSchema = external_exports.strictObject({
29979
+ _meta: optionalMetadata,
29980
+ description: boundedString,
29981
+ input: external_exports.strictObject({ _meta: optionalMetadata, hint: boundedString }).readonly().nullable().optional(),
29982
+ name: shortString
29983
+ }).readonly();
29984
+ var configSelectOptionSchema = external_exports.strictObject({
29985
+ _meta: optionalMetadata,
29986
+ description: boundedString.nullable().optional(),
29987
+ name: shortString,
29988
+ value: shortString
29989
+ }).readonly();
29990
+ var configSelectGroupSchema = external_exports.strictObject({
29991
+ _meta: optionalMetadata,
29992
+ group: shortString,
29993
+ name: shortString,
29994
+ options: external_exports.array(configSelectOptionSchema).max(MAX_COLLECTION_SIZE).readonly()
29843
29995
  }).readonly();
29844
- var eventEnvelopeSchema = external_exports.union([ephemeralEventEnvelopeSchema, reliableSessionEventEnvelopeSchema]).readonly();
29845
- var acknowledgementOutcomeSchema = external_exports.discriminatedUnion("kind", [
29846
- external_exports.strictObject({ kind: external_exports.literal("relayed") }).readonly(),
29996
+ var configBaseFields = {
29997
+ _meta: optionalMetadata,
29998
+ category: shortString.nullable().optional(),
29999
+ description: boundedString.nullable().optional(),
30000
+ id: shortString,
30001
+ name: shortString
30002
+ };
30003
+ var sessionConfigOptionSchema2 = external_exports.discriminatedUnion("type", [
30004
+ external_exports.strictObject({
30005
+ ...configBaseFields,
30006
+ currentValue: shortString,
30007
+ options: external_exports.union([
30008
+ external_exports.array(configSelectOptionSchema).max(MAX_COLLECTION_SIZE).readonly(),
30009
+ external_exports.array(configSelectGroupSchema).max(MAX_COLLECTION_SIZE).readonly()
30010
+ ]),
30011
+ type: external_exports.literal("select")
30012
+ }).readonly(),
30013
+ external_exports.strictObject({ ...configBaseFields, currentValue: external_exports.boolean(), type: external_exports.literal("boolean") }).readonly()
30014
+ ]);
30015
+ var contentChunkFields = {
30016
+ _meta: optionalMetadata,
30017
+ content: contentBlockV2Schema,
30018
+ messageId: shortString.nullable().optional()
30019
+ };
30020
+ var acpSessionUpdateV2Schema = external_exports.discriminatedUnion("sessionUpdate", [
30021
+ external_exports.strictObject({ ...contentChunkFields, sessionUpdate: external_exports.literal("user_message_chunk") }).readonly(),
30022
+ external_exports.strictObject({ ...contentChunkFields, sessionUpdate: external_exports.literal("agent_message_chunk") }).readonly(),
30023
+ external_exports.strictObject({ ...contentChunkFields, sessionUpdate: external_exports.literal("agent_thought_chunk") }).readonly(),
30024
+ external_exports.strictObject({
30025
+ _meta: optionalMetadata,
30026
+ content: external_exports.array(toolCallContentSchema).max(MAX_COLLECTION_SIZE).readonly().optional(),
30027
+ kind: toolKindSchema.optional(),
30028
+ locations: external_exports.array(toolCallLocationSchema).max(MAX_COLLECTION_SIZE).readonly().optional(),
30029
+ name: shortString.nullable().optional(),
30030
+ rawInput: boundedJsonSchema.optional(),
30031
+ rawOutput: boundedJsonSchema.optional(),
30032
+ sessionUpdate: external_exports.literal("tool_call"),
30033
+ status: toolStatusSchema.optional(),
30034
+ title: boundedString,
30035
+ toolCallId: shortString
30036
+ }).readonly(),
30037
+ external_exports.strictObject({ ...toolPatchFields, sessionUpdate: external_exports.literal("tool_call_update"), toolCallId: shortString }).readonly(),
30038
+ external_exports.strictObject({
30039
+ _meta: optionalMetadata,
30040
+ entries: external_exports.array(planEntrySchema).max(MAX_COLLECTION_SIZE).readonly(),
30041
+ sessionUpdate: external_exports.literal("plan")
30042
+ }).readonly(),
30043
+ external_exports.strictObject({ _meta: optionalMetadata, plan: planContentSchema, sessionUpdate: external_exports.literal("plan_update") }).readonly(),
30044
+ external_exports.strictObject({ _meta: optionalMetadata, planId: shortString, sessionUpdate: external_exports.literal("plan_removed") }).readonly(),
30045
+ external_exports.strictObject({
30046
+ _meta: optionalMetadata,
30047
+ availableCommands: external_exports.array(commandSchema).max(MAX_COLLECTION_SIZE).readonly(),
30048
+ sessionUpdate: external_exports.literal("available_commands_update")
30049
+ }).readonly(),
30050
+ external_exports.strictObject({
30051
+ _meta: optionalMetadata,
30052
+ currentModeId: shortString,
30053
+ sessionUpdate: external_exports.literal("current_mode_update")
30054
+ }).readonly(),
30055
+ external_exports.strictObject({
30056
+ _meta: optionalMetadata,
30057
+ configOptions: external_exports.array(sessionConfigOptionSchema2).max(MAX_COLLECTION_SIZE).readonly(),
30058
+ sessionUpdate: external_exports.literal("config_option_update")
30059
+ }).readonly(),
29847
30060
  external_exports.strictObject({
29848
- kind: external_exports.literal("recorded"),
29849
- providerId: identifierStringSchema,
29850
- recordingEpoch: identifierStringSchema
30061
+ _meta: optionalMetadata,
30062
+ sessionUpdate: external_exports.literal("session_info_update"),
30063
+ title: boundedString.nullable().optional(),
30064
+ updatedAt: shortString.nullable().optional()
30065
+ }).readonly(),
30066
+ external_exports.strictObject({
30067
+ _meta: optionalMetadata,
30068
+ cost: external_exports.strictObject({ _meta: optionalMetadata, amount: external_exports.number().finite(), currency: external_exports.string().max(16) }).readonly().nullable().optional(),
30069
+ sessionUpdate: external_exports.literal("usage_update"),
30070
+ size: external_exports.number().int().nonnegative().safe(),
30071
+ used: external_exports.number().int().nonnegative().safe()
30072
+ }).readonly(),
30073
+ external_exports.strictObject({
30074
+ _meta: optionalMetadata,
30075
+ compactionId: shortString,
30076
+ error: boundedString.nullable().optional(),
30077
+ sessionUpdate: external_exports.literal("compaction_update"),
30078
+ status: shortString,
30079
+ summary: external_exports.array(contentBlockV2Schema).max(MAX_COLLECTION_SIZE).readonly().nullable().optional()
30080
+ }).readonly(),
30081
+ external_exports.strictObject({
30082
+ _meta: optionalMetadata,
30083
+ compactionId: shortString,
30084
+ content: contentBlockV2Schema,
30085
+ sessionUpdate: external_exports.literal("compaction_summary_chunk")
29851
30086
  }).readonly()
29852
30087
  ]);
29853
- var eventAcknowledgementSchema = external_exports.strictObject({
30088
+ var lifecycleBase = { commandId: identifierStringSchema };
30089
+ var sessionEventPayloadV2Schema = external_exports.discriminatedUnion("kind", [
30090
+ external_exports.strictObject({ kind: external_exports.literal("acp.session.update"), update: acpSessionUpdateV2Schema }).readonly(),
30091
+ external_exports.strictObject({
30092
+ ...lifecycleBase,
30093
+ content: external_exports.array(contentBlockV2Schema).min(1).max(100).readonly(),
30094
+ kind: external_exports.literal("prompt.requested")
30095
+ }).readonly(),
30096
+ external_exports.strictObject({ ...lifecycleBase, attemptId: identifierStringSchema, epoch: identifierStringSchema, kind: external_exports.literal("prompt.started") }).readonly(),
30097
+ external_exports.strictObject({ ...lifecycleBase, kind: external_exports.literal("prompt.completed"), stopReason: shortString }).readonly(),
30098
+ external_exports.strictObject({
30099
+ ...lifecycleBase,
30100
+ code: identifierStringSchema,
30101
+ kind: external_exports.literal("prompt.failed-before-start"),
30102
+ message: external_exports.string().min(1).max(500)
30103
+ }).readonly(),
30104
+ external_exports.strictObject({
30105
+ ...lifecycleBase,
30106
+ attemptId: identifierStringSchema,
30107
+ code: identifierStringSchema,
30108
+ kind: external_exports.literal("prompt.failed"),
30109
+ message: external_exports.string().min(1).max(500)
30110
+ }).readonly()
30111
+ ]);
30112
+ var positionSchema = external_exports.string().regex(/^(0|[1-9][0-9]*)$/);
30113
+ var provenanceSchema = external_exports.discriminatedUnion("kind", [
30114
+ external_exports.strictObject({ kind: external_exports.literal("original") }).readonly(),
30115
+ external_exports.strictObject({
30116
+ kind: external_exports.literal("imported"),
30117
+ sourceEventId: identifierStringSchema,
30118
+ sourcePosition: positionSchema,
30119
+ sourceSessionId: identifierStringSchema
30120
+ }).readonly(),
30121
+ external_exports.strictObject({
30122
+ kind: external_exports.literal("forked"),
30123
+ sourceEventId: identifierStringSchema,
30124
+ sourcePosition: positionSchema,
30125
+ sourceSessionId: identifierStringSchema
30126
+ }).readonly()
30127
+ ]);
30128
+ var sessionEventV2Schema = external_exports.strictObject({
29854
30129
  eventId: identifierStringSchema,
29855
- kind: external_exports.literal(SESSION_EVENT_ACK_KIND),
29856
- outcome: acknowledgementOutcomeSchema,
30130
+ payload: sessionEventPayloadV2Schema,
30131
+ position: positionSchema,
30132
+ provenance: provenanceSchema,
30133
+ recordedAt: external_exports.iso.datetime({ offset: true }),
29857
30134
  sessionId: identifierStringSchema
29858
30135
  }).readonly();
29859
- var eventDeferredSchema = external_exports.strictObject({
29860
- eventId: identifierStringSchema,
29861
- kind: external_exports.literal(SESSION_EVENT_DEFERRED_KIND),
29862
- retryAfterMilliseconds: external_exports.number().int().min(100).max(6e4),
29863
- sessionId: identifierStringSchema
30136
+ var sessionEventEnvelopeV2Schema = external_exports.strictObject({ event: sessionEventV2Schema, kind: external_exports.literal(SESSION_EVENT_V2_KIND) }).readonly();
30137
+ var sessionEventLogPageV2Schema = external_exports.strictObject({
30138
+ events: external_exports.array(sessionEventV2Schema).max(MAX_EVENT_COUNT).readonly(),
30139
+ nextCursor: external_exports.string().min(1).max(512).nullable(),
30140
+ tailCursor: external_exports.string().max(512),
30141
+ truncated: external_exports.boolean(),
30142
+ version: external_exports.literal(2)
29864
30143
  }).readonly();
29865
- var eventRejectedSchema = external_exports.strictObject({
29866
- code: external_exports.enum(SessionEventRejectionCode),
29867
- eventId: identifierStringSchema,
29868
- kind: external_exports.literal(SESSION_EVENT_REJECTED_KIND),
30144
+ var nativeEventPageRequestV2Schema = external_exports.strictObject({ cursor: external_exports.string().min(1).max(512).nullable(), eventLimit: external_exports.number().int().min(1).max(1e4) }).readonly();
30145
+ var executingPromptRequestEventLogV2Schema = external_exports.strictObject({
30146
+ attemptId: identifierStringSchema,
30147
+ commandId: identifierStringSchema,
30148
+ epoch: identifierStringSchema,
30149
+ events: external_exports.array(sessionEventV2Schema).max(MAX_EVENT_COUNT).readonly(),
30150
+ tailCursor: external_exports.string().max(512),
30151
+ truncated: external_exports.boolean()
30152
+ }).readonly();
30153
+ var nativeSessionEventsV2Schema = external_exports.strictObject({
30154
+ executingPromptRequest: executingPromptRequestEventLogV2Schema.nullable(),
30155
+ history: sessionEventLogPageV2Schema
30156
+ }).readonly();
30157
+ function inputValue(value) {
30158
+ if (typeof value !== "string") {
30159
+ return value;
30160
+ }
30161
+ try {
30162
+ return JSON.parse(value);
30163
+ } catch (cause) {
30164
+ throw new ProtocolMessageError("Session Event Log V2 message is not valid JSON", { cause });
30165
+ }
30166
+ }
30167
+ function decode5(value, schema) {
30168
+ const result = schema.safeParse(inputValue(value));
30169
+ if (!result.success) {
30170
+ throw new ProtocolMessageError("Session Event Log V2 message does not match its schema", {
30171
+ cause: result.error
30172
+ });
30173
+ }
30174
+ return result.data;
30175
+ }
30176
+ function encode4(value, schema) {
30177
+ return JSON.stringify(decode5(value, schema));
30178
+ }
30179
+ var decodeSessionEventV2 = (value) => decode5(value, sessionEventV2Schema);
30180
+ var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelopeV2Schema);
30181
+ var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
30182
+ var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
30183
+
30184
+ // ../protocol/src/session-events.ts
30185
+ var SESSION_EVENT_KIND = "session.event";
30186
+ var SESSION_FORKED_KIND = "session.forked";
30187
+ var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
30188
+ var sessionEventEnvelopeSchema = external_exports.strictObject({
30189
+ kind: external_exports.literal(SESSION_EVENT_KIND),
30190
+ payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
29869
30191
  sessionId: identifierStringSchema
29870
30192
  }).readonly();
29871
30193
  var SESSION_QUEUE_CHANGED_KIND = "session.queue.changed";
@@ -29876,7 +30198,7 @@ var sessionForkedSchema = external_exports.strictObject({
29876
30198
  sourceSessionId: identifierStringSchema,
29877
30199
  throughCommandId: identifierStringSchema
29878
30200
  }).readonly();
29879
- function decode5(encoded, schema) {
30201
+ function decode6(encoded, schema) {
29880
30202
  let value;
29881
30203
  try {
29882
30204
  value = JSON.parse(encoded);
@@ -29891,7 +30213,7 @@ function decode5(encoded, schema) {
29891
30213
  }
29892
30214
  return decoded.data;
29893
30215
  }
29894
- var encode4 = (message, schema) => {
30216
+ var encode5 = (message, schema) => {
29895
30217
  const decoded = schema.safeParse(message);
29896
30218
  if (!decoded.success) {
29897
30219
  throw new ProtocolMessageError("Message does not match its schema", {
@@ -29900,21 +30222,15 @@ var encode4 = (message, schema) => {
29900
30222
  }
29901
30223
  return JSON.stringify(decoded.data);
29902
30224
  };
29903
- var decodeSessionEventEnvelope = (encoded) => decode5(encoded, eventEnvelopeSchema);
29904
- var encodeSessionEventEnvelope = (message) => encode4(message, eventEnvelopeSchema);
29905
- var decodeSessionEventAcknowledgement = (encoded) => decode5(encoded, eventAcknowledgementSchema);
29906
- var encodeSessionEventAcknowledgement = (message) => encode4(message, eventAcknowledgementSchema);
29907
- var decodeSessionEventDeferred = (encoded) => decode5(encoded, eventDeferredSchema);
29908
- var encodeSessionEventDeferred = (message) => encode4(message, eventDeferredSchema);
29909
- var decodeSessionEventRejected = (encoded) => decode5(encoded, eventRejectedSchema);
29910
- var encodeSessionEventRejected = (message) => encode4(message, eventRejectedSchema);
30225
+ var decodeSessionEventEnvelope = (encoded) => decode6(encoded, sessionEventEnvelopeSchema);
30226
+ var encodeSessionEventEnvelope = (message) => encode5(message, sessionEventEnvelopeSchema);
29911
30227
  function decodeRecordedSessionEvent(encoded) {
29912
30228
  const kind = decodeMessageKind(encoded);
29913
30229
  switch (kind) {
29914
30230
  case SESSION_QUEUE_CHANGED_KIND:
29915
- return decode5(encoded, sessionQueueChangedSchema);
30231
+ return decode6(encoded, sessionQueueChangedSchema);
29916
30232
  case SESSION_FORKED_KIND:
29917
- return decode5(encoded, sessionForkedSchema);
30233
+ return decode6(encoded, sessionForkedSchema);
29918
30234
  case AGENT_ACTIVITY_KIND:
29919
30235
  return decodeAgentActivityEvent(encoded);
29920
30236
  case AGENT_ACTIVITY_NARRATION_KIND:
@@ -29958,6 +30274,8 @@ var SESSION_LIVE_HISTORY_LOAD_KIND = "session.live-history.load";
29958
30274
  var SESSION_LIVE_HISTORY_LOADED_KIND = "session.live-history.loaded";
29959
30275
  var SESSION_LIVE_HISTORY_PAGE_LOAD_KIND = "session.live-history.page.load";
29960
30276
  var SESSION_LIVE_HISTORY_PAGE_LOADED_KIND = "session.live-history.page.loaded";
30277
+ var SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
30278
+ var SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
29961
30279
  var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
29962
30280
  var sessionLiveHistoryLoadSchema = external_exports.strictObject({
29963
30281
  additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
@@ -29991,7 +30309,24 @@ var sessionLiveHistoryPageLoadedSchema = external_exports.strictObject({
29991
30309
  requestId: identifierStringSchema,
29992
30310
  sessionId: identifierStringSchema
29993
30311
  }).readonly();
29994
- function decode6(schema, encoded) {
30312
+ var sessionLiveHistoryV2PageLoadSchema = external_exports.strictObject({
30313
+ additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
30314
+ agentId: identifierStringSchema,
30315
+ bindingId: identifierStringSchema,
30316
+ cursor: external_exports.string().min(1).max(512).nullable(),
30317
+ directoryId: directoryIdentifier,
30318
+ kind: external_exports.literal(SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND),
30319
+ eventLimit: external_exports.number().int().min(1).max(1e4),
30320
+ requestId: identifierStringSchema,
30321
+ sessionId: identifierStringSchema
30322
+ }).readonly();
30323
+ var sessionLiveHistoryV2PageLoadedSchema = external_exports.strictObject({
30324
+ events: nativeSessionEventsV2Schema,
30325
+ kind: external_exports.literal(SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND),
30326
+ requestId: identifierStringSchema,
30327
+ sessionId: identifierStringSchema
30328
+ }).readonly();
30329
+ function decode7(schema, encoded) {
29995
30330
  try {
29996
30331
  const value = JSON.parse(encoded);
29997
30332
  return schema.parse(value);
@@ -29999,14 +30334,18 @@ function decode6(schema, encoded) {
29999
30334
  throw new ProtocolMessageError("Invalid live Session history message", { cause });
30000
30335
  }
30001
30336
  }
30002
- var decodeSessionLiveHistoryLoad = (encoded) => decode6(sessionLiveHistoryLoadSchema, encoded);
30003
- var decodeSessionLiveHistoryLoaded = (encoded) => decode6(sessionLiveHistoryLoadedSchema, encoded);
30337
+ var decodeSessionLiveHistoryLoad = (encoded) => decode7(sessionLiveHistoryLoadSchema, encoded);
30338
+ var decodeSessionLiveHistoryLoaded = (encoded) => decode7(sessionLiveHistoryLoadedSchema, encoded);
30004
30339
  var encodeSessionLiveHistoryLoad = (value) => JSON.stringify(sessionLiveHistoryLoadSchema.parse(value));
30005
30340
  var encodeSessionLiveHistoryLoaded = (value) => JSON.stringify(sessionLiveHistoryLoadedSchema.parse(value));
30006
- var decodeSessionLiveHistoryPageLoad = (encoded) => decode6(sessionLiveHistoryPageLoadSchema, encoded);
30007
- var decodeSessionLiveHistoryPageLoaded = (encoded) => decode6(sessionLiveHistoryPageLoadedSchema, encoded);
30341
+ var decodeSessionLiveHistoryPageLoad = (encoded) => decode7(sessionLiveHistoryPageLoadSchema, encoded);
30342
+ var decodeSessionLiveHistoryPageLoaded = (encoded) => decode7(sessionLiveHistoryPageLoadedSchema, encoded);
30008
30343
  var encodeSessionLiveHistoryPageLoad = (value) => JSON.stringify(sessionLiveHistoryPageLoadSchema.parse(value));
30009
30344
  var encodeSessionLiveHistoryPageLoaded = (value) => JSON.stringify(sessionLiveHistoryPageLoadedSchema.parse(value));
30345
+ var decodeSessionLiveHistoryV2PageLoad = (encoded) => decode7(sessionLiveHistoryV2PageLoadSchema, encoded);
30346
+ var decodeSessionLiveHistoryV2PageLoaded = (encoded) => decode7(sessionLiveHistoryV2PageLoadedSchema, encoded);
30347
+ var encodeSessionLiveHistoryV2PageLoad = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadSchema.parse(value));
30348
+ var encodeSessionLiveHistoryV2PageLoaded = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadedSchema.parse(value));
30010
30349
 
30011
30350
  // ../protocol/src/daemon-transport.ts
30012
30351
  function defineMessageSignature(kind, encoder, decoder) {
@@ -30081,21 +30420,6 @@ var serviceToDaemonSignatures = {
30081
30420
  encodeSessionElicitationRespondCommand,
30082
30421
  decodeSessionElicitationRespondCommand
30083
30422
  ),
30084
- [SESSION_EVENT_ACK_KIND]: defineMessageSignature(
30085
- SESSION_EVENT_ACK_KIND,
30086
- encodeSessionEventAcknowledgement,
30087
- decodeSessionEventAcknowledgement
30088
- ),
30089
- [SESSION_EVENT_DEFERRED_KIND]: defineMessageSignature(
30090
- SESSION_EVENT_DEFERRED_KIND,
30091
- encodeSessionEventDeferred,
30092
- decodeSessionEventDeferred
30093
- ),
30094
- [SESSION_EVENT_REJECTED_KIND]: defineMessageSignature(
30095
- SESSION_EVENT_REJECTED_KIND,
30096
- encodeSessionEventRejected,
30097
- decodeSessionEventRejected
30098
- ),
30099
30423
  [SESSION_LIVE_HISTORY_LOAD_KIND]: defineMessageSignature(
30100
30424
  SESSION_LIVE_HISTORY_LOAD_KIND,
30101
30425
  encodeSessionLiveHistoryLoad,
@@ -30106,6 +30430,11 @@ var serviceToDaemonSignatures = {
30106
30430
  encodeSessionLiveHistoryPageLoad,
30107
30431
  decodeSessionLiveHistoryPageLoad
30108
30432
  ),
30433
+ [SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND]: defineMessageSignature(
30434
+ SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND,
30435
+ encodeSessionLiveHistoryV2PageLoad,
30436
+ decodeSessionLiveHistoryV2PageLoad
30437
+ ),
30109
30438
  [SESSION_PERMISSION_RESPOND_KIND]: defineMessageSignature(
30110
30439
  SESSION_PERMISSION_RESPOND_KIND,
30111
30440
  encodeSessionPermissionRespondCommand,
@@ -30221,6 +30550,11 @@ var daemonToServiceSignatures = {
30221
30550
  encodeSessionEventEnvelope,
30222
30551
  decodeSessionEventEnvelope
30223
30552
  ),
30553
+ [SESSION_EVENT_V2_KIND]: defineMessageSignature(
30554
+ SESSION_EVENT_V2_KIND,
30555
+ encodeSessionEventEnvelopeV2,
30556
+ decodeSessionEventEnvelopeV2
30557
+ ),
30224
30558
  [SESSION_OPERATION_FAILED_KIND]: defineMessageSignature(
30225
30559
  SESSION_OPERATION_FAILED_KIND,
30226
30560
  encodeSessionOperationFailedEvent,
@@ -30236,6 +30570,11 @@ var daemonToServiceSignatures = {
30236
30570
  encodeSessionLiveHistoryPageLoaded,
30237
30571
  decodeSessionLiveHistoryPageLoaded
30238
30572
  ),
30573
+ [SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND]: defineMessageSignature(
30574
+ SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND,
30575
+ encodeSessionLiveHistoryV2PageLoaded,
30576
+ decodeSessionLiveHistoryV2PageLoaded
30577
+ ),
30239
30578
  [SESSION_READY_KIND]: defineMessageSignature(SESSION_READY_KIND, encodeSessionReadyEvent, decodeSessionReadyEvent),
30240
30579
  [WORKSPACE_ENTRIES_KIND]: defineMessageSignature(
30241
30580
  WORKSPACE_ENTRIES_KIND,
@@ -30320,7 +30659,7 @@ function createDaemonConfig(connection, agents = [], installableAgents = [], loc
30320
30659
 
30321
30660
  // src/daemon-manager.ts
30322
30661
  import { spawn as spawn6 } from "node:child_process";
30323
- import { createHash as createHash7, randomBytes } from "node:crypto";
30662
+ import { createHash as createHash8, randomBytes } from "node:crypto";
30324
30663
  import { readFile as readFile3, unlink as unlink2, writeFile as writeFile4 } from "node:fs/promises";
30325
30664
  import { createConnection, createServer } from "node:net";
30326
30665
  import { tmpdir } from "node:os";
@@ -30655,16 +30994,16 @@ var RuntimeInstallationStore = class _RuntimeInstallationStore {
30655
30994
  };
30656
30995
  #readConnectionForChannel = async (channelId, signal) => {
30657
30996
  const normalizedChannelId = validateIdentifier(channelId, "invalid_channel_id");
30658
- const index = decodeChannelIndex(
30997
+ const index2 = decodeChannelIndex(
30659
30998
  await readJsonFile(this.channelIndexPath(normalizedChannelId), signal, "connection_not_found")
30660
30999
  );
30661
- if (index.applicationId !== this.applicationId || index.installationId !== this.installationId || index.channelId !== normalizedChannelId) {
31000
+ if (index2.applicationId !== this.applicationId || index2.installationId !== this.installationId || index2.channelId !== normalizedChannelId) {
30662
31001
  throw new RuntimeInstallationStoreError(
30663
31002
  "connection_owner_mismatch",
30664
31003
  "The saved Runtime connection belongs to another installation"
30665
31004
  );
30666
31005
  }
30667
- return await this.readConnection(index.connectionId, signal);
31006
+ return await this.readConnection(index2.connectionId, signal);
30668
31007
  };
30669
31008
  saveConnection = async (input2, signal) => {
30670
31009
  const stored = new VerifiedRuntimeConnection(
@@ -30859,16 +31198,16 @@ function hasExactKeys2(value, expectedKeys) {
30859
31198
  }
30860
31199
  function readSingleOption(arguments_, option) {
30861
31200
  const values = [];
30862
- for (let index = 0; index < arguments_.length; index += 1) {
30863
- if (arguments_[index] !== option) {
31201
+ for (let index2 = 0; index2 < arguments_.length; index2 += 1) {
31202
+ if (arguments_[index2] !== option) {
30864
31203
  continue;
30865
31204
  }
30866
- const value = arguments_[index + 1];
31205
+ const value = arguments_[index2 + 1];
30867
31206
  if (value === void 0 || value.startsWith("--")) {
30868
31207
  throw new PairingClientError("invalid_arguments", `${option} requires a value`);
30869
31208
  }
30870
31209
  values.push(value);
30871
- index += 1;
31210
+ index2 += 1;
30872
31211
  }
30873
31212
  if (values.length !== 1) {
30874
31213
  throw new PairingClientError("invalid_arguments", `${option} must be provided exactly once`);
@@ -30876,8 +31215,8 @@ function readSingleOption(arguments_, option) {
30876
31215
  return values[0] ?? "";
30877
31216
  }
30878
31217
  function assertKnownArguments(arguments_) {
30879
- for (let index = 0; index < arguments_.length; index += 2) {
30880
- const option = arguments_[index];
31218
+ for (let index2 = 0; index2 < arguments_.length; index2 += 2) {
31219
+ const option = arguments_[index2];
30881
31220
  if (option !== "--url" && option !== "--code" && option !== "--pairing" && option !== "--workspace") {
30882
31221
  throw new PairingClientError("invalid_arguments", `Unknown pairing option: ${option ?? "missing option"}`);
30883
31222
  }
@@ -31154,7 +31493,7 @@ var AuditStore = class {
31154
31493
  };
31155
31494
 
31156
31495
  // src/run-daemon.ts
31157
- import { createHash as createHash6, randomUUID as randomUUID8 } from "node:crypto";
31496
+ import { createHash as createHash7, randomUUID as randomUUID7 } from "node:crypto";
31158
31497
  import { join as join18 } from "node:path";
31159
31498
  import { styleText } from "node:util";
31160
31499
 
@@ -31277,7 +31616,7 @@ function startsWith(bytes, signature, offset = 0) {
31277
31616
  if (bytes.byteLength < offset + signature.byteLength) {
31278
31617
  return false;
31279
31618
  }
31280
- return signature.every((value, index) => bytes[offset + index] === value);
31619
+ return signature.every((value, index2) => bytes[offset + index2] === value);
31281
31620
  }
31282
31621
  function sniffRasterMime(bytes) {
31283
31622
  if (startsWith(bytes, PNG_SIGNATURE)) {
@@ -31405,7 +31744,7 @@ function startsWith2(bytes, signature, offset = 0) {
31405
31744
  if (bytes.byteLength < offset + signature.byteLength) {
31406
31745
  return false;
31407
31746
  }
31408
- return signature.every((value, index) => bytes[offset + index] === value);
31747
+ return signature.every((value, index2) => bytes[offset + index2] === value);
31409
31748
  }
31410
31749
  function sniffVideoMime(bytes) {
31411
31750
  if (startsWith2(bytes, MP4_FILE_TYPE, 4)) {
@@ -31534,10 +31873,10 @@ async function replaceImageMarkers(text2, replace) {
31534
31873
  let cursor = 0;
31535
31874
  let rewritten = "";
31536
31875
  for (const match of matches) {
31537
- const index = match.index ?? 0;
31538
- rewritten += text2.slice(cursor, index);
31876
+ const index2 = match.index ?? 0;
31877
+ rewritten += text2.slice(cursor, index2);
31539
31878
  rewritten += await replace(match[1] ?? "");
31540
- cursor = index + match[0].length;
31879
+ cursor = index2 + match[0].length;
31541
31880
  }
31542
31881
  return `${rewritten}${text2.slice(cursor)}`;
31543
31882
  }
@@ -32703,6 +33042,7 @@ function sessionConfigProtocolForAgent(_agentId) {
32703
33042
 
32704
33043
  // src/acp/session-contracts.ts
32705
33044
  var NullAcpSessionObserver = class {
33045
+ onAcpUpdate = (_sessionId, _update) => Promise.resolve();
32706
33046
  onCommands = () => Promise.resolve();
32707
33047
  onConfig = () => Promise.resolve();
32708
33048
  onContent = () => Promise.resolve();
@@ -32770,6 +33110,7 @@ function historyContentCharacters(messages) {
32770
33110
  var AcpHistoryReplay = class {
32771
33111
  #activities = /* @__PURE__ */ new Map();
32772
33112
  #messages = [];
33113
+ #updates = [];
32773
33114
  #turnActivityIds = /* @__PURE__ */ new Set();
32774
33115
  #activityTracker = new AcpActivityTracker(
32775
33116
  async (activity2) => {
@@ -32791,7 +33132,8 @@ var AcpHistoryReplay = class {
32791
33132
  #firstMessageIndex = 0;
32792
33133
  #characters = 0;
32793
33134
  #truncated = false;
32794
- record = async (update) => {
33135
+ record = async (update, rawUpdate) => {
33136
+ this.#updates.push(rawUpdate);
32795
33137
  if (update.sessionUpdate === "agent_thought_chunk") {
32796
33138
  if (update.content.type === "text") {
32797
33139
  await this.#activityTracker.recordNarrative(
@@ -32872,6 +33214,20 @@ var AcpHistoryReplay = class {
32872
33214
  this.#lastMessageId = id;
32873
33215
  this.trimMessages();
32874
33216
  };
33217
+ eventPage = (eventLimit, cursor) => {
33218
+ const parsedCursor = cursor === null ? this.#updates.length : Number(cursor);
33219
+ if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > this.#updates.length) {
33220
+ throw new Error("The native event cursor is invalid");
33221
+ }
33222
+ const endUpdate = parsedCursor;
33223
+ const startUpdate = Math.max(0, endUpdate - eventLimit);
33224
+ return {
33225
+ nextCursor: startUpdate === 0 ? null : startUpdate.toString(),
33226
+ startPosition: startUpdate + 1,
33227
+ truncated: startUpdate > 0,
33228
+ updates: this.#updates.slice(startUpdate, endUpdate)
33229
+ };
33230
+ };
32875
33231
  snapshot = async () => {
32876
33232
  await this.#activityTracker.finish();
32877
33233
  const messages = this.#messages.slice(this.#firstMessageIndex).map((message) => {
@@ -34859,8 +35215,8 @@ function haveSameKeys(left, right) {
34859
35215
  if (leftKeys.length !== rightKeys.length) {
34860
35216
  return false;
34861
35217
  }
34862
- for (const [index, key] of leftKeys.entries()) {
34863
- if (key !== rightKeys[index]) {
35218
+ for (const [index2, key] of leftKeys.entries()) {
35219
+ if (key !== rightKeys[index2]) {
34864
35220
  return false;
34865
35221
  }
34866
35222
  }
@@ -36048,6 +36404,55 @@ var sqliteTable = (name, columns, extraConfig) => {
36048
36404
  return sqliteTableBase(name, columns, extraConfig);
36049
36405
  };
36050
36406
 
36407
+ // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6.13_better-sqlite3@12.4.1/node_modules/drizzle-orm/sqlite-core/indexes.js
36408
+ var IndexBuilderOn = class {
36409
+ constructor(name, unique) {
36410
+ this.name = name;
36411
+ this.unique = unique;
36412
+ }
36413
+ static [entityKind] = "SQLiteIndexBuilderOn";
36414
+ on(...columns) {
36415
+ return new IndexBuilder(this.name, columns, this.unique);
36416
+ }
36417
+ };
36418
+ var IndexBuilder = class {
36419
+ static [entityKind] = "SQLiteIndexBuilder";
36420
+ /** @internal */
36421
+ config;
36422
+ constructor(name, columns, unique) {
36423
+ this.config = {
36424
+ name,
36425
+ columns,
36426
+ unique,
36427
+ where: void 0
36428
+ };
36429
+ }
36430
+ /**
36431
+ * Condition for partial index.
36432
+ */
36433
+ where(condition) {
36434
+ this.config.where = condition;
36435
+ return this;
36436
+ }
36437
+ /** @internal */
36438
+ build(table) {
36439
+ return new Index(this.config, table);
36440
+ }
36441
+ };
36442
+ var Index = class {
36443
+ static [entityKind] = "SQLiteIndex";
36444
+ config;
36445
+ constructor(config2, table) {
36446
+ this.config = { ...config2, table };
36447
+ }
36448
+ };
36449
+ function index(name) {
36450
+ return new IndexBuilderOn(name, false);
36451
+ }
36452
+ function uniqueIndex(name) {
36453
+ return new IndexBuilderOn(name, true);
36454
+ }
36455
+
36051
36456
  // ../../node_modules/.pnpm/drizzle-orm@0.45.2_@cloudflare+workers-types@5.20260918.1_@types+better-sqlite3@7.6.13_better-sqlite3@12.4.1/node_modules/drizzle-orm/sqlite-core/utils.js
36052
36457
  function extractUsedTable(table) {
36053
36458
  if (is(table, SQLiteTable)) {
@@ -36396,8 +36801,8 @@ var SQLiteDialect = class {
36396
36801
  }
36397
36802
  const joinsArray = [];
36398
36803
  if (joins) {
36399
- for (const [index, joinMeta] of joins.entries()) {
36400
- if (index === 0) {
36804
+ for (const [index2, joinMeta] of joins.entries()) {
36805
+ if (index2 === 0) {
36401
36806
  joinsArray.push(sql` `);
36402
36807
  }
36403
36808
  const table = joinMeta.table;
@@ -36417,7 +36822,7 @@ var SQLiteDialect = class {
36417
36822
  sql`${sql.raw(joinMeta.joinType)} join ${table}${onSql}`
36418
36823
  );
36419
36824
  }
36420
- if (index < joins.length - 1) {
36825
+ if (index2 < joins.length - 1) {
36421
36826
  joinsArray.push(sql` `);
36422
36827
  }
36423
36828
  }
@@ -36430,9 +36835,9 @@ var SQLiteDialect = class {
36430
36835
  buildOrderBy(orderBy) {
36431
36836
  const orderByList = [];
36432
36837
  if (orderBy) {
36433
- for (const [index, orderByValue] of orderBy.entries()) {
36838
+ for (const [index2, orderByValue] of orderBy.entries()) {
36434
36839
  orderByList.push(orderByValue);
36435
- if (index < orderBy.length - 1) {
36840
+ if (index2 < orderBy.length - 1) {
36436
36841
  orderByList.push(sql`, `);
36437
36842
  }
36438
36843
  }
@@ -36485,9 +36890,9 @@ var SQLiteDialect = class {
36485
36890
  const havingSql = having ? sql` having ${having}` : void 0;
36486
36891
  const groupByList = [];
36487
36892
  if (groupBy) {
36488
- for (const [index, groupByValue] of groupBy.entries()) {
36893
+ for (const [index2, groupByValue] of groupBy.entries()) {
36489
36894
  groupByList.push(groupByValue);
36490
- if (index < groupBy.length - 1) {
36895
+ if (index2 < groupBy.length - 1) {
36491
36896
  groupByList.push(sql`, `);
36492
36897
  }
36493
36898
  }
@@ -38901,6 +39306,10 @@ var acpSessionStoreMigrations = [
38901
39306
  {
38902
39307
  "name": "0001_regular_ultimates.sql",
38903
39308
  "sql": "ALTER TABLE `acp_session` ADD `last_terminal_command_id` text;"
39309
+ },
39310
+ {
39311
+ "name": "0002_equal_black_queen.sql",
39312
+ "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`);"
38904
39313
  }
38905
39314
  ];
38906
39315
 
@@ -38908,7 +39317,8 @@ var acpSessionStoreMigrations = [
38908
39317
  var acp_session_store_exports = {};
38909
39318
  __export(acp_session_store_exports, {
38910
39319
  acpSession: () => acpSession,
38911
- deletedAcpSession: () => deletedAcpSession
39320
+ deletedAcpSession: () => deletedAcpSession,
39321
+ sessionEventV2: () => sessionEventV2
38912
39322
  });
38913
39323
 
38914
39324
  // src/schema/acp-session-store/acp-session.ts
@@ -38929,6 +39339,21 @@ var deletedAcpSession = sqliteTable("deleted_acp_session", {
38929
39339
  sessionId: text("session_id").primaryKey()
38930
39340
  });
38931
39341
 
39342
+ // src/schema/acp-session-store/session-event-v2.ts
39343
+ var sessionEventV2 = sqliteTable(
39344
+ "session_event_v2",
39345
+ {
39346
+ eventId: text("event_id").primaryKey(),
39347
+ eventJson: text("event_json").notNull(),
39348
+ position: integer2("position").notNull(),
39349
+ sessionId: text("session_id").notNull()
39350
+ },
39351
+ (table) => [
39352
+ uniqueIndex("session_event_v2_session_position_unique").on(table.sessionId, table.position),
39353
+ index("session_event_v2_session_position_index").on(table.sessionId, table.position)
39354
+ ]
39355
+ );
39356
+
38932
39357
  // src/acp/session-store.ts
38933
39358
  var AcpStoredSession = class {
38934
39359
  additionalDirectories;
@@ -38971,9 +39396,14 @@ var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
38971
39396
  var MemoryAcpSessionStore = class {
38972
39397
  #sessions = /* @__PURE__ */ new Map();
38973
39398
  #deleted = /* @__PURE__ */ new Set();
39399
+ #eventsV2 = /* @__PURE__ */ new Map();
39400
+ appendEventV2 = (event) => {
39401
+ this.#eventsV2.set(event.sessionId, [...this.#eventsV2.get(event.sessionId) ?? [], event]);
39402
+ };
38974
39403
  close = () => {
38975
39404
  this.#sessions.clear();
38976
39405
  this.#deleted.clear();
39406
+ this.#eventsV2.clear();
38977
39407
  };
38978
39408
  findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
38979
39409
  (session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
@@ -38984,6 +39414,7 @@ var MemoryAcpSessionStore = class {
38984
39414
  for (const id of ids) {
38985
39415
  this.#sessions.delete(id);
38986
39416
  this.#deleted.add(id);
39417
+ this.#eventsV2.delete(id);
38987
39418
  }
38988
39419
  return ids;
38989
39420
  };
@@ -38996,7 +39427,9 @@ var MemoryAcpSessionStore = class {
38996
39427
  };
38997
39428
  remove = (sessionId) => {
38998
39429
  this.#sessions.delete(sessionId);
39430
+ this.#eventsV2.delete(sessionId);
38999
39431
  };
39432
+ readEventsV2 = (sessionId) => this.#eventsV2.get(sessionId) ?? [];
39000
39433
  write = (session) => {
39001
39434
  this.#sessions.set(session.sessionId, session);
39002
39435
  };
@@ -39045,15 +39478,15 @@ var SqliteAcpSessionStore = class {
39045
39478
  this.#sqliteDatabase.close();
39046
39479
  throw new Error("The ACP Session database was created by a newer Mobius version");
39047
39480
  }
39048
- for (let index = version3; index < acpSessionStoreMigrations.length; index += 1) {
39049
- const migration = acpSessionStoreMigrations[index];
39481
+ for (let index2 = version3; index2 < acpSessionStoreMigrations.length; index2 += 1) {
39482
+ const migration = acpSessionStoreMigrations[index2];
39050
39483
  if (migration === void 0) {
39051
39484
  throw new Error("The ACP Session migration is unavailable");
39052
39485
  }
39053
39486
  this.#sqliteDatabase.exec("BEGIN IMMEDIATE");
39054
39487
  try {
39055
39488
  this.#sqliteDatabase.exec(migration.sql);
39056
- this.#sqliteDatabase.pragma(`user_version = ${index + 1}`);
39489
+ this.#sqliteDatabase.pragma(`user_version = ${index2 + 1}`);
39057
39490
  this.#sqliteDatabase.exec("COMMIT");
39058
39491
  } catch (error62) {
39059
39492
  this.#sqliteDatabase.exec("ROLLBACK");
@@ -39064,6 +39497,14 @@ var SqliteAcpSessionStore = class {
39064
39497
  close = () => {
39065
39498
  this.#sqliteDatabase.close();
39066
39499
  };
39500
+ appendEventV2 = (event) => {
39501
+ this.#database.insert(sessionEventV2).values({
39502
+ eventId: event.eventId,
39503
+ eventJson: JSON.stringify(event),
39504
+ position: Number(event.position),
39505
+ sessionId: event.sessionId
39506
+ }).run();
39507
+ };
39067
39508
  findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
39068
39509
  list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
39069
39510
  markDeleted = (agentId, nativeSessionId) => {
@@ -39072,6 +39513,7 @@ var SqliteAcpSessionStore = class {
39072
39513
  transaction.delete(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).run();
39073
39514
  for (const id of ids) {
39074
39515
  transaction.insert(deletedAcpSession).values({ sessionId: id }).onConflictDoNothing().run();
39516
+ transaction.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, id)).run();
39075
39517
  }
39076
39518
  });
39077
39519
  return ids;
@@ -39085,8 +39527,12 @@ var SqliteAcpSessionStore = class {
39085
39527
  const row = this.#database.select().from(acpSession).where(eq(acpSession.sessionId, sessionId)).get();
39086
39528
  return row === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(decodeStoredSession(row));
39087
39529
  };
39530
+ readEventsV2 = (sessionId) => this.#database.select({ eventJson: sessionEventV2.eventJson }).from(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).orderBy(asc(sessionEventV2.position)).all().map((row) => decodeSessionEventV2(row.eventJson));
39088
39531
  remove = (sessionId) => {
39089
- this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
39532
+ this.#database.transaction((transaction) => {
39533
+ transaction.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
39534
+ transaction.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).run();
39535
+ });
39090
39536
  };
39091
39537
  write = (session) => {
39092
39538
  const value = {
@@ -39119,7 +39565,7 @@ var RetryableAcpInitializationError = class extends AcpExecutionError {
39119
39565
  }
39120
39566
  };
39121
39567
  function arraysEqual(left, right) {
39122
- return left.length === right.length && left.every((value, index) => value === right[index]);
39568
+ return left.length === right.length && left.every((value, index2) => value === right[index2]);
39123
39569
  }
39124
39570
  function recordsEqual(left, right) {
39125
39571
  const leftEntries = Object.entries(left);
@@ -39266,6 +39712,17 @@ var AgentSession = class _AgentSession {
39266
39712
  const loaded = await this.#loadSession(signal, "ACP agent exited while loading history");
39267
39713
  return await embedLocalHistoryImages(await loaded.history.snapshot(), signal);
39268
39714
  };
39715
+ loadHistoryEventsV2 = async (eventLimit, cursor, signal) => {
39716
+ if (!this.#capabilities.loadSession) {
39717
+ throw new AcpExecutionError(
39718
+ "This Agent restores context but does not provide message history.",
39719
+ {},
39720
+ "native_history_unsupported"
39721
+ );
39722
+ }
39723
+ const loaded = await this.#loadSession(signal, "ACP agent exited while loading history");
39724
+ return loaded.history.eventPage(eventLimit, cursor);
39725
+ };
39269
39726
  async #loadSession(signal, exitMessage) {
39270
39727
  if (this.#sessionLoad.kind === "loaded") {
39271
39728
  return this.#sessionLoad;
@@ -39912,8 +40369,14 @@ var AgentSession = class _AgentSession {
39912
40369
  #processUpdate = async (notification) => {
39913
40370
  this.assertNativeSession(notification.sessionId);
39914
40371
  const update = notification.update;
40372
+ const rawUpdate = decodeAcpSessionUpdateV2(JSON.stringify(update));
39915
40373
  if (this.#sessionLoad.kind !== "not-requested") {
39916
- await this.#sessionLoad.history.record(update);
40374
+ await this.#sessionLoad.history.record(update, rawUpdate);
40375
+ } else {
40376
+ const onAcpUpdate = this.#getObserver().onAcpUpdate;
40377
+ if (onAcpUpdate !== void 0) {
40378
+ await onAcpUpdate(this.#mobiusSessionId, rawUpdate);
40379
+ }
39917
40380
  }
39918
40381
  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")) {
39919
40382
  return;
@@ -40295,6 +40758,21 @@ var AgentQueryProcesses = class {
40295
40758
  async (runtime) => await runtime.closeProcess()
40296
40759
  );
40297
40760
  };
40761
+ previewEventsV2 = async (options, nativeSessionId, eventLimit, cursor) => {
40762
+ return await this.#processes.runTransient(
40763
+ options.signal,
40764
+ async () => await AgentSession.startNativeSessionBrowser(
40765
+ options,
40766
+ () => this.#observer,
40767
+ new MemoryAcpSessionStore()
40768
+ ),
40769
+ async (runtime) => {
40770
+ runtime.selectNativeSession(nativeSessionId);
40771
+ return await runtime.loadHistoryEventsV2(eventLimit, cursor, options.signal);
40772
+ },
40773
+ async (runtime) => await runtime.closeProcess()
40774
+ );
40775
+ };
40298
40776
  close = async () => {
40299
40777
  await Promise.all(
40300
40778
  this.#processesByQuery.entries().map(async ([id, runtime]) => await this.retire(id, runtime))
@@ -40364,9 +40842,9 @@ var AcpProcessCapacityLock = class {
40364
40842
  return await waiter.completion.promise;
40365
40843
  } finally {
40366
40844
  signal.removeEventListener("abort", waiter.cancel);
40367
- const index = this.#waiters.indexOf(waiter);
40368
- if (index >= 0) {
40369
- this.#waiters.splice(index, 1);
40845
+ const index2 = this.#waiters.indexOf(waiter);
40846
+ if (index2 >= 0) {
40847
+ this.#waiters.splice(index2, 1);
40370
40848
  }
40371
40849
  }
40372
40850
  };
@@ -40996,6 +41474,22 @@ var AgentRuntimeManager = class {
40996
41474
  this.#nativeOperations.delete(key);
40997
41475
  }
40998
41476
  });
41477
+ previewNativeSessionEventsV2 = async (options, nativeSessionId, eventLimit, cursor) => this.#operations.run(options, async (options2) => {
41478
+ const key = `${options2.agent.id}:${nativeSessionId}`;
41479
+ if (this.#nativeOperations.has(key)) {
41480
+ throw new AcpExecutionError(
41481
+ "Wait for the native session's running operation to finish",
41482
+ {},
41483
+ "session_busy"
41484
+ );
41485
+ }
41486
+ this.#nativeOperations.add(key);
41487
+ try {
41488
+ return await this.#queryProcesses.previewEventsV2(options2, nativeSessionId, eventLimit, cursor);
41489
+ } finally {
41490
+ this.#nativeOperations.delete(key);
41491
+ }
41492
+ });
40999
41493
  loadSessionHistory = async (options) => this.#operations.run(options, async (options2) => {
41000
41494
  return await this.#executionProcesses.use(options2.sessionId, async () => {
41001
41495
  const runtime = await this.ensureSession(options2);
@@ -41013,6 +41507,12 @@ var AgentRuntimeManager = class {
41013
41507
  return await runtime.loadHistory(options2.signal);
41014
41508
  });
41015
41509
  });
41510
+ loadSessionEventsV2 = async (options, eventLimit, cursor) => this.#operations.run(options, async (options2) => {
41511
+ return await this.#executionProcesses.use(options2.sessionId, async () => {
41512
+ const runtime = await this.ensureSession(options2);
41513
+ return await runtime.loadHistoryEventsV2(eventLimit, cursor, options2.signal);
41514
+ });
41515
+ });
41016
41516
  openNativeSession = async (options, origin) => this.#operations.run(options, async (options2) => {
41017
41517
  const key = `${options2.agent.id}:${origin.nativeSessionId}`;
41018
41518
  if (this.#nativeOperations.has(key)) {
@@ -42215,9 +42715,15 @@ function reportOperationFailure(socket, requestId, sessionId, error62, runtimeTi
42215
42715
  // src/daemon-observers.ts
42216
42716
  var DaemonAcpObserver = class {
42217
42717
  #record;
42218
- constructor(record2) {
42718
+ #recordV2;
42719
+ constructor(record2, recordV2 = () => void 0) {
42219
42720
  this.#record = record2;
42721
+ this.#recordV2 = recordV2;
42220
42722
  }
42723
+ onAcpUpdate = (sessionId, update) => {
42724
+ this.#recordV2(sessionId, update);
42725
+ return Promise.resolve();
42726
+ };
42221
42727
  onCommands = (event) => {
42222
42728
  this.#record(event.sessionId, event);
42223
42729
  return Promise.resolve();
@@ -42354,8 +42860,8 @@ var ACTIVE_TURN_TEXT_CHUNK_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT /
42354
42860
  function boundedRecoveryMessages(messages) {
42355
42861
  const selected = [];
42356
42862
  let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT;
42357
- for (let index = messages.length - 1; index >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index -= 1) {
42358
- const message = messages[index];
42863
+ for (let index2 = messages.length - 1; index2 >= 0 && selected.length < SESSION_HISTORY_MESSAGE_LIMIT; index2 -= 1) {
42864
+ const message = messages[index2];
42359
42865
  if (message === void 0) {
42360
42866
  break;
42361
42867
  }
@@ -42496,7 +43002,7 @@ var ActiveDaemonTurn = class {
42496
43002
  ];
42497
43003
  } else {
42498
43004
  this.#timeline = this.#timeline.map(
42499
- (entry, index) => index === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
43005
+ (entry, index2) => index2 === target && entry.kind === "message" ? { ...entry, content: new Map([...entry.content, [event.contentId, event.content]]) } : entry
42500
43006
  );
42501
43007
  }
42502
43008
  } else if (event.kind === SESSION_PERMISSION_REQUESTED_KIND || event.kind === SESSION_ELICITATION_REQUESTED_KIND) {
@@ -43507,7 +44013,7 @@ async function readAcpHistory(sessions, directories, bindingId, options, nativeS
43507
44013
  async (directory) => await directories.identify(bindingId, directory, options.signal)
43508
44014
  )
43509
44015
  );
43510
- if (primary.path !== options.cwd || additional.length !== options.additionalDirectories.length || additional.some((directory, index) => directory.path !== options.additionalDirectories[index])) {
44016
+ if (primary.path !== options.cwd || additional.length !== options.additionalDirectories.length || additional.some((directory, index2) => directory.path !== options.additionalDirectories[index2])) {
43511
44017
  throw new AcpExecutionError(
43512
44018
  "The native Session belongs to another workspace.",
43513
44019
  {},
@@ -43640,7 +44146,7 @@ var NativeSessionService = class {
43640
44146
  "native_session_not_found"
43641
44147
  );
43642
44148
  }
43643
- if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path3, index) => path3 !== additionalDirectories[index])) {
44149
+ if (source.agentId !== command.agentId || source.cwd !== cwd || source.additionalDirectories.length !== additionalDirectories.length || source.additionalDirectories.some((path3, index2) => path3 !== additionalDirectories[index2])) {
43644
44150
  throw new AcpExecutionError(
43645
44151
  "The source conversation execution target does not match the fork request",
43646
44152
  {},
@@ -43661,8 +44167,8 @@ var NativeSessionService = class {
43661
44167
  signal.throwIfAborted();
43662
44168
  const directory = await this.#directories.list(this.#config.bindingId, command.directoryId, signal);
43663
44169
  const ready2 = {
43664
- additionalDirectories: additionalDirectories.map((path3, index) => ({
43665
- directoryId: command.additionalDirectoryIds[index] ?? command.directoryId,
44170
+ additionalDirectories: additionalDirectories.map((path3, index2) => ({
44171
+ directoryId: command.additionalDirectoryIds[index2] ?? command.directoryId,
43666
44172
  name: basename5(path3) || path3
43667
44173
  })),
43668
44174
  agentId: command.agentId,
@@ -43994,7 +44500,7 @@ var NativeSessionService = class {
43994
44500
  resolveTarget = async (command, options, selected) => {
43995
44501
  let cursor = null;
43996
44502
  const visited = /* @__PURE__ */ new Set();
43997
- for (let index = 0; index < 100; index += 1) {
44503
+ for (let index2 = 0; index2 < 100; index2 += 1) {
43998
44504
  const page = await this.#sessions.listNativeSessions(options, cursor);
43999
44505
  const info = page.sessions.find((entry) => entry.sessionId === selected.nativeSessionId);
44000
44506
  if (info !== void 0) {
@@ -44002,7 +44508,7 @@ var NativeSessionService = class {
44002
44508
  if (target === null) {
44003
44509
  throw new LocalAuthorizationError("The selected native session is not authorized");
44004
44510
  }
44005
- if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path3, index2) => path3 !== selected.additionalDirectories[index2])) {
44511
+ if (target.cwd !== selected.cwd || target.additionalDirectories.length !== selected.additionalDirectories.length || target.additionalDirectories.some((path3, index3) => path3 !== selected.additionalDirectories[index3])) {
44006
44512
  throw new AcpExecutionError(
44007
44513
  "This session's directory changed. Refresh the list before continuing.",
44008
44514
  {},
@@ -45090,6 +45596,9 @@ async function streamLocalFile(command, send2, signal, workingDirectory) {
45090
45596
  });
45091
45597
  }
45092
45598
 
45599
+ // src/daemon-history-commands.ts
45600
+ import { createHash as createHash6 } from "node:crypto";
45601
+
45093
45602
  // src/authorization/resolve-session-directories.ts
45094
45603
  import { basename as basename7 } from "node:path";
45095
45604
  var ResolvedSessionDirectories = class {
@@ -45189,8 +45698,8 @@ function selectMessagesBefore(messages, endIndex, messageLimit, characterLimit)
45189
45698
  const selected = [];
45190
45699
  let remainingCharacters = characterLimit;
45191
45700
  let startIndex = endIndex;
45192
- for (let index = endIndex - 1; index >= 0 && selected.length < messageLimit; index -= 1) {
45193
- const message = messages[index];
45701
+ for (let index2 = endIndex - 1; index2 >= 0 && selected.length < messageLimit; index2 -= 1) {
45702
+ const message = messages[index2];
45194
45703
  if (message === void 0) {
45195
45704
  break;
45196
45705
  }
@@ -45200,7 +45709,7 @@ function selectMessagesBefore(messages, endIndex, messageLimit, characterLimit)
45200
45709
  }
45201
45710
  selected.unshift(message);
45202
45711
  remainingCharacters -= characters;
45203
- startIndex = index;
45712
+ startIndex = index2;
45204
45713
  }
45205
45714
  if (selected.length === 0 && endIndex > 0) {
45206
45715
  throw new AcpExecutionError(
@@ -45480,6 +45989,79 @@ async function executeSessionLiveHistoryPageLoad(socket, command, config2, direc
45480
45989
  });
45481
45990
  }
45482
45991
  }
45992
+ function replayEvent(sessionId, position, update) {
45993
+ const encoded = JSON.stringify(update);
45994
+ const eventId = `native-${createHash6("sha256").update(sessionId).update(":").update(position.toString()).update(":").update(encoded).digest("hex")}`;
45995
+ return {
45996
+ eventId,
45997
+ payload: { kind: "acp.session.update", update },
45998
+ position: position.toString(),
45999
+ provenance: { kind: "original" },
46000
+ recordedAt: "1970-01-01T00:00:00.000Z",
46001
+ sessionId
46002
+ };
46003
+ }
46004
+ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, directories, audit, sessions, localRecovery, executingPromptRequest, signal) {
46005
+ try {
46006
+ const local = localRecovery(command.sessionId, command.eventLimit, command.cursor);
46007
+ if (local !== null) {
46008
+ send(socket, {
46009
+ events: local,
46010
+ kind: "session.live-history.v2.page.loaded",
46011
+ requestId: command.requestId,
46012
+ sessionId: command.sessionId
46013
+ });
46014
+ return;
46015
+ }
46016
+ const resolved = await resolveSessionDirectories(
46017
+ directories,
46018
+ config2.bindingId,
46019
+ command.directoryId,
46020
+ command.additionalDirectoryIds,
46021
+ signal
46022
+ );
46023
+ const replay = await sessions.loadSessionEventsV2(
46024
+ {
46025
+ additionalDirectories: resolved.additionalDirectories,
46026
+ agent: config2.catalog.find(command.agentId),
46027
+ cwd: resolved.cwd,
46028
+ sessionId: command.sessionId,
46029
+ signal
46030
+ },
46031
+ command.eventLimit,
46032
+ command.cursor
46033
+ );
46034
+ signal.throwIfAborted();
46035
+ const events = replay.updates.map(
46036
+ (update, index2) => replayEvent(command.sessionId, replay.startPosition + index2, update)
46037
+ );
46038
+ const tailCursor = events.at(-1)?.eventId ?? "";
46039
+ audit.record({
46040
+ commandId: command.requestId,
46041
+ event: "session_event_log_v2_loaded",
46042
+ sessionId: command.sessionId
46043
+ });
46044
+ send(socket, {
46045
+ events: {
46046
+ executingPromptRequest: executingPromptRequest(command.sessionId),
46047
+ history: {
46048
+ events,
46049
+ nextCursor: replay.nextCursor,
46050
+ tailCursor,
46051
+ truncated: replay.truncated,
46052
+ version: 2
46053
+ }
46054
+ },
46055
+ kind: "session.live-history.v2.page.loaded",
46056
+ requestId: command.requestId,
46057
+ sessionId: command.sessionId
46058
+ });
46059
+ } catch (error62) {
46060
+ if (!signal.aborted) {
46061
+ reportOperationFailure(socket, command.requestId, command.sessionId, error62);
46062
+ }
46063
+ }
46064
+ }
45483
46065
 
45484
46066
  // src/acp/session-config/apply-session-configuration.ts
45485
46067
  import { randomUUID as randomUUID5 } from "node:crypto";
@@ -45794,6 +46376,7 @@ function daemonActivity(command, activity2) {
45794
46376
  async function executePrompt({
45795
46377
  operations,
45796
46378
  publisher,
46379
+ eventLogV2,
45797
46380
  command,
45798
46381
  config: config2,
45799
46382
  directories,
@@ -45898,6 +46481,7 @@ async function executePrompt({
45898
46481
  }
45899
46482
  }
45900
46483
  const stream = activateAttempt();
46484
+ eventLogV2.started(command.sessionId, command.commandId, attemptId, stream.epoch);
45901
46485
  if (!prepared.prompted) {
45902
46486
  const listing = await directories.list(config2.bindingId, command.directoryId, signal);
45903
46487
  publisher.publish(command.sessionId, {
@@ -45967,6 +46551,7 @@ async function executePrompt({
45967
46551
  sessionId: command.sessionId,
45968
46552
  stopReason
45969
46553
  });
46554
+ eventLogV2.completed(command.sessionId, command.commandId, stopReason);
45970
46555
  operations.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
45971
46556
  audit.record({
45972
46557
  commandId: command.commandId,
@@ -45982,6 +46567,7 @@ async function executePrompt({
45982
46567
  sessionId: command.sessionId,
45983
46568
  stopReason: "cancelled"
45984
46569
  });
46570
+ eventLogV2.completed(command.sessionId, command.commandId, "cancelled");
45985
46571
  operations.transitionExecution(command.commandId, "cancelled");
45986
46572
  audit.record({
45987
46573
  commandId: command.commandId,
@@ -45996,12 +46582,10 @@ async function executePrompt({
45996
46582
  sessionId: command.sessionId
45997
46583
  });
45998
46584
  const code = operationErrorCode(error62);
45999
- reportFailure(
46000
- publisher,
46001
- command,
46002
- code === "session_operation_failed" ? "agent_execution_failed" : code,
46003
- code === "session_operation_failed" ? "The local agent could not complete the request" : operationErrorMessage(error62)
46004
- );
46585
+ const failureCode = code === "session_operation_failed" ? "agent_execution_failed" : code;
46586
+ const failureMessage = code === "session_operation_failed" ? "The local agent could not complete the request" : operationErrorMessage(error62);
46587
+ eventLogV2.failed(command.sessionId, command.commandId, failureCode, failureMessage);
46588
+ reportFailure(publisher, command, failureCode, failureMessage);
46005
46589
  operations.transitionExecution(command.commandId, "failed");
46006
46590
  console.error("Mobius daemon command failed", error62);
46007
46591
  }
@@ -46284,6 +46868,7 @@ function createDaemonCommandHandler({
46284
46868
  nativeSessions,
46285
46869
  operations,
46286
46870
  publisher,
46871
+ eventLogV2,
46287
46872
  activeTurns,
46288
46873
  diagnostics,
46289
46874
  socket,
@@ -46353,6 +46938,20 @@ function createDaemonCommandHandler({
46353
46938
  );
46354
46939
  return;
46355
46940
  }
46941
+ if (kind === SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND) {
46942
+ void executeSessionLiveHistoryV2PageLoad(
46943
+ socket,
46944
+ message,
46945
+ config2,
46946
+ directories,
46947
+ audit,
46948
+ sessions,
46949
+ eventLogV2.recovery,
46950
+ eventLogV2.executingPromptRequest,
46951
+ signal
46952
+ );
46953
+ return;
46954
+ }
46356
46955
  if (kind === NATIVE_SESSION_CANCEL_KIND) {
46357
46956
  nativeRequestHandler.cancel(message);
46358
46957
  return;
@@ -46538,9 +47137,11 @@ function createDaemonCommandHandler({
46538
47137
  return;
46539
47138
  }
46540
47139
  const turn = activeTurns.start(command, receipt.attemptId);
47140
+ eventLogV2.requested(command);
46541
47141
  void executePrompt({
46542
47142
  operations,
46543
47143
  publisher,
47144
+ eventLogV2,
46544
47145
  command,
46545
47146
  config: config2,
46546
47147
  directories,
@@ -46830,6 +47431,7 @@ async function runRelayConnection({
46830
47431
  nativeSessions,
46831
47432
  operations,
46832
47433
  publisher,
47434
+ eventLogV2,
46833
47435
  activeTurns,
46834
47436
  connectionEpoch,
46835
47437
  diagnostics,
@@ -46840,7 +47442,6 @@ async function runRelayConnection({
46840
47442
  }) {
46841
47443
  const relayUrl = new URL(config2.relayUrl);
46842
47444
  relayUrl.searchParams.set("liveness", "1");
46843
- relayUrl.searchParams.set("sessionEventDelivery", "reliable-v1");
46844
47445
  const socket = await connectRelay(relayUrl, signal);
46845
47446
  diagnostics.connectionOpened(connectionEpoch);
46846
47447
  const connectionController = new AbortController();
@@ -46853,6 +47454,7 @@ async function runRelayConnection({
46853
47454
  nativeSessions,
46854
47455
  operations,
46855
47456
  publisher,
47457
+ eventLogV2,
46856
47458
  activeTurns,
46857
47459
  diagnostics,
46858
47460
  socket,
@@ -46960,10 +47562,7 @@ async function runRelayConnection({
46960
47562
  const message = decodeServiceToDaemonMessage(encoded);
46961
47563
  const kind = message.kind;
46962
47564
  if (kind === RUNTIME_LIVENESS_READY_KIND) {
46963
- publisher.connect(
46964
- socket,
46965
- message.sessionEventDelivery === "reliable-v1" ? "reliable" : "ephemeral"
46966
- );
47565
+ publisher.connect(socket);
46967
47566
  connectionLiveness.start();
46968
47567
  return;
46969
47568
  }
@@ -46971,18 +47570,6 @@ async function runRelayConnection({
46971
47570
  connectionLiveness.acknowledge(message);
46972
47571
  return;
46973
47572
  }
46974
- if (kind === SESSION_EVENT_ACK_KIND) {
46975
- publisher.acknowledge(message);
46976
- return;
46977
- }
46978
- if (kind === SESSION_EVENT_DEFERRED_KIND) {
46979
- publisher.defer(message);
46980
- return;
46981
- }
46982
- if (kind === SESSION_EVENT_REJECTED_KIND) {
46983
- publisher.reject(message);
46984
- return;
46985
- }
46986
47573
  commands.handle(message);
46987
47574
  } catch (error62) {
46988
47575
  console.error("Mobius daemon rejected a message", error62);
@@ -47009,245 +47596,304 @@ async function runRelayConnection({
47009
47596
 
47010
47597
  // src/relay-connection/session-event-publisher.ts
47011
47598
  import { WebSocket as WebSocket9 } from "undici";
47012
-
47013
- // src/relay-connection/session-event-queue.ts
47014
- import { randomUUID as randomUUID7 } from "node:crypto";
47015
- var STANDARD_EVENT_BYTES = 96 * 1024 * 1024;
47016
- var CRITICAL_EVENT_BYTES = 128 * 1024 * 1024;
47017
- var SessionEventQueueCapacityError = class extends Error {
47018
- code = "session_event_queue_full";
47019
- constructor() {
47020
- super("The in-memory Session event queue is full");
47021
- this.name = "SessionEventQueueCapacityError";
47022
- }
47023
- };
47024
- var SessionEventQueue = class {
47025
- #streamId = randomUUID7();
47026
- #events = /* @__PURE__ */ new Map();
47027
- #nextSourceSeq = 1;
47028
- #totalBytes = 0;
47029
- enqueueBatch = (sessionId, payloads, critical) => {
47030
- if (payloads.length < 1 || payloads.length > 32) {
47031
- throw new Error("A Session event batch must contain between 1 and 32 events");
47032
- }
47033
- if (!Number.isSafeInteger(this.#nextSourceSeq + payloads.length)) {
47034
- throw new Error("The Session event source sequence is exhausted");
47035
- }
47036
- const entries = payloads.map((payload, index) => {
47037
- const envelope2 = {
47038
- delivery: {
47039
- eventId: randomUUID7(),
47040
- kind: "reliable",
47041
- sourceSeq: (this.#nextSourceSeq + index).toString(),
47042
- streamId: this.#streamId
47043
- },
47044
- kind: SESSION_EVENT_KIND,
47045
- payload,
47046
- sessionId
47047
- };
47048
- return { envelope: envelope2, byteLength: Buffer.byteLength(encodeSessionEventEnvelope(envelope2), "utf8") };
47599
+ var MAX_BUFFERED_BYTES = 32 * 1024 * 1024;
47600
+ var DaemonSessionEventPublisher = class {
47601
+ #socket = null;
47602
+ connect = (socket) => {
47603
+ this.#socket = socket;
47604
+ };
47605
+ disconnect = (socket) => {
47606
+ if (this.#socket === socket) {
47607
+ this.#socket = null;
47608
+ }
47609
+ };
47610
+ close = () => {
47611
+ this.#socket = null;
47612
+ };
47613
+ publish = (sessionId, event) => {
47614
+ const socket = this.#socket;
47615
+ if (socket === null || socket.readyState !== WebSocket9.OPEN) {
47616
+ return;
47617
+ }
47618
+ const encoded = encodeDaemonToServiceMessage({
47619
+ kind: SESSION_EVENT_KIND,
47620
+ payload: encodeRecordedSessionEvent(event),
47621
+ sessionId
47049
47622
  });
47050
- const byteLength = entries.reduce((total, entry) => total + entry.byteLength, 0);
47051
- if (this.#totalBytes + byteLength > (critical ? CRITICAL_EVENT_BYTES : STANDARD_EVENT_BYTES)) {
47052
- throw new SessionEventQueueCapacityError();
47623
+ if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
47624
+ socket.close(1013, "Live event transport overloaded");
47625
+ return;
47053
47626
  }
47054
- for (const entry of entries) {
47055
- this.#events.set(entry.envelope.delivery.eventId, entry);
47627
+ try {
47628
+ socket.send(encoded);
47629
+ } catch {
47056
47630
  }
47057
- this.#nextSourceSeq += entries.length;
47058
- this.#totalBytes += byteLength;
47059
47631
  };
47060
- pending = (limit, excludedEventIds) => {
47061
- const result = [];
47062
- for (const [eventId, entry] of this.#events) {
47063
- if (!excludedEventIds.has(eventId)) {
47064
- result.push(entry.envelope);
47065
- if (result.length === limit) {
47066
- break;
47067
- }
47068
- }
47632
+ publishBatch = (sessionId, events) => {
47633
+ for (const event of events) {
47634
+ this.publish(sessionId, event);
47069
47635
  }
47070
- return result;
47071
47636
  };
47072
- remove = (eventId, sessionId) => {
47073
- const entry = this.#events.get(eventId);
47074
- if (entry === void 0 || entry.envelope.sessionId !== sessionId) {
47075
- return false;
47637
+ publishV2 = (event) => {
47638
+ const socket = this.#socket;
47639
+ if (socket === null || socket.readyState !== WebSocket9.OPEN) {
47640
+ return;
47641
+ }
47642
+ const encoded = encodeDaemonToServiceMessage({ event, kind: SESSION_EVENT_V2_KIND });
47643
+ if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
47644
+ socket.close(1013, "Live event transport overloaded");
47645
+ return;
47646
+ }
47647
+ try {
47648
+ socket.send(encoded);
47649
+ } catch {
47076
47650
  }
47077
- this.#events.delete(eventId);
47078
- this.#totalBytes -= entry.byteLength;
47079
- return true;
47080
47651
  };
47081
- clear = () => {
47082
- this.#events.clear();
47083
- this.#totalBytes = 0;
47652
+ };
47653
+
47654
+ // src/relay-connection/timer.ts
47655
+ var SystemDaemonTimer = class {
47656
+ schedule = (callback, milliseconds) => {
47657
+ const timeout = setTimeout(callback, milliseconds);
47658
+ return { cancel: () => clearTimeout(timeout) };
47084
47659
  };
47085
47660
  };
47661
+ var systemDaemonTimer = new SystemDaemonTimer();
47086
47662
 
47087
- // src/relay-connection/session-event-publisher.ts
47088
- var SESSION_EVENT_REPLAY_WINDOW = 16;
47089
- var SESSION_EVENT_REPLAY_BYTE_LIMIT = 32 * 1024 * 1024;
47090
- function reservesSessionEventCapacity(event) {
47091
- if (event.kind === SESSION_COMPLETED_KIND || event.kind === SESSION_FAILED_KIND || event.kind === SESSION_FORKED_KIND || event.kind === SESSION_READY_KIND) {
47092
- return true;
47663
+ // src/session-event-log-v2.ts
47664
+ var EXECUTING_PROMPT_EVENT_LIMIT = 1e4;
47665
+ function promptContent(command) {
47666
+ const content = [];
47667
+ if (command.prompt.length > 0) {
47668
+ content.push({ text: command.prompt, type: "text" });
47669
+ }
47670
+ for (const image of command.images) {
47671
+ content.push({
47672
+ _meta: { mobius: { name: image.name } },
47673
+ data: image.data,
47674
+ mimeType: image.mimeType,
47675
+ type: "image"
47676
+ });
47093
47677
  }
47094
- return event.kind === AGENT_ACTIVITY_KIND && (event.activityType === "progress" || event.activityType === "reasoning") && (event.status === "completed" || event.status === "failed");
47095
- }
47096
- var DaemonSessionEventPublisher = class {
47097
- #inFlight = /* @__PURE__ */ new Map();
47098
- #queue = new SessionEventQueue();
47099
- #reportedCapacityKinds = /* @__PURE__ */ new Set();
47100
- #timer;
47101
- #connection = { kind: "disconnected" };
47102
- #deferredReplay = null;
47103
- #inFlightBytes = 0;
47104
- constructor(timer) {
47105
- this.#timer = timer;
47678
+ for (const resource of command.resources) {
47679
+ content.push(
47680
+ resource.type === "embedded" ? {
47681
+ resource: { mimeType: resource.mimeType, text: resource.text, uri: resource.uri },
47682
+ type: "resource"
47683
+ } : { mimeType: resource.mimeType, name: resource.name, type: "resource_link", uri: resource.uri }
47684
+ );
47106
47685
  }
47107
- acknowledge = (acknowledgement) => {
47108
- if (!this.#queue.remove(acknowledgement.eventId, acknowledgement.sessionId)) {
47109
- return;
47686
+ return content;
47687
+ }
47688
+ function encodeLocalEventCursor(cursor) {
47689
+ return Buffer.from(JSON.stringify(cursor), "utf8").toString("base64url");
47690
+ }
47691
+ function decodeLocalEventCursor(sessionId, cursor) {
47692
+ try {
47693
+ const value = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
47694
+ if (typeof value !== "object" || value === null || Array.isArray(value) || Object.keys(value).sort().join(",") !== "endEvent,sessionId" || Reflect.get(value, "sessionId") !== sessionId) {
47695
+ throw new Error("Invalid V2 event cursor target");
47110
47696
  }
47111
- this.#removeInFlight(acknowledgement.eventId);
47112
- this.#publishNextBatch();
47113
- };
47114
- close = () => {
47115
- this.#deferredReplay?.cancel();
47116
- this.#deferredReplay = null;
47117
- this.#connection = { kind: "disconnected" };
47118
- this.#clearInFlight();
47119
- this.#queue.clear();
47120
- };
47121
- connect = (socket, delivery) => {
47122
- this.#connection = { delivery, kind: "connected", socket };
47123
- this.#clearInFlight();
47124
- this.#publishNextBatch();
47125
- };
47126
- defer = (deferred) => {
47127
- if (!this.#inFlight.has(deferred.eventId)) {
47128
- return;
47697
+ const endEvent = Reflect.get(value, "endEvent");
47698
+ if (typeof endEvent !== "number" || !Number.isSafeInteger(endEvent) || endEvent < 0) {
47699
+ throw new Error("Invalid V2 event cursor boundary");
47129
47700
  }
47130
- this.#clearInFlight();
47131
- if (this.#deferredReplay !== null) {
47132
- return;
47701
+ return { endEvent, sessionId };
47702
+ } catch (cause) {
47703
+ throw new AcpExecutionError("The native Session event cursor is invalid", { cause }, "invalid_cursor");
47704
+ }
47705
+ }
47706
+ var DaemonSessionEventLogV2 = class {
47707
+ #positions = /* @__PURE__ */ new Map();
47708
+ #events = /* @__PURE__ */ new Map();
47709
+ #requests = /* @__PURE__ */ new Map();
47710
+ #loadedRequestSessions = /* @__PURE__ */ new Set();
47711
+ #publisher;
47712
+ #store;
47713
+ constructor(publisher, store) {
47714
+ this.#publisher = publisher;
47715
+ this.#store = store;
47716
+ }
47717
+ #eventsFor = (sessionId) => {
47718
+ const cached2 = this.#events.get(sessionId);
47719
+ if (cached2 !== void 0) {
47720
+ return cached2;
47721
+ }
47722
+ const stored = this.#store.readEventsV2(sessionId);
47723
+ this.#events.set(sessionId, stored);
47724
+ const lastPosition = stored.at(-1)?.position;
47725
+ if (lastPosition !== void 0) {
47726
+ this.#positions.set(sessionId, Number(lastPosition));
47133
47727
  }
47134
- this.#deferredReplay = this.#timer.schedule(() => {
47135
- this.#deferredReplay = null;
47136
- this.#publishNextBatch();
47137
- }, deferred.retryAfterMilliseconds);
47728
+ return stored;
47138
47729
  };
47139
- disconnect = (socket) => {
47140
- if (this.#connection.kind !== "connected" || this.#connection.socket !== socket) {
47730
+ #loadRequests = (sessionId) => {
47731
+ if (this.#loadedRequestSessions.has(sessionId)) {
47141
47732
  return;
47142
47733
  }
47143
- this.#connection = { kind: "disconnected" };
47144
- this.#clearInFlight();
47145
- };
47146
- publish = (sessionId, event) => {
47147
- try {
47148
- this.#queue.enqueueBatch(
47149
- sessionId,
47150
- [encodeRecordedSessionEvent(event)],
47151
- reservesSessionEventCapacity(event)
47152
- );
47153
- } catch (error62) {
47154
- if (!(error62 instanceof SessionEventQueueCapacityError)) {
47155
- throw error62;
47734
+ for (const event of this.#eventsFor(sessionId)) {
47735
+ const payload = event.payload;
47736
+ if (payload.kind === "prompt.requested") {
47737
+ this.#requests.set(payload.commandId, {
47738
+ commandId: payload.commandId,
47739
+ events: [event],
47740
+ kind: "requested",
47741
+ sessionId
47742
+ });
47743
+ continue;
47156
47744
  }
47157
- if (!this.#reportedCapacityKinds.has(event.kind)) {
47158
- this.#reportedCapacityKinds.add(event.kind);
47159
- console.warn(`Mobius daemon could not buffer "${event.kind}" because the Session event queue is full`);
47745
+ if (payload.kind === "acp.session.update") {
47746
+ const executing = [...this.#requests.values()].find(
47747
+ (request) => request.sessionId === sessionId && request.kind === "executing"
47748
+ );
47749
+ if (executing !== void 0) {
47750
+ this.#requests.set(executing.commandId, {
47751
+ ...executing,
47752
+ events: [...executing.events, event]
47753
+ });
47754
+ }
47755
+ continue;
47160
47756
  }
47161
- return;
47162
- }
47163
- this.#publishNextBatch();
47757
+ if (!("commandId" in payload)) {
47758
+ continue;
47759
+ }
47760
+ const state = this.#requests.get(payload.commandId);
47761
+ if (state === void 0) {
47762
+ continue;
47763
+ }
47764
+ const events = [...state.events, event];
47765
+ if (payload.kind === "prompt.started") {
47766
+ this.#requests.set(payload.commandId, {
47767
+ attemptId: payload.attemptId,
47768
+ commandId: payload.commandId,
47769
+ epoch: payload.epoch,
47770
+ events,
47771
+ kind: "executing",
47772
+ sessionId
47773
+ });
47774
+ } else if (payload.kind === "prompt.completed" || payload.kind === "prompt.failed" || payload.kind === "prompt.failed-before-start") {
47775
+ this.#requests.delete(payload.commandId);
47776
+ }
47777
+ }
47778
+ this.#loadedRequestSessions.add(sessionId);
47779
+ };
47780
+ #append = (sessionId, payload) => {
47781
+ this.#eventsFor(sessionId);
47782
+ const position = (this.#positions.get(sessionId) ?? 0) + 1;
47783
+ const event = {
47784
+ eventId: `event-${crypto.randomUUID()}`,
47785
+ payload,
47786
+ position: position.toString(),
47787
+ provenance: { kind: "original" },
47788
+ recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
47789
+ sessionId
47790
+ };
47791
+ this.#store.appendEventV2(event);
47792
+ this.#positions.set(sessionId, position);
47793
+ this.#events.set(sessionId, [...this.#eventsFor(sessionId), event]);
47794
+ this.#publisher.publishV2(event);
47795
+ return event;
47164
47796
  };
47165
- publishBatch = (sessionId, events) => {
47166
- const critical = events.some(reservesSessionEventCapacity);
47167
- this.#queue.enqueueBatch(sessionId, events.map(encodeRecordedSessionEvent), critical);
47168
- this.#publishNextBatch();
47797
+ requested = (command) => {
47798
+ const event = this.#append(command.sessionId, {
47799
+ commandId: command.commandId,
47800
+ content: promptContent(command),
47801
+ kind: "prompt.requested"
47802
+ });
47803
+ this.#requests.set(command.commandId, {
47804
+ commandId: command.commandId,
47805
+ events: [event],
47806
+ kind: "requested",
47807
+ sessionId: command.sessionId
47808
+ });
47169
47809
  };
47170
- reject = (rejection) => {
47171
- if (!this.#queue.remove(rejection.eventId, rejection.sessionId)) {
47810
+ started = (sessionId, commandId, attemptId, epoch) => {
47811
+ this.#loadRequests(sessionId);
47812
+ const request = this.#requests.get(commandId);
47813
+ if (request?.sessionId !== sessionId) {
47172
47814
  return;
47173
47815
  }
47174
- this.#removeInFlight(rejection.eventId);
47175
- console.error(`Mobius Relay rejected Session event ${rejection.eventId} with code ${rejection.code}`);
47176
- this.#publishNextBatch();
47177
- };
47178
- #clearInFlight = () => {
47179
- this.#inFlight.clear();
47180
- this.#inFlightBytes = 0;
47816
+ const event = this.#append(sessionId, { attemptId, commandId, epoch, kind: "prompt.started" });
47817
+ this.#requests.set(commandId, {
47818
+ attemptId,
47819
+ commandId,
47820
+ epoch,
47821
+ events: [...request.events, event],
47822
+ kind: "executing",
47823
+ sessionId
47824
+ });
47181
47825
  };
47182
- #publishNextBatch = () => {
47183
- if (this.#deferredReplay !== null || this.#connection.kind !== "connected") {
47184
- return;
47185
- }
47186
- while (this.#inFlight.size < SESSION_EVENT_REPLAY_WINDOW) {
47187
- const batch = this.#queue.pending(
47188
- SESSION_EVENT_REPLAY_WINDOW - this.#inFlight.size,
47189
- new Set(this.#inFlight.keys())
47190
- );
47191
- let sent = 0;
47192
- for (const envelope2 of batch) {
47193
- const encoded = encodeDaemonToServiceMessage(
47194
- this.#connection.delivery === "reliable" ? envelope2 : {
47195
- kind: envelope2.kind,
47196
- payload: envelope2.payload,
47197
- sessionId: envelope2.sessionId
47198
- }
47199
- );
47200
- const byteLength = Buffer.byteLength(encoded, "utf8");
47201
- if (this.#inFlightBytes + byteLength > SESSION_EVENT_REPLAY_BYTE_LIMIT) {
47202
- return;
47203
- }
47204
- if (!this.#send(encoded)) {
47205
- this.#clearInFlight();
47206
- return;
47207
- }
47208
- if (this.#connection.delivery === "ephemeral") {
47209
- this.#queue.remove(envelope2.delivery.eventId, envelope2.sessionId);
47210
- sent += 1;
47211
- continue;
47212
- }
47213
- this.#inFlight.set(envelope2.delivery.eventId, { byteLength });
47214
- this.#inFlightBytes += byteLength;
47215
- sent += 1;
47216
- }
47217
- if (sent === 0) {
47218
- return;
47219
- }
47826
+ acpUpdate = (sessionId, update) => {
47827
+ this.#loadRequests(sessionId);
47828
+ const event = this.#append(sessionId, { kind: "acp.session.update", update });
47829
+ const executing = [...this.#requests.values()].find(
47830
+ (request) => request.sessionId === sessionId && request.kind === "executing"
47831
+ );
47832
+ if (executing !== void 0) {
47833
+ this.#requests.set(executing.commandId, { ...executing, events: [...executing.events, event] });
47220
47834
  }
47221
47835
  };
47222
- #removeInFlight = (eventId) => {
47223
- const inFlight = this.#inFlight.get(eventId);
47224
- if (inFlight === void 0) {
47225
- return;
47226
- }
47227
- this.#inFlight.delete(eventId);
47228
- this.#inFlightBytes -= inFlight.byteLength;
47836
+ completed = (sessionId, commandId, stopReason) => {
47837
+ this.#append(sessionId, { commandId, kind: "prompt.completed", stopReason });
47838
+ this.#requests.delete(commandId);
47229
47839
  };
47230
- #send = (encoded) => {
47231
- if (this.#connection.kind !== "connected" || this.#connection.socket.readyState !== WebSocket9.OPEN) {
47232
- return false;
47840
+ failed = (sessionId, commandId, code, message) => {
47841
+ this.#loadRequests(sessionId);
47842
+ const request = this.#requests.get(commandId);
47843
+ if (request?.kind === "executing" && request.commandId === commandId) {
47844
+ this.#append(sessionId, { attemptId: request.attemptId, code, commandId, kind: "prompt.failed", message });
47845
+ } else {
47846
+ this.#append(sessionId, { code, commandId, kind: "prompt.failed-before-start", message });
47233
47847
  }
47234
- try {
47235
- this.#connection.socket.send(encoded);
47236
- return true;
47237
- } catch {
47238
- return false;
47848
+ this.#requests.delete(commandId);
47849
+ };
47850
+ executingPromptRequest = (sessionId) => {
47851
+ this.#loadRequests(sessionId);
47852
+ const request = [...this.#requests.values()].find(
47853
+ (candidate) => candidate.sessionId === sessionId && candidate.kind === "executing"
47854
+ );
47855
+ if (request?.kind !== "executing") {
47856
+ return null;
47239
47857
  }
47858
+ const events = request.events.slice(-EXECUTING_PROMPT_EVENT_LIMIT);
47859
+ return {
47860
+ attemptId: request.attemptId,
47861
+ commandId: request.commandId,
47862
+ epoch: request.epoch,
47863
+ events,
47864
+ tailCursor: events.at(-1)?.eventId ?? "",
47865
+ truncated: events.length < request.events.length
47866
+ };
47240
47867
  };
47241
- };
47242
-
47243
- // src/relay-connection/timer.ts
47244
- var SystemDaemonTimer = class {
47245
- schedule = (callback, milliseconds) => {
47246
- const timeout = setTimeout(callback, milliseconds);
47247
- return { cancel: () => clearTimeout(timeout) };
47868
+ recovery = (sessionId, eventLimit, cursor) => {
47869
+ const events = this.#eventsFor(sessionId);
47870
+ if (events.length === 0) {
47871
+ return null;
47872
+ }
47873
+ const executingPromptRequest = this.executingPromptRequest(sessionId);
47874
+ const executingRequestState = [...this.#requests.values()].find(
47875
+ (request) => request.sessionId === sessionId && request.kind === "executing"
47876
+ );
47877
+ const firstExecutingPosition = executingRequestState?.events[0]?.position;
47878
+ const historyEvents = firstExecutingPosition === void 0 ? events : events.filter((event) => BigInt(event.position) < BigInt(firstExecutingPosition));
47879
+ const endEvent = cursor === null ? historyEvents.length : decodeLocalEventCursor(sessionId, cursor).endEvent;
47880
+ if (endEvent > historyEvents.length) {
47881
+ throw new AcpExecutionError("The native Session event cursor is invalid", {}, "invalid_cursor");
47882
+ }
47883
+ const startEvent = Math.max(0, endEvent - eventLimit);
47884
+ const pageEvents = historyEvents.slice(startEvent, endEvent);
47885
+ return {
47886
+ executingPromptRequest,
47887
+ history: {
47888
+ events: pageEvents,
47889
+ nextCursor: startEvent === 0 ? null : encodeLocalEventCursor({ endEvent: startEvent, sessionId }),
47890
+ tailCursor: pageEvents.at(-1)?.eventId ?? "",
47891
+ truncated: startEvent > 0,
47892
+ version: 2
47893
+ }
47894
+ };
47248
47895
  };
47249
47896
  };
47250
- var systemDaemonTimer = new SystemDaemonTimer();
47251
47897
 
47252
47898
  // src/run-daemon.ts
47253
47899
  var RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
@@ -47297,7 +47943,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
47297
47943
  {
47298
47944
  agentId: agent.id,
47299
47945
  kind: AGENT_INSTALL_REQUEST_KIND,
47300
- requestId: `automatic-integration-${randomUUID8()}`
47946
+ requestId: `automatic-integration-${randomUUID7()}`
47301
47947
  },
47302
47948
  signal
47303
47949
  );
@@ -47316,16 +47962,17 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
47316
47962
  stateDirectory
47317
47963
  });
47318
47964
  const sessionStore = new SqliteAcpSessionStore(
47319
- join18(stateDirectory, "sessions", `${createHash6("sha256").update(config2.channelId).digest("hex")}.sqlite`)
47965
+ join18(stateDirectory, "sessions", `${createHash7("sha256").update(config2.channelId).digest("hex")}.sqlite`)
47320
47966
  );
47321
47967
  const operations = new DaemonOperationState();
47322
- const publisher = new DaemonSessionEventPublisher(timer);
47968
+ const publisher = new DaemonSessionEventPublisher();
47969
+ const eventLogV2 = new DaemonSessionEventLogV2(publisher, sessionStore);
47323
47970
  const activeTurns = new DaemonTurnRegistry(operations);
47324
47971
  const recordSessionEvent = (sessionId, event) => {
47325
47972
  publisher.publish(sessionId, activeTurns.recordEvent(event));
47326
47973
  };
47327
47974
  const agentRuntime = new AgentRuntimeManager(
47328
- new DaemonAcpObserver(recordSessionEvent),
47975
+ new DaemonAcpObserver(recordSessionEvent, eventLogV2.acpUpdate),
47329
47976
  sessionStore,
47330
47977
  {
47331
47978
  read: async (options2, nativeSessionId, nativeTurn) => options2.agent.id === "codex" ? (await readCodexFullHistory(
@@ -47363,7 +48010,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
47363
48010
  options2.signal
47364
48011
  );
47365
48012
  return cwd === options2.cwd && additionalDirectories.length === options2.additionalDirectories.length && additionalDirectories.every(
47366
- (directory, index) => directory === options2.additionalDirectories[index]
48013
+ (directory, index2) => directory === options2.additionalDirectories[index2]
47367
48014
  );
47368
48015
  });
47369
48016
  }
@@ -47449,6 +48096,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
47449
48096
  nativeSessions,
47450
48097
  operations,
47451
48098
  publisher,
48099
+ eventLogV2,
47452
48100
  activeTurns,
47453
48101
  connectionEpoch,
47454
48102
  diagnostics,
@@ -47601,7 +48249,7 @@ function isRecord11(value) {
47601
48249
  return typeof value === "object" && value !== null && !Array.isArray(value);
47602
48250
  }
47603
48251
  function controlSocketPath(stateDirectory) {
47604
- const installationHash = createHash7("sha256").update(stateDirectory).digest("hex").slice(0, 32);
48252
+ const installationHash = createHash8("sha256").update(stateDirectory).digest("hex").slice(0, 32);
47605
48253
  return process.platform === "win32" ? `\\\\.\\pipe\\mobius-${installationHash}` : join19(tmpdir(), `mobius-${installationHash}.sock`);
47606
48254
  }
47607
48255
  function controlTokenPath(stateDirectory) {
@@ -47832,12 +48480,12 @@ var RuntimeSupervisor = class {
47832
48480
  }
47833
48481
  };
47834
48482
  function pairingIdentifier(arguments_) {
47835
- const indexes = arguments_.flatMap((argument, index2) => argument === "--pairing" ? [index2] : []);
48483
+ const indexes = arguments_.flatMap((argument, index3) => argument === "--pairing" ? [index3] : []);
47836
48484
  if (indexes.length !== 1) {
47837
48485
  return null;
47838
48486
  }
47839
- const index = indexes[0];
47840
- return index === void 0 ? null : arguments_[index + 1] ?? null;
48487
+ const index2 = indexes[0];
48488
+ return index2 === void 0 ? null : arguments_[index2 + 1] ?? null;
47841
48489
  }
47842
48490
  async function waitForReady(active, signal) {
47843
48491
  if (active.status === "online") {
@@ -48132,9 +48780,9 @@ function formatPairTable(pairs) {
48132
48780
  const headers = ["connection_id", "app_id", "runtime_id", "workspace", "status"];
48133
48781
  const rows = pairs.map((pair) => [pair.connectionId, pair.appId, pair.runtimeId, pair.workspace, pair.status]);
48134
48782
  const widths = headers.map(
48135
- (header, index) => Math.max(header.length, ...rows.map((row) => row[index]?.length ?? 0))
48783
+ (header, index2) => Math.max(header.length, ...rows.map((row) => row[index2]?.length ?? 0))
48136
48784
  );
48137
- const line = (row) => `| ${row.map((value, index) => value.padEnd(widths[index] ?? value.length)).join(" | ")} |`;
48785
+ const line = (row) => `| ${row.map((value, index2) => value.padEnd(widths[index2] ?? value.length)).join(" | ")} |`;
48138
48786
  const divider = `|-${widths.map((width) => "-".repeat(width)).join("-|-")}-|`;
48139
48787
  return `${line(headers)}
48140
48788
  ${divider}