@moxt-ai/mobius 0.0.457 → 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-SWSQPASF.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({
@@ -2768,18 +2768,18 @@ var validateAsync = async (schema, value, _ctx) => {
2768
2768
  return result.issues.length === 0;
2769
2769
  };
2770
2770
  var _encode = (_Err) => {
2771
- const parse5 = _parse(_Err);
2771
+ const parse6 = _parse(_Err);
2772
2772
  const fn2 = (schema, value, _ctx, _params) => {
2773
2773
  const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
2774
- return parse5(schema, value, ctx, finalizeParams(fn2, _params));
2774
+ return parse6(schema, value, ctx, finalizeParams(fn2, _params));
2775
2775
  };
2776
2776
  return fn2;
2777
2777
  };
2778
2778
  var encode = /* @__PURE__ */ _encode($ZodRealError);
2779
2779
  var _decode = (_Err) => {
2780
- const parse5 = _parse(_Err);
2780
+ const parse6 = _parse(_Err);
2781
2781
  const fn2 = (schema, value, _ctx, _params) => {
2782
- return parse5(schema, value, _ctx, finalizeParams(fn2, _params));
2782
+ return parse6(schema, value, _ctx, finalizeParams(fn2, _params));
2783
2783
  };
2784
2784
  return fn2;
2785
2785
  };
@@ -4274,7 +4274,7 @@ function capSize(inst, size) {
4274
4274
  if (!caps.length)
4275
4275
  return;
4276
4276
  const cap = Math.min(...caps.map((c) => c[0]));
4277
- const parse5 = inst._zod.parse;
4277
+ const parse6 = inst._zod.parse;
4278
4278
  inst._zod.parse = (payload, ctx) => {
4279
4279
  const n = size(payload.value);
4280
4280
  if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
@@ -4288,7 +4288,7 @@ function capSize(inst, size) {
4288
4288
  }
4289
4289
  }
4290
4290
  }
4291
- return parse5(payload, ctx);
4291
+ return parse6(payload, ctx);
4292
4292
  };
4293
4293
  }
4294
4294
  var arraySize = (input2) => Array.isArray(input2) ? input2.length : -1;
