wave-agent-sdk 0.19.5 → 0.19.7

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 (371) hide show
  1. package/dist/agent.d.ts +30 -14
  2. package/dist/agent.js +70 -56
  3. package/dist/constants/goalPrompts.d.ts +0 -1
  4. package/dist/constants/subagents.d.ts +0 -1
  5. package/dist/constants/toolLimits.d.ts +0 -1
  6. package/dist/constants/tools.d.ts +0 -1
  7. package/dist/core/plugin.d.ts +0 -1
  8. package/dist/core/session.d.ts +0 -1
  9. package/dist/index.d.ts +0 -1
  10. package/dist/managers/MemoryRuleManager.d.ts +0 -1
  11. package/dist/managers/aiManager.d.ts +15 -2
  12. package/dist/managers/aiManager.js +65 -11
  13. package/dist/managers/backgroundTaskManager.d.ts +1 -3
  14. package/dist/managers/backgroundTaskManager.js +20 -22
  15. package/dist/managers/bangManager.d.ts +0 -1
  16. package/dist/managers/bangManager.js +2 -1
  17. package/dist/managers/cronManager.d.ts +0 -1
  18. package/dist/managers/foregroundTaskManager.d.ts +0 -1
  19. package/dist/managers/forkedAgentManager.d.ts +0 -1
  20. package/dist/managers/goalManager.d.ts +0 -1
  21. package/dist/managers/hookManager.d.ts +0 -1
  22. package/dist/managers/liveConfigManager.d.ts +0 -1
  23. package/dist/managers/lspManager.d.ts +0 -1
  24. package/dist/managers/mcpManager.d.ts +0 -1
  25. package/dist/managers/messageManager.d.ts +7 -1
  26. package/dist/managers/messageManager.js +64 -5
  27. package/dist/managers/messageQueue.d.ts +25 -2
  28. package/dist/managers/messageQueue.js +53 -1
  29. package/dist/managers/permissionManager.d.ts +0 -1
  30. package/dist/managers/permissionManager.js +3 -3
  31. package/dist/managers/planManager.d.ts +0 -1
  32. package/dist/managers/pluginManager.d.ts +0 -1
  33. package/dist/managers/pluginScopeManager.d.ts +0 -1
  34. package/dist/managers/reversionManager.d.ts +0 -1
  35. package/dist/managers/skillManager.d.ts +0 -1
  36. package/dist/managers/slashCommandManager.d.ts +0 -1
  37. package/dist/managers/subagentManager.d.ts +0 -3
  38. package/dist/managers/subagentManager.js +15 -14
  39. package/dist/managers/toolManager.d.ts +0 -1
  40. package/dist/managers/workflowManager.d.ts +1 -2
  41. package/dist/managers/workflowManager.js +4 -4
  42. package/dist/prompts/autoMemory.d.ts +0 -1
  43. package/dist/prompts/autoMemoryExtraction.d.ts +0 -1
  44. package/dist/prompts/index.d.ts +3 -2
  45. package/dist/prompts/index.js +2 -4
  46. package/dist/prompts/planModeReminders.d.ts +0 -1
  47. package/dist/services/GitService.d.ts +0 -1
  48. package/dist/services/MarketplaceService.d.ts +0 -1
  49. package/dist/services/MemoryRuleService.d.ts +0 -1
  50. package/dist/services/aiService.d.ts +0 -1
  51. package/dist/services/authService.d.ts +0 -1
  52. package/dist/services/autoMemoryService.d.ts +0 -1
  53. package/dist/services/configurationService.d.ts +0 -1
  54. package/dist/services/fileWatcher.d.ts +0 -1
  55. package/dist/services/hook.d.ts +0 -1
  56. package/dist/services/hook.js +6 -0
  57. package/dist/services/initializationService.d.ts +0 -1
  58. package/dist/services/interactionService.d.ts +0 -1
  59. package/dist/services/interactionService.js +10 -0
  60. package/dist/services/jsonlHandler.d.ts +0 -1
  61. package/dist/services/memory.d.ts +0 -1
  62. package/dist/services/pluginLoader.d.ts +0 -1
  63. package/dist/services/remoteSettingsService.d.ts +0 -1
  64. package/dist/services/reversionService.d.ts +0 -1
  65. package/dist/services/session.d.ts +0 -1
  66. package/dist/services/taskManager.d.ts +0 -1
  67. package/dist/services/taskManager.js +8 -1
  68. package/dist/telemetry/events.d.ts +0 -1
  69. package/dist/telemetry/instrumentation.d.ts +0 -1
  70. package/dist/telemetry/sessionTracing.d.ts +0 -1
  71. package/dist/tools/agentTool.d.ts +0 -1
  72. package/dist/tools/askUserQuestion.d.ts +0 -1
  73. package/dist/tools/bashTool.d.ts +0 -1
  74. package/dist/tools/bashTool.js +7 -5
  75. package/dist/tools/buildTool.d.ts +0 -1
  76. package/dist/tools/cronCreateTool.d.ts +0 -1
  77. package/dist/tools/cronDeleteTool.d.ts +0 -1
  78. package/dist/tools/cronListTool.d.ts +0 -1
  79. package/dist/tools/editTool.d.ts +0 -1
  80. package/dist/tools/enterPlanMode.d.ts +0 -1
  81. package/dist/tools/enterWorktreeTool.d.ts +0 -1
  82. package/dist/tools/enterWorktreeTool.js +3 -8
  83. package/dist/tools/exitPlanMode.d.ts +0 -1
  84. package/dist/tools/exitWorktreeTool.d.ts +0 -1
  85. package/dist/tools/exitWorktreeTool.js +5 -8
  86. package/dist/tools/globTool.d.ts +0 -1
  87. package/dist/tools/grepTool.d.ts +0 -1
  88. package/dist/tools/lspTool.d.ts +0 -1
  89. package/dist/tools/readTool.d.ts +0 -1
  90. package/dist/tools/skillTool.d.ts +0 -1
  91. package/dist/tools/taskManagementTools.d.ts +0 -1
  92. package/dist/tools/taskStopTool.d.ts +0 -1
  93. package/dist/tools/types.d.ts +0 -1
  94. package/dist/tools/webFetchTool.d.ts +0 -1
  95. package/dist/tools/workflowTool.d.ts +0 -1
  96. package/dist/tools/writeTool.d.ts +0 -1
  97. package/dist/types/agent.d.ts +0 -1
  98. package/dist/types/auth.d.ts +0 -1
  99. package/dist/types/commands.d.ts +0 -1
  100. package/dist/types/config.d.ts +0 -1
  101. package/dist/types/configuration.d.ts +0 -1
  102. package/dist/types/core.d.ts +0 -1
  103. package/dist/types/cron.d.ts +0 -1
  104. package/dist/types/environment.d.ts +0 -1
  105. package/dist/types/fileSearch.d.ts +0 -1
  106. package/dist/types/history.d.ts +0 -1
  107. package/dist/types/hooks.d.ts +2 -1
  108. package/dist/types/index.d.ts +0 -1
  109. package/dist/types/lsp.d.ts +0 -1
  110. package/dist/types/marketplace.d.ts +0 -1
  111. package/dist/types/mcp.d.ts +0 -1
  112. package/dist/types/memoryRule.d.ts +0 -1
  113. package/dist/types/messaging.d.ts +2 -1
  114. package/dist/types/permissions.d.ts +0 -1
  115. package/dist/types/plugins.d.ts +0 -1
  116. package/dist/types/processes.d.ts +0 -1
  117. package/dist/types/reversion.d.ts +0 -1
  118. package/dist/types/session.d.ts +0 -1
  119. package/dist/types/skills.d.ts +0 -1
  120. package/dist/types/tasks.d.ts +0 -1
  121. package/dist/types/telemetry.d.ts +0 -1
  122. package/dist/types/tools.d.ts +0 -1
  123. package/dist/types/workflow.d.ts +0 -1
  124. package/dist/utils/abortUtils.d.ts +0 -1
  125. package/dist/utils/atomicWrite.d.ts +0 -1
  126. package/dist/utils/bashParser.d.ts +0 -1
  127. package/dist/utils/cacheControlUtils.d.ts +0 -1
  128. package/dist/utils/commandArgumentParser.d.ts +0 -1
  129. package/dist/utils/commandPathResolver.d.ts +0 -1
  130. package/dist/utils/configPaths.d.ts +0 -1
  131. package/dist/utils/configValidator.d.ts +0 -1
  132. package/dist/utils/constants.d.ts +0 -1
  133. package/dist/utils/container.d.ts +0 -1
  134. package/dist/utils/containerSetup.d.ts +0 -1
  135. package/dist/utils/containerSetup.js +3 -3
  136. package/dist/utils/convertMessagesForAPI.d.ts +0 -1
  137. package/dist/utils/cronTasks.d.ts +0 -1
  138. package/dist/utils/cronTasksLock.d.ts +0 -1
  139. package/dist/utils/cronToHuman.d.ts +0 -1
  140. package/dist/utils/customCommands.d.ts +0 -1
  141. package/dist/utils/editUtils.d.ts +0 -1
  142. package/dist/utils/fileFormat.d.ts +0 -1
  143. package/dist/utils/fileSearch.d.ts +0 -1
  144. package/dist/utils/fileUtils.d.ts +0 -1
  145. package/dist/utils/gitUtils.d.ts +0 -1
  146. package/dist/utils/globalLogger.d.ts +0 -1
  147. package/dist/utils/groupMessagesByApiRound.d.ts +0 -1
  148. package/dist/utils/hookMatcher.d.ts +0 -1
  149. package/dist/utils/markdownParser.d.ts +0 -1
  150. package/dist/utils/mcpUtils.d.ts +0 -1
  151. package/dist/utils/messageOperations.d.ts +0 -1
  152. package/dist/utils/modelCapabilities.d.ts +0 -1
  153. package/dist/utils/nameGenerator.d.ts +0 -1
  154. package/dist/utils/notificationXml.d.ts +0 -1
  155. package/dist/utils/openaiClient.d.ts +0 -1
  156. package/dist/utils/parseCronExpression.d.ts +0 -1
  157. package/dist/utils/path.d.ts +0 -1
  158. package/dist/utils/pathEncoder.d.ts +0 -1
  159. package/dist/utils/pathSafety.d.ts +0 -1
  160. package/dist/utils/promptHistory.d.ts +0 -1
  161. package/dist/utils/ripgrep.d.ts +0 -1
  162. package/dist/utils/shellResolver.d.ts +0 -1
  163. package/dist/utils/shellResolver.js +156 -7
  164. package/dist/utils/skillParser.d.ts +0 -1
  165. package/dist/utils/stringUtils.d.ts +0 -1
  166. package/dist/utils/subagentParser.d.ts +0 -1
  167. package/dist/utils/taskReminder.d.ts +0 -1
  168. package/dist/utils/tokenCalculation.d.ts +0 -1
  169. package/dist/utils/tokenEstimate.d.ts +0 -1
  170. package/dist/utils/toolResultStorage.d.ts +0 -1
  171. package/dist/utils/worktreeSession.d.ts +6 -7
  172. package/dist/utils/worktreeSession.js +7 -11
  173. package/dist/utils/worktreeUtils.d.ts +0 -1
  174. package/dist/workflow/budgetTracker.d.ts +0 -1
  175. package/dist/workflow/concurrencyLimiter.d.ts +0 -1
  176. package/dist/workflow/journal.d.ts +0 -1
  177. package/dist/workflow/progressReporter.d.ts +0 -1
  178. package/dist/workflow/runState.d.ts +0 -1
  179. package/dist/workflow/scriptRuntime.d.ts +0 -1
  180. package/dist/workflow/structuredOutput.d.ts +0 -1
  181. package/dist/workflow/types.d.ts +0 -1
  182. package/dist/workflow/workflowApis.d.ts +0 -1
  183. package/package.json +1 -1
  184. package/src/agent.ts +80 -67
  185. package/src/managers/aiManager.ts +79 -12
  186. package/src/managers/backgroundTaskManager.ts +21 -23
  187. package/src/managers/bangManager.ts +2 -1
  188. package/src/managers/messageManager.ts +72 -6
  189. package/src/managers/messageQueue.ts +60 -2
  190. package/src/managers/permissionManager.ts +6 -3
  191. package/src/managers/subagentManager.ts +22 -16
  192. package/src/managers/workflowManager.ts +5 -5
  193. package/src/prompts/index.ts +4 -4
  194. package/src/services/hook.ts +9 -0
  195. package/src/services/interactionService.ts +11 -0
  196. package/src/services/taskManager.ts +8 -1
  197. package/src/tools/bashTool.ts +11 -5
  198. package/src/tools/enterWorktreeTool.ts +4 -14
  199. package/src/tools/exitWorktreeTool.ts +5 -13
  200. package/src/types/hooks.ts +2 -0
  201. package/src/types/messaging.ts +2 -0
  202. package/src/utils/containerSetup.ts +3 -3
  203. package/src/utils/shellResolver.ts +167 -8
  204. package/src/utils/worktreeSession.ts +6 -16
  205. package/dist/agent.d.ts.map +0 -1
  206. package/dist/constants/goalPrompts.d.ts.map +0 -1
  207. package/dist/constants/subagents.d.ts.map +0 -1
  208. package/dist/constants/toolLimits.d.ts.map +0 -1
  209. package/dist/constants/tools.d.ts.map +0 -1
  210. package/dist/core/plugin.d.ts.map +0 -1
  211. package/dist/core/session.d.ts.map +0 -1
  212. package/dist/index.d.ts.map +0 -1
  213. package/dist/managers/MemoryRuleManager.d.ts.map +0 -1
  214. package/dist/managers/aiManager.d.ts.map +0 -1
  215. package/dist/managers/backgroundTaskManager.d.ts.map +0 -1
  216. package/dist/managers/bangManager.d.ts.map +0 -1
  217. package/dist/managers/cronManager.d.ts.map +0 -1
  218. package/dist/managers/foregroundTaskManager.d.ts.map +0 -1
  219. package/dist/managers/forkedAgentManager.d.ts.map +0 -1
  220. package/dist/managers/goalManager.d.ts.map +0 -1
  221. package/dist/managers/hookManager.d.ts.map +0 -1
  222. package/dist/managers/liveConfigManager.d.ts.map +0 -1
  223. package/dist/managers/lspManager.d.ts.map +0 -1
  224. package/dist/managers/mcpManager.d.ts.map +0 -1
  225. package/dist/managers/messageManager.d.ts.map +0 -1
  226. package/dist/managers/messageQueue.d.ts.map +0 -1
  227. package/dist/managers/notificationQueue.d.ts +0 -8
  228. package/dist/managers/notificationQueue.d.ts.map +0 -1
  229. package/dist/managers/notificationQueue.js +0 -17
  230. package/dist/managers/permissionManager.d.ts.map +0 -1
  231. package/dist/managers/planManager.d.ts.map +0 -1
  232. package/dist/managers/pluginManager.d.ts.map +0 -1
  233. package/dist/managers/pluginScopeManager.d.ts.map +0 -1
  234. package/dist/managers/reversionManager.d.ts.map +0 -1
  235. package/dist/managers/skillManager.d.ts.map +0 -1
  236. package/dist/managers/slashCommandManager.d.ts.map +0 -1
  237. package/dist/managers/subagentManager.d.ts.map +0 -1
  238. package/dist/managers/toolManager.d.ts.map +0 -1
  239. package/dist/managers/workflowManager.d.ts.map +0 -1
  240. package/dist/prompts/autoMemory.d.ts.map +0 -1
  241. package/dist/prompts/autoMemoryExtraction.d.ts.map +0 -1
  242. package/dist/prompts/index.d.ts.map +0 -1
  243. package/dist/prompts/planModeReminders.d.ts.map +0 -1
  244. package/dist/services/GitService.d.ts.map +0 -1
  245. package/dist/services/MarketplaceService.d.ts.map +0 -1
  246. package/dist/services/MemoryRuleService.d.ts.map +0 -1
  247. package/dist/services/aiService.d.ts.map +0 -1
  248. package/dist/services/authService.d.ts.map +0 -1
  249. package/dist/services/autoMemoryService.d.ts.map +0 -1
  250. package/dist/services/configurationService.d.ts.map +0 -1
  251. package/dist/services/fileWatcher.d.ts.map +0 -1
  252. package/dist/services/hook.d.ts.map +0 -1
  253. package/dist/services/initializationService.d.ts.map +0 -1
  254. package/dist/services/interactionService.d.ts.map +0 -1
  255. package/dist/services/jsonlHandler.d.ts.map +0 -1
  256. package/dist/services/memory.d.ts.map +0 -1
  257. package/dist/services/pluginLoader.d.ts.map +0 -1
  258. package/dist/services/remoteSettingsService.d.ts.map +0 -1
  259. package/dist/services/reversionService.d.ts.map +0 -1
  260. package/dist/services/session.d.ts.map +0 -1
  261. package/dist/services/taskManager.d.ts.map +0 -1
  262. package/dist/telemetry/events.d.ts.map +0 -1
  263. package/dist/telemetry/instrumentation.d.ts.map +0 -1
  264. package/dist/telemetry/sessionTracing.d.ts.map +0 -1
  265. package/dist/tools/agentTool.d.ts.map +0 -1
  266. package/dist/tools/askUserQuestion.d.ts.map +0 -1
  267. package/dist/tools/bashTool.d.ts.map +0 -1
  268. package/dist/tools/buildTool.d.ts.map +0 -1
  269. package/dist/tools/cronCreateTool.d.ts.map +0 -1
  270. package/dist/tools/cronDeleteTool.d.ts.map +0 -1
  271. package/dist/tools/cronListTool.d.ts.map +0 -1
  272. package/dist/tools/editTool.d.ts.map +0 -1
  273. package/dist/tools/enterPlanMode.d.ts.map +0 -1
  274. package/dist/tools/enterWorktreeTool.d.ts.map +0 -1
  275. package/dist/tools/exitPlanMode.d.ts.map +0 -1
  276. package/dist/tools/exitWorktreeTool.d.ts.map +0 -1
  277. package/dist/tools/globTool.d.ts.map +0 -1
  278. package/dist/tools/grepTool.d.ts.map +0 -1
  279. package/dist/tools/lspTool.d.ts.map +0 -1
  280. package/dist/tools/readTool.d.ts.map +0 -1
  281. package/dist/tools/skillTool.d.ts.map +0 -1
  282. package/dist/tools/taskManagementTools.d.ts.map +0 -1
  283. package/dist/tools/taskStopTool.d.ts.map +0 -1
  284. package/dist/tools/types.d.ts.map +0 -1
  285. package/dist/tools/webFetchTool.d.ts.map +0 -1
  286. package/dist/tools/workflowTool.d.ts.map +0 -1
  287. package/dist/tools/writeTool.d.ts.map +0 -1
  288. package/dist/types/agent.d.ts.map +0 -1
  289. package/dist/types/auth.d.ts.map +0 -1
  290. package/dist/types/commands.d.ts.map +0 -1
  291. package/dist/types/config.d.ts.map +0 -1
  292. package/dist/types/configuration.d.ts.map +0 -1
  293. package/dist/types/core.d.ts.map +0 -1
  294. package/dist/types/cron.d.ts.map +0 -1
  295. package/dist/types/environment.d.ts.map +0 -1
  296. package/dist/types/fileSearch.d.ts.map +0 -1
  297. package/dist/types/history.d.ts.map +0 -1
  298. package/dist/types/hooks.d.ts.map +0 -1
  299. package/dist/types/index.d.ts.map +0 -1
  300. package/dist/types/lsp.d.ts.map +0 -1
  301. package/dist/types/marketplace.d.ts.map +0 -1
  302. package/dist/types/mcp.d.ts.map +0 -1
  303. package/dist/types/memoryRule.d.ts.map +0 -1
  304. package/dist/types/messaging.d.ts.map +0 -1
  305. package/dist/types/permissions.d.ts.map +0 -1
  306. package/dist/types/plugins.d.ts.map +0 -1
  307. package/dist/types/processes.d.ts.map +0 -1
  308. package/dist/types/reversion.d.ts.map +0 -1
  309. package/dist/types/session.d.ts.map +0 -1
  310. package/dist/types/skills.d.ts.map +0 -1
  311. package/dist/types/tasks.d.ts.map +0 -1
  312. package/dist/types/telemetry.d.ts.map +0 -1
  313. package/dist/types/tools.d.ts.map +0 -1
  314. package/dist/types/workflow.d.ts.map +0 -1
  315. package/dist/utils/abortUtils.d.ts.map +0 -1
  316. package/dist/utils/atomicWrite.d.ts.map +0 -1
  317. package/dist/utils/bashParser.d.ts.map +0 -1
  318. package/dist/utils/cacheControlUtils.d.ts.map +0 -1
  319. package/dist/utils/commandArgumentParser.d.ts.map +0 -1
  320. package/dist/utils/commandPathResolver.d.ts.map +0 -1
  321. package/dist/utils/configPaths.d.ts.map +0 -1
  322. package/dist/utils/configValidator.d.ts.map +0 -1
  323. package/dist/utils/constants.d.ts.map +0 -1
  324. package/dist/utils/container.d.ts.map +0 -1
  325. package/dist/utils/containerSetup.d.ts.map +0 -1
  326. package/dist/utils/convertMessagesForAPI.d.ts.map +0 -1
  327. package/dist/utils/cronTasks.d.ts.map +0 -1
  328. package/dist/utils/cronTasksLock.d.ts.map +0 -1
  329. package/dist/utils/cronToHuman.d.ts.map +0 -1
  330. package/dist/utils/customCommands.d.ts.map +0 -1
  331. package/dist/utils/editUtils.d.ts.map +0 -1
  332. package/dist/utils/fileFormat.d.ts.map +0 -1
  333. package/dist/utils/fileSearch.d.ts.map +0 -1
  334. package/dist/utils/fileUtils.d.ts.map +0 -1
  335. package/dist/utils/gitUtils.d.ts.map +0 -1
  336. package/dist/utils/globalLogger.d.ts.map +0 -1
  337. package/dist/utils/groupMessagesByApiRound.d.ts.map +0 -1
  338. package/dist/utils/hookMatcher.d.ts.map +0 -1
  339. package/dist/utils/markdownParser.d.ts.map +0 -1
  340. package/dist/utils/mcpUtils.d.ts.map +0 -1
  341. package/dist/utils/messageOperations.d.ts.map +0 -1
  342. package/dist/utils/modelCapabilities.d.ts.map +0 -1
  343. package/dist/utils/nameGenerator.d.ts.map +0 -1
  344. package/dist/utils/notificationXml.d.ts.map +0 -1
  345. package/dist/utils/openaiClient.d.ts.map +0 -1
  346. package/dist/utils/parseCronExpression.d.ts.map +0 -1
  347. package/dist/utils/path.d.ts.map +0 -1
  348. package/dist/utils/pathEncoder.d.ts.map +0 -1
  349. package/dist/utils/pathSafety.d.ts.map +0 -1
  350. package/dist/utils/promptHistory.d.ts.map +0 -1
  351. package/dist/utils/ripgrep.d.ts.map +0 -1
  352. package/dist/utils/shellResolver.d.ts.map +0 -1
  353. package/dist/utils/skillParser.d.ts.map +0 -1
  354. package/dist/utils/stringUtils.d.ts.map +0 -1
  355. package/dist/utils/subagentParser.d.ts.map +0 -1
  356. package/dist/utils/taskReminder.d.ts.map +0 -1
  357. package/dist/utils/tokenCalculation.d.ts.map +0 -1
  358. package/dist/utils/tokenEstimate.d.ts.map +0 -1
  359. package/dist/utils/toolResultStorage.d.ts.map +0 -1
  360. package/dist/utils/worktreeSession.d.ts.map +0 -1
  361. package/dist/utils/worktreeUtils.d.ts.map +0 -1
  362. package/dist/workflow/budgetTracker.d.ts.map +0 -1
  363. package/dist/workflow/concurrencyLimiter.d.ts.map +0 -1
  364. package/dist/workflow/journal.d.ts.map +0 -1
  365. package/dist/workflow/progressReporter.d.ts.map +0 -1
  366. package/dist/workflow/runState.d.ts.map +0 -1
  367. package/dist/workflow/scriptRuntime.d.ts.map +0 -1
  368. package/dist/workflow/structuredOutput.d.ts.map +0 -1
  369. package/dist/workflow/types.d.ts.map +0 -1
  370. package/dist/workflow/workflowApis.d.ts.map +0 -1
  371. package/src/managers/notificationQueue.ts +0 -19
