@moxt-ai/mobius 0.0.453 → 0.0.454

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.
@@ -3,7 +3,7 @@ import {
3
3
  __export,
4
4
  __using,
5
5
  package_default
6
- } from "./chunk-2Q5CQHJI.js";
6
+ } from "./chunk-TOQQNYQU.js";
7
7
 
8
8
  // src/engine/runtime/relay/runtime-revocation.ts
9
9
  var runtimeRevocationCloseCode = 1008;
@@ -28014,11 +28014,13 @@ var systemTimer = new SystemTimer();
28014
28014
  // src/engine/acp/adapter/antigravity/background-wakeup.ts
28015
28015
  var TRANSCRIPT_TAIL_BYTES = 65536;
28016
28016
  var TRANSCRIPT_INITIAL_DELAY_MS = 40;
28017
- var TRANSCRIPT_RETRY_DELAY_MS = 150;
28018
- var WAKEUP_STREAM_FALLBACK_MS = 1500;
28019
- var WAKEUP_AWAITING_OUTPUT_MS = 6e4;
28017
+ var TRANSCRIPT_POLL_INTERVAL_MS = 150;
28018
+ var WAKEUP_INACTIVITY_TIMEOUT_MS = 3e5;
28020
28019
  var SESSION_UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
28021
- var SUBAGENT_IDLE_PATTERN = /\bSubagent [0-9a-f-]+ has gone idle\b/u;
28020
+ var SUBAGENT_CONVERSATION_ID_PATTERN = /"conversationId"\s*:\s*"([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"/giu;
28021
+ 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;
28022
+ var AGENT_EXECUTOR_ERROR_PATTERN = /^\s*⚠ agent executor error:\s*(.+?)\s*$/su;
28023
+ var SUBAGENT_CREATED_MARKER = "Created the following subagent";
28022
28024
  var MAXIMUM_TOOL_DESCRIPTION_CHARS = 500;
28023
28025
  var transcriptStepSchema = external_exports.object({
28024
28026
  content: external_exports.string().optional(),
@@ -28072,7 +28074,7 @@ async function readTranscriptTailState(launchEnvironment, sessionId, baselineSte
28072
28074
  return null;
28073
28075
  }
28074
28076
  if (tail.bytes.byteLength === 0) {
28075
- return { maxStepIndex: -1, settledWithoutToolCalls: false, steps: [] };
28077
+ return { maxStepIndex: -1, settledStepIndex: null, steps: [] };
28076
28078
  }
28077
28079
  const text2 = new TextDecoder().decode(tail.bytes);
28078
28080
  const lines = text2.split("\n");
@@ -28094,32 +28096,43 @@ async function readTranscriptTailState(launchEnvironment, sessionId, baselineSte
28094
28096
  steps.push(parsed.data);
28095
28097
  }
28096
28098
  }
28097
- const lastStep = steps.at(-1);
28098
- const maxStepIndex = lastStep?.step_index ?? -1;
28099
- const settledWithoutToolCalls = lastStep !== void 0 && lastStep.step_index > baselineStepIndex && lastStep.type === "PLANNER_RESPONSE" && lastStep.status === "DONE" && (lastStep.tool_calls === void 0 || lastStep.tool_calls.length === 0);
28100
- return { maxStepIndex, settledWithoutToolCalls, steps };
28099
+ steps.sort((left, right) => left.step_index - right.step_index);
28100
+ const maxStepIndex = steps.at(-1)?.step_index ?? -1;
28101
+ const settledStep = steps.find(
28102
+ (step) => step.step_index > baselineStepIndex && step.type === "PLANNER_RESPONSE" && step.status === "DONE" && (step.tool_calls === void 0 || step.tool_calls.length === 0)
28103
+ );
28104
+ return {
28105
+ maxStepIndex,
28106
+ settledStepIndex: settledStep?.step_index ?? null,
28107
+ steps
28108
+ };
28101
28109
  }