@@ -26708,13 +26708,13 @@ var ConnectionBuilder = class {
26708
26708
  /**
26709
26709
  * Adds a typed request handler for one method.
26710
26710
  */
26711
- onReceiveRequest(method, parse5, handler) {
26711
+ onReceiveRequest(method, parse6, handler) {
26712
26712
  return this.withHandler({
26713
26713
  handleMessage: async (message, cx2) => {
26714
26714
  if (message.kind !== "request" || message.method !== method) {
26715
26715
  return Handled.no(message);
26716
26716
  }
26717
- const request = parse5(message.params);
26717
+ const request = parse6(message.params);
26718
26718
  return await handler(request, message.responder, cx2) ?? Handled.yes();
26719
26719
  },
26720
26720
  describe: () => `${this.connectionName ?? "request"}:${method}`
@@ -26723,13 +26723,13 @@ var ConnectionBuilder = class {
26723
26723
  /**
26724
26724
  * Adds a typed notification handler for one method.
26725
26725
  */
26726
- onReceiveNotification(method, parse5, handler) {
26726
+ onReceiveNotification(method, parse6, handler) {
26727
26727
  return this.withHandler({
26728
26728
  handleMessage: async (message, cx2) => {
26729
26729
  if (message.kind !== "notification" || message.method !== method) {
26730
26730
  return Handled.no(message);
26731
26731
  }
26732
- const notification = parse5(message.params);
26732
+ const notification = parse6(message.params);
26733
26733
  return await handler(notification, cx2) ?? Handled.yes();
26734
26734
  },
26735
26735
  describe: () => `${this.connectionName ?? "notification"}:${method}`
@@ -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
+ }
29927
+ }
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);
29937
+ }
29938
+ } else {
29939
+ unboundOwed.push(toolCallId);
29713
29940
  }
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]);
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;
29717
29947
  }
29718
29948
  }
29949
+ for (const toolCallId of unboundOwed.slice(0, unmatchedReceived)) {
29950
+ session.wakeupOwedToolCallIds.delete(toolCallId);
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: [] };
@@ -71840,6 +72103,7 @@ var ClaudeAcpAgent = class {
71840
72103
  const backgroundTasks = /* @__PURE__ */ new Set();
71841
72104
  const awaitingBackgroundResults = /* @__PURE__ */ new Set();
71842
72105
  let processingBackgroundResults = /* @__PURE__ */ new Set();
72106
+ const deliveredBackgroundResults = /* @__PURE__ */ new Set();
71843
72107
  const backgroundTaskDetails = /* @__PURE__ */ new Map();
71844
72108
  let publishedBackgroundTasks = "[]";
71845
72109
  let hasBackgroundLevel = false;
@@ -72009,6 +72273,16 @@ var ClaudeAcpAgent = class {
72009
72273
  }
72010
72274
  };
72011
72275
  const findUnsettledTurn = (uuid3) => (session.turnQueue ?? []).find((t) => t.promptUuid === uuid3 && !t.settled);
72276
+ const deliveredTaskResults = (message) => {
72277
+ if (!("isReplay" in message) || message.isReplay !== true || message.parent_tool_use_id !== null) {
72278
+ return [];
72279
+ }
72280
+ const notification = message.origin === void 0 ? findUnsettledTurn(message.uuid) === void 0 : isTaskNotificationOrigin(message.origin);
72281
+ if (!notification) {
72282
+ return [];
72283
+ }
72284
+ return parseTaskNotifications(message.message.content, message.uuid).map((task) => task.id).filter((id) => awaitingBackgroundResults.has(id) || backgroundTasks.has(id));
72285
+ };
72012
72286
  const firstUnsettledQueuedTurn = () => (session.turnQueue ?? []).find((t) => !t.settled);
72013
72287
  const publishBackgroundTasks = async () => {
72014
72288
  const report = (taskId, state) => {
@@ -72084,6 +72358,7 @@ var ClaudeAcpAgent = class {
72084
72358
  backgroundTasks.clear();
72085
72359
  awaitingBackgroundResults.clear();
72086
72360
  processingBackgroundResults.clear();
72361
+ deliveredBackgroundResults.clear();
72087
72362
  backgroundTaskDetails.clear();
72088
72363
  try {
72089
72364
  await publishBackgroundTasks();
@@ -72899,14 +73174,22 @@ ${message.api_refusal_explanation}` : "";
72899
73174
  }
72900
73175
  }
72901
73176
  } finally {
73177
+ const handled = [...deliveredBackgroundResults];
73178
+ deliveredBackgroundResults.clear();
73179
+ for (const id of handled) {
73180
+ backgroundTasks.delete(id);
73181
+ }
72902
73182
  if (message.origin?.kind === "task-notification") {
72903
- for (const id of processingBackgroundResults) {
72904
- awaitingBackgroundResults.delete(id);
72905
- if (!backgroundTasks.has(id)) {
72906
- backgroundTaskDetails.delete(id);
72907
- }
72908
- }
73183
+ handled.push(...processingBackgroundResults);
72909
73184
  processingBackgroundResults.clear();
73185
+ }
73186
+ for (const id of handled) {
73187
+ awaitingBackgroundResults.delete(id);
73188
+ if (!backgroundTasks.has(id)) {
73189
+ backgroundTaskDetails.delete(id);
73190
+ }
73191
+ }
73192
+ if (handled.length > 0 || message.origin?.kind === "task-notification") {
72910
73193
  reportBackgroundActivity();
72911
73194
  }
72912
73195
  if (!isAutonomousResult) {
@@ -72996,6 +73279,11 @@ ${message.api_refusal_explanation}` : "";
72996
73279
  }
72997
73280
  case "user":
72998
73281
  case "assistant": {
73282
+ if (message.type === "user") {
73283
+ for (const id of deliveredTaskResults(message)) {
73284
+ deliveredBackgroundResults.add(id);
73285
+ }
73286
+ }
72999
73287
  if (message.type === "user" && isTaskNotificationOrigin(message.origin)) {
73000
73288
  const tasks = parseTaskNotifications(message.message.content, message.uuid ?? "unknown");
73001
73289
  for (const task of tasks) {
@@ -96738,7 +97026,13 @@ var AgentSession = class _AgentSession {
96738
97026
  const messageId = result._meta?.messageId;
96739
97027
  const completion = { ...messageId === void 0 ? {} : { messageId }, stopReason: result.stopReason };
96740
97028
  if (result.stopReason !== "cancelled" && this.#recordedBackground.length > 0) {
96741
- 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
+ );
96742
97036
  } else {
96743
97037
  await this.recordLifecycleEvent({
96744
97038
  payload: { commandId: options.commandId, kind: "prompt.completed", ...completion },
@@ -97018,20 +97312,35 @@ var AgentSession = class _AgentSession {
97018
97312
  this.#getObserver().onAgentTurn?.(this.#mobiusSessionId, null);
97019
97313
  };
97020
97314
  /** Keeps a command whose reply ended open for the background work still outstanding (see HeldCommand). */
97021
- #hold = (commandId, attemptId, completion) => {
97315
+ #hold = (commandId, attemptId, completion, scope, continues) => {
97022
97316
  this.#held = {
97023
97317
  attemptId,
97024
97318
  cancelled: false,
97025
97319
  commandId,
97026
97320
  completion,
97321
+ continues,
97027
97322
  limit: this.#timer.schedule(() => {
97028
97323
  void this.#releaseHeld().catch((error62) => {
97029
97324
  console.error("Mobius daemon could not end a command held for background work", error62);
97030
97325
  });
97031
- }, BACKGROUND_HOLD_LIMIT_MILLISECONDS)
97326
+ }, BACKGROUND_HOLD_LIMIT_MILLISECONDS),
97327
+ scope
97032
97328
  };
97033
97329
  this.#getObserver().onAgentTurn?.(this.#mobiusSessionId, commandId);
97034
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
+ };
97035
97344
  /**
97036
97345
  * Records the end of the held command, if one is open: how its reply ended, unless it was stopped or `failure`
97037
97346
  * says its continuation failed. The Agent's continuation of it, if one runs, belongs to nothing after this.
@@ -97060,7 +97369,7 @@ var AgentSession = class _AgentSession {
97060
97369
  };
97061
97370
  /** Ends the held command once no background work is outstanding and no continuation of it is running. */
97062
97371
  #releaseHeldIfDone = async () => {
97063
- if (this.#held !== null && this.#agentTurn === null && this.#recordedBackground.length === 0) {
97372
+ if (this.#held !== null && this.#agentTurn === null && !this.#heldHasRemainingWork(this.#held)) {
97064
97373
  await this.#releaseHeld();
97065
97374
  }
97066
97375
  };
@@ -97097,14 +97406,20 @@ var AgentSession = class _AgentSession {
97097
97406
  }
97098
97407
  const held = this.#held;
97099
97408
  if (held !== null) {
97100
- this.#agentTurn = {
97101
- attemptId: held.attemptId,
97102
- cancelled: false,
97103
- commandId: held.commandId,
97104
- continues: void 0,
97105
- held: true
97106
- };
97107
- 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
+ }
97108
97423
  }
