@moxt-ai/mobius 0.0.176 → 0.0.177

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 (55) hide show
  1. package/dist/acp/agent-runtime-manager.d.ts +2 -1
  2. package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
  3. package/dist/acp/agent-runtime-manager.js +11 -1
  4. package/dist/acp/agent-runtime-manager.js.map +1 -1
  5. package/dist/acp/agent-session.d.ts +3 -1
  6. package/dist/acp/agent-session.d.ts.map +1 -1
  7. package/dist/acp/agent-session.js +48 -20
  8. package/dist/acp/agent-session.js.map +1 -1
  9. package/dist/acp/codex/agent.d.ts.map +1 -1
  10. package/dist/acp/codex/agent.js +0 -12
  11. package/dist/acp/codex/agent.js.map +1 -1
  12. package/dist/acp/session-contracts.d.ts +3 -1
  13. package/dist/acp/session-contracts.d.ts.map +1 -1
  14. package/dist/acp/session-contracts.js.map +1 -1
  15. package/dist/cli.js +197 -610
  16. package/dist/cli.js.map +4 -4
  17. package/dist/daemon-command-handler.d.ts +1 -3
  18. package/dist/daemon-command-handler.d.ts.map +1 -1
  19. package/dist/daemon-command-handler.js +11 -9
  20. package/dist/daemon-command-handler.js.map +1 -1
  21. package/dist/daemon-command-results.d.ts +2 -3
  22. package/dist/daemon-command-results.d.ts.map +1 -1
  23. package/dist/daemon-command-results.js +4 -12
  24. package/dist/daemon-command-results.js.map +1 -1
  25. package/dist/daemon-prompt-executor.d.ts +2 -6
  26. package/dist/daemon-prompt-executor.d.ts.map +1 -1
  27. package/dist/daemon-prompt-executor.js +20 -73
  28. package/dist/daemon-prompt-executor.js.map +1 -1
  29. package/dist/daemon-session-commands.d.ts +2 -3
  30. package/dist/daemon-session-commands.d.ts.map +1 -1
  31. package/dist/daemon-session-commands.js +3 -15
  32. package/dist/daemon-session-commands.js.map +1 -1
  33. package/dist/index.js +196 -609
  34. package/dist/index.js.map +4 -4
  35. package/dist/relay-connection/run-relay-connection.d.ts.map +1 -1
  36. package/dist/relay-connection/run-relay-connection.js +0 -1
  37. package/dist/relay-connection/run-relay-connection.js.map +1 -1
  38. package/dist/relay-connection/session-event-publisher.d.ts +2 -3
  39. package/dist/relay-connection/session-event-publisher.d.ts.map +1 -1
  40. package/dist/relay-connection/session-event-publisher.js +8 -46
  41. package/dist/relay-connection/session-event-publisher.js.map +1 -1
  42. package/dist/run-daemon.d.ts.map +1 -1
  43. package/dist/run-daemon.js +4 -5
  44. package/dist/run-daemon.js.map +1 -1
  45. package/dist/runtime.js +196 -609
  46. package/dist/runtime.js.map +4 -4
  47. package/dist/session-event-log-v2.d.ts +7 -5
  48. package/dist/session-event-log-v2.d.ts.map +1 -1
  49. package/dist/session-event-log-v2.js +83 -12
  50. package/dist/session-event-log-v2.js.map +1 -1
  51. package/package.json +1 -1
  52. package/dist/relay-connection/coalescing-agent-event-publisher.d.ts +0 -32
  53. package/dist/relay-connection/coalescing-agent-event-publisher.d.ts.map +0 -1
  54. package/dist/relay-connection/coalescing-agent-event-publisher.js +0 -116
  55. package/dist/relay-connection/coalescing-agent-event-publisher.js.map +0 -1
package/dist/cli.js CHANGED
@@ -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.176",
3384
+ version: "0.0.177",
3385
3385
  description: "Mobius CLI for pairing and running local AI agent services.",
3386
3386
  type: "module",
3387
3387
  bin: {
@@ -25913,14 +25913,6 @@ var CodexAcpAgent = class {
25913
25913
  if (isCompactPrompt(context.params.prompt)) {
25914
25914
  return await this.#compact(context.signal);
25915
25915
  }
25916
- const messageId = crypto.randomUUID();
25917
- for (const content of context.params.prompt) {
25918
- await this.#emit({
25919
- content,
25920
- messageId,
25921
- sessionUpdate: "user_message_chunk"
25922
- });
25923
- }
25924
25916
  return await this.#runTurn(promptInput(context.params.prompt), context.signal);
