@moxt-ai/mobius 0.0.428 → 0.0.430

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 (51) hide show
  1. package/dist/{chunk-6BCVMXHM.js → chunk-6DTIQNQZ.js} +128 -17
  2. package/dist/{chunk-6BCVMXHM.js.map → chunk-6DTIQNQZ.js.map} +2 -2
  3. package/dist/{chunk-HFF7ZGCS.js → chunk-BMTH2ZGL.js} +2 -2
  4. package/dist/{chunk-HFF7ZGCS.js.map → chunk-BMTH2ZGL.js.map} +1 -1
  5. package/dist/{cli-4WZ5S3YB.js → cli-BSEEN4KA.js} +3 -3
  6. package/dist/cli.js +2 -2
  7. package/dist/engine/acp/adapter/codex/adapter.d.ts +0 -5
  8. package/dist/engine/acp/adapter/codex/adapter.d.ts.map +1 -1
  9. package/dist/engine/acp/adapter/codex/adapter.js +20 -0
  10. package/dist/engine/acp/adapter/codex/adapter.js.map +1 -1
  11. package/dist/engine/acp/adapter/codex/agent-connection.d.ts.map +1 -1
  12. package/dist/engine/acp/adapter/codex/agent-connection.js +1 -0
  13. package/dist/engine/acp/adapter/codex/agent-connection.js.map +1 -1
  14. package/dist/engine/acp/adapter/execution-connections.d.ts +3 -1
  15. package/dist/engine/acp/adapter/execution-connections.d.ts.map +1 -1
  16. package/dist/engine/acp/adapter/execution-connections.js +3 -0
  17. package/dist/engine/acp/adapter/execution-connections.js.map +1 -1
  18. package/dist/engine/acp/adapter/session-events.d.ts +3 -1
  19. package/dist/engine/acp/adapter/session-events.d.ts.map +1 -1
  20. package/dist/engine/acp/adapter/session-events.js +5 -0
  21. package/dist/engine/acp/adapter/session-events.js.map +1 -1
  22. package/dist/engine/acp/agent/in-process-endpoint.d.ts +7 -1
  23. package/dist/engine/acp/agent/in-process-endpoint.d.ts.map +1 -1
  24. package/dist/engine/acp/connection/agent-connection.d.ts +2 -1
  25. package/dist/engine/acp/connection/agent-connection.d.ts.map +1 -1
  26. package/dist/engine/acp/harness/codex/agent.d.ts.map +1 -1
  27. package/dist/engine/acp/harness/codex/agent.js +12 -3
  28. package/dist/engine/acp/harness/codex/agent.js.map +1 -1
  29. package/dist/engine/acp/harness/codex/borrowed-agent.d.ts +7 -2
  30. package/dist/engine/acp/harness/codex/borrowed-agent.d.ts.map +1 -1
  31. package/dist/engine/acp/harness/codex/borrowed-agent.js +33 -5
  32. package/dist/engine/acp/harness/codex/borrowed-agent.js.map +1 -1
  33. package/dist/engine/acp/harness/codex/owned-agent.d.ts +1 -0
  34. package/dist/engine/acp/harness/codex/owned-agent.d.ts.map +1 -1
  35. package/dist/engine/acp/harness/codex/owned-agent.js +1 -0
  36. package/dist/engine/acp/harness/codex/owned-agent.js.map +1 -1
  37. package/dist/engine/acp/harness/codex/session-agent.d.ts +2 -0
  38. package/dist/engine/acp/harness/codex/session-agent.d.ts.map +1 -1
  39. package/dist/engine/session/api/session-layer.d.ts.map +1 -1
  40. package/dist/engine/session/api/session-layer.js +1 -0
  41. package/dist/engine/session/api/session-layer.js.map +1 -1
  42. package/dist/engine/session/live/agent-session.d.ts.map +1 -1
  43. package/dist/engine/session/live/agent-session.js +22 -1
  44. package/dist/engine/session/live/agent-session.js.map +1 -1
  45. package/dist/engine/session/manager/session-manager.d.ts +4 -2
  46. package/dist/engine/session/manager/session-manager.d.ts.map +1 -1
  47. package/dist/engine/session/manager/session-manager.js +22 -3
  48. package/dist/engine/session/manager/session-manager.js.map +1 -1
  49. package/dist/engine.js +2 -2
  50. package/package.json +2 -2
  51. /package/dist/{cli-4WZ5S3YB.js.map → cli-BSEEN4KA.js.map} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  __export,
