@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/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 = [];
33724
33714
  #capabilities = {
33725
33715
  additionalDirectories: false,
33726
33716
  audioPrompt: false,
@@ -33894,26 +33884,47 @@ 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
+ const previous2 = this.#bufferedAgentText.at(-1);
33903
+ if (previous2?.messageId === messageId) {
33904
+ this.#bufferedAgentText = [
33905
+ ...this.#bufferedAgentText.slice(0, -1),
33906
+ { chunks: [...previous2.chunks, text3], messageId }
33907
+ ];
33908
+ return;
33909
+ }
33910
+ this.#bufferedAgentText = [...this.#bufferedAgentText, { chunks: [text3], messageId }];
33911
+ };
33912
+ flushAgentText = async () => {
33913
+ const buffered = this.#bufferedAgentText;
33914
+ this.#bufferedAgentText = [];
33915
+ for (const message of buffered) {
33916
+ await this.emitAgentMessage(message.chunks, message.messageId);
33917
+ }
33918
+ };
33919
+ recordBufferedAgentTextAsProgress = async () => {
33920
+ const buffered = this.#bufferedAgentText;
33921
+ this.#bufferedAgentText = [];
33922
+ for (const message of buffered) {
33923
+ for (const chunk of message.chunks) {
33924
+ await this.#turn.activities.recordNarrative("progress", message.messageId, chunk);
33925
+ }
33926
+ }
33927
+ };
33917
33928
  prepareAgentContent = async (content3) => {
33918
33929
  if (content3.type === "image" && content3.data.length > 0) {
33919
33930
  const raster = readInlineRaster(content3.data, content3.name);
@@ -33923,7 +33934,7 @@ var AcpProcessSession = class _AcpProcessSession {
33923
33934
  }
33924
33935
  if (content3.type === "image" && content3.data.length === 0 && content3.uri.length > 0) {
33925
33936
  const signal = AbortSignal.timeout(2e4);
33926
- const raster = await readAuthorizedRaster(content3.uri, this.imageRoots(), signal);
33937
+ const raster = await readLocalRaster(content3.uri, signal);
33927
33938
  if (raster !== null) {
33928
33939
  return await this.importRaster(raster, signal);
33929
33940
  }
@@ -34393,6 +34404,7 @@ var AcpProcessSession = class _AcpProcessSession {
34393
34404
  options.signal
34394
34405
  );
34395
34406
  await this.#updateTail;
34407
+ await this.flushAgentText();
34396
34408
  await running.activities.finish();
34397
34409
  let result;
34398
34410
  try {
@@ -34424,6 +34436,7 @@ var AcpProcessSession = class _AcpProcessSession {
34424
34436
  cause: error62
34425
34437
  });
34426
34438
  } finally {
34439
+ this.#bufferedAgentText = [];
34427
34440
  this.#turn = new IdleAcpTurn();
34428
34441
  }
34429
34442
  };
@@ -34715,10 +34728,11 @@ var AcpProcessSession = class _AcpProcessSession {
34715
34728
  );
34716
34729
  } else {
34717
34730
  await this.#turn.activities.finishNarrative();
34718
- await this.emitAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
34731
+ await this.bufferAgentText(update.content.text, truncate3(update.messageId ?? "", 255));
34719
34732
  }
