@moxt-ai/mobius 0.0.387 → 0.0.388

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 (48) hide show
  1. package/dist/{chunk-A62FEGIN.js → chunk-7BSIM5AK.js} +123 -114
  2. package/dist/{chunk-A62FEGIN.js.map → chunk-7BSIM5AK.js.map} +3 -3
  3. package/dist/{chunk-S7PKNDIS.js → chunk-Z4WUPVBL.js} +2 -2
  4. package/dist/{chunk-S7PKNDIS.js.map → chunk-Z4WUPVBL.js.map} +1 -1
  5. package/dist/{cli-43LPJ5ID.js → cli-O57WJIFN.js} +3 -3
  6. package/dist/cli.js +2 -2
  7. package/dist/engine/runtime/command/registry/prompt.d.ts.map +1 -1
  8. package/dist/engine/runtime/command/registry/prompt.js +2 -3
  9. package/dist/engine/runtime/command/registry/prompt.js.map +1 -1
  10. package/dist/engine/runtime/relay/session-event-publisher.d.ts.map +1 -1
  11. package/dist/engine/runtime/relay/session-event-publisher.js +2 -4
  12. package/dist/engine/runtime/relay/session-event-publisher.js.map +1 -1
  13. package/dist/engine/session/api/session-layer.js +3 -3
  14. package/dist/engine/session/api/session-layer.js.map +1 -1
  15. package/dist/engine/session/live/agent-session.d.ts.map +1 -1
  16. package/dist/engine/session/live/agent-session.js +4 -3
  17. package/dist/engine/session/live/agent-session.js.map +1 -1
  18. package/dist/engine/session/prompt/execute-prompt.d.ts +8 -8
  19. package/dist/engine/session/prompt/execute-prompt.d.ts.map +1 -1
  20. package/dist/engine/session/prompt/execute-prompt.js +10 -10
  21. package/dist/engine/session/prompt/execute-prompt.js.map +1 -1
  22. package/dist/engine/session/prompt/prompt-lifecycle.d.ts +8 -4
  23. package/dist/engine/session/prompt/prompt-lifecycle.d.ts.map +1 -1
  24. package/dist/engine/session/prompt/prompt-lifecycle.js +18 -17
  25. package/dist/engine/session/prompt/prompt-lifecycle.js.map +1 -1
  26. package/dist/engine/session/turn/active-executions.d.ts +4 -2
  27. package/dist/engine/session/turn/active-executions.d.ts.map +1 -1
  28. package/dist/engine/session/turn/active-executions.js +4 -6
  29. package/dist/engine/session/turn/active-executions.js.map +1 -1
  30. package/dist/engine/session/turn/active-turn.d.ts +12 -8
  31. package/dist/engine/session/turn/active-turn.d.ts.map +1 -1
  32. package/dist/engine/session/turn/active-turn.js +47 -36
  33. package/dist/engine/session/turn/active-turn.js.map +1 -1
  34. package/dist/engine/session/turn/execution-receipts.d.ts +6 -2
  35. package/dist/engine/session/turn/execution-receipts.d.ts.map +1 -1
  36. package/dist/engine/session/turn/execution-receipts.js +18 -32
  37. package/dist/engine/session/turn/execution-receipts.js.map +1 -1
  38. package/dist/engine/session/turn/session-execution.d.ts +6 -2
  39. package/dist/engine/session/turn/session-execution.d.ts.map +1 -1
  40. package/dist/engine/session/turn/session-execution.js +10 -7
  41. package/dist/engine/session/turn/session-execution.js.map +1 -1
  42. package/dist/engine/session/turn/session-turns.d.ts +1 -1
  43. package/dist/engine/session/turn/session-turns.d.ts.map +1 -1
  44. package/dist/engine/session/turn/session-turns.js +1 -1
  45. package/dist/engine/session/turn/session-turns.js.map +1 -1
  46. package/dist/engine.js +2 -2
  47. package/package.json +2 -2
  48. /package/dist/{cli-43LPJ5ID.js.map → cli-O57WJIFN.js.map} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  __export,
4
4
  __using,
5
5
  package_default
6
- } from "./chunk-S7PKNDIS.js";
6
+ } from "./chunk-Z4WUPVBL.js";
7
7
 
8
8
  // src/engine/runtime/relay/runtime-revocation.ts
