@moxt-ai/mobius 0.0.464 → 0.0.465

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.
@@ -5,7 +5,7 @@ import {
5
5
  __toESM,
6
6
  __using,
7
7
  package_default
8
- } from "./chunk-W5MXRFJ5.js";
8
+ } from "./chunk-RQXSP55N.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
@@ -106018,4 +106070,4 @@ export {
106018
106070
  * MIT Licensed
106019
106071
  *)
106020
106072
  */
106021
- //# sourceMappingURL=chunk-YN6SPJT7.js.map
106073
+ //# sourceMappingURL=chunk-CPVZCCBS.js.map