@vicary/pi-subagents 0.87.0 → 0.88.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/bundle/agents.js +3 -3
  3. package/bundle/child-tool-plan.js +3 -3
  4. package/bundle/{chunk-3CVOAS77.js → chunk-2DIEL4WG.js} +2 -2
  5. package/bundle/{chunk-75LVXBSA.js → chunk-2HKPEANZ.js} +114 -49
  6. package/bundle/{chunk-ESWW6XSX.js → chunk-47ZN7NKR.js} +1 -1
  7. package/bundle/{chunk-C3KWLXDH.js → chunk-4MVDMA5C.js} +9 -1
  8. package/bundle/{chunk-XV7RTWTS.js → chunk-4ZQBZDF3.js} +21 -6
  9. package/bundle/{chunk-LZKVUWIY.js → chunk-5EMPFFO4.js} +30 -5
  10. package/bundle/{chunk-OOE3R7IQ.js → chunk-6CG2VAG4.js} +2 -2
  11. package/bundle/{chunk-HDICKROY.js → chunk-7OX6O7DQ.js} +31 -14
  12. package/bundle/{chunk-Z4TR7MK6.js → chunk-AZPP3G4N.js} +14 -5
  13. package/bundle/{chunk-PUSTU4Q7.js → chunk-BKISQ5CJ.js} +130 -49
  14. package/bundle/{chunk-NMYBVCGP.js → chunk-CGWNA6EJ.js} +75 -44
  15. package/bundle/{chunk-PGU4TZV3.js → chunk-CPSUJHZE.js} +417 -455
  16. package/bundle/{chunk-W52LJANO.js → chunk-CYKNHFXB.js} +1 -1
  17. package/bundle/{chunk-SIAQXPJ4.js → chunk-D32H53HM.js} +21 -9
  18. package/bundle/{chunk-YEXKJJVS.js → chunk-DSHQWGHO.js} +4 -4
  19. package/bundle/{chunk-6O7YH2QV.js → chunk-GDR2ILWY.js} +1 -1
  20. package/bundle/{chunk-O7A26O6B.js → chunk-IYT7X46U.js} +6 -4
  21. package/bundle/{chunk-NJTSXIMG.js → chunk-JQTHG2ID.js} +12 -12
  22. package/bundle/{chunk-C5QWQSSM.js → chunk-KXW62VBU.js} +1 -1
  23. package/bundle/{chunk-BFF6YDK6.js → chunk-L4YY2TOE.js} +1 -1
  24. package/bundle/{chunk-2NY5PCKQ.js → chunk-LV3CPYXJ.js} +4 -4
  25. package/bundle/{chunk-2D2DQGC2.js → chunk-PYKBTBY6.js} +27 -10
  26. package/bundle/{chunk-M2VBGET6.js → chunk-RMZAAXIR.js} +7 -2
  27. package/bundle/{chunk-HTI7DD5D.js → chunk-V7SZMS6W.js} +2 -2
  28. package/bundle/{chunk-VFUFOZBU.js → chunk-W6HIYD2Z.js} +1 -1
  29. package/bundle/{chunk-USRX7QXD.js → chunk-XIA5GSEU.js} +2 -2
  30. package/bundle/{chunk-CTPAE36Y.js → chunk-YARY7JWU.js} +22 -0
  31. package/bundle/chunk-YDZ7BZD5.js +523 -0
  32. package/bundle/control-channel.js +2 -2
  33. package/bundle/index.js +1 -1
  34. package/bundle/intercom-bridge.js +2 -2
  35. package/bundle/preflight.js +9 -9
  36. package/bundle/project-panes.js +3 -3
  37. package/bundle/required-child-extensions.js +1 -1
  38. package/docs/agents.md +4 -2
  39. package/docs/configuration.md +4 -2
  40. package/docs/observability.md +2 -0
  41. package/docs/tool-reference.md +4 -1
  42. package/docs/workflows.md +3 -1
  43. package/package.json +3 -3
  44. package/skills/pi-subagents/SKILL.md +8 -2
  45. package/src/agents/agent-management.d.ts +1 -0
  46. package/src/agents/agent-management.js +12 -4
  47. package/src/agents/agents.d.ts +1 -0
  48. package/src/agents/agents.js +2 -2
  49. package/src/extension/config.d.ts +9 -0
  50. package/src/extension/config.js +13 -0
  51. package/src/extension/index.d.ts +1 -1
  52. package/src/extension/index.js +47 -23
  53. package/src/extension/schemas.d.ts +2 -0
  54. package/src/extension/schemas.js +1 -0
  55. package/src/extension/subagent-launch-tool.d.ts +6 -2
  56. package/src/extension/subagent-launch-tool.js +13 -9
  57. package/src/extension/tool-activation.js +20 -3
  58. package/src/runs/background/async-resume.js +2 -1
  59. package/src/runs/background/async-retention.d.ts +0 -2
  60. package/src/runs/background/async-retention.js +11 -5
  61. package/src/runs/background/async-status.d.ts +2 -0
  62. package/src/runs/background/async-status.js +4 -0
  63. package/src/runs/background/run-child-session.d.ts +2 -2
  64. package/src/runs/background/run-child-session.js +4 -7
  65. package/src/runs/background/stale-run-reconciler.js +17 -8
  66. package/src/runs/background/steering.d.ts +2 -11
  67. package/src/runs/background/steering.js +11 -6
  68. package/src/runs/background/subagent-runner.d.ts +0 -2
  69. package/src/runs/background/subagent-runner.js +73 -58
  70. package/src/runs/foreground/async-steering-action.js +24 -9
  71. package/src/runs/foreground/execution.js +32 -15
  72. package/src/runs/foreground/prompt-audit.js +1 -0
  73. package/src/runs/foreground/subagent-executor.d.ts +1 -8
  74. package/src/runs/foreground/subagent-executor.js +17 -21
  75. package/src/runs/shared/async-status-projection.d.ts +2 -0
  76. package/src/runs/shared/async-status-projection.js +10 -0
  77. package/src/runs/shared/child-launch.js +6 -3
  78. package/src/runs/shared/child-session.d.ts +1 -1
  79. package/src/runs/shared/child-session.js +24 -30
  80. package/src/runs/shared/mcp-config-sources.d.ts +2 -0
  81. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +5 -5
  82. package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -15
  83. package/src/runs/shared/subagent-prompt-runtime.js +14 -2
  84. package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
  85. package/src/runs/shared/supervisor-wait-timer.js +61 -0
  86. package/src/shared/artifacts.d.ts +1 -0
  87. package/src/shared/artifacts.js +107 -9
  88. package/src/shared/compaction-interruption.d.ts +9 -0
  89. package/src/shared/compaction-interruption.js +47 -0
  90. package/src/shared/parent-wake.d.ts +3 -2
  91. package/src/shared/parent-wake.js +14 -3
  92. package/src/shared/reported-progress.d.ts +1 -0
  93. package/src/shared/reported-progress.js +12 -0
  94. package/src/shared/required-child-extensions.d.ts +2 -0
  95. package/src/shared/required-child-extensions.js +27 -0
  96. package/src/shared/status-format.d.ts +1 -0
  97. package/src/shared/status-format.js +1 -1
  98. package/src/shared/types.d.ts +9 -0
  99. package/src/shared/utils.d.ts +3 -1
  100. package/src/shared/utils.js +4 -0
  101. package/src/tui/fleet.d.ts +7 -2
  102. package/src/tui/fleet.js +22 -0
  103. package/src/tui/render.js +33 -2
  104. package/src/watchdog/permission-arbiter.js +1 -0
  105. package/src/watchdog/review.d.ts +0 -5
  106. package/src/watchdog/review.js +2 -1
  107. package/src/workflows/workflow-script-worker.js +3 -1
  108. package/bundle/chunk-XSDYTXHF.js +0 -242
