@moxt-ai/mobius 0.0.45 → 0.0.46

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.46",
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 = null;
34361
34351
  #capabilities = {
34362
34352
  additionalDirectories: false,
34363
34353
  audioPrompt: false,
@@ -34531,26 +34521,37 @@ 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
+ if (this.#bufferedAgentText !== null && this.#bufferedAgentText.messageId !== messageId) {
34540
+ await this.emitAgentMessage(this.#bufferedAgentText.chunks, this.#bufferedAgentText.messageId);
34541
+ this.#bufferedAgentText = null;
34542
+ }
34543
+ this.#bufferedAgentText = {
34544
+ chunks: [...this.#bufferedAgentText?.chunks ?? [], text3],
34545
+ messageId
34546
+ };
34547
+ };
34548
+ flushAgentText = async () => {
34549
+ const buffered = this.#bufferedAgentText;
34550
+ this.#bufferedAgentText = null;
34551
+ if (buffered !== null) {
34552
+ await this.emitAgentMessage(buffered.chunks, buffered.messageId);
34553
+ }
34554
+ };
34554
34555
  prepareAgentContent = async (content3) => {
34555
34556
  if (content3.type === "image" && content3.data.length > 0) {
34556
34557
  const raster = readInlineRaster(content3.data, content3.name);
@@ -34560,7 +34561,7 @@ var AcpProcessSession = class _AcpProcessSession {
34560
34561
  }
34561
34562
  if (content3.type === "image" && content3.data.length === 0 && content3.uri.length > 0) {
34562
34563
  const signal = AbortSignal.timeout(2e4);
34563
- const raster = await readAuthorizedRaster(content3.uri, this.imageRoots(), signal);
34564
+ const raster = await readLocalRaster(content3.uri, signal);
34564
34565
  if (raster !== null) {
34565
34566
  return await this.importRaster(raster, signal);
34566
34567
  }
@@ -35030,6 +35031,7 @@ var AcpProcessSession = class _AcpProcessSession {
35030
35031
  options.signal
35031
35032
  );
35032
35033
  await this.#updateTail;
35034
+ await this.flushAgentText();
35033
35035
  await running.activities.finish();
35034
35036
  let result;
35035
35037
  try {
@@ -35061,6 +35063,7 @@ var AcpProcessSession = class _AcpProcessSession {
35061
35063
  cause: error62
35062
35064
  });
35063
35065
  } finally {
35066
+ this.#bufferedAgentText = null;
35064
35067
  this.#turn = new IdleAcpTurn();
35065
35068
  }
35066
35069
  };
@@ -35352,10 +35355,11 @@ var AcpProcessSession = class _AcpProcessSession {
35352
35355
  );
35353
35356
  } else {
35354
35357
  await this.#turn.activities.finishNarrative();
35355
- await this.emitAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
35358
+ await this.bufferAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
35356
35359
  }
