@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/index.js CHANGED
@@ -22328,7 +22328,7 @@ import {
22328
22328
 
22329
22329
  // src/authorization/local-raster.ts
22330
22330
  import { readFile as readFile2, realpath as realpath2, stat as stat2 } from "node:fs/promises";
22331
- import { basename, isAbsolute, normalize, relative, sep } from "node:path";
22331
+ import { basename, isAbsolute, normalize } from "node:path";
22332
22332
  import { fileURLToPath as fileURLToPath2 } from "node:url";
22333
22333
  var MAX_LOCAL_RASTER_BYTES = 3e6;
22334
22334
  var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71);
@@ -22386,10 +22386,6 @@ function readInlineRaster(data, name = "Image") {
22386
22386
  }
22387
22387
  return new LocalRasterImage(basename(name) || "Image", mimeType, bytes);
22388
22388
  }
22389
- function isInsideRoot(root, target) {
22390
- const relation = relative(root, target);
22391
- return relation !== ".." && !relation.startsWith(`..${sep}`) && !isAbsolute(relation);
22392
- }
22393
22389
  async function resolveCanonicalPath(requested, signal) {
22394
22390
  signal.throwIfAborted();
22395
22391
  if (!isAbsolute(requested) || requested.includes("\0") || normalize(requested) !== requested) {
@@ -22434,7 +22430,7 @@ function parseLocalImageUri(uri) {
22434
22430
  }
22435
22431
  return trimmed;
22436
22432
  }
22437
- async function readAuthorizedRaster(uri, roots, signal) {
22433
+ async function readLocalRaster(uri, signal) {
22438
22434
  signal.throwIfAborted();
22439
22435
  const requested = parseLocalImageUri(uri);
22440
22436
  if (requested === null) {
@@ -22449,21 +22445,6 @@ async function readAuthorizedRaster(uri, roots, signal) {
22449
22445
  if (!targetMetadata.isFile() || targetMetadata.size < 1 || targetMetadata.size > MAX_LOCAL_RASTER_BYTES) {
22450
22446
  return null;
22451
22447
  }
22452
- const authorizedRoots = [];
22453
- for (const root of roots) {
22454
- const directory = await resolveCanonicalPath(root, signal);
22455
- if (directory === null) {
22456
- continue;
22457
- }
22458
- const metadata = await stat2(directory);
22459
- signal.throwIfAborted();
22460
- if (metadata.isDirectory()) {
22461
- authorizedRoots.push(directory);
22462
- }
22463
- }
22464
- if (!authorizedRoots.some((root) => isInsideRoot(root, target))) {
22465
- return null;
22466
- }
22467
22448
  const bytes = new Uint8Array(await readFile2(target));
22468
22449
  signal.throwIfAborted();
22469
22450
  if (bytes.byteLength < 1 || bytes.byteLength > MAX_LOCAL_RASTER_BYTES) {
@@ -22562,7 +22543,7 @@ var unmeasuredOperationMetrics = Object.freeze({
22562
22543
 
22563
22544
  // src/native-sessions/history-images.ts
22564
22545
  var IMAGE_MARKER = /\[@image\]\(([^)\r\n]*)(?:\)|$)/g;
22565
- async function embedLocalHistoryImages(history, roots, signal) {
22546
+ async function embedLocalHistoryImages(history, signal) {
22566
22547
  if (history.status !== "available") {
22567
22548
  return history;
22568
22549
  }
@@ -22570,7 +22551,7 @@ async function embedLocalHistoryImages(history, roots, signal) {
22570
22551
  let imageCharacters = 0;
22571
22552
  for (const message of history.messages) {
22572
22553
  signal.throwIfAborted();
22573
- const resolved = await resolveMessageImages(message, roots, imageCharacters, signal);
22554
+ const resolved = await resolveMessageImages(message, imageCharacters, signal);
22574
22555
  imageCharacters += (resolved.images ?? []).reduce((size, image) => size + image.data.length, 0);
22575
22556
  messages.push(resolved);
22576
22557
  }
@@ -22579,7 +22560,7 @@ async function embedLocalHistoryImages(history, roots, signal) {
22579
22560
  messages
22580
22561
  };
22581
22562
  }
22582
- async function resolveMessageImages(message, roots, usedCharacters, signal) {
22563
+ async function resolveMessageImages(message, usedCharacters, signal) {
22583
22564
  const images = [...message.images ?? []];
22584
22565
  let imageCharacters = images.reduce((size, image) => size + image.data.length, 0);
22585
22566
  const text3 = await replaceImageMarkers(message.text, async (uri) => {
@@ -22595,7 +22576,7 @@ async function resolveMessageImages(message, roots, usedCharacters, signal) {
22595
22576
  imageCharacters += embedded.data.length;
22596
22577
  return "";
22597
22578
  }
22598
- const local = await readAuthorizedRaster(uri, roots, signal);
22579
+ const local = await readLocalRaster(uri, signal);
22599
22580
  if (local === null) {
22600
22581
  return "[Image unavailable]";
22601
22582
  }
@@ -30327,16 +30308,24 @@ function parseMarkdownImages(markdown) {
30327
30308
  });
30328
30309
  return images.sort((left, right) => left.start - right.start);
30329
30310
  }
30330
- async function emitMarkdownWithLocalImages(options) {
30311
+ async function emitMarkdownChunksWithLocalImages(options) {
30312
+ const markdown = options.chunks.join("");
30313
+ const images = parseMarkdownImages(markdown);
30314
+ if (images.length === 0) {
30315
+ for (const chunk of options.chunks) {
30316
+ await options.onText(chunk);
30317
+ }
30318
+ return;
30319
+ }
30331
30320
  let cursor = 0;
30332
- for (const image of parseMarkdownImages(options.markdown)) {
30321
+ for (const image of images) {
30333
30322
  if (image.start < cursor) {
30334
30323
  continue;
30335
30324
  }
30336
30325
  if (image.start > cursor) {
30337
- await options.onText(options.markdown.slice(cursor, image.start));
30326
+ await options.onText(markdown.slice(cursor, image.start));
30338
30327
  }
30339
- const raster = await readAuthorizedRaster(image.uri, options.roots, options.signal);
30328
+ const raster = await readLocalRaster(image.uri, options.signal);
30340
30329
  if (raster === null) {
30341
30330
  await options.onText("[Image unavailable]");
30342
30331
  } else {
@@ -30344,8 +30333,8 @@ async function emitMarkdownWithLocalImages(options) {
30344
30333
  }
30345
30334
  cursor = image.end;
30346
30335
  }
30347
- if (cursor < options.markdown.length) {
30348
- await options.onText(options.markdown.slice(cursor));
30336
+ if (cursor < markdown.length) {
30337
+ await options.onText(markdown.slice(cursor));
30349
30338
  }
30350
30339
  }
30351
30340
 
@@ -31687,6 +31676,7 @@ var AcpProcessSession = class _AcpProcessSession {
31687
31676
  #preSessionUpdateBytes = 0;
31688
31677
  #agentName = "";
31689
31678
  #agentVersion = "";
31679
+ #bufferedAgentText = null;
31690
31680
  #capabilities = {
31691
31681
  additionalDirectories: false,
31692
31682
  audioPrompt: false,
@@ -31860,26 +31850,37 @@ var AcpProcessSession = class _AcpProcessSession {
31860
31850
  );
31861
31851
  await this.#updateTail;
31862
31852
  signal.throwIfAborted();
31863
- return await embedLocalHistoryImages(
31864
- history.snapshot(),
31865
- [this.#cwd, ...this.#additionalDirectories],
31866
- signal
31867
- );
31853
+ return await embedLocalHistoryImages(history.snapshot(), signal);
31868
31854
  } finally {
31869
31855
  this.#replay = { kind: "idle" };
31870
31856
  }
31871
31857
  };
31872
- imageRoots = () => [this.#cwd, ...this.#additionalDirectories];
31873
- emitAgentText = async (text3, messageId) => {
31858
+ emitAgentMessage = async (chunks, messageId) => {
31874
31859
  const signal = AbortSignal.timeout(2e4);
31875
- await emitMarkdownWithLocalImages({
31876
- markdown: text3,
31860
+ await emitMarkdownChunksWithLocalImages({
31861
+ chunks,
31877
31862
  onImage: async (image) => await this.emitRaster(image, messageId, signal),
31878
31863
  onText: async (content3) => await this.#turn.onText(content3, messageId),
31879
- roots: this.imageRoots(),
31880
31864
  signal
31881
31865
  });
31882
31866
  };
31867
+ bufferAgentText = async (text3, messageId) => {
31868
+ if (this.#bufferedAgentText !== null && this.#bufferedAgentText.messageId !== messageId) {
31869
+ await this.emitAgentMessage(this.#bufferedAgentText.chunks, this.#bufferedAgentText.messageId);
31870
+ this.#bufferedAgentText = null;
31871
+ }
31872
+ this.#bufferedAgentText = {
31873
+ chunks: [...this.#bufferedAgentText?.chunks ?? [], text3],
31874
+ messageId
31875
+ };
31876
+ };
31877
+ flushAgentText = async () => {
31878
+ const buffered = this.#bufferedAgentText;
31879
+ this.#bufferedAgentText = null;
31880
+ if (buffered !== null) {
31881
+ await this.emitAgentMessage(buffered.chunks, buffered.messageId);
31882
+ }
31883
+ };
31883
31884
  prepareAgentContent = async (content3) => {
31884
31885
  if (content3.type === "image" && content3.data.length > 0) {
31885
31886
  const raster = readInlineRaster(content3.data, content3.name);
@@ -31889,7 +31890,7 @@ var AcpProcessSession = class _AcpProcessSession {
31889
31890
  }
31890
31891
  if (content3.type === "image" && content3.data.length === 0 && content3.uri.length > 0) {
31891
31892
  const signal = AbortSignal.timeout(2e4);
31892
- const raster = await readAuthorizedRaster(content3.uri, this.imageRoots(), signal);
31893
+ const raster = await readLocalRaster(content3.uri, signal);
31893
31894
  if (raster !== null) {
31894
31895
  return await this.importRaster(raster, signal);
31895
31896
  }
@@ -32359,6 +32360,7 @@ var AcpProcessSession = class _AcpProcessSession {
32359
32360
  options.signal
32360
32361
  );
32361
32362
  await this.#updateTail;
32363
+ await this.flushAgentText();
32362
32364
  await running.activities.finish();
32363
32365
  let result;
32364
32366
  try {
@@ -32390,6 +32392,7 @@ var AcpProcessSession = class _AcpProcessSession {
32390
32392
  cause: error62
32391
32393
  });
32392
32394
  } finally {
32395
+ this.#bufferedAgentText = null;
32393
32396
  this.#turn = new IdleAcpTurn();
32394
32397
  }
32395
32398
  };
@@ -32681,10 +32684,11 @@ var AcpProcessSession = class _AcpProcessSession {
32681
32684
  );
32682
32685
  } else {
32683
32686
  await this.#turn.activities.finishNarrative();
32684
- await this.emitAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
32687
+ await this.bufferAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
32685
32688
  }
32686
32689
  } else {
32687
32690
  await this.#turn.activities.finishNarrative();
32691
+ await this.flushAgentText();
32688
32692
  await this.emitAgentContent(
32689
32693
  normalizeContentBlock(update.content),
32690
32694
  truncate3(update.messageId ?? "", 255)
@@ -34698,7 +34702,7 @@ var LocalAgentInventory = class {
34698
34702
 
34699
34703
  // src/agent-installation/managed-npm-package.ts
34700
34704
  import { mkdir as mkdir2, mkdtemp, open as open2, realpath as realpath3, rename, rm, stat as stat3 } from "node:fs/promises";
34701
- import { delimiter, dirname as dirname4, isAbsolute as isAbsolute3, join as join4, relative as relative2, sep as sep2 } from "node:path";
34705
+ import { delimiter, dirname as dirname4, isAbsolute as isAbsolute3, join as join4, relative, sep } from "node:path";
34702
34706
  var INSTALL_TIMEOUT_MILLISECONDS = 5 * 60 * 1e3;
34703
34707
  var PACKAGE_METADATA_LIMIT_BYTES = 64 * 1024;
34704
34708
  var PACKAGE_LOCK_LIMIT_BYTES = 8 * 1024 * 1024;
@@ -34752,8 +34756,8 @@ function packagePath(root, packageName) {
34752
34756
  return join4(root, "node_modules", ...packageName.split("/"));
34753
34757
  }
34754
34758
  function isContainedPath(root, candidate) {
34755
- const difference = relative2(root, candidate);
34756
- return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep2}`) && !isAbsolute3(difference);
34759
+ const difference = relative(root, candidate);
34760
+ return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep}`) && !isAbsolute3(difference);
34757
34761
  }
34758
34762
  async function readJsonRecord(path2, maximumBytes) {
34759
34763
  try {
@@ -35379,7 +35383,7 @@ var GeminiCliAgentSpecification = class extends DirectAcpAgentDefinition {
35379
35383
 
35380
35384
  // src/agent-catalog/agents/grok-build-agent.ts
35381
35385
  import { realpath as realpath5 } from "node:fs/promises";
35382
- import { isAbsolute as isAbsolute6, join as join8, relative as relative3, sep as sep3 } from "node:path";
35386
+ import { isAbsolute as isAbsolute6, join as join8, relative as relative2, sep as sep2 } from "node:path";
35383
35387
  import {
35384
35388
  RequestError as RequestError2
35385
35389
  } from "@agentclientprotocol/sdk";
@@ -35444,8 +35448,8 @@ function grokBuildManagedPackage(platform, architecture) {
35444
35448
 
35445
35449
  // src/agent-catalog/agents/grok-build-agent.ts
35446
35450
  function isContainedPath2(root, candidate) {
35447
- const difference = relative3(root, candidate);
35448
- return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep3}`) && !isAbsolute6(difference);
35451
+ const difference = relative2(root, candidate);
35452
+ return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep2}`) && !isAbsolute6(difference);
35449
35453
  }
35450
35454
  var GrokBuildAgentSpecification = class extends DirectAcpAgentDefinition {
35451
35455
  adapterVersion = GROK_BUILD_MANAGED_VERSION;
@@ -35547,7 +35551,7 @@ import { join as join10 } from "node:path";
35547
35551
  import { createHash } from "node:crypto";
35548
35552
  import { createReadStream } from "node:fs";
35549
35553
  import { chmod as chmod2, copyFile, mkdir as mkdir3, mkdtemp as mkdtemp2, open as open3, realpath as realpath6, rename as rename2, rm as rm2, stat as stat5, writeFile } from "node:fs/promises";
35550
- import { delimiter as delimiter2, dirname as dirname5, isAbsolute as isAbsolute7, join as join9, relative as relative4, sep as sep4 } from "node:path";
35554
+ import { delimiter as delimiter2, dirname as dirname5, isAbsolute as isAbsolute7, join as join9, relative as relative3, sep as sep3 } from "node:path";
35551
35555
 
35552
35556
  // src/agent-installation/verified-download.ts
35553
35557
  import { fetch as fetch2 } from "undici";
@@ -35652,8 +35656,8 @@ function isRecord10(value) {
35652
35656
  return typeof value === "object" && value !== null && !Array.isArray(value);
35653
35657
  }
35654
35658
  function isContainedPath3(root, candidate) {
35655
- const difference = relative4(root, candidate);
35656
- return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep4}`) && !isAbsolute7(difference);
35659
+ const difference = relative3(root, candidate);
35660
+ return difference.length > 0 && difference !== ".." && !difference.startsWith(`..${sep3}`) && !isAbsolute7(difference);
35657
35661
  }
35658
35662
  async function hashFile(path2, signal) {
35659
35663
  signal.throwIfAborted();
@@ -37874,7 +37878,7 @@ async function uploadRuntimeArtifact(config2, sessionId, artifact, signal) {
37874
37878
  // src/authorization/workspace-directory.ts
37875
37879
  import { readdir as readdir2, realpath as realpath8, stat as stat7 } from "node:fs/promises";
37876
37880
  import { homedir as homedir2 } from "node:os";
37877
- import { basename as basename4, dirname as dirname6, isAbsolute as isAbsolute10, join as join16, normalize as normalize3, relative as relative5 } from "node:path";
37881
+ import { basename as basename4, dirname as dirname6, isAbsolute as isAbsolute10, join as join16, normalize as normalize3, relative as relative4 } from "node:path";
37878
37882
  var WorkspaceDirectoryListing = class {
37879
37883
  directoryId;
37880
37884
  directoryLabel;
@@ -37957,7 +37961,7 @@ var WorkspaceDirectoryService = class {
37957
37961
  }
37958
37962
  };
37959
37963
  label = (path2) => {
37960
- const suffix = relative5(homedir2(), path2);
37964
+ const suffix = relative4(homedir2(), path2);
37961
37965
  return suffix === "" ? "~" : !isAbsolute10(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
37962
37966
  };
37963
37967
  identify = async (bindingId, requestedPath, signal) => {
@@ -38294,7 +38298,7 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
38294
38298
  const snapshot = await response.promise;
38295
38299
  return {
38296
38300
  ...snapshot,
38297
- history: await embedLocalHistoryImages(snapshot.history, [cwd, snapshot.cwd], signal)
38301
+ history: await embedLocalHistoryImages(snapshot.history, signal)
38298
38302
  };
38299
38303
  } finally {
38300
38304
  clearTimeout(timeout);
@@ -39891,17 +39895,7 @@ var DaemonAcpObserver = class {
39891
39895
  this.#config = config2;
39892
39896
  this.#record = record4;
39893
39897
  }
39894
- importLocalArtifact = async (sessionId, artifact, signal) => {
39895
- try {
39896
- return (await uploadRuntimeArtifact(this.#config, sessionId, artifact, signal)).artifactId;
39897
- } catch (cause) {
39898
- signal.throwIfAborted();
39899
- if (cause instanceof Error && cause.name === "AbortError") {
39900
- throw cause;
39901
- }
39902
- return "";
39903
- }
39904
- };
39898
+ importLocalArtifact = async (sessionId, artifact, signal) => (await uploadRuntimeArtifact(this.#config, sessionId, artifact, signal)).artifactId;
39905
39899
  onCommands = (event) => {
39906
39900
  this.#record(event.sessionId, encodeSessionCommandsUpdatedEvent(event));
39907
39901
  return Promise.resolve();
@@ -40943,24 +40937,55 @@ function assertPreparedPermission(configOptions, permissionMode) {
40943
40937
  );
40944
40938
  }
40945
40939
  }
40946
- async function applyRequiredExecutionSelection(sessions, configOptions, selection, category, agent, cwd, additionalDirectories, sessionId, signal) {
40940
+ function warnIgnoredExecutionSetting(audit, commandId, sessionId, agentId, selection, category, reason) {
40941
+ const details = {
40942
+ agentId,
40943
+ category,
40944
+ configId: selection.configId,
40945
+ reason,
40946
+ requestedValue: selection.value
40947
+ };
40948
+ const event = "bot_execution_setting_ignored";
40949
+ audit.record({ commandId, details, event, sessionId });
40950
+ process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
40951
+ `);
40952
+ }
40953
+ async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
40954
+ if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
40955
+ return configOptions;
40956
+ }
40947
40957
  const option2 = configOptions.find((candidate) => candidate.id === selection.configId);
40948
- if (option2 === void 0 || option2.type !== "select" || option2.category !== category || selection.valueType !== "select" || selection.booleanValue) {
40949
- throw new AcpExecutionError(
40950
- `The required Agent setting ${selection.configId} is unavailable`,
40951
- {},
40952
- "invalid_session_configuration"
40958
+ if (option2 === void 0) {
40959
+ warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "setting_unavailable");
40960
+ return configOptions;
40961
+ }
40962
+ if (option2.type !== "select" || option2.category !== category) {
40963
+ warnIgnoredExecutionSetting(
40964
+ audit,
40965
+ commandId,
40966
+ sessionId,
40967
+ agent.id,
40968
+ selection,
40969
+ category,
40970
+ "setting_schema_mismatch"
40953
40971
  );
40972
+ return configOptions;
40954
40973
  }
40955
- if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
40974
+ if (selection.valueType !== "select" || selection.booleanValue) {
40975
+ warnIgnoredExecutionSetting(
40976
+ audit,
40977
+ commandId,
40978
+ sessionId,
40979
+ agent.id,
40980
+ selection,
40981
+ category,
40982
+ "selection_schema_mismatch"
40983
+ );
40956
40984
  return configOptions;
40957
40985
  }
40958
40986
  if (!option2.values.some((value) => value.value === selection.value)) {
40959
- throw new AcpExecutionError(
40960
- `The required Agent setting ${selection.configId} is unavailable`,
40961
- {},
40962
- "invalid_session_configuration"
40963
- );
40987
+ warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "value_unavailable");
40988
+ return configOptions;
40964
40989
  }
40965
40990
  if (option2.currentValue === selection.value) {
40966
40991
  return configOptions;
@@ -41059,25 +41084,29 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
41059
41084
  signal: executionSignal
41060
41085
  });
41061
41086
  assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
41062
- let configOptions = await applyRequiredExecutionSelection(
41087
+ let configOptions = await applySupportedExecutionSelection(
41063
41088
  sessions,
41089
+ audit,
41064
41090
  prepared.configOptions,
41065
41091
  execution.executionConfiguration.model,
41066
41092
  "model",
41067
41093
  agent,
41068
41094
  resolved.cwd,
41069
41095
  resolved.additionalDirectories,
41096
+ command.commandId,
41070
41097
  command.sessionId,
41071
41098
  executionSignal
41072
41099
  );
41073
- configOptions = await applyRequiredExecutionSelection(
41100
+ configOptions = await applySupportedExecutionSelection(
41074
41101
  sessions,
41102
+ audit,
41075
41103
  configOptions,
41076
41104
  execution.executionConfiguration.reasoningEffort,
41077
41105
  "thought_level",
41078
41106
  agent,
41079
41107
  resolved.cwd,
41080
41108
  resolved.additionalDirectories,
41109
+ command.commandId,
41081
41110
  command.sessionId,
41082
41111
  executionSignal
41083
41112
  );