@@ -10,10 +10,10 @@ import {
10
10
  setInlineWorkflowCoverage,
11
11
  setMainThinkingLevelSource,
12
12
  widgetRenderKey
13
- } from "./chunk-LZKVUWIY.js";
13
+ } from "./chunk-5EMPFFO4.js";
14
14
  import {
15
15
  package_default
16
- } from "./chunk-OOE3R7IQ.js";
16
+ } from "./chunk-6CG2VAG4.js";
17
17
  import {
18
18
  EXTERNAL_JOB_BRIDGE_REQUEST_DIR,
19
19
  REVIVAL_ORIGIN_FILE,
@@ -23,6 +23,8 @@ import {
23
23
  buildSubagentResultIntercomPayload,
24
24
  clearProviderRetry,
25
25
  compactNestedResultChildren,
26
+ compactionInProgress,
27
+ compactionInterruptedRun,
26
28
  controlNotificationKey,
27
29
  createParentWake,
28
30
  createScheduledRunManager,
@@ -37,6 +39,7 @@ import {
37
39
  getInspectorPlugins,
38
40
  hasLiveSubagentWork,
39
41
  hasWorkflowResumeRefusal,
42
+ installCompactionInterruptionCapture,
40
43
  listRetainedChildren,
41
44
  listScheduledRunSummaries,
42
45
  markSeenWithTtl,
@@ -60,9 +63,10 @@ import {
60
63
  sameProviderDiagnostics,
61
64
  serviceExternalJobBridgeRequests,
62
65
  snapshotProviderDiagnostics,
66
+ takeCompactionAbort,
63
67
  workflowResumeClaimState,
64
68
  workflowResumeRefusal
65
- } from "./chunk-75LVXBSA.js";
69
+ } from "./chunk-2HKPEANZ.js";
66
70
  import {
67
71
  SUBAGENT_CHILD_ENV,
68
72
  SUBAGENT_PARENT_SESSION_ENV,
@@ -82,14 +86,14 @@ import {
82
86
  resolvePiSessionId,
83
87
  resolveWaitToolConfig,
84
88
  setDeclarationPinning
85
- } from "./chunk-O7A26O6B.js";
89
+ } from "./chunk-IYT7X46U.js";
86
90
  import {
87
91
  deliverAsyncRunStop,
88
92
  ownerConfirmedDead,
89
93
  readSessionMessagesTail,
90
94
  resolveSubagentRunId,
91
95
  restoreForegroundRunHistory
92
- } from "./chunk-2NY5PCKQ.js";
96
+ } from "./chunk-LV3CPYXJ.js";
93
97
  import {
94
98
  ASYNC_STATUS_SNAPSHOT_KIND,
95
99
  ASYNC_STATUS_SNAPSHOT_VERSION,
@@ -105,7 +109,7 @@ import {
105
109
  resolveAsyncStatusChild,
106
110
  runLaunchDir,
107
111
  stopStoppableAsyncStatusChildren
108
- } from "./chunk-XV7RTWTS.js";
112
+ } from "./chunk-4ZQBZDF3.js";
109
113
  import {
110
114
  CONTACT_SUPERVISOR_TOOL_NAME,
111
115
  NATIVE_SUPERVISOR_TOOL_NAME,
@@ -115,7 +119,7 @@ import {
115
119
  parseSupervisorReplyData,
116
120
  parseSupervisorRequestDetails,
117
121
  topLevelSupervisorTool
118
- } from "./chunk-W52LJANO.js";
122
+ } from "./chunk-CYKNHFXB.js";
119
123
  import {
120
124
  MODEL_ONLY_TOOL,
121
125
  canRenderComponents,
@@ -137,10 +141,11 @@ import {
137
141
  loadConfig,
138
142
  resolveAbandonedSlotReleaseAfterMs,
139
143
  resolveAsyncByDefault,
144
+ resolveConfigDefaultTimeoutMs,
140
145
  resolveDisabledFeatureSurface,
141
146
  resolveMaxActiveAsyncRunsPerSession,
142
147
  resolveScheduledStoreRoot
143
- } from "./chunk-M2VBGET6.js";
148
+ } from "./chunk-RMZAAXIR.js";
144
149
  import {
145
150
  ACTIVE_RUN_INDEX_DIR,
146
151
  MissionNotFoundError,
@@ -191,28 +196,28 @@ import {
191
196
  withWorkflowChildRunModel,
192
197
  writeAsyncResultFile,
193
198
  writeResultIndexForData
194
- } from "./chunk-PGU4TZV3.js";
195
- import "./chunk-VFUFOZBU.js";
199
+ } from "./chunk-CPSUJHZE.js";
200
+ import "./chunk-W6HIYD2Z.js";
196
201
  import {
197
202
  shouldUseNativeFsWatch
198
203
  } from "./chunk-NIXWDZZV.js";
199
204
  import {
200
205
  validateIntercomBridgeConfig
201
- } from "./chunk-ESWW6XSX.js";
206
+ } from "./chunk-47ZN7NKR.js";
202
207
  import "./chunk-7F6RKT6W.js";