4
4
  __using,
5
5
  package_default
6
- } from "./chunk-HFF7ZGCS.js";
6
+ } from "./chunk-BMTH2ZGL.js";
7
7
 
8
8
  // src/engine/runtime/relay/runtime-revocation.ts
9
9
  var runtimeRevocationCloseCode = 1008;
@@ -20082,7 +20082,15 @@ var workspaceEntrySchema = external_exports.object({
20082
20082
  name: external_exports.string().min(1).max(255)
20083
20083
  }).readonly();
20084
20084
  var sessionStatusSchema = external_exports.discriminatedUnion("kind", [
20085
- external_exports.object({ kind: external_exports.literal("idle") }).readonly(),
20085
+ external_exports.object({
20086
+ kind: external_exports.literal("idle"),
20087
+ /**
20088
+ * Present when the Session's most recent started command failed, while the Runtime retains its receipt, so
20089
+ * a client that did not watch it can still show the Session failed until another command starts. It
20090
+ * carries what the execution's `lastTurn` reports for that failure. Runtimes before it existed omit it.
20091
+ */
20092
+ failedTurn: external_exports.object({ code: identifierStringSchema, commandId: identifierStringSchema, message: external_exports.string().min(1).max(500) }).readonly().optional().catch(void 0)
20093
+ }).readonly(),
20086
20094
  external_exports.object({
20087
20095
  commandId: identifierStringSchema,
20088
20096
  kind: external_exports.literal("working")
@@ -20764,6 +20772,12 @@ var lifecycleMetadataSchema = external_exports.discriminatedUnion("kind", [
20764
20772
  targetCommandId: identifierStringSchema.optional()
20765
20773
  }).readonly(),
20766
20774
  external_exports.object({ ...lifecycleBase, attemptId: identifierStringSchema, epoch: identifierStringSchema, kind: external_exports.literal("prompt.started") }).readonly(),
20775
+ // The Runtime did not run this prompt itself: it handed it to the native session's owner, another client of the
20776
+ // Agent such as the Codex app, which runs queued input on its own terms. `queued`: the owner holds the prompt and
20777
+ // may keep holding it; Codex pauses its queue after an interrupted turn until its user continues. `started`: the
20778
+ // owner began running it, so only the owner can stop it and cancelling it here leaves it running. Runtimes before
20779
+ // this event never delegate.
20780
+ external_exports.object({ ...lifecycleBase, kind: external_exports.literal("prompt.delegated"), stage: external_exports.enum(["queued", "started"]) }).readonly(),
20767
20781
  promptCompletedSchema,
20768
20782
  external_exports.object({
20769
20783
  ...lifecycleBase,
@@ -20781,6 +20795,7 @@ var isPromptTerminal = (payload) => {
20781
20795
  return true;
20782
20796
  case "prompt.requested":
20783
20797
  case "prompt.started":
20798
+ case "prompt.delegated":
20784
20799
  case "session.queue.changed":
20785
20800
  case "session.permission.requested":
20786
20801
  case "session.permission.resolved":
@@ -72775,19 +72790,26 @@ function waitForNextPoll(timer, signal) {
72775
72790
  }
72776
72791
  var CodexBorrowedAcpAgent = class {
72777
72792
  steeringSupported = false;
72793
+ runsTurns = false;
72778
72794
  #client;
72779
72795
  #threadId;
72780
72796
  #emit;
72797
+ #onDelegation;
72781
72798
  #closed = new AbortController();
72782
72799
  #seen = /* @__PURE__ */ new Map();
72783
72800
  #pending = null;
72784
72801
  #watch = null;
72785
72802
  #lifecycle = { kind: "following" };
72786
- constructor(client2, threadId, emit) {
72803
+ constructor(client2, threadId, emit, onDelegation) {
72787
72804
  this.#client = client2;
72788
72805
  this.#threadId = threadId;
72789
72806
  this.#emit = emit;
72807
+ this.#onDelegation = onDelegation;
72790
72808
  }
72809
+ #reportDelegation = async (pending, stage) => {
72810
+ pending.delegation = pending.delegation.then(async () => await this.#onDelegation(stage));
72811
+ await pending.delegation;
72812
+ };
72791
72813
  initialize = async (signal) => {
72792
72814
  queuePageSchema.parse(
72793
72815
  await this.#client.request(
@@ -72876,7 +72898,11 @@ var CodexBorrowedAcpAgent = class {
72876
72898
  const clientId = typeof raw === "object" && raw !== null ? Reflect.get(raw, "clientId") : void 0;
72877
72899
  matches ||= clientId === this.#pending?.clientId;
72878
72900
  if (this.#pending !== null && clientId === this.#pending.clientId) {
72901
+ const started = this.#pending.input.kind === "awaiting";
72879
72902
  this.#pending.input = { kind: "identified", messageId: item.id };
72903
+ if (started) {
72904
+ await this.#reportDelegation(this.#pending, "started");
72905
+ }
72880
72906
  }
72881
72907
  const text2 = item.content.flatMap(
72882
72908
  (block) => typeof block === "object" && block !== null && Reflect.get(block, "type") === "text" && typeof Reflect.get(block, "text") === "string" ? [String(Reflect.get(block, "text"))] : []
@@ -72951,7 +72977,8 @@ var CodexBorrowedAcpAgent = class {
72951
72977
  clientId: randomUUID7(),
72952
72978
  completion: Promise.withResolvers(),
72953
72979
  settled: Promise.withResolvers(),
72954
- input: { kind: "awaiting" }
72980
+ input: { kind: "awaiting" },
72981
+ delegation: Promise.resolve()
72955
72982
  };
72956
72983
  this.#pending = pending;
72957
72984
  void pending.completion.promise.catch(() => {
@@ -72978,6 +73005,7 @@ var CodexBorrowedAcpAgent = class {
72978
73005
  "invalid_native_session_response"
72979
73006
  );
72980
73007
  }
73008
+ await this.#reportDelegation(pending, "queued");
72981
73009
  const result = await pending.completion.promise;
72982
73010
  outcome = result.stopReason === "cancelled" ? "cancelled" : "completed";
72983
73011
  return pending.input.kind === "identified" ? await promptResultWithMessageId2(Promise.resolve(result), pending.input.messageId) : result;
@@ -72999,6 +73027,7 @@ var CodexBorrowedAcpAgent = class {
72999
73027
  pending.settled.resolve();
73000
73028
  }
73001
73029
  };
73030
+ /** Withdraws this client's submission while the owner has not taken it; false once the owner has. */
73002
73031
  #removeQueuedInput = async (clientId) => {
73003
73032
  const signal = AbortSignal.timeout(REQUEST_TIMEOUT);
73004
73033
  let cursor = null;
@@ -73018,7 +73047,7 @@ var CodexBorrowedAcpAgent = class {
73018
73047
  { threadId: this.#threadId, queuedSubmissionId: queued.id },
73019
73048
  signal
73020
73049
  );
73021
- return;
73050
+ return true;
73022
73051
  }
73023
73052
  }
73024
73053
  cursor = page.nextCursor ?? null;
@@ -73029,6 +73058,7 @@ var CodexBorrowedAcpAgent = class {
73029
73058
  cursors.add(cursor);
73030
73059
  }
73031
73060
  } while (cursor !== null);
73061
+ return false;
73032
73062
  };
73033
73063
  nativeTurnId = () => null;
73034
73064
  steer = async (_params, signal) => {
@@ -73055,9 +73085,16 @@ var CodexBorrowedAcpAgent = class {
73055
73085
  "native_session_unsupported"
73056
73086
  );
73057
73087
  };
73088
+ /**
73089
+ * Withdraws the prompt while it waits in the owner's queue. Once the owner runs it, only the owner can stop it,
73090
+ * so the prompt keeps running and following reports how the owner ends it.
73091
+ */
73058
73092
  cancel = async () => {
73059
73093
  const pending = this.#pending;
73060
- if (pending !== null) {
73094
+ if (pending === null || pending.input.kind === "identified") {
73095
+ return;
73096
+ }
73097
+ if (await this.#removeQueuedInput(pending.clientId)) {
73061
73098
  pending.completion.resolve({ stopReason: "cancelled" });
73062
73099
  await pending.settled.promise;
73063
73100
  }
@@ -73065,7 +73102,11 @@ var CodexBorrowedAcpAgent = class {
73065
73102
  close = async () => {
73066
73103
  this.#lifecycle = { kind: "closed" };
73067
73104
  this.#closed.abort();
73068
- await this.cancel();
73105
+ const pending = this.#pending;
73106
+ if (pending !== null) {
73107
+ pending.completion.resolve({ stopReason: "cancelled" });
73108
+ await pending.settled.promise;
73109
+ }
73069
73110
  await this.#watch;
73070
73111
  };
73071
73112
  };
@@ -73404,6 +73445,7 @@ function userInputSchema(questions) {
73404
73445
  }
73405
73446
  var CodexOwnedAcpAgent = class {
73406
73447
  steeringSupported = true;
73448
+ runsTurns = true;
73407
73449
  #context;
73408
73450
  #appServer;
73409
73451
  #settings;
@@ -74614,11 +74656,13 @@ var CodexAcpAgent = class {
74614
74656
  #settings;
74615
74657
  #onSessionUpdate;
74616
74658
  #onBackgroundActivity;
74659
+ #onPromptDelegation;
74617
74660
  #nativeSessionId = "";
74618
74661
  #sessionAgent;
74619
74662
  constructor(options) {
74620
74663
  this.#onSessionUpdate = options.onSessionUpdate;
74621
74664
  this.#onBackgroundActivity = options.onBackgroundActivity;
74665
+ this.#onPromptDelegation = options.onPromptDelegation;
74622
74666
  this.#appServer = new CodexAppServerClient({
74623
74667
  command: options.command,
74624
74668
  cwd: options.cwd,
@@ -74691,7 +74735,7 @@ var CodexAcpAgent = class {
74691
74735
  await this.#replaySavedHistory(context.signal);
74692
74736
  this.#advertiseCompactCommand();
74693
74737
  return {
74694
- _meta: { steering: { supported: this.#sessionAgent.steeringSupported } },
74738
+ _meta: this.#sessionMeta(),
74695
74739
  configOptions: this.#settings.configOptions()
74696
74740
  };
74697
74741
  }).onRequest(methods.agent.session.fork, async (context) => {
@@ -74717,7 +74761,7 @@ var CodexAcpAgent = class {
74717
74761
  await this.#resume(context.params.sessionId, context.params.cwd, context.signal);
74718
74762
  this.#advertiseCompactCommand();
74719
74763
  return {
74720
- _meta: { steering: { supported: this.#sessionAgent.steeringSupported } },
74764
+ _meta: this.#sessionMeta(),
74721
74765
  configOptions: this.#settings.configOptions()
74722
74766
  };
74723
74767
  }).onRequest(methods.agent.session.prompt, async (context) => {
@@ -74829,7 +74873,9 @@ var CodexAcpAgent = class {
74829
74873
  AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS3)])
74830
74874
  )
74831
74875
  );
74832
- const queued = new CodexBorrowedAcpAgent(this.#appServer, threadId, this.#emit);
74876
+ const queued = new CodexBorrowedAcpAgent(this.#appServer, threadId, this.#emit, async (stage) => {
74877
+ await this.#onPromptDelegation?.(stage);
74878
+ });
74833
74879
  await queued.initialize(signal);
74834
74880
  this.#nativeSessionId = threadId;
74835
74881
  this.#settings.selectRestoredThread({
@@ -74845,6 +74891,11 @@ var CodexAcpAgent = class {
74845
74891
  this.#settings.selectRestoredThread(resumed);
74846
74892
  await this.#settings.probeCollaborationMode(this.#nativeSessionId, signal);
74847
74893
  };
74894
+ /** What the session response tells Mobius about the session behavior selected while opening it. */
74895
+ #sessionMeta = () => ({
74896
+ steering: { supported: this.#sessionAgent.steeringSupported },
74897
+ codex: { runsTurns: this.#sessionAgent.runsTurns }
74898
+ });
74848
74899
  // ACP load requires chronological replay. Resume only restores execution;
74849
74900
  // native pages supply history without a single full-transcript response.
74850
74901
  #replaySavedHistory = async (signal) => {
@@ -74889,7 +74940,8 @@ var CodexAgentConnection = class extends EndpointAgentConnection {
74889
74940
  cwd: options.cwd,
74890
74941
  environment: options.environment,
74891
74942
  onSessionUpdate: options.client.onUpdate,
74892
- onBackgroundActivity: (activity) => options.onBackgroundActivity?.(activity)
74943
+ onBackgroundActivity: (activity) => options.onBackgroundActivity?.(activity),
74944
+ onPromptDelegation: async (stage) => await options.onPromptDelegation?.(stage)
74893
74945
  });
74894
74946
  super(endpoint, options.client);
74895
74947
  }
@@ -80335,6 +80387,11 @@ var AdapterSessionConnection = class {
80335
80387
  }
80336
80388
  this.#backgroundActivity = activity;
80337
80389
  this.#onBackgroundActivity(activity);
80390
+ },
80391
+ onPromptDelegation: async (stage) => {
80392
+ if (!this.#lifetime.signal.aborted) {
80393
+ await options.onPromptDelegation?.(stage);
80394
+ }
80338
80395
  }
80339
80396
  });
80340
80397
  }
@@ -80514,6 +80571,7 @@ var AcpExecutionConnections = class {
80514
80571
  ...params.scope.externalizeUpdate === void 0 ? {} : { externalizeUpdate: params.scope.externalizeUpdate },
80515
80572
  onEvent: (event) => params.onSessionEvent(connection.events.sessionId(), event),
80516
80573
  ...params.onBackgroundActivity === void 0 ? {} : { onBackgroundActivity: params.onBackgroundActivity },
80574
+ ...params.onPromptDelegation === void 0 ? {} : { onPromptDelegation: params.onPromptDelegation },
80517
80575
  interactions: params.interactions
80518
80576
  },
80519
80577
  this.#externalizer,
@@ -80586,6 +80644,8 @@ var AcpExecutionConnections = class {
80586
80644
  }
80587
80645
  return session;
80588
80646
  };
80647
+ /** The open writer's connection for this native session, if any. */
80648
+ connection = (target) => this.#find(target)?.connection;
80589
80649
  cancel = async ({ signal, ...target }) => {
80590
80650
  const bounded = AbortSignal.any([signal, AbortSignal.timeout(3e4)]);
80591
80651
  bounded.throwIfAborted();
@@ -87239,11 +87299,15 @@ function fitCodexToolEvent(event) {
87239
87299
  }
87240
87300
 
87241
87301
  // src/engine/acp/adapter/codex/adapter.ts
87302
+ var sessionTurnOwnershipSchema = external_exports.object({
87303
+ _meta: external_exports.object({ codex: external_exports.object({ runsTurns: external_exports.boolean() }).optional() }).optional()
87304
+ });
87242
87305
  var CodexAdapter = class {
87243
87306
  #agent;
87244
87307
  #queryProcesses;
87245
87308
  #connector;
87246
87309
  #executionConnections;
87310
+ #queueingConnections = /* @__PURE__ */ new WeakSet();
87247
87311
  #dependencies;
87248
87312
  #contentExternalizer;
87249
87313
  #previewCache = null;
@@ -87321,6 +87385,7 @@ var CodexAdapter = class {
87321
87385
  "ACP agent exited while resuming a session",
87322
87386
  signal
87323
87387
  );
87388
+ this.#recordTurnOwnership(connection, response);
87324
87389
  return normalizeOpenedSession(execution, nativeSessionId, response, signal);
87325
87390
  });
87326
87391
  openSessionWithReplay = (params) => this.#executionConnections.withConnection(this.#executionParams(params), async (execution, signal) => {
@@ -87337,12 +87402,23 @@ var CodexAdapter = class {
87337
87402
  signal
87338
87403
  );
87339
87404
  await connection.race(connection.events.drained(), "ACP agent exited while loading a session", signal);
87405
+ this.#recordTurnOwnership(connection, response);
87340
87406
  return normalizeOpenedSession(execution, nativeSessionId, response, signal);
87341
87407
  });
87342
87408
  cancel = async (params) => {
87409
+ const connection = this.#executionConnections.connection(params);
87410
+ if (connection !== void 0 && this.#queueingConnections.has(connection)) {
87411
+ return await this.#executionConnections.cancel(params);
87412
+ }
87343
87413
  await this.#executionConnections.closeSession(params);
87344
87414
  return "closed";
87345
87415
  };
87416
+ /** A connection keeps the turn ownership its harness chose while opening the thread. */
87417
+ #recordTurnOwnership = (connection, response) => {
87418
+ if (sessionTurnOwnershipSchema.parse(response)._meta?.codex?.runsTurns === false) {
87419
+ this.#queueingConnections.add(connection);
87420
+ }
87421
+ };
87346
87422
  closeSession = (...args) => this.#executionConnections.closeSession(...args);
87347
87423
  releaseSession = (params) => this.#executionConnections.releaseSession(params);
87348
87424
  // Codex admits one active writer per thread; another client borrows the thread instead.
@@ -89989,6 +90065,8 @@ var AgentSession = class _AgentSession {
89989
90065
  }
89990
90066
  hasBackgroundActivity = () => this.#backgroundActivity !== "none";
89991
90067
  #backgroundActivity = "none";
90068
+ /** The command whose prompt the Agent is running, which only the Agent can report as delegated. */
90069
+ #delegableCommandId = null;
89992
90070
  #modelEffort = null;
89993
90071
  #scope;
89994
90072
  #subscriber;
@@ -90068,6 +90146,15 @@ var AgentSession = class _AgentSession {
90068
90146
  void this.#recordNativeHistoryRevision();
90069
90147
  }
90070
90148
  },
90149
+ onPromptDelegation: async (stage) => {
90150
+ const commandId = this.#delegableCommandId;
90151
+ if (commandId !== null) {
90152
+ await this.recordLifecycleEvent({
90153
+ payload: { commandId, kind: "prompt.delegated", stage },
90154
+ type: "lifecycle-metadata"
90155
+ });
90156
+ }
90157
+ },
90071
90158
  interactions: {
90072
90159
  onPermission: this.#interactions.onPermission,
90073
90160
  onElicitation: this.#interactions.onElicitation,
@@ -90519,10 +90606,15 @@ var AgentSession = class _AgentSession {
90519
90606
  type: "lifecycle-metadata"
90520
90607
  });
90521
90608
  }
90609
+ this.#delegableCommandId = lifecycle === void 0 ? null : options.commandId;
90522
90610
  try {
90523
- const result = await this.#writeNativeHistory(
90524
- async () => await this.#adapter.prompt({ ...this.#target(), content: options, signal: options.signal })
90525
- );
90611
+ const result = await this.#writeNativeHistory(async () => {
90612
+ try {
90613
+ return await this.#adapter.prompt({ ...this.#target(), content: options, signal: options.signal });
90614
+ } finally {
90615
+ this.#delegableCommandId = null;
90616
+ }
90617
+ });
90526
90618
  this.writeStoredSession((/* @__PURE__ */ new Date()).toISOString());
90527
90619
  if (lifecycle !== void 0) {
90528
90620
  const messageId = result._meta?.messageId;
@@ -90908,6 +91000,7 @@ var SessionManager2 = class {
90908
91000
  changed: () => this.#processes.notifyChanged()
90909
91001
  });
90910
91002
  #executions;
91003
+ #lastTurn;
90911
91004
  #agentSettingsObserver = new NullSessionObserver();
90912
91005
  #nativeOperations = /* @__PURE__ */ new Set();
90913
91006
  #sessionClosures = /* @__PURE__ */ new Map();
@@ -90926,14 +91019,20 @@ var SessionManager2 = class {
90926
91019
  sessionIdentity,
90927
91020
  onSessionStatusChanged,
90928
91021
  onSessionClosed = () => void 0,
91022
+ lastTurn = () => void 0,
90929
91023
  timer
90930
91024
  }) {
90931
91025
  this.#observer = observer;
90932
91026
  this.#processes = processes;
90933
91027
  this.#store = store;
90934
91028
  this.#sessionIdentity = sessionIdentity;
91029
+ this.#lastTurn = lastTurn;
90935
91030
  this.#executions = new ActiveExecutions(
90936
- (sessionId, status) => onSessionStatusChanged({ kind: "session.status.changed", sessionId, status })
91031
+ (sessionId, status) => onSessionStatusChanged({
91032
+ kind: "session.status.changed",
91033
+ sessionId,
91034
+ status: this.#reported(sessionId, status)
91035
+ })
90937
91036
  );
90938
91037
  this.#onSessionClosed = onSessionClosed;
90939
91038
  this.#timer = timer;
@@ -91543,7 +91642,18 @@ var SessionManager2 = class {
91543
91642
  const stored = this.#store.read(sessionId);
91544
91643
  return stored instanceof FoundStoredSession ? [stored.session] : [];
91545
91644
  });
91546
- sessionStatus = (sessionId) => this.#executions.status(sessionId);
91645
+ sessionStatus = (sessionId) => this.#reported(sessionId, this.#executions.status(sessionId));
91646
+ /** An idle Session whose last started command failed says so, so a client that did not watch it still knows. */
91647
+ #reported = (sessionId, status) => {
91648
+ if (status.kind !== "idle") {
91649
+ return status;
91650
+ }
91651
+ const lastTurn = this.#lastTurn(sessionId);
91652
+ return lastTurn?.state === "failed" ? {
91653
+ ...status,
91654
+ failedTurn: { code: lastTurn.code, commandId: lastTurn.commandId, message: lastTurn.message }
91655
+ } : status;
91656
+ };
91547
91657
  listSessions = (limit) => this.#store.list().filter((session) => session.prompted).slice(0, limit);
91548
91658
  findLinkedSessions = (agentId, nativeSessionId) => this.#store.findNative(agentId, nativeSessionId);
91549
91659
  interactionSnapshot = (options) => {
@@ -93505,6 +93615,7 @@ function buildSessionLayer(options) {
93505
93615
  sessionIdentity: "native",
93506
93616
  onSessionStatusChanged: sink.publishStatus,
93507
93617
  onSessionClosed: sink.publishClosed,
93618
+ lastTurn: operations.lastTurn,
93508
93619
  timer
93509
93620
  });
93510
93621
  const eventProjection = new PromptLifecycle(
@@ -97722,4 +97833,4 @@ export {
97722
97833
  * MIT Licensed
97723
97834
  *)
97724
97835
  */
97725
- //# sourceMappingURL=chunk-6BCVMXHM.js.map
97836
+ //# sourceMappingURL=chunk-6DTIQNQZ.js.map