28102
- function countConsumedSubagentIdles(steps, afterStepIndex, throughStepIndex) {
28103
- const relevant = steps.filter((step) => step.step_index > afterStepIndex && step.step_index <= throughStepIndex);
28104
- let lastPlannerIndex = -1;
28105
- for (let index2 = relevant.length - 1; index2 >= 0; index2 -= 1) {
28106
- const step = relevant[index2];
28107
- if (step?.type === "PLANNER_RESPONSE") {
28108
- lastPlannerIndex = index2;
28109
- break;
28110
+ function extractUuidMatches(text2, pattern) {
28111
+ pattern.lastIndex = 0;
28112
+ const matches = [];
28113
+ for (const match of text2.matchAll(pattern)) {
28114
+ const captured = match[1]?.toLowerCase();
28115
+ if (captured !== void 0) {
28116
+ matches.push(captured);
28110
28117
  }
28111
28118
  }
28112
- if (lastPlannerIndex <= 0) {
28113
- return 0;
28119
+ return matches;
28120
+ }
28121
+ function extractExecutorError(updateKind, update) {
28122
+ if (updateKind !== "agent_message_chunk" && updateKind !== "agent_message") {
28123
+ return void 0;
28114
28124
  }
28115
- let count = 0;
28116
- for (let index2 = 0; index2 < lastPlannerIndex; index2 += 1) {
28117
- const step = relevant[index2];
28118
- if (step?.type === "SYSTEM_MESSAGE" && step.content !== void 0 && SUBAGENT_IDLE_PATTERN.test(step.content)) {
28119
- count += 1;
28120
- }
28125
+ const content = update["content"];
28126
+ if (!isRecord5(content) || content["type"] !== "text") {
28127
+ return void 0;
28121
28128
  }
28122
- return count;
28129
+ const text2 = readString3(content, "text");
28130
+ if (text2 === void 0) {
28131
+ return void 0;
28132
+ }
28133
+ const match = AGENT_EXECUTOR_ERROR_PATTERN.exec(text2);
28134
+ const message = match?.[1];
28135
+ return message === void 0 ? void 0 : truncate(message, MAXIMUM_TOOL_DESCRIPTION_CHARS);
28123
28136
  }
28124
28137
  function extractToolInputRecords(update) {
28125
28138
  const records = [];
@@ -28181,7 +28194,7 @@ function inspectToolMetadata(update, previous) {
28181
28194
  const inputs = extractToolInputRecords(update);
28182
28195
  const category = readToolCategory(update, inputs, previous);
28183
28196
  let isDaemon = previous?.isDaemon ?? false;
28184
- let subagentKillCount = previous?.subagentKillCount ?? 0;
28197
+ const subagentKillIds = new Set(previous?.subagentKillIds ?? []);
28185
28198
  let subagentKillAll = previous?.subagentKillAll ?? false;
28186
28199
  for (const record2 of inputs) {
28187
28200
  if (record2["IsDaemon"] === true) {
@@ -28196,7 +28209,14 @@ function inspectToolMetadata(update, previous) {
28196
28209
  if (action === "kill_all") {
28197
28210
  subagentKillAll = true;
28198
28211
  } else if (action === "kill" && Array.isArray(record2["ConversationIds"])) {
28199
- subagentKillCount = Math.max(subagentKillCount, record2["ConversationIds"].length);
28212
+ for (const rawId of record2["ConversationIds"]) {
28213
+ if (typeof rawId === "string") {
28214
+ const normalized = rawId.trim().toLowerCase();
28215
+ if (normalized.length > 0) {
28216
+ subagentKillIds.add(normalized);
28217
+ }
28218
+ }
28219
+ }
28200
28220
  }
28201
28221
  }
28202
28222
  }
@@ -28206,7 +28226,7 @@ function inspectToolMetadata(update, previous) {
28206
28226
  description: description === void 0 ? void 0 : truncate(description, MAXIMUM_TOOL_DESCRIPTION_CHARS),
28207
28227
  isDaemon,
28208
28228
  subagentKillAll,
28209
- subagentKillCount
28229
+ subagentKillIds: [...subagentKillIds]
28210
28230
  };
28211
28231
  }
28212
28232
  function backgroundKindFor(category) {
@@ -28270,8 +28290,16 @@ var AntigravityBackgroundWakeup = class {
28270
28290
  baselineStepIndex: -1,
28271
28291
  lastEmittedBackgroundKey: "[]",
28272
28292
  phase: { cancelRequested: false, kind: "idle" },
28293
+ sessionOpenStepIndex: -1,
28294
+ subagents: {
28295
+ boundCreationSteps: /* @__PURE__ */ new Set(),
28296
+ consumedIdleSteps: /* @__PURE__ */ new Set(),
28297
+ conversationIdByToolCallId: /* @__PURE__ */ new Map(),
28298
+ pendingToolCallIds: []
28299
+ },
28273
28300
  toolMetadata: /* @__PURE__ */ new Map(),
28274
- wakeupGeneration: 0
28301
+ wakeupGeneration: 0,
28302
+ wakeupStageSeq: 0
28275
28303
  };
28276
28304
  this.#sessions.set(sessionId, created);
28277
28305
  return created;
@@ -28283,12 +28311,14 @@ var AntigravityBackgroundWakeup = class {
28283
28311
  switch (phase.stage.kind) {
28284
28312
  case "awaiting-output":
28285
28313
  phase.stage.timeout.cancel();
28314
+ phase.stage.transcriptCheck.cancel();
28286
28315
  return;
28287
28316
  case "blocked-on-work":
28317
+ case "verifying-timeout":
28288
28318
  return;
28289
28319
  case "streaming":
28290
- phase.stage.transcriptCheck?.cancel();
28291
- phase.stage.fallbackTimeout.cancel();
28320
+ phase.stage.transcriptCheck.cancel();
28321
+ phase.stage.inactivityTimeout.cancel();
28292
28322
  return;
28293
28323
  default: {
28294
28324
  const unreachable2 = phase.stage;
@@ -28296,6 +28326,11 @@ var AntigravityBackgroundWakeup = class {
28296
28326
  }
28297
28327
  }
28298
28328
  };
28329
+ #emitNotifications = (notifications) => {
28330
+ for (const notification of notifications) {
28331
+ this.#emitMetaUpdate(notification);
28332
+ }
28333
+ };
28299
28334
  #takeBackgroundTasksUpdate = (sessionId, session) => {
28300
28335
  const tasks = [...session.backgroundTasks.values()];
28301
28336
  const serialized = JSON.stringify(tasks);
@@ -28305,26 +28340,48 @@ var AntigravityBackgroundWakeup = class {
28305
28340
  session.lastEmittedBackgroundKey = serialized;
28306
28341
  return makeMetaNotification(sessionId, BACKGROUND_TASKS_META, tasks);
28307
28342
  };
28308
- #removeSubagentTasks = (session, count) => {
28309
- if (count <= 0) {
28310
- return;
28343
+ #registerSubagentTask = (session, toolCallId, description) => {
28344
+ if (!session.backgroundTasks.has(toolCallId)) {
28345
+ session.backgroundTasks.set(toolCallId, {
28346
+ ...description === void 0 ? {} : { description },
28347
+ kind: "subagent",
28348
+ state: "running",
28349
+ taskId: toolCallId,
28350
+ toolUseId: toolCallId
28351
+ });
28311
28352
  }
28312
- let remaining = count;
28313
- for (const [taskId, task] of session.backgroundTasks) {
28314
- if (task.kind !== "subagent") {
28315
- continue;
28316
- }
28317
- session.backgroundTasks.delete(taskId);
28318
- remaining -= 1;
28319
- if (remaining === 0) {
28320
- break;
28353
+ if (!session.subagents.conversationIdByToolCallId.has(toolCallId) && !session.subagents.pendingToolCallIds.includes(toolCallId)) {
28354
+ session.subagents.pendingToolCallIds.push(toolCallId);
28355
+ }
28356
+ };
28357
+ #deleteSubagentTask = (session, toolCallId) => {
28358
+ session.backgroundTasks.delete(toolCallId);
28359
+ session.subagents.conversationIdByToolCallId.delete(toolCallId);
28360
+ const pendingIndex = session.subagents.pendingToolCallIds.indexOf(toolCallId);
28361
+ if (pendingIndex !== -1) {
28362
+ session.subagents.pendingToolCallIds.splice(pendingIndex, 1);
28363
+ }
28364
+ };
28365
+ #deleteAllSubagentTasks = (session) => {
28366
+ for (const [taskId, task] of [...session.backgroundTasks.entries()]) {
28367
+ if (task.kind === "subagent") {
28368
+ this.#deleteSubagentTask(session, taskId);
28321
28369
  }
28322
28370
  }
28323
28371
  };
28372
+ #clearAllBackgroundTasks = (session) => {
28373
+ session.backgroundTasks.clear();
28374
+ session.subagents.conversationIdByToolCallId.clear();
28375
+ session.subagents.pendingToolCallIds.length = 0;
28376
+ };
28324
28377
  #dropAwaitingResultTasks = (session) => {
28325
- for (const [taskId, task] of session.backgroundTasks) {
28378
+ for (const [taskId, task] of [...session.backgroundTasks.entries()]) {
28326
28379
  if (task.state === "awaiting-results") {
28327
- session.backgroundTasks.delete(taskId);
28380
+ if (task.kind === "subagent") {
28381
+ this.#deleteSubagentTask(session, taskId);
28382
+ } else {
28383
+ session.backgroundTasks.delete(taskId);
28384
+ }
28328
28385
  }
28329
28386
  }
28330
28387
  };
@@ -28336,49 +28393,183 @@ var AntigravityBackgroundWakeup = class {
28336
28393
  }
28337
28394
  return false;
28338
28395
  };
28339
- #oldestRunningSubagentId = (session) => {
28340
- for (const task of session.backgroundTasks.values()) {
28341
- if (task.kind === "subagent" && task.state === "running") {
28342
- return task.taskId;
28396
+ #syncSubagentCreations = (session, steps) => {
28397
+ if (session.subagents.pendingToolCallIds.length === 0) {
28398
+ return;
28399
+ }
28400
+ for (const step of steps) {
28401
+ if (step.step_index <= session.sessionOpenStepIndex || step.type !== "GENERIC" || step.status !== "DONE" || session.subagents.boundCreationSteps.has(step.step_index) || step.content === void 0 || !step.content.includes(SUBAGENT_CREATED_MARKER)) {
28402
+ continue;
28403
+ }
28404
+ const createdIds = extractUuidMatches(step.content, SUBAGENT_CONVERSATION_ID_PATTERN);
28405
+ if (createdIds.length === 0) {
28406
+ continue;
28407
+ }
28408
+ let boundAny = false;
28409
+ for (const conversationId of createdIds) {
28410
+ let nextToolCallId;
28411
+ while (session.subagents.pendingToolCallIds.length > 0) {
28412
+ const candidate = session.subagents.pendingToolCallIds.shift();
28413
+ if (candidate !== void 0 && session.backgroundTasks.has(candidate)) {
28414
+ nextToolCallId = candidate;
28415
+ break;
28416
+ }
28417
+ }
28418
+ if (nextToolCallId === void 0) {
28419
+ break;
28420
+ }
28421
+ session.subagents.conversationIdByToolCallId.set(nextToolCallId, conversationId);
28422
+ boundAny = true;
28423
+ }
28424
+ if (boundAny) {
28425
+ session.subagents.boundCreationSteps.add(step.step_index);
28426
+ }
28427
+ }
28428
+ };
28429
+ #findSubagentToolCallId = (session, conversationId) => {
28430
+ const targetId = conversationId.toLowerCase();
28431
+ for (const [toolCallId, mappedId] of session.subagents.conversationIdByToolCallId) {
28432
+ if (mappedId === targetId && session.backgroundTasks.has(toolCallId)) {
28433
+ return toolCallId;
28343
28434
  }
28344
28435
  }
28345
28436
  return void 0;
28346
28437
  };
28438
+ #processIdleSubagentMessages = (session, steps, maxStepExclusive, onMatchedToolCall) => {
28439
+ for (const step of steps) {
28440
+ if (step.step_index <= session.sessionOpenStepIndex || maxStepExclusive !== void 0 && step.step_index >= maxStepExclusive || step.type !== "SYSTEM_MESSAGE" || session.subagents.consumedIdleSteps.has(step.step_index) || step.content === void 0) {
28441
+ continue;
28442
+ }
28443
+ const idleIds = extractUuidMatches(step.content, SUBAGENT_IDLE_ID_PATTERN);
28444
+ if (idleIds.length === 0) {
28445
+ continue;
28446
+ }
28447
+ session.subagents.consumedIdleSteps.add(step.step_index);
28448
+ for (const conversationId of idleIds) {
28449
+ const toolCallId = this.#findSubagentToolCallId(session, conversationId);
28450
+ if (toolCallId !== void 0) {
28451
+ onMatchedToolCall(toolCallId);
28452
+ }
28453
+ }
28454
+ }
28455
+ };
28456
+ #markTriggeredSubagentIdles = (session, steps) => {
28457
+ const matched = /* @__PURE__ */ new Set();
28458
+ this.#processIdleSubagentMessages(session, steps, void 0, (toolCallId) => {
28459
+ const existing = session.backgroundTasks.get(toolCallId);
28460
+ if (existing !== void 0) {
28461
+ session.backgroundTasks.set(toolCallId, { ...existing, state: "awaiting-results" });
28462
+ matched.add(toolCallId);
28463
+ }
28464
+ });
28465
+ return [...matched];
28466
+ };
28467
+ #consumeSubagentIdlesThrough = (session, steps, plannerStepIndex) => {
28468
+ this.#processIdleSubagentMessages(session, steps, plannerStepIndex, (toolCallId) => {
28469
+ this.#deleteSubagentTask(session, toolCallId);
28470
+ });
28471
+ };
28472
+ #killSubagentsByMetadata = async (sessionId, session, meta3) => {
28473
+ if (meta3.subagentKillAll) {
28474
+ this.#deleteAllSubagentTasks(session);
28475
+ return true;
28476
+ }
28477
+ if (meta3.subagentKillIds.length === 0) {
28478
+ return true;
28479
+ }
28480
+ await this.#syncPendingSubagentCreations(sessionId, session);
28481
+ if (this.#disposed || this.#sessions.get(sessionId) !== session) {
28482
+ return false;
28483
+ }
28484
+ for (const conversationId of meta3.subagentKillIds) {
28485
+ const targetToolCallId = this.#findSubagentToolCallId(session, conversationId);
28486
+ if (targetToolCallId !== void 0) {
28487
+ this.#deleteSubagentTask(session, targetToolCallId);
28488
+ }
28489
+ }
28490
+ return true;
28491
+ };
28492
+ #syncPendingSubagentCreations = async (sessionId, session) => {
28493
+ if (session.subagents.pendingToolCallIds.length === 0) {
28494
+ return;
28495
+ }
28496
+ const tail = await readTranscriptTailState(this.#launchEnvironment, sessionId, session.baselineStepIndex);
28497
+ if (this.#disposed || this.#sessions.get(sessionId) !== session || tail === null) {
28498
+ return;
28499
+ }
28500
+ this.#syncSubagentCreations(session, tail.steps);
28501
+ };
28502
+ #scheduleTranscriptPoll = (sessionId, generation, stageEpoch, delayMs) => this.#timer.schedule(() => {
28503
+ void this.#checkWakeupTranscript(sessionId, generation, stageEpoch);
28504
+ }, delayMs);
28347
28505
  #setWakeupAwaitingOutput = (sessionId, session, generation, openToolIds) => {