203
- import "./chunk-SIAQXPJ4.js";
204
- import "./chunk-CTPAE36Y.js";
208
+ import "./chunk-D32H53HM.js";
209
+ import "./chunk-YARY7JWU.js";
205
210
  import {
206
211
  listHerdrProjectPaneRoots,
207
212
  restoreHerdrProjectPaneSnapshots
208
- } from "./chunk-3CVOAS77.js";
213
+ } from "./chunk-2DIEL4WG.js";
209
214
  import "./chunk-7J4ZXMY7.js";
210
215
  import {
211
216
  cleanupAllArtifactDirs,
212
217
  cleanupOldArtifacts,
213
218
  getArtifactPaths,
214
219
  getArtifactsDir
215
- } from "./chunk-XSDYTXHF.js";
220
+ } from "./chunk-YDZ7BZD5.js";
216
221
  import {
217
222
  listBackgroundWorkProviders
218
223
  } from "./chunk-XA3DY6UG.js";
@@ -220,12 +225,12 @@ import "./chunk-YYREO77V.js";
220
225
  import "./chunk-UKG4V45O.js";
221
226
  import {
222
227
  registerRuntimeAgentEventListener
223
- } from "./chunk-BFF6YDK6.js";
228
+ } from "./chunk-L4YY2TOE.js";
224
229
  import {
225
230
  clearRuntimeAgentsForPi,
226
231
  listRuntimeAgentConfigs,
227
232
  mergeRuntimeAgents
228
- } from "./chunk-C5QWQSSM.js";
233
+ } from "./chunk-KXW62VBU.js";
229
234
  import {
230
235
  DEFAULT_FILE_SYSTEM_RETRY_DELAYS_MS,
231
236
  DEFAULT_WAIT_TOOL_NAME,
@@ -268,7 +273,7 @@ import {
268
273
  waitToolName,
269
274
  withSettingsFileLease,
270
275
  writeAtomicJson
271
- } from "./chunk-C3KWLXDH.js";
276
+ } from "./chunk-4MVDMA5C.js";
272
277
  import {
273
278
  DEFAULT_ARTIFACT_CONFIG,
274
279
  DIRS,
@@ -316,6 +321,7 @@ import { randomUUID as randomUUID3 } from "node:crypto";
316
321
  import * as fs16 from "node:fs";
317
322
  import * as os3 from "node:os";
318
323
  import * as path16 from "node:path";
324
+ import { AgentSession } from "@earendil-works/pi-coding-agent";
319
325
  import { Box as Box2, Container as Container3, Spacer as Spacer3, Text as Text2 } from "@earendil-works/pi-tui";
320
326
 
321
327
  // src/agents/global-npm-root.ts
@@ -1570,9 +1576,13 @@ async function computeProcessStartIdentity(pid) {
1570
1576
  }
1571
1577
  if (process.platform === "win32") {
1572
1578
  const started = await new Promise((resolve6) => {
1573
- execFile2("powershell.exe", ["-NoProfile", "-Command", `(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CreationDate`], { encoding: "utf-8", windowsHide: true, timeout: 5e3 }, (error, stdout) => {
1574
- resolve6(error ? "" : stdout.trim());
1575
- });
1579
+ try {
1580
+ execFile2("powershell.exe", ["-NoProfile", "-Command", `(Get-CimInstance Win32_Process -Filter "ProcessId=${pid}").CreationDate`], { encoding: "utf-8", windowsHide: true, timeout: 5e3 }, (error, stdout) => {
1581
+ resolve6(error ? "" : stdout.trim());
1582
+ });
1583
+ } catch {
1584
+ resolve6("");
1585
+ }
1576
1586
  });
1577
1587
  return started ? `win:${started}` : void 0;
1578
1588
  }
@@ -5360,7 +5370,7 @@ function registerSlashCommands(pi, state, options = {}) {
5360
5370
  }
5361
5371
  fleetOpen = true;
5362
5372
  try {
5363
- const { openSubagentFleet } = await import("./chunk-2D2DQGC2.js");
5373
+ const { openSubagentFleet } = await import("./chunk-PYKBTBY6.js");
5364
5374
  await openSubagentFleet(ctx, state, { asyncDirRoot: DIRS.async, inspectorPlugins: () => getInspectorPlugins(pi), resultsDir: DIRS.results, fleetKeybindings: options.fleetKeybindings });
5365
5375
  } finally {
5366
5376
  fleetOpen = false;
@@ -8079,12 +8089,20 @@ ${advertised}` : ""}` }],
8079
8089
  };
