@moxt-ai/mobius 0.0.444 → 0.0.448

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 (69) hide show
  1. package/dist/{chunk-Z4MPXGOW.js → chunk-4PY4RNTC.js} +2 -2
  2. package/dist/{chunk-Z4MPXGOW.js.map → chunk-4PY4RNTC.js.map} +1 -1
  3. package/dist/{chunk-KV2EUHFD.js → chunk-X6VDMZHE.js} +536 -96
  4. package/dist/{chunk-KV2EUHFD.js.map → chunk-X6VDMZHE.js.map} +4 -4
  5. package/dist/{cli-4DZDU3E3.js → cli-B5KWLA5R.js} +3 -3
  6. package/dist/cli.js +2 -2
  7. package/dist/engine/acp/adapter/claude/adapter.d.ts +1 -0
  8. package/dist/engine/acp/adapter/claude/adapter.d.ts.map +1 -1
  9. package/dist/engine/acp/adapter/claude/adapter.js +1 -0
  10. package/dist/engine/acp/adapter/claude/adapter.js.map +1 -1
  11. package/dist/engine/acp/adapter/codex/adapter.d.ts +1 -0
  12. package/dist/engine/acp/adapter/codex/adapter.d.ts.map +1 -1
  13. package/dist/engine/acp/adapter/codex/adapter.js +5 -0
  14. package/dist/engine/acp/adapter/codex/adapter.js.map +1 -1
  15. package/dist/engine/acp/adapter/execution-connections.d.ts +3 -1
  16. package/dist/engine/acp/adapter/execution-connections.d.ts.map +1 -1
  17. package/dist/engine/acp/adapter/execution-connections.js +35 -0
  18. package/dist/engine/acp/adapter/execution-connections.js.map +1 -1
  19. package/dist/engine/acp/adapter/pi/adapter.d.ts +1 -0
  20. package/dist/engine/acp/adapter/pi/adapter.d.ts.map +1 -1
  21. package/dist/engine/acp/adapter/pi/adapter.js +5 -0
  22. package/dist/engine/acp/adapter/pi/adapter.js.map +1 -1
  23. package/dist/engine/acp/adapter/session-events.d.ts +7 -1
  24. package/dist/engine/acp/adapter/session-events.d.ts.map +1 -1
  25. package/dist/engine/acp/adapter/session-events.js +65 -0
  26. package/dist/engine/acp/adapter/session-events.js.map +1 -1
  27. package/dist/engine/acp/agent/in-process-endpoint.d.ts +28 -0
  28. package/dist/engine/acp/agent/in-process-endpoint.d.ts.map +1 -1
  29. package/dist/engine/acp/agent/in-process-endpoint.js +7 -0
  30. package/dist/engine/acp/agent/in-process-endpoint.js.map +1 -1
  31. package/dist/engine/acp/native-history/preview-contract.d.ts +12 -0
  32. package/dist/engine/acp/native-history/preview-contract.d.ts.map +1 -1
  33. package/dist/engine/agent/settings/agent-settings-adapter.d.ts +1 -1
  34. package/dist/engine/agent/settings/agent-settings-adapter.d.ts.map +1 -1
  35. package/dist/engine/agent/settings/agent-settings-adapter.js +1 -6
  36. package/dist/engine/agent/settings/agent-settings-adapter.js.map +1 -1
  37. package/dist/engine/agent/settings/agent-settings-base.d.ts +1 -2
  38. package/dist/engine/agent/settings/agent-settings-base.d.ts.map +1 -1
  39. package/dist/engine/agent/settings/agent-settings-base.js +0 -2
  40. package/dist/engine/agent/settings/agent-settings-base.js.map +1 -1
  41. package/dist/engine/runtime/command/registry/interactions.d.ts.map +1 -1
  42. package/dist/engine/runtime/command/registry/interactions.js +7 -0
  43. package/dist/engine/runtime/command/registry/interactions.js.map +1 -1
  44. package/dist/engine/session/api/session-api.d.ts +2 -0
  45. package/dist/engine/session/api/session-api.d.ts.map +1 -1
  46. package/dist/engine/session/api/session-api.js.map +1 -1
  47. package/dist/engine/session/live/agent-session.d.ts +10 -1
  48. package/dist/engine/session/live/agent-session.d.ts.map +1 -1
  49. package/dist/engine/session/live/agent-session.js +145 -2
  50. package/dist/engine/session/live/agent-session.js.map +1 -1
  51. package/dist/engine/session/manager/session-manager.d.ts +2 -0
  52. package/dist/engine/session/manager/session-manager.d.ts.map +1 -1
  53. package/dist/engine/session/manager/session-manager.js +89 -20
  54. package/dist/engine/session/manager/session-manager.js.map +1 -1
  55. package/dist/engine/session/prompt/prompt-lifecycle.d.ts.map +1 -1
  56. package/dist/engine/session/prompt/prompt-lifecycle.js +5 -1
  57. package/dist/engine/session/prompt/prompt-lifecycle.js.map +1 -1
  58. package/dist/engine/session/settings/agent-settings-cache.js +1 -1
  59. package/dist/engine/session/settings/agent-settings-cache.js.map +1 -1
  60. package/dist/engine/session/settings/discover-agent-settings.d.ts.map +1 -1
  61. package/dist/engine/session/settings/discover-agent-settings.js +6 -49
  62. package/dist/engine/session/settings/discover-agent-settings.js.map +1 -1
  63. package/dist/engine.js +2 -2
  64. package/package.json +2 -2
  65. package/dist/engine/agent/settings/codex-settings-adapter.d.ts +0 -5
  66. package/dist/engine/agent/settings/codex-settings-adapter.d.ts.map +0 -1
  67. package/dist/engine/agent/settings/codex-settings-adapter.js +0 -6
  68. package/dist/engine/agent/settings/codex-settings-adapter.js.map +0 -1
  69. /package/dist/{cli-4DZDU3E3.js.map → cli-B5KWLA5R.js.map} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  __export,
4
4
  __using,
5
5
  package_default
6
- } from "./chunk-Z4MPXGOW.js";
6
+ } from "./chunk-4PY4RNTC.js";
7
7
 
8
8
  // src/engine/runtime/relay/runtime-revocation.ts
9
9
  var runtimeRevocationCloseCode = 1008;
@@ -20160,11 +20160,12 @@ var agentSettingSchema = external_exports.object({
20160
20160
  }).readonly();
20161
20161
  var agentSettingsSchema = external_exports.array(agentSettingSchema).max(128).readonly();
20162
20162
  var AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE = "complete";
20163
- var AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION = "on_model_selection";
20164
20163
  var AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE = "unavailable";
20165
20164
  var agentModelEffortResolutionSchema = external_exports.enum([
20166
20165
  AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE,
20167
- AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION,
20166
+ // Runtimes released before settings discovery covered every model report this with a table that may
20167
+ // omit models. Current Runtimes never send it; readers still accept it from those Runtimes.
20168
+ "on_model_selection",
20168
20169
  AGENT_MODEL_EFFORT_RESOLUTION_UNAVAILABLE
20169
20170
  ]);