35357
35360
  } else {
35358
35361
  await this.#turn.activities.finishNarrative();
35362
+ await this.flushAgentText();
35359
35363
  await this.emitAgentContent(
35360
35364
  normalizeContentBlock(update.content),
35361
35365
  truncate3(update.messageId ?? "", 255)
@@ -37551,7 +37555,7 @@ var LocalAuthorizationError = class extends Error {
37551
37555
  // src/authorization/workspace-directory.ts
37552
37556
  import { readdir as readdir2, realpath as realpath8, stat as stat7 } from "node:fs/promises";
37553
37557
  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";
37558
+ import { basename as basename4, dirname as dirname5, isAbsolute as isAbsolute9, join as join16, normalize as normalize3, relative as relative4 } from "node:path";
37555
37559
  var WorkspaceDirectoryListing = class {
37556
37560
  directoryId;
37557
37561
  directoryLabel;
@@ -37634,7 +37638,7 @@ var WorkspaceDirectoryService = class {
37634
37638
  }
37635
37639
  };
37636
37640
  label = (path2) => {
37637
- const suffix = relative5(homedir2(), path2);
37641
+ const suffix = relative4(homedir2(), path2);
37638
37642
  return suffix === "" ? "~" : !isAbsolute9(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
37639
37643
  };
37640
37644
  identify = async (bindingId, requestedPath, signal) => {
@@ -38372,7 +38376,7 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
38372
38376
  const snapshot = await response.promise;
38373
38377
  return {
38374
38378
  ...snapshot,
38375
- history: await embedLocalHistoryImages(snapshot.history, [cwd, snapshot.cwd], signal)
38379
+ history: await embedLocalHistoryImages(snapshot.history, signal)
38376
38380
  };
38377
38381
  } finally {
38378
38382
  clearTimeout(timeout);
@@ -39969,17 +39973,7 @@ var DaemonAcpObserver = class {
39969
39973
  this.#config = config2;
39970
39974
  this.#record = record4;
39971
39975
  }
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
- };
39976
+ importLocalArtifact = async (sessionId, artifact, signal) => (await uploadRuntimeArtifact(this.#config, sessionId, artifact, signal)).artifactId;
39983
39977
  onCommands = (event) => {
39984
39978
  this.#record(event.sessionId, encodeSessionCommandsUpdatedEvent(event));
39985
39979
  return Promise.resolve();
@@ -41021,24 +41015,55 @@ function assertPreparedPermission(configOptions, permissionMode) {
41021
41015
  );
41022
41016
  }
41023
41017
  }
41024
- async function applyRequiredExecutionSelection(sessions, configOptions, selection, category, agent, cwd, additionalDirectories, sessionId, signal) {
41018
+ function warnIgnoredExecutionSetting(audit, commandId, sessionId, agentId, selection, category, reason) {
41019
+ const details = {
41020
+ agentId,
41021
+ category,
41022
+ configId: selection.configId,
41023
+ reason,
41024
+ requestedValue: selection.value
41025
+ };
41026
+ const event = "bot_execution_setting_ignored";
41027
+ audit.record({ commandId, details, event, sessionId });
41028
+ process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
41029
+ `);
41030
+ }
41031
+ async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
41032
+ if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
41033
+ return configOptions;
41034
+ }
41025
41035
  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"
41036
+ if (option2 === void 0) {
41037
+ warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "setting_unavailable");
41038
+ return configOptions;
41039
+ }
41040
+ if (option2.type !== "select" || option2.category !== category) {
41041
+ warnIgnoredExecutionSetting(
41042
+ audit,
41043
+ commandId,
41044
+ sessionId,
41045
+ agent.id,
41046
+ selection,
41047
+ category,
41048
+ "setting_schema_mismatch"
41031
41049
  );
41050
+ return configOptions;
41032
41051
  }
41033
- if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
41052
+ if (selection.valueType !== "select" || selection.booleanValue) {
41053
+ warnIgnoredExecutionSetting(
41054
+ audit,
41055
+ commandId,
41056
+ sessionId,
41057
+ agent.id,
41058
+ selection,
41059
+ category,
41060
+ "selection_schema_mismatch"
41061
+ );
41034
41062
  return configOptions;
41035
41063
  }
41036
41064
  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
- );
41065
+ warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "value_unavailable");
41066
+ return configOptions;
41042
41067
  }
41043
41068
  if (option2.currentValue === selection.value) {
41044
41069
  return configOptions;
@@ -41137,25 +41162,29 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41137
41162
  signal: executionSignal
41138
41163
  });
41139
41164
  assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
41140
- let configOptions = await applyRequiredExecutionSelection(
41165
+ let configOptions = await applySupportedExecutionSelection(
41141
41166
  sessions,
41167
+ audit,
41142
41168
  prepared.configOptions,
41143
41169
  execution.executionConfiguration.model,
41144
41170
  "model",
41145
41171
  agent,
41146
41172
  resolved.cwd,
41147
41173
  resolved.additionalDirectories,
41174
+ command.commandId,
41148
41175
  command.sessionId,
41149
41176
  executionSignal
41150
41177
  );
41151
- configOptions = await applyRequiredExecutionSelection(
41178
+ configOptions = await applySupportedExecutionSelection(
41152
41179
  sessions,
41180
+ audit,
41153
41181
  configOptions,
41154
41182
  execution.executionConfiguration.reasoningEffort,
41155
41183
  "thought_level",
41156
41184
  agent,
41157
41185
  resolved.cwd,
41158
41186
  resolved.additionalDirectories,
41187
+ command.commandId,
41159
41188
  command.sessionId,
41160
41189
  executionSignal
41161
41190
  );