9
9
  var runtimeRevocationCloseCode = 1008;
@@ -20760,6 +20760,27 @@ var lifecycleMetadataSchema = external_exports.discriminatedUnion("kind", [
20760
20760
  message: external_exports.string().min(1).max(500)
20761
20761
  }).readonly()
20762
20762
  ]);
20763
+ var isPromptTerminal = (payload) => {
20764
+ switch (payload.kind) {
20765
+ case "prompt.completed":
20766
+ case "prompt.failed":
20767
+ case "prompt.failed-before-start":
20768
+ return true;
20769
+ case "prompt.requested":
20770
+ case "prompt.started":
20771
+ case "session.queue.changed":
20772
+ case "session.permission.requested":
20773
+ case "session.permission.resolved":
20774
+ case "session.elicitation.requested":
20775
+ case "session.elicitation.resolved":
20776
+ return false;
20777
+ default: {
20778
+ const unknownKind = payload;
20779
+ void unknownKind;
20780
+ return false;
20781
+ }
20782
+ }
20783
+ };
20763
20784
  var sessionEventPayloadSchema = external_exports.discriminatedUnion("type", [
20764
20785
  external_exports.object({ payload: acpSessionUpdateSchema, type: external_exports.literal("acp") }).readonly(),
20765
20786
  external_exports.object({ payload: lifecycleMetadataSchema, type: external_exports.literal("lifecycle-metadata") }).readonly()
@@ -86672,9 +86693,6 @@ var AgentSession = class _AgentSession {
86672
86693
  additionalDirectories: this.#additionalDirectories
86673
86694
  });
86674
86695
  prompt = async (options) => {
86675
- if (this.#turn.running) {
86676
- throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
86677
- }
86678
86696
  if (!this.#capabilities.loadSession && this.#sessionLoad.kind === "not-requested") {
86679
86697
  this.#sessionLoad = {
86680
86698
  kind: "loaded",
@@ -86693,6 +86711,7 @@ var AgentSession = class _AgentSession {
86693
86711
  await this.#completedHistory(options.signal);
86694
86712
  }
86695
86713
  validatePromptContent(options, this.#capabilities);
86714
+ options.signal.throwIfAborted();
86696
86715
  if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
86697
86716
  this.#sessionTitle = conversationTitleFromText(options.prompt);
86698
86717
  }
@@ -86773,6 +86792,7 @@ var AgentSession = class _AgentSession {
86773
86792
  throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
86774
86793
  }
86775
86794
  validatePromptContent(options, this.#capabilities);
86795
+ options.signal.throwIfAborted();
86776
86796
  const lifecycle = options.lifecycle;
86777
86797
  if (lifecycle !== void 0) {
86778
86798
  await this.recordLifecycleEvent({
@@ -87018,9 +87038,6 @@ var ActiveExecutions = class {
87018
87038
  };
87019
87039
  isBusy = (id) => this.#entries.has(id);
87020
87040
  begin = (id, commandId) => {
87021
- if (this.#entries.has(id)) {
87022
- throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
87023
- }
87024
87041
  this.#entries.set(id, { kind: "running", commandId });
87025
87042
  };
87026
87043
  cancel = (id, commandId, stop) => {
@@ -88351,16 +88368,17 @@ function promptContent(command) {
88351
88368
  }
88352
88369
  var PromptLifecycle = class {
88353
88370
  #sink;
88371
+ /** Terminal events held until their command's admission and execution state are released. */
88354
88372
  #terminal = /* @__PURE__ */ new Map();
88355
88373
  #publications = /* @__PURE__ */ new Map();
88356
88374
  #queued = /* @__PURE__ */ new Map();
88357
88375
  #recordActiveTurn;
88358
- #hasStarted;
88376
+ #executions;
88359
88377
  #recordLifecycle;
88360
- constructor(sink, recordLifecycle, recordActiveTurn, hasStarted) {
88378
+ constructor(sink, recordLifecycle, recordActiveTurn, executions) {
88361
88379
  this.#recordLifecycle = recordLifecycle;
88362
88380
  this.#recordActiveTurn = recordActiveTurn;
88363
- this.#hasStarted = hasStarted;
88381
+ this.#executions = executions;
88364
88382
  this.#sink = sink;
88365
88383
  }
88366
88384
  requested = (command) => {
@@ -88377,8 +88395,8 @@ var PromptLifecycle = class {
88377
88395
  ...command.targetCommandId.length === 0 ? {} : { targetCommandId: command.targetCommandId }
88378
88396
  });
88379
88397
  };
88380
- /** Metadata for an execution already claimed by the receipt owner. */
88381
- started = (sessionId, commandId, attemptId, epoch, disposition) => {
88398
+ /** The lifecycle metadata the Agent session records when it starts this claimed command. */
88399
+ lifecycle = (sessionId, commandId, attemptId, epoch, disposition) => {
88382
88400
  const request = this.#queued.get(commandId);
88383
88401
  if (request?.sessionId === sessionId) {
88384
88402
  return {
@@ -88395,7 +88413,7 @@ var PromptLifecycle = class {
88395
88413
  record = (recorded) => {
88396
88414
  this.#recordActiveTurn(recorded);
88397
88415
  const sessionId = recorded.sessionId;
88398
- if (recorded.type === "lifecycle-metadata" && (recorded.payload.kind === "prompt.completed" || recorded.payload.kind === "prompt.failed" || recorded.payload.kind === "prompt.failed-before-start")) {
88416
+ if (recorded.type === "lifecycle-metadata" && isPromptTerminal(recorded.payload)) {
88399
88417
  this.#terminal.set(recorded.payload.commandId, recorded);
88400
88418
  const pending2 = this.#publications.get(sessionId) ?? [];
88401
88419
  pending2.push(recorded);
@@ -88446,7 +88464,7 @@ var PromptLifecycle = class {
88446
88464
  };
88447
88465
  completed = async (sessionId, commandId, stopReason) => {
88448
88466
  const request = this.#queued.get(commandId);
88449
- if (request?.sessionId !== sessionId || this.#terminal.has(commandId)) {
88467
+ if (request?.sessionId !== sessionId || this.#executions.isTerminalExecution(commandId, sessionId)) {
88450
88468
  return;
88451
88469
  }
88452
88470
  const recorded = await this.#recordLifecycle(sessionId, {
@@ -88455,7 +88473,7 @@ var PromptLifecycle = class {
88455
88473
  kind: "prompt.completed",
88456
88474
  commandId,
88457
88475
  stopReason,
88458
- ...this.#hasStarted(commandId, sessionId) ? {} : { execution: "not-started" }
88476
+ ...this.#executions.hasStarted(commandId, sessionId) ? {} : { execution: "not-started" }
88459
88477
  }
88460
88478
  });
88461
88479
  if (!recorded) {
@@ -88467,21 +88485,24 @@ var PromptLifecycle = class {
88467
88485
  );
88468
88486
  }
88469
88487
  };
88470
- failed = async (sessionId, commandId, code, message) => {
88488
+ /** Settles a failed command; whether it failed before or after starting is its receipt's fact. */
88489
+ failed = async (sessionId, commandId, attemptId, code, message) => {
88471
88490
  const request = this.#queued.get(commandId);
88472
- if (request?.sessionId !== sessionId || this.#terminal.has(commandId)) {
88491
+ if (request?.sessionId !== sessionId || this.#executions.isTerminalExecution(commandId, sessionId)) {
88473
88492
  return;
88474
88493
  }
88475
88494
  const recorded = await this.#recordLifecycle(sessionId, {
88476
88495
  type: "lifecycle-metadata",
88477
- payload: { kind: "prompt.failed-before-start", commandId, code, message }
88496
+ payload: this.#executions.hasStarted(commandId, sessionId) ? { kind: "prompt.failed", attemptId, commandId, code, message } : { kind: "prompt.failed-before-start", commandId, code, message }
88478
88497
  });
88479
88498
  if (!recorded || code === SESSION_CLOSED_ERROR_CODE) {
88480
88499
  this.#sink.publishOperationFailure(sessionId, commandId, code, message);
88481
88500
  }
88482
88501
  };
88483
88502
  promptRequestRecovery = (sessionId) => ({
88484
- queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId && !this.#hasStarted(request.commandId, sessionId)).map(({ commandId, content, disposition, targetCommandId }) => ({
88503
+ queuedPromptRequests: [...this.#queued.values()].filter(
88504
+ (request) => request.sessionId === sessionId && !this.#executions.hasStarted(request.commandId, sessionId)
88505
+ ).map(({ commandId, content, disposition, targetCommandId }) => ({
88485
88506
  commandId,
88486
88507
  content,
88487
88508
  ...disposition === void 0 ? {} : { disposition },
@@ -88503,6 +88524,7 @@ async function settleAbandonedTurn(projection, operations, cancellation) {
88503
88524
  await projection.failed(
88504
88525
  cancellation.sessionId,
88505
88526
  cancellation.commandId,
88527
+ attemptId,
88506
88528
  "agent_execution_abandoned",
88507
88529
  "The local Agent execution was abandoned before it completed"
88508
88530
  );
@@ -88614,7 +88636,7 @@ var ExecutionReceipts = class {
88614
88636
  return { state: "accepted" };
88615
88637
  }
88616
88638
  const outcome = this.outcome(commandId);
88617
- if (outcome?.type !== "lifecycle-metadata") {
88639
+ if (outcome?.type !== "lifecycle-metadata" || !isPromptTerminal(outcome.payload)) {
88618
88640
  return { state: "expired" };
88619
88641
  }
88620
88642
  switch (outcome.payload.kind) {
@@ -88623,8 +88645,6 @@ var ExecutionReceipts = class {
88623
88645
  case "prompt.failed":
88624
88646
  case "prompt.failed-before-start":
88625
88647
  return { code: outcome.payload.code, state: "failed" };
88626
- default:
88627
- return { state: "expired" };
88628
88648
  }
88629
88649
  };
88630
88650
  /**
@@ -88647,7 +88667,7 @@ var ExecutionReceipts = class {
88647
88667
  }
88648
88668
  }
88649
88669
  const outcome = last === void 0 ? void 0 : this.outcome(last);
88650
- if (last === void 0 || outcome?.type !== "lifecycle-metadata") {
88670
+ if (last === void 0 || outcome?.type !== "lifecycle-metadata" || !isPromptTerminal(outcome.payload)) {
88651
88671
  return void 0;
88652
88672
  }
88653
88673
  switch (outcome.payload.kind) {
@@ -88661,8 +88681,6 @@ var ExecutionReceipts = class {
88661
88681
  message: outcome.payload.message,
88662
88682
  state: "failed"
88663
88683
  };
88664
- default:
88665
- return void 0;
88666
88684
  }
88667
88685
  };
88668
88686
  /** Started identities remain authoritative after their detailed receipt is evicted. */
@@ -88706,12 +88724,24 @@ var ExecutionReceipts = class {
88706
88724
  });
88707
88725
  return outcome;
88708
88726
  };
88709
- recordOutcome = (event) => {
88727
+ /**
88728
+ * Receipts follow their command's recorded lifecycle. `prompt.started` is recorded where the command is handed
88729
+ * to the Agent, so the started mark and the event clients see are one transition; a terminal event settles the
88730
+ * receipt. Nothing else marks a command started.
88731
+ */
88732
+ record = (event) => {
88710
88733
  if (event.type !== "lifecycle-metadata") {
88711
88734
  return;
88712
88735
  }
88713
88736
  const payload = event.payload;
88714
- if (payload.kind !== "prompt.completed" && payload.kind !== "prompt.failed" && payload.kind !== "prompt.failed-before-start") {
88737
+ if (payload.kind === "prompt.started") {
88738
+ const receipt2 = this.#executions.get(payload.commandId);
88739
+ if (receipt2?.state.kind === "pending") {
88740
+ this.#save(payload.commandId, { ...receipt2, state: { kind: "started" } });
88741
+ }
88742
+ return;
88743
+ }
88744
+ if (!isPromptTerminal(payload)) {
88715
88745
  return;
88716
88746
  }
88717
88747
  const receipt = this.#executions.get(payload.commandId);
@@ -88794,27 +88824,6 @@ var ExecutionReceipts = class {
88794
88824
  });
88795
88825
  return { attemptId, commandId, kind: "accepted" };
88796
88826
  };
88797
- markExecutionStarted = (commandId) => {
88798
- const current = this.#executions.get(commandId);
88799
- if (current === void 0) {
88800
- throw new Error("The runtime execution receipt does not exist");
88801
- }
88802
- const state = current.state;
88803
- switch (state.kind) {
88804
- case "pending":
88805
- this.#save(commandId, { ...current, state: { kind: "started" } });
88806
- return;
88807
- case "started":
88808
- return;
88809
- case "settled-before-start":
88810
- case "settled-after-start":
88811
- throw new Error("The runtime execution transition is invalid");
88812
- default: {
88813
- const unreachable2 = state;
88814
- throw new Error("Unexpected execution state", { cause: unreachable2 });
88815
- }
88816
- }
88817
- };
88818
88827
  /** Only commands without a terminal result can still be cancelled. */
88819
88828
  findUnsettledAttemptId = (commandId, sessionId) => {
88820
88829
  const receipt = this.#executions.get(commandId);
@@ -88922,69 +88931,79 @@ import { randomUUID as randomUUID16 } from "node:crypto";
88922
88931
  var ActiveRuntimeTurn = class {
88923
88932
  attemptId;
88924
88933
  command;
88934
+ epoch = decodeIdentifier(randomUUID16());
88925
88935
  #controller;
88926
88936
  #finished = Promise.withResolvers();
88937
+ #started;
88927
88938
  #cancellationRequested = false;
88928
- #dispatch;
88939
+ #admission = { kind: "waiting" };
88929
88940
  #sequence = 0;
88930
88941
  #interaction = null;
88931
- #epoch = decodeIdentifier(randomUUID16());
88932
- constructor(command, attemptId) {
88942
+ /** `started` reads the command's execution receipt, the single owner of whether the command started. */
88943
+ constructor(command, attemptId, started) {
88933
88944
  this.attemptId = attemptId;
88934
88945
  this.command = command;
88935
88946
  this.#controller = new AbortController();
88936
- this.#dispatch = { kind: "pending" };
88947
+ this.#started = started;
88937
88948
  }
88938
88949
  enqueue = () => {
88939
- if (this.#dispatch.kind !== "pending") {
88940
- throw new Error("Only a pending prompt can enter the queue");
88950
+ if (this.#admission.kind !== "waiting") {
88951
+ throw new Error("Only a waiting prompt can enter the queue");
88941
88952
  }
88942
- this.#dispatch = { kind: "queued", promotion: Promise.withResolvers() };
88953
+ this.#admission = { kind: "queued", promotion: Promise.withResolvers() };
88943
88954
  };
88944
- isQueued = () => (this.#dispatch.kind === "queued" || this.#dispatch.kind === "admitted" && this.#dispatch.disposition === SessionPromptDisposition.Queue) && !this.#controller.signal.aborted;
88955
+ isQueued = () => (this.#admission.kind === "queued" || this.#admission.kind === "admitted" && this.#admission.disposition === SessionPromptDisposition.Queue) && !this.#started() && !this.#controller.signal.aborted;
88956
+ /** Whether the command's execution was handed to the Agent. */
88957
+ hasStarted = () => this.#started();
88945
88958
  abortRuntime = () => {
88946
88959
  this.#controller.abort();
88947
88960
  };
88948
88961
  finish = () => {
88949
88962
  this.#finished.resolve();
88950
88963
  };
88951
- activate = (execution) => {
88952
- this.#dispatch = { kind: "running", execution };
88953
- return { epoch: this.#epoch, sequence: 0 };
88954
- };
88955
88964
  promoteQueuedPrompt = (command) => {
88956
88965
  if (command.commandId !== this.command.commandId || command.sessionId !== this.command.sessionId || this.#controller.signal.aborted) {
88957
88966
  return "unavailable";
88958
88967
  }
88959
- switch (this.#dispatch.kind) {
88968
+ switch (this.#admission.kind) {
88960
88969
  case "queued": {
88961
- const promotion = this.#dispatch.promotion;
88962
- this.#dispatch = { kind: "promoted" };
88970
+ const promotion = this.#admission.promotion;
88971
+ this.#admission = { kind: "promoted" };
88963
88972
  promotion.resolve();
88964
88973
  return "accepted";
88965
88974
  }
88966
88975
  case "promoted":
88967
88976
  return "accepted";
88968
88977
  case "admitted":
88969
- return this.#dispatch.disposition === SessionPromptDisposition.Steer ? "accepted" : "already-started";
88970
- case "running":
88971
- return "already-started";
88972
- case "pending":
88978
+ return this.#admission.disposition === SessionPromptDisposition.Steer ? "accepted" : "already-started";
88979
+ case "waiting":
88973
88980
  return "unavailable";
88974
88981
  }
88975
88982
  };
88976
88983
  admit = () => {
88977
88984
  const disposition = this.effectiveDisposition();
88978
- this.#dispatch = { kind: "admitted", disposition };
88985
+ this.#admission = { kind: "admitted", disposition };
88979
88986
  return disposition;
88980
88987
  };
88981
88988
  queuePromotion = () => {
88982
- if (this.#dispatch.kind === "queued") {
88983
- return this.#dispatch.promotion.promise;
88989
+ if (this.#admission.kind === "queued") {
88990
+ return this.#admission.promotion.promise;
88984
88991
  }
88985
- return this.#dispatch.kind === "promoted" ? Promise.resolve() : null;
88992
+ return this.#admission.kind === "promoted" ? Promise.resolve() : null;
88986
88993
  };
88987
- effectiveDisposition = () => this.#dispatch.kind === "promoted" ? SessionPromptDisposition.Steer : this.command.disposition;
88994
+ effectiveDisposition = () => {
88995
+ switch (this.#admission.kind) {
88996
+ case "waiting":
88997
+ case "queued":
88998
+ return this.command.disposition;
88999
+ case "promoted":
89000
+ return SessionPromptDisposition.Steer;
89001
+ case "admitted":
89002
+ return this.#admission.disposition;
89003
+ }
89004
+ };
89005
+ /** A steering prompt joins the execution of the turn it steers; every other prompt owns its execution. */
89006
+ execution = () => this.effectiveDisposition() === SessionPromptDisposition.Steer ? this.command.targetCommandId : this.command.commandId;
88988
89007
  recordEvent = (event) => {
88989
89008
  if (event.sessionId !== this.command.sessionId || "commandId" in event && event.commandId !== this.command.commandId) {
88990
89009
  return event;
@@ -88996,33 +89015,33 @@ var ActiveRuntimeTurn = class {
88996
89015
  }
88997
89016
  return event;
88998
89017
  };
88999
- recordSteeringPrompt = (command) => {
89000
- return this.#dispatch.kind === "running" && command.sessionId === this.command.sessionId && command.targetCommandId === this.command.commandId;
89001
- };
89002
89018
  snapshot = () => {
89003
- if (this.#dispatch.kind !== "running") {
89019
+ if (!this.#started()) {
89004
89020
  return null;
89005
89021
  }
89006
89022
  return {
89007
89023
  commandId: decodeIdentifier(this.command.commandId),
89008
- epoch: this.#epoch,
89024
+ epoch: this.epoch,
89009
89025
  interaction: this.#interaction,
89010
89026
  sequence: this.#sequence,
89011
89027
  state: "running"
89012
89028
  };
89013
89029
  };
89014
- matches = (cancellation) => cancellation.commandId === this.command.commandId && cancellation.sessionId === this.command.sessionId;
89015
89030
  matchesInteraction = (interactionId, sessionId) => this.command.sessionId === sessionId && this.#interaction?.interactionId === interactionId;
89031
+ /**
89032
+ * Before the command starts, cancellation withdraws it by aborting its own admission and preparation. Once it
89033
+ * started, the Agent execution it belongs to must be asked to stop.
89034
+ */
89016
89035
  requestCancellation = () => {
89017
89036
  if (this.#cancellationRequested) {
89018
89037
  return { kind: "already-requested" };
89019
89038
  }
89020
89039
  this.#cancellationRequested = true;
89021
- if (this.#dispatch.kind !== "running") {
89022
- this.#controller.abort(new Error("The queued Agent turn was cancelled"));
89040
+ if (!this.#started()) {
89041
+ this.#controller.abort(new Error("The Agent turn was cancelled before it started"));
89023
89042
  return { kind: "pending" };
89024
89043
  }
89025
- return { kind: "running", execution: this.#dispatch.execution };
89044
+ return { kind: "running", execution: this.execution() };
89026
89045
  };
89027
89046
  cancellationRequested = () => this.#cancellationRequested;
89028
89047
  get signal() {
@@ -89068,7 +89087,11 @@ var SessionExecutionState = class {
89068
89087
  }
89069
89088
  isEmpty = () => this.#turnsByCommandId.size === 0;
89070
89089
  start = (command, attemptId) => {
89071
- const turn = new ActiveRuntimeTurn(command, attemptId);
89090
+ const turn = new ActiveRuntimeTurn(
89091
+ command,
89092
+ attemptId,
89093
+ () => this.#operations.hasStarted(command.commandId, this.#sessionId)
89094
+ );
89072
89095
  this.#turnsByCommandId.set(command.commandId, turn);
89073
89096
  return turn;
89074
89097
  };
@@ -89093,10 +89116,8 @@ var SessionExecutionState = class {
89093
89116
  }
89094
89117
  return event;
89095
89118
  };
89096
- recordSteeringPrompt = (command) => {
89097
- const target = this.#turnsByCommandId.get(command.targetCommandId);
89098
- return target?.recordSteeringPrompt(command) ?? false;
89099
- };
89119
+ /** A steering prompt can join only a target whose execution already started. */
89120
+ steerTargetStarted = (command) => this.#turnsByCommandId.get(command.targetCommandId)?.hasStarted() ?? false;
89100
89121
  turns = () => [...this.#turnsByCommandId.values()];
89101
89122
  close = async () => {
89102
89123
  const turns = [...this.#turnsByCommandId.values()];
@@ -89109,7 +89130,7 @@ var SessionExecutionState = class {
89109
89130
  const command = turn.command;
89110
89131
  waitSignal.throwIfAborted();
89111
89132
  const head = () => [...this.#turnsByCommandId.values()].find(
89112
- (turn2) => turn2.command.disposition !== SessionPromptDisposition.Steer
89133
+ (turn2) => turn2.effectiveDisposition() !== SessionPromptDisposition.Steer
89113
89134
  );
89114
89135
  if (command.disposition === SessionPromptDisposition.Queue) {
89115
89136
  const target = head();
@@ -89181,7 +89202,7 @@ var SessionTurns = class {
89181
89202
  this.recordEvent(event.payload.event);
89182
89203
  }
89183
89204
  };
89184
- recordSteeringPrompt = (command) => this.#bySessionId.get(command.sessionId)?.recordSteeringPrompt(command) ?? false;
89205
+ steerTargetStarted = (command) => this.#bySessionId.get(command.sessionId)?.steerTargetStarted(command) ?? false;
89185
89206
  executionSnapshot = async (matches) => {
89186
89207
  for (const session of this.#bySessionId.values()) {
89187
89208
  const matching = [];
@@ -89431,7 +89452,7 @@ function buildSessionLayer(options) {
89431
89452
  const manager = new SessionManager2({
89432
89453
  observer: new SessionLayerObserver(
89433
89454
  (event) => {
89434
- operations.recordOutcome(event);
89455
+ operations.record(event);
89435
89456
  eventProjection.record(event);
89436
89457
  },
89437
89458
  sink.publishInfo,
@@ -89454,12 +89475,12 @@ function buildSessionLayer(options) {
89454
89475
  return true;
89455
89476
  }
89456
89477
  const recorded = events.append(sessionId, event);
89457
- operations.recordOutcome(recorded);
89478
+ operations.record(recorded);
89458
89479
  eventProjection.record(recorded);
89459
89480
  return true;
89460
89481
  },
89461
89482
  activeSessions.recordSessionEvent,
89462
- operations.hasStarted
89483
+ operations
89463
89484
  );
89464
89485
  const nativeSessions = new NativeSessionService(
89465
89486
  bindingId,
@@ -91742,7 +91763,6 @@ function warnIgnoredSetting(event, commandId, sessionId, agentId, selection, cat
91742
91763
 
91743
91764
  // src/engine/session/prompt/execute-prompt.ts
91744
91765
  async function executePrompt({
91745
- operations,
91746
91766
  eventProjection,
91747
91767
  command,
91748
91768
  resolveAgent,
@@ -91751,10 +91771,10 @@ async function executePrompt({
91751
91771
  directories,
91752
91772
  sessions,
91753
91773
  attemptId,
91754
- activateAttempt,
91774
+ epoch,
91755
91775
  waitForSessionAvailability,
91756
91776
  signal,
91757
- recordSteeringPrompt,
91777
+ steerTargetStarted,
91758
91778
  cancellationRequested
91759
91779
  }) {
91760
91780
  try {
@@ -91812,24 +91832,14 @@ async function executePrompt({
91812
91832
  prepared = await sessions.prepareExecutionSession(preparation);
91813
91833
  }
91814
91834
  signal.throwIfAborted();
91815
- operations.markExecutionStarted(command.commandId);
91816
- if (availability.disposition === SessionPromptDisposition.Steer) {
91817
- if (!recordSteeringPrompt()) {
91818
- throw new AcpExecutionError(
91819
- "The steering target is unavailable",
91820
- {},
91821
- "prompt_queue_target_unavailable"
91822
- );
91823
- }
91835
+ if (availability.disposition === SessionPromptDisposition.Steer && !steerTargetStarted()) {
91836
+ throw new AcpExecutionError("The steering target is unavailable", {}, "prompt_queue_target_unavailable");
91824
91837
  }
91825
- const stream = activateAttempt(
91826
- availability.disposition === SessionPromptDisposition.Steer ? command.targetCommandId : command.commandId
91827
- );
91828
- const lifecycle = eventProjection.started(
91838
+ const lifecycle = eventProjection.lifecycle(
91829
91839
  command.sessionId,
91830
91840
  command.commandId,
91831
91841
  attemptId,
91832
- stream.epoch,
91842
+ epoch,
91833
91843
  availability.disposition
91834
91844
  );
91835
91845
  const attachments = await resolvePromptArtifacts(readArtifact, command.attachments, signal);
@@ -91888,7 +91898,7 @@ async function executePrompt({
91888
91898
  const code = operationErrorCode(error62);
91889
91899
  const failureCode = code === "session_operation_failed" ? "agent_execution_failed" : code;
91890
91900
  const failureMessage = code === "session_operation_failed" ? "The local agent could not complete the request" : operationErrorMessage(error62);
91891
- await eventProjection.failed(command.sessionId, command.commandId, failureCode, failureMessage);
91901
+ await eventProjection.failed(command.sessionId, command.commandId, attemptId, failureCode, failureMessage);
91892
91902
  reportFailure("session_prompt_failed", command.commandId, {
91893
91903
  agentId: command.agentId,
91894
91904
  code: failureCode,
@@ -91958,7 +91968,6 @@ var sessionPromptCommand = {
91958
91968
  });
91959
91969
  };
91960
91970
  void executePrompt({
91961
- operations: context.operations,
91962
91971
  eventProjection: context.eventProjection,
91963
91972
  command: message,
91964
91973
  resolveAgent: context.resolveAgent,
@@ -91977,12 +91986,12 @@ var sessionPromptCommand = {
91977
91986
  directories: context.directories,
91978
91987
  sessions: context.sessions,
91979
91988
  attemptId: receipt.attemptId,
91980
- activateAttempt: turn.activate,
91989
+ epoch: turn.epoch,
91981
91990
  waitForSessionAvailability: (signal) => context.sessionTurns.admitAndWait(turn, signal, () => {
91982
91991
  queueChanged();
91983
91992
  }),
91984
91993
  signal: turn.signal,
91985
- recordSteeringPrompt: () => context.sessionTurns.recordSteeringPrompt(message),
91994
+ steerTargetStarted: () => context.sessionTurns.steerTargetStarted(message),
91986
91995
  cancellationRequested: turn.cancellationRequested
91987
91996
  }).catch((error62) => {
91988
91997
  console.error("Mobius daemon turn failed", error62);
@@ -93082,7 +93091,7 @@ var RuntimeSessionEventPublisher = class {
93082
93091
  commandId: payload.commandId,
93083
93092
  generationId: event.sessionGenerationId
93084
93093
  });
93085
- } else if ((payload.kind === "prompt.completed" || payload.kind === "prompt.failed" || payload.kind === "prompt.failed-before-start") && this.#awaitingFirstAnswer.get(event.sessionId)?.commandId === payload.commandId && this.#awaitingFirstAnswer.get(event.sessionId)?.generationId === event.sessionGenerationId) {
93094
+ } else if (isPromptTerminal(payload) && this.#awaitingFirstAnswer.get(event.sessionId)?.commandId === payload.commandId && this.#awaitingFirstAnswer.get(event.sessionId)?.generationId === event.sessionGenerationId) {
93086
93095
  this.#awaitingFirstAnswer.delete(event.sessionId);
93087
93096
  }
93088
93097
  return false;
@@ -93587,4 +93596,4 @@ export {
93587
93596
  * MIT Licensed
93588
93597
  *)
93589
93598
  */
93590
- //# sourceMappingURL=chunk-A62FEGIN.js.map
93599
+ //# sourceMappingURL=chunk-7BSIM5AK.js.map