20170
20171
  var agentModelEffortSchema = external_exports.object({
@@ -20758,6 +20759,26 @@ var promptExecutionContextSchema = external_exports.object({
20758
20759
  directoryId: DIRECTORY_IDENTIFIER,
20759
20760
  additionalDirectoryIds: external_exports.array(DIRECTORY_IDENTIFIER).max(16).readonly()
20760
20761
  }).readonly();
20762
+ var promptInitiatorSchema = external_exports.object({
20763
+ kind: external_exports.literal("agent"),
20764
+ reason: external_exports.enum(["background-task", "other"]).catch("other"),
20765
+ // The command a client submitted whose background work led the Agent to start this one, followed through
20766
+ // earlier commands the Agent started itself. Absent when the Runtime cannot tell.
20767
+ continues: identifierStringSchema.optional().catch(void 0)
20768
+ }).readonly();
20769
+ var SESSION_BACKGROUND_TASK_MAX_COUNT = 100;
20770
+ var sessionBackgroundTaskSchema = external_exports.object({
20771
+ // Agent-owned identity.
20772
+ taskId: external_exports.string().min(1).max(2048),
20773
+ kind: external_exports.enum(["subagent", "shell", "other"]).catch("other"),
20774
+ state: external_exports.enum(["running", "awaiting-results"]).catch("running"),
20775
+ // The command a client submitted that this work belongs to, followed through commands the Agent started
20776
+ // itself. Absent when the Runtime cannot tell.
20777
+ commandId: identifierStringSchema.optional().catch(void 0),
20778
+ // The tool call that started the work, when the Agent reported one.
20779
+ toolCallId: external_exports.string().min(1).max(2048).optional().catch(void 0),
20780
+ description: external_exports.string().max(500).optional().catch(void 0)
20781
+ }).readonly();
20761
20782
  var promptCompletedSchema = external_exports.object({
20762
20783
  ...lifecycleBase,
20763
20784
  kind: external_exports.literal("prompt.completed"),
@@ -20777,6 +20798,13 @@ var lifecycleMetadataSchema = external_exports.discriminatedUnion("kind", [
20777
20798
  // `changedByCommandId` names the command whose admission to or departure from the queue changed it. Runtimes
20778
20799
  // before it existed omit it, so a reader must treat an unnamed change as possibly any command's.
20779
20800
  external_exports.object({ changedByCommandId: identifierStringSchema.optional(), kind: external_exports.literal("session.queue.changed") }).readonly(),
20801
+ // The Session's complete outstanding background work, replacing the last one recorded. An empty list means none
20802
+ // remains, including after the Agent process that ran it ended. A new Session generation starts with none.
20803
+ // Runtimes before it existed never record it.
20804
+ external_exports.object({
20805
+ kind: external_exports.literal("session.background.changed"),
20806
+ tasks: external_exports.array(sessionBackgroundTaskSchema).max(SESSION_BACKGROUND_TASK_MAX_COUNT).readonly()
20807
+ }).readonly(),
20780
20808
  external_exports.object({ event: sessionPermissionRequestedEventSchema, kind: external_exports.literal("session.permission.requested") }).readonly(),
20781
20809
  external_exports.object({ event: sessionPermissionResolvedEventSchema, kind: external_exports.literal("session.permission.resolved") }).readonly(),
20782
20810
  external_exports.object({ event: sessionElicitationRequestedEventSchema, kind: external_exports.literal("session.elicitation.requested") }).readonly(),
@@ -20789,7 +20817,14 @@ var lifecycleMetadataSchema = external_exports.discriminatedUnion("kind", [
20789
20817
  context: promptExecutionContextSchema.optional(),
20790
20818
  targetCommandId: identifierStringSchema.optional()
20791
20819
  }).readonly(),
20792
- external_exports.object({ ...lifecycleBase, attemptId: identifierStringSchema, epoch: identifierStringSchema, kind: external_exports.literal("prompt.started") }).readonly(),
20820
+ external_exports.object({
20821
+ ...lifecycleBase,
20822
+ attemptId: identifierStringSchema,
20823
+ epoch: identifierStringSchema,
20824
+ // An initiator a reader cannot decode leaves the command one a client submitted, as before it existed.
20825
+ initiator: promptInitiatorSchema.optional().catch(void 0),
20826
+ kind: external_exports.literal("prompt.started")
20827
+ }).readonly(),
20793
20828
  // The Runtime did not run this prompt itself: it handed it to the native session's owner, another client of the
20794
20829
  // Agent such as the Codex app, which runs queued input on its own terms. `queued`: the owner holds the prompt and
20795
20830
  // may keep holding it; Codex pauses its queue after an interrupted turn until its user continues. `started`: the
@@ -20815,6 +20850,7 @@ var isPromptTerminal = (payload) => {
20815
20850
  case "prompt.started":
20816
20851
  case "prompt.delegated":
20817
20852
  case "session.queue.changed":
20853
+ case "session.background.changed":
20818
20854
  case "session.permission.requested":
20819
20855
  case "session.permission.resolved":
20820
20856
  case "session.elicitation.requested":
@@ -26775,6 +26811,8 @@ function acpEndpointTerminationError(termination) {
26775
26811
  }
26776
26812
  }
26777
26813
  }
26814
+ var BACKGROUND_TASKS_META = "mobius.backgroundTasks";
26815
+ var AGENT_TURN_META = "mobius.agentTurn";
26778
26816
 
26779
26817
  // src/engine/acp/connection/agent-operation.ts
26780
26818
  var promptFailureIdentitySchema = external_exports.object({ messageId: external_exports.string().min(1).max(2048) });
@@ -66587,6 +66625,17 @@ function parseRevisionRequest(params) {
66587
66625
  }
66588
66626
  return { sessionId };
66589
66627
  }
66628
+ var MODEL_SETTINGS_METHOD = "_session/model_settings";
66629
+ function parseModelSettingsRequest(params) {
66630
+ if (!params || typeof params !== "object") {
66631
+ throw RequestError.invalidParams(void 0, "model settings params must be an object");
66632
+ }
66633
+ const { sessionId } = params;
66634
+ if (typeof sessionId !== "string" || sessionId.length === 0) {
66635
+ throw RequestError.invalidParams(void 0, "model settings params require a non-empty sessionId");
66636
+ }
66637
+ return { sessionId };
66638
+ }
66590
66639
  var AUTONOMOUS_RESULT_ORIGINS = /* @__PURE__ */ new Set([
66591
66640
  "task-notification",
66592
66641
  "peer",
@@ -67592,6 +67641,8 @@ var ClaudeAcpAgent = class {
67592
67641
  const backgroundTasks = /* @__PURE__ */ new Set();
67593
67642
  const awaitingBackgroundResults = /* @__PURE__ */ new Set();
67594
67643
  let processingBackgroundResults = /* @__PURE__ */ new Set();
67644
+ const backgroundTaskDetails = /* @__PURE__ */ new Map();
67645
+ let publishedBackgroundTasks = "[]";
67595
67646
  let hasBackgroundLevel = false;
67596
67647
  const reportBackgroundActivity = () => this.reportBackgroundActivity(session, backgroundTasks.size > 0 ? "running" : awaitingBackgroundResults.size > 0 ? "awaiting-results" : "none");
67597
67648
  let lastAssistantTotalUsage = null;
@@ -67760,6 +67811,70 @@ var ClaudeAcpAgent = class {
67760
67811
  };
67761
67812
  const findUnsettledTurn = (uuid3) => (session.turnQueue ?? []).find((t) => t.promptUuid === uuid3 && !t.settled);
67762
67813
  const firstUnsettledQueuedTurn = () => (session.turnQueue ?? []).find((t) => !t.settled);
67814
+ const publishBackgroundTasks = async () => {
67815
+ const report = (taskId, state) => {
67816
+ const details = backgroundTaskDetails.get(taskId);
67817
+ if (details?.ambient === true) {
67818
+ return [];
67819
+ }
67820
+ return [
67821
+ {
67822
+ taskId,
67823
+ kind: details?.kind ?? "other",
67824
+ state,
67825
+ ...details?.toolUseId === void 0 ? {} : { toolUseId: details.toolUseId },
67826
+ ...details?.description === void 0 ? {} : { description: details.description }
67827
+ }
67828
+ ];
67829
+ };
67830
+ const tasks = [
67831
+ ...[...backgroundTasks].flatMap((taskId) => report(taskId, "running")),
67832
+ ...[...awaitingBackgroundResults].filter((taskId) => !backgroundTasks.has(taskId)).flatMap((taskId) => report(taskId, "awaiting-results"))
67833
+ ];
67834
+ const encoded = JSON.stringify(tasks);
67835
+ if (encoded === publishedBackgroundTasks) {
67836
+ return;
67837
+ }
67838
+ publishedBackgroundTasks = encoded;
67839
+ await this.client.sessionUpdate({
67840
+ sessionId: params.sessionId,
67841
+ update: { sessionUpdate: "session_info_update", _meta: { [BACKGROUND_TASKS_META2]: tasks } }
67842
+ });
67843
+ };
67844
+ const noPromptInFlight = () => !(session.activeTurn && !session.activeTurn.settled) && firstUnsettledQueuedTurn() === void 0 && (session.pendingOrphanResults ?? 0) === 0 && (session.orphanCommands?.size ?? 0) === 0;
67845
+ const startAgentTurn = async () => {
67846
+ if (session.agentTurn !== void 0 || !noPromptInFlight()) {
67847
+ return;
67848
+ }
67849
+ await publishBackgroundTasks();
67850
+ session.agentTurn = { cancelled: false };
67851
+ const taskIds = [...awaitingBackgroundResults];
67852
+ const started = {
67853
+ stage: "started",
67854
+ reason: taskIds.length > 0 ? "background-task" : "other",
67855
+ taskIds
67856
+ };
67857
+ await this.client.sessionUpdate({
67858
+ sessionId: params.sessionId,
67859
+ update: { sessionUpdate: "session_info_update", _meta: { [AGENT_TURN_META2]: started } }
67860
+ });
67861
+ };
67862
+ const endAgentTurn = async () => {
67863
+ const agentTurn = session.agentTurn;
67864
+ if (agentTurn === void 0) {
67865
+ return;
67866
+ }
67867
+ session.agentTurn = void 0;
67868
+ await publishBackgroundTasks();
67869
+ const ended = {
67870
+ stage: "ended",
67871
+ stopReason: agentTurn.cancelled ? "cancelled" : "end_turn"
67872
+ };
67873
+ await this.client.sessionUpdate({
67874
+ sessionId: params.sessionId,
67875
+ update: { sessionUpdate: "session_info_update", _meta: { [AGENT_TURN_META2]: ended } }
67876
+ });
67877
+ };
67763
67878
  const turnAwaitingSubagents = (turn) => {
67764
67879
  if (!turn.spawnedTaskIds?.size) {
67765
67880
  return false;
@@ -67874,6 +67989,10 @@ var ClaudeAcpAgent = class {
67874
67989
  let pendingNext = null;
67875
67990
  try {
67876
67991
  while (true) {
67992
+ await publishBackgroundTasks();
67993
+ if (session.agentTurn !== void 0 && !noPromptInFlight()) {
67994
+ await endAgentTurn();
67995
+ }
67877
67996
  pendingNext ??= session.query.next().then((result) => ({ kind: "message", result }));
67878
67997
  const nextMessage = pendingNext;
67879
67998
  let onAbort;
@@ -67985,6 +68104,7 @@ var ClaudeAcpAgent = class {
67985
68104
  switch (message.subtype) {
67986
68105
  case "init":
67987
68106
  processingBackgroundResults = new Set(awaitingBackgroundResults);
68107
+ await startAgentTurn();
67988
68108
  if (message.capabilities?.includes("msg_lifecycle_v1")) {
67989
68109
  session.msgLifecycleV1 = true;
67990
68110
  }
@@ -68066,6 +68186,9 @@ var ClaudeAcpAgent = class {
68066
68186
  }
68067
68187
  case "session_state_changed": {
68068
68188
  session.lastSessionState = message.state;
68189
+ if (message.state === "running") {
68190
+ await startAgentTurn();
68191
+ }
68069
68192
  if (message.state === "idle") {
68070
68193
  disarmResultWatchdog();
68071
68194
  const boundary = session.idleBoundary;
@@ -68090,6 +68213,9 @@ var ClaudeAcpAgent = class {
68090
68213
  failActive(RequestError.internalError(errorKindData("no_result"), TURN_NO_RESULT_MESSAGE));
68091
68214
  }
68092
68215
  await session.titles.onTurnEnd(session);
68216
+ if (noPromptInFlight()) {
68217
+ await endAgentTurn();
68218
+ }
68093
68219
  }
68094
68220
  break;
68095
68221
  }
@@ -68207,6 +68333,12 @@ var ClaudeAcpAgent = class {
68207
68333
  parentToolUseId: message.tool_use_id,
68208
68334
  isSubagent: !!message.subagent_type
68209
68335
  });
68336
+ backgroundTaskDetails.set(message.task_id, {
68337
+ kind: message.subagent_type ? "subagent" : message.task_type === "local_bash" ? "shell" : "other",
68338
+ ambient: message.ambient === true || message.skip_transcript === true,
68339
+ ...message.tool_use_id === void 0 ? {} : { toolUseId: message.tool_use_id },
68340
+ ...message.description.length === 0 ? {} : { description: message.description }
68341
+ });
68210
68342
  if (message.subagent_type && session.activeTurn && !session.activeTurn.settled) {
68211
68343
  session.activeTurn.spawnedTaskIds ??= /* @__PURE__ */ new Set();
68212
68344
  session.activeTurn.spawnedTaskIds.add(message.task_id);
@@ -68227,6 +68359,7 @@ var ClaudeAcpAgent = class {
68227
68359
  if (message.skip_transcript) {
68228
68360
  backgroundTasks.delete(message.task_id);
68229
68361
  awaitingBackgroundResults.delete(message.task_id);
68362
+ backgroundTaskDetails.delete(message.task_id);
68230
68363
  } else if (backgroundTasks.delete(message.task_id)) {
68231
68364
  awaitingBackgroundResults.add(message.task_id);
68232
68365
  }
@@ -68514,6 +68647,9 @@ ${message.api_refusal_explanation}` : "";
68514
68647
  if (message.origin?.kind === "task-notification") {
68515
68648
  for (const id of processingBackgroundResults) {
68516
68649
  awaitingBackgroundResults.delete(id);
68650
+ if (!backgroundTasks.has(id)) {
68651
+ backgroundTaskDetails.delete(id);
68652
+ }
68517
68653
  }
68518
68654
  processingBackgroundResults.clear();
68519
68655
  reportBackgroundActivity();
@@ -68913,6 +69049,9 @@ ${message.api_refusal_explanation}` : "";
68913
69049
  return;
68914
69050
  }
68915
69051
  session.cancelled = true;
69052
+ if (session.agentTurn !== void 0) {
69053
+ session.agentTurn.cancelled = true;
69054
+ }
68916
69055
  session.pendingExitPlanModeInterruption = void 0;
68917
69056
  session.pendingExitPlanContextReset = void 0;
68918
69057
  if (session.queryClosed) {
@@ -69078,6 +69217,36 @@ ${message.api_refusal_explanation}` : "";
69078
69217
  latestEntryId: await getEnvironmentSessionRevision(this.environment, params.sessionId, session.streamedMessageIds, signal)
69079
69218
  };
69080
69219
  }
69220
+ /** The settings this session would offer with each of its models selected,
69221
+ * built the way a model switch rebuilds them (see applyConfigOptionValue)
69222
+ * but without touching the query: no setModel, so no provider request. The
69223
+ * effort shown for each model is what Claude Code resolves from the
69224
+ * persisted settings for that model. A user's pin made through the ACP
69225
+ * picker belongs to this session only and is not carried across. */
69226
+ async readModelSettings(params) {
69227
+ const session = this.sessions[params.sessionId];
69228
+ if (!session) {
69229
+ throw new Error("Session not found");
69230
+ }
69231
+ const settings = session.settingsManager.getSettings();
69232
+ const useBooleanOption = clientSupportsBooleanConfigOptions(this.clientCapabilities);
69233
+ return {
69234
+ models: session.models.availableModels.map(({ modelId }) => {
69235
+ const modelInfo = session.modelInfos.find((info) => info.value === modelId);
69236
+ const modes = session.modes.currentModeId === "auto" && modelInfo !== void 0 && modelInfo.supportsAutoMode !== true ? { ...session.modes, currentModeId: AUTO_MODE_FALLBACK } : session.modes;
69237
+ const disabledReason = session.fastModeDisabledReason === "model_not_allowed" && modelId !== session.models.currentModelId ? void 0 : session.fastModeDisabledReason;
69238
+ return {
69239
+ modelId,
69240
+ configOptions: buildConfigOptions(modes, { ...session.models, currentModelId: modelId }, session.modelInfos, settingsEffortForModel(settings, modelInfo, modelId), session.agents, session.currentAgent, {
69241
+ supported: modelInfo?.supportsFastMode ?? false,
69242
+ enabled: session.fastModeEnabled,
69243
+ useBooleanOption,
69244
+ disabledReason
69245
+ })
69246
+ };
69247
+ })
69248
+ };
69249
+ }
69081
69250
  async setSessionMode(params) {
69082
69251
  return this.sessionModes.setSessionMode(params);
69083
69252
  }
@@ -71291,12 +71460,14 @@ async function runPromptWithCancellation(agent2, params, signal) {
71291
71460
  signal.removeEventListener("abort", onAbort);
71292
71461
  }
71293
71462
  }
71463
+ var BACKGROUND_TASKS_META2 = "mobius.backgroundTasks";
71464
+ var AGENT_TURN_META2 = "mobius.agentTurn";
71294
71465
  function createClaudeAcpApp(options = {}) {
71295
71466
  let agent2 = null;
71296
71467
  const app = agent({ name: "claude-code-acp" }).onConnect((connection) => {
71297
71468
  agent2 = new ClaudeAcpAgent(new ClientConnection(connection.client, options.onSessionUpdate), options.logger, options.environment, options.spawnClaudeCodeProcess, options.onBackgroundActivity, options.onPromptSuggestion);
71298
71469
  options.onConnect?.(connection);
71299
- }).onRequest(methods.agent.initialize, (ctx) => requiredAgent(agent2).initialize(ctx.params)).onRequest(methods.agent.session.new, (ctx) => requiredAgent(agent2).newSession(ctx.params)).onRequest(methods.agent.session.load, (ctx) => requiredAgent(agent2).loadSession(ctx.params, ctx.signal)).onRequest(methods.agent.session.fork, (ctx) => requiredAgent(agent2).unstable_forkSession(ctx.params, ctx.signal)).onRequest(methods.agent.session.list, (ctx) => requiredAgent(agent2).listSessions(ctx.params, ctx.signal)).onRequest(methods.agent.session.delete, (ctx) => requiredAgent(agent2).deleteSession(ctx.params)).onRequest(methods.agent.session.resume, (ctx) => requiredAgent(agent2).resumeSession(ctx.params)).onRequest(methods.agent.session.close, (ctx) => requiredAgent(agent2).closeSession(ctx.params)).onRequest(methods.agent.session.setMode, (ctx) => requiredAgent(agent2).setSessionMode(ctx.params)).onRequest(methods.agent.session.setConfigOption, (ctx) => requiredAgent(agent2).setSessionConfigOption(ctx.params)).onRequest(methods.agent.authenticate, (ctx) => requiredAgent(agent2).authenticate(ctx.params)).onRequest(methods.agent.providers.list, (ctx) => requiredAgent(agent2).unstable_listProviders(ctx.params)).onRequest(methods.agent.providers.set, (ctx) => requiredAgent(agent2).unstable_setProvider(ctx.params)).onRequest(methods.agent.providers.disable, (ctx) => requiredAgent(agent2).unstable_disableProvider(ctx.params)).onRequest(methods.agent.logout, (ctx) => requiredAgent(agent2).logout(ctx.params)).onRequest(methods.agent.session.prompt, (ctx) => runPromptWithCancellation(requiredAgent(agent2), ctx.params, ctx.signal)).onNotification(methods.agent.session.cancel, (ctx) => requiredAgent(agent2).cancel(ctx.params)).onRequest(STEER_METHOD, { parse: parseSteerRequest }, (ctx) => requiredAgent(agent2).steer(ctx.params)).onRequest(RENAME_METHOD, { parse: parseRenameRequest }, (ctx) => requiredAgent(agent2).renameSession(ctx.params)).onRequest(REVISION_METHOD, { parse: parseRevisionRequest }, (ctx) => requiredAgent(agent2).readSessionRevision(ctx.params, ctx.signal)).onRequest(GOAL_CONTROL_METHOD, { parse: parseGoalRequest }, (ctx) => requiredAgent(agent2).goal(ctx.params));
71470
+ }).onRequest(methods.agent.initialize, (ctx) => requiredAgent(agent2).initialize(ctx.params)).onRequest(methods.agent.session.new, (ctx) => requiredAgent(agent2).newSession(ctx.params)).onRequest(methods.agent.session.load, (ctx) => requiredAgent(agent2).loadSession(ctx.params, ctx.signal)).onRequest(methods.agent.session.fork, (ctx) => requiredAgent(agent2).unstable_forkSession(ctx.params, ctx.signal)).onRequest(methods.agent.session.list, (ctx) => requiredAgent(agent2).listSessions(ctx.params, ctx.signal)).onRequest(methods.agent.session.delete, (ctx) => requiredAgent(agent2).deleteSession(ctx.params)).onRequest(methods.agent.session.resume, (ctx) => requiredAgent(agent2).resumeSession(ctx.params)).onRequest(methods.agent.session.close, (ctx) => requiredAgent(agent2).closeSession(ctx.params)).onRequest(methods.agent.session.setMode, (ctx) => requiredAgent(agent2).setSessionMode(ctx.params)).onRequest(methods.agent.session.setConfigOption, (ctx) => requiredAgent(agent2).setSessionConfigOption(ctx.params)).onRequest(methods.agent.authenticate, (ctx) => requiredAgent(agent2).authenticate(ctx.params)).onRequest(methods.agent.providers.list, (ctx) => requiredAgent(agent2).unstable_listProviders(ctx.params)).onRequest(methods.agent.providers.set, (ctx) => requiredAgent(agent2).unstable_setProvider(ctx.params)).onRequest(methods.agent.providers.disable, (ctx) => requiredAgent(agent2).unstable_disableProvider(ctx.params)).onRequest(methods.agent.logout, (ctx) => requiredAgent(agent2).logout(ctx.params)).onRequest(methods.agent.session.prompt, (ctx) => runPromptWithCancellation(requiredAgent(agent2), ctx.params, ctx.signal)).onNotification(methods.agent.session.cancel, (ctx) => requiredAgent(agent2).cancel(ctx.params)).onRequest(STEER_METHOD, { parse: parseSteerRequest }, (ctx) => requiredAgent(agent2).steer(ctx.params)).onRequest(RENAME_METHOD, { parse: parseRenameRequest }, (ctx) => requiredAgent(agent2).renameSession(ctx.params)).onRequest(REVISION_METHOD, { parse: parseRevisionRequest }, (ctx) => requiredAgent(agent2).readSessionRevision(ctx.params, ctx.signal)).onRequest(MODEL_SETTINGS_METHOD, { parse: parseModelSettingsRequest }, (ctx) => requiredAgent(agent2).readModelSettings(ctx.params)).onRequest(GOAL_CONTROL_METHOD, { parse: parseGoalRequest }, (ctx) => requiredAgent(agent2).goal(ctx.params));
71300
71471
  return { agent: () => agent2, app };
71301
71472
  }
71302
71473
  function requiredAgent(agent2) {
@@ -80736,6 +80907,48 @@ function applyConfigurationChanges(base, changes) {
80736
80907
  }
80737
80908
 
80738
80909
  // src/engine/acp/adapter/session-events.ts
80910
+ var harnessText = external_exports.string().min(1).max(2048);
80911
+ var backgroundTaskReportsSchema = external_exports.array(
80912
+ external_exports.object({
80913
+ taskId: harnessText,
80914
+ kind: external_exports.enum(["subagent", "shell", "other"]).catch("other"),
80915
+ state: external_exports.enum(["running", "awaiting-results"]),
80916
+ toolUseId: harnessText.optional().catch(void 0),
80917
+ description: external_exports.string().optional().catch(void 0)
80918
+ }).readonly()
80919
+ ).max(1e3).readonly();
80920
+ var agentTurnReportSchema = external_exports.discriminatedUnion("stage", [
80921
+ external_exports.object({
80922
+ stage: external_exports.literal("started"),
80923
+ reason: external_exports.enum(["background-task", "other"]).catch("other"),
80924
+ taskIds: external_exports.array(harnessText).max(1e3).readonly()
80925
+ }).readonly(),
80926
+ external_exports.object({ stage: external_exports.literal("ended"), stopReason: external_exports.enum(["end_turn", "cancelled"]) }).readonly()
80927
+ ]);
80928
+ function harnessReports(update) {
80929
+ if (update.sessionUpdate !== "session_info_update") {
80930
+ return null;
80931
+ }
80932
+ const meta3 = update._meta;
80933
+ if (meta3 === void 0 || meta3 === null || !(AGENT_TURN_META in meta3) && !(BACKGROUND_TASKS_META in meta3)) {
80934
+ return null;
80935
+ }
80936
+ const decode6 = (key, schema) => {
80937
+ if (!(key in meta3)) {
80938
+ return null;
80939
+ }
80940
+ const decoded = schema.safeParse(meta3[key]);
80941
+ if (!decoded.success) {
80942
+ console.warn("[acp] Dropped a harness report that does not decode", { key });
80943
+ return null;
80944
+ }
80945
+ return decoded.data;
80946
+ };
80947
+ return {
80948
+ agentTurn: decode6(AGENT_TURN_META, agentTurnReportSchema),
80949
+ backgroundTasks: decode6(BACKGROUND_TASKS_META, backgroundTaskReportsSchema)
80950
+ };
80951
+ }
80739
80952
  function withMobiusFields(update, eventUpdate) {
80740
80953
  if (typeof eventUpdate !== "object" || eventUpdate === null) {
80741
80954
  return eventUpdate;
@@ -80778,6 +80991,16 @@ var AdapterSessionConnection = class {
80778
80991
  if (notification.sessionId !== this.#updates.sessionId()) {
80779
80992
  throw new AcpExecutionError("ACP agent referenced an unknown session", {}, "invalid_agent_session");
80780
80993
  }
80994
+ const reports = harnessReports(notification.update);
80995
+ if (reports !== null) {
80996
+ if (reports.backgroundTasks !== null) {
80997
+ await options.onBackgroundTasks?.(reports.backgroundTasks);
80998
+ }
80999
+ if (reports.agentTurn !== null) {
81000
+ await options.onAgentTurn?.(reports.agentTurn);
81001
+ }
81002
+ return;
81003
+ }
80781
81004
  const signal = AbortSignal.any([this.#lifetime.signal, AbortSignal.timeout(3e4)]);
80782
81005
  const externalized = options.externalizeUpdate === void 0 ? await externalizer.update(notification.sessionId, notification.update, signal) : await options.externalizeUpdate(notification.update, signal);
80783
81006
  signal.throwIfAborted();
@@ -81026,6 +81249,9 @@ var AcpSessionConnector = class {
81026
81249
  // src/engine/acp/adapter/execution-connections.ts
81027
81250
  var absolutePathSchema = external_exports.string().min(1).refine(isAbsolute15);
81028
81251
  var nativeHistoryRevisionSchema = external_exports.object({ latestEntryId: external_exports.string().max(256) });
81252
+ var modelSettingsResponseSchema = external_exports.object({
81253
+ models: external_exports.array(external_exports.object({ modelId: external_exports.string().min(1).max(500), configOptions: external_exports.array(external_exports.unknown()).max(500) })).max(500)
81254
+ });
81029
81255
  var isMethodNotFound = (cause) => cause instanceof RequestError && cause.code === -32601;
81030
81256
  var targetSchema = external_exports.object({
81031
81257
  nativeSessionId: nativeSessionIdSchema,
@@ -81064,6 +81290,8 @@ var AcpExecutionConnections = class {
81064
81290
  ...params.onBackgroundActivity === void 0 ? {} : { onBackgroundActivity: params.onBackgroundActivity },
81065
81291
  ...params.onPromptDelegation === void 0 ? {} : { onPromptDelegation: params.onPromptDelegation },
81066
81292
  ...params.onPromptSuggestion === void 0 ? {} : { onPromptSuggestion: params.onPromptSuggestion },
81293
+ ...params.onAgentTurn === void 0 ? {} : { onAgentTurn: params.onAgentTurn },
81294
+ ...params.onBackgroundTasks === void 0 ? {} : { onBackgroundTasks: params.onBackgroundTasks },
81067
81295
  interactions: params.interactions
81068
81296
  },
81069
81297
  this.#externalizer,
@@ -81339,6 +81567,47 @@ var AcpExecutionConnections = class {
81339
81567
  }
81340
81568
  return { kind: "tracked", latestEntryId: decoded.data.latestEntryId };
81341
81569
  };
81570
+ /** Reads each model's settings from a harness that can report them without switching models. */
81571
+ readModelSettings = async ({
81572
+ signal,
81573
+ ...target
81574
+ }) => {
81575
+ signal.throwIfAborted();
81576
+ const { connection, scope } = this.#resolve(target);
81577
+ let response;
81578
+ try {
81579
+ response = await connection.race(
81580
+ connection.connection.agent.request(
81581
+ "_session/model_settings",
81582
+ { sessionId: target.nativeSessionId },
81583
+ { cancellationSignal: AbortSignal.any([signal, AbortSignal.timeout(3e4)]) }
81584
+ ),
81585
+ "ACP agent exited while reading model settings",
81586
+ signal
81587
+ );
81588
+ } catch (error62) {
81589
+ signal.throwIfAborted();
81590
+ if (error62 instanceof AcpExecutionError && isMethodNotFound(error62.cause)) {
81591
+ return { kind: "unsupported" };
81592
+ }
81593
+ throw error62;
81594
+ }
81595
+ const decoded = modelSettingsResponseSchema.safeParse(response);
81596
+ if (!decoded.success) {
81597
+ throw new AcpExecutionError(
81598
+ "ACP agent returned invalid model settings",
81599
+ { cause: decoded.error },
81600
+ "invalid_session_configuration"
81601
+ );
81602
+ }
81603
+ const protocol = sessionConfigProtocolForAgent(scope.agent.id);
81604
+ const current = connection.snapshot().configOptions;
81605
+ const models = /* @__PURE__ */ new Map();
81606
+ for (const { modelId, configOptions } of decoded.data.models) {
81607
+ models.set(modelId, protocol.normalizeUpdate(current, configOptions));
81608
+ }
81609
+ return { kind: "reported", models };
81610
+ };
81342
81611
  configureSession = async ({
81343
81612
  selection,
81344
81613
  signal,
@@ -81754,6 +82023,7 @@ var ClaudeAdapter = class {
81754
82023
  steer = (...args) => this.#executionConnections.steer(...args);
81755
82024
  renameSession = (...args) => this.#executionConnections.renameSession(...args);
81756
82025
  configureSession = (...args) => this.#executionConnections.configureSession(...args);
82026
+ readModelSettings = (params) => this.#executionConnections.readModelSettings(params);
81757
82027
  close = async () => await runCleanup(
81758
82028
  () => this.#queryProcesses.close(),
81759
82029
  () => this.#executionConnections.close()
@@ -81931,6 +82201,11 @@ var CodexAdapter = class {
81931
82201
  steer = (...args) => this.#executionConnections.steer(...args);
81932
82202
  renameSession = (...args) => this.#executionConnections.renameSession(...args);
81933
82203
  configureSession = (...args) => this.#executionConnections.configureSession(...args);
82204
+ // Codex reports every model's effort in its own catalog; other settings follow a model selection.
82205
+ readModelSettings = async ({ signal }) => {
82206
+ signal.throwIfAborted();
82207
+ return { kind: "unsupported" };
82208
+ };
81934
82209
  close = async () => {
81935
82210
  await runCleanup(
81936
82211
  () => this.#queryProcesses.close(),
@@ -82003,6 +82278,11 @@ var PiAdapter = class {
82003
82278
  steer = (...args) => this.#executionConnections.steer(...args);
82004
82279
  renameSession = (...args) => this.#executionConnections.renameSession(...args);
82005
82280
  configureSession = (...args) => this.#executionConnections.configureSession(...args);
82281
+ // Pi reports thinking levels for its current model only, so each model's settings follow a selection.
82282
+ readModelSettings = async ({ signal }) => {
82283
+ signal.throwIfAborted();
82284
+ return { kind: "unsupported" };
82285
+ };
82006
82286
  close = async () => await runCleanup(
82007
82287
  () => this.#queryProcesses.close(),
82008
82288
  () => this.#executionConnections.close()
@@ -89059,6 +89339,9 @@ var unmeasuredOperationMetrics = Object.freeze({
89059
89339
  snapshot: () => Object.freeze([])
89060
89340
  });
89061
89341
 
89342
+ // src/engine/session/live/agent-session.ts
89343
+ import { randomUUID as randomUUID14 } from "node:crypto";
89344
+
89062
89345
  // ../mobius-sdk/src/conversation-title.ts
89063
89346
  var CONVERSATION_TITLE_CHARACTER_LIMIT = 42;
89064
89347
  function conversationTitleFromText(text2) {
@@ -90239,6 +90522,19 @@ var AgentSession = class _AgentSession {
90239
90522
  }
90240
90523
  hasBackgroundActivity = () => this.#backgroundActivity !== "none";
90241
90524
  #backgroundActivity = "none";
90525
+ /**
90526
+ * The Turn the Agent is running on its own, with no prompt from any client. It has a command of the Runtime's
90527
+ * own, recorded with the same lifecycle events a client's prompt has.
90528
+ */
90529
+ #agentTurn = null;
90530
+ /** The last command a client's prompt started; the Agent's own work continues it unless its work says otherwise. */
90531
+ #lastClientCommandId = void 0;
90532
+ /** The client command each piece of outstanding background work belongs to, fixed when it is first reported. */
90533
+ #backgroundTaskCommands = /* @__PURE__ */ new Map();
90534
+ /** The background work last recorded, so a report that changes nothing records nothing. */
90535
+ #recordedBackground = [];
90536
+ /** The command the Turn the Agent started on its own runs under, while it runs. */
90537
+ agentTurnCommand = () => this.#agentTurn?.commandId;
90242
90538
  /** The command whose prompt the Agent is running, which only the Agent can report as delegated. */
90243
90539
  #delegableCommandId = null;
90244
90540
  #modelEffort = null;
@@ -90294,7 +90590,7 @@ var AgentSession = class _AgentSession {
90294
90590
  cwd: () => this.#cwd,
90295
90591
  getToolCall: (toolCallId) => this.#store.events.getToolCall(this.#mobiusSessionId, toolCallId),
90296
90592
  sessionId: () => this.#mobiusSessionId,
90297
- commandId: () => this.#agentCommand() ?? SESSION_CONTROL_COMMAND_ID,
90593
+ commandId: () => this.#agentCommand() ?? this.#agentTurn?.commandId ?? SESSION_CONTROL_COMMAND_ID,
90298
90594
  assertNativeSession: this.assertNativeSession,
90299
90595
  observer: getObserver,
90300
90596
  recordSessionEvent: this.recordLifecycleEvent
@@ -90322,6 +90618,12 @@ var AgentSession = class _AgentSession {
90322
90618
  void this.#recordNativeHistoryRevision();
90323
90619
  }
90324
90620
  },
90621
+ onAgentTurn: async (report) => {
90622
+ await this.#recordAgentTurn(report);
90623
+ },
90624
+ onBackgroundTasks: async (tasks) => {
90625
+ await this.#recordBackgroundTasks(tasks);
90626
+ },
90325
90627
  onPromptDelegation: async (stage) => {
90326
90628
  const commandId = this.#delegableCommandId;
90327
90629
  if (commandId !== null) {
@@ -90647,6 +90949,8 @@ var AgentSession = class _AgentSession {
90647
90949
  }, options.signal);
90648
90950
  /** Applies a setting the Runtime owns, whatever the configuration's current revision. */
90649
90951
  applyConfiguration = async (change) => this.#configurationChanges.run(async (signal) => await this.#change(change, signal), change.signal);
90952
+ /** Each model's settings as the Agent reports them without switching models, when it can. */
90953
+ readModelSettings = async (signal) => await this.#adapter.readModelSettings({ ...this.#target(), signal });
90650
90954
  #change = async (change, signal) => {
90651
90955
  await this.#applyConfiguration(
90652
90956
  change.valueType === "boolean" ? { type: "boolean", configId: change.configId, booleanValue: change.booleanValue } : { type: "select", configId: change.configId, value: change.value },
@@ -90741,6 +91045,9 @@ var AgentSession = class _AgentSession {
90741
91045
  });
90742
91046
  }
90743
91047
  this.#delegableCommandId = lifecycle === void 0 ? null : options.commandId;
91048
+ if (lifecycle !== void 0) {
91049
+ this.#lastClientCommandId = options.commandId;
91050
+ }
90744
91051
  try {
90745
91052
  const result = await this.#writeNativeHistory(async () => {
90746
91053
  try {
@@ -90982,6 +91289,122 @@ var AgentSession = class _AgentSession {
90982
91289
  await this.#adapter.releaseSession({ ...this.#target(), signal: AbortSignal.timeout(3e4) });
90983
91290
  }
90984
91291
  this.#backgroundActivity = "none";
91292
+ const agentTurn = this.#agentTurn;
91293
+ if (agentTurn !== null) {
91294
+ this.#agentTurn = null;
91295
+ await this.recordLifecycleEvent({
91296
+ payload: {
91297
+ attemptId: agentTurn.attemptId,
91298
+ code: "agent_process_closed",
91299
+ commandId: agentTurn.commandId,
91300
+ kind: "prompt.failed",
91301
+ message: "The Agent process ended before the work it started on its own finished"
91302
+ },
91303
+ type: "lifecycle-metadata"
91304
+ });
91305
+ this.#getObserver().onAgentTurn?.(this.#mobiusSessionId, null);
91306
+ }
91307
+ await this.#recordBackgroundTasks([]);
91308
+ };
91309
+ /**
91310
+ * Cancels the Turn the Agent started on its own when `commandId` names it; returns whether it did. Its end is
91311
+ * recorded when the Agent reports it, as for any interrupted work.
91312
+ */
91313
+ cancelAgentTurn = async (commandId, signal) => {
91314
+ if (this.#agentTurn?.commandId !== commandId) {
91315
+ return false;
91316
+ }
91317
+ await this.#interactions.cancelPendingInteractions();
91318
+ signal.throwIfAborted();
91319
+ await this.#adapter.cancel({ ...this.#target(), signal });
91320
+ return true;
91321
+ };
91322
+ #recordAgentTurn = async (report) => {
91323
+ switch (report.stage) {
91324
+ case "started": {
91325
+ if (this.#agentTurn !== null) {
91326
+ return;
91327
+ }
91328
+ const continues = report.taskIds.flatMap((taskId) => {
91329
+ const commandId = this.#backgroundTaskCommands.get(taskId);
91330
+ return commandId === void 0 ? [] : [commandId];
91331
+ })[0] ?? this.#lastClientCommandId;
91332
+ const agentTurn = { attemptId: randomUUID14(), commandId: `agent-${randomUUID14()}`, continues };
91333
+ this.#agentTurn = agentTurn;
91334
+ await this.recordLifecycleEvent({
91335
+ payload: {
91336
+ attemptId: agentTurn.attemptId,
91337
+ commandId: agentTurn.commandId,
91338
+ epoch: randomUUID14(),
91339
+ initiator: {
91340
+ kind: "agent",
91341
+ reason: report.reason,
91342
+ ...continues === void 0 ? {} : { continues }
91343
+ },
91344
+ kind: "prompt.started"
91345
+ },
91346
+ type: "lifecycle-metadata"
91347
+ });
91348
+ this.#getObserver().onAgentTurn?.(this.#mobiusSessionId, agentTurn.commandId);
91349
+ return;
91350
+ }
91351
+ case "ended": {
91352
+ const agentTurn = this.#agentTurn;
91353
+ if (agentTurn === null) {
91354
+ return;
91355
+ }
91356
+ this.#agentTurn = null;
91357
+ await this.recordLifecycleEvent({
91358
+ payload: {
91359
+ commandId: agentTurn.commandId,
91360
+ kind: "prompt.completed",
91361
+ stopReason: report.stopReason
91362
+ },
91363
+ type: "lifecycle-metadata"
91364
+ });
91365
+ this.#getObserver().onAgentTurn?.(this.#mobiusSessionId, null);
91366
+ return;
91367
+ }
91368
+ default: {
91369
+ const unreachable2 = report;
91370
+ throw new AcpExecutionError("Unexpected Agent Turn report", { cause: unreachable2 });
91371
+ }
91372
+ }
91373
+ };
91374
+ /**
91375
+ * Records the Session's outstanding background work when it changed. Each piece belongs to the client command that
91376
+ * was running, or that the Agent's own Turn continued, when it was first reported.
91377
+ */
91378
+ #recordBackgroundTasks = async (reports) => {
91379
+ const owner = this.#agentCommand() ?? this.#agentTurn?.continues ?? this.#lastClientCommandId;
91380
+ const current = new Set(reports.map((report) => report.taskId));
91381
+ for (const taskId of this.#backgroundTaskCommands.keys()) {
91382
+ if (!current.has(taskId)) {
91383
+ this.#backgroundTaskCommands.delete(taskId);
91384
+ }
91385
+ }
91386
+ const tasks = reports.slice(0, SESSION_BACKGROUND_TASK_MAX_COUNT).map((report) => {
91387
+ if (owner !== void 0 && !this.#backgroundTaskCommands.has(report.taskId)) {
91388
+ this.#backgroundTaskCommands.set(report.taskId, owner);
91389
+ }
91390
+ const commandId = this.#backgroundTaskCommands.get(report.taskId);
91391
+ return {
91392
+ kind: report.kind,
91393
+ state: report.state,
91394
+ taskId: report.taskId,
91395
+ ...commandId === void 0 ? {} : { commandId },
91396
+ ...report.toolUseId === void 0 ? {} : { toolCallId: report.toolUseId },
91397
+ ...report.description === void 0 ? {} : { description: truncate(report.description, 500) }
91398
+ };
91399
+ });
91400
+ if (JSON.stringify(tasks) === JSON.stringify(this.#recordedBackground)) {
91401
+ return;
91402
+ }
91403
+ this.#recordedBackground = tasks;
91404
+ await this.recordLifecycleEvent({
91405
+ payload: { kind: "session.background.changed", tasks },
91406
+ type: "lifecycle-metadata"
91407
+ });
90985
91408
  };
90986
91409
  agentSettingsModelEffort = () => this.#modelEffort;
90987
91410
  #sessionParams = (signal) => ({
@@ -91137,7 +91560,11 @@ var SessionManager2 = class {
91137
91560
  #store;
91138
91561
  #onSessionClosed;
91139
91562
  #timer;
91140
- #observer;
91563
+ /** What each Session's Agent process reports to: the runtime's observer, plus the Agent Turns this manager tracks. */
91564
+ #runtimeObserver;
91565
+ #onSessionStatusChanged;
91566
+ /** The command of the Turn each Session's Agent is running on its own; no client's prompt holds it. */
91567
+ #agentTurns = /* @__PURE__ */ new Map();
91141
91568
  /** Each Session's next-prompt suggestions. They outlive the Session's Agent process. */
91142
91569
  promptSuggestions;
91143
91570
  constructor({
@@ -91149,7 +91576,8 @@ var SessionManager2 = class {
91149
91576
  lastTurn = () => void 0,
91150
91577
  timer
91151
91578
  }) {
91152
- this.#observer = observer;
91579
+ this.#runtimeObserver = this.#observing(observer);
91580
+ this.#onSessionStatusChanged = onSessionStatusChanged;
91153
91581
  this.#processes = processes;
91154
91582
  this.#store = store;
91155
91583
  this.#lastTurn = lastTurn;
@@ -91172,11 +91600,42 @@ var SessionManager2 = class {
91172
91600
  return await runtime.recordControlEvent(event);
91173
91601
  };
91174
91602
  setObserver = (observer) => {
91175
- this.#observer = observer;
91603
+ this.#runtimeObserver = this.#observing(observer);
91176
91604
  };
91605
+ #observing(observer) {
91606
+ return {
91607
+ ...observer.onBackgroundActivity === void 0 ? {} : { onBackgroundActivity: observer.onBackgroundActivity },
91608
+ ...observer.onSessionEvent === void 0 ? {} : { onSessionEvent: observer.onSessionEvent },
91609
+ onAgentTurn: (sessionId, commandId) => {
91610
+ observer.onAgentTurn?.(sessionId, commandId);
91611
+ this.#agentTurnChanged(sessionId, commandId);
91612
+ },
91613
+ onCommands: observer.onCommands,
91614
+ onConfig: observer.onConfig,
91615
+ onElicitation: observer.onElicitation,
91616
+ onElicitationResolved: observer.onElicitationResolved,
91617
+ onInfo: observer.onInfo,
91618
+ onPermission: observer.onPermission,
91619
+ onPermissionResolved: observer.onPermissionResolved
91620
+ };
91621
+ }
91622
+ #agentTurnChanged(sessionId, commandId) {
91623
+ if (commandId === null) {
91624
+ this.#agentTurns.delete(sessionId);
91625
+ } else {
91626
+ this.#agentTurns.set(sessionId, commandId);
91627
+ }
91628
+ this.#onSessionStatusChanged({
91629
+ kind: "session.status.changed",
91630
+ sessionId,
91631
+ status: this.sessionStatus(sessionId)
91632
+ });
91633
+ }
91634
+ /** Whether `commandId` names the Turn the Session's Agent is running on its own. */
91635
+ isAgentTurn = (sessionId, commandId) => this.#agentTurns.get(sessionId) === commandId;
91177
91636
  #retention(sessionId) {
91178
91637
  return {
91179
- isBusy: () => this.#executionProcesses.get(sessionId)?.hasBackgroundActivity() === true || this.#executions.isBusy(sessionId) || this.#executionProcesses.isBusy(sessionId),
91638
+ isBusy: () => this.#executionProcesses.get(sessionId)?.hasBackgroundActivity() === true || this.#agentTurns.has(sessionId) || this.#executions.isBusy(sessionId) || this.#executionProcesses.isBusy(sessionId),
91180
91639
  retire: (runtime) => this.#retireSessionProcess(sessionId, runtime, () => runtime.close()),
91181
91640
  retireIdle: (runtime) => this.#stopSessionProcess(sessionId, runtime)
91182
91641
  };
@@ -91247,7 +91706,7 @@ var SessionManager2 = class {
91247
91706
  async (capabilities) => await AgentSession.start(
91248
91707
  options,
91249
91708
  recovery,
91250
- () => this.#observer,
91709
+ () => this.#runtimeObserver,
91251
91710
  this.#executions.agentCommand,
91252
91711
  this.#store,
91253
91712
  metrics,
@@ -91271,7 +91730,7 @@ var SessionManager2 = class {
91271
91730
  async (capabilities) => await AgentSession.start(
91272
91731
  options,
91273
91732
  recovery,
91274
- () => this.#observer,
91733
+ () => this.#runtimeObserver,
91275
91734
  this.#executions.agentCommand,
91276
91735
  this.#store,
91277
91736
  metrics,
@@ -91292,7 +91751,7 @@ var SessionManager2 = class {
91292
91751
  async (capabilities) => await AgentSession.start(
91293
91752
  options,
91294
91753
  recovery,
91295
- () => this.#observer,
91754
+ () => this.#runtimeObserver,
91296
91755
  this.#executions.agentCommand,
91297
91756
  this.#store,
91298
91757
  unmeasuredOperationMetrics,
@@ -91349,7 +91808,7 @@ var SessionManager2 = class {
91349
91808
  async (capabilities) => await AgentSession.start(
91350
91809
  options,
91351
91810
  recovery,
91352
- () => this.#observer,
91811
+ () => this.#runtimeObserver,
91353
91812
  this.#executions.agentCommand,
91354
91813
  this.#store,
91355
91814
  unmeasuredOperationMetrics,
@@ -91489,17 +91948,33 @@ var SessionManager2 = class {
91489
91948
  if (options2.model !== void 0) {
91490
91949
  return { requested: await inspectModel(options2.model), models };
91491
91950
  }
91492
- if (nativeEffort?.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE && modelOption2?.type === "select" && Object.hasOwn(nativeEffort.valuesByModel, modelOption2.currentValue)) {
91493
- const effort = prepared.configOptions.find(
91494
- (option) => option.id === nativeEffort.effortSettingId
91495
- );
91951
+ if (modelOption2?.type !== "select") {
91952
+ return { requested: snapshot(prepared.configOptions), models };
91953
+ }
91954
+ if (nativeEffort !== null && !Object.hasOwn(nativeEffort.valuesByModel, modelOption2.currentValue)) {
91955
+ return { requested: snapshot(prepared.configOptions), models };
91956
+ }
91957
+ const report = await runtime.readModelSettings(options2.signal);
91958
+ if (report.kind === "reported") {
91496
91959
  for (const { value } of modelOption2.values) {
91497
- models.set(value, await inspectModel(value));
91498
- if (value !== modelOption2.currentValue && modelOption2.currentValue !== "") {
91499
- await change(modelOption2.id, modelOption2.currentValue);
91500
- if (effort?.type === "select" && effort.currentValue !== "") {
91501
- await change(effort.id, effort.currentValue);
91502
- }
91960
+ const configOptions = report.models.get(value);
91961
+ if (configOptions !== void 0) {
91962
+ models.set(value, snapshot(configOptions));
91963
+ }
91964
+ }
91965
+ }
91966
+ const effort = prepared.configOptions.find(
91967
+ (option) => option.id === "reasoning_effort" || option.category === "thought_level"
91968
+ );
91969
+ for (const { value } of modelOption2.values) {
91970
+ if (models.has(value)) {
91971
+ continue;
91972
+ }
91973
+ models.set(value, await inspectModel(value));
91974
+ if (value !== modelOption2.currentValue && modelOption2.currentValue !== "") {
91975
+ await change(modelOption2.id, modelOption2.currentValue);
91976
+ if (effort?.type === "select" && effort.currentValue !== "") {
91977
+ await change(effort.id, effort.currentValue);
91503
91978
  }
91504
91979
  }
91505
91980
  }
@@ -91602,6 +92077,10 @@ var SessionManager2 = class {
91602
92077
  );
91603
92078
  /** Cancels the named command's Agent execution; a command that is not executing has nothing to stop. */
91604
92079
  cancelPrompt = async (sessionId, commandId, signal = AbortSignal.timeout(3e4)) => this.#operations.run({ signal }, async ({ signal: signal2 }) => {
92080
+ if (this.#agentTurns.get(sessionId) === commandId) {
92081
+ await this.#executionProcesses.get(sessionId)?.cancelAgentTurn(commandId, signal2);
92082
+ return;
92083
+ }
91605
92084
  await this.#executions.cancel(sessionId, commandId, async () => {
91606
92085
  const runtime = this.#executionProcesses.get(sessionId);
91607
92086
  if (runtime !== void 0) {
@@ -91797,11 +92276,18 @@ var SessionManager2 = class {
91797
92276
  return stored instanceof FoundStoredSession ? [stored.session] : [];
91798
92277
  });
91799
92278
  sessionStatus = (sessionId) => this.#reported(sessionId, this.#executions.status(sessionId));
91800
- /** An idle Session whose last started command failed says so, so a client that did not watch it still knows. */
92279
+ /**
92280
+ * A Session whose Agent runs a Turn of its own is working on that command while no client's prompt runs. An idle
92281
+ * Session whose last started command failed says so, so a client that did not watch it still knows.
92282
+ */
91801
92283
  #reported = (sessionId, status) => {
91802
92284
  if (status.kind !== "idle") {
91803
92285
  return status;
91804
92286
  }
92287
+ const agentTurn = this.#agentTurns.get(sessionId);
92288
+ if (agentTurn !== void 0) {
92289
+ return { commandId: agentTurn, kind: "working" };
92290
+ }
91805
92291
  const lastTurn = this.#lastTurn(sessionId);
91806
92292
  return lastTurn?.state === "failed" ? {
91807
92293
  ...status,
@@ -92066,7 +92552,7 @@ var PromptLifecycle = class {
92066
92552
  record = (recorded) => {
92067
92553
  this.#recordActiveTurn(recorded);
92068
92554
  const sessionId = recorded.sessionId;
92069
- if (recorded.type === "lifecycle-metadata" && isPromptTerminal(recorded.payload)) {
92555
+ if (recorded.type === "lifecycle-metadata" && isPromptTerminal(recorded.payload) && this.#queued.has(recorded.payload.commandId)) {
92070
92556
  this.#terminal.set(recorded.payload.commandId, recorded);
92071
92557
  const pending = this.#publications.get(sessionId) ?? [];
92072
92558
  pending.push(recorded);
@@ -92209,7 +92695,7 @@ async function settleAbandonedTurn(projection, operations, cancellation) {
92209
92695
  }
92210
92696
 
92211
92697
  // src/engine/session/turn/execution-receipts.ts
92212
- import { createHash as createHash7, randomUUID as randomUUID14 } from "node:crypto";
92698
+ import { createHash as createHash7, randomUUID as randomUUID15 } from "node:crypto";
92213
92699
  var MAX_TERMINAL_RECEIPTS = 1024;
92214
92700
  function executionStarted(state) {
92215
92701
  switch (state.kind) {
@@ -92511,7 +92997,7 @@ var ExecutionReceipts = class {
92511
92997
  ).digest("hex");
92512
92998
  this.#save(commandId, {
92513
92999
  admissionOrder: this.#nextAdmissionOrder(),
92514
- attemptId: randomUUID14(),
93000
+ attemptId: randomUUID15(),
92515
93001
  commandHash,
92516
93002
  sessionId,
92517
93003
  state: {
@@ -92623,7 +93109,7 @@ var ExecutionReceipts = class {
92623
93109
  default:
92624
93110
  return unexpectedStanding(standing);
92625
93111
  }
92626
- const attemptId = randomUUID14();
93112
+ const attemptId = randomUUID15();
92627
93113
  this.#save(commandId, {
92628
93114
  admissionOrder: this.#nextAdmissionOrder(),
92629
93115
  attemptId,
@@ -92736,11 +93222,11 @@ var RuntimeTurnActivity = class {
92736
93222
  };
92737
93223
 
92738
93224
  // src/engine/session/turn/active-turn.ts
92739
- import { randomUUID as randomUUID15 } from "node:crypto";
93225
+ import { randomUUID as randomUUID16 } from "node:crypto";
92740
93226
  var ActiveRuntimeTurn = class {
92741
93227
  attemptId;
92742
93228
  command;
92743
- epoch = decodeIdentifier(randomUUID15());
93229
+ epoch = decodeIdentifier(randomUUID16());
92744
93230
  #controller;
92745
93231
  #finished = Promise.withResolvers();
92746
93232
  #started;
@@ -93387,11 +93873,11 @@ import { extname as extname2, join as join29 } from "node:path";
93387
93873
  import { pathToFileURL as pathToFileURL3 } from "node:url";
93388
93874
 
93389
93875
  // src/engine/storage/files/scratch-directory.ts
93390
- import { randomUUID as randomUUID16 } from "node:crypto";
93876
+ import { randomUUID as randomUUID17 } from "node:crypto";
93391
93877
  import { lstat as lstat4, mkdir as mkdir5, readdir as readdir6, readFile as readFile7, realpath as realpath7, rename as rename4, rm as rm5, stat as stat6, utimes, writeFile as writeFile2 } from "node:fs/promises";
93392
93878
  import { dirname as dirname11, join as join28 } from "node:path";
93393
93879
  async function atomicWrite(path6, bytes, signal) {
93394
- const temporary = `${path6}.${randomUUID16()}.tmp`;
93880
+ const temporary = `${path6}.${randomUUID17()}.tmp`;
93395
93881
  try {
93396
93882
  await writeFile2(temporary, bytes, { mode: 384, signal });
93397
93883
  signal.throwIfAborted();
@@ -93403,7 +93889,7 @@ async function atomicWrite(path6, bytes, signal) {
93403
93889
  var ScratchDirectory = class {
93404
93890
  #root;
93405
93891
  constructor(parent) {
93406
- this.#root = join28(parent, randomUUID16());
93892
+ this.#root = join28(parent, randomUUID17());
93407
93893
  }
93408
93894
  /** Refreshes this directory's lease and removes sibling directories whose lease is older than `leaseMilliseconds`. */
93409
93895
  refreshLease = async (leaseMilliseconds) => {
@@ -93890,7 +94376,7 @@ var AgentProcessPool = class {
93890
94376
  };
93891
94377
 
93892
94378
  // src/engine/session/settings/agent-settings-cache.ts
93893
- import { createHash as createHash9, randomUUID as randomUUID17 } from "node:crypto";
94379
+ import { createHash as createHash9, randomUUID as randomUUID18 } from "node:crypto";
93894
94380
  import { join as join30 } from "node:path";
93895
94381
  var CACHE_FILE_LIMIT = 32 * 1024 * 1024;
93896
94382
  var CACHE_FORMAT = 1;
@@ -93902,7 +94388,7 @@ var modelEffortSchema = external_exports.discriminatedUnion("kind", [
93902
94388
  value: external_exports.object({
93903
94389
  effortSettingId: external_exports.string(),
93904
94390
  modelSettingId: external_exports.string(),
93905
- resolution: external_exports.enum(["complete", "on_model_selection", "unavailable"]),
94391
+ resolution: external_exports.enum(["complete", "unavailable"]),
93906
94392
  unsupportedModelIds: external_exports.array(external_exports.string()),
93907
94393
  valuesByModel: external_exports.record(
93908
94394
  external_exports.string(),
@@ -93963,7 +94449,7 @@ var AgentSettingsCache = class {
93963
94449
  return this.#generation;
93964
94450
  }
93965
94451
  invalidate = async (signal) => {
93966
- await writeInstallationFile(this.#generationPath, randomUUID17(), signal);
94452
+ await writeInstallationFile(this.#generationPath, randomUUID18(), signal);
93967
94453
  this.#generation += 1;
93968
94454
  };
93969
94455
  open = async (agent2, signal) => {
@@ -94429,23 +94915,13 @@ var AppliedAgentLaunchSettings = class {
94429
94915
  }
94430
94916
  };
94431
94917
  var AgentSettingsAdapter = class {
94432
- modelEffortResolution = AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION;
94433
94918
  applyLaunchSelection = (agent2, _selection) => new AgentSettingsLaunchSelectionResult(agent2, false);
94434
94919
  settings = (_agent) => [];
94435
94920
  };
94436
94921
 
94437
- // src/engine/agent/settings/codex-settings-adapter.ts
94438
- var CodexSettingsAdapter = class extends AgentSettingsAdapter {
94439
- modelEffortResolution = AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE;
94440
- };
94441
-
94442
94922
  // src/engine/agent/settings/agent-settings-adapter.ts
94443
94923
  var genericAdapter = new AgentSettingsAdapter();
94444
- var codexAdapter = new CodexSettingsAdapter();
94445
- function agentSettingsAdapterForAgent(agentId) {
94446
- if (agentId === "codex") {
94447
- return codexAdapter;
94448
- }
94924
+ function agentSettingsAdapterForAgent(_agentId) {
94449
94925
  return genericAdapter;
94450
94926
  }
94451
94927
  function applyAgentLaunchSettings(agent2, selections) {
@@ -94553,9 +95029,7 @@ async function collectAgentSettings(command, agent2, inspect, signal) {
94553
95029
  }
94554
95030
  }
94555
95031
  }
94556
- const adapter = agentSettingsAdapterForAgent(agent2.id);
94557
95032
  const { modelEffort, effort } = await discoverModelEffort(
94558
- adapter.modelEffortResolution,
94559
95033
  baseSnapshot.configOptions,
94560
95034
  unsupportedModels,
94561
95035
  baseSnapshot.modelEffort,
@@ -94652,21 +95126,16 @@ function unavailableModelEffort() {
94652
95126
  valuesByModel: {}
94653
95127
  };
94654
95128
  }
94655
- async function discoverModelEffort(resolution, initialOptions, initiallyUnsupportedModels, discoveredModelEffort, inspect, signal) {
95129
+ async function discoverModelEffort(initialOptions, initiallyUnsupportedModels, discoveredModelEffort, inspect, signal) {
94656
95130
  const model = modelOption(initialOptions);
94657
95131
  const unsupportedModels = initiallyUnsupportedModels;
94658
- if (resolution !== AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE && resolution !== AGENT_MODEL_EFFORT_RESOLUTION_ON_MODEL_SELECTION) {
94659
- return {
94660
- modelEffort: { ...unavailableModelEffort(), unsupportedModelIds: unsupportedModelIds(unsupportedModels) }
94661
- };
94662
- }
94663
95132
  if (model === void 0 || model.type !== "select" || model.values.length === 0) {
94664
95133
  return {
94665
95134
  modelEffort: { ...unavailableModelEffort(), unsupportedModelIds: unsupportedModelIds(unsupportedModels) }
94666
95135
  };
94667
95136
  }
94668
95137
  const inspectModel = async (model2) => (await inspect(model2)).configOptions;
94669
- if (resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE && discoveredModelEffort.kind === "complete" && discoveredModelEffort.value.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE) {
95138
+ if (discoveredModelEffort.kind === "complete" && discoveredModelEffort.value.resolution === AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE) {
94670
95139
  for (const { value } of model.values) {
94671
95140
  if (value !== model.currentValue) {
94672
95141
  try {
@@ -94683,41 +95152,6 @@ async function discoverModelEffort(resolution, initialOptions, initiallyUnsuppor
94683
95152
  return { modelEffort: discoveredModelEffort.value };
94684
95153
  }
94685
95154
  const valuesByModel = /* @__PURE__ */ new Map();
94686
- if (resolution === "complete") {
94687
- const effort2 = effortOption(initialOptions);
94688
- if (effort2 === void 0 || effort2.type !== "select" || effort2.values.length < 2) {
94689
- return {
94690
- modelEffort: {
94691
- ...unavailableModelEffort(),
94692
- unsupportedModelIds: unsupportedModelIds(unsupportedModels)
94693
- }
94694
- };
94695
- }
94696
- for (const value of model.values) {
94697
- if (unsupportedModels.some((diagnostic) => diagnostic.requestedValue === value.value)) {
94698
- continue;
94699
- }
94700
- try {
94701
- const selectedEffort = effortOption(await inspectModel(value.value));
94702
- valuesByModel.set(value.value, selectedEffort?.type === "select" ? selectedEffort.values : []);
94703
- } catch (cause) {
94704
- signal.throwIfAborted();
94705
- if (!isUnavailableModel(cause, model.id, value.value)) {
94706
- throw cause;
94707
- }
94708
- unsupportedModels.push(cause);
94709
- }
94710
- }
94711
- return {
94712
- modelEffort: {
94713
- effortSettingId: effort2.id,
94714
- modelSettingId: model.id,
94715
- resolution: "complete",
94716
- unsupportedModelIds: unsupportedModelIds(unsupportedModels),
94717
- valuesByModel: Object.fromEntries(valuesByModel)
94718
- }
94719
- };
94720
- }
94721
95155
  const defaultEffort = effortOption(initialOptions);
94722
95156
  let effort = defaultEffort;
94723
95157
  for (const value of model.values) {
@@ -94742,7 +95176,7 @@ async function discoverModelEffort(resolution, initialOptions, initiallyUnsuppor
94742
95176
  modelEffort: {
94743
95177
  effortSettingId: effort?.id ?? "",
94744
95178
  modelSettingId: model.id,
94745
- resolution: "on_model_selection",
95179
+ resolution: AGENT_MODEL_EFFORT_RESOLUTION_COMPLETE,
94746
95180
  unsupportedModelIds: unsupportedModelIds(unsupportedModels),
94747
95181
  valuesByModel: Object.fromEntries(valuesByModel)
94748
95182
  }
@@ -95236,6 +95670,12 @@ var sessionCancelCommand = {
95236
95670
  if (message.kind !== SESSION_CANCEL_KIND) {
95237
95671
  throw new Error("Command kind mismatch");
95238
95672
  }
95673
+ if (sessions.isAgentTurn(message.sessionId, message.commandId)) {
95674
+ void sessions.cancelPrompt(message.sessionId, message.commandId, signal).catch((error62) => {
95675
+ console.error("Mobius daemon could not cancel the Agent's own turn", error62);
95676
+ });
95677
+ return;
95678
+ }
95239
95679
  const turn = sessionTurns.get(message.commandId, message.sessionId);
95240
95680
  if (turn === void 0) {
95241
95681
  void settleAbandonedTurn(eventProjection, operations, message).catch((error62) => {
@@ -95525,7 +95965,7 @@ async function resolveSessionDirectories(directories, bindingId, directoryId, ad
95525
95965
  }
95526
95966
 
95527
95967
  // src/engine/session/prompt/apply-session-configuration.ts
95528
- import { randomUUID as randomUUID18 } from "node:crypto";
95968
+ import { randomUUID as randomUUID19 } from "node:crypto";
95529
95969
  function invalidSessionConfiguration(message) {
95530
95970
  return new AcpExecutionError(message, {}, "invalid_session_configuration");
95531
95971
  }
@@ -95650,7 +96090,7 @@ async function applySessionConfigurationSelection(sessions, options, selection,
95650
96090
  booleanValue: selection.booleanValue,
95651
96091
  configId: selection.configId,
95652
96092
  cwd,
95653
- requestId: `cfg_${randomUUID18()}`,
96093
+ requestId: `cfg_${randomUUID19()}`,
95654
96094
  sessionId,
95655
96095
  signal,
95656
96096
  value: selection.value,
@@ -97636,4 +98076,4 @@ export {
97636
98076
  * MIT Licensed
97637
98077
  *)
97638
98078
  */
97639
- //# sourceMappingURL=chunk-KV2EUHFD.js.map
98079
+ //# sourceMappingURL=chunk-X6VDMZHE.js.map