package/dist/agent.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type QueuedMessage } from "./managers/messageQueue.js";
2
2
  import { SlashCommand, CustomSlashCommand, AgentOptions } from "./types/index.js";
3
3
  import type { Message, McpServerStatus, GatewayConfig, ModelConfig, Usage, PermissionMode, ForegroundTask } from "./types/index.js";
4
+ import type { WorktreeSession } from "./utils/worktreeSession.js";
4
5
  export declare class Agent {
5
6
  private messageManager;
6
7
  private aiManager;
@@ -21,9 +22,8 @@ export declare class Agent {
21
22
  private goalManager;
22
23
  private hookManager;
23
24
  private reversionManager;
24
- private notificationQueue;
25
25
  private messageQueue;
26
- private pendingNotificationPromises;
26
+ private dispatchPromise;
27
27
  private memoryRuleManager;
28
28
  private liveConfigManager;
29
29
  private taskManager;
@@ -71,6 +71,12 @@ export declare class Agent {
71
71
  * @param newCwd - The new working directory
72
72
  */
73
73
  setWorkdir(newCwd: string): void;
74
+ /**
75
+ * Set this session's worktree session state (used by CLI -w startup to inject the
76
+ * session created before the agent existed). Delegates to AIManager so the state is
77
+ * stored in this agent's own DI container.
78
+ */
79
+ setWorktreeSession(session: WorktreeSession | null): void;
74
80
  /** Get project memory content */
75
81
  get projectMemory(): string;
76
82
  /** Get user memory content */
@@ -83,7 +89,7 @@ export declare class Agent {
83
89
  get isCompacting(): boolean;
84
90
  /** Get bash command execution status */
85
91
  get isCommandRunning(): boolean;
86
- /** Get queued messages */
92
+ /** Get queued user-facing messages (excludes background notifications) */
87
93
  get queuedMessages(): QueuedMessage[];
88
94
  /** Get goal status string */
89
95
  get goalStatus(): string;
@@ -107,13 +113,29 @@ export declare class Agent {
107
113
  */
108
114
  removeQueuedMessageById(id: string): boolean;
109
115
  /**
110
- * Unified dequeue trigger checks state machine before processing.
111
- * Called from onMessageEnqueued, onLoadingChange(false), and
112
- * onCommandRunningChange(false).
116
+ * Update a queued message's content by its ID (does not change queue order)
117
+ * @param id - The ID of the message to update
118
+ * @param patch - The fields to update
119
+ * @returns true if the message was updated, false if not found
120
+ */
121
+ updateQueuedMessageById(id: string, patch: {
122
+ content?: string;
123
+ images?: Array<{
124
+ path: string;
125
+ mimeType: string;
126
+ }>;
127
+ type?: "message" | "bang";
128
+ }): boolean;
129
+ /**
130
+ * Unified dispatch trigger — checks state machine before processing.
131
+ * Handles user messages, bang commands, and background task notifications
132
+ * through a single serialized path. Called from onMessageEnqueued,
133
+ * onLoadingChange(false), and onCommandRunningChange(false).
113
134
  */
114
- private tryDequeue;
135
+ private tryDispatch;
115
136
  /**
116
- * Process the next queued message when the agent becomes idle.
137
+ * Process the next queued item when the agent becomes idle.
138
+ * Handles three item types: user messages, bang commands, and notifications.
117
139
  */
118
140
  private processQueuedMessage;
119
141
  /** Get background bash shell output */
@@ -200,11 +222,6 @@ export declare class Agent {
200
222
  */
201
223
  restoreSession(sessionId: string): Promise<void>;
202
224
  abortAIMessage(): void;
203
- /**
204
- * Process pending background task notifications by injecting them as user messages
205
- * and triggering a new AI response cycle.
206
- */
207
- private processPendingNotifications;
208
225
  /** Execute bash command (bang command) */
209
226
  bang(command: string): Promise<void>;
210
227
  clearMessages(): Promise<void>;
@@ -374,4 +391,3 @@ export declare class Agent {
374
391
  */
375
392
  get hasRunningBackgroundWork(): boolean;
376
393
  }
377
- //# sourceMappingURL=agent.d.ts.map
package/dist/agent.js CHANGED
@@ -51,7 +51,7 @@ export class Agent {
51
51
  */
52
52
  constructor(options) {
53
53
  this.bangManager = null;
54
- this.pendingNotificationPromises = []; // Track pending notification processing
54
+ this.dispatchPromise = null; // Track current dispatch for teardown
55
55
  this.sessionStartTime = Date.now();
56
56
  const { logger, workdir, systemPrompt, stream = true } = options;
57
57
  // Set working directory early as we need it for loading configuration
@@ -111,36 +111,27 @@ export class Agent {
111
111
  this.bangManager = this.container.get("BangManager");
112
112
  this.cronManager = this.container.get("CronManager");
113
113
  this.goalManager = this.container.get("GoalManager");
114
- this.notificationQueue = this.container.get("NotificationQueue");
115
114
  this.messageQueue = this.container.get("MessageQueue");
116
- // Wire up notification queue to trigger AI when notifications arrive while idle
117
- this.notificationQueue.onNotificationsEnqueued = () => {
118
- // If the AI is NOT loading (idle), trigger a new AI cycle to process notifications
119
- if (!this.aiManager.isLoading) {
120
- const pendingPromise = this.processPendingNotifications().catch((error) => {
121
- this.logger?.error("Failed to process pending notifications:", error);
122
- });
123
- this.pendingNotificationPromises.push(pendingPromise);
124
- }
125
- };
126
115
  // Wire up CWD change callback from AIManager to sync Agent's workdir
127
116
  this.aiManager.setOnCwdChange((newCwd) => {
128
117
  this.workdir = newCwd;
129
118
  this.container.register("Workdir", newCwd);
130
119
  this.options.callbacks?.onWorkdirChange?.(newCwd);
131
120
  });
132
- // Wire up message queue to process when agent becomes idle
133
- this.messageQueue.onMessageEnqueued = () => this.tryDequeue();
121
+ // Wire up message queue to process when agent becomes idle.
122
+ // Both user messages and background task notifications enqueue here,
123
+ // unified through a single dispatch path (tryDispatch).
124
+ this.messageQueue.onMessageEnqueued = () => this.tryDispatch();
134
125
  // Wire up AI loading changes to process queue when AI becomes idle
135
126
  this.aiManager.onLoadingChange = (loading) => {
136
127
  if (!loading)
137
- this.tryDequeue();
128
+ this.tryDispatch();
138
129
  };
139
130
  // Wire up bang manager callback for command running changes
140
131
  this.bangManager.onCommandRunningChange = (running) => {
141
132
  this.options.callbacks?.onCommandRunningChange?.(running);
142
133
  if (!running)
143
- this.tryDequeue();
134
+ this.tryDispatch();
144
135
  };
145
136
  // Set initial permission mode if provided
146
137
  if (options.permissionMode) {
@@ -184,6 +175,14 @@ export class Agent {
184
175
  this.container.register("Workdir", newCwd);
185
176
  this.options.callbacks?.onWorkdirChange?.(newCwd);
186
177
  }
178
+ /**
179
+ * Set this session's worktree session state (used by CLI -w startup to inject the
180
+ * session created before the agent existed). Delegates to AIManager so the state is
181
+ * stored in this agent's own DI container.
182
+ */
183
+ setWorktreeSession(session) {
184
+ this.aiManager.setWorktreeSession(session);
185
+ }
187
186
  /** Get project memory content */
188
187
  get projectMemory() {
189
188
  const memoryService = this.container.get("MemoryService");
@@ -210,9 +209,11 @@ export class Agent {
210
209
  get isCommandRunning() {
211
210
  return this.bangManager?.isCommandRunning ?? false;
212
211
  }
213
- /** Get queued messages */
212
+ /** Get queued user-facing messages (excludes background notifications) */
214
213
  get queuedMessages() {
215
- return this.messageQueue.getQueue();
214
+ return this.messageQueue
215
+ .getQueue()
216
+ .filter((m) => m.type !== "notification");
216
217
  }
217
218
  /** Get goal status string */
218
219
  get goalStatus() {
@@ -258,11 +259,25 @@ export class Agent {
258
259
  return removed;
259
260
  }
260
261
  /**
261
- * Unified dequeue trigger checks state machine before processing.
262
- * Called from onMessageEnqueued, onLoadingChange(false), and
263
- * onCommandRunningChange(false).
262
+ * Update a queued message's content by its ID (does not change queue order)
263
+ * @param id - The ID of the message to update
264
+ * @param patch - The fields to update
265
+ * @returns true if the message was updated, false if not found
266
+ */
267
+ updateQueuedMessageById(id, patch) {
268
+ const updated = this.messageQueue.updateById(id, patch);
269
+ if (updated) {
270
+ this.options.callbacks?.onQueuedMessagesChange?.(this.queuedMessages);
271
+ }
272
+ return updated;
273
+ }
274
+ /**
275
+ * Unified dispatch trigger — checks state machine before processing.
276
+ * Handles user messages, bang commands, and background task notifications
277
+ * through a single serialized path. Called from onMessageEnqueued,
278
+ * onLoadingChange(false), and onCommandRunningChange(false).
264
279
  */
265
- tryDequeue() {
280
+ tryDispatch() {
266
281
  if (this.messageQueue.state !== "idle")
267
282
  return;
268
283
  if (!this.messageQueue.hasPending())
@@ -270,17 +285,19 @@ export class Agent {
270
285
  if (this.aiManager.isLoading || this.isCommandRunning)
271
286
  return;
272
287
  this.messageQueue.transitionTo("dispatching");
273
- this.processQueuedMessage()
288
+ this.dispatchPromise = this.processQueuedMessage()
274
289
  .catch((error) => {
275
290
  this.logger?.error("Failed to process queued message:", error);
276
291
  })
277
292
  .finally(() => {
278
293
  this.messageQueue.transitionTo("idle");
279
- this.tryDequeue(); // Re-check after processing
294
+ this.dispatchPromise = null;
295
+ this.tryDispatch(); // Re-check after processing
280
296
  });
281
297
  }
282
298
  /**
283
- * Process the next queued message when the agent becomes idle.
299
+ * Process the next queued item when the agent becomes idle.
300
+ * Handles three item types: user messages, bang commands, and notifications.
284
301
  */
285
302
  async processQueuedMessage() {
286
303
  const next = this.messageQueue.dequeue();
@@ -292,6 +309,26 @@ export class Agent {
292
309
  await this.bangManager?.executeCommand(next.content);
293
310
  await this.messageManager.saveSession();
294
311
  }
312
+ else if (next.type === "notification") {
313
+ // Drain all pending notifications and batch them into a single AI turn
314
+ const allNotifications = [
315
+ next.content,
316
+ ...this.messageQueue.drainNotifications(),
317
+ ];
318
+ for (const xml of allNotifications) {
319
+ const block = parseTaskNotificationXml(xml);
320
+ if (block) {
321
+ this.messageManager.addNotificationMessage({
322
+ taskId: block.taskId,
323
+ taskType: block.taskType,
324
+ status: block.status,
325
+ summary: block.summary,
326
+ outputFile: block.outputFile,
327
+ });
328
+ }
329
+ }
330
+ await this.aiManager.sendAIMessage({ recursionDepth: 0 });
331
+ }
295
332
  else {
296
333
  await this.sendMessage(next.content, next.images);
297
334
  }
@@ -468,29 +505,6 @@ export class Agent {
468
505
  abortAIMessage() {
469
506
  this.aiManager.abortAIMessage();
470
507
  }
471
- /**
472
- * Process pending background task notifications by injecting them as user messages
473
- * and triggering a new AI response cycle.
474
- */
475
- async processPendingNotifications() {
476
- const notifications = this.notificationQueue.dequeueAll();
477
- if (notifications.length === 0)
478
- return;
479
- for (const notification of notifications) {
480
- const block = parseTaskNotificationXml(notification);
481
- if (block) {
482
- this.messageManager.addNotificationMessage({
483
- taskId: block.taskId,
484
- taskType: block.taskType,
485
- status: block.status,
486
- summary: block.summary,
487
- outputFile: block.outputFile,
488
- });
489
- }
490
- }
491
- // Trigger AI to process the notifications
492
- await this.aiManager.sendAIMessage({ recursionDepth: 0 });
493
- }
494
508
  /** Execute bash command (bang command) */
495
509
  async bang(command) {
496
510
  // If the agent is busy, enqueue the bang command
@@ -619,8 +633,9 @@ export class Agent {
619
633
  /** Unified interrupt method, interrupts both AI messages and command execution */
620
634
  abortMessage() {
621
635
  if (this.aiManager.isLoading || this.isCommandRunning) {
622
- // Clear queue first to prevent processQueuedMessage from dequeuing
623
- // when abortAIMessage triggers onLoadingChange(false)
636
+ // Clear user-facing queue items first to prevent processQueuedMessage
637
+ // from dequeuing when abortAIMessage triggers onLoadingChange(false).
638
+ // Notifications are preserved so background task results aren't lost.
624
639
  this.messageQueue.clear();
625
640
  this.options.callbacks?.onQueuedMessagesChange?.(this.queuedMessages);
626
641
  }
@@ -694,14 +709,13 @@ export class Agent {
694
709
  exitReason: "destroy",
695
710
  }).catch(() => { });
696
711
  await shutdownTelemetry();
697
- // Clear notification callback first to prevent any late triggers from
712
+ // Clear message queue callback first to prevent any late triggers from
698
713
  // starting async work during teardown
699
- this.notificationQueue.onNotificationsEnqueued = undefined;
700
- // Await any pending notification processing to prevent race conditions
714
+ this.messageQueue.onMessageEnqueued = undefined;
715
+ // Await any pending dispatch to prevent race conditions
701
716
  // with test teardown (e.g., V8 coverage stream cleanup)
702
- if (this.pendingNotificationPromises.length > 0) {
703
- await Promise.allSettled(this.pendingNotificationPromises);
704
- this.pendingNotificationPromises = [];
717
+ if (this.dispatchPromise) {
718
+ await this.dispatchPromise.catch(() => { });
705
719
  }
706
720
  // Fire SessionEnd hooks (fire-and-forget, don't block shutdown)
707
721
  try {
@@ -1,2 +1 @@
1
1
  export declare const GOAL_EVALUATION_SYSTEM_PROMPT = "You are a goal evaluator. Given a goal condition and a conversation, determine whether the goal has been achieved.\n\nRules:\n- Judge ONLY based on what the conversation shows \u2014 tool outputs, test results, file contents, etc.\n- Do NOT assume work is done without evidence in the conversation.\n- Be strict and conservative: when uncertain, return met: false.\n- Be concise: your reason should be 1-2 sentences.\n\nRespond with JSON only, no other text:\n{\"met\": boolean, \"reason\": \"short explanation\"}";
2
- //# sourceMappingURL=goalPrompts.d.ts.map
@@ -2,4 +2,3 @@ export declare const BASH_SUBAGENT_TYPE = "Bash";
2
2
  export declare const EXPLORE_SUBAGENT_TYPE = "Explore";
3
3
  export declare const PLAN_SUBAGENT_TYPE = "Plan";
4
4
  export declare const GENERAL_PURPOSE_SUBAGENT_TYPE = "general-purpose";
5
- //# sourceMappingURL=subagents.d.ts.map
@@ -9,4 +9,3 @@ export declare const BASH_MAX_OUTPUT_CHARS = 30000;
9
9
  export declare const SKILL_BASH_MAX_OUTPUT_CHARS = 30000;
10
10
  /** Preview size in characters when output is persisted to disk. */
11
11
  export declare const PREVIEW_SIZE_BYTES = 2048;
12
- //# sourceMappingURL=toolLimits.d.ts.map
@@ -22,4 +22,3 @@ export declare const WEB_FETCH_TOOL_NAME = "WebFetch";
22
22
  export declare const ENTER_WORKTREE_TOOL_NAME = "EnterWorktree";
23
23
  export declare const EXIT_WORKTREE_TOOL_NAME = "ExitWorktree";
24
24
  export declare const WORKFLOW_TOOL_NAME = "Workflow";
25
- //# sourceMappingURL=tools.d.ts.map
@@ -87,4 +87,3 @@ export declare class PluginCore {
87
87
  */
88
88
  removeEnabledPlugin(scope: Scope, pluginId: string): Promise<void>;
89
89
  }
90
- //# sourceMappingURL=plugin.d.ts.map
@@ -1,3 +1,2 @@
1
1
  export { listSessions, listAllSessions, truncateContent, loadSessionFromJsonl, loadFullMessageThread, deleteSession, } from "../services/session.js";
2
2
  export type { SessionMetadata, SessionData } from "../services/session.js";
3
- //# sourceMappingURL=session.d.ts.map
package/dist/index.d.ts CHANGED
@@ -25,4 +25,3 @@ export * from "./utils/worktreeSession.js";
25
25
  export * from "./types/index.js";
26
26
  export * from "./tools/buildTool.js";
27
27
  export type { ToolPlugin, ToolResult, ToolContext } from "./tools/types.js";
28
- //# sourceMappingURL=index.d.ts.map
@@ -39,4 +39,3 @@ export declare class MemoryRuleManager {
39
39
  */
40
40
  reload(): Promise<void>;
41
41
  }
42
- //# sourceMappingURL=MemoryRuleManager.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import type { GatewayConfig, ModelConfig, Usage } from "../types/index.js";
2
2
  import { Container } from "../utils/container.js";
3
+ import type { WorktreeSession } from "../utils/worktreeSession.js";
3
4
  export interface AIManagerCallbacks {
4
5
  onCompactionStateChange?: (isCompacting: boolean) => void;
5
6
  onUsageAdded?: (usage: Usage) => void;
@@ -20,6 +21,7 @@ export interface AIManagerOptions {
20
21
  export declare class AIManager {
21
22
  private container;
22
23
  isLoading: boolean;
24
+ private turnGeneration;
23
25
  private abortController;
24
26
  onLoadingChange?: (loading: boolean) => void;
25
27
  private toolAbortController;
@@ -60,9 +62,21 @@ export declare class AIManager {
60
62
  getOriginalWorkdir(): string;
61
63
  /**
62
64
  * Update the working directory mid-session (e.g., when entering/exiting a worktree).
63
- * Also updates process.chdir() so bash commands use the new directory.
65
+ * Only updates this session's DI container; it does NOT change the process-level
66
+ * process.cwd(), so concurrent sessions in the same stdio process are unaffected.
67
+ * Triggers `_onCwdChange` (wired by Agent to `onWorkdirChange`) so the host is
68
+ * notified of worktree switches. Unlike bash `cd`, this does NOT run CwdChanged
69
+ * hooks (worktree has its own WorktreeCreate/WorktreeRemove hooks).
64
70
  */
65
71
  setWorkdir(newWorkdir: string): void;
72
+ /**
73
+ * Get this session's worktree session state (null if not in a worktree).
74
+ */
75
+ getWorktreeSession(): WorktreeSession | null;
76
+ /**
77
+ * Set this session's worktree session state.
78
+ */
79
+ setWorktreeSession(session: WorktreeSession | null): void;
66
80
  setOnCwdChange(callback: (newCwd: string) => void): void;
67
81
  private isCompacting;
68
82
  private callbacks;
@@ -126,4 +140,3 @@ export declare class AIManager {
126
140
  */
127
141
  private executePostToolUseHooks;
128
142
  }
129
- //# sourceMappingURL=aiManager.d.ts.map
@@ -53,6 +53,7 @@ export class AIManager {
53
53
  constructor(container, options) {
54
54
  this.container = container;
55
55
  this.isLoading = false;
56
+ this.turnGeneration = 0; // Guards against concurrent sendAIMessage turns
56
57
  this.abortController = null;
57
58
  this.toolAbortController = null;
58
59
  this.consecutiveCompactionFailures = 0;
@@ -135,11 +136,27 @@ export class AIManager {
135
136
  }
136
137
  /**
137
138
  * Update the working directory mid-session (e.g., when entering/exiting a worktree).
138
- * Also updates process.chdir() so bash commands use the new directory.
139
+ * Only updates this session's DI container; it does NOT change the process-level
140
+ * process.cwd(), so concurrent sessions in the same stdio process are unaffected.
141
+ * Triggers `_onCwdChange` (wired by Agent to `onWorkdirChange`) so the host is
142
+ * notified of worktree switches. Unlike bash `cd`, this does NOT run CwdChanged
143
+ * hooks (worktree has its own WorktreeCreate/WorktreeRemove hooks).
139
144
  */
140
145
  setWorkdir(newWorkdir) {
141
146
  this.container.register("Workdir", newWorkdir);
142
- process.chdir(newWorkdir);
147
+ this._onCwdChange?.(newWorkdir);
148
+ }
149
+ /**
150
+ * Get this session's worktree session state (null if not in a worktree).
151
+ */
152
+ getWorktreeSession() {
153
+ return (this.container.get("WorktreeSession") ?? null);
154
+ }
155
+ /**
156
+ * Set this session's worktree session state.
157
+ */
158
+ setWorktreeSession(session) {
159
+ this.container.register("WorktreeSession", session);
143
160
  }
144
161
  setOnCwdChange(callback) {
145
162
  this._onCwdChange = callback;
@@ -225,6 +242,9 @@ export class AIManager {
225
242
  options?.callbacks?.onLoadingChange?.(isLoading);
226
243
  }
227
244
  abortAIMessage() {
245
+ // Bump generation so the in-flight turn's end-of-turn setIsLoading(false)
246
+ // is skipped (generation mismatch), preventing it from racing with this abort.
247
+ this.turnGeneration++;
228
248
  // Interrupt AI service
229
249
  if (this.abortController) {
230
250
  try {
@@ -544,6 +564,14 @@ export class AIManager {
544
564
  async sendAIMessage(options = {}) {
545
565
  const { recursionDepth = 0, model, allowedRules, maxTokens } = options;
546
566
  let turnOffset = recursionDepth;
567
+ // Reserve this turn synchronously before any async work. Bumping the
568
+ // generation invalidates any in-flight turn's end-of-turn cleanup, and
569
+ // recording myGeneration lets us skip cleanup if a newer turn (or abort)
570
+ // has superseded us. setIsLoading(true) here also closes the "idle but
571
+ // previous turn not finished" race window by marking us busy immediately.
572
+ this.turnGeneration++;
573
+ const myGeneration = this.turnGeneration;
574
+ this.setIsLoading(true);
547
575
  outer: while (true) {
548
576
  let shouldRestart = false;
549
577
  // OpenTelemetry: start interaction span for this turn (initial call only)
@@ -561,9 +589,8 @@ export class AIManager {
561
589
  prompt_length: String(userPromptText.length),
562
590
  }).catch(() => { }); // Non-blocking
563
591
  }
564
- // Set loading state early for the initial call, before any async work
592
+ // Apply allowed rules for the initial call
565
593
  if (turnOffset === 0) {
566
- this.setIsLoading(true);
567
594
  if (allowedRules && allowedRules.length > 0) {
568
595
  this.permissionManager?.addTemporaryRules(allowedRules);
569
596
  }
@@ -657,6 +684,7 @@ export class AIManager {
657
684
  originalWorkdir: this.getOriginalWorkdir(),
658
685
  language: this.getLanguage(),
659
686
  isSubagent: !!this.subagentType,
687
+ worktreeSession: this.getWorktreeSession(),
660
688
  autoMemory: autoMemoryOptions,
661
689
  }), // Pass custom system prompt
662
690
  maxTokens: maxTokens, // Pass max tokens override
@@ -941,6 +969,12 @@ export class AIManager {
941
969
  error_type: error instanceof Error ? error.constructor.name : "Unknown",
942
970
  message: error instanceof Error ? error.message : String(error),
943
971
  }).catch(() => { }); // Non-blocking
972
+ // Finalize any streaming text/reasoning blocks so the UI stops ticking
973
+ // its in-progress timer (e.g. when the request is aborted mid-thought).
974
+ this.messageManager.finalizeStreamingBlocks();
975
+ // Finalize any tool blocks stuck in start/streaming/running so the UI
976
+ // stops showing the yellow "running" spinner (e.g. abort mid-tool-stream).
977
+ this.messageManager.finalizeAbortedToolBlocks(error instanceof Error ? error.message : undefined);
944
978
  this.messageManager.addErrorBlock(error instanceof Error ? error.message : "Unknown error occurred");
945
979
  // Exit inner loop on error
946
980
  break inner;
@@ -953,8 +987,6 @@ export class AIManager {
953
987
  endInteractionSpan();
954
988
  // Save session in each iteration to ensure message persistence
955
989
  await this.messageManager.saveSession();
956
- // Set loading to false first
957
- this.setIsLoading(false);
958
990
  // Clear temporary rules
959
991
  this.permissionManager?.clearTemporaryRules();
960
992
  // Clear abort controllers
@@ -1035,11 +1067,11 @@ export class AIManager {
1035
1067
  }
1036
1068
  // Inject pending notifications from background tasks (after Stop hooks,
1037
1069
  // aligned with Claude Code which fires Stop hooks unconditionally)
1038
- const notificationQueue = this.container.has("NotificationQueue")
1039
- ? this.container.get("NotificationQueue")
1070
+ const messageQueue = this.container.has("MessageQueue")
1071
+ ? this.container.get("MessageQueue")
1040
1072
  : undefined;
1041
- if (notificationQueue && notificationQueue.hasPending()) {
1042
- const notifications = notificationQueue.dequeueAll();
1073
+ if (messageQueue && messageQueue.hasNotifications()) {
1074
+ const notifications = messageQueue.drainNotifications();
1043
1075
  for (const notification of notifications) {
1044
1076
  const block = parseTaskNotificationXml(notification);
1045
1077
  if (block) {
@@ -1057,8 +1089,16 @@ export class AIManager {
1057
1089
  turnOffset = 0;
1058
1090
  }
1059
1091
  }
1060
- if (!shouldRestart)
1092
+ if (!shouldRestart) {
1093
+ // Release loading state only after ALL cleanup is done (session save,
1094
+ // Stop hooks, notification injection). Generation check ensures a
1095
+ // superseded (aborted or newer) turn doesn't clobber the current
1096
+ // loading state.
1097
+ if (myGeneration === this.turnGeneration) {
1098
+ this.setIsLoading(false);
1099
+ }
1061
1100
  break outer;
1101
+ }
1062
1102
  }
1063
1103
  }
1064
1104
  /**
@@ -1088,6 +1128,19 @@ export class AIManager {
1088
1128
  prompt: j.prompt,
1089
1129
  }))
1090
1130
  : undefined;
1131
+ // Extract text content from the last assistant message so hooks can
1132
+ // inspect the final response without reading the transcript file.
1133
+ const allMessages = this.messageManager.getMessages();
1134
+ const lastAssistant = [...allMessages]
1135
+ .reverse()
1136
+ .find((m) => m.role === "assistant");
1137
+ const lastAssistantText = lastAssistant
1138
+ ? lastAssistant.blocks
1139
+ .filter((b) => b.type === "text")
1140
+ .map((b) => b.content)
1141
+ .join("\n")
1142
+ .trim() || undefined
1143
+ : undefined;
1091
1144
  const context = {
1092
1145
  event: hookName,
1093
1146
  projectDir: this.getWorkdir(),
@@ -1098,6 +1151,7 @@ export class AIManager {
1098
1151
  subagentType: this.subagentType, // Include subagent type in hook context
1099
1152
  backgroundTasks, // Stop-only: running background tasks snapshot
1100
1153
  sessionCrons, // Stop-only: session cron jobs snapshot
1154
+ lastAssistantMessage: lastAssistantText, // Stop/SubagentStop: last assistant message text
1101
1155
  // Stop hooks don't need toolName, toolInput, toolResponse, or userPrompt
1102
1156
  env: Object.fromEntries(Object.entries(process.env).filter((e) => e[1] !== undefined)), // Include environment variables
1103
1157
  };
@@ -15,7 +15,6 @@ export declare class BackgroundTaskManager {
15
15
  private callbacks;
16
16
  private workdir;
17
17
  constructor(container: Container, options: BackgroundTaskManagerOptions);
18
- private get notificationQueue();
19
18
  /**
20
19
  * Fire the onBackgroundTasksChange callback so UI consumers refresh.
21
20
  * Public so other managers (e.g. WorkflowManager) can trigger a refresh
@@ -26,7 +25,7 @@ export declare class BackgroundTaskManager {
26
25
  addTask(task: BackgroundTask): void;
27
26
  getTask(id: string): BackgroundTask | undefined;
28
27
  getAllTasks(): BackgroundTask[];
29
- startShell(command: string, timeout?: number): {
28
+ startShell(command: string, timeout?: number, cwd?: string): {
30
29
  id: string;
31
30
  child: ChildProcess;
32
31
  detach: () => void;
@@ -43,4 +42,3 @@ export declare class BackgroundTaskManager {
43
42
  stopTask(id: string): boolean;
44
43
  cleanup(): void;
45
44
  }
46
- //# sourceMappingURL=backgroundTaskManager.d.ts.map