@moxt-ai/mobius 0.0.410 → 0.0.412

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 (32) hide show
  1. package/dist/{chunk-2S33N4G2.js → chunk-7ER5P6H5.js} +80 -40
  2. package/dist/{chunk-2S33N4G2.js.map → chunk-7ER5P6H5.js.map} +3 -3
  3. package/dist/{chunk-M4L66DBW.js → chunk-PMJDO7PC.js} +2 -2
  4. package/dist/{chunk-M4L66DBW.js.map → chunk-PMJDO7PC.js.map} +1 -1
  5. package/dist/{cli-VDA77LWX.js → cli-KGI5XDXC.js} +3 -3
  6. package/dist/cli.js +2 -2
  7. package/dist/engine/runtime/command/agent-settings-discovery.d.ts.map +1 -1
  8. package/dist/engine/runtime/command/agent-settings-discovery.js +6 -1
  9. package/dist/engine/runtime/command/agent-settings-discovery.js.map +1 -1
  10. package/dist/engine/runtime/command/registry/interactions.d.ts.map +1 -1
  11. package/dist/engine/runtime/command/registry/interactions.js +7 -2
  12. package/dist/engine/runtime/command/registry/interactions.js.map +1 -1
  13. package/dist/engine/runtime/command/registry/prompt.d.ts.map +1 -1
  14. package/dist/engine/runtime/command/registry/prompt.js +8 -7
  15. package/dist/engine/runtime/command/registry/prompt.js.map +1 -1
  16. package/dist/engine/session/api/session-layer.d.ts.map +1 -1
  17. package/dist/engine/session/api/session-layer.js +1 -1
  18. package/dist/engine/session/api/session-layer.js.map +1 -1
  19. package/dist/engine/session/prompt/prompt-lifecycle.d.ts +7 -2
  20. package/dist/engine/session/prompt/prompt-lifecycle.d.ts.map +1 -1
  21. package/dist/engine/session/prompt/prompt-lifecycle.js +32 -9
  22. package/dist/engine/session/prompt/prompt-lifecycle.js.map +1 -1
  23. package/dist/engine/session/settings/discover-agent-settings.d.ts.map +1 -1
  24. package/dist/engine/session/settings/discover-agent-settings.js +5 -1
  25. package/dist/engine/session/settings/discover-agent-settings.js.map +1 -1
  26. package/dist/engine/session/turn/execution-receipts.d.ts +16 -3
  27. package/dist/engine/session/turn/execution-receipts.d.ts.map +1 -1
  28. package/dist/engine/session/turn/execution-receipts.js +17 -14
  29. package/dist/engine/session/turn/execution-receipts.js.map +1 -1
  30. package/dist/engine.js +2 -2
  31. package/package.json +2 -2
  32. /package/dist/{cli-VDA77LWX.js.map → cli-KGI5XDXC.js.map} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  __export,
4
4
  __using,
5
5
  package_default
6
- } from "./chunk-M4L66DBW.js";
6
+ } from "./chunk-PMJDO7PC.js";
7
7
 
8
8
  // src/engine/runtime/relay/runtime-revocation.ts
9
9
  var runtimeRevocationCloseCode = 1008;
@@ -20159,6 +20159,9 @@ var agentModelEffortSchema = external_exports.object({
20159
20159
  }).readonly();