28348
28506
  this.#cancelWakeupTimers(session.phase);
28507
+ session.wakeupStageSeq += 1;
28508
+ const stageEpoch = session.wakeupStageSeq;
28509
+ const transcriptCheck = this.#scheduleTranscriptPoll(
28510
+ sessionId,
28511
+ generation,
28512
+ stageEpoch,
28513
+ TRANSCRIPT_INITIAL_DELAY_MS
28514
+ );
28349
28515
  const timeout = this.#timer.schedule(() => {
28350
- this.#finishWakeupFromTimer(sessionId, generation, "end_turn");
28351
- }, WAKEUP_AWAITING_OUTPUT_MS);
28516
+ void this.#handleWakeupTimeout(
28517
+ sessionId,
28518
+ generation,
28519
+ stageEpoch,
28520
+ "Antigravity continuation timed out waiting for output"
28521
+ );
28522
+ }, WAKEUP_INACTIVITY_TIMEOUT_MS);
28352
28523
  session.phase = {
28353
28524
  generation,
28354
28525
  kind: "wakeup",
28355
28526
  openToolIds,
28356
- stage: { kind: "awaiting-output", timeout }
28527
+ stage: { kind: "awaiting-output", stageEpoch, timeout, transcriptCheck }
28357
28528
  };
