@moxt-ai/mobius 0.0.464 → 0.0.466

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.
Files changed (28) hide show
  1. package/dist/{chunk-YN6SPJT7.js → chunk-7P2QHD5S.js} +138 -60
  2. package/dist/{chunk-YN6SPJT7.js.map → chunk-7P2QHD5S.js.map} +2 -2
  3. package/dist/{chunk-W5MXRFJ5.js → chunk-CP7CJWBV.js} +2 -2
  4. package/dist/{chunk-W5MXRFJ5.js.map → chunk-CP7CJWBV.js.map} +1 -1
  5. package/dist/{cli-JLNGQRI5.js → cli-6REFJJ5X.js} +3 -3
  6. package/dist/cli.js +2 -2
  7. package/dist/engine/infra/operation-metrics.d.ts +5 -0
  8. package/dist/engine/infra/operation-metrics.d.ts.map +1 -1
  9. package/dist/engine/infra/operation-metrics.js +9 -1
  10. package/dist/engine/infra/operation-metrics.js.map +1 -1
  11. package/dist/engine/runtime/relay/session-event-publisher.d.ts.map +1 -1
  12. package/dist/engine/runtime/relay/session-event-publisher.js +37 -14
  13. package/dist/engine/runtime/relay/session-event-publisher.js.map +1 -1
  14. package/dist/engine/session/api/session-api.d.ts +8 -0
  15. package/dist/engine/session/api/session-api.d.ts.map +1 -1
  16. package/dist/engine/session/api/session-api.js.map +1 -1
  17. package/dist/engine/session/live/agent-session.d.ts.map +1 -1
  18. package/dist/engine/session/live/agent-session.js +26 -21
  19. package/dist/engine/session/live/agent-session.js.map +1 -1
  20. package/dist/engine/session/manager/session-manager.d.ts.map +1 -1
  21. package/dist/engine/session/manager/session-manager.js +3 -2
  22. package/dist/engine/session/manager/session-manager.js.map +1 -1
  23. package/dist/engine/session/prompt/execute-prompt.d.ts.map +1 -1
  24. package/dist/engine/session/prompt/execute-prompt.js +32 -7
  25. package/dist/engine/session/prompt/execute-prompt.js.map +1 -1
  26. package/dist/engine.js +2 -2
  27. package/package.json +1 -1
  28. /package/dist/{cli-JLNGQRI5.js.map → cli-6REFJJ5X.js.map} +0 -0
@@ -5,7 +5,7 @@ import {
5
5
  __toESM,
6
6
  __using,
7
7
  package_default
8
- } from "./chunk-W5MXRFJ5.js";
8
+ } from "./chunk-CP7CJWBV.js";
9
9
 
10
10
  // ../../node_modules/.pnpm/ignore@7.0.9/node_modules/ignore/index.js
