@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/runtime.js CHANGED
@@ -24362,7 +24362,7 @@ import {
24362
24362
 
24363
24363
  // src/authorization/local-raster.ts
24364
24364
  import { readFile as readFile2, realpath as realpath6, stat as stat5 } from "node:fs/promises";
24365
- import { basename, isAbsolute as isAbsolute8, normalize as normalize2, relative as relative4, sep as sep4 } from "node:path";
24365
+ import { basename, isAbsolute as isAbsolute8, normalize as normalize2 } from "node:path";
24366
24366
  import { fileURLToPath } from "node:url";
24367
24367
  var MAX_LOCAL_RASTER_BYTES = 3e6;
24368
24368
  var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71);
@@ -24420,10 +24420,6 @@ function readInlineRaster(data, name = "Image") {
24420
24420
  }
24421
24421
  return new LocalRasterImage(basename(name) || "Image", mimeType, bytes);
24422
24422
  }
24423
- function isInsideRoot(root, target) {
24424
- const relation = relative4(root, target);
24425
- return relation !== ".." && !relation.startsWith(`..${sep4}`) && !isAbsolute8(relation);
24426
- }
24427
24423
  async function resolveCanonicalPath(requested, signal) {
24428
24424
  signal.throwIfAborted();
24429
24425
  if (!isAbsolute8(requested) || requested.includes("\0") || normalize2(requested) !== requested) {
@@ -24468,7 +24464,7 @@ function parseLocalImageUri(uri) {
24468
24464
  }
24469
24465
  return trimmed;
24470
24466
  }
24471
- async function readAuthorizedRaster(uri, roots, signal) {
24467
+ async function readLocalRaster(uri, signal) {
24472
24468
  signal.throwIfAborted();
24473
24469
  const requested = parseLocalImageUri(uri);
24474
24470
  if (requested === null) {
@@ -24483,21 +24479,6 @@ async function readAuthorizedRaster(uri, roots, signal) {
24483
24479
  if (!targetMetadata.isFile() || targetMetadata.size < 1 || targetMetadata.size > MAX_LOCAL_RASTER_BYTES) {
24484
24480
  return null;
24485
24481
  }
24486
- const authorizedRoots = [];
24487
- for (const root of roots) {
24488
- const directory = await resolveCanonicalPath(root, signal);
24489
- if (directory === null) {
24490
- continue;
24491
- }
24492
- const metadata = await stat5(directory);
24493
- signal.throwIfAborted();
24494
- if (metadata.isDirectory()) {
24495
- authorizedRoots.push(directory);
24496
- }
24497
- }
24498
- if (!authorizedRoots.some((root) => isInsideRoot(root, target))) {
24499
- return null;
24500
- }
24501
24482
  const bytes = new Uint8Array(await readFile2(target));
24502
24483
  signal.throwIfAborted();
24503
24484
  if (bytes.byteLength < 1 || bytes.byteLength > MAX_LOCAL_RASTER_BYTES) {
@@ -24596,7 +24577,7 @@ var unmeasuredOperationMetrics = Object.freeze({
24596
24577
 
24597
24578
  // src/native-sessions/history-images.ts
24598
24579
  var IMAGE_MARKER = /\[@image\]\(([^)\r\n]*)(?:\)|$)/g;
24599
- async function embedLocalHistoryImages(history, roots, signal) {
24580
+ async function embedLocalHistoryImages(history, signal) {
24600
24581
  if (history.status !== "available") {
24601
24582
  return history;
24602
24583
  }
@@ -24604,7 +24585,7 @@ async function embedLocalHistoryImages(history, roots, signal) {
24604
24585
  let imageCharacters = 0;
24605
24586
  for (const message of history.messages) {
24606
24587
  signal.throwIfAborted();
24607
- const resolved = await resolveMessageImages(message, roots, imageCharacters, signal);
24588
+ const resolved = await resolveMessageImages(message, imageCharacters, signal);
24608
24589
  imageCharacters += (resolved.images ?? []).reduce((size, image) => size + image.data.length, 0);
24609
24590
  messages.push(resolved);
24610
24591
  }
@@ -24613,7 +24594,7 @@ async function embedLocalHistoryImages(history, roots, signal) {
24613
24594
  messages
24614
24595
  };
24615
24596
  }
24616
- async function resolveMessageImages(message, roots, usedCharacters, signal) {
24597
+ async function resolveMessageImages(message, usedCharacters, signal) {
24617
24598
  const images = [...message.images ?? []];
24618
24599
  let imageCharacters = images.reduce((size, image) => size + image.data.length, 0);
24619
24600
  const text3 = await replaceImageMarkers(message.text, async (uri) => {
@@ -24629,7 +24610,7 @@ async function resolveMessageImages(message, roots, usedCharacters, signal) {
24629
24610
  imageCharacters += embedded.data.length;
24630
24611
  return "";
24631
24612
  }
24632
- const local = await readAuthorizedRaster(uri, roots, signal);
24613
+ const local = await readLocalRaster(uri, signal);
24633
24614
  if (local === null) {
24634
24615
  return "[Image unavailable]";
24635
24616
  }
@@ -32361,16 +32342,24 @@ function parseMarkdownImages(markdown) {
32361
32342
  });
32362
32343
  return images.sort((left, right) => left.start - right.start);
32363
32344
  }
32364
- async function emitMarkdownWithLocalImages(options) {
32345
+ async function emitMarkdownChunksWithLocalImages(options) {
32346
+ const markdown = options.chunks.join("");
32347
+ const images = parseMarkdownImages(markdown);
32348
+ if (images.length === 0) {
32349
+ for (const chunk of options.chunks) {
32350
+ await options.onText(chunk);
32351
+ }
32352
+ return;
32353
+ }
32365
32354
  let cursor = 0;
32366
- for (const image of parseMarkdownImages(options.markdown)) {
32355
+ for (const image of images) {
32367
32356
  if (image.start < cursor) {
32368
32357
  continue;
32369
32358
  }
32370
32359
  if (image.start > cursor) {
32371
- await options.onText(options.markdown.slice(cursor, image.start));
32360
+ await options.onText(markdown.slice(cursor, image.start));
32372
32361
  }
32373
- const raster = await readAuthorizedRaster(image.uri, options.roots, options.signal);
32362
+ const raster = await readLocalRaster(image.uri, options.signal);
32374
32363
  if (raster === null) {
32375
32364
  await options.onText("[Image unavailable]");
32376
32365
  } else {
@@ -32378,8 +32367,8 @@ async function emitMarkdownWithLocalImages(options) {
32378
32367
  }
32379
32368
  cursor = image.end;
32380
32369
  }
32381
- if (cursor < options.markdown.length) {
32382
- await options.onText(options.markdown.slice(cursor));
32370
+ if (cursor < markdown.length) {
32371
+ await options.onText(markdown.slice(cursor));
32383
32372
  }
32384
32373
  }
32385
32374
 
@@ -33721,6 +33710,7 @@ var AcpProcessSession = class _AcpProcessSession {
33721
33710
  #preSessionUpdateBytes = 0;
33722
33711
  #agentName = "";
33723
33712
  #agentVersion = "";
33713
+ #bufferedAgentText = null;
33724
33714
  #capabilities = {
33725
33715
  additionalDirectories: false,
33726
33716
  audioPrompt: false,
@@ -33894,26 +33884,37 @@ var AcpProcessSession = class _AcpProcessSession {
33894
33884
  );
33895
33885
  await this.#updateTail;
33896
33886
  signal.throwIfAborted();
33897
- return await embedLocalHistoryImages(
33898
- history.snapshot(),
33899
- [this.#cwd, ...this.#additionalDirectories],
33900
- signal
33901
- );
33887
+ return await embedLocalHistoryImages(history.snapshot(), signal);
33902
33888
  } finally {
33903
33889
  this.#replay = { kind: "idle" };
33904
33890
  }
33905
33891
  };
33906
- imageRoots = () => [this.#cwd, ...this.#additionalDirectories];
33907
- emitAgentText = async (text3, messageId) => {
33892
+ emitAgentMessage = async (chunks, messageId) => {
33908
33893
  const signal = AbortSignal.timeout(2e4);
33909
- await emitMarkdownWithLocalImages({
33910
- markdown: text3,
33894
+ await emitMarkdownChunksWithLocalImages({
33895
+ chunks,
33911
33896
  onImage: async (image) => await this.emitRaster(image, messageId, signal),
33912
33897
  onText: async (content3) => await this.#turn.onText(content3, messageId),
33913
- roots: this.imageRoots(),
33914
33898
  signal
33915
33899
  });
33916
33900
  };
33901
+ bufferAgentText = async (text3, messageId) => {
33902
+ if (this.#bufferedAgentText !== null && this.#bufferedAgentText.messageId !== messageId) {
33903
+ await this.emitAgentMessage(this.#bufferedAgentText.chunks, this.#bufferedAgentText.messageId);
33904
+ this.#bufferedAgentText = null;
33905
+ }
33906
+ this.#bufferedAgentText = {
33907
+ chunks: [...this.#bufferedAgentText?.chunks ?? [], text3],
33908
+ messageId
33909
+ };
33910
+ };
33911
+ flushAgentText = async () => {
33912
+ const buffered = this.#bufferedAgentText;
33913
+ this.#bufferedAgentText = null;
33914
+ if (buffered !== null) {
33915
+ await this.emitAgentMessage(buffered.chunks, buffered.messageId);
33916
+ }
33917
+ };
33917
33918
  prepareAgentContent = async (content3) => {
33918
33919
  if (content3.type === "image" && content3.data.length > 0) {
33919
33920
  const raster = readInlineRaster(content3.data, content3.name);
@@ -33923,7 +33924,7 @@ var AcpProcessSession = class _AcpProcessSession {
33923
33924
  }
33924
33925
  if (content3.type === "image" && content3.data.length === 0 && content3.uri.length > 0) {
33925
33926
  const signal = AbortSignal.timeout(2e4);
33926
- const raster = await readAuthorizedRaster(content3.uri, this.imageRoots(), signal);
33927
+ const raster = await readLocalRaster(content3.uri, signal);
33927
33928
  if (raster !== null) {
33928
33929
  return await this.importRaster(raster, signal);
33929
33930
  }
@@ -34393,6 +34394,7 @@ var AcpProcessSession = class _AcpProcessSession {
34393
34394
  options.signal
34394
34395
  );
34395
34396
  await this.#updateTail;
34397
+ await this.flushAgentText();
34396
34398
  await running.activities.finish();
34397
34399
  let result;
34398
34400
  try {
@@ -34424,6 +34426,7 @@ var AcpProcessSession = class _AcpProcessSession {
34424
34426
  cause: error62
34425
34427
  });
34426
34428
  } finally {
34429
+ this.#bufferedAgentText = null;
34427
34430
  this.#turn = new IdleAcpTurn();
34428
34431
  }
34429
34432
  };
@@ -34715,10 +34718,11 @@ var AcpProcessSession = class _AcpProcessSession {
34715
34718
  );
34716
34719
  } else {
34717
34720
  await this.#turn.activities.finishNarrative();
34718
- await this.emitAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
34721
+ await this.bufferAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
34719
34722
  }
34720
34723
  } else {
34721
34724
  await this.#turn.activities.finishNarrative();
34725
+ await this.flushAgentText();
34722
34726
  await this.emitAgentContent(
34723
34727
  normalizeContentBlock(update.content),
34724
34728
  truncate3(update.messageId ?? "", 255)
@@ -36914,7 +36918,7 @@ var LocalAuthorizationError = class extends Error {
36914
36918
  // src/authorization/workspace-directory.ts
36915
36919
  import { readdir as readdir2, realpath as realpath7, stat as stat6 } from "node:fs/promises";
36916
36920
  import { homedir as homedir2 } from "node:os";
36917
- import { basename as basename3, dirname as dirname5, isAbsolute as isAbsolute9, join as join15, normalize as normalize3, relative as relative5 } from "node:path";
36921
+ import { basename as basename3, dirname as dirname5, isAbsolute as isAbsolute9, join as join15, normalize as normalize3, relative as relative4 } from "node:path";
36918
36922
  var WorkspaceDirectoryListing = class {
36919
36923
  directoryId;
36920
36924
  directoryLabel;
@@ -36997,7 +37001,7 @@ var WorkspaceDirectoryService = class {
36997
37001
  }
36998
37002
  };
36999
37003
  label = (path2) => {
37000
- const suffix = relative5(homedir2(), path2);
37004
+ const suffix = relative4(homedir2(), path2);
37001
37005
  return suffix === "" ? "~" : !isAbsolute9(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
37002
37006
  };
37003
37007
  identify = async (bindingId, requestedPath, signal) => {
@@ -37735,7 +37739,7 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
37735
37739
  const snapshot = await response.promise;
37736
37740
  return {
37737
37741
  ...snapshot,
37738
- history: await embedLocalHistoryImages(snapshot.history, [cwd, snapshot.cwd], signal)
37742
+ history: await embedLocalHistoryImages(snapshot.history, signal)
37739
37743
  };
37740
37744
  } finally {
37741
37745
  clearTimeout(timeout);
@@ -39332,17 +39336,7 @@ var DaemonAcpObserver = class {
39332
39336
  this.#config = config2;
39333
39337
  this.#record = record4;
39334
39338
  }
39335
- importLocalArtifact = async (sessionId, artifact, signal) => {
39336
- try {
39337
- return (await uploadRuntimeArtifact(this.#config, sessionId, artifact, signal)).artifactId;
39338
- } catch (cause) {
39339
- signal.throwIfAborted();
39340
- if (cause instanceof Error && cause.name === "AbortError") {
39341
- throw cause;
39342
- }
39343
- return "";
39344
- }
39345
- };
39339
+ importLocalArtifact = async (sessionId, artifact, signal) => (await uploadRuntimeArtifact(this.#config, sessionId, artifact, signal)).artifactId;
39346
39340
  onCommands = (event) => {
39347
39341
  this.#record(event.sessionId, encodeSessionCommandsUpdatedEvent(event));
39348
39342
  return Promise.resolve();
@@ -40384,24 +40378,55 @@ function assertPreparedPermission(configOptions, permissionMode) {
40384
40378
  );
40385
40379
  }
40386
40380
  }
40387
- async function applyRequiredExecutionSelection(sessions, configOptions, selection, category, agent, cwd, additionalDirectories, sessionId, signal) {
40381
+ function warnIgnoredExecutionSetting(audit, commandId, sessionId, agentId, selection, category, reason) {
40382
+ const details = {
40383
+ agentId,
40384
+ category,
40385
+ configId: selection.configId,
40386
+ reason,
40387
+ requestedValue: selection.value
40388
+ };
40389
+ const event = "bot_execution_setting_ignored";
40390
+ audit.record({ commandId, details, event, sessionId });
40391
+ process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
40392
+ `);
40393
+ }
40394
+ async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
40395
+ if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
40396
+ return configOptions;
40397
+ }
40388
40398
  const option = configOptions.find((candidate) => candidate.id === selection.configId);
40389
- if (option === void 0 || option.type !== "select" || option.category !== category || selection.valueType !== "select" || selection.booleanValue) {
40390
- throw new AcpExecutionError(
40391
- `The required Agent setting ${selection.configId} is unavailable`,
40392
- {},
40393
- "invalid_session_configuration"
40399
+ if (option === void 0) {
40400
+ warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "setting_unavailable");
40401
+ return configOptions;
40402
+ }
40403
+ if (option.type !== "select" || option.category !== category) {
40404
+ warnIgnoredExecutionSetting(
40405
+ audit,
40406
+ commandId,
40407
+ sessionId,
40408
+ agent.id,
40409
+ selection,
40410
+ category,
40411
+ "setting_schema_mismatch"
40394
40412
  );
40413
+ return configOptions;
40395
40414
  }
40396
- if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
40415
+ if (selection.valueType !== "select" || selection.booleanValue) {
40416
+ warnIgnoredExecutionSetting(
40417
+ audit,
40418
+ commandId,
40419
+ sessionId,
40420
+ agent.id,
40421
+ selection,
40422
+ category,
40423
+ "selection_schema_mismatch"
40424
+ );
40397
40425
  return configOptions;
40398
40426
  }
40399
40427
  if (!option.values.some((value) => value.value === selection.value)) {
40400
- throw new AcpExecutionError(
40401
- `The required Agent setting ${selection.configId} is unavailable`,
40402
- {},
40403
- "invalid_session_configuration"
40404
- );
40428
+ warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "value_unavailable");
40429
+ return configOptions;
40405
40430
  }
40406
40431
  if (option.currentValue === selection.value) {
40407
40432
  return configOptions;
@@ -40500,25 +40525,29 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
40500
40525
  signal: executionSignal
40501
40526
  });
40502
40527
  assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
40503
- let configOptions = await applyRequiredExecutionSelection(
40528
+ let configOptions = await applySupportedExecutionSelection(
40504
40529
  sessions,
40530
+ audit,
40505
40531
  prepared.configOptions,
40506
40532
  execution.executionConfiguration.model,
40507
40533
  "model",
40508
40534
  agent,
40509
40535
  resolved.cwd,
40510
40536
  resolved.additionalDirectories,
40537
+ command.commandId,
40511
40538
  command.sessionId,
40512
40539
  executionSignal
40513
40540
  );
40514
- configOptions = await applyRequiredExecutionSelection(
40541
+ configOptions = await applySupportedExecutionSelection(
40515
40542
  sessions,
40543
+ audit,
40516
40544
  configOptions,
40517
40545
  execution.executionConfiguration.reasoningEffort,
40518
40546
  "thought_level",
40519
40547
  agent,
40520
40548
  resolved.cwd,
40521
40549
  resolved.additionalDirectories,
40550
+ command.commandId,
40522
40551
  command.sessionId,
40523
40552
  executionSignal
40524
40553
  );