@moxt-ai/mobius 0.0.328 → 0.0.329

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.
package/dist/cli.js CHANGED
@@ -2086,7 +2086,7 @@ var init_package = __esm({
2086
2086
  "package.json"() {
2087
2087
  package_default = {
2088
2088
  name: "@moxt-ai/mobius",
2089
- version: "0.0.328",
2089
+ version: "0.0.329",
2090
2090
  description: "Mobius CLI for pairing and running local AI agent services.",
2091
2091
  type: "module",
2092
2092
  bin: {
@@ -74997,6 +74997,15 @@ var init_lifecycle = __esm({
74997
74997
  });
74998
74998
 
74999
74999
  // ../mobius-sdk/src/protocol/session/prompt/commands.ts
75000
+ function decodeSessionCancelBeforeStartCommand(encoded) {
75001
+ const value = parseJson(encoded);
75002
+ assertKind(value, SESSION_CANCEL_BEFORE_START_KIND);
75003
+ return {
75004
+ commandId: readIdentifier(value, "commandId"),
75005
+ kind: SESSION_CANCEL_BEFORE_START_KIND,
75006
+ sessionId: readIdentifier(value, "sessionId")
75007
+ };
75008
+ }
75000
75009
  function readPromptDisposition(value) {
75001
75010
  const field = value["disposition"];
75002
75011
  if (field === void 0 || field === SessionPromptDisposition.Reject) {
@@ -75097,7 +75106,7 @@ function encodeSessionCancelCommand(message) {
75097
75106
  function encodeSessionPromptDispositionCommand(message) {
75098
75107
  return JSON.stringify(decodeSessionPromptDispositionCommand(JSON.stringify(message)));
75099
75108
  }
75100
- var SESSION_PROMPT_KIND, SESSION_PROMPT_DISPOSITION_KIND, SESSION_CANCEL_KIND, SessionPromptDisposition, SessionHistoryPolicy, MAX_PROMPT_LENGTH, MAX_PROMPT_ATTACHMENT_BYTES, promptAttachmentSchema, decodePromptAttachmentsValue;
75109
+ var SESSION_PROMPT_KIND, SESSION_PROMPT_DISPOSITION_KIND, SESSION_CANCEL_KIND, SESSION_CANCEL_BEFORE_START_KIND, SessionPromptDisposition, SessionHistoryPolicy, MAX_PROMPT_LENGTH, MAX_PROMPT_ATTACHMENT_BYTES, encodeSessionCancelBeforeStartCommand, promptAttachmentSchema, decodePromptAttachmentsValue;
75101
75110
  var init_commands = __esm({
75102
75111
  "../mobius-sdk/src/protocol/session/prompt/commands.ts"() {
75103
75112
  "use strict";
@@ -75108,6 +75117,7 @@ var init_commands = __esm({
75108
75117
  SESSION_PROMPT_KIND = "session.prompt";
75109
75118
  SESSION_PROMPT_DISPOSITION_KIND = "session.prompt.disposition";
75110
75119
  SESSION_CANCEL_KIND = "session.cancel";
75120
+ SESSION_CANCEL_BEFORE_START_KIND = "session.cancel-before-start";
75111
75121
  SessionPromptDisposition = Object.freeze({
75112
75122
  Queue: "queue",
75113
75123
  Reject: "reject",
@@ -75119,6 +75129,7 @@ var init_commands = __esm({
75119
75129
  });
75120
75130
  MAX_PROMPT_LENGTH = 1e5;
75121
75131
  MAX_PROMPT_ATTACHMENT_BYTES = 32 * 1024 * 1024;
75132
+ encodeSessionCancelBeforeStartCommand = (message) => JSON.stringify(decodeSessionCancelBeforeStartCommand(JSON.stringify(message)));
75122
75133
  promptAttachmentSchema = external_exports.object({
75123
75134
  byteLength: external_exports.number().int().positive().max(MAX_PROMPT_ATTACHMENT_BYTES),
75124
75135
  contentKey: external_exports.string().regex(/^[a-f0-9]{64}$/u),
@@ -75868,7 +75879,7 @@ var init_recording = __esm({
75868
75879
  });
75869
75880
 
75870
75881
  // ../mobius-sdk/src/protocol/session/recording/turn-history.ts
75871
- var SESSION_RECORDING_TURN_PAGE_DECODE_MAX_ELEMENTS, SESSION_RECORDING_TURN_ITEM_ID_MAX_LENGTH, isoTimestamp, shortText, itemText, turnCursorSchema, turnItemCursorSchema, attemptTiming, promptSucceededOutcome, promptCancelledOutcome, promptFailedOutcome, sessionRecordingTurnAttemptSchema, turnItemBase, textItemFields, sessionRecordingToolDetailSchema, sessionRecordingTurnItemSchema, sessionRecordingTurnPromptSchema, sessionRecordingTurnPrecedingSchema, sessionRecordingTurnSchema, sessionRecordingInteractionSchema, sessionRecordingTurnPageSchema, sessionRecordingTurnItemPageSchema, sessionRecordingTurnItemDetailSchema;
75882
+ var SESSION_RECORDING_TURN_PAGE_DECODE_MAX_ELEMENTS, SESSION_RECORDING_TURN_ITEM_ID_MAX_LENGTH, isoTimestamp, shortText, itemText, turnCursorSchema, turnItemCursorSchema, attemptTiming, promptSucceededOutcome, promptCancelledOutcome, promptFailedOutcome, sessionRecordingTurnAttemptSchema, turnItemBase, textItemFields, sessionRecordingToolDetailSchema, sessionRecordingTurnItemSchema, sessionRecordingTurnPromptSchema, sessionRecordingTurnPrecedingSchema, sessionRecordingTurnSchema, sessionRecordingInteractionSchema, SESSION_RECORDING_EXECUTION_COMMAND_MAX_LIMIT, recordingActiveCommandsSchema, sessionRecordingExecutionSchema, sessionRecordingTurnPageSchema, sessionRecordingTurnItemPageSchema, sessionRecordingTurnItemDetailSchema;
75872
75883
  var init_turn_history = __esm({
75873
75884
  "../mobius-sdk/src/protocol/session/recording/turn-history.ts"() {
75874
75885
  "use strict";
@@ -75995,6 +76006,24 @@ var init_turn_history = __esm({
75995
76006
  kind: external_exports.literal("elicitation")
75996
76007
  }).readonly()
75997
76008
  ]);
76009
+ SESSION_RECORDING_EXECUTION_COMMAND_MAX_LIMIT = 100;
76010
+ recordingActiveCommandsSchema = external_exports.object({
76011
+ commandIds: external_exports.array(identifierStringSchema).max(1e3).readonly(),
76012
+ generationId: identifierStringSchema
76013
+ }).readonly().nullable();
76014
+ sessionRecordingExecutionSchema = external_exports.object({
76015
+ activeCommands: recordingActiveCommandsSchema,
76016
+ commands: external_exports.array(
76017
+ external_exports.object({
76018
+ attempt: sessionRecordingTurnAttemptSchema,
76019
+ commandId: identifierStringSchema,
76020
+ generationId: identifierStringSchema
76021
+ }).readonly()
76022
+ ).max(SESSION_RECORDING_EXECUTION_COMMAND_MAX_LIMIT).readonly(),
76023
+ sessionId: identifierStringSchema,
76024
+ tailCursor: recordingCursorSchema,
76025
+ version: external_exports.literal(1)
76026
+ }).readonly();
75998
76027
  sessionRecordingTurnPageSchema = external_exports.object({
75999
76028
  // Commands that own Agent output in the newest Session generation, innermost last.
76000
76029
  activeCommands: external_exports.object({
@@ -76289,6 +76318,11 @@ var init_daemon_transport = __esm({
76289
76318
  decodeRuntimeDiagnosticsRequest
76290
76319
  ),
76291
76320
  [RUNTIME_PING_KIND]: defineMessageSignature(RUNTIME_PING_KIND, encodeRuntimePingCommand, decodeRuntimePingCommand),
76321
+ [SESSION_CANCEL_BEFORE_START_KIND]: defineMessageSignature(
76322
+ SESSION_CANCEL_BEFORE_START_KIND,
76323
+ encodeSessionCancelBeforeStartCommand,
76324
+ decodeSessionCancelBeforeStartCommand
76325
+ ),
76292
76326
  [SESSION_CANCEL_KIND]: defineMessageSignature(
76293
76327
  SESSION_CANCEL_KIND,
76294
76328
  encodeSessionCancelCommand,
@@ -92477,12 +92511,19 @@ async function prepareVersionData(version2, signal, environment = process.env, f
92477
92511
  signal.throwIfAborted();
92478
92512
  const root = readStateDirectory(environment);
92479
92513
  const targetVersion = runtimeUpgradeVersionSchema.parse(version2);
92480
- if (await versionDataExists(root, targetVersion, signal)) {
92481
- return;
92482
- }
92483
- const previous = await readCurrentDataVersion(root, signal) ?? fallbackVersion;
92484
- if (previous === null) {
92485
- return;
92514
+ const current = await readCurrentDataVersion(root, signal);
92515
+ let previous;
92516
+ if (current !== null) {
92517
+ if (current === targetVersion) {
92518
+ return;
92519
+ }
92520
+ await discardVersionData(root, targetVersion, signal);
92521
+ previous = current;
92522
+ } else {
92523
+ if (fallbackVersion === null || await versionDataExists(root, targetVersion, signal)) {
92524
+ return;
92525
+ }
92526
+ previous = fallbackVersion;
92486
92527
  }
92487
92528
  const leftBehind = await copyVersionData(root, runtimeUpgradeVersionSchema.parse(previous), targetVersion, signal);
92488
92529
  for (const entry of leftBehind) {
@@ -97013,6 +97054,11 @@ function promptContent(command) {
97013
97054
  return content;
97014
97055
  }
97015
97056
  async function settleAbandonedTurn(projection, operations, cancellation) {
97057
+ const outcome = operations.recordCancellationBeforeAdmission(cancellation.commandId, cancellation.sessionId);
97058
+ if (outcome !== void 0) {
97059
+ await projection.replayOutcome(cancellation.sessionId, outcome);
97060
+ return;
97061
+ }
97016
97062
  const attemptId = operations.findUnsettledAttemptId(cancellation.commandId, cancellation.sessionId);
97017
97063
  if (attemptId === null) {
97018
97064
  console.warn("Mobius daemon ignored cancellation for an inactive turn");
@@ -97233,6 +97279,33 @@ var init_execution_receipts = __esm({
97233
97279
  const receipt = this.#executions.get(commandId);
97234
97280
  return receipt?.outcome === null || receipt === void 0 ? void 0 : sessionEventPayloadSchema.parse(JSON.parse(receipt.outcome));
97235
97281
  };
97282
+ /** Reserves an unseen command for cancellation before a delayed prompt can claim its identity. */
97283
+ recordCancellationBeforeAdmission = (commandId, sessionId) => {
97284
+ const existing = this.#executions.get(commandId);
97285
+ if (existing !== void 0) {
97286
+ return existing.sessionId === sessionId && isTerminal(existing.state) ? this.outcome(commandId) : void 0;
97287
+ }
97288
+ const outcome = {
97289
+ type: "lifecycle-metadata",
97290
+ payload: { kind: "prompt.completed", commandId, stopReason: "cancelled" }
97291
+ };
97292
+ const commandHash = createHash7("sha256").update(
97293
+ encodeSessionCancelBeforeStartCommand({
97294
+ commandId,
97295
+ kind: "session.cancel-before-start",
97296
+ sessionId
97297
+ })
97298
+ ).digest("hex");
97299
+ this.#save(commandId, {
97300
+ attemptId: randomUUID16(),
97301
+ commandHash,
97302
+ sessionId,
97303
+ state: "cancelled",
97304
+ started: false,
97305
+ outcome: JSON.stringify({ ...outcome, recordedAt: (/* @__PURE__ */ new Date()).toISOString() })
97306
+ });
97307
+ return outcome;
97308
+ };
97236
97309
  recordOutcome = (event) => {
97237
97310
  if (event.type !== "lifecycle-metadata") {
97238
97311
  return;
@@ -100045,11 +100118,12 @@ var init_history3 = __esm({
100045
100118
  });
100046
100119
 
100047
100120
  // src/runtime/command/registry/interactions.ts
100048
- var sessionCancelCommand, sessionCloseCommand, promptDispositionCommand, permissionRespondCommand, elicitationRespondCommand;
100121
+ var sessionCancelCommand, sessionCancelBeforeStartCommand, sessionCloseCommand, promptDispositionCommand, permissionRespondCommand, elicitationRespondCommand;
100049
100122
  var init_interactions2 = __esm({
100050
100123
  "src/runtime/command/registry/interactions.ts"() {
100051
100124
  "use strict";
100052
100125
  init_protocol();
100126
+ init_session_error();
100053
100127
  init_prompt_lifecycle();
100054
100128
  init_transport();
100055
100129
  sessionCancelCommand = {
@@ -100074,6 +100148,41 @@ var init_interactions2 = __esm({
100074
100148
  });
100075
100149
  }
100076
100150
  };
100151
+ sessionCancelBeforeStartCommand = {
100152
+ kind: SESSION_CANCEL_BEFORE_START_KIND,
100153
+ handle: ({ eventProjection, operations, sessionTurns, socket }, message) => {
100154
+ if (message.kind !== SESSION_CANCEL_BEFORE_START_KIND) {
100155
+ throw new Error("Command kind mismatch");
100156
+ }
100157
+ const turn = sessionTurns.get(message.commandId, message.sessionId);
100158
+ if (turn === void 0) {
100159
+ const outcome = operations.recordCancellationBeforeAdmission(message.commandId, message.sessionId);
100160
+ if (outcome !== void 0) {
100161
+ void eventProjection.replayOutcome(message.sessionId, outcome).catch((error62) => {
100162
+ reportOperationFailure(socket, message.commandId, message.sessionId, error62);
100163
+ });
100164
+ return;
100165
+ }
100166
+ reportOperationFailure(
100167
+ socket,
100168
+ message.commandId,
100169
+ message.sessionId,
100170
+ new SessionError("turn_not_active", "The command is not waiting to start")
100171
+ );
100172
+ return;
100173
+ }
100174
+ if (turn.snapshot() !== null) {
100175
+ reportOperationFailure(
100176
+ socket,
100177
+ message.commandId,
100178
+ message.sessionId,
100179
+ new SessionError("turn_already_started", "The command already started")
100180
+ );
100181
+ return;
100182
+ }
100183
+ turn.requestCancellation();
100184
+ }
100185
+ };
100077
100186
  sessionCloseCommand = {
100078
100187
  kind: SESSION_CLOSE_KIND,
100079
100188
  handle: ({ sessions, signal, socket }, message) => {
@@ -101243,6 +101352,7 @@ function createCommandRegistry(context) {
101243
101352
  ...createAgentSettingsCommands(context),
101244
101353
  ...contentWrites.commands,
101245
101354
  fileReadCommand,
101355
+ sessionCancelBeforeStartCommand,
101246
101356
  sessionCancelCommand,
101247
101357
  sessionCloseCommand,
101248
101358
  promptDispositionCommand,