@moxt-ai/mobius 0.0.458 → 0.0.459

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import {
5
5
  __toESM,
6
6
  __using,
7
7
  package_default
8
- } from "./chunk-BHWFDFZG.js";
8
+ } from "./chunk-OYY3E77D.js";
9
9
 
10
10
  // ../../node_modules/.pnpm/ignore@7.0.9/node_modules/ignore/index.js
11
11
  var require_ignore = __commonJS({
@@ -29007,8 +29007,10 @@ var SUBAGENT_CONVERSATION_ID_PATTERN = /"conversationId"\s*:\s*"([0-9a-f]{8}-[0-
29007
29007
  var SUBAGENT_IDLE_ID_PATTERN = /\bSubagent ([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}) (?:has gone|went) idle\b/giu;
29008
29008
  var AGENT_EXECUTOR_ERROR_PATTERN = /^\s*⚠ agent executor error:\s*(.+?)\s*$/su;
29009
29009
  var TASK_RESULT_SENDER_PATTERN = /\bsender=([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/(task-\d+)\b/giu;
29010
+ var BACKGROUND_TASK_CREATED_PATTERN = /\bTool is running as a background task with task id:\s*([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/(task-\d+)\b/iu;
29010
29011
  var SUBAGENT_CREATED_MARKER = "Created the following subagent";
29011
29012
  var MAXIMUM_TOOL_DESCRIPTION_CHARS = 500;
29013
+ var MINIMUM_TRUNCATED_MATCH_CHARS = 16;
29012
29014
  var transcriptStepSchema = external_exports.object({
29013
29015
  content: external_exports.string().optional(),
29014
29016
  status: external_exports.string().optional(),
@@ -29209,15 +29211,80 @@ function inspectToolMetadata(update, previous) {
29209
29211
  }
29210
29212
  }
29211
29213
  }
29214
+ const matchText = readInputString(inputs, "CommandLine") ?? readInputString(inputs, "Prompt") ?? readInputString(inputs, "Description") ?? previous?.matchText;
29212
29215
  const description = readInputString(inputs, "toolSummary") ?? readInputString(inputs, "Description") ?? readInputString(inputs, "Role") ?? readInputString(inputs, "CommandLine") ?? readInputString(inputs, "Prompt") ?? readString3(update, "title") ?? previous?.description;
29213
29216
  return {
29214
29217
  category,
29215
29218
  description: description === void 0 ? void 0 : truncate(description, MAXIMUM_TOOL_DESCRIPTION_CHARS),
29216
29219
  isDaemon,
29220
+ matchText,
29217
29221
  subagentKillAll,
29218
29222
  subagentKillIds: [...subagentKillIds]
29219
29223
  };
29220
29224
  }
29225
+ function isBackgroundableCategory(category) {
29226
+ return category === "command" || category === "schedule" || category === "workflow";
29227
+ }
29228
+ function decodeTranscriptArg(value) {
29229
+ if (typeof value !== "string") {
29230
+ return value;
29231
+ }
29232
+ try {
29233
+ return JSON.parse(value);
29234
+ } catch {
29235
+ return value;
29236
+ }
29237
+ }
29238
+ function readTranscriptArgString(args, key) {
29239
+ const raw = args[key];
29240
+ if (raw === void 0) {
29241
+ return void 0;
29242
+ }
29243
+ const decoded = decodeTranscriptArg(raw);
29244
+ if (typeof decoded !== "string") {
29245
+ return void 0;
29246
+ }
29247
+ const stripped = typeof raw === "string" && decoded === raw && decoded.startsWith('"') ? decoded.slice(1) : decoded;
29248
+ const trimmed = stripped.trim();
29249
+ return trimmed.length > 0 ? trimmed : void 0;
29250
+ }
29251
+ function readTranscriptToolCallInfo(raw) {
29252
+ if (!isRecord5(raw)) {
29253
+ return null;
29254
+ }
29255
+ const name2 = readString3(raw, "name");
29256
+ const category = name2 === "run_command" ? "command" : name2 === "schedule" ? "schedule" : name2 === "run_workflow" ? "workflow" : null;
29257
+ const args = isRecord5(raw["args"]) ? raw["args"] : void 0;
29258
+ const isDaemon = args !== void 0 && (decodeTranscriptArg(args["IsDaemon"]) === true || readTranscriptArgString(args, "CronExpression") !== void 0);
29259
+ const matchText = args === void 0 ? void 0 : readTranscriptArgString(args, "CommandLine") ?? readTranscriptArgString(args, "Prompt") ?? readTranscriptArgString(args, "Description");
29260
+ return { category, isDaemon, matchText };
29261
+ }
29262
+ function matchesCandidateText(candidateText, transcriptText) {
29263
+ if (candidateText === void 0 || transcriptText === void 0) {
29264
+ return false;
29265
+ }
29266
+ if (candidateText === transcriptText) {
29267
+ return true;
29268
+ }
29269
+ const shorter = candidateText.length <= transcriptText.length ? candidateText : transcriptText;
29270
+ const longer = candidateText.length <= transcriptText.length ? transcriptText : candidateText;
29271
+ return shorter.length >= MINIMUM_TRUNCATED_MATCH_CHARS && longer.startsWith(shorter);
29272
+ }
29273
+ function extractTaskResultSenderIds(sessionId, steps, minStepExclusive, maxStepInclusive) {
29274
+ const targetSessionId = sessionId.toLowerCase();
29275
+ const received = /* @__PURE__ */ new Set();
29276
+ for (const step of steps) {
29277
+ if (step.step_index <= minStepExclusive || step.step_index > maxStepInclusive || step.type !== "SYSTEM_MESSAGE" || step.content === void 0) {
29278
+ continue;
29279
+ }
29280
+ for (const match of step.content.matchAll(TASK_RESULT_SENDER_PATTERN)) {
29281
+ if (match[1]?.toLowerCase() === targetSessionId && match[2] !== void 0) {
29282
+ received.add(match[2]);
29283
+ }
29284
+ }
29285
+ }
29286
+ return received;
29287
+ }
29221
29288
  function backgroundKindFor(category) {
29222
29289
  switch (category) {
29223
29290
  case "command":
@@ -29275,6 +29342,14 @@ var AntigravityBackgroundWakeup = class {
29275
29342
  }
29276
29343
  const created = {
29277
29344
  activeInteractions: 0,
29345
+ backgroundCorrelation: {
29346
+ boundCreationSteps: /* @__PURE__ */ new Set(),
29347
+ daemonNativeTaskIds: /* @__PURE__ */ new Set(),
29348
+ deliveredNativeTaskIds: /* @__PURE__ */ new Set(),
29349
+ nativeTaskIdByToolCallId: /* @__PURE__ */ new Map(),
29350
+ pendingCandidates: [],
29351
+ toolCallIdByNativeTaskId: /* @__PURE__ */ new Map()
29352
+ },
29278
29353
  backgroundTasks: /* @__PURE__ */ new Map(),
29279
29354
  baselineStepIndex: -1,
29280
29355
  lastEmittedBackgroundKey: "[]",
@@ -29287,8 +29362,9 @@ var AntigravityBackgroundWakeup = class {
29287
29362
  pendingToolCallIds: []
29288
29363
  },
29289
29364
  toolMetadata: /* @__PURE__ */ new Map(),
29365
+ wakeupCompletedOpenBgCandidates: /* @__PURE__ */ new Set(),
29290
29366
  wakeupGeneration: 0,
29291
- wakeupPendingTaskResults: 0,
29367
+ wakeupOwedToolCallIds: /* @__PURE__ */ new Set(),
29292
29368
  wakeupSettledStepIndex: null,
29293
29369
  wakeupStageSeq: 0
29294
29370
  };
@@ -29360,8 +29436,19 @@ var AntigravityBackgroundWakeup = class {
29360
29436
  }
29361
29437
  }
29362
29438
  };
29439
+ #deleteBackgroundTask = (session, toolCallId) => {
29440
+ session.backgroundTasks.delete(toolCallId);
29441
+ session.wakeupOwedToolCallIds.delete(toolCallId);
29442
+ session.wakeupCompletedOpenBgCandidates.delete(toolCallId);
29443
+ this.#removeBackgroundCandidate(session, toolCallId);
29444
+ session.backgroundCorrelation.nativeTaskIdByToolCallId.delete(toolCallId);
29445
+ };
29363
29446
  #clearAllBackgroundTasks = (session) => {
29364
29447
  session.backgroundTasks.clear();
29448
+ session.wakeupOwedToolCallIds.clear();
29449
+ session.wakeupCompletedOpenBgCandidates.clear();
29450
+ session.backgroundCorrelation.pendingCandidates.length = 0;
29451
+ session.backgroundCorrelation.nativeTaskIdByToolCallId.clear();
29365
29452
  session.subagents.conversationIdByToolCallId.clear();
29366
29453
  session.subagents.pendingToolCallIds.length = 0;
29367
29454
  };
@@ -29371,7 +29458,101 @@ var AntigravityBackgroundWakeup = class {
29371
29458
  if (task.kind === "subagent") {
29372
29459
  this.#deleteSubagentTask(session, taskId);
29373
29460
  } else {
29374
- session.backgroundTasks.delete(taskId);
29461
+ this.#deleteBackgroundTask(session, taskId);
29462
+ }
29463
+ }
29464
+ }
29465
+ };
29466
+ #recordBackgroundCandidate = (session, toolCallId, meta3) => {
29467
+ if (meta3.isDaemon || !isBackgroundableCategory(meta3.category)) {
29468
+ return;
29469
+ }
29470
+ if (session.backgroundCorrelation.nativeTaskIdByToolCallId.has(toolCallId)) {
29471
+ return;
29472
+ }
29473
+ const candidates = session.backgroundCorrelation.pendingCandidates;
29474
+ const existingIndex = candidates.findIndex((candidate) => candidate.toolCallId === toolCallId);
29475
+ if (existingIndex !== -1) {
29476
+ const existing = candidates[existingIndex];
29477
+ if (existing !== void 0 && existing.matchText === void 0 && meta3.matchText !== void 0) {
29478
+ candidates[existingIndex] = { ...existing, matchText: meta3.matchText };
29479
+ }
29480
+ return;
29481
+ }
29482
+ candidates.push({
29483
+ category: meta3.category,
29484
+ matchText: meta3.matchText,
29485
+ toolCallId
29486
+ });
29487
+ };
29488
+ #removeBackgroundCandidate = (session, toolCallId) => {
29489
+ const candidates = session.backgroundCorrelation.pendingCandidates;
29490
+ const index2 = candidates.findIndex((candidate) => candidate.toolCallId === toolCallId);
29491
+ if (index2 !== -1) {
29492
+ candidates.splice(index2, 1);
29493
+ }
29494
+ };
29495
+ #isActiveBackgroundCandidate = (session, toolCallId) => session.backgroundTasks.has(toolCallId) || session.phase.kind === "wakeup" && session.phase.openToolIds.has(toolCallId) || session.wakeupCompletedOpenBgCandidates.has(toolCallId) || session.wakeupOwedToolCallIds.has(toolCallId);
29496
+ #pruneInactiveCandidates = (session) => {
29497
+ const candidates = session.backgroundCorrelation.pendingCandidates;
29498
+ let writeIndex = 0;
29499
+ for (const candidate of candidates) {
29500
+ if (this.#isActiveBackgroundCandidate(session, candidate.toolCallId)) {
29501
+ candidates[writeIndex] = candidate;
29502
+ writeIndex += 1;
29503
+ }
29504
+ }
29505
+ candidates.length = writeIndex;
29506
+ };
29507
+ #syncBackgroundTaskCreations = (sessionId, session, steps) => {
29508
+ const correlation = session.backgroundCorrelation;
29509
+ const targetSessionId = sessionId.toLowerCase();
29510
+ let lastPlanner;
29511
+ for (const step of steps) {
29512
+ if (step.type === "PLANNER_RESPONSE" && step.tool_calls !== void 0 && step.tool_calls.length > 0) {
29513
+ lastPlanner = step;
29514
+ continue;
29515
+ }
29516
+ if (step.type !== "GENERIC" || step.status !== "RUNNING" || step.content === void 0 || correlation.boundCreationSteps.has(step.step_index)) {
29517
+ continue;
29518
+ }
29519
+ const match = BACKGROUND_TASK_CREATED_PATTERN.exec(step.content);
29520
+ if (match === null || match[1]?.toLowerCase() !== targetSessionId || match[2] === void 0) {
29521
+ continue;
29522
+ }
29523
+ const nativeTaskId = match[2];
29524
+ correlation.boundCreationSteps.add(step.step_index);
29525
+ const offset = lastPlanner === void 0 ? -1 : step.step_index - lastPlanner.step_index - 1;
29526
+ const rawToolCall = lastPlanner?.tool_calls !== void 0 && offset >= 0 && offset < lastPlanner.tool_calls.length ? lastPlanner.tool_calls[offset] : void 0;
29527
+ const info = readTranscriptToolCallInfo(rawToolCall);
29528
+ if (info?.isDaemon === true) {
29529
+ correlation.daemonNativeTaskIds.add(nativeTaskId);
29530
+ continue;
29531
+ }
29532
+ if (info !== null && info.category === null || step.step_index <= session.sessionOpenStepIndex) {
29533
+ continue;
29534
+ }
29535
+ const candidates = correlation.pendingCandidates;
29536
+ const categoryMatches = (candidate) => info === null || info.category === null || candidate.category === info.category;
29537
+ let matchedIndex = candidates.findIndex(
29538
+ (candidate) => this.#isActiveBackgroundCandidate(session, candidate.toolCallId) && categoryMatches(candidate) && matchesCandidateText(candidate.matchText, info?.matchText)
29539
+ );
29540
+ if (matchedIndex === -1) {
29541
+ matchedIndex = candidates.findIndex(
29542
+ (candidate) => this.#isActiveBackgroundCandidate(session, candidate.toolCallId) && categoryMatches(candidate)
29543
+ );
29544
+ }
29545
+ if (matchedIndex === -1 && info?.matchText !== void 0) {
29546
+ matchedIndex = candidates.findIndex(
29547
+ (candidate) => categoryMatches(candidate) && matchesCandidateText(candidate.matchText, info.matchText)
29548
+ );
29549
+ }
29550
+ if (matchedIndex !== -1) {
29551
+ const matched = candidates[matchedIndex];
29552
+ if (matched !== void 0) {
29553
+ candidates.splice(matchedIndex, 1);
29554
+ correlation.nativeTaskIdByToolCallId.set(matched.toolCallId, nativeTaskId);
29555
+ correlation.toolCallIdByNativeTaskId.set(nativeTaskId, matched.toolCallId);
29375
29556
  }
29376
29557
  }
29377
29558
  }