34720
34733
  } else {
34721
34734
  await this.#turn.activities.finishNarrative();
34735
+ await this.flushAgentText();
34722
34736
  await this.emitAgentContent(
34723
34737
  normalizeContentBlock(update.content),
34724
34738
  truncate3(update.messageId ?? "", 255)
@@ -34737,6 +34751,7 @@ var AcpProcessSession = class _AcpProcessSession {
34737
34751
  return;
34738
34752
  }
34739
34753
  if (update.sessionUpdate === "tool_call") {
34754
+ await this.recordBufferedAgentTextAsProgress();
34740
34755
  await this.#turn.activities.recordToolCall(update);
34741
34756
  return;
34742
34757
  }
@@ -36914,7 +36929,7 @@ var LocalAuthorizationError = class extends Error {
36914
36929
  // src/authorization/workspace-directory.ts
36915
36930
  import { readdir as readdir2, realpath as realpath7, stat as stat6 } from "node:fs/promises";
36916
36931
  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";
36932
+ import { basename as basename3, dirname as dirname5, isAbsolute as isAbsolute9, join as join15, normalize as normalize3, relative as relative4 } from "node:path";
36918
36933
  var WorkspaceDirectoryListing = class {
36919
36934
  directoryId;
36920
36935
  directoryLabel;
@@ -36997,7 +37012,7 @@ var WorkspaceDirectoryService = class {
36997
37012
  }
36998
37013
  };
36999
37014
  label = (path2) => {
37000
- const suffix = relative5(homedir2(), path2);
37015
+ const suffix = relative4(homedir2(), path2);
37001
37016
  return suffix === "" ? "~" : !isAbsolute9(suffix) && suffix !== ".." && !suffix.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ? `~/${suffix.replaceAll("\\", "/")}` : path2;
37002
37017
  };
37003
37018
  identify = async (bindingId, requestedPath, signal) => {
@@ -37735,7 +37750,7 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
37735
37750
  const snapshot = await response.promise;
37736
37751
  return {
37737
37752
  ...snapshot,
37738
- history: await embedLocalHistoryImages(snapshot.history, [cwd, snapshot.cwd], signal)
37753
+ history: await embedLocalHistoryImages(snapshot.history, signal)
37739
37754
  };
37740
37755
  } finally {
37741
37756
  clearTimeout(timeout);
@@ -39332,17 +39347,7 @@ var DaemonAcpObserver = class {
39332
39347
  this.#config = config2;
39333
39348
  this.#record = record4;
39334
39349
  }
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
- };
39350
+ importLocalArtifact = async (sessionId, artifact, signal) => (await uploadRuntimeArtifact(this.#config, sessionId, artifact, signal)).artifactId;
39346
39351
  onCommands = (event) => {
39347
39352
  this.#record(event.sessionId, encodeSessionCommandsUpdatedEvent(event));
39348
39353
  return Promise.resolve();
@@ -40384,24 +40389,55 @@ function assertPreparedPermission(configOptions, permissionMode) {
40384
40389
  );
40385
40390
  }
40386
40391
  }
40387
- async function applyRequiredExecutionSelection(sessions, configOptions, selection, category, agent, cwd, additionalDirectories, sessionId, signal) {
40392
+ function warnIgnoredExecutionSetting(audit, commandId, sessionId, agentId, selection, category, reason) {
40393
+ const details = {
40394
+ agentId,
40395
+ category,
40396
+ configId: selection.configId,
40397
+ reason,
40398
+ requestedValue: selection.value
40399
+ };
40400
+ const event = "bot_execution_setting_ignored";
40401
+ audit.record({ commandId, details, event, sessionId });
40402
+ process.stderr.write(`Mobius daemon warning ${JSON.stringify({ commandId, event, sessionId, ...details })}
40403
+ `);
40404
+ }
40405
+ async function applySupportedExecutionSelection(sessions, audit, configOptions, selection, category, agent, cwd, additionalDirectories, commandId, sessionId, signal) {
40406
+ if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
40407
+ return configOptions;
40408
+ }
40388
40409
  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"
40410
+ if (option === void 0) {
40411
+ warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "setting_unavailable");
40412
+ return configOptions;
40413
+ }
40414
+ if (option.type !== "select" || option.category !== category) {
40415
+ warnIgnoredExecutionSetting(
40416
+ audit,
40417
+ commandId,
40418
+ sessionId,
40419
+ agent.id,
40420
+ selection,
40421
+ category,
40422
+ "setting_schema_mismatch"
40394
40423
  );
40424
+ return configOptions;
40395
40425
  }
40396
- if (selection.value === AGENT_DEFAULT_EXECUTION_SETTING) {
40426
+ if (selection.valueType !== "select" || selection.booleanValue) {
40427
+ warnIgnoredExecutionSetting(
40428
+ audit,
40429
+ commandId,
40430
+ sessionId,
40431
+ agent.id,
40432
+ selection,
40433
+ category,
40434
+ "selection_schema_mismatch"
40435
+ );
40397
40436
  return configOptions;
40398
40437
  }
40399
40438
  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
- );
40439
+ warnIgnoredExecutionSetting(audit, commandId, sessionId, agent.id, selection, category, "value_unavailable");
40440
+ return configOptions;
40405
40441
  }
40406
40442
  if (option.currentValue === selection.value) {
40407
40443
  return configOptions;
@@ -40500,25 +40536,29 @@ async function executeBotPrompt(outbox, publisher, command, config2, directories
40500
40536
  signal: executionSignal
40501
40537
  });
40502
40538
  assertPreparedPermission(prepared.configOptions, execution.executionConfiguration.permissionMode);
40503
- let configOptions = await applyRequiredExecutionSelection(
40539
+ let configOptions = await applySupportedExecutionSelection(
40504
40540
  sessions,
40541
+ audit,
40505
40542
  prepared.configOptions,
40506
40543
  execution.executionConfiguration.model,
40507
40544
  "model",
40508
40545
  agent,
40509
40546
  resolved.cwd,
40510
40547
  resolved.additionalDirectories,
40548
+ command.commandId,
40511
40549
  command.sessionId,
40512
40550
  executionSignal
40513
40551
  );
40514
- configOptions = await applyRequiredExecutionSelection(
40552
+ configOptions = await applySupportedExecutionSelection(
40515
40553
  sessions,
40554
+ audit,
40516
40555
  configOptions,
40517
40556
  execution.executionConfiguration.reasoningEffort,
40518
40557
  "thought_level",
40519
40558
  agent,
40520
40559
  resolved.cwd,
40521
40560
  resolved.additionalDirectories,
40561
+ command.commandId,
40522
40562
  command.sessionId,
40523
40563
  executionSignal
40524
40564
  );