97109
97424
  const continues = report.taskIds.flatMap((taskId) => {
97110
97425
  const commandId = this.#backgroundTaskCommands.get(taskId);
@@ -97115,7 +97430,8 @@ var AgentSession = class _AgentSession {
97115
97430
  cancelled: false,
97116
97431
  commandId: `agent-${randomUUID15()}`,
97117
97432
  continues,
97118
- held: false
97433
+ held: false,
97434
+ startedTaskIds: /* @__PURE__ */ new Set()
97119
97435
  };
97120
97436
  this.#agentTurn = agentTurn;
97121
97437
  await this.recordLifecycleEvent({
@@ -97151,6 +97467,21 @@ var AgentSession = class _AgentSession {
97151
97467
  await this.#releaseHeldIfDone();
97152
97468
  return;
97153
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
+ }
97154
97485
  await this.recordLifecycleEvent({
97155
97486
  payload: {
97156
97487
  commandId: agentTurn.commandId,
@@ -97178,13 +97509,18 @@ var AgentSession = class _AgentSession {
97178
97509
  */
97179
97510
  #recordBackgroundTasks = async (reports) => {
97180
97511
  const owner = this.#agentCommand() ?? this.#agentTurn?.continues ?? this.#lastClientCommandId;
97512
+ const previousTaskIds = new Set(this.#recordedBackground.map((task) => task.taskId));
97181
97513
  const current = new Set(reports.map((report) => report.taskId));
97182
97514
  for (const taskId of this.#backgroundTaskCommands.keys()) {
97183
97515
  if (!current.has(taskId)) {
97184
97516
  this.#backgroundTaskCommands.delete(taskId);
97185
97517
  }
97186
97518
  }
97519
+ const addedTaskIds = [];
97187
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
+ }
97188
97524
  if (owner !== void 0 && !this.#backgroundTaskCommands.has(report.taskId)) {
97189
97525
  this.#backgroundTaskCommands.set(report.taskId, owner);
97190
97526
  }
@@ -97198,6 +97534,21 @@ var AgentSession = class _AgentSession {
97198
97534
  ...report.description === void 0 ? {} : { description: truncate(report.description, 500) }
97199
97535
  };
97200
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
+ }
97201
97552
  if (JSON.stringify(tasks) === JSON.stringify(this.#recordedBackground)) {
97202
97553
  return;
97203
97554
  }
@@ -101643,7 +101994,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
101643
101994
  var import_ignore = __toESM(require_ignore(), 1);
101644
101995
  import { constants as constants6 } from "node:fs";
101645
101996
  import { lstat as lstat5, open as open6, readdir as readdir7, realpath as realpath8 } from "node:fs/promises";
101646
- import { dirname as dirname12, isAbsolute as isAbsolute17, join as join34, relative as relative4, sep as sep6 } from "node:path";
101997
+ import { dirname as dirname12, isAbsolute as isAbsolute17, join as join34, parse as parse5, relative as relative4, sep as sep6 } from "node:path";
101647
101998
  var MAXIMUM_NAME_LENGTH = 255;
101648
101999
  var MAXIMUM_PATH_LENGTH = 1024;
101649
102000
  var MAXIMUM_IGNORE_FILE_BYTES = 1024 * 1024;
@@ -101680,7 +102031,7 @@ async function listResolvedDirectory(root, resolved, offset, limit, signal, time
101680
102031
  let task;
101681
102032
  const deadline = new AbortController();
101682
102033
  try {
101683
- const ancestry = await recordAncestry(root, resolved);
102034
+ const ancestry = await recordAncestry(resolved);
101684
102035
  signal.throwIfAborted();
101685
102036
  task = timer.schedule(
101686
102037
  () => deadline.abort(new DOMException("Reading the workspace directory timed out", "TimeoutError")),
@@ -101831,8 +102182,8 @@ async function openValidatedDirectory(resolved) {
101831
102182
  throw cause;
101832
102183
  }
101833
102184
  }
101834
- async function recordAncestry(root, resolved) {
101835
- const top = dirname12(root);
102185
+ async function recordAncestry(resolved) {
102186
+ const top = parse5(resolved.path).root;
101836
102187
  const below = relative4(top, resolved.path);
101837
102188
  const paths = [top];
101838
102189
  for (const segment of below === "" ? [] : below.split(sep6)) {
@@ -101852,9 +102203,10 @@ async function verifyAncestryUnchanged(ancestry, resolved, handle) {
101852
102203
  if (!sameDirectory(resolved, await handle.stat({ bigint: true }))) {
101853
102204
  throw directoryChanged();
101854
102205
  }
101855
- for (const before of ancestry) {
102206
+ for (const [index2, before] of ancestry.entries()) {
101856
102207
  const after = await ancestorState(before.path);
101857
- if (after.device !== before.device || after.inode !== before.inode || after.changedAt !== before.changedAt || after.modifiedAt !== before.modifiedAt) {
102208
+ const holdsNext = index2 < ancestry.length - 1;
102209
+ if (after.device !== before.device || after.inode !== before.inode || holdsNext && (after.changedAt !== before.changedAt || after.modifiedAt !== before.modifiedAt)) {
101858
102210
  throw directoryChanged();
101859
102211
  }
101860
102212
  }
@@ -104826,4 +105178,4 @@ export {
104826
105178
  * MIT Licensed
104827
105179
  *)
104828
105180
  */
104829
- //# sourceMappingURL=chunk-VDTIJC4T.js.map
105181
+ //# sourceMappingURL=chunk-KVFXX7GF.js.map