@@ -29571,9 +29752,13 @@ var AntigravityBackgroundWakeup = class {
29571
29752
  }
29572
29753
  session.wakeupGeneration += 1;
29573
29754
  const generation = session.wakeupGeneration;
29574
- session.wakeupPendingTaskResults = [...session.backgroundTasks.values()].filter(
29575
- (task) => task.kind !== "subagent" && task.state === "awaiting-results"
29576
- ).length;
29755
+ session.wakeupOwedToolCallIds.clear();
29756
+ session.wakeupCompletedOpenBgCandidates.clear();
29757
+ for (const [toolCallId, task] of session.backgroundTasks) {
29758
+ if (task.kind !== "subagent" && task.state === "awaiting-results") {
29759
+ session.wakeupOwedToolCallIds.add(toolCallId);
29760
+ }
29761
+ }
29577
29762
  session.wakeupSettledStepIndex = null;
29578
29763
  this.#setWakeupAwaitingOutput(sessionId, session, generation, /* @__PURE__ */ new Set());
29579
29764
  notifications.push(
@@ -29591,6 +29776,8 @@ var AntigravityBackgroundWakeup = class {
29591
29776
  }
29592
29777
  this.#cancelWakeupTimers(session.phase);
29593
29778
  session.phase = { cancelRequested, kind: "idle" };
29779
+ session.wakeupOwedToolCallIds.clear();
29780
+ session.wakeupCompletedOpenBgCandidates.clear();
29594
29781
  this.#dropAwaitingResultTasks(session);
29595
29782
  const notifications = [];
29596
29783
  const bgNotification = this.#takeBackgroundTasksUpdate(sessionId, session);
@@ -29611,6 +29798,8 @@ var AntigravityBackgroundWakeup = class {
29611
29798
  }
29612
29799
  this.#cancelWakeupTimers(session.phase);
29613
29800
  session.phase = { cancelRequested: false, kind: "idle" };
29801
+ session.wakeupOwedToolCallIds.clear();
29802
+ session.wakeupCompletedOpenBgCandidates.clear();
29614
29803
  this.#dropAwaitingResultTasks(session);
29615
29804
  const notifications = [];
29616
29805
  const bgNotification = this.#takeBackgroundTasksUpdate(sessionId, session);
@@ -29674,11 +29863,16 @@ var AntigravityBackgroundWakeup = class {
29674
29863
  }
29675
29864
  if (tail !== null) {
29676
29865
  this.#syncSubagentCreations(current, tail.steps);
29866
+ this.#syncBackgroundTaskCreations(sessionId, current, tail.steps);
29677
29867
  }
29678
29868
  if (tail?.settledStepIndex !== null && tail?.settledStepIndex !== void 0) {
29679
29869
  if (this.#settleWakeupReply(sessionId, current, tail, tail.settledStepIndex)) {
29680
29870
  this.#emitNotifications(this.#finishWakeup(sessionId, current, "end_turn", false));
29681
29871
  } else {
29872
+ const bg2 = this.#takeBackgroundTasksUpdate(sessionId, current);
29873
+ if (bg2 !== null) {
29874
+ this.#emitMetaUpdate(bg2);
29875
+ }
29682
29876
  this.#setWakeupAwaitingOutput(sessionId, current, generation, current.phase.openToolIds);
29683
29877
  }
29684
29878
  return;
@@ -29693,9 +29887,10 @@ var AntigravityBackgroundWakeup = class {
29693
29887
  this.#rescheduleTranscriptCheck(sessionId, current, generation, stageEpoch, currentStage);
29694
29888
  };
29695
29889
  /**
29696
- * Records that the continuation's reply settled at `settledStepIndex` and counts the task results Antigravity
29697
- * handed to it up to there. Answers whether the continuation ends: it goes on while results are still owed, since
29698
- * Antigravity hands each to the run right after the reply it has, and the run continues from it.
29890
+ * Records that the continuation's reply settled at `settledStepIndex` and reconciles the task results Antigravity
29891
+ * handed to it up to there against the specific background tool calls still owed. Answers whether the continuation
29892
+ * ends: it goes on while any owed non-daemon result has not reached the transcript yet, since Antigravity hands
29893
+ * each to the run right after the reply it has, and the run continues from it.
29699
29894
  */
29700
29895
  #settleWakeupReply = (sessionId, session, tail, settledStepIndex) => {
29701
29896
  const sinceStepIndex = session.baselineStepIndex;
@@ -29703,22 +29898,60 @@ var AntigravityBackgroundWakeup = class {
29703
29898
  session.wakeupSettledStepIndex = settledStepIndex;
29704
29899
  this.#consumeSubagentIdlesThrough(session, tail.steps, settledStepIndex);
29705
29900
  if (tail.firstStepIndex > sinceStepIndex + 1) {
29706
- session.wakeupPendingTaskResults = 0;
29901
+ session.wakeupOwedToolCallIds.clear();
29902
+ session.wakeupCompletedOpenBgCandidates.clear();
29903
+ this.#pruneInactiveCandidates(session);
29707
29904
  return true;
29708
29905
  }
29709
- const received = /* @__PURE__ */ new Set();
29710
- for (const step of tail.steps) {
29711
- if (step.step_index <= sinceStepIndex || step.step_index > settledStepIndex || step.type !== "SYSTEM_MESSAGE" || step.content === void 0) {
29712
- continue;
29906
+ const correlation = session.backgroundCorrelation;
29907
+ const received = extractTaskResultSenderIds(sessionId, tail.steps, sinceStepIndex, settledStepIndex);
29908
+ for (const nativeTaskId of received) {
29909
+ correlation.deliveredNativeTaskIds.add(nativeTaskId);
29910
+ }
29911
+ for (const toolCallId of [...session.wakeupCompletedOpenBgCandidates]) {
29912
+ session.wakeupCompletedOpenBgCandidates.delete(toolCallId);
29913
+ const nativeTaskId = correlation.nativeTaskIdByToolCallId.get(toolCallId);
29914
+ if (nativeTaskId !== void 0 && !correlation.deliveredNativeTaskIds.has(nativeTaskId)) {
29915
+ session.wakeupOwedToolCallIds.add(toolCallId);
29916
+ if (!session.backgroundTasks.has(toolCallId)) {
29917
+ const meta3 = session.toolMetadata.get(toolCallId);
29918
+ const kind = backgroundKindFor(meta3?.category ?? null) ?? "shell";
29919
+ session.backgroundTasks.set(toolCallId, {
29920
+ ...meta3?.description === void 0 ? {} : { description: meta3.description },
29921
+ kind,
29922
+ state: "awaiting-results",
29923
+ taskId: toolCallId,
29924
+ toolUseId: toolCallId
29925
+ });
29926
+ }
29713
29927
  }
29714
- for (const match of step.content.matchAll(TASK_RESULT_SENDER_PATTERN)) {
29715
- if (match[1]?.toLowerCase() === sessionId.toLowerCase() && match[2] !== void 0) {
29716
- received.add(match[2]);
29928
+ }
29929
+ const consumedReceived = /* @__PURE__ */ new Set();
29930
+ const unboundOwed = [];
29931
+ for (const toolCallId of [...session.wakeupOwedToolCallIds]) {
29932
+ const nativeTaskId = correlation.nativeTaskIdByToolCallId.get(toolCallId);
29933
+ if (nativeTaskId !== void 0) {
29934
+ if (correlation.deliveredNativeTaskIds.has(nativeTaskId)) {
29935
+ session.wakeupOwedToolCallIds.delete(toolCallId);
29936
+ consumedReceived.add(nativeTaskId);
29717
29937
  }
29938
+ } else {
29939
+ unboundOwed.push(toolCallId);
29940
+ }
29941
+ }
29942
+ if (unboundOwed.length > 0) {
29943
+ let unmatchedReceived = 0;
29944
+ for (const nativeTaskId of received) {
29945
+ if (!consumedReceived.has(nativeTaskId) && !correlation.daemonNativeTaskIds.has(nativeTaskId) && !correlation.toolCallIdByNativeTaskId.has(nativeTaskId)) {
29946
+ unmatchedReceived += 1;
29947
+ }
29948
+ }
29949
+ for (const toolCallId of unboundOwed.slice(0, unmatchedReceived)) {
29950
+ session.wakeupOwedToolCallIds.delete(toolCallId);
29718
29951
  }
29719
29952
  }
29720
- session.wakeupPendingTaskResults = Math.max(0, session.wakeupPendingTaskResults - received.size);
29721
- return session.wakeupPendingTaskResults === 0;
29953
+ this.#pruneInactiveCandidates(session);
29954
+ return session.wakeupOwedToolCallIds.size === 0;
29722
29955
  };
29723
29956
  #handleWakeupTimeout = async (sessionId, generation, stageEpoch, message) => {
29724
29957
  if (this.#disposed) {
@@ -29751,6 +29984,7 @@ var AntigravityBackgroundWakeup = class {
29751
29984
  }
29752
29985
  if (tail !== null) {
29753
29986
  this.#syncSubagentCreations(current, tail.steps);
29987
+ this.#syncBackgroundTaskCreations(sessionId, current, tail.steps);
29754
29988
  }
29755
29989
  if (tail?.settledStepIndex !== null && tail?.settledStepIndex !== void 0) {
29756
29990
  this.#settleWakeupReply(sessionId, current, tail, tail.settledStepIndex);
@@ -29815,7 +30049,7 @@ var AntigravityBackgroundWakeup = class {
29815
30049
  const meta3 = inspectToolMetadata(update, session.toolMetadata.get(toolCallId));
29816
30050
  session.toolMetadata.set(toolCallId, meta3);
29817
30051
  if (meta3.isDaemon) {
29818
- session.backgroundTasks.delete(toolCallId);
30052
+ this.#deleteBackgroundTask(session, toolCallId);
29819
30053
  return;
29820
30054
  }
29821
30055
  if (meta3.category === "manage-subagents" && status === "completed") {
@@ -29834,6 +30068,7 @@ var AntigravityBackgroundWakeup = class {
29834
30068
  return;
29835
30069
  }
29836
30070
  if (!cancelled && status === "in_progress") {
30071
+ this.#recordBackgroundCandidate(session, toolCallId, meta3);
29837
30072
  session.backgroundTasks.set(toolCallId, {
29838
30073
  ...meta3.description === void 0 ? {} : { description: meta3.description },
29839
30074
  kind,
@@ -29845,6 +30080,9 @@ var AntigravityBackgroundWakeup = class {
29845
30080
  }
29846
30081
  if (status === "pending" || status === "completed" || status === "failed" || status === "cancelled") {
29847
30082
  session.backgroundTasks.delete(toolCallId);
30083
+ if (status !== "pending") {
30084
+ this.#removeBackgroundCandidate(session, toolCallId);
30085
+ }
29848
30086
  }
29849
30087
  };
29850
30088
  #applyWakeupToolUpdate = async (sessionId, session, update, notifications) => {
@@ -29863,7 +30101,7 @@ var AntigravityBackgroundWakeup = class {
29863
30101
  if (trackedExisting !== void 0) {
29864
30102
  if (status === "completed") {
29865
30103
  if (trackedExisting.kind !== "subagent" && trackedExisting.state !== "awaiting-results") {
29866
- session.wakeupPendingTaskResults += 1;
30104
+ session.wakeupOwedToolCallIds.add(toolCallId);
29867
30105
  }
29868
30106
  session.backgroundTasks.set(toolCallId, { ...trackedExisting, state: "awaiting-results" });
29869
30107
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
@@ -29882,7 +30120,7 @@ var AntigravityBackgroundWakeup = class {
29882
30120
  if (trackedExisting.kind === "subagent") {
29883
30121
  this.#deleteSubagentTask(session, toolCallId);
29884
30122
  } else {
29885
- session.backgroundTasks.delete(toolCallId);
30123
+ this.#deleteBackgroundTask(session, toolCallId);
29886
30124
  }
29887
30125
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
29888
30126
  if (bg2 !== null) {
@@ -29892,6 +30130,7 @@ var AntigravityBackgroundWakeup = class {
29892
30130
  return;
29893
30131
  }
29894
30132
  if (meta3.isDaemon) {
30133
+ this.#removeBackgroundCandidate(session, toolCallId);
29895
30134
  if (session.phase.openToolIds.has(toolCallId)) {
29896
30135
  const nextOpenToolIds = new Set(session.phase.openToolIds);
29897
30136
  nextOpenToolIds.delete(toolCallId);
@@ -29900,6 +30139,7 @@ var AntigravityBackgroundWakeup = class {
29900
30139
  return;
29901
30140
  }
29902
30141
  if (updateKind === "tool_call" && (status === "in_progress" || status === "pending")) {
30142
+ this.#recordBackgroundCandidate(session, toolCallId, meta3);
29903
30143
  if (!session.phase.openToolIds.has(toolCallId)) {
29904
30144
  const nextOpenToolIds = new Set(session.phase.openToolIds);
29905
30145
  nextOpenToolIds.add(toolCallId);
@@ -29908,12 +30148,24 @@ var AntigravityBackgroundWakeup = class {
29908
30148
  this.#pauseOrResumeWakeupTimers(sessionId, session);
29909
30149
  return;
29910
30150
  }
30151
+ if (status === "in_progress" || status === "pending") {
30152
+ this.#recordBackgroundCandidate(session, toolCallId, meta3);
30153
+ return;
30154
+ }
29911
30155
  if (status === "completed" || status === "failed" || status === "cancelled") {
29912
- if (session.phase.openToolIds.has(toolCallId)) {
30156
+ const wasOpenTool = session.phase.openToolIds.has(toolCallId);
30157
+ if (wasOpenTool) {
29913
30158
  const nextOpenToolIds = new Set(session.phase.openToolIds);
29914
30159
  nextOpenToolIds.delete(toolCallId);
29915
30160
  session.phase = { ...session.phase, openToolIds: nextOpenToolIds };
29916
30161
  }
30162
+ const kind = backgroundKindFor(meta3.category);
30163
+ if (wasOpenTool && status === "completed" && (kind === "shell" || kind === "other")) {
30164
+ this.#recordBackgroundCandidate(session, toolCallId, meta3);
30165
+ session.wakeupCompletedOpenBgCandidates.add(toolCallId);
30166
+ } else if (status === "failed" || status === "cancelled") {
30167
+ this.#removeBackgroundCandidate(session, toolCallId);
30168
+ }
29917
30169
  if (meta3.category === "subagent" && status === "completed") {
29918
30170
  this.#registerSubagentTask(session, toolCallId, meta3.description);
29919
30171
  await this.#syncPendingSubagentCreations(sessionId, session);
@@ -30020,6 +30272,7 @@ var AntigravityBackgroundWakeup = class {
30020
30272
  if (tail2 !== null) {
30021
30273
  session2.baselineStepIndex = Math.max(session2.baselineStepIndex, tail2.maxStepIndex);
30022
30274
  session2.sessionOpenStepIndex = Math.max(session2.sessionOpenStepIndex, tail2.maxStepIndex);
30275
+ this.#syncBackgroundTaskCreations(tracked.sessionId, session2, tail2.steps);
30023
30276
  }
30024
30277
  if (tracked.kind === "load") {
30025
30278
  session2.phase = { cancelRequested: false, kind: "idle" };
@@ -30037,6 +30290,16 @@ var AntigravityBackgroundWakeup = class {
30037
30290
  if (tail !== null) {
30038
30291
  session2.baselineStepIndex = Math.max(session2.baselineStepIndex, tail.maxStepIndex);
30039
30292
  this.#syncSubagentCreations(session2, tail.steps);
30293
+ this.#syncBackgroundTaskCreations(tracked.sessionId, session2, tail.steps);
30294
+ for (const nativeTaskId of extractTaskResultSenderIds(
30295
+ tracked.sessionId,
30296
+ tail.steps,
30297
+ prePromptStepIndex,
30298
+ session2.baselineStepIndex
30299
+ )) {
30300
+ session2.backgroundCorrelation.deliveredNativeTaskIds.add(nativeTaskId);
30301
+ }
30302
+ this.#pruneInactiveCandidates(session2);
30040
30303
  if (!promptCancelled) {
30041
30304
  let lastPlannerStepIndex;
30042
30305
  for (let index2 = tail.steps.length - 1; index2 >= 0; index2 -= 1) {
@@ -30101,7 +30364,7 @@ var AntigravityBackgroundWakeup = class {
30101
30364
  if (existing.kind === "subagent") {
30102
30365
  this.#deleteSubagentTask(session, toolCallId);
30103
30366
  } else {
30104
- session.backgroundTasks.delete(toolCallId);
30367
+ this.#deleteBackgroundTask(session, toolCallId);
30105
30368
  }
30106
30369
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
30107
30370
  return bg2 === null ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [bg2], beforeUpdates: [] };
@@ -30111,7 +30374,7 @@ var AntigravityBackgroundWakeup = class {
30111
30374
  if (existing.kind === "subagent") {
30112
30375
  this.#deleteSubagentTask(session, toolCallId);
30113
30376
  } else {
30114
- session.backgroundTasks.delete(toolCallId);
30377
+ this.#deleteBackgroundTask(session, toolCallId);
30115
30378
  }
30116
30379
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
30117
30380
  return bg2 === null ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [bg2], beforeUpdates: [] };
@@ -96763,7 +97026,13 @@ var AgentSession = class _AgentSession {
96763
97026
  const messageId = result._meta?.messageId;
96764
97027
  const completion = { ...messageId === void 0 ? {} : { messageId }, stopReason: result.stopReason };
96765
97028
  if (result.stopReason !== "cancelled" && this.#recordedBackground.length > 0) {
96766
- this.#hold(options.commandId, lifecycle.attemptId, completion);
97029
+ this.#hold(
97030
+ options.commandId,
97031
+ lifecycle.attemptId,
97032
+ completion,
97033
+ { kind: "all-background" },
97034
+ void 0
97035
+ );
96767
97036
  } else {
96768
97037
  await this.recordLifecycleEvent({
96769
97038
  payload: { commandId: options.commandId, kind: "prompt.completed", ...completion },
@@ -97043,20 +97312,35 @@ var AgentSession = class _AgentSession {
97043
97312
  this.#getObserver().onAgentTurn?.(this.#mobiusSessionId, null);
97044
97313
  };
97045
97314
  /** Keeps a command whose reply ended open for the background work still outstanding (see HeldCommand). */
97046
- #hold = (commandId, attemptId, completion) => {
97315
+ #hold = (commandId, attemptId, completion, scope, continues) => {
97047
97316
  this.#held = {
97048
97317
  attemptId,
97049
97318
  cancelled: false,
97050
97319
  commandId,
97051
97320
  completion,
97321
+ continues,
97052
97322
  limit: this.#timer.schedule(() => {
97053
97323
  void this.#releaseHeld().catch((error62) => {
97054
97324
  console.error("Mobius daemon could not end a command held for background work", error62);
97055
97325
  });
97056
- }, BACKGROUND_HOLD_LIMIT_MILLISECONDS)
97326
+ }, BACKGROUND_HOLD_LIMIT_MILLISECONDS),
97327
+ scope
97057
97328
  };
97058
97329
  this.#getObserver().onAgentTurn?.(this.#mobiusSessionId, commandId);
97059
97330
  };
97331
+ #heldHasRemainingWork = (held) => {
97332
+ const scope = held.scope;
97333
+ switch (scope.kind) {
97334
+ case "all-background":
97335
+ return this.#recordedBackground.length > 0;
97336
+ case "started-tasks":
97337
+ return this.#recordedBackground.some((task) => scope.taskIds.has(task.taskId));
97338
+ default: {
97339
+ const unreachable2 = scope;
97340
+ throw new AcpExecutionError("Unexpected held command scope", { cause: unreachable2 });
97341
+ }
97342
+ }
97343
+ };
97060
97344
  /**
97061
97345
  * Records the end of the held command, if one is open: how its reply ended, unless it was stopped or `failure`
97062
97346
  * says its continuation failed. The Agent's continuation of it, if one runs, belongs to nothing after this.
@@ -97085,7 +97369,7 @@ var AgentSession = class _AgentSession {
97085
97369
  };
97086
97370
  /** Ends the held command once no background work is outstanding and no continuation of it is running. */
97087
97371
  #releaseHeldIfDone = async () => {
97088
- if (this.#held !== null && this.#agentTurn === null && this.#recordedBackground.length === 0) {
97372
+ if (this.#held !== null && this.#agentTurn === null && !this.#heldHasRemainingWork(this.#held)) {
97089
97373
  await this.#releaseHeld();
97090
97374
  }
97091
97375
  };
@@ -97122,14 +97406,20 @@ var AgentSession = class _AgentSession {
97122
97406
  }
97123
97407
  const held = this.#held;
97124
97408
  if (held !== null) {
97125
- this.#agentTurn = {
97126
- attemptId: held.attemptId,
97127
- cancelled: false,
97128
- commandId: held.commandId,
97129
- continues: void 0,
97130
- held: true
97131
- };
97132
- return;
97409
+ const heldScope = held.scope;
97410
+ if (heldScope.kind === "started-tasks" && report.taskIds.length > 0 && report.taskIds.every((taskId) => !heldScope.taskIds.has(taskId))) {
97411
+ await this.#releaseHeld();
97412
+ } else {
97413
+ this.#agentTurn = {
97414
+ attemptId: held.attemptId,
97415
+ cancelled: false,
97416
+ commandId: held.commandId,
97417
+ continues: held.continues,
97418
+ held: true,
97419
+ startedTaskIds: /* @__PURE__ */ new Set()
97420
+ };
97421
+ return;
97422
+ }
97133
97423
  }
97134
97424
  const continues = report.taskIds.flatMap((taskId) => {
97135
97425
  const commandId = this.#backgroundTaskCommands.get(taskId);
@@ -97140,7 +97430,8 @@ var AgentSession = class _AgentSession {
97140
97430
  cancelled: false,
97141
97431
  commandId: `agent-${randomUUID15()}`,
97142
97432
  continues,
97143
- held: false
97433
+ held: false,
97434
+ startedTaskIds: /* @__PURE__ */ new Set()
97144
97435
  };
97145
97436
  this.#agentTurn = agentTurn;
97146
97437
  await this.recordLifecycleEvent({
@@ -97176,6 +97467,21 @@ var AgentSession = class _AgentSession {
97176
97467
  await this.#releaseHeldIfDone();
97177
97468
  return;
97178
97469
  }
97470
+ if (!agentTurn.cancelled && report.stopReason !== "cancelled") {
97471
+ const remainingStarted = new Set(
97472
+ this.#recordedBackground.map((task) => task.taskId).filter((taskId) => agentTurn.startedTaskIds.has(taskId))
97473
+ );
97474
+ if (remainingStarted.size > 0) {
97475
+ this.#hold(
97476
+ agentTurn.commandId,
97477
+ agentTurn.attemptId,
97478
+ { stopReason: report.stopReason },
97479
+ { kind: "started-tasks", taskIds: remainingStarted },
97480
+ agentTurn.continues
97481
+ );
97482
+ return;
97483
+ }
97484
+ }
97179
97485
  await this.recordLifecycleEvent({
97180
97486
  payload: {
97181
97487
  commandId: agentTurn.commandId,
@@ -97203,13 +97509,18 @@ var AgentSession = class _AgentSession {
97203
97509
  */
97204
97510
  #recordBackgroundTasks = async (reports) => {
97205
97511
  const owner = this.#agentCommand() ?? this.#agentTurn?.continues ?? this.#lastClientCommandId;
97512
+ const previousTaskIds = new Set(this.#recordedBackground.map((task) => task.taskId));
97206
97513
  const current = new Set(reports.map((report) => report.taskId));
97207
97514
  for (const taskId of this.#backgroundTaskCommands.keys()) {
97208
97515
  if (!current.has(taskId)) {
97209
97516
  this.#backgroundTaskCommands.delete(taskId);
97210
97517
  }
97211
97518
  }
97519
+ const addedTaskIds = [];
97212
97520
  const tasks = reports.slice(0, SESSION_BACKGROUND_TASK_MAX_COUNT).map((report) => {
97521
+ if (!previousTaskIds.has(report.taskId)) {
97522
+ addedTaskIds.push(report.taskId);
97523
+ }
97213
97524
  if (owner !== void 0 && !this.#backgroundTaskCommands.has(report.taskId)) {
97214
97525
  this.#backgroundTaskCommands.set(report.taskId, owner);
97215
97526
  }
@@ -97223,6 +97534,21 @@ var AgentSession = class _AgentSession {
97223
97534
  ...report.description === void 0 ? {} : { description: truncate(report.description, 500) }
97224
97535
  };
97225
97536
  });
97537
+ if (addedTaskIds.length > 0) {
97538
+ if (this.#agentTurn !== null && !this.#agentTurn.held) {
97539
+ for (const taskId of addedTaskIds) {
97540
+ this.#agentTurn.startedTaskIds.add(taskId);
97541
+ }
97542
+ } else if (this.#agentTurn?.held === true && this.#held !== null && this.#held.scope.kind === "started-tasks") {
97543
+ this.#held = {
97544
+ ...this.#held,
97545
+ scope: {
97546
+ kind: "started-tasks",
97547
+ taskIds: /* @__PURE__ */ new Set([...this.#held.scope.taskIds, ...addedTaskIds])
97548
+ }
97549
+ };
97550
+ }
97551
+ }
97226
97552
  if (JSON.stringify(tasks) === JSON.stringify(this.#recordedBackground)) {
97227
97553
  return;
97228
97554
  }
@@ -104852,4 +105178,4 @@ export {
104852
105178
  * MIT Licensed
104853
105179
  *)
104854
105180
  */
104855
- //# sourceMappingURL=chunk-TDFSYA4U.js.map
105181
+ //# sourceMappingURL=chunk-KVFXX7GF.js.map