20160
20160
  var agentSettingsDiscoverCommandSchema = external_exports.object({
20161
20161
  agentId: identifierStringSchema,
20162
+ // The directory a Session would start in, whose project settings the Agent reads. Omitted, the Runtime's
20163
+ // default directory. A Runtime that predates this field ignores it; see the discovered event's `directoryId`.
20164
+ directoryId: DIRECTORY_IDENTIFIER.optional(),
20162
20165
  kind: external_exports.literal(AGENT_SETTINGS_DISCOVER_KIND),
20163
20166
  model: external_exports.string().min(1).max(500).optional(),
20164
20167
  requestId: identifierStringSchema
@@ -20167,6 +20170,9 @@ var agentSettingsDiscoveredEventSchema = external_exports.object({
20167
20170
  agentId: identifierStringSchema,
20168
20171
  agentName: external_exports.string().max(255),
20169
20172
  agentVersion: external_exports.string().max(128),
20173
+ // The directory the settings were discovered in. Absent from older Runtimes, which always discover in the
20174
+ // Runtime's default directory whatever the command named.
20175
+ directoryId: DIRECTORY_IDENTIFIER.optional(),
20170
20176
  kind: external_exports.literal(AGENT_SETTINGS_DISCOVERED_KIND),
20171
20177
  modelEffort: agentModelEffortSchema,
20172
20178
  requestId: identifierStringSchema,
@@ -20798,9 +20804,10 @@ var sessionEventPayloadSchema = external_exports.discriminatedUnion("type", [
20798
20804
  external_exports.object({ payload: lifecycleMetadataSchema, type: external_exports.literal("lifecycle-metadata") }).readonly()
20799
20805
  ]);
20800
20806
  var positionSchema = external_exports.string().regex(/^(0|[1-9][0-9]*)$/);
20807
+ var mobiusMetadataFields = { omitted: external_exports.literal(true).optional(), restated: external_exports.literal(true).optional() };
20801
20808
  var sharedSessionEventFields = {
20802
20809
  eventId: identifierStringSchema,
20803
- mobiusMetadata: external_exports.object({ omitted: external_exports.literal(true).optional() }).readonly().optional(),
20810
+ mobiusMetadata: external_exports.object(mobiusMetadataFields).readonly().optional(),
20804
20811
  recordedAt: external_exports.iso.datetime({ offset: true }),
20805
20812
  sessionGenerationId: identifierStringSchema,
20806
20813
  sessionId: identifierStringSchema
@@ -20823,7 +20830,7 @@ var wireLifecyclePayloadSchema = external_exports.object({
20823
20830
  }).passthrough().readonly();
20824
20831
  var wireEventFields = {
20825
20832
  ...sessionLiveEventFields,
20826
- mobiusMetadata: external_exports.object({ omitted: external_exports.literal(true).optional() }).passthrough().readonly().optional()
20833
+ mobiusMetadata: external_exports.object(mobiusMetadataFields).passthrough().readonly().optional()
20827
20834
  };
20828
20835
  var sessionWireEventSchema = external_exports.union([
20829
20836
  external_exports.object({
@@ -88600,8 +88607,10 @@ var PromptLifecycle = class {
88600
88607
  #recordActiveTurn;
88601
88608
  #executions;
88602
88609
  #recordLifecycle;
88603
- constructor(sink, recordLifecycle, recordActiveTurn, executions) {
88610
+ #append;
88611
+ constructor(sink, recordLifecycle, append, recordActiveTurn, executions) {
88604
88612
  this.#recordLifecycle = recordLifecycle;
88613
+ this.#append = append;
88605
88614
  this.#recordActiveTurn = recordActiveTurn;
88606
88615
  this.#executions = executions;
88607
88616
  this.#sink = sink;
@@ -88640,16 +88649,20 @@ var PromptLifecycle = class {
88640
88649
  const sessionId = recorded.sessionId;
88641
88650
  if (recorded.type === "lifecycle-metadata" && isPromptTerminal(recorded.payload)) {
88642
88651
  this.#terminal.set(recorded.payload.commandId, recorded);
88643
- const pending2 = this.#publications.get(sessionId) ?? [];
88644
- pending2.push(recorded);
88645
- this.#publications.set(sessionId, pending2);
88652
+ const pending = this.#publications.get(sessionId) ?? [];
88653
+ pending.push(recorded);
88654
+ this.#publications.set(sessionId, pending);
88646
88655
  return;
88647
88656
  }
88648
- const pending = this.#publications.get(sessionId);
88657
+ this.#publishInOrder(recorded);
88658
+ };
88659
+ /** Publishes after the Session's held terminal events, so clients receive its events in order. */
88660
+ #publishInOrder = (event) => {
88661
+ const pending = this.#publications.get(event.sessionId);
88649
88662
  if (pending !== void 0) {
88650
- pending.push(recorded);
88663
+ pending.push(event);
88651
88664
  } else {
88652
- this.#sink.publish(recorded);
88665
+ this.#sink.publish(event);
88653
88666
  }
88654
88667
  };
88655
88668
  publishTerminal = (sessionId, commandId) => {
@@ -88674,13 +88687,24 @@ var PromptLifecycle = class {
88674
88687
  }
88675
88688
  this.#queued.delete(commandId);
88676
88689
  };
88677
- replayOutcome = async (sessionId, event) => {
88690
+ recordOutcome = async (sessionId, event) => {
88678
88691
  if (event.type !== "lifecycle-metadata" || !("commandId" in event.payload)) {
88679
88692
  return;
88680
88693
  }
88681
88694
  await this.#recordLifecycle(sessionId, event);
88682
88695
  this.publishTerminal(sessionId, event.payload.commandId);
88683
88696
  };
88697
+ /**
88698
+ * Answers a retried request about a command with the outcome its receipt already holds. The restatement is marked,
88699
+ * so Recording and status notifications do not take it for a new outcome, and it does not settle the receipt again.
88700
+ */
88701
+ restateOutcome = (sessionId, event) => {
88702
+ if (event.type !== "lifecycle-metadata" || !("commandId" in event.payload)) {
88703
+ return;
88704
+ }
88705
+ const restated = this.#append(sessionId, event);
88706
+ this.#publishInOrder({ ...restated, mobiusMetadata: { ...restated.mobiusMetadata, restated: true } });
88707
+ };
88684
88708
  queueChanged = async (sessionId, commandId) => {
88685
88709
  await this.#recordLifecycle(sessionId, {
88686
88710
  type: "lifecycle-metadata",
@@ -88739,10 +88763,16 @@ var PromptLifecycle = class {
88739
88763
  });
88740
88764
  };
88741
88765
  async function settleAbandonedTurn(projection, operations, cancellation) {
88742
- const outcome = operations.recordCancellationBeforeAdmission(cancellation.commandId, cancellation.sessionId);
88743
- if (outcome !== void 0) {
88744
- await projection.replayOutcome(cancellation.sessionId, outcome);
88745
- return;
88766
+ const cancelled = operations.recordCancellationBeforeAdmission(cancellation.commandId, cancellation.sessionId);
88767
+ switch (cancelled.kind) {
88768
+ case "recorded":
88769
+ await projection.recordOutcome(cancellation.sessionId, cancelled.outcome);
88770
+ return;
88771
+ case "restated":
88772
+ projection.restateOutcome(cancellation.sessionId, cancelled.outcome);
88773
+ return;
88774
+ case "unavailable":
88775
+ break;
88746
88776
  }
88747
88777
  const attemptId = operations.findUnsettledAttemptId(cancellation.commandId, cancellation.sessionId);
88748
88778
  if (attemptId === null) {
@@ -88834,7 +88864,6 @@ var unexpectedStanding = (standing) => {
88834
88864
  };
88835
88865
  var ExecutionReceipts = class {
88836
88866
  #executions = /* @__PURE__ */ new Map();
88837
- #recoveredCommands = /* @__PURE__ */ new Set();
88838
88867
  #table;
88839
88868
  #cancellations;
88840
88869
  #closing = false;
@@ -88854,7 +88883,6 @@ var ExecutionReceipts = class {
88854
88883
  if (cancelledBeforeStart(state)) {
88855
88884
  retained.push({ commandId, sessionId: identity2.sessionId });
88856
88885
  }
88857
- this.#recoveredCommands.add(commandId);
88858
88886
  }
88859
88887
  cancellations.retain(retained);
88860
88888
  }
@@ -88875,7 +88903,6 @@ var ExecutionReceipts = class {
88875
88903
  this.#executions.set(commandId, receipt);
88876
88904
  for (const evictedCommandId of evicted) {
88877
88905
  this.#executions.delete(evictedCommandId);
88878
- this.#recoveredCommands.delete(evictedCommandId);
88879
88906
  }
88880
88907
  let activeCount = 0;
88881
88908
  for (const entry of this.#executions.values()) {
@@ -89008,22 +89035,30 @@ var ExecutionReceipts = class {
89008
89035
  return unexpectedStanding(standing);
89009
89036
  }
89010
89037
  };
89011
- /** Reserves an unseen command for cancellation before a delayed prompt can claim its identity. */
89038
+ /**
89039
+ * Reserves an unseen command for cancellation before a delayed prompt can claim its identity. A command that
89040
+ * already has an outcome keeps it, and the outcome is restated rather than recorded again.
89041
+ */
89012
89042
  recordCancellationBeforeAdmission = (commandId, sessionId) => {
89013
89043
  const standing = this.#standing(commandId, sessionId);
89014
89044
  switch (standing.kind) {
89015
89045
  case "foreign":
89016
- return void 0;
89046
+ return { kind: "unavailable" };
89017
89047
  case "retryable":
89018
- case "retained":
89019
- return this.outcome(commandId);
89048
+ case "retained": {
89049
+ const outcome2 = this.outcome(commandId);
89050
+ return outcome2 === void 0 ? { kind: "unavailable" } : { kind: "restated", outcome: outcome2 };
89051
+ }
89020
89052
  case "expired":
89021
89053
  return {
89022
- type: "lifecycle-metadata",
89023
- payload: { kind: "prompt.completed", commandId, stopReason: "cancelled" }
89054
+ kind: "restated",
89055
+ outcome: {
89056
+ type: "lifecycle-metadata",
89057
+ payload: { kind: "prompt.completed", commandId, stopReason: "cancelled" }
89058
+ }
89024
89059
  };
89025
89060
  case "cancelled":
89026
- return cancelledBeforeStartOutcome(commandId);
89061
+ return { kind: "restated", outcome: cancelledBeforeStartOutcome(commandId) };
89027
89062
  case "unseen":
89028
89063
  break;
89029
89064
  default:
@@ -89047,7 +89082,7 @@ var ExecutionReceipts = class {
89047
89082
  outcome: JSON.stringify({ ...outcome, recordedAt: (/* @__PURE__ */ new Date()).toISOString() })
89048
89083
  }
89049
89084
  });
89050
- return outcome;
89085
+ return { kind: "recorded", outcome };
89051
89086
  };
89052
89087
  /**
89053
89088
  * Receipts follow their command's recorded lifecycle. `prompt.started` is recorded where the command is handed
@@ -89130,14 +89165,13 @@ var ExecutionReceipts = class {
89130
89165
  attemptId: standing.receipt.attemptId,
89131
89166
  commandId,
89132
89167
  kind: "duplicate",
89133
- outcome: this.#recoveredCommands.has(commandId) ? this.outcome(commandId) : void 0
89168
+ state: executionOutcome(standing.receipt.state) === null ? "unsettled" : "settled"
89134
89169
  };
89135
89170
  case "expired":
89136
89171
  return standing.commandHash === commandHash ? { kind: "expired" } : { kind: "conflict" };
89137
89172
  case "retryable":
89138
89173
  this.#table.remove(commandId);
89139
89174
  this.#executions.delete(commandId);
89140
- this.#recoveredCommands.delete(commandId);
89141
89175
  return this.claimExecution(commandId, sessionId, commandJson);
89142
89176
  case "unseen":
89143
89177
  break;
@@ -89165,7 +89199,6 @@ var ExecutionReceipts = class {
89165
89199
  };
89166
89200
  close = () => {
89167
89201
  this.#executions.clear();
89168
- this.#recoveredCommands.clear();
89169
89202
  this.#cancellations.close();
89170
89203
  };
89171
89204
  };
@@ -89827,6 +89860,7 @@ function buildSessionLayer(options) {
89827
89860
  eventProjection.record(recorded);
89828
89861
  return true;
89829
89862
  },
89863
+ (sessionId, event) => events.append(sessionId, event),
89830
89864
  activeSessions.recordSessionEvent,
89831
89865
  operations
89832
89866
  );
@@ -90805,7 +90839,8 @@ function unsupportedModelIds(unsupportedModels) {
90805
90839
  }
90806
90840
  async function discoverAgentSettings(command, resolveAgent, bindingId, directories, sessions, signal) {
90807
90841
  const { agent, adapter: harnessAdapter } = await resolveAgent(command.agentId, signal);
90808
- const cwd = await directories.resolve(bindingId, "default", signal);
90842
+ const directoryId = command.directoryId ?? "default";
90843
+ const cwd = await directories.resolve(bindingId, directoryId, signal);
90809
90844
  const inspectedBaseSnapshot = await sessions.inspectAgentSettings({
90810
90845
  adapter: harnessAdapter,
90811
90846
  additionalDirectories: [],
@@ -90879,6 +90914,7 @@ async function discoverAgentSettings(command, resolveAgent, bindingId, directori
90879
90914
  agentId: command.agentId,
90880
90915
  agentName: selectedSnapshot.agentName,
90881
90916
  agentVersion: selectedSnapshot.agentVersion,
90917
+ directoryId,
90882
90918
  kind: AGENT_SETTINGS_DISCOVERED_KIND,
90883
90919
  modelEffort,
90884
90920
  requestId: command.requestId,
@@ -91068,8 +91104,9 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
91068
91104
  const { config: config2, directories, sessions, diagnostics, socket, signal, timer } = dependencies;
91069
91105
  const agentSettingsDiscoveries = /* @__PURE__ */ new Map();
91070
91106
  const handle = (command) => {
91107
+ const directoryId = command.directoryId ?? "default";
91071
91108
  const existing = [...agentSettingsDiscoveries.values()].find(
91072
- (request) => request.agentId === command.agentId && !request.controller.signal.aborted
91109
+ (request) => request.agentId === command.agentId && request.directoryId === directoryId && !request.controller.signal.aborted
91073
91110
  );
91074
91111
  if ([...agentSettingsDiscoveries.values()].some((request) => request.requestIds.has(command.requestId))) {
91075
91112
  if (socket.readyState === WebSocket4.OPEN) {
@@ -91167,6 +91204,7 @@ function createAgentSettingsDiscoveryHandler(dependencies) {
91167
91204
  })();
91168
91205
  agentSettingsDiscoveries.set(command.requestId, {
91169
91206
  agentId: command.agentId,
91207
+ directoryId,
91170
91208
  model: command.model,
91171
91209
  requestIds,
91172
91210
  completion,
@@ -91703,9 +91741,14 @@ var sessionCancelBeforeStartCommand = {
91703
91741
  }
91704
91742
  const turn = sessionTurns.get(message.commandId, message.sessionId);
91705
91743
  if (turn === void 0) {
91706
- const outcome = operations.recordCancellationBeforeAdmission(message.commandId, message.sessionId);
91744
+ const cancelled = operations.recordCancellationBeforeAdmission(message.commandId, message.sessionId);
91745
+ const outcome = cancelled.kind === "unavailable" ? void 0 : cancelled.outcome;
91707
91746
  if (outcome?.type === "lifecycle-metadata" && outcome.payload.kind === "prompt.completed" && promptCompletion(outcome.payload).kind === "cancelled") {
91708
- void eventProjection.replayOutcome(message.sessionId, outcome).catch((error62) => {
91747
+ if (cancelled.kind === "restated") {
91748
+ eventProjection.restateOutcome(message.sessionId, outcome);
91749
+ return;
91750
+ }
91751
+ void eventProjection.recordOutcome(message.sessionId, outcome).catch((error62) => {
91709
91752
  reportOperationFailure(socket, message.commandId, message.sessionId, error62);
91710
91753
  });
91711
91754
  return;
@@ -92268,18 +92311,15 @@ var sessionPromptCommand = {
92268
92311
  return;
92269
92312
  }
92270
92313
  if (receipt.kind === "duplicate") {
92271
- const outcome = receipt.outcome;
92272
- const original = context.sessionTurns.get(message.commandId, message.sessionId);
92273
92314
  send(context.socket, {
92274
92315
  kind: "session.prompt.accepted",
92275
92316
  requestId: message.commandId,
92276
92317
  sessionId: message.sessionId,
92277
- state: outcome !== void 0 ? "settled" : original?.isQueued() === true ? "queued" : "running"
92318
+ state: receipt.state === "settled" ? "settled" : context.sessionTurns.get(message.commandId, message.sessionId)?.isQueued() === true ? "queued" : "running"
92278
92319
  });
92320
+ const outcome = receipt.state === "settled" ? context.operations.outcome(message.commandId) : void 0;
92279
92321
  if (outcome !== void 0) {
92280
- void context.eventProjection.replayOutcome(message.sessionId, outcome).catch((cause) => {
92281
- console.error("Could not replay the persisted execution outcome", cause);
92282
- });
92322
+ context.eventProjection.restateOutcome(message.sessionId, outcome);
92283
92323
  }
92284
92324
  return;
92285
92325
  }
@@ -94000,4 +94040,4 @@ export {
94000
94040
  * MIT Licensed
94001
94041
  *)
94002
94042
  */
94003
- //# sourceMappingURL=chunk-2S33N4G2.js.map
94043
+ //# sourceMappingURL=chunk-7ER5P6H5.js.map