8080
8090
  registerPinnedTool(pi, loader);
8081
8091
  let loaderSelected = true;
8092
+ let undeclared;
8093
+ const activationState = () => [LOADER_NAME, SUBAGENT_NAME].map((name) => pi.getActiveTools().includes(name)).join();
8082
8094
  const replyOwed = () => options.hasPendingSupervisorRequest?.() === true;
8083
- pi.on("session_start", (_event, ctx) => {
8095
+ const decide = (ctx) => {
8084
8096
  loaderSelected = applyRecordedSelection(pi, ctx, mode, replyOwed());
8097
+ undeclared = Array.isArray(pi.getActiveTools()) ? activationState() : void 0;
8098
+ };
8099
+ pi.on("session_start", (_event, ctx) => decide(ctx));
8100
+ pi.on("session_tree", (_event, ctx) => decide(ctx));
8101
+ pi.on("agent_start", () => {
8102
+ undeclared = void 0;
8085
8103
  });
8086
- pi.on("session_tree", (_event, ctx) => {
8087
- loaderSelected = applyRecordedSelection(pi, ctx, mode, replyOwed());
8104
+ pi.on("model_select", (_event, ctx) => {
8105
+ if (mode === "auto" && ctx.isIdle() && undeclared === activationState() && loaderSelected !== addsToolsWithoutCheckpoint(ctx.model) && ctx.sessionManager.buildSessionContext().messages.length === 0) decide(ctx);
8088
8106
  });
8089
8107
  pi.on("before_agent_start", (event) => {
8090
8108
  const available = pi.getAllTools();
@@ -8678,6 +8696,7 @@ function registerSubagentExtension(pi) {
8678
8696
  if (process.env[SUBAGENT_CHILD_ENV] === "1") {
8679
8697
  return;
8680
8698
  }
8699
+ installCompactionInterruptionCapture(AgentSession);
8681
8700
  const runtimeRegistry = getRuntimeRegistry();
8682
8701
  setMainThinkingLevelSource(() => readMainThinkingLevel(() => pi.getThinkingLevel()));
8683
8702
  DIRS.results = ensureAccessibleDir(DIRS.results);
@@ -8765,7 +8784,7 @@ function registerSubagentExtension(pi) {
8765
8784
  const ctx = withLastUiContext((current) => current);
8766
8785
  if (!ctx) return;
8767
8786
  try {
8768
- const { openSubagentFleet } = await import("./chunk-2D2DQGC2.js");
8787
+ const { openSubagentFleet } = await import("./chunk-PYKBTBY6.js");
8769
8788
  await openSubagentFleet(ctx, state, { initialKey: itemKey, asyncDirRoot: DIRS.async, resultsDir: DIRS.results, fleetKeybindings: config.fleetKeybindings, inspectorPlugins: () => getInspectorPlugins(pi) });
8770
8789
  } catch (error) {
8771
8790
  if (isStaleExtensionContextError(error)) {
@@ -8938,7 +8957,7 @@ function registerSubagentExtension(pi) {
8938
8957
  ])
8939
8958
  });
8940
8959
  } catch (error) {
8941
- console.error("Failed to clean retained async subagent state:", error);
8960
+ reportSessionWarning(state, `Failed to clean retained async subagent state: ${error instanceof Error ? error.message : String(error)}`, "async-retention-cleanup");
8942
8961
  }
8943
8962
  }, ASYNC_RETENTION_DELAY_MS);
8944
8963
  asyncRetentionTimer.unref?.();
@@ -8974,7 +8993,7 @@ function registerSubagentExtension(pi) {
8974
8993
  let executor;
8975
8994
  let executorPromise;
8976
8995
  let executorModulePromise;
8977
- const loadExecutorModule = () => executorModulePromise ??= import("./chunk-PUSTU4Q7.js");
8996
+ const loadExecutorModule = () => executorModulePromise ??= import("./chunk-BKISQ5CJ.js");
8978
8997
  const getExecutor = () => {
8979
8998
  executorPromise ??= loadExecutorModule().then(({ createSubagentExecutor }) => {
8980
8999
  executor = createSubagentExecutor(executorDeps);
@@ -8988,7 +9007,7 @@ function registerSubagentExtension(pi) {
8988
9007
  modulePreloadTimer = setTimeout(() => {
8989
9008
  loadExecutorModule().catch(() => {
8990
9009
  });
8991
- if (fleetViewEnabled) import("./chunk-2D2DQGC2.js").catch(() => {
9010
+ if (fleetViewEnabled) import("./chunk-PYKBTBY6.js").catch(() => {
8992
9011
  });
8993
9012
  }, MODULE_PRELOAD_DELAY_MS);
8994
9013
  modulePreloadTimer.unref?.();
@@ -9161,12 +9180,12 @@ ${close}` }]
9161
9180
  registerWaitTool(pi, state, waitToolConfig.enabled, waitSubscriptionManager, waitToolConfig.defaultTimeoutMs, void 0, supervisorChannel.hasPendingRequests);
9162
9181
  pi.on("agent_end", async (_event, ctx) => {
9163
9182
  try {
9164
- if (ctx.hasUI && ctx.signal?.aborted) {
9183
+ if (ctx.hasUI && ctx.signal?.aborted && !takeCompactionAbort(ctx.sessionManager)) {
9165
9184
  parentWake.userAborted();
9166
9185
  const active = activeAsyncJobCount();
9167
9186
  if (active > 0) ctx.ui.notify(`${active} background subagent run${active === 1 ? " is" : "s are"} still active${slashCommandsEnabled ? " \xB7 /subagents-stop" : ""}`, "info");
9168
9187
  }
9169
- if (!ctx.hasUI) await drainOutstandingWork({ state, events: pi.events, hasPendingSupervisorRequest: supervisorChannel.hasPendingRequests }).then(resultWatcher.deliverPendingResults);
9188
+ if (!ctx.hasUI) await drainOutstandingWork({ state, events: pi.events, hasPendingSupervisorRequest: supervisorChannel.hasPendingRequests, timeoutMs: resolveConfigDefaultTimeoutMs(config.timeoutMs) }).then(resultWatcher.deliverPendingResults);
9170
9189
  } finally {
9171
9190
  const ownerSessionId = state.currentSessionId;
9172
9191
  if (ownerSessionId) {
@@ -9477,9 +9496,11 @@ ${close}` }]
9477
9496
  }
9478
9497
  };
9479
9498
  let compactionResumeTimer;
9499
+ let compactionInterruptedParent = false;
9480
9500
  const cancelCompactionResume = () => {
9481
9501
  clearTimeout(compactionResumeTimer);
9482
9502
  compactionResumeTimer = void 0;
9503
+ compactionInterruptedParent = false;
9483
9504
  };
9484
9505
  pi.on("agent_start", () => {
9485
9506
  cancelCompactionResume();
@@ -9499,32 +9520,42 @@ ${close}` }]
9499
9520
  pi.on("session_before_compact", (event) => {
9500
9521
  if (event.reason !== "manual") suspendWidgetsForCompaction();
9501
9522
  });
9502
- pi.on("session_compact", (event) => {
9523
+ const wakeAfterCompaction = (completed) => (event, ctx) => {
9503
9524
  if (event.reason !== "manual") return;
9504
- if (activeAsyncJobCount() === 0 || !withLastUiContext(() => true)) return;
9505
- cancelCompactionResume();
9525
+ const sessionManager = ctx.sessionManager;
9526
+ if (completed && compactionInterruptedRun(sessionManager)) compactionInterruptedParent = true;
9527
+ if (compactionResumeTimer) return;
9506
9528
  const sessionId = state.currentSessionId;
9507
9529
  const deadline = Date.now() + COMPACTION_RESUME_DEADLINE_MS;
9508
- const resumeWhenIdle = () => {
9509
- if (state.currentSessionId !== sessionId || activeAsyncJobCount() === 0) return;
9510
- const idle = withLastUiContext((ctx) => ctx.isIdle());
9511
- if (idle === void 0) return;
9512
- if (!idle) {
9513
- if (Date.now() < deadline) compactionResumeTimer = setTimeout(resumeWhenIdle, COMPACTION_RESUME_POLL_MS);
9530
+ const wakeWhenIdle = () => {
9531
+ compactionResumeTimer = void 0;
9532
+ if (state.currentSessionId !== sessionId) return;
9533
+ let idle;
9534
+ try {
9535
+ idle = ctx.isIdle();
9536
+ } catch {
9514
9537
  return;
9515
9538
  }
9516
- parentWake.releaseHold();
9539
+ if (!idle || compactionInProgress(sessionManager)) {
9540
+ if (Date.now() < deadline) compactionResumeTimer = setTimeout(wakeWhenIdle, COMPACTION_RESUME_POLL_MS);
9541
+ return;
9542
+ }
9543
+ const interrupted = compactionInterruptedParent && activeAsyncJobCount() > 0 && withLastUiContext(() => true) === true;
9544
+ compactionInterruptedParent = false;
9545
+ if (!parentWake.takeDeferredWake() && !interrupted) return;
9517
9546
  parentWake.sendMessage(
9518
9547
  {
9519
9548
  customType: "subagent-compaction-resume",
9520
- content: "Compaction is complete. Resume the parent task now; background subagent results will arrive separately when ready.",
9549
+ content: interrupted ? "Compaction is complete. Resume the parent task now; background subagent results will arrive separately when ready." : "Compaction is complete. Act on the background subagent notices above.",
9521
9550
  display: false
9522
9551
  },
9523
9552
  { triggerTurn: true }
9524
9553
  );
9525
9554
  };
9526
- compactionResumeTimer = setTimeout(resumeWhenIdle, COMPACTION_RESUME_POLL_MS);
9527
- });
9555
+ compactionResumeTimer = setTimeout(wakeWhenIdle, COMPACTION_RESUME_POLL_MS);
9556
+ };
9557
+ pi.on("session_compact", wakeAfterCompaction(true));
9558
+ pi.on("session_compact_failed", wakeAfterCompaction(false));
9528
9559
  pi.on("session_start", (event, ctx) => {
9529
9560
  parentWake.bindSession(ctx);
9530
9561
  completionNotifier.bindSession(ctx.sessionManager);