28358
28529
  };
28359
28530
  #setWakeupBlockedOnWork = (session, generation, openToolIds) => {
28360
28531
  this.#cancelWakeupTimers(session.phase);
28532
+ session.wakeupStageSeq += 1;
28533
+ const stageEpoch = session.wakeupStageSeq;
28361
28534
  session.phase = {
28362
28535
  generation,
28363
28536
  kind: "wakeup",
28364
28537
  openToolIds,
28365
- stage: { kind: "blocked-on-work" }
28538
+ stage: { kind: "blocked-on-work", stageEpoch }
28366
28539
  };
28367
28540
  };
28368
- #setWakeupStreaming = (sessionId, session, generation, openToolIds) => {
28541
+ #setWakeupStreaming = (sessionId, session, generation, openToolIds, incomingExecutorError) => {
28542
+ const previousExecutorError = session.phase.kind === "wakeup" && session.phase.generation === generation && session.phase.stage.kind === "streaming" ? session.phase.stage.executorError : void 0;
28543
+ const executorError = incomingExecutorError ?? previousExecutorError;
28369
28544
  this.#cancelWakeupTimers(session.phase);
28370
- const scheduleTranscriptCheck = (delayMs, allowRetry) => this.#timer.schedule(() => {
28371
- void this.#checkWakeupTranscript(sessionId, generation, allowRetry);
28372
- }, delayMs);
28373
- const fallbackTimeout = this.#timer.schedule(() => {
28374
- this.#finishWakeupFromTimer(sessionId, generation, "end_turn");
28375
- }, WAKEUP_STREAM_FALLBACK_MS);
28376
- const transcriptCheck = scheduleTranscriptCheck(TRANSCRIPT_INITIAL_DELAY_MS, true);
28545
+ session.wakeupStageSeq += 1;
28546
+ const stageEpoch = session.wakeupStageSeq;
28547
+ const transcriptCheck = this.#scheduleTranscriptPoll(
28548
+ sessionId,
28549
+ generation,
28550
+ stageEpoch,
28551
+ TRANSCRIPT_INITIAL_DELAY_MS
28552
+ );
28553
+ const inactivityTimeout = this.#timer.schedule(() => {
28554
+ void this.#handleWakeupTimeout(
28555
+ sessionId,
28556
+ generation,
28557
+ stageEpoch,
28558
+ "Antigravity continuation timed out while streaming"
28559
+ );
28560
+ }, WAKEUP_INACTIVITY_TIMEOUT_MS);
28377
28561
  session.phase = {
28378
28562
  generation,
28379
28563
  kind: "wakeup",
28380
28564
  openToolIds,
28381
- stage: { fallbackTimeout, kind: "streaming", transcriptCheck }
28565
+ stage: {
28566
+ executorError,
28567
+ executorErrorPolls: 0,
28568
+ inactivityTimeout,
28569
+ kind: "streaming",
28570
+ stageEpoch,
28571
+ transcriptCheck
28572
+ }
28382
28573
  };
28383
28574
  };
28384
28575
  #enterWakeup = (sessionId, session, taskIds) => {
@@ -28419,7 +28610,51 @@ var AntigravityBackgroundWakeup = class {
28419
28610
  );
28420
28611
  return notifications;
28421
28612
  };
28422
- #checkWakeupTranscript = async (sessionId, generation, allowRetry) => {
28613
+ #failWakeup = (sessionId, session, message) => {
28614
+ if (session.phase.kind !== "wakeup") {
28615
+ return [];
28616
+ }
28617
+ this.#cancelWakeupTimers(session.phase);
28618
+ session.phase = { cancelRequested: false, kind: "idle" };
28619
+ this.#dropAwaitingResultTasks(session);
28620
+ const notifications = [];
28621
+ const bgNotification = this.#takeBackgroundTasksUpdate(sessionId, session);
28622
+ if (bgNotification !== null) {
28623
+ notifications.push(bgNotification);
28624
+ }
28625
+ notifications.push(
28626
+ makeMetaNotification(sessionId, AGENT_TURN_META, {
28627
+ message,
28628
+ stage: "failed"
28629
+ })
28630
+ );
28631
+ return notifications;
28632
+ };
28633
+ #rescheduleTranscriptCheck = (sessionId, session, generation, stageEpoch, stage) => {
28634
+ if (session.phase.kind !== "wakeup") {
28635
+ return;
28636
+ }
28637
+ const nextCheck = this.#scheduleTranscriptPoll(sessionId, generation, stageEpoch, TRANSCRIPT_POLL_INTERVAL_MS);
28638
+ switch (stage.kind) {
28639
+ case "awaiting-output":
28640
+ session.phase = {
28641
+ ...session.phase,
28642
+ stage: { ...stage, transcriptCheck: nextCheck }
28643
+ };
28644
+ return;
28645
+ case "streaming":
28646
+ session.phase = {
28647
+ ...session.phase,
28648
+ stage: {
28649
+ ...stage,
28650
+ executorErrorPolls: stage.executorError === void 0 ? 0 : stage.executorErrorPolls + 1,
28651
+ transcriptCheck: nextCheck
28652
+ }
28653
+ };
28654
+ return;
28655
+ }
28656
+ };
28657
+ #checkWakeupTranscript = async (sessionId, generation, stageEpoch) => {
28423
28658
  if (this.#disposed) {
28424
28659
  return;
28425
28660
  }