25925
25917
  }).onRequest(
25926
25918
  "_session/steering",
@@ -26406,10 +26398,6 @@ var CodexAcpAgent = class {
26406
26398
  if (steering.length === 0) {
26407
26399
  throw new AcpExecutionError("Codex received an empty steering request", {}, "invalid_request");
26408
26400
  }
26409
- const messageId = crypto.randomUUID();
26410
- for (const block of steering) {
26411
- await this.#emit({ content: block.content, messageId, sessionUpdate: "user_message_chunk" });
26412
- }
26413
26401
  const response = turnSteerResponseSchema.parse(
26414
26402
  await this.#appServer.request(
26415
26403
  "turn/steer",
@@ -28970,8 +28958,6 @@ function decodeValue(value, schema) {
28970
28958
  }
28971
28959
  return result.data;
28972
28960
  }
28973
- var decodeAgentDisplayContentValue = (value) => decodeValue(value, displayContentSchema);
28974
- var decodeRecordedAgentContentValue = (value) => decodeValue(value, recordedDisplayContentSchema);
28975
28961
  var decodePromptImagesValue = (value) => decodeValue(value, external_exports.array(promptImageSchema).max(8).readonly());
28976
28962
  var decodePromptResourcesValue = (value) => decodeValue(value, external_exports.array(promptResourceSchema).max(16).readonly());
28977
28963
  var decodeSessionConfigurationSelections = (value) => decodeValue(value, sessionConfigurationSelectionsSchema);
@@ -29013,20 +28999,13 @@ var encodeSessionReadyEvent = (message) => encode3(message, sessionReadyEventSch
29013
28999
  var decodeSessionConfigureCommand = (encoded) => decode3(encoded, sessionConfigureCommandSchema);
29014
29000
  var encodeSessionConfigureCommand = (message) => encode3(message, sessionConfigureCommandSchema);
29015
29001
  var decodeSessionConfigUpdatedEvent = (encoded) => decode3(encoded, sessionConfigUpdatedEventSchema);
29016
- var decodeSessionUsageUpdatedEvent = (encoded) => decode3(encoded, sessionUsageUpdatedEventSchema);
29017
- var decodeSessionCommandsUpdatedEvent = (encoded) => decode3(encoded, sessionCommandsUpdatedEventSchema);
29018
- var decodeSessionInfoUpdatedEvent = (encoded) => decode3(encoded, sessionInfoUpdatedEventSchema);
29019
- var decodeSessionPermissionRequestedEvent = (encoded) => decode3(encoded, sessionPermissionRequestedEventSchema);
29002
+ var encodeSessionConfigUpdatedEvent = (message) => encode3(message, sessionConfigUpdatedEventSchema);
29020
29003
  var decodeSessionPermissionRespondCommand = (encoded) => decode3(encoded, sessionPermissionRespondCommandSchema);
29021
29004
  var encodeSessionPermissionRespondCommand = (message) => encode3(message, sessionPermissionRespondCommandSchema);
29022
- var decodeSessionPermissionResolvedEvent = (encoded) => decode3(encoded, sessionPermissionResolvedEventSchema);
29023
- var decodeSessionElicitationRequestedEvent = (encoded) => decode3(encoded, sessionElicitationRequestedEventSchema);
29024
29005
  var decodeSessionElicitationRespondCommand = (encoded) => decode3(encoded, sessionElicitationRespondCommandSchema);
29025
29006
  var encodeSessionElicitationRespondCommand = (message) => encode3(message, sessionElicitationRespondCommandSchema);
29026
- var decodeSessionElicitationResolvedEvent = (encoded) => decode3(encoded, sessionElicitationResolvedEventSchema);
29027
29007
  var decodeSessionOperationFailedEvent = (encoded) => decode3(encoded, sessionOperationFailedEventSchema);
29028
29008
  var encodeSessionOperationFailedEvent = (message) => encode3(message, sessionOperationFailedEventSchema);
29029
- var decodeAgentContentEvent = (encoded) => decode3(encoded, agentContentEventSchema);
29030
29009
  var decodeAgentInstallRequestCommand = (encoded) => decode3(encoded, agentInstallRequestCommandSchema);
29031
29010
  var encodeAgentInstallRequestCommand = (message) => encode3(message, agentInstallRequestCommandSchema);
29032
29011
  var decodeAgentInstallCancelCommand = (encoded) => decode3(encoded, agentInstallCancelCommandSchema);
@@ -29052,7 +29031,6 @@ var RUNTIME_HEARTBEAT_KIND = "runtime.heartbeat";
29052
29031
  var RUNTIME_HEARTBEAT_ACK_KIND = "runtime.heartbeat.ack";
29053
29032
  var RUNTIME_PING_KIND = "runtime.ping";
29054
29033
  var RUNTIME_PONG_KIND = "runtime.pong";
29055
- var SESSION_STARTED_KIND = "session.started";
29056
29034
  var SESSION_QUEUED_KIND = "session.queued";
29057
29035
  var AGENT_MESSAGE_DELTA_KIND = "agent.message.delta";
29058
29036
  var AGENT_ACTIVITY_KIND = "agent.activity";
@@ -29062,8 +29040,6 @@ var AGENT_ACTIVITY_RECORDED_FIELD_LIMIT = 4e6;
29062
29040
  var AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT = 6e6;
29063
29041
  var AGENT_ACTIVITY_LOCATION_LIMIT = 12;
29064
29042
  var AGENT_ACTIVITY_LOCATION_LENGTH_LIMIT = 1024;
29065
- var SESSION_COMPLETED_KIND = "session.completed";
29066
- var SESSION_FAILED_KIND = "session.failed";
29067
29043
  var SessionPromptDisposition = Object.freeze({
29068
29044
  Queue: "queue",
29069
29045
  Reject: "reject",
@@ -29074,23 +29050,6 @@ var SessionPromptDisposition = Object.freeze({
29074
29050
  var DIRECTORY_IDENTIFIER_PATTERN2 = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/;
29075
29051
  var MAX_PROMPT_LENGTH = 1e4;
29076
29052
  var MAX_PROMPT_ATTACHMENT_LENGTH = 6e6;
29077
- var MAX_EVENT_TEXT_LENGTH = 1e5;
29078
- var ACTIVITY_TYPES = /* @__PURE__ */ new Set(["notice", "plan", "progress", "reasoning", "tool"]);
29079
- var NARRATION_ACTIVITY_TYPES = /* @__PURE__ */ new Set(["progress", "reasoning"]);
29080
- var ACTIVITY_STATUSES = /* @__PURE__ */ new Set(["pending", "running", "completed", "failed"]);
29081
- var TOOL_KINDS = /* @__PURE__ */ new Set([
29082
- "",
29083
- "delete",
29084
- "edit",
29085
- "execute",
29086
- "fetch",
29087
- "move",
29088
- "other",
29089
- "read",
29090
- "search",
29091
- "switch_mode",
29092
- "think"
29093
- ]);
29094
29053
  var ProtocolMessageError = class extends Error {
29095
29054
  code = "invalid_protocol_message";
29096
29055
  constructor(message, options = {}) {
@@ -29140,13 +29099,6 @@ function readText(value, key, maximumLength) {
29140
29099
  }
29141
29100
  return field;
29142
29101
  }
29143
- function readAllowedString(value, key, allowedValues) {
29144
- const field = readText(value, key, 64);
29145
- if (!allowedValues.has(field)) {
29146
- throw new ProtocolMessageError(`Invalid value field: ${key}`);
29147
- }
29148
- return field;
29149
- }
29150
29102
  function readPromptDisposition(value) {
29151
29103
  const field = value["disposition"];
29152
29104
  if (field === void 0 || field === SessionPromptDisposition.Reject) {
@@ -29160,32 +29112,6 @@ function readPromptDisposition(value) {
29160
29112
  }
29161
29113
  throw new ProtocolMessageError("Invalid value field: disposition");
29162
29114
  }
29163
- function readSequence(value, key) {
29164
- const field = value[key];
29165
- if (typeof field !== "number" || !Number.isSafeInteger(field) || field < 0) {
29166
- throw new ProtocolMessageError(`Invalid integer field: ${key}`);
29167
- }
29168
- return field;
29169
- }
29170
- function readLocations(value) {
29171
- const field = value["locations"];
29172
- if (!Array.isArray(field) || field.length > AGENT_ACTIVITY_LOCATION_LIMIT) {
29173
- throw new ProtocolMessageError("Invalid locations field");
29174
- }
29175
- const locations = [];
29176
- const unique = /* @__PURE__ */ new Set();
29177
- for (const location of field) {
29178
- if (typeof location !== "string" || location.length === 0 || location.length > AGENT_ACTIVITY_LOCATION_LENGTH_LIMIT) {
29179
- throw new ProtocolMessageError("Invalid activity location");
29180
- }
29181
- if (unique.has(location)) {
29182
- throw new ProtocolMessageError("Duplicate activity location");
29183
- }
29184
- unique.add(location);
29185
- locations.push(location);
29186
- }
29187
- return locations;
29188
- }
29189
29115
  function readDirectoryIdentifiers(value, key, maximumCount) {
29190
29116
  const field = value[key];
29191
29117
  if (!Array.isArray(field) || field.length > maximumCount) {
@@ -29202,54 +29128,6 @@ function readDirectoryIdentifiers(value, key, maximumCount) {
29202
29128
  }
29203
29129
  return identifiers;
29204
29130
  }
29205
- function readActivityContent(value) {
29206
- const field = value["content"];
29207
- if (!Array.isArray(field) || field.length > 100) {
29208
- throw new ProtocolMessageError("Invalid activity content field");
29209
- }
29210
- return field.map((entry) => decodeAgentDisplayContentValue(entry));
29211
- }
29212
- function readActivityDetail(value) {
29213
- const field = value["detail"];
29214
- if (!isRecord5(field)) {
29215
- throw new ProtocolMessageError("Invalid activity detail field");
29216
- }
29217
- const kind = readString2(field, "kind", 32);
29218
- if (kind === "available") {
29219
- return {
29220
- artifactId: readIdentifier(field, "artifactId"),
29221
- kind
29222
- };
29223
- }
29224
- if (kind === "unrecorded") {
29225
- return { kind };
29226
- }
29227
- if (kind === "truncated") {
29228
- const capturedBytes = readSequence(field, "capturedBytes");
29229
- const originalBytes = readSequence(field, "originalBytes");
29230
- if (capturedBytes > originalBytes) {
29231
- throw new ProtocolMessageError("Invalid truncated activity detail size");
29232
- }
29233
- return { capturedBytes, kind, originalBytes };
29234
- }
29235
- if (kind === "recorded") {
29236
- const contentValue = field["content"];
29237
- if (!Array.isArray(contentValue) || contentValue.length > 100) {
29238
- throw new ProtocolMessageError("Invalid recorded activity content");
29239
- }
29240
- const detail = {
29241
- content: contentValue.map((entry) => decodeRecordedAgentContentValue(entry)),
29242
- input: readText(field, "input", AGENT_ACTIVITY_RECORDED_FIELD_LIMIT),
29243
- kind,
29244
- output: readText(field, "output", AGENT_ACTIVITY_RECORDED_FIELD_LIMIT)
29245
- };
29246
- if (JSON.stringify(detail).length > AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT) {
29247
- throw new ProtocolMessageError("Recorded activity detail is too large");
29248
- }
29249
- return detail;
29250
- }
29251
- throw new ProtocolMessageError("Invalid activity detail availability");
29252
- }
29253
29131
  function readIdentifier(value, key) {
29254
29132
  try {
29255
29133
  return decodeIdentifier(value[key]);
@@ -29374,82 +29252,6 @@ function decodeRuntimePongEvent(encoded) {
29374
29252
  assertKind(value, RUNTIME_PONG_KIND);
29375
29253
  return { kind: RUNTIME_PONG_KIND, requestId: readIdentifier(value, "requestId") };
29376
29254
  }
29377
- function decodeSessionStartedEvent(encoded) {
29378
- const value = parseJson2(encoded);
29379
- assertKind(value, SESSION_STARTED_KIND);
29380
- const sequence = readSequence(value, "sequence");
29381
- if (sequence !== 0) {
29382
- throw new ProtocolMessageError("Invalid live start sequence");
29383
- }
29384
- return {
29385
- commandId: readIdentifier(value, "commandId"),
29386
- epoch: readIdentifier(value, "epoch"),
29387
- kind: SESSION_STARTED_KIND,
29388
- attemptId: readIdentifier(value, "attemptId"),
29389
- prompt: readText(value, "prompt", MAX_PROMPT_LENGTH),
29390
- sequence,
29391
- sessionId: readIdentifier(value, "sessionId")
29392
- };
29393
- }
29394
- function decodeAgentMessageDeltaEvent(encoded) {
29395
- const value = parseJson2(encoded);
29396
- assertKind(value, AGENT_MESSAGE_DELTA_KIND);
29397
- const sequence = readSequence(value, "sequence");
29398
- if (sequence === 0) {
29399
- throw new ProtocolMessageError("Invalid live sequence");
29400
- }
29401
- return {
29402
- commandId: readIdentifier(value, "commandId"),
29403
- epoch: readIdentifier(value, "epoch"),
29404
- kind: AGENT_MESSAGE_DELTA_KIND,
29405
- messageId: value["messageId"] === void 0 ? "" : readText(value, "messageId", 255),
29406
- sequence,
29407
- sessionId: readIdentifier(value, "sessionId"),
29408
- text: readString2(value, "text", MAX_EVENT_TEXT_LENGTH)
29409
- };
29410
- }
29411
- function decodeAgentActivityEvent(encoded) {
29412
- const value = parseJson2(encoded);
29413
- assertKind(value, AGENT_ACTIVITY_KIND);
29414
- return {
29415
- activityId: readIdentifier(value, "activityId"),
29416
- activityType: readAllowedString(value, "activityType", ACTIVITY_TYPES),
29417
- commandId: readIdentifier(value, "commandId"),
29418
- content: readActivityContent(value),
29419
- detail: readActivityDetail(value),
29420
- input: readText(value, "input", AGENT_ACTIVITY_DETAIL_LIMIT),
29421
- kind: AGENT_ACTIVITY_KIND,
29422
- locations: readLocations(value),
29423
- name: readText(value, "name", 128),
29424
- output: readText(value, "output", AGENT_ACTIVITY_DETAIL_LIMIT),
29425
- sequence: readSequence(value, "sequence"),
29426
- sessionId: readIdentifier(value, "sessionId"),
29427
- status: readAllowedString(value, "status", ACTIVITY_STATUSES),
29428
- title: readString2(value, "title", 500),
29429
- toolKind: readAllowedString(value, "toolKind", TOOL_KINDS)
29430
- };
29431
- }
29432
- function decodeSessionCompletedEvent(encoded) {
29433
- const value = parseJson2(encoded);
29434
- assertKind(value, SESSION_COMPLETED_KIND);
29435
- return {
29436
- commandId: readIdentifier(value, "commandId"),
29437
- kind: SESSION_COMPLETED_KIND,
29438
- sessionId: readIdentifier(value, "sessionId"),
29439
- stopReason: readString2(value, "stopReason", 64)
29440
- };
29441
- }
29442
- function decodeSessionFailedEvent(encoded) {
29443
- const value = parseJson2(encoded);
29444
- assertKind(value, SESSION_FAILED_KIND);
29445
- return {
29446
- code: readIdentifier(value, "code"),
29447
- commandId: readIdentifier(value, "commandId"),
29448
- kind: SESSION_FAILED_KIND,
29449
- message: readString2(value, "message", 500),
29450
- sessionId: readIdentifier(value, "sessionId")
29451
- };
29452
- }
29453
29255
  function encodeSessionPromptCommand(message) {
29454
29256
  return JSON.stringify(decodeSessionPromptCommand(JSON.stringify(message)));
29455
29257
  }
@@ -29477,19 +29279,6 @@ function encodeRuntimePingCommand(message) {
29477
29279
  function encodeRuntimePongEvent(message) {
29478
29280
  return JSON.stringify(decodeRuntimePongEvent(JSON.stringify(message)));
29479
29281
  }
29480
- function decodeAgentActivityNarrationEvent(encoded) {
29481
- const value = parseJson2(encoded);
29482
- assertKind(value, AGENT_ACTIVITY_NARRATION_KIND);
29483
- return {
29484
- activityId: readIdentifier(value, "activityId"),
29485
- activityType: readAllowedString(value, "activityType", NARRATION_ACTIVITY_TYPES),
29486
- commandId: readIdentifier(value, "commandId"),
29487
- kind: AGENT_ACTIVITY_NARRATION_KIND,
29488
- sequence: readSequence(value, "sequence"),
29489
- sessionId: readIdentifier(value, "sessionId"),
29490
- text: readText(value, "text", MAX_EVENT_TEXT_LENGTH)
29491
- };
29492
- }
29493
29282
 
29494
29283
  // ../protocol/src/session-history.ts
29495
29284
  var SESSION_HISTORY_CHARACTER_LIMIT = 256e3;
@@ -30058,6 +29847,11 @@ var acpSessionUpdateV2Schema = external_exports.discriminatedUnion("sessionUpdat
30058
29847
  }).readonly()
30059
29848
  ]);
30060
29849
  var lifecycleBase = { commandId: identifierStringSchema };
29850
+ var promptExecutionContextV2Schema = external_exports.object({
29851
+ agentId: identifierStringSchema,
29852
+ directoryId: shortString,
29853
+ additionalDirectoryIds: external_exports.array(identifierStringSchema).max(16).readonly()
29854
+ }).readonly();
30061
29855
  var lifecycleMetadataV2Schema = external_exports.discriminatedUnion("kind", [
30062
29856
  external_exports.object({ kind: external_exports.literal("session.queue.changed") }).readonly(),
30063
29857
  external_exports.object({ event: sessionPermissionRequestedEventSchema, kind: external_exports.literal("session.permission.requested") }).readonly(),
@@ -30067,7 +29861,8 @@ var lifecycleMetadataV2Schema = external_exports.discriminatedUnion("kind", [
30067
29861
  external_exports.object({
30068
29862
  ...lifecycleBase,
30069
29863
  content: external_exports.array(contentBlockV2Schema).min(1).max(100).readonly(),
30070
- kind: external_exports.literal("prompt.requested")
29864
+ kind: external_exports.literal("prompt.requested"),
29865
+ context: promptExecutionContextV2Schema.optional()
30071
29866
  }).readonly(),
30072
29867
  external_exports.object({ ...lifecycleBase, attemptId: identifierStringSchema, epoch: identifierStringSchema, kind: external_exports.literal("prompt.started") }).readonly(),
30073
29868
  external_exports.object({ ...lifecycleBase, kind: external_exports.literal("prompt.completed"), stopReason: shortString }).readonly(),
@@ -30207,94 +30002,6 @@ var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelop
30207
30002
  var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
30208
30003
  var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
30209
30004
 
30210
- // ../protocol/src/session-events.ts
30211
- var SESSION_EVENT_KIND = "session.event";
30212
- var SESSION_FORKED_KIND = "session.forked";
30213
- var MAX_RECORDED_EVENT_LENGTH = 8 * 1024 * 1024;
30214
- var sessionEventEnvelopeSchema = external_exports.object({
30215
- kind: external_exports.literal(SESSION_EVENT_KIND),
30216
- payload: external_exports.string().min(2).max(MAX_RECORDED_EVENT_LENGTH),
30217
- sessionId: identifierStringSchema
30218
- }).readonly();
30219
- var SESSION_QUEUE_CHANGED_KIND = "session.queue.changed";
30220
- var sessionQueueChangedSchema = external_exports.object({ kind: external_exports.literal(SESSION_QUEUE_CHANGED_KIND), sessionId: identifierStringSchema }).readonly();
30221
- var sessionForkedSchema = external_exports.object({
30222
- kind: external_exports.literal(SESSION_FORKED_KIND),
30223
- sessionId: identifierStringSchema,
30224
- sourceSessionId: identifierStringSchema,
30225
- throughCommandId: identifierStringSchema
30226
- }).readonly();
30227
- function decode6(encoded, schema) {
30228
- let value;
30229
- try {
30230
- value = JSON.parse(encoded);
30231
- } catch (cause) {
30232
- throw new ProtocolMessageError("Message is not valid JSON", { cause });
30233
- }
30234
- const decoded = schema.safeParse(value);
30235
- if (!decoded.success) {
30236
- throw new ProtocolMessageError("Message does not match its schema", {
30237
- cause: decoded.error
30238
- });
30239
- }
30240
- return decoded.data;
30241
- }
30242
- var encode5 = (message, schema) => {
30243
- const decoded = schema.safeParse(message);
30244
- if (!decoded.success) {
30245
- throw new ProtocolMessageError("Message does not match its schema", {
30246
- cause: decoded.error
30247
- });
30248
- }
30249
- return JSON.stringify(decoded.data);
30250
- };
30251
- var decodeSessionEventEnvelope = (encoded) => decode6(encoded, sessionEventEnvelopeSchema);
30252
- var encodeSessionEventEnvelope = (message) => encode5(message, sessionEventEnvelopeSchema);
30253
- function decodeRecordedSessionEvent(encoded) {
30254
- const kind = decodeMessageKind(encoded);
30255
- switch (kind) {
30256
- case SESSION_QUEUE_CHANGED_KIND:
30257
- return decode6(encoded, sessionQueueChangedSchema);
30258
- case SESSION_FORKED_KIND:
30259
- return decode6(encoded, sessionForkedSchema);
30260
- case AGENT_ACTIVITY_KIND:
30261
- return decodeAgentActivityEvent(encoded);
30262
- case AGENT_ACTIVITY_NARRATION_KIND:
30263
- return decodeAgentActivityNarrationEvent(encoded);
30264
- case AGENT_CONTENT_KIND:
30265
- return decodeAgentContentEvent(encoded);
30266
- case AGENT_MESSAGE_DELTA_KIND:
30267
- return decodeAgentMessageDeltaEvent(encoded);
30268
- case SESSION_COMMANDS_UPDATED_KIND:
30269
- return decodeSessionCommandsUpdatedEvent(encoded);
30270
- case SESSION_COMPLETED_KIND:
30271
- return decodeSessionCompletedEvent(encoded);
30272
- case SESSION_CONFIG_UPDATED_KIND:
30273
- return decodeSessionConfigUpdatedEvent(encoded);
30274
- case SESSION_ELICITATION_REQUESTED_KIND:
30275
- return decodeSessionElicitationRequestedEvent(encoded);
30276
- case SESSION_ELICITATION_RESOLVED_KIND:
30277
- return decodeSessionElicitationResolvedEvent(encoded);
30278
- case SESSION_FAILED_KIND:
30279
- return decodeSessionFailedEvent(encoded);
30280
- case SESSION_INFO_UPDATED_KIND:
30281
- return decodeSessionInfoUpdatedEvent(encoded);
30282
- case SESSION_PERMISSION_REQUESTED_KIND:
30283
- return decodeSessionPermissionRequestedEvent(encoded);
30284
- case SESSION_PERMISSION_RESOLVED_KIND:
30285
- return decodeSessionPermissionResolvedEvent(encoded);
30286
- case SESSION_READY_KIND:
30287
- return decodeSessionReadyEvent(encoded);
30288
- case SESSION_STARTED_KIND:
30289
- return decodeSessionStartedEvent(encoded);
30290
- case SESSION_USAGE_UPDATED_KIND:
30291
- return decodeSessionUsageUpdatedEvent(encoded);
30292
- default:
30293
- throw new UnsupportedProtocolMessageKindError("daemon-to-service", kind);
30294
- }
30295
- }
30296
- var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSessionEvent(JSON.stringify(event)));
30297
-
30298
30005
  // ../protocol/src/session-live-history.ts
30299
30006
  var SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
30300
30007
  var SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
@@ -30316,7 +30023,7 @@ var sessionLiveHistoryV2PageLoadedSchema = external_exports.object({
30316
30023
  requestId: identifierStringSchema,
30317
30024
  sessionId: identifierStringSchema
30318
30025
  }).readonly();
30319
- function decode7(schema, encoded) {
30026
+ function decode6(schema, encoded) {
30320
30027
  try {
30321
30028
  const value = JSON.parse(encoded);
30322
30029
  return schema.parse(value);
@@ -30324,8 +30031,8 @@ function decode7(schema, encoded) {
30324
30031
  throw new ProtocolMessageError("Invalid live Session history message", { cause });
30325
30032
  }
30326
30033
  }
30327
- var decodeSessionLiveHistoryV2PageLoad = (encoded) => decode7(sessionLiveHistoryV2PageLoadSchema, encoded);
30328
- var decodeSessionLiveHistoryV2PageLoaded = (encoded) => decode7(sessionLiveHistoryV2PageLoadedSchema, encoded);
30034
+ var decodeSessionLiveHistoryV2PageLoad = (encoded) => decode6(sessionLiveHistoryV2PageLoadSchema, encoded);
30035
+ var decodeSessionLiveHistoryV2PageLoaded = (encoded) => decode6(sessionLiveHistoryV2PageLoadedSchema, encoded);
30329
30036
  var encodeSessionLiveHistoryV2PageLoad = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadSchema.parse(value));
30330
30037
  var encodeSessionLiveHistoryV2PageLoaded = (value) => JSON.stringify(sessionLiveHistoryV2PageLoadedSchema.parse(value));
30331
30038
 
@@ -30439,6 +30146,11 @@ function decodeServiceToDaemonMessage(encoded) {
30439
30146
  return signature.decoder(encoded);
30440
30147
  }
30441
30148
  var daemonToServiceSignatures = {
30149
+ [SESSION_CONFIG_UPDATED_KIND]: defineMessageSignature(
30150
+ SESSION_CONFIG_UPDATED_KIND,
30151
+ encodeSessionConfigUpdatedEvent,
30152
+ decodeSessionConfigUpdatedEvent
30153
+ ),
30442
30154
  [AGENT_INSTALL_CANCELLED_KIND]: defineMessageSignature(
30443
30155
  AGENT_INSTALL_CANCELLED_KIND,
30444
30156
  encodeAgentInstallCancelledEvent,
@@ -30509,11 +30221,6 @@ var daemonToServiceSignatures = {
30509
30221
  decodeRuntimeHeartbeatEvent
30510
30222
  ),
30511
30223
  [RUNTIME_PONG_KIND]: defineMessageSignature(RUNTIME_PONG_KIND, encodeRuntimePongEvent, decodeRuntimePongEvent),
30512
- [SESSION_EVENT_KIND]: defineMessageSignature(
30513
- SESSION_EVENT_KIND,
30514
- encodeSessionEventEnvelope,
30515
- decodeSessionEventEnvelope
30516
- ),
30517
30224
  [SESSION_EVENT_V2_KIND]: defineMessageSignature(
30518
30225
  SESSION_EVENT_V2_KIND,
30519
30226
  encodeSessionEventEnvelopeV2,
@@ -39007,7 +38714,7 @@ var AgentSession = class _AgentSession {
39007
38714
  commandId: () => this.#turn.commandId,
39008
38715
  assertNativeSession: (sessionId) => this.assertNativeSession(sessionId),
39009
38716
  observer: getObserver,
39010
- recordSessionEventV2: this.#recordLifecycleEventV2
38717
+ recordSessionEventV2: this.recordLifecycleEventV2
39011
38718
  });
39012
38719
  this.#connection = new AgentConnection(agent, cwd, this);
39013
38720
  this.#contentExternalizer = contentExternalizer;
@@ -39590,7 +39297,14 @@ var AgentSession = class _AgentSession {
39590
39297
  if (this.#turn.running) {
39591
39298
  throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
39592
39299
  }
39593
- const completedHistory = this.#capabilities.loadSession ? await this.#completedHistory(options.signal, "ACP agent exited while loading history before a prompt") : null;
39300
+ if (!this.#capabilities.loadSession && this.#sessionLoad.kind === "not-requested") {
39301
+ this.#sessionLoad = {
39302
+ kind: "loaded",
39303
+ history: new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId),
39304
+ response: {}
39305
+ };
39306
+ }
39307
+ const completedHistory = this.#capabilities.loadSession ? await this.#completedHistory(options.signal, "ACP agent exited while loading history before a prompt") : this.#sessionLoad.kind === "loaded" ? this.#sessionLoad.history : null;
39594
39308
  const prompt = this.buildPrompt(options);
39595
39309
  if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
39596
39310
  this.#sessionTitle = truncate(options.prompt, 500);
@@ -39619,11 +39333,16 @@ var AgentSession = class _AgentSession {
39619
39333
  this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay(this.#store.eventsV2, this.#mobiusSessionId);
39620
39334
  const lifecycleV2 = options.lifecycleV2;
39621
39335
  if (lifecycleV2 !== void 0) {
39622
- await this.#recordLifecycleEventV2({
39623
- payload: { commandId: options.commandId, content: lifecycleV2.content, kind: "prompt.requested" },
39336
+ await this.recordLifecycleEventV2({
39337
+ payload: {
39338
+ commandId: options.commandId,
39339
+ content: lifecycleV2.content,
39340
+ kind: "prompt.requested",
39341
+ ...lifecycleV2.context === void 0 ? {} : { context: lifecycleV2.context }
39342
+ },
39624
39343
  type: "lifecycle-metadata"
39625
39344
  });
39626
- await this.#recordLifecycleEventV2({
39345
+ await this.recordLifecycleEventV2({
39627
39346
  payload: {
39628
39347
  attemptId: lifecycleV2.attemptId,
39629
39348
  commandId: options.commandId,
@@ -39686,7 +39405,7 @@ var AgentSession = class _AgentSession {
39686
39405
  )
39687
39406
  );
39688
39407
  if (lifecycleV2 !== void 0) {
39689
- await this.#recordLifecycleEventV2({
39408
+ await this.recordLifecycleEventV2({
39690
39409
  payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: result.stopReason },
39691
39410
  type: "lifecycle-metadata"
39692
39411
  });
@@ -39696,8 +39415,8 @@ var AgentSession = class _AgentSession {
39696
39415
  await running.activities.finish();
39697
39416
  const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
39698
39417
  if (lifecycleV2 !== void 0) {
39699
- await this.#recordLifecycleEventV2({
39700
- payload: {
39418
+ await this.recordLifecycleEventV2({
39419
+ payload: options.cancellationRequested?.() === true ? { commandId: options.commandId, kind: "prompt.completed", stopReason: "cancelled" } : {
39701
39420
  attemptId: lifecycleV2.attemptId,
39702
39421
  code: failure2.code,
39703
39422
  commandId: options.commandId,
@@ -39733,11 +39452,16 @@ var AgentSession = class _AgentSession {
39733
39452
  const prompt = this.buildPrompt(options);
39734
39453
  const lifecycleV2 = options.lifecycleV2;
39735
39454
  if (lifecycleV2 !== void 0) {
39736
- await this.#recordLifecycleEventV2({
39737
- payload: { commandId: options.commandId, content: lifecycleV2.content, kind: "prompt.requested" },
39455
+ await this.recordLifecycleEventV2({
39456
+ payload: {
39457
+ commandId: options.commandId,
39458
+ content: lifecycleV2.content,
39459
+ kind: "prompt.requested",
39460
+ ...lifecycleV2.context === void 0 ? {} : { context: lifecycleV2.context }
39461
+ },
39738
39462
  type: "lifecycle-metadata"
39739
39463
  });
39740
- await this.#recordLifecycleEventV2({
39464
+ await this.recordLifecycleEventV2({
39741
39465
  payload: {
39742
39466
  attemptId: lifecycleV2.attemptId,
39743
39467
  commandId: options.commandId,
@@ -39767,7 +39491,7 @@ var AgentSession = class _AgentSession {
39767
39491
  const outcome = response["outcome"];
39768
39492
  if (outcome === "injected" || outcome === "startedNewTurn") {
39769
39493
  if (lifecycleV2 !== void 0) {
39770
- await this.#recordLifecycleEventV2({
39494
+ await this.recordLifecycleEventV2({
39771
39495
  payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: "steered" },
39772
39496
  type: "lifecycle-metadata"
39773
39497
  });
@@ -39792,7 +39516,7 @@ var AgentSession = class _AgentSession {
39792
39516
  } catch (error62) {
39793
39517
  const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
39794
39518
  if (lifecycleV2 !== void 0) {
39795
- await this.#recordLifecycleEventV2({
39519
+ await this.recordLifecycleEventV2({
39796
39520
  payload: {
39797
39521
  attemptId: lifecycleV2.attemptId,
39798
39522
  code: failure2.code,
@@ -39825,7 +39549,14 @@ var AgentSession = class _AgentSession {
39825
39549
  onElicitation = (request, signal) => this.#interactions.onElicitation(request, signal);
39826
39550
  onElicitationComplete = (notification) => this.#interactions.onElicitationComplete(notification);
39827
39551
  onUpdate = (notification) => this.#updates.receive(notification);
39828
- #recordLifecycleEventV2 = async (event) => {
39552
+ recordControlEventV2 = async (event) => {
39553
+ if (this.#sessionLoad.kind !== "loaded") {
39554
+ return false;
39555
+ }
39556
+ await this.recordLifecycleEventV2(event);
39557
+ return true;
39558
+ };
39559
+ recordLifecycleEventV2 = async (event) => {
39829
39560
  if (event.type !== "lifecycle-metadata" || this.#sessionLoad.kind !== "loaded") {
39830
39561
  return;
39831
39562
  }
@@ -40888,6 +40619,13 @@ var AgentRuntimeManager = class {
40888
40619
  this.#contentExternalizer = contentExternalizer;
40889
40620
  this.#queryProcesses = new AgentQueryProcesses(this.#processes, contentExternalizer);
40890
40621
  }
40622
+ recordLifecycleEventV2 = async (sessionId, event) => {
40623
+ const runtime = this.#executionProcesses.get(sessionId);
40624
+ if (runtime === void 0) {
40625
+ return false;
40626
+ }
40627
+ return await runtime.recordControlEventV2(event);
40628
+ };
40891
40629
  setObserver = (observer) => {
40892
40630
  this.#observer = observer;
40893
40631
  };
@@ -41217,7 +40955,10 @@ var AgentRuntimeManager = class {
41217
40955
  return { stopReason: "cancelled" };
41218
40956
  }
41219
40957
  try {
41220
- const result = await runtime.prompt(options2);
40958
+ const result = await runtime.prompt({
40959
+ ...options2,
40960
+ cancellationRequested: () => this.#executions.cancellation(options2.sessionId) !== void 0
40961
+ });
41221
40962
  return this.#executions.cancellation(options2.sessionId) !== void 0 ? { stopReason: "cancelled" } : result;
41222
40963
  } catch (error62) {
41223
40964
  if (this.#executions.cancellation(options2.sessionId) !== void 0) {
@@ -42515,16 +42256,7 @@ function send(socket, message) {
42515
42256
  }
42516
42257
  socket.send(encodeDaemonToServiceMessage(message));
42517
42258
  }
42518
- function reportFailure(publisher, command, code, message) {
42519
- publisher.publish(command.sessionId, {
42520
- code,
42521
- commandId: command.commandId,
42522
- kind: SESSION_FAILED_KIND,
42523
- message,
42524
- sessionId: command.sessionId
42525
- });
42526
- }
42527
- function settleAbandonedTurn(publisher, operations, audit, cancellation) {
42259
+ async function settleAbandonedTurn(eventLog, operations, audit, cancellation) {
42528
42260
  const attemptId = operations.findUnsettledAttemptId(cancellation.commandId, cancellation.sessionId);
42529
42261
  if (attemptId === null) {
42530
42262
  console.warn("Mobius daemon ignored cancellation for an inactive turn");
@@ -42535,13 +42267,14 @@ function settleAbandonedTurn(publisher, operations, audit, cancellation) {
42535
42267
  event: "session_abandoned_turn_settled",
42536
42268
  sessionId: cancellation.sessionId
42537
42269
  });
42538
- reportFailure(
42539
- publisher,
42540
- cancellation,
42270
+ await eventLog.failed(
42271
+ cancellation.sessionId,
42272
+ cancellation.commandId,
42541
42273
  "agent_execution_abandoned",
42542
42274
  "The local Agent execution was abandoned before it completed"
42543
42275
  );
42544
42276
  operations.transitionExecution(cancellation.commandId, "failed");
42277
+ eventLog.publishTerminal(cancellation.sessionId, cancellation.commandId);
42545
42278
  }
42546
42279
  function operationErrorCode(error62) {
42547
42280
  if (error62 instanceof AcpExecutionError || error62 instanceof LocalAuthorizationError || error62 instanceof LocalAgentCatalogError || error62 instanceof PromptArtifactError) {
@@ -45630,112 +45363,6 @@ function warnIgnoredSetting(audit, event, commandId, sessionId, agentId, selecti
45630
45363
  `);
45631
45364
  }
45632
45365
 
45633
- // src/relay-connection/coalescing-agent-event-publisher.ts
45634
- var AGENT_EVENT_COALESCING_MILLISECONDS = 100;
45635
- var AGENT_EVENT_TEXT_MAXIMUM_LENGTH = 1e5;
45636
- var CoalescingAgentEventPublisher = class {
45637
- #entries = [];
45638
- #publish;
45639
- #publishedActivityIds = /* @__PURE__ */ new Set();
45640
- #scheduled = null;
45641
- #timer;
45642
- constructor(timer, publish) {
45643
- this.#publish = publish;
45644
- this.#timer = timer;
45645
- }
45646
- flush = () => {
45647
- this.#scheduled?.cancel();
45648
- this.#scheduled = null;
45649
- const entries = this.#entries;
45650
- this.#entries = [];
45651
- for (const entry of entries) {
45652
- this.#publish(entry);
45653
- }
45654
- };
45655
- recordActivity = (activity2) => {
45656
- const latest = this.#entries.at(-1);
45657
- this.#entries = latest?.kind === "activity" && latest.activity.activityId === activity2.activityId ? [...this.#entries.slice(0, -1), { activity: activity2, kind: "activity" }] : [...this.#entries, { activity: activity2, kind: "activity" }];
45658
- const first = !this.#publishedActivityIds.has(activity2.activityId);
45659
- this.#publishedActivityIds.add(activity2.activityId);
45660
- if (first || activity2.status !== "pending" && activity2.status !== "running") {
45661
- this.flush();
45662
- } else {
45663
- this.schedule();
45664
- }
45665
- return Promise.resolve();
45666
- };
45667
- recordNarration = (increment) => {
45668
- if (increment.text.length === 0) {
45669
- return Promise.resolve();
45670
- }
45671
- let remaining = increment.text;
45672
- while (remaining.length > 0) {
45673
- const latest = this.#entries.at(-1);
45674
- if (latest?.kind === "narration" && latest.increment.activityId === increment.activityId) {
45675
- const available = AGENT_EVENT_TEXT_MAXIMUM_LENGTH - latest.increment.text.length;
45676
- if (available > 0) {
45677
- this.#entries = [
45678
- ...this.#entries.slice(0, -1),
45679
- {
45680
- increment: {
45681
- ...increment,
45682
- text: `${latest.increment.text}${remaining.slice(0, available)}`
45683
- },
45684
- kind: "narration"
45685
- }
45686
- ];
45687
- remaining = remaining.slice(available);
45688
- continue;
45689
- }
45690
- }
45691
- this.#entries = [
45692
- ...this.#entries,
45693
- {
45694
- increment: { ...increment, text: remaining.slice(0, AGENT_EVENT_TEXT_MAXIMUM_LENGTH) },
45695
- kind: "narration"
45696
- }
45697
- ];
45698
- remaining = remaining.slice(AGENT_EVENT_TEXT_MAXIMUM_LENGTH);
45699
- }
45700
- this.schedule();
45701
- return Promise.resolve();
45702
- };
45703
- recordText = (text2, messageId) => {
45704
- if (text2.length === 0) {
45705
- return Promise.resolve();
45706
- }
45707
- let remaining = text2;
45708
- while (remaining.length > 0) {
45709
- const latest = this.#entries.at(-1);
45710
- if (latest?.kind === "text" && latest.messageId === messageId) {
45711
- const available = AGENT_EVENT_TEXT_MAXIMUM_LENGTH - latest.text.length;
45712
- if (available > 0) {
45713
- this.#entries = [
45714
- ...this.#entries.slice(0, -1),
45715
- { ...latest, text: `${latest.text}${remaining.slice(0, available)}` }
45716
- ];
45717
- remaining = remaining.slice(available);
45718
- continue;
45719
- }
45720
- }
45721
- this.#entries = [
45722
- ...this.#entries,
45723
- {
45724
- kind: "text",
45725
- messageId,
45726
- text: remaining.slice(0, AGENT_EVENT_TEXT_MAXIMUM_LENGTH)
45727
- }
45728
- ];
45729
- remaining = remaining.slice(AGENT_EVENT_TEXT_MAXIMUM_LENGTH);
45730
- }
45731
- this.schedule();
45732
- return Promise.resolve();
45733
- };
45734
- schedule() {
45735
- this.#scheduled ??= this.#timer.schedule(this.flush, AGENT_EVENT_COALESCING_MILLISECONDS);
45736
- }
45737
- };
45738
-
45739
45366
  // src/daemon-prompt-executor.ts
45740
45367
  function daemonActivity(command, activity2) {
45741
45368
  return {
@@ -45758,7 +45385,6 @@ function daemonActivity(command, activity2) {
45758
45385
  }
45759
45386
  async function executePrompt({
45760
45387
  operations,
45761
- publisher,
45762
45388
  eventLogV2,
45763
45389
  command,
45764
45390
  config: config2,
@@ -45768,36 +45394,11 @@ async function executePrompt({
45768
45394
  attemptId,
45769
45395
  activateAttempt,
45770
45396
  waitForSessionAvailability,
45771
- timer,
45772
45397
  signal,
45773
- recordLiveEvent,
45398
+ recordTurnEvent,
45774
45399
  recordSteeringPrompt,
45775
45400
  cancellationRequested
45776
45401
  }) {
45777
- const events = new CoalescingAgentEventPublisher(timer, (event) => {
45778
- if (event.kind === "text") {
45779
- publisher.publish(
45780
- command.sessionId,
45781
- recordLiveEvent({ kind: AGENT_MESSAGE_DELTA_KIND, messageId: event.messageId, text: event.text })
45782
- );
45783
- return;
45784
- }
45785
- if (event.kind === "narration") {
45786
- const recorded = {
45787
- activityId: event.increment.activityId,
45788
- activityType: event.increment.activityType,
45789
- commandId: command.commandId,
45790
- kind: AGENT_ACTIVITY_NARRATION_KIND,
45791
- sequence: event.increment.sequence,
45792
- sessionId: command.sessionId,
45793
- text: event.increment.text
45794
- };
45795
- publisher.publish(command.sessionId, recordLiveEvent(recorded));
45796
- return;
45797
- }
45798
- const activity2 = daemonActivity(command, event.activity);
45799
- publisher.publish(command.sessionId, recordLiveEvent(activity2));
45800
- });
45801
45402
  try {
45802
45403
  const resolved = await resolveSessionDirectories(
45803
45404
  directories,
@@ -45865,33 +45466,6 @@ async function executePrompt({
45865
45466
  }
45866
45467
  const stream = activateAttempt();
45867
45468
  const lifecycleV2 = eventLogV2.started(command.sessionId, command.commandId, attemptId, stream.epoch);
45868
- if (!prepared.prompted) {
45869
- const listing = await directories.list(config2.bindingId, command.directoryId, signal);
45870
- publisher.publish(command.sessionId, {
45871
- additionalDirectories: resolved.additionalDirectoryEntries,
45872
- agentId: command.agentId,
45873
- agentName: prepared.agentName,
45874
- agentVersion: prepared.agentVersion,
45875
- capabilities: prepared.capabilities,
45876
- commands: prepared.commands,
45877
- configOptions: prepared.configOptions,
45878
- directoryId: command.directoryId,
45879
- directoryLabel: listing.directoryLabel,
45880
- kind: SESSION_READY_KIND,
45881
- requestId: command.commandId,
45882
- restored: prepared.restored,
45883
- sessionId: command.sessionId
45884
- });
45885
- }
45886
- publisher.publish(command.sessionId, {
45887
- commandId: command.commandId,
45888
- epoch: stream.epoch,
45889
- kind: SESSION_STARTED_KIND,
45890
- attemptId,
45891
- prompt: command.prompt,
45892
- sequence: stream.sequence,
45893
- sessionId: command.sessionId
45894
- });
45895
45469
  const attachments = await resolvePromptArtifacts(config2, command, signal);
45896
45470
  let stopReason;
45897
45471
  if (availability.disposition === SessionPromptDisposition.Steer) {
@@ -45918,9 +45492,20 @@ async function executePrompt({
45918
45492
  disposition: availability.disposition,
45919
45493
  images: attachments.images,
45920
45494
  lifecycleV2,
45921
- onActivity: events.recordActivity,
45922
- onNarration: events.recordNarration,
45923
- onText: events.recordText,
45495
+ onActivity: async (activity2) => {
45496
+ recordTurnEvent(daemonActivity(command, activity2));
45497
+ },
45498
+ onNarration: async (increment) => {
45499
+ recordTurnEvent({
45500
+ ...increment,
45501
+ commandId: command.commandId,
45502
+ sessionId: command.sessionId,
45503
+ kind: AGENT_ACTIVITY_NARRATION_KIND
45504
+ });
45505
+ },
45506
+ onText: async (text2, messageId) => {
45507
+ recordTurnEvent({ kind: AGENT_MESSAGE_DELTA_KIND, text: text2, messageId });
45508
+ },
45924
45509
  prompt: command.prompt,
45925
45510
  resources: attachments.resources,
45926
45511
  sessionId: command.sessionId,
@@ -45929,14 +45514,7 @@ async function executePrompt({
45929
45514
  });
45930
45515
  stopReason = result.stopReason;
45931
45516
  }
45932
- events.flush();
45933
- publisher.publish(command.sessionId, {
45934
- commandId: command.commandId,
45935
- kind: SESSION_COMPLETED_KIND,
45936
- sessionId: command.sessionId,
45937
- stopReason
45938
- });
45939
- eventLogV2.completed(command.sessionId, command.commandId, stopReason);
45517
+ await eventLogV2.completed(command.sessionId, command.commandId, stopReason);
45940
45518
  operations.transitionExecution(command.commandId, stopReason === "cancelled" ? "cancelled" : "succeeded");
45941
45519
  audit.record({
45942
45520
  commandId: command.commandId,
@@ -45944,15 +45522,8 @@ async function executePrompt({
45944
45522
  sessionId: command.sessionId
45945
45523
  });
45946
45524
  } catch (error62) {
45947
- events.flush();
45948
45525
  if (signal.aborted && cancellationRequested()) {
45949
- publisher.publish(command.sessionId, {
45950
- commandId: command.commandId,
45951
- kind: SESSION_COMPLETED_KIND,
45952
- sessionId: command.sessionId,
45953
- stopReason: "cancelled"
45954
- });
45955
- eventLogV2.completed(command.sessionId, command.commandId, "cancelled");
45526
+ await eventLogV2.completed(command.sessionId, command.commandId, "cancelled");
45956
45527
  operations.transitionExecution(command.commandId, "cancelled");
45957
45528
  audit.record({
45958
45529
  commandId: command.commandId,
@@ -45969,8 +45540,7 @@ async function executePrompt({
45969
45540
  const code = operationErrorCode(error62);
45970
45541
  const failureCode = code === "session_operation_failed" ? "agent_execution_failed" : code;
45971
45542
  const failureMessage = code === "session_operation_failed" ? "The local agent could not complete the request" : operationErrorMessage(error62);
45972
- eventLogV2.failed(command.sessionId, command.commandId, failureCode, failureMessage);
45973
- reportFailure(publisher, command, failureCode, failureMessage);
45543
+ await eventLogV2.failed(command.sessionId, command.commandId, failureCode, failureMessage);
45974
45544
  operations.transitionExecution(command.commandId, "failed");
45975
45545
  console.error("Mobius daemon command failed", error62);
45976
45546
  }
@@ -45998,7 +45568,7 @@ async function executeWorkspaceList(socket, command, directories, audit, signal)
45998
45568
  reportOperationFailure(socket, command.requestId, "", error62);
45999
45569
  }
46000
45570
  }
46001
- async function executeSessionPrepare(publisher, socket, command, config2, directories, audit, sessions, diagnostics, signal) {
45571
+ async function executeSessionPrepare(socket, command, config2, directories, audit, sessions, diagnostics, signal) {
46002
45572
  const metrics = new AccumulatingOperationMetrics();
46003
45573
  try {
46004
45574
  const readyEvent = await metrics.measure("prepare-total", async () => {
@@ -46048,12 +45618,6 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
46048
45618
  event: "session_configured",
46049
45619
  sessionId: command.sessionId
46050
45620
  });
46051
- publisher.publish(command.sessionId, {
46052
- configOptions,
46053
- kind: "session.config.updated",
46054
- requestId: command.requestId,
46055
- sessionId: command.sessionId
46056
- });
46057
45621
  }
46058
45622
  const event = {
46059
45623
  additionalDirectories: resolved.additionalDirectoryEntries,
@@ -46071,11 +45635,6 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
46071
45635
  sessionId: command.sessionId,
46072
45636
  runtimeTimings: metrics.snapshot()
46073
45637
  };
46074
- if (command.transient !== true) {
46075
- metrics.measureSync("readiness-commit", () => {
46076
- publisher.publish(command.sessionId, event);
46077
- });
46078
- }
46079
45638
  return event;
46080
45639
  });
46081
45640
  send(socket, {
@@ -46105,7 +45664,7 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
46105
45664
  reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
46106
45665
  }
46107
45666
  }
46108
- async function executeSessionConfigure(publisher, socket, command, config2, directories, audit, sessions, signal) {
45667
+ async function executeSessionConfigure(socket, command, config2, directories, audit, sessions, signal) {
46109
45668
  try {
46110
45669
  const resolved = await resolveSessionDirectories(
46111
45670
  directories,
@@ -46131,7 +45690,7 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
46131
45690
  event: "session_configured",
46132
45691
  sessionId: command.sessionId
46133
45692
  });
46134
- publisher.publish(command.sessionId, {
45693
+ send(socket, {
46135
45694
  configOptions,
46136
45695
  kind: "session.config.updated",
46137
45696
  requestId: command.requestId,
@@ -46251,7 +45810,6 @@ function createDaemonCommandHandler({
46251
45810
  installations,
46252
45811
  nativeSessions,
46253
45812
  operations,
46254
- publisher,
46255
45813
  eventLogV2,
46256
45814
  externalContent,
46257
45815
  activeTurns,
@@ -46272,8 +45830,9 @@ function createDaemonCommandHandler({
46272
45830
  timer
46273
45831
  });
46274
45832
  const queueChanged = (sessionId) => {
46275
- publisher.publish(sessionId, { kind: "session.queue.changed", sessionId });
46276
- eventLogV2.queueChanged(sessionId);
45833
+ void eventLogV2.queueChanged(sessionId).catch((error62) => {
45834
+ console.error("Could not record queue change", error62);
45835
+ });
46277
45836
  };
46278
45837
  const nativeRequestHandler = createNativeSessionRequestHandler({
46279
45838
  audit,
@@ -46342,7 +45901,9 @@ function createDaemonCommandHandler({
46342
45901
  const cancellation = message;
46343
45902
  const turn2 = activeTurns.get(cancellation.commandId);
46344
45903
  if (turn2 === void 0 || !turn2.matches(cancellation)) {
46345
- settleAbandonedTurn(publisher, operations, audit, cancellation);
45904
+ void settleAbandonedTurn(eventLogV2, operations, audit, cancellation).catch((error62) => {
45905
+ console.error("Could not settle abandoned turn", error62);
45906
+ });
46346
45907
  return;
46347
45908
  }
46348
45909
  const cancellationState = turn2.requestCancellation();
@@ -46382,22 +45943,12 @@ function createDaemonCommandHandler({
46382
45943
  }
46383
45944
  if (kind === SESSION_PREPARE_KIND) {
46384
45945
  const command2 = message;
46385
- void executeSessionPrepare(
46386
- publisher,
46387
- socket,
46388
- command2,
46389
- config2,
46390
- directories,
46391
- audit,
46392
- sessions,
46393
- diagnostics,
46394
- signal
46395
- );
45946
+ void executeSessionPrepare(socket, command2, config2, directories, audit, sessions, diagnostics, signal);
46396
45947
  return;
46397
45948
  }
46398
45949
  if (kind === SESSION_CONFIGURE_KIND) {
46399
45950
  const command2 = message;
46400
- void executeSessionConfigure(publisher, socket, command2, config2, directories, audit, sessions, signal);
45951
+ void executeSessionConfigure(socket, command2, config2, directories, audit, sessions, signal);
46401
45952
  return;
46402
45953
  }
46403
45954
  if (kind === SESSION_LIST_KIND) {
@@ -46499,7 +46050,6 @@ function createDaemonCommandHandler({
46499
46050
  eventLogV2.requested(command);
46500
46051
  void executePrompt({
46501
46052
  operations,
46502
- publisher,
46503
46053
  eventLogV2,
46504
46054
  command,
46505
46055
  config: config2,
@@ -46516,15 +46066,15 @@ function createDaemonCommandHandler({
46516
46066
  sessionId: command.sessionId
46517
46067
  });
46518
46068
  }),
46519
- timer,
46520
46069
  signal: turn.signal,
46521
- recordLiveEvent: turn.recordEvent,
46070
+ recordTurnEvent: turn.recordEvent,
46522
46071
  recordSteeringPrompt: () => activeTurns.recordSteeringPrompt(command),
46523
46072
  cancellationRequested: turn.cancellationRequested
46524
46073
  }).catch((error62) => {
46525
46074
  console.error("Mobius daemon turn failed", error62);
46526
46075
  }).finally(() => {
46527
46076
  activeTurns.finish(turn);
46077
+ eventLogV2.publishTerminal(command.sessionId, command.commandId);
46528
46078
  if (command.disposition === SessionPromptDisposition.Queue) {
46529
46079
  queueChanged(command.sessionId);
46530
46080
  }
@@ -46808,7 +46358,6 @@ async function runRelayConnection({
46808
46358
  installations,
46809
46359
  nativeSessions,
46810
46360
  operations,
46811
- publisher,
46812
46361
  eventLogV2,
46813
46362
  externalContent,
46814
46363
  activeTurns,
@@ -46973,51 +46522,17 @@ var DaemonSessionEventPublisher = class {
46973
46522
  close = () => {
46974
46523
  this.#socket = null;
46975
46524
  };
46976
- publish = (sessionId, event) => {
46977
- const socket = this.#socket;
46978
- if (socket === null || socket.readyState !== WebSocket8.OPEN) {
46979
- return;
46980
- }
46981
- const encoded = encodeDaemonToServiceMessage({
46982
- kind: SESSION_EVENT_KIND,
46983
- payload: encodeRecordedSessionEvent(event),
46984
- sessionId
46985
- });
46986
- if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
46987
- socket.close(1013, "Live event transport overloaded");
46988
- return;
46989
- }
46990
- try {
46991
- socket.send(encoded);
46992
- } catch {
46993
- }
46994
- };
46995
- publishBatch = (sessionId, events) => {
46996
- for (const event of events) {
46997
- this.publish(sessionId, event);
46998
- }
46999
- };
47000
- publishStatus = (event) => {
47001
- const socket = this.#socket;
47002
- if (socket === null || socket.readyState !== WebSocket8.OPEN) {
47003
- return;
47004
- }
47005
- const encoded = encodeDaemonToServiceMessage(event);
47006
- if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
47007
- socket.close(1013, "Live event transport overloaded");
47008
- return;
47009
- }
47010
- try {
47011
- socket.send(encoded);
47012
- } catch {
47013
- }
46525
+ publishOperationFailure = (sessionId, requestId, code, message) => {
46526
+ this.#send({ kind: "session.operation.failed", sessionId, requestId, code, message });
47014
46527
  };
47015
- publishV2 = (event) => {
46528
+ publishStatus = (event) => this.#send(event);
46529
+ publishV2 = (event) => this.#send({ event, kind: SESSION_EVENT_V2_KIND });
46530
+ #send = (message) => {
47016
46531
  const socket = this.#socket;
47017
46532
  if (socket === null || socket.readyState !== WebSocket8.OPEN) {
47018
46533
  return;
47019
46534
  }
47020
- const encoded = encodeDaemonToServiceMessage({ event, kind: SESSION_EVENT_V2_KIND });
46535
+ const encoded = encodeDaemonToServiceMessage(message);
47021
46536
  if (socket.bufferedAmount + Buffer.byteLength(encoded, "utf8") > MAX_BUFFERED_BYTES) {
47022
46537
  socket.close(1013, "Live event transport overloaded");
47023
46538
  return;
@@ -47077,8 +46592,12 @@ function sessionEventV22(daemonGenerationId, sessionId, position, event, recorde
47077
46592
  var DaemonSessionEventLogV2 = class {
47078
46593
  daemonGenerationId;
47079
46594
  #publisher;
46595
+ #terminal = /* @__PURE__ */ new Map();
46596
+ #publications = /* @__PURE__ */ new Map();
47080
46597
  #queued = /* @__PURE__ */ new Map();
47081
- constructor(publisher, daemonGenerationId = randomUUID9()) {
46598
+ #recordLifecycle;
46599
+ constructor(publisher, recordLifecycle, daemonGenerationId = randomUUID9()) {
46600
+ this.#recordLifecycle = recordLifecycle;
47082
46601
  this.#publisher = publisher;
47083
46602
  this.daemonGenerationId = daemonGenerationId;
47084
46603
  }
@@ -47086,36 +46605,101 @@ var DaemonSessionEventLogV2 = class {
47086
46605
  this.#queued.set(command.commandId, {
47087
46606
  commandId: command.commandId,
47088
46607
  content: promptContent(command),
46608
+ context: {
46609
+ agentId: command.agentId,
46610
+ directoryId: command.directoryId,
46611
+ additionalDirectoryIds: command.additionalDirectoryIds
46612
+ },
46613
+ phase: "queued",
47089
46614
  sessionId: command.sessionId
47090
46615
  });
47091
46616
  };
47092
46617
  started = (sessionId, commandId, attemptId, epoch) => {
47093
46618
  const request = this.#queued.get(commandId);
47094
46619
  if (request?.sessionId === sessionId) {
47095
- this.#queued.delete(commandId);
47096
- return { attemptId, content: request.content, epoch };
46620
+ this.#queued.set(commandId, { ...request, phase: "running" });
46621
+ return { attemptId, content: request.content, epoch, context: request.context };
47097
46622
  }
47098
46623
  throw new Error("The executing prompt was not registered in the V2 queue");
47099
46624
  };
47100
46625
  record = (sessionId, event, position) => {
47101
- this.#publisher.publishV2(this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString()));
46626
+ const recorded = this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString());
46627
+ if (event.type === "lifecycle-metadata" && (event.payload.kind === "prompt.completed" || event.payload.kind === "prompt.failed" || event.payload.kind === "prompt.failed-before-start")) {
46628
+ this.#terminal.set(event.payload.commandId, recorded);
46629
+ const pending2 = this.#publications.get(sessionId) ?? [];
46630
+ pending2.push(recorded);
46631
+ this.#publications.set(sessionId, pending2);
46632
+ return;
46633
+ }
46634
+ const pending = this.#publications.get(sessionId);
46635
+ if (pending !== void 0) {
46636
+ pending.push(recorded);
46637
+ } else {
46638
+ this.#publisher.publishV2(recorded);
46639
+ }
46640
+ };
46641
+ publishTerminal = (sessionId, commandId) => {
46642
+ const event = this.#terminal.get(commandId);
46643
+ if (event?.sessionId === sessionId) {
46644
+ this.#terminal.delete(commandId);
46645
+ const pending = this.#publications.get(sessionId) ?? [];
46646
+ while (pending.length > 0) {
46647
+ const next = pending[0];
46648
+ if (next === void 0) {
46649
+ break;
46650
+ }
46651
+ if (next.type === "lifecycle-metadata" && "commandId" in next.payload && this.#terminal.has(next.payload.commandId)) {
46652
+ break;
46653
+ }
46654
+ pending.shift();
46655
+ this.#publisher.publishV2(next);
46656
+ }
46657
+ if (pending.length === 0) {
46658
+ this.#publications.delete(sessionId);
46659
+ }
46660
+ }
46661
+ this.#queued.delete(commandId);
47102
46662
  };
47103
46663
  event = (sessionId, position, event, recordedAt) => sessionEventV22(this.daemonGenerationId, sessionId, position, event, recordedAt);
47104
- queueChanged = (_sessionId) => void 0;
47105
- completed = (sessionId, commandId, _stopReason) => {
46664
+ queueChanged = async (sessionId) => {
46665
+ await this.#recordLifecycle(sessionId, {
46666
+ type: "lifecycle-metadata",
46667
+ payload: { kind: "session.queue.changed" }
46668
+ });
46669
+ };
46670
+ completed = async (sessionId, commandId, stopReason) => {
47106
46671
  const request = this.#queued.get(commandId);
47107
- if (request?.sessionId === sessionId) {
47108
- this.#queued.delete(commandId);
46672
+ if (request?.sessionId !== sessionId || this.#terminal.has(commandId)) {
46673
+ return;
46674
+ }
46675
+ const recorded = await this.#recordLifecycle(sessionId, {
46676
+ type: "lifecycle-metadata",
46677
+ payload: { kind: "prompt.completed", commandId, stopReason }
46678
+ });
46679
+ if (!recorded) {
46680
+ this.#publisher.publishOperationFailure(
46681
+ sessionId,
46682
+ commandId,
46683
+ "cancelled",
46684
+ "The prompt was cancelled before execution"
46685
+ );
47109
46686
  }
47110
46687
  };
47111
- failed = (sessionId, commandId, _code, _message) => {
46688
+ failed = async (sessionId, commandId, code, message) => {
47112
46689
  const request = this.#queued.get(commandId);
47113
- if (request?.sessionId === sessionId) {
47114
- this.#queued.delete(commandId);
46690
+ if (request?.sessionId !== sessionId || this.#terminal.has(commandId)) {
46691
+ return;
46692
+ }
46693
+ const recorded = await this.#recordLifecycle(sessionId, {
46694
+ type: "lifecycle-metadata",
46695
+ payload: { kind: "prompt.failed-before-start", commandId, code, message }
46696
+ });
46697
+ if (!recorded) {
46698
+ this.#publisher.publishOperationFailure(sessionId, commandId, code, message);
47115
46699
  }
47116
46700
  };
47117
46701
  promptRequestRecovery = (sessionId) => ({
47118
- queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId).map(({ commandId, content }) => ({ commandId, content }))
46702
+ queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId && request.phase === "queued").map(({ commandId, content }) => ({ commandId, content }))
47119
46703
  });
47120
46704
  };
47121
46705
 
@@ -47202,13 +46786,16 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
47202
46786
  await using externalContent = new LocalExternalContentStore(stateDirectory);
47203
46787
  const operations = new DaemonOperationState();
47204
46788
  const publisher = new DaemonSessionEventPublisher();
47205
- const eventLogV2 = new DaemonSessionEventLogV2(publisher, daemonGenerationId);
46789
+ const eventLogV2 = new DaemonSessionEventLogV2(
46790
+ publisher,
46791
+ (sessionId, event) => agentRuntime.recordLifecycleEventV2(sessionId, event),
46792
+ daemonGenerationId
46793
+ );
47206
46794
  const activeTurns = new DaemonTurnRegistry(operations);
47207
- const recordSessionEvent = (sessionId, event) => {
47208
- publisher.publish(sessionId, activeTurns.recordEvent(event));
47209
- };
47210
46795
  const agentRuntime = new AgentRuntimeManager(
47211
- new DaemonAcpObserver(recordSessionEvent, eventLogV2.record),
46796
+ new DaemonAcpObserver((_sessionId, event) => {
46797
+ activeTurns.recordEvent(event);
46798
+ }, eventLogV2.record),
47212
46799
  sessionStore,
47213
46800
  {
47214
46801
  read: async (options2, nativeSessionId, nativeTurn) => options2.agent.id === "codex" ? (await readCodexFullHistory(