11
11
  var require_ignore = __commonJS({
@@ -95616,6 +95616,14 @@ var CachedSessionEventStore = class {
95616
95616
  // src/engine/infra/operation-metrics.ts
95617
95617
  var AccumulatingOperationMetrics = class {
95618
95618
  #durations = /* @__PURE__ */ new Map();
95619
+ #maximumMilliseconds;
95620
+ /**
95621
+ * Each accumulated duration stops at `maximumMilliseconds`, which bounds what is reported to a peer. A
95622
+ * diagnostic that stays on this machine passes `Infinity`, so a long wait reads as long as it was.
95623
+ */
95624
+ constructor(maximumMilliseconds = 12e4) {
95625
+ this.#maximumMilliseconds = maximumMilliseconds;
95626
+ }
95619
95627
  measure = async (name2, operation) => {
95620
95628
  const startedAt = performance.now();
95621
95629
  try {
@@ -95638,7 +95646,7 @@ var AccumulatingOperationMetrics = class {
95638
95646
  record = (name2, durationMilliseconds) => {
95639
95647
  this.#durations.set(
95640
95648
  name2,
95641
- Math.min(12e4, (this.#durations.get(name2) ?? 0) + Math.max(0, durationMilliseconds))
95649
+ Math.min(this.#maximumMilliseconds, (this.#durations.get(name2) ?? 0) + Math.max(0, durationMilliseconds))
95642
95650
  );
95643
95651
  };
95644
95652
  };
@@ -97431,27 +97439,30 @@ var AgentSession = class _AgentSession {
97431
97439
  this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
97432
97440
  const lifecycle = options.lifecycle;
97433
97441
  if (lifecycle !== void 0) {
97434
- await this.#releaseHeld();
97435
- await this.recordLifecycleEvent({
97436
- payload: {
97437
- commandId: options.commandId,
97438
- content: lifecycle.content,
97439
- ...lifecycle.disposition === void 0 ? {} : { disposition: lifecycle.disposition },
97440
- kind: "prompt.requested",
97441
- ...lifecycle.context === void 0 ? {} : { context: lifecycle.context },
97442
- ...lifecycle.targetCommandId === void 0 ? {} : { targetCommandId: lifecycle.targetCommandId }
97443
- },
97444
- type: "lifecycle-metadata"
97445
- });
97446
- await this.recordLifecycleEvent({
97447
- payload: {
97448
- attemptId: lifecycle.attemptId,
97449
- commandId: options.commandId,
97450
- epoch: lifecycle.epoch,
97451
- kind: "prompt.started"
97452
- },
97453
- type: "lifecycle-metadata"
97442
+ await (options.timing?.metrics ?? unmeasuredOperationMetrics).measure("record-started", async () => {
97443
+ await this.#releaseHeld();
97444
+ await this.recordLifecycleEvent({
97445
+ payload: {
97446
+ commandId: options.commandId,
97447
+ content: lifecycle.content,
97448
+ ...lifecycle.disposition === void 0 ? {} : { disposition: lifecycle.disposition },
97449
+ kind: "prompt.requested",
97450
+ ...lifecycle.context === void 0 ? {} : { context: lifecycle.context },
97451
+ ...lifecycle.targetCommandId === void 0 ? {} : { targetCommandId: lifecycle.targetCommandId }
97452
+ },
97453
+ type: "lifecycle-metadata"
97454
+ });
97455
+ await this.recordLifecycleEvent({
97456
+ payload: {
97457
+ attemptId: lifecycle.attemptId,
97458
+ commandId: options.commandId,
97459
+ epoch: lifecycle.epoch,
97460
+ kind: "prompt.started"
97461
+ },
97462
+ type: "lifecycle-metadata"
97463
+ });
97454
97464
  });
97465
+ options.timing?.handedToAgent();
97455
97466
  }
97456
97467
  this.#delegableCommandId = lifecycle === void 0 ? null : options.commandId;
97457
97468
  if (lifecycle !== void 0) {
@@ -98784,12 +98795,13 @@ var SessionManager2 = class {
98784
98795
  if (cancelled()) {
98785
98796
  return { stopReason: "cancelled" };
98786
98797
  }
98787
- const runtime = await this.ensureSession(options2);
98798
+ const metrics = options2.timing?.metrics ?? unmeasuredOperationMetrics;
98799
+ const runtime = await metrics.measure("ensure-session", async () => await this.ensureSession(options2));
98788
98800
  if (cancelled()) {
98789
98801
  return { stopReason: "cancelled" };
98790
98802
  }
98791
98803
  try {
98792
- await runtime.preparePrompt(options2.signal);
98804
+ await metrics.measure("prepare-prompt", async () => await runtime.preparePrompt(options2.signal));
98793
98805
  if (cancelled()) {
98794
98806
  return { stopReason: "cancelled" };
98795
98807
  }
@@ -103544,20 +103556,46 @@ async function executePrompt({
103544
103556
  signal,
103545
103557
  cancellationRequested
103546
103558
  }) {
103559
+ const receivedAt = performance.now();
103560
+ const metrics = new AccumulatingOperationMetrics(Number.POSITIVE_INFINITY);
103561
+ const timing = {
103562
+ metrics,
103563
+ handedToAgent: () => {
103564
+ console.info(
103565
+ JSON.stringify({
103566
+ event: "runtime-prompt-preparation-timing",
103567
+ sessionId: command.sessionId,
103568
+ commandId: command.commandId,
103569
+ observedAt: Date.now(),
103570
+ phases: {
103571
+ ...Object.fromEntries(
103572
+ metrics.snapshot().map((metric) => [metric.name, metric.durationMilliseconds])
103573
+ ),
103574
+ total: performance.now() - receivedAt
103575
+ }
103576
+ })
103577
+ );
103578
+ }
103579
+ };
103547
103580
  try {
103548
- const resolved = await resolveSessionDirectories(
103549
- directories,
103550
- command.bindingId,
103551
- command.directoryId,
103552
- command.additionalDirectoryIds,
103553
- signal
103581
+ const resolved = await metrics.measure(
103582
+ "resolve-directories",
103583
+ async () => await resolveSessionDirectories(
103584
+ directories,
103585
+ command.bindingId,
103586
+ command.directoryId,
103587
+ command.additionalDirectoryIds,
103588
+ signal
103589
+ )
103554
103590
  );
103555
- const { agent: agent2, adapter, externalizeSessionUpdate } = await resolveAgent(
103556
- command.agentId,
103557
- signal,
103558
- command.sessionId
103591
+ const { agent: agent2, adapter, externalizeSessionUpdate } = await metrics.measure(
103592
+ "resolve-agent",
103593
+ async () => await resolveAgent(command.agentId, signal, command.sessionId)
103594
+ );
103595
+ const availability = await metrics.measure(
103596
+ "await-session-availability",
103597
+ async () => await waitForSessionAvailability(signal)
103559
103598
  );
103560
- const availability = await waitForSessionAvailability(signal);
103561
103599
  if (availability.kind === "busy") {
103562
103600
  throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
103563
103601
  }
@@ -103588,21 +103626,31 @@ async function executePrompt({
103588
103626
  if (availability.disposition !== SessionPromptDisposition.Steer) {
103589
103627
  sessions.promptSuggestions.want(command.sessionId, command.suggestNextPrompt === true);
103590
103628
  }
103591
- let prepared = await sessions.prepareExecutionSession(preparation);
103629
+ let prepared = await metrics.measure(
103630
+ "prepare-session",
103631
+ async () => await sessions.prepareExecutionSession(preparation)
103632
+ );
103592
103633
  if (command.sessionConfigurations !== void 0 && availability.disposition !== SessionPromptDisposition.Steer) {
103593
- await applyCompleteSessionConfiguration(
103594
- sessions,
103595
- prepared.configOptions,
103596
- sessionConfigurations ?? [],
103597
- executionAgent,
103598
- adapter,
103599
- resolved.cwd,
103600
- resolved.additionalDirectories,
103601
- command.commandId,
103602
- command.sessionId,
103603
- signal
103634
+ const configurations = prepared.configOptions;
103635
+ await metrics.measure(
103636
+ "apply-configuration",
103637
+ async () => await applyCompleteSessionConfiguration(
103638
+ sessions,
103639
+ configurations,
103640
+ sessionConfigurations ?? [],
103641
+ executionAgent,
103642
+ adapter,
103643
+ resolved.cwd,
103644
+ resolved.additionalDirectories,
103645
+ command.commandId,
103646
+ command.sessionId,
103647
+ signal
103648
+ )
103649
+ );
103650
+ prepared = await metrics.measure(
103651
+ "prepare-session",
103652
+ async () => await sessions.prepareExecutionSession(preparation)
103604
103653
  );
103605
- prepared = await sessions.prepareExecutionSession(preparation);
103606
103654
  }
103607
103655
  signal.throwIfAborted();
103608
103656
  const lifecycle = eventProjection.lifecycle(
@@ -103612,7 +103660,10 @@ async function executePrompt({
103612
103660
  epoch,
103613
103661
  availability.disposition
103614
103662
  );
103615
- const attachments = await resolvePromptArtifacts(readArtifact, command.attachments, signal);
103663
+ const attachments = await metrics.measure(
103664
+ "resolve-attachments",
103665
+ async () => await resolvePromptArtifacts(readArtifact, command.attachments, signal)
103666
+ );
103616
103667
  const skipped = command.attachments.length - attachments.images.length - attachments.resources.length;
103617
103668
  if (skipped > 0) {
103618
103669
  reportFailure("prompt_attachments_skipped", command.commandId, { count: skipped.toString() });
@@ -103656,6 +103707,7 @@ async function executePrompt({
103656
103707
  resources: attachments.resources,
103657
103708
  sessionId: command.sessionId,
103658
103709
  signal,
103710
+ timing,
103659
103711
  ...suggestion2 === "requested" ? { suggestNextPrompt: true } : {},
103660
103712
  targetCommandId: command.targetCommandId,
103661
103713
  recovery
@@ -105106,6 +105158,7 @@ var MAX_SESSION_EVENT_RESENDS = 5;
105106
105158
  var RuntimeSessionEventPublisher = class {
105107
105159
  #retained = [];
105108
105160
  #sessions = /* @__PURE__ */ new Map();
105161
+ /** Sessions whose latest prompt has started and has not yet produced its first answer text. */
105109
105162
  #awaitingFirstAnswer = /* @__PURE__ */ new Map();
105110
105163
  #retainedBytes = 0;
105111
105164
  #unsentCount = 0;
@@ -105239,7 +105292,8 @@ var RuntimeSessionEventPublisher = class {
105239
105292
  return;
105240
105293
  }
105241
105294
  const awaiting = this.#awaitingFirstAnswer.get(event.sessionId);
105242
- const firstAnswer = this.#consumeFirstAnswer(event);
105295
+ const decision = this.#decideHandoff(event);
105296
+ const firstAnswer = decision.firstAnswer;
105243
105297
  this.#retained.push({
105244
105298
  event,
105245
105299
  position: Number(event.position),
@@ -105261,7 +105315,7 @@ var RuntimeSessionEventPublisher = class {
105261
105315
  return;
105262
105316
  }
105263
105317
  const socket = connection.socket;
105264
- if (firstAnswer || this.#unsentCount >= SESSION_EVENT_BATCH_MAX_SIZE || EMPTY_ENVELOPE_BYTES + this.#unsentBytes >= MAX_EVENT_BATCH_BYTES) {
105318
+ if (decision.immediate || this.#unsentCount >= SESSION_EVENT_BATCH_MAX_SIZE || EMPTY_ENVELOPE_BYTES + this.#unsentBytes >= MAX_EVENT_BATCH_BYTES) {
105265
105319
  this.flushEvents(socket);
105266
105320
  return;
105267
105321
  }
@@ -105350,24 +105404,48 @@ var RuntimeSessionEventPublisher = class {
105350
105404
  delivery.resends = 0;
105351
105405
  }
105352
105406
  };
105353
- #consumeFirstAnswer = (event) => {
105407
+ /**
105408
+ * Decides whether `event` leaves without waiting for the batching window: the first thought or message after a
105409
+ * `prompt.started`, and the first answer text. Only the send time differs; batches keep the published order, so
105410
+ * whatever was waiting, the start included, leaves with them.
105411
+ *
105412
+ * The start itself and tool calls stay batched, because a client may act on either the moment it sees it. A
105413
+ * prompt is recorded as started just before it is handed to the Agent, and a cancellation that arrives in
105414
+ * between reaches an Agent that has nothing to cancel yet. An Agent such as Antigravity refuses steering for an
105415
+ * instant after announcing a command. The first thought or message cannot come before the Agent has the prompt.
105416
+ */
105417
+ #decideHandoff = (event) => {
105418
+ const batched = { firstAnswer: false, immediate: false };
105354
105419
  if (event.type === "lifecycle-metadata") {
105355
105420
  const payload = event.payload;
105356
105421
  if (payload.kind === "prompt.started") {
105357
105422
  this.#awaitingFirstAnswer.set(event.sessionId, {
105358
105423
  commandId: payload.commandId,
105359
- generationId: event.sessionGenerationId
105424
+ generationId: event.sessionGenerationId,
105425
+ output: "awaiting-first-output"
105360
105426
  });
105361
- } else if (isPromptTerminal(payload) && this.#awaitingFirstAnswer.get(event.sessionId)?.commandId === payload.commandId && this.#awaitingFirstAnswer.get(event.sessionId)?.generationId === event.sessionGenerationId) {
105427
+ return batched;
105428
+ }
105429
+ if (isPromptTerminal(payload) && this.#awaitingFirstAnswer.get(event.sessionId)?.commandId === payload.commandId && this.#awaitingFirstAnswer.get(event.sessionId)?.generationId === event.sessionGenerationId) {
105362
105430
  this.#awaitingFirstAnswer.delete(event.sessionId);
105363
105431
  }
105364
- return false;
105432
+ return batched;
105365
105433
  }
105366
- if (event.type !== "acp" || event.payload.sessionUpdate !== "agent_message_chunk" || event.payload.content.type !== "text" || event.payload.content.text.length === 0 || this.#awaitingFirstAnswer.get(event.sessionId)?.generationId !== event.sessionGenerationId) {
105367
- return false;
105434
+ const awaiting = this.#awaitingFirstAnswer.get(event.sessionId);
105435
+ if (event.type !== "acp" || awaiting?.generationId !== event.sessionGenerationId) {
105436
+ return batched;
105368
105437
  }
105369
- this.#awaitingFirstAnswer.delete(event.sessionId);
105370
- return true;
105438
+ const update = event.payload;
105439
+ if (update.sessionUpdate === "agent_message_chunk" && update.content.type === "text" && update.content.text.length > 0) {
105440
+ this.#awaitingFirstAnswer.delete(event.sessionId);
105441
+ return { firstAnswer: true, immediate: true };
105442
+ }
105443
+ const isOutput = update.sessionUpdate === "agent_message_chunk" || update.sessionUpdate === "agent_thought_chunk";
105444
+ if (isOutput && awaiting.output === "awaiting-first-output") {
105445
+ this.#awaitingFirstAnswer.set(event.sessionId, { ...awaiting, output: "first-output-handed-off" });
105446
+ return { firstAnswer: false, immediate: true };
105447
+ }
105448
+ return batched;
105371
105449
  };
105372
105450
  cancelFlush = () => {
105373
105451
  this.#pendingTask?.cancel();
@@ -106018,4 +106096,4 @@ export {
106018
106096
  * MIT Licensed
106019
106097
  *)
106020
106098
  */
106021
- //# sourceMappingURL=chunk-YN6SPJT7.js.map
106099
+ //# sourceMappingURL=chunk-7P2QHD5S.js.map