@@ -28427,7 +28662,7 @@ var AntigravityBackgroundWakeup = class {
28427
28662
  if (session === void 0 || session.phase.kind !== "wakeup" || session.phase.generation !== generation) {
28428
28663
  return;
28429
28664
  }
28430
- if (session.phase.stage.kind !== "streaming") {
28665
+ if (session.phase.stage.stageEpoch !== stageEpoch || session.phase.stage.kind !== "streaming" && session.phase.stage.kind !== "awaiting-output") {
28431
28666
  return;
28432
28667
  }
28433
28668
  const tail = await readTranscriptTailState(this.#launchEnvironment, sessionId, session.baselineStepIndex);
@@ -28438,31 +28673,29 @@ var AntigravityBackgroundWakeup = class {
28438
28673
  if (current === void 0 || current.phase.kind !== "wakeup" || current.phase.generation !== generation) {
28439
28674
  return;
28440
28675
  }
28441
- if (current.phase.stage.kind !== "streaming") {
28676
+ const currentStage = current.phase.stage;
28677
+ if (currentStage.stageEpoch !== stageEpoch || currentStage.kind !== "streaming" && currentStage.kind !== "awaiting-output") {
28442
28678
  return;
28443
28679
  }
28444
- if (tail?.settledWithoutToolCalls) {
28445
- current.baselineStepIndex = Math.max(current.baselineStepIndex, tail.maxStepIndex);
28446
- for (const notification of this.#finishWakeup(sessionId, current, "end_turn", false)) {
28447
- this.#emitMetaUpdate(notification);
28448
- }
28680
+ if (tail !== null) {
28681
+ this.#syncSubagentCreations(current, tail.steps);
28682
+ }
28683
+ if (tail?.settledStepIndex !== null && tail?.settledStepIndex !== void 0) {
28684
+ current.baselineStepIndex = Math.max(current.baselineStepIndex, tail.settledStepIndex);
28685
+ this.#consumeSubagentIdlesThrough(current, tail.steps, tail.settledStepIndex);
28686
+ this.#emitNotifications(this.#finishWakeup(sessionId, current, "end_turn", false));
28449
28687
  return;
28450
28688
  }
28451
- if (allowRetry) {
28452
- const retryTask = this.#timer.schedule(() => {
28453
- void this.#checkWakeupTranscript(sessionId, generation, false);
28454
- }, TRANSCRIPT_RETRY_DELAY_MS);
28455
- current.phase = {
28456
- ...current.phase,
28457
- stage: {
28458
- fallbackTimeout: current.phase.stage.fallbackTimeout,
28459
- kind: "streaming",
28460
- transcriptCheck: retryTask
28461
- }
28462
- };
28689
+ if (currentStage.kind === "streaming" && currentStage.executorError !== void 0 && currentStage.executorErrorPolls >= 1) {
28690
+ if (tail !== null && tail.maxStepIndex > current.baselineStepIndex) {
28691
+ current.baselineStepIndex = tail.maxStepIndex;
28692
+ }
28693
+ this.#emitNotifications(this.#failWakeup(sessionId, current, currentStage.executorError));
28694
+ return;
28463
28695
  }
28696
+ this.#rescheduleTranscriptCheck(sessionId, current, generation, stageEpoch, currentStage);
28464
28697
  };
28465
- #finishWakeupFromTimer = (sessionId, generation, stopReason) => {
28698
+ #handleWakeupTimeout = async (sessionId, generation, stageEpoch, message) => {
28466
28699
  if (this.#disposed) {
28467
28700
  return;
28468
28701
  }
@@ -28470,21 +28703,40 @@ var AntigravityBackgroundWakeup = class {
28470
28703
  if (session === void 0 || session.phase.kind !== "wakeup" || session.phase.generation !== generation) {
28471
28704
  return;
28472
28705
  }
28473
- void readTranscriptTailState(this.#launchEnvironment, sessionId, session.baselineStepIndex).then((tail) => {
28474
- if (this.#disposed) {
28475
- return;
28476
- }
28477
- const current = this.#sessions.get(sessionId);
28478
- if (current === void 0 || current.phase.kind !== "wakeup" || current.phase.generation !== generation) {
28479
- return;
28480
- }
28481
- if (tail !== null && tail.maxStepIndex > current.baselineStepIndex) {
28482
- current.baselineStepIndex = tail.maxStepIndex;
28483
- }
28484
- for (const notification of this.#finishWakeup(sessionId, current, stopReason, false)) {
28485
- this.#emitMetaUpdate(notification);
28486
- }
28487
- });
28706
+ if (session.phase.stage.stageEpoch !== stageEpoch || session.phase.stage.kind !== "awaiting-output" && session.phase.stage.kind !== "streaming") {
28707
+ return;
28708
+ }
28709
+ this.#cancelWakeupTimers(session.phase);
28710
+ session.wakeupStageSeq += 1;
28711
+ const timeoutEpoch = session.wakeupStageSeq;
28712
+ session.phase = {
28713
+ ...session.phase,
28714
+ stage: { kind: "verifying-timeout", message, stageEpoch: timeoutEpoch }
28715
+ };
28716
+ const tail = await readTranscriptTailState(this.#launchEnvironment, sessionId, session.baselineStepIndex);
28717
+ if (this.#disposed) {
28718
+ return;
28719
+ }
28720
+ const current = this.#sessions.get(sessionId);
28721
+ if (current === void 0 || current.phase.kind !== "wakeup" || current.phase.generation !== generation) {
28722
+ return;
28723
+ }
28724
+ if (current.phase.stage.kind !== "verifying-timeout" || current.phase.stage.stageEpoch !== timeoutEpoch) {
28725
+ return;
28726
+ }
28727
+ if (tail !== null) {
28728
+ this.#syncSubagentCreations(current, tail.steps);
28729
+ }
28730
+ if (tail?.settledStepIndex !== null && tail?.settledStepIndex !== void 0) {
28731
+ current.baselineStepIndex = Math.max(current.baselineStepIndex, tail.settledStepIndex);
28732
+ this.#consumeSubagentIdlesThrough(current, tail.steps, tail.settledStepIndex);
28733
+ this.#emitNotifications(this.#finishWakeup(sessionId, current, "end_turn", false));
28734
+ return;
28735
+ }
28736
+ if (tail !== null && tail.maxStepIndex > current.baselineStepIndex) {
28737
+ current.baselineStepIndex = tail.maxStepIndex;
28738
+ }
28739
+ this.#emitNotifications(this.#failWakeup(sessionId, current, message));
28488
28740
  };
28489
28741
  #promoteOpenWakeupToolsToBackground = (session) => {
28490
28742
  if (session.phase.kind !== "wakeup" || session.phase.openToolIds.size === 0) {
@@ -28519,12 +28771,14 @@ var AntigravityBackgroundWakeup = class {
28519
28771
  return;
28520
28772
  }
28521
28773
  if (session.phase.openToolIds.size > 0 || session.activeInteractions > 0) {
28522
- this.#setWakeupBlockedOnWork(session, session.phase.generation, session.phase.openToolIds);
28774
+ if (session.phase.stage.kind !== "blocked-on-work") {
28775
+ this.#setWakeupBlockedOnWork(session, session.phase.generation, session.phase.openToolIds);
28776
+ }
28523
28777
  } else if (session.phase.stage.kind === "blocked-on-work") {
28524
28778
  this.#setWakeupAwaitingOutput(sessionId, session, session.phase.generation, session.phase.openToolIds);
28525
28779
  }
28526
28780
  };
28527
- #applyClientPromptToolUpdate = (session, update, cancelled) => {
28781
+ #applyClientPromptToolUpdate = async (sessionId, session, update, cancelled) => {
28528
28782
  const toolCallId = readString3(update, "toolCallId");
28529
28783
  const status = readString3(update, "status");
28530
28784
  if (toolCallId === void 0 || status === void 0) {
@@ -28537,22 +28791,13 @@ var AntigravityBackgroundWakeup = class {
28537
28791
  return;
28538
28792
  }
28539
28793
  if (meta3.category === "manage-subagents" && status === "completed") {
28540
- if (meta3.subagentKillAll) {
28541
- this.#removeSubagentTasks(session, session.backgroundTasks.size);
28542
- } else {
28543
- this.#removeSubagentTasks(session, meta3.subagentKillCount);
28544
- }
28794
+ await this.#killSubagentsByMetadata(sessionId, session, meta3);
28545
28795
  return;
28546
28796
  }
28547
28797
  if (meta3.category === "subagent") {
28548
- if (!cancelled && status === "completed" && !session.backgroundTasks.has(toolCallId)) {
28549
- session.backgroundTasks.set(toolCallId, {
28550
- ...meta3.description === void 0 ? {} : { description: meta3.description },
28551
- kind: "subagent",
28552
- state: "running",
28553
- taskId: toolCallId,
28554
- toolUseId: toolCallId
28555
- });
28798
+ if (!cancelled && status === "completed") {
28799
+ this.#registerSubagentTask(session, toolCallId, meta3.description);
28800
+ await this.#syncPendingSubagentCreations(sessionId, session);
28556
28801
  }
28557
28802
  return;
28558
28803
  }
@@ -28574,7 +28819,7 @@ var AntigravityBackgroundWakeup = class {
28574
28819
  session.backgroundTasks.delete(toolCallId);
28575
28820
  }
28576
28821
  };
28577
- #applyWakeupToolUpdate = (sessionId, session, update, notifications) => {
28822
+ #applyWakeupToolUpdate = async (sessionId, session, update, notifications) => {
28578
28823
  if (session.phase.kind !== "wakeup") {
28579
28824
  return;
28580
28825
  }
@@ -28603,7 +28848,11 @@ var AntigravityBackgroundWakeup = class {
28603
28848
  );
28604
28849
  }
28605
28850
  } else if (status === "failed" || status === "cancelled") {
28606
- session.backgroundTasks.delete(toolCallId);
28851
+ if (trackedExisting.kind === "subagent") {
28852
+ this.#deleteSubagentTask(session, toolCallId);
28853
+ } else {
28854
+ session.backgroundTasks.delete(toolCallId);
28855
+ }
28607
28856
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
28608
28857
  if (bg2 !== null) {
28609
28858
  notifications.push(bg2);
@@ -28635,22 +28884,19 @@ var AntigravityBackgroundWakeup = class {
28635
28884
  session.phase = { ...session.phase, openToolIds: nextOpenToolIds };
28636
28885
  }
28637
28886
  if (meta3.category === "subagent" && status === "completed") {
28638
- session.backgroundTasks.set(toolCallId, {
28639
- ...meta3.description === void 0 ? {} : { description: meta3.description },
28640
- kind: "subagent",
28641
- state: "running",
28642
- taskId: toolCallId,
28643
- toolUseId: toolCallId
28644
- });
28887
+ this.#registerSubagentTask(session, toolCallId, meta3.description);
28888
+ await this.#syncPendingSubagentCreations(sessionId, session);
28889
+ if (this.#disposed || this.#sessions.get(sessionId) !== session) {
28890
+ return;
28891
+ }
28645
28892
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
28646
28893
  if (bg2 !== null) {
28647
28894
  notifications.push(bg2);
28648
28895
  }
28649
28896
  } else if (meta3.category === "manage-subagents" && status === "completed") {
28650
- if (meta3.subagentKillAll) {
28651
- this.#removeSubagentTasks(session, session.backgroundTasks.size);
28652
- } else {
28653
- this.#removeSubagentTasks(session, meta3.subagentKillCount);
28897
+ const active = await this.#killSubagentsByMetadata(sessionId, session, meta3);
28898
+ if (!active) {
28899
+ return;
28654
28900
  }
28655
28901
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
28656
28902
  if (bg2 !== null) {
@@ -28693,9 +28939,7 @@ var AntigravityBackgroundWakeup = class {
28693
28939
  }
28694
28940
  const session = this.#ensureSession(sessionId);
28695
28941
  if (session.phase.kind === "wakeup") {
28696
- for (const notification of this.#finishWakeup(sessionId, session, "end_turn", false)) {
28697
- this.#emitMetaUpdate(notification);
28698
- }
28942
+ this.#emitNotifications(this.#finishWakeup(sessionId, session, "end_turn", false));
28699
28943
  }
28700
28944
  const tail = await readTranscriptTailState(
28701
28945
  this.#launchEnvironment,
@@ -28721,6 +28965,9 @@ var AntigravityBackgroundWakeup = class {
28721
28965
  };
28722
28966
  onIncomingMessage = async (message) => {
28723
28967
  if (this.#disposed) {
28968
+ if (isResponseMessage2(message) && "result" in message && isRecord5(message.result) && readString3(message.result, "stopReason") !== "cancelled") {
28969
+ return { afterUpdates: [], beforeUpdates: [], rewritePromptCancelled: true };
28970
+ }
28724
28971
  return EMPTY_INCOMING_OUTCOME;
28725
28972
  }
28726
28973
  if (isResponseMessage2(message)) {
@@ -28741,6 +28988,7 @@ var AntigravityBackgroundWakeup = class {
28741
28988
  );
28742
28989
  if (tail2 !== null) {
28743
28990
  session2.baselineStepIndex = Math.max(session2.baselineStepIndex, tail2.maxStepIndex);
28991
+ session2.sessionOpenStepIndex = Math.max(session2.sessionOpenStepIndex, tail2.maxStepIndex);
28744
28992
  }
28745
28993
  if (tracked.kind === "load") {
28746
28994
  session2.phase = { cancelRequested: false, kind: "idle" };
@@ -28748,29 +28996,45 @@ var AntigravityBackgroundWakeup = class {
28748
28996
  return EMPTY_INCOMING_OUTCOME;
28749
28997
  }
28750
28998
  const prePromptStepIndex = session2.phase.kind === "client-prompt" ? session2.phase.prePromptStepIndex : session2.baselineStepIndex;
28751
- const promptCancelled = session2.phase.kind === "client-prompt" && session2.phase.cancelled || "result" in message && isRecord5(message.result) && readString3(message.result, "stopReason") === "cancelled";
28999
+ const responseStopReason = "result" in message && isRecord5(message.result) ? readString3(message.result, "stopReason") : void 0;
28752
29000
  const tail = await readTranscriptTailState(
28753
29001
  this.#launchEnvironment,
28754
29002
  tracked.sessionId,
28755
29003
  session2.baselineStepIndex
28756
29004
  );
29005
+ const promptCancelled = this.#disposed || session2.phase.kind === "client-prompt" && session2.phase.cancelled || session2.phase.kind === "idle" && session2.phase.cancelRequested || responseStopReason === "cancelled";
28757
29006
  if (tail !== null) {
28758
29007
  session2.baselineStepIndex = Math.max(session2.baselineStepIndex, tail.maxStepIndex);
29008
+ this.#syncSubagentCreations(session2, tail.steps);
28759
29009
  if (!promptCancelled) {
28760
- const consumedSubagents = countConsumedSubagentIdles(
28761
- tail.steps,
28762
- prePromptStepIndex,
28763
- session2.baselineStepIndex
28764
- );
28765
- this.#removeSubagentTasks(session2, consumedSubagents);
29010
+ let lastPlannerStepIndex;
29011
+ for (let index2 = tail.steps.length - 1; index2 >= 0; index2 -= 1) {
29012
+ const step = tail.steps[index2];
29013
+ if (step !== void 0 && step.step_index > prePromptStepIndex && step.step_index <= session2.baselineStepIndex && step.type === "PLANNER_RESPONSE") {
29014
+ lastPlannerStepIndex = step.step_index;
29015
+ break;
29016
+ }
29017
+ }
29018
+ if (lastPlannerStepIndex !== void 0) {
29019
+ this.#consumeSubagentIdlesThrough(session2, tail.steps, lastPlannerStepIndex);
29020
+ }
28766
29021
  }
28767
29022
  }
28768
29023
  if (promptCancelled) {
28769
- session2.backgroundTasks.clear();
29024
+ this.#clearAllBackgroundTasks(session2);
28770
29025
  }
28771
29026
  session2.phase = { cancelRequested: promptCancelled, kind: "idle" };
28772
29027
  const bg2 = this.#takeBackgroundTasksUpdate(tracked.sessionId, session2);
28773
- return bg2 === null ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [], beforeUpdates: [bg2] };
29028
+ const rewritePromptCancelled = promptCancelled && "result" in message && isRecord5(message.result) && responseStopReason !== "cancelled";
29029
+ const beforeUpdates = bg2 === null ? [] : [bg2];
29030
+ if (beforeUpdates.length === 0 && !rewritePromptCancelled) {
29031
+ return EMPTY_INCOMING_OUTCOME;
29032
+ }
29033
+ return {
29034
+ afterUpdates: [],
29035
+ beforeUpdates,
29036
+ ...rewritePromptCancelled ? { rewritePromptCancelled: true } : {}
29037
+ };
28774
29038
  }
28775
29039
  if (!isNotificationMessage2(message) || message.method !== methods.client.session.update) {
28776
29040
  return EMPTY_INCOMING_OUTCOME;
@@ -28791,7 +29055,7 @@ var AntigravityBackgroundWakeup = class {
28791
29055
  return EMPTY_INCOMING_OUTCOME;
28792
29056
  case "client-prompt": {
28793
29057
  if (updateKind === "tool_call" || updateKind === "tool_call_update") {
28794
- this.#applyClientPromptToolUpdate(session, update, session.phase.cancelled);
29058
+ await this.#applyClientPromptToolUpdate(sessionId, session, update, session.phase.cancelled);
28795
29059
  }
28796
29060
  return EMPTY_INCOMING_OUTCOME;
28797
29061
  }
@@ -28803,13 +29067,21 @@ var AntigravityBackgroundWakeup = class {
28803
29067
  const existing = session.backgroundTasks.get(toolCallId);
28804
29068
  if (existing !== void 0) {
28805
29069
  if (status === "failed" || status === "cancelled") {
28806
- session.backgroundTasks.delete(toolCallId);
29070
+ if (existing.kind === "subagent") {
29071
+ this.#deleteSubagentTask(session, toolCallId);
29072
+ } else {
29073
+ session.backgroundTasks.delete(toolCallId);
29074
+ }
28807
29075
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
28808
29076
  return bg2 === null ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [bg2], beforeUpdates: [] };
28809
29077
  }
28810
29078
  if (status === "completed") {
28811
29079
  if (session.phase.cancelRequested) {
28812
- session.backgroundTasks.delete(toolCallId);
29080
+ if (existing.kind === "subagent") {
29081
+ this.#deleteSubagentTask(session, toolCallId);
29082
+ } else {
29083
+ session.backgroundTasks.delete(toolCallId);
29084
+ }
28813
29085
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
28814
29086
  return bg2 === null ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [bg2], beforeUpdates: [] };
28815
29087
  }
@@ -28835,20 +29107,27 @@ var AntigravityBackgroundWakeup = class {
28835
29107
  return EMPTY_INCOMING_OUTCOME;
28836
29108
  }
28837
29109
  }
28838
- const subagentTaskId = this.#oldestRunningSubagentId(session);
28839
- if (subagentTaskId !== void 0) {
28840
- const existing = session.backgroundTasks.get(subagentTaskId);
28841
- if (existing !== void 0) {
28842
- session.backgroundTasks.set(subagentTaskId, { ...existing, state: "awaiting-results" });
29110
+ let matchedTaskIds = [];
29111
+ if (this.#hasSubagentTasks(session)) {
29112
+ const tail = await readTranscriptTailState(
29113
+ this.#launchEnvironment,
29114
+ sessionId,
29115
+ session.baselineStepIndex
29116
+ );
29117
+ if (this.#disposed || this.#sessions.get(sessionId) !== session) {
29118
+ return EMPTY_INCOMING_OUTCOME;
29119
+ }
29120
+ if (session.phase.kind !== "idle" || session.phase.cancelRequested) {
29121
+ return EMPTY_INCOMING_OUTCOME;
29122
+ }
29123
+ if (tail !== null) {
29124
+ this.#syncSubagentCreations(session, tail.steps);
29125
+ matchedTaskIds = this.#markTriggeredSubagentIdles(session, tail.steps);
28843
29126
  }
28844
29127
  }
28845
- const startedNotifications = this.#enterWakeup(
28846
- sessionId,
28847
- session,
28848
- subagentTaskId === void 0 ? [] : [subagentTaskId]
28849
- );
29128
+ const startedNotifications = this.#enterWakeup(sessionId, session, matchedTaskIds);
28850
29129
  const extraWakeup = [];
28851
- this.#handleWakeupUpdate(sessionId, session, updateKind, update, extraWakeup);
29130
+ await this.#handleWakeupUpdate(sessionId, session, updateKind, update, extraWakeup);
28852
29131
  return {
28853
29132
  afterUpdates: [],
28854
29133
  beforeUpdates: [...startedNotifications, ...extraWakeup]
@@ -28856,7 +29135,7 @@ var AntigravityBackgroundWakeup = class {
28856
29135
  }
28857
29136
  case "wakeup": {
28858
29137
  const beforeUpdates = [];
28859
- this.#handleWakeupUpdate(sessionId, session, updateKind, update, beforeUpdates);
29138
+ await this.#handleWakeupUpdate(sessionId, session, updateKind, update, beforeUpdates);
28860
29139
  return beforeUpdates.length === 0 ? EMPTY_INCOMING_OUTCOME : { afterUpdates: [], beforeUpdates };
28861
29140
  }
28862
29141
  default: {
@@ -28865,22 +29144,29 @@ var AntigravityBackgroundWakeup = class {
28865
29144
  }
28866
29145
  }
28867
29146
  };
28868
- #handleWakeupUpdate = (sessionId, session, updateKind, update, beforeUpdates) => {
29147
+ #handleWakeupUpdate = async (sessionId, session, updateKind, update, beforeUpdates) => {
28869
29148
  if (session.phase.kind !== "wakeup") {
28870
29149
  return;
28871
29150
  }
28872
29151
  if (updateKind === "tool_call" || updateKind === "tool_call_update") {
28873
- this.#applyWakeupToolUpdate(sessionId, session, update, beforeUpdates);
29152
+ await this.#applyWakeupToolUpdate(sessionId, session, update, beforeUpdates);
28874
29153
  return;
28875
29154
  }
28876
29155
  if (isWakeupChunkUpdateKind(updateKind)) {
29156
+ const executorError = extractExecutorError(updateKind, update);
28877
29157
  this.#promoteOpenWakeupToolsToBackground(session);
28878
29158
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
28879
29159
  if (bg2 !== null) {
28880
29160
  beforeUpdates.push(bg2);
28881
29161
  }
28882
29162
  if (session.phase.openToolIds.size === 0 && session.activeInteractions === 0) {
28883
- this.#setWakeupStreaming(sessionId, session, session.phase.generation, session.phase.openToolIds);
29163
+ this.#setWakeupStreaming(
29164
+ sessionId,
29165
+ session,
29166
+ session.phase.generation,
29167
+ session.phase.openToolIds,
29168
+ executorError
29169
+ );
28884
29170
  }
28885
29171
  }
28886
29172
  };
@@ -28911,8 +29197,8 @@ var AntigravityBackgroundWakeup = class {
28911
29197
  const mustClose = session.phase.kind === "wakeup" || this.#hasSubagentTasks(session);
28912
29198
  if (mustClose) {
28913
29199
  this.#cancelWakeupTimers(session.phase);
28914
- session.backgroundTasks.clear();
28915
- session.phase = { cancelRequested: true, kind: "idle" };
29200
+ this.#clearAllBackgroundTasks(session);
29201
+ session.phase = session.phase.kind === "client-prompt" ? { ...session.phase, cancelled: true } : { cancelRequested: true, kind: "idle" };
28916
29202
  return "close";
28917
29203
  }
28918
29204
  if (session.phase.kind === "client-prompt") {
@@ -28929,7 +29215,7 @@ var AntigravityBackgroundWakeup = class {
28929
29215
  for (const [sessionId, session] of this.#sessions) {
28930
29216
  const wasWakeup = session.phase.kind === "wakeup";
28931
29217
  this.#cancelWakeupTimers(session.phase);
28932
- session.backgroundTasks.clear();
29218
+ this.#clearAllBackgroundTasks(session);
28933
29219
  if (wasWakeup) {
28934
29220
  session.phase = { cancelRequested: false, kind: "idle" };
28935
29221
  this.#emitMetaUpdate(
@@ -29117,7 +29403,8 @@ var AntigravityAgentConnection = class {
29117
29403
  emitMetaUpdate: (notification) => {
29118
29404
  this.#queueMetaUpdate(notification);
29119
29405
  },
29120
- launchEnvironment
29406
+ launchEnvironment,
29407
+ ...options.timer === void 0 ? {} : { timer: options.timer }
29121
29408
  });
29122
29409
  const launch = executableLaunch2(options.command, ["acp"]);
29123
29410
  const child = spawn2(launch.command, [...launch.arguments], {
@@ -29282,10 +29569,11 @@ var AntigravityAgentConnection = class {
29282
29569
  closeProcess = () => {
29283
29570
  this.#closePromise ??= (async () => {
29284
29571
  try {
29285
- this.#backgroundWakeup.dispose();
29572
+ this.#child.stdout?.pause();
29286
29573
  this.#deliveryAbort.abort(new DOMException("Antigravity ACP connection closed", "AbortError"));
29287
- const captured = await captureProcessTree(this.#child);
29288
29574
  this.connection.close();
29575
+ this.#backgroundWakeup.dispose();
29576
+ const captured = await captureProcessTree(this.#child);
29289
29577
  this.#child.stdin?.end();
29290
29578
  await stopProcessTree(this.#child, captured);
29291
29579
  } finally {
@@ -29538,11 +29826,17 @@ var AntigravityAgentConnection = class {
29538
29826
  const readable = rawStream.readable.pipeThrough(
29539
29827
  new TransformStream({
29540
29828
  transform: async (chunk, controller) => {
29829
+ if (this.#closePromise !== null || this.#deliveryAbort.signal.aborted) {
29830
+ return;
29831
+ }
29541
29832
  const transformed = transformIncoming(chunk);
29542
29833
  if (transformed === void 0) {
29543
29834
  return;
29544
29835
  }
29545
29836
  const outcome = await this.#backgroundWakeup.onIncomingMessage(transformed);
29837
+ if (this.#closePromise !== null || this.#deliveryAbort.signal.aborted) {
29838
+ return;
29839
+ }
29546
29840
  if (isResponseMessage3(transformed)) {
29547
29841
  for (const metaUpdate of outcome.beforeUpdates) {
29548
29842
  this.#queueMetaUpdate(metaUpdate);
@@ -29550,7 +29844,11 @@ var AntigravityAgentConnection = class {
29550
29844
  if (outcome.beforeUpdates.length > 0) {
29551
29845
  await this.#flushDeliveries();
29552
29846
  }
29553
- controller.enqueue(transformed);
29847
+ const outgoingResponse = outcome.rewritePromptCancelled === true && "result" in transformed && isRecord5(transformed.result) ? {
29848
+ ...transformed,
29849
+ result: { ...transformed.result, stopReason: "cancelled" }
29850
+ } : transformed;
29851
+ controller.enqueue(outgoingResponse);
29554
29852
  for (const metaUpdate of outcome.afterUpdates) {
29555
29853
  this.#queueMetaUpdate(metaUpdate);
29556
29854
  }
@@ -29649,14 +29947,19 @@ var AntigravityAgentSpecification = class extends InProcessAcpAgentSpecification
29649
29947
  acpProbeTimeoutMilliseconds = ACP_PROBE_TIMEOUT_MILLISECONDS2;
29650
29948
  adapterVersionArguments = Object.freeze([]);
29651
29949
  agentExecutable = "agy";
29652
- createConnection = (options) => new AntigravityAgentConnection(options);
29950
+ #timer;
29951
+ createConnection = (options) => new AntigravityAgentConnection({
29952
+ ...options,
29953
+ ...this.#timer === void 0 ? {} : { timer: this.#timer }
29954
+ });
29653
29955
  id = "antigravity";
29654
29956
  label = "Antigravity";
29655
29957
  minimumSupportedAgentVersion = "1.5.1";
29656
29958
  maximumTestedAgentVersion = "1.5.10";
29657
29959
  authenticationCommand = () => "agy acp --login";
29658
- constructor() {
29960
+ constructor(options) {
29659
29961
  super("MOBIUS_ANTIGRAVITY_PATH");
29962
+ this.#timer = options?.timer;
29660
29963
  }
29661
29964
  resolveInstalledAgentExecutables = async (context) => {
29662
29965
  context.signal.throwIfAborted();
@@ -100593,4 +100896,4 @@ export {
100593
100896
  * MIT Licensed
100594
100897
  *)
100595
100898
  */
100596
- //# sourceMappingURL=chunk-PVKEDOVN.js.map
100899
+ //# sourceMappingURL=chunk-7VYQEJW7.js.map