@moxt-ai/mobius 0.0.45 → 0.0.47

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
@@ -11,7 +11,7 @@ import { mkdir as mkdir5 } from "node:fs/promises";
11
11
  // package.json
12
12
  var package_default = {
13
13
  name: "@moxt-ai/mobius",
14
- version: "0.0.45",
14
+ version: "0.0.47",
15
15
  description: "Mobius CLI for pairing and running local AI agent services.",
16
16
  type: "module",
17
17
  bin: {
@@ -24999,7 +24999,7 @@ import {
24999
24999
 
25000
25000
  // src/authorization/local-raster.ts
25001
25001
  import { readFile as readFile2, realpath as realpath7, stat as stat6 } from "node:fs/promises";
25002
- import { basename as basename2, isAbsolute as isAbsolute8, normalize as normalize2, relative as relative4, sep as sep4 } from "node:path";
25002
+ import { basename as basename2, isAbsolute as isAbsolute8, normalize as normalize2 } from "node:path";
25003
25003
  import { fileURLToPath } from "node:url";
25004
25004
  var MAX_LOCAL_RASTER_BYTES = 3e6;
25005
25005
  var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71);
@@ -25057,10 +25057,6 @@ function readInlineRaster(data, name = "Image") {
25057
25057
  }
25058
25058
  return new LocalRasterImage(basename2(name) || "Image", mimeType, bytes);
25059
25059
  }
25060
- function isInsideRoot(root, target) {
25061
- const relation = relative4(root, target);
25062
- return relation !== ".." && !relation.startsWith(`..${sep4}`) && !isAbsolute8(relation);
25063
- }
25064
25060
  async function resolveCanonicalPath(requested, signal) {
25065
25061
  signal.throwIfAborted();
25066
25062
  if (!isAbsolute8(requested) || requested.includes("\0") || normalize2(requested) !== requested) {
@@ -25105,7 +25101,7 @@ function parseLocalImageUri(uri) {
25105
25101
  }
25106
25102
  return trimmed;
25107
25103
  }
25108
- async function readAuthorizedRaster(uri, roots, signal) {
25104
+ async function readLocalRaster(uri, signal) {
25109
25105
  signal.throwIfAborted();
25110
25106
  const requested = parseLocalImageUri(uri);
25111
25107
  if (requested === null) {
@@ -25120,21 +25116,6 @@ async function readAuthorizedRaster(uri, roots, signal) {
25120
25116
  if (!targetMetadata.isFile() || targetMetadata.size < 1 || targetMetadata.size > MAX_LOCAL_RASTER_BYTES) {
25121
25117
  return null;
25122
25118
  }
25123
- const authorizedRoots = [];
25124
- for (const root of roots) {
25125
- const directory = await resolveCanonicalPath(root, signal);
25126
- if (directory === null) {
25127
- continue;
25128
- }
25129
- const metadata = await stat6(directory);
25130
- signal.throwIfAborted();
25131
- if (metadata.isDirectory()) {
25132
- authorizedRoots.push(directory);
25133
- }
25134
- }
25135
- if (!authorizedRoots.some((root) => isInsideRoot(root, target))) {
25136
- return null;
25137
- }
25138
25119
  const bytes = new Uint8Array(await readFile2(target));
25139
25120
  signal.throwIfAborted();
25140
25121
  if (bytes.byteLength < 1 || bytes.byteLength > MAX_LOCAL_RASTER_BYTES) {
@@ -25233,7 +25214,7 @@ var unmeasuredOperationMetrics = Object.freeze({
25233
25214
 
25234
25215
  // src/native-sessions/history-images.ts
25235
25216
  var IMAGE_MARKER = /\[@image\]\(([^)\r\n]*)(?:\)|$)/g;
25236
- async function embedLocalHistoryImages(history, roots, signal) {
25217
+ async function embedLocalHistoryImages(history, signal) {
25237
25218
  if (history.status !== "available") {
25238
25219
  return history;
25239
25220
  }
@@ -25241,7 +25222,7 @@ async function embedLocalHistoryImages(history, roots, signal) {
25241
25222
  let imageCharacters = 0;
25242
25223
  for (const message of history.messages) {
25243
25224
  signal.throwIfAborted();
25244
- const resolved = await resolveMessageImages(message, roots, imageCharacters, signal);
25225
+ const resolved = await resolveMessageImages(message, imageCharacters, signal);
25245
25226
  imageCharacters += (resolved.images ?? []).reduce((size, image) => size + image.data.length, 0);
25246
25227
  messages.push(resolved);
25247
25228
  }
@@ -25250,7 +25231,7 @@ async function embedLocalHistoryImages(history, roots, signal) {
25250
25231
  messages
25251
25232
  };
25252
25233
  }
25253
- async function resolveMessageImages(message, roots, usedCharacters, signal) {
25234
+ async function resolveMessageImages(message, usedCharacters, signal) {
25254
25235
  const images = [...message.images ?? []];
25255
25236
  let imageCharacters = images.reduce((size, image) => size + image.data.length, 0);
25256
25237
  const text3 = await replaceImageMarkers(message.text, async (uri) => {
@@ -25266,7 +25247,7 @@ async function resolveMessageImages(message, roots, usedCharacters, signal) {
25266
25247
  imageCharacters += embedded.data.length;
25267
25248
  return "";
25268
25249
  }
25269
- const local = await readAuthorizedRaster(uri, roots, signal);
25250
+ const local = await readLocalRaster(uri, signal);
25270
25251
  if (local === null) {
25271
25252
  return "[Image unavailable]";
25272
25253
  }
@@ -32998,16 +32979,24 @@ function parseMarkdownImages(markdown) {
32998
32979
  });
32999
32980
  return images.sort((left, right) => left.start - right.start);
33000
32981
  }
33001
- async function emitMarkdownWithLocalImages(options) {
32982
+ async function emitMarkdownChunksWithLocalImages(options) {
32983
+ const markdown = options.chunks.join("");
32984
+ const images = parseMarkdownImages(markdown);
32985
+ if (images.length === 0) {
32986
+ for (const chunk of options.chunks) {
32987
+ await options.onText(chunk);
32988
+ }
32989
+ return;
32990
+ }
33002
32991
  let cursor = 0;
33003
- for (const image of parseMarkdownImages(options.markdown)) {
32992
+ for (const image of images) {
33004
32993
  if (image.start < cursor) {
33005
32994
  continue;
33006
32995
  }
33007
32996
  if (image.start > cursor) {
33008
- await options.onText(options.markdown.slice(cursor, image.start));
32997
+ await options.onText(markdown.slice(cursor, image.start));
33009
32998
  }
33010
- const raster = await readAuthorizedRaster(image.uri, options.roots, options.signal);
32999
+ const raster = await readLocalRaster(image.uri, options.signal);
33011
33000
  if (raster === null) {
33012
33001
  await options.onText("[Image unavailable]");
33013
33002
  } else {
@@ -33015,8 +33004,8 @@ async function emitMarkdownWithLocalImages(options) {
33015
33004
  }
33016
33005
  cursor = image.end;
33017
33006
  }
33018
- if (cursor < options.markdown.length) {
33019
- await options.onText(options.markdown.slice(cursor));
33007
+ if (cursor < markdown.length) {
33008
+ await options.onText(markdown.slice(cursor));
33020
33009
  }
33021
33010
  }
33022
33011
 
@@ -34358,6 +34347,7 @@ var AcpProcessSession = class _AcpProcessSession {
34358
34347
  #preSessionUpdateBytes = 0;
34359
34348
  #agentName = "";
34360
34349
  #agentVersion = "";
34350
+ #bufferedAgentText = [];
34361
34351
  #capabilities = {
34362
34352
  additionalDirectories: false,
34363
34353
  audioPrompt: false,
@@ -34531,26 +34521,47 @@ var AcpProcessSession = class _AcpProcessSession {
34531
34521
  );
34532
34522
  await this.#updateTail;
34533
34523
  signal.throwIfAborted();
34534
- return await embedLocalHistoryImages(
34535
- history.snapshot(),
34536
- [this.#cwd, ...this.#additionalDirectories],
34537
- signal
34538
- );
34524
+ return await embedLocalHistoryImages(history.snapshot(), signal);
34539
34525
  } finally {
34540
34526
  this.#replay = { kind: "idle" };
34541
34527
  }
34542
34528
  };
34543
- imageRoots = () => [this.#cwd, ...this.#additionalDirectories];
34544
- emitAgentText = async (text3, messageId) => {
34529
+ emitAgentMessage = async (chunks, messageId) => {
34545
34530
  const signal = AbortSignal.timeout(2e4);
34546
- await emitMarkdownWithLocalImages({
34547
- markdown: text3,
34531
+ await emitMarkdownChunksWithLocalImages({
34532
+ chunks,
34548
34533
  onImage: async (image) => await this.emitRaster(image, messageId, signal),
34549
34534
  onText: async (content3) => await this.#turn.onText(content3, messageId),
34550
- roots: this.imageRoots(),
34551
34535
  signal
34552
34536
  });
34553
34537
  };
34538
+ bufferAgentText = async (text3, messageId) => {
34539
+ const previous2 = this.#bufferedAgentText.at(-1);
34540
+ if (previous2?.messageId === messageId) {
34541
+ this.#bufferedAgentText = [
34542
+ ...this.#bufferedAgentText.slice(0, -1),
34543
+ { chunks: [...previous2.chunks, text3], messageId }
34544
+ ];
34545
+ return;
34546
+ }
34547
+ this.#bufferedAgentText = [...this.#bufferedAgentText, { chunks: [text3], messageId }];
34548
+ };
34549
+ flushAgentText = async () => {
34550
+ const buffered = this.#bufferedAgentText;
34551
+ this.#bufferedAgentText = [];
34552
+ for (const message of buffered) {
34553
+ await this.emitAgentMessage(message.chunks, message.messageId);
34554
+ }
34555
+ };
34556
+ recordBufferedAgentTextAsProgress = async () => {
34557
+ const buffered = this.#bufferedAgentText;
34558
+ this.#bufferedAgentText = [];
34559
+ for (const message of buffered) {
34560
+ for (const chunk of message.chunks) {
34561
+ await this.#turn.activities.recordNarrative("progress", message.messageId, chunk);
34562
+ }
34563
+ }
34564
+ };
34554
34565
  prepareAgentContent = async (content3) => {
34555
34566
  if (content3.type === "image" && content3.data.length > 0) {
34556
34567
  const raster = readInlineRaster(content3.data, content3.name);
@@ -34560,7 +34571,7 @@ var AcpProcessSession = class _AcpProcessSession {
34560
34571
  }
34561
34572
  if (content3.type === "image" && content3.data.length === 0 && content3.uri.length > 0) {
34562
34573
  const signal = AbortSignal.timeout(2e4);
34563
- const raster = await readAuthorizedRaster(content3.uri, this.imageRoots(), signal);
34574
+ const raster = await readLocalRaster(content3.uri, signal);
34564
34575
  if (raster !== null) {
34565
34576
  return await this.importRaster(raster, signal);
34566
34577
  }
@@ -35030,6 +35041,7 @@ var AcpProcessSession = class _AcpProcessSession {
35030
35041
  options.signal
35031
35042
  );
35032
35043
  await this.#updateTail;
35044
+ await this.flushAgentText();
35033
35045
  await running.activities.finish();
35034
35046
  let result;
35035
35047
  try {
@@ -35061,6 +35073,7 @@ var AcpProcessSession = class _AcpProcessSession {
35061
35073
  cause: error62
35062
35074
  });
35063
35075
  } finally {
35076
+ this.#bufferedAgentText = [];
35064
35077
  this.#turn = new IdleAcpTurn();
35065
35078
  }
35066
35079
  };
@@ -35352,10 +35365,11 @@ var AcpProcessSession = class _AcpProcessSession {
35352
35365
  );
35353
35366
  } else {
35354
35367
  await this.#turn.activities.finishNarrative();
35355
- await this.emitAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
35368
+ await this.bufferAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
35356
35369
  }
35357
35370
  } else {
35358
35371
  await this.#turn.activities.finishNarrative();
35372
+ await this.flushAgentText();
35359
35373
  await this.emitAgentContent(
35360
35374
  normalizeContentBlock(update.content),
35361
35375
  truncate3(update.messageId ?? "", 255)
@@ -35374,6 +35388,7 @@ var AcpProcessSession = class _AcpProcessSession {
35374
35388
  return;
35375
35389
  }
35376
35390
  if (update.sessionUpdate === "tool_call") {
35391
+ await this.recordBufferedAgentTextAsProgress();
35377
35392
  await this.#turn.activities.recordToolCall(update);
35378
35393
  return;
35379
35394
  }
@@ -37551,7 +37566,7 @@ var LocalAuthorizationError = class extends Error {
37551
37566
  // src/authorization/workspace-directory.ts
37552
37567
  import { readdir as readdir2, realpath as realpath8, stat as stat7 } from "node:fs/promises";
37553
37568
  import { homedir as homedir2 } from "node:os";
37554
- import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute9, join as join16, normalize as normalize3, relative as relative5 } from "node:path";
37569
+ import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute9, join as join16, normalize as normalize3, relative as relative4 } from "node:path";
37555
37570
  var WorkspaceDirectoryListing = class {
37556
37571
  directoryId;
37557
37572
  directoryLabel;
@@ -37634,7 +37649,7 @@ var WorkspaceDirectoryService = class {
37634
37649
  }
37635
37650
  };
37636
37651
  label = (path2) => {
37637
- const suffix = relative5(homedir2(), path2);
37652
+ const suffix = relative4(homedir2(), path2);
37638
37653
  return suffix === "" ? "~" : !isAbsolute9(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
37639
37654
  };
37640
37655
  identify = async (bindingId, requestedPath, signal) => {
@@ -38372,7 +38387,7 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
38372
38387
  const snapshot = await response.promise;
38373
38388
  return {
38374
38389
  ...snapshot,
38375
- history: await embedLocalHistoryImages(snapshot.history, [cwd, snapshot.cwd], signal)
38390
+ history: await embedLocalHistoryImages(snapshot.history, signal)
38376
38391
  };
38377
38392
  } finally {
38378
38393
  clearTimeout(timeout);
@@ -39969,17 +39984,7 @@ var DaemonAcpObserver = class {
39969
39984
  this.#config = config2;
39970
39985
  this.#record = record4;
39971
39986
  }
39972
- importLocalArtifact = async (sessionId, artifact, signal) => {
39973
- try {
39974
- return (await uploadRuntimeArtifact(this.#config, sessionId, artifact, signal)).artifactId;
39975
- } catch (cause) {
39976
- signal.throwIfAborted();
39977
- if (cause instanceof Error && cause.name === "AbortError") {
39978
- throw cause;
39979
- }
39980
- return "";
39981
- }
39982
- };
39987
+ importLocalArtifact = async (sessionId, artifact, signal) => (await uploadRuntimeArtifact(this.#config, sessionId, artifact, signal)).artifactId;
39983
39988
  onCommands = (event) => {
39984
39989
  this.#record(event.sessionId, encodeSessionCommandsUpdatedEvent(event));
39985
39990
  return Promise.resolve();
@@ -41021,24 +41026,55 @@ function assertPreparedPermission(configOptions, permissionMode) {
41021
41026
  );
41022
41027
  }
41023
41028
  }
41024
- async function applyRequiredExecutionSelection(sessions, configOptions, selection, category, agent, cwd, additionalDirectories, sessionId, signal) {
41029
+ function warnIgnoredExecutionSetting(audit, commandId, sessionId, agentId, selection, category, reason) {
41030
+ const details = {
41031
+ agentId,
41032
+ category,
41033
+ configId: selection.configId,
41034
+ reason,
41035
+ requestedValue: selection.value
41036
+ };
41037
+ const event = "bot_execution_setting_ignored";
41038
+ audit.record({ commandId, details, event, sessionId });
41039
+ process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
41040
+ `);
41041
+ }
41042
+ async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
41043
+ if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
41044
+ return configOptions;
41045
+ }
41025
41046
  const option2 = configOptions.find((candidate) => candidate.id === selection.configId);
41026
- if (option2 === void 0 || option2.type !== "select" || option2.category !== category || selection.valueType !== "select" || selection.booleanValue) {
41027
- throw new AcpExecutionError(
41028
- `The required Agent setting ${selection.configId} is unavailable`,
41029
- {},
41030
- "invalid_session_configuration"
41047
+ if (option2 === void 0) {
41048
+ warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "setting_unavailable");
41049
+ return configOptions;
41050
+ }
41051
+ if (option2.type !== "select" || option2.category !== category) {
41052
+ warnIgnoredExecutionSetting(
41053
+ audit,
41054
+ commandId,
41055
+ sessionId,
41056
+ agent.id,
41057
+ selection,
41058
+ category,
41059
+ "setting_schema_mismatch"
41031
41060
  );
41061
+ return configOptions;
41032
41062
  }
41033
- if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
41063
+ if (selection.valueType !== "select" || selection.booleanValue) {
41064
+ warnIgnoredExecutionSetting(
41065
+ audit,
41066
+ commandId,
41067
+ sessionId,
41068
+ agent.id,
41069
+ selection,
41070
+ category,
41071
+ "selection_schema_mismatch"
41072
+ );
41034
41073
  return configOptions;
41035
41074
  }
41036
41075
  if (!option2.values.some((value) => value.value === selection.value)) {
41037
- throw new AcpExecutionError(
41038
- `The required Agent setting ${selection.configId} is unavailable`,
41039
- {},
41040
- "invalid_session_configuration"
41041
- );
41076
+ warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "value_unavailable");
41077
+ return configOptions;
41042
41078
  }
41043
41079
  if (option2.currentValue === selection.value) {
41044
41080
  return configOptions;
@@ -41137,25 +41173,29 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41137
41173
  signal: executionSignal
41138
41174
  });
41139
41175
  assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
41140
- let configOptions = await applyRequiredExecutionSelection(
41176
+ let configOptions = await applySupportedExecutionSelection(
41141
41177
  sessions,
41178
+ audit,
41142
41179
  prepared.configOptions,
41143
41180
  execution.executionConfiguration.model,
41144
41181
  "model",
41145
41182
  agent,
41146
41183
  resolved.cwd,
41147
41184
  resolved.additionalDirectories,
41185
+ command.commandId,
41148
41186
  command.sessionId,
41149
41187
  executionSignal
41150
41188
  );
41151
- configOptions = await applyRequiredExecutionSelection(
41189
+ configOptions = await applySupportedExecutionSelection(
41152
41190
  sessions,
41191
+ audit,
41153
41192
  configOptions,
41154
41193
  execution.executionConfiguration.reasoningEffort,
41155
41194
  "thought_level",
41156
41195
  agent,
41157
41196
  resolved.cwd,
41158
41197
  resolved.additionalDirectories,
41198
+ command.commandId,
41159
41199
  command.sessionId,
41160
41200
  executionSignal
41161
41201
  );