@kenkaiiii/ggcoder 4.3.232 → 4.3.233

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 (348) hide show
  1. package/README.md +1 -2
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.js +7 -89
  4. package/dist/cli.js.map +1 -1
  5. package/dist/core/agent-session.d.ts.map +1 -1
  6. package/dist/core/agent-session.js +2 -2
  7. package/dist/core/agent-session.js.map +1 -1
  8. package/dist/core/prompt-commands.d.ts.map +1 -1
  9. package/dist/core/prompt-commands.js +8 -16
  10. package/dist/core/prompt-commands.js.map +1 -1
  11. package/dist/core/prompt-commands.test.js +14 -44
  12. package/dist/core/prompt-commands.test.js.map +1 -1
  13. package/dist/core/runtime-mode.d.ts +0 -11
  14. package/dist/core/runtime-mode.d.ts.map +1 -1
  15. package/dist/core/runtime-mode.js +0 -9
  16. package/dist/core/runtime-mode.js.map +1 -1
  17. package/dist/core/session-restore-display.test.js +4 -110
  18. package/dist/core/session-restore-display.test.js.map +1 -1
  19. package/dist/interactive.d.ts.map +1 -1
  20. package/dist/interactive.js +1 -1
  21. package/dist/interactive.js.map +1 -1
  22. package/dist/system-prompt.d.ts +1 -2
  23. package/dist/system-prompt.d.ts.map +1 -1
  24. package/dist/system-prompt.js +11 -58
  25. package/dist/system-prompt.js.map +1 -1
  26. package/dist/system-prompt.test.js +3 -158
  27. package/dist/system-prompt.test.js.map +1 -1
  28. package/dist/tools/bash.d.ts +1 -4
  29. package/dist/tools/bash.d.ts.map +1 -1
  30. package/dist/tools/bash.js +3 -12
  31. package/dist/tools/bash.js.map +1 -1
  32. package/dist/tools/checkpoint-hook.test.js +3 -3
  33. package/dist/tools/checkpoint-hook.test.js.map +1 -1
  34. package/dist/tools/edit.d.ts +1 -4
  35. package/dist/tools/edit.d.ts.map +1 -1
  36. package/dist/tools/edit.js +5 -13
  37. package/dist/tools/edit.js.map +1 -1
  38. package/dist/tools/enter-plan.js +1 -1
  39. package/dist/tools/enter-plan.js.map +1 -1
  40. package/dist/tools/index.d.ts +0 -9
  41. package/dist/tools/index.d.ts.map +1 -1
  42. package/dist/tools/index.js +4 -8
  43. package/dist/tools/index.js.map +1 -1
  44. package/dist/tools/prompt-hints.d.ts.map +1 -1
  45. package/dist/tools/prompt-hints.js +0 -2
  46. package/dist/tools/prompt-hints.js.map +1 -1
  47. package/dist/tools/screenshot.d.ts +1 -1
  48. package/dist/tools/subagent.d.ts +1 -4
  49. package/dist/tools/subagent.d.ts.map +1 -1
  50. package/dist/tools/subagent.js +2 -5
  51. package/dist/tools/subagent.js.map +1 -1
  52. package/dist/tools/write.d.ts +1 -4
  53. package/dist/tools/write.d.ts.map +1 -1
  54. package/dist/tools/write.js +5 -13
  55. package/dist/tools/write.js.map +1 -1
  56. package/dist/ui/App.d.ts +5 -20
  57. package/dist/ui/App.d.ts.map +1 -1
  58. package/dist/ui/App.js +71 -309
  59. package/dist/ui/App.js.map +1 -1
  60. package/dist/ui/app-items.d.ts +23 -25
  61. package/dist/ui/app-items.d.ts.map +1 -1
  62. package/dist/ui/app-items.js +37 -0
  63. package/dist/ui/app-items.js.map +1 -1
  64. package/dist/ui/app-items.test.d.ts +2 -0
  65. package/dist/ui/app-items.test.d.ts.map +1 -0
  66. package/dist/ui/app-items.test.js +38 -0
  67. package/dist/ui/app-items.test.js.map +1 -0
  68. package/dist/ui/app-state-persistence.test.js +14 -318
  69. package/dist/ui/app-state-persistence.test.js.map +1 -1
  70. package/dist/ui/chat-layout-pinning.test.js +74 -4
  71. package/dist/ui/chat-layout-pinning.test.js.map +1 -1
  72. package/dist/ui/components/AssistantMessage.test.js +6 -9
  73. package/dist/ui/components/AssistantMessage.test.js.map +1 -1
  74. package/dist/ui/components/Banner.js +1 -1
  75. package/dist/ui/components/Banner.js.map +1 -1
  76. package/dist/ui/components/ChatFooterPane.d.ts +1 -5
  77. package/dist/ui/components/ChatFooterPane.d.ts.map +1 -1
  78. package/dist/ui/components/ChatFooterPane.js +3 -4
  79. package/dist/ui/components/ChatFooterPane.js.map +1 -1
  80. package/dist/ui/components/ChatInputStack.d.ts +3 -1
  81. package/dist/ui/components/ChatInputStack.d.ts.map +1 -1
  82. package/dist/ui/components/ChatInputStack.js +4 -3
  83. package/dist/ui/components/ChatInputStack.js.map +1 -1
  84. package/dist/ui/components/ChatScreen.d.ts +3 -16
  85. package/dist/ui/components/ChatScreen.d.ts.map +1 -1
  86. package/dist/ui/components/ChatScreen.js +2 -3
  87. package/dist/ui/components/ChatScreen.js.map +1 -1
  88. package/dist/ui/components/Footer.d.ts +3 -8
  89. package/dist/ui/components/Footer.d.ts.map +1 -1
  90. package/dist/ui/components/Footer.js +5 -25
  91. package/dist/ui/components/Footer.js.map +1 -1
  92. package/dist/ui/components/InputArea.d.ts +1 -9
  93. package/dist/ui/components/InputArea.d.ts.map +1 -1
  94. package/dist/ui/components/InputArea.js +2 -44
  95. package/dist/ui/components/InputArea.js.map +1 -1
  96. package/dist/ui/components/LiveToolPanel.d.ts +30 -0
  97. package/dist/ui/components/LiveToolPanel.d.ts.map +1 -0
  98. package/dist/ui/components/LiveToolPanel.js +66 -0
  99. package/dist/ui/components/LiveToolPanel.js.map +1 -0
  100. package/dist/ui/components/ToolExecution.js +0 -2
  101. package/dist/ui/components/ToolExecution.js.map +1 -1
  102. package/dist/ui/components/TranscriptViewport.d.ts +1 -1
  103. package/dist/ui/components/TranscriptViewport.js +1 -1
  104. package/dist/ui/footer-jump-regression.test.js +12 -2
  105. package/dist/ui/footer-jump-regression.test.js.map +1 -1
  106. package/dist/ui/footer-status-layout.test.js +4 -12
  107. package/dist/ui/footer-status-layout.test.js.map +1 -1
  108. package/dist/ui/hooks/useChatLayoutMeasurements.d.ts +3 -4
  109. package/dist/ui/hooks/useChatLayoutMeasurements.d.ts.map +1 -1
  110. package/dist/ui/hooks/useChatLayoutMeasurements.js +26 -4
  111. package/dist/ui/hooks/useChatLayoutMeasurements.js.map +1 -1
  112. package/dist/ui/hooks/useModeState.d.ts +4 -19
  113. package/dist/ui/hooks/useModeState.d.ts.map +1 -1
  114. package/dist/ui/hooks/useModeState.js +5 -45
  115. package/dist/ui/hooks/useModeState.js.map +1 -1
  116. package/dist/ui/hooks/usePixelFixFlow.js +2 -2
  117. package/dist/ui/layout-decisions.d.ts +11 -34
  118. package/dist/ui/layout-decisions.d.ts.map +1 -1
  119. package/dist/ui/layout-decisions.js +15 -42
  120. package/dist/ui/layout-decisions.js.map +1 -1
  121. package/dist/ui/live-area-height.d.ts.map +1 -1
  122. package/dist/ui/live-area-height.js +6 -1
  123. package/dist/ui/live-area-height.js.map +1 -1
  124. package/dist/ui/live-frame-height.test.js +26 -1
  125. package/dist/ui/live-frame-height.test.js.map +1 -1
  126. package/dist/ui/plan-overlay.test.js +1 -1
  127. package/dist/ui/plan-overlay.test.js.map +1 -1
  128. package/dist/ui/prompt-routing.d.ts +1 -19
  129. package/dist/ui/prompt-routing.d.ts.map +1 -1
  130. package/dist/ui/prompt-routing.js +1 -79
  131. package/dist/ui/prompt-routing.js.map +1 -1
  132. package/dist/ui/render.d.ts +3 -18
  133. package/dist/ui/render.d.ts.map +1 -1
  134. package/dist/ui/render.js +0 -10
  135. package/dist/ui/render.js.map +1 -1
  136. package/dist/ui/scroll-stabilization.test.js +1 -7
  137. package/dist/ui/scroll-stabilization.test.js.map +1 -1
  138. package/dist/ui/slash-command-images.test.js +11 -86
  139. package/dist/ui/slash-command-images.test.js.map +1 -1
  140. package/dist/ui/streaming-flush-bounce.test.d.ts +2 -0
  141. package/dist/ui/streaming-flush-bounce.test.d.ts.map +1 -0
  142. package/dist/ui/streaming-flush-bounce.test.js +156 -0
  143. package/dist/ui/streaming-flush-bounce.test.js.map +1 -0
  144. package/dist/ui/submit-prompt-command.d.ts +1 -16
  145. package/dist/ui/submit-prompt-command.d.ts.map +1 -1
  146. package/dist/ui/submit-prompt-command.js +4 -54
  147. package/dist/ui/submit-prompt-command.js.map +1 -1
  148. package/dist/ui/submit-slash-commands.d.ts +0 -1
  149. package/dist/ui/submit-slash-commands.d.ts.map +1 -1
  150. package/dist/ui/submit-slash-commands.js +0 -4
  151. package/dist/ui/submit-slash-commands.js.map +1 -1
  152. package/dist/ui/terminal-history-status-renderers.d.ts +0 -1
  153. package/dist/ui/terminal-history-status-renderers.d.ts.map +1 -1
  154. package/dist/ui/terminal-history-status-renderers.js +0 -3
  155. package/dist/ui/terminal-history-status-renderers.js.map +1 -1
  156. package/dist/ui/terminal-history.d.ts.map +1 -1
  157. package/dist/ui/terminal-history.js +11 -56
  158. package/dist/ui/terminal-history.js.map +1 -1
  159. package/dist/ui/terminal-history.test.js +6 -33
  160. package/dist/ui/terminal-history.test.js.map +1 -1
  161. package/dist/ui/tool-line-summary.d.ts +29 -0
  162. package/dist/ui/tool-line-summary.d.ts.map +1 -0
  163. package/dist/ui/tool-line-summary.js +153 -0
  164. package/dist/ui/tool-line-summary.js.map +1 -0
  165. package/dist/ui/transcript/TranscriptRenderer.d.ts +1 -1
  166. package/dist/ui/transcript/TranscriptRenderer.d.ts.map +1 -1
  167. package/dist/ui/transcript/TranscriptRenderer.js +18 -12
  168. package/dist/ui/transcript/TranscriptRenderer.js.map +1 -1
  169. package/dist/ui/transcript/presentation.d.ts +1 -17
  170. package/dist/ui/transcript/presentation.d.ts.map +1 -1
  171. package/dist/ui/transcript/presentation.js +0 -26
  172. package/dist/ui/transcript/presentation.js.map +1 -1
  173. package/dist/ui/transcript/spacing.d.ts +2 -2
  174. package/dist/ui/transcript/spacing.d.ts.map +1 -1
  175. package/dist/ui/transcript/spacing.js +14 -9
  176. package/dist/ui/transcript/spacing.js.map +1 -1
  177. package/dist/ui/transcript/spacing.test.js +5 -8
  178. package/dist/ui/transcript/spacing.test.js.map +1 -1
  179. package/dist/ui/transcript/tool-presentation.js +1 -1
  180. package/dist/ui/transcript/tool-presentation.js.map +1 -1
  181. package/dist/ui/transcript/transcript-lines.d.ts.map +1 -1
  182. package/dist/ui/transcript/transcript-lines.js +4 -0
  183. package/dist/ui/transcript/transcript-lines.js.map +1 -1
  184. package/dist/ui/tui-history-parity.test.js +0 -47
  185. package/dist/ui/tui-history-parity.test.js.map +1 -1
  186. package/dist/ui/tui-simulation.test.js +2 -1
  187. package/dist/ui/tui-simulation.test.js.map +1 -1
  188. package/package.json +4 -4
  189. package/dist/core/goal-controller.d.ts +0 -82
  190. package/dist/core/goal-controller.d.ts.map +0 -1
  191. package/dist/core/goal-controller.js +0 -838
  192. package/dist/core/goal-controller.js.map +0 -1
  193. package/dist/core/goal-controller.test.d.ts +0 -2
  194. package/dist/core/goal-controller.test.d.ts.map +0 -1
  195. package/dist/core/goal-controller.test.js +0 -1279
  196. package/dist/core/goal-controller.test.js.map +0 -1
  197. package/dist/core/goal-engine.d.ts +0 -61
  198. package/dist/core/goal-engine.d.ts.map +0 -1
  199. package/dist/core/goal-engine.js +0 -123
  200. package/dist/core/goal-engine.js.map +0 -1
  201. package/dist/core/goal-engine.test.d.ts +0 -2
  202. package/dist/core/goal-engine.test.d.ts.map +0 -1
  203. package/dist/core/goal-engine.test.js +0 -295
  204. package/dist/core/goal-engine.test.js.map +0 -1
  205. package/dist/core/goal-integration.d.ts +0 -80
  206. package/dist/core/goal-integration.d.ts.map +0 -1
  207. package/dist/core/goal-integration.js +0 -296
  208. package/dist/core/goal-integration.js.map +0 -1
  209. package/dist/core/goal-integration.test.d.ts +0 -2
  210. package/dist/core/goal-integration.test.d.ts.map +0 -1
  211. package/dist/core/goal-integration.test.js +0 -369
  212. package/dist/core/goal-integration.test.js.map +0 -1
  213. package/dist/core/goal-lifecycle-smoke.test.d.ts +0 -2
  214. package/dist/core/goal-lifecycle-smoke.test.d.ts.map +0 -1
  215. package/dist/core/goal-lifecycle-smoke.test.js +0 -248
  216. package/dist/core/goal-lifecycle-smoke.test.js.map +0 -1
  217. package/dist/core/goal-overhead-harness.d.ts +0 -33
  218. package/dist/core/goal-overhead-harness.d.ts.map +0 -1
  219. package/dist/core/goal-overhead-harness.js +0 -268
  220. package/dist/core/goal-overhead-harness.js.map +0 -1
  221. package/dist/core/goal-prerequisites.d.ts +0 -23
  222. package/dist/core/goal-prerequisites.d.ts.map +0 -1
  223. package/dist/core/goal-prerequisites.js +0 -114
  224. package/dist/core/goal-prerequisites.js.map +0 -1
  225. package/dist/core/goal-prerequisites.test.d.ts +0 -2
  226. package/dist/core/goal-prerequisites.test.d.ts.map +0 -1
  227. package/dist/core/goal-prerequisites.test.js +0 -154
  228. package/dist/core/goal-prerequisites.test.js.map +0 -1
  229. package/dist/core/goal-references.d.ts +0 -14
  230. package/dist/core/goal-references.d.ts.map +0 -1
  231. package/dist/core/goal-references.js +0 -153
  232. package/dist/core/goal-references.js.map +0 -1
  233. package/dist/core/goal-references.test.d.ts +0 -2
  234. package/dist/core/goal-references.test.d.ts.map +0 -1
  235. package/dist/core/goal-references.test.js +0 -77
  236. package/dist/core/goal-references.test.js.map +0 -1
  237. package/dist/core/goal-store.d.ts +0 -289
  238. package/dist/core/goal-store.d.ts.map +0 -1
  239. package/dist/core/goal-store.js +0 -1156
  240. package/dist/core/goal-store.js.map +0 -1
  241. package/dist/core/goal-store.test.d.ts +0 -2
  242. package/dist/core/goal-store.test.d.ts.map +0 -1
  243. package/dist/core/goal-store.test.js +0 -530
  244. package/dist/core/goal-store.test.js.map +0 -1
  245. package/dist/core/goal-verifier.d.ts +0 -17
  246. package/dist/core/goal-verifier.d.ts.map +0 -1
  247. package/dist/core/goal-verifier.js +0 -87
  248. package/dist/core/goal-verifier.js.map +0 -1
  249. package/dist/core/goal-verifier.test.d.ts +0 -2
  250. package/dist/core/goal-verifier.test.d.ts.map +0 -1
  251. package/dist/core/goal-verifier.test.js +0 -131
  252. package/dist/core/goal-verifier.test.js.map +0 -1
  253. package/dist/core/goal-worker-dev-server-lifecycle.test.d.ts +0 -2
  254. package/dist/core/goal-worker-dev-server-lifecycle.test.d.ts.map +0 -1
  255. package/dist/core/goal-worker-dev-server-lifecycle.test.js +0 -68
  256. package/dist/core/goal-worker-dev-server-lifecycle.test.js.map +0 -1
  257. package/dist/core/goal-worker.d.ts +0 -61
  258. package/dist/core/goal-worker.d.ts.map +0 -1
  259. package/dist/core/goal-worker.js +0 -467
  260. package/dist/core/goal-worker.js.map +0 -1
  261. package/dist/core/goal-worker.test.d.ts +0 -2
  262. package/dist/core/goal-worker.test.d.ts.map +0 -1
  263. package/dist/core/goal-worker.test.js +0 -493
  264. package/dist/core/goal-worker.test.js.map +0 -1
  265. package/dist/core/goal-worktree.d.ts +0 -108
  266. package/dist/core/goal-worktree.d.ts.map +0 -1
  267. package/dist/core/goal-worktree.js +0 -300
  268. package/dist/core/goal-worktree.js.map +0 -1
  269. package/dist/core/goal-worktree.test.d.ts +0 -2
  270. package/dist/core/goal-worktree.test.d.ts.map +0 -1
  271. package/dist/core/goal-worktree.test.js +0 -448
  272. package/dist/core/goal-worktree.test.js.map +0 -1
  273. package/dist/tools/goal-mode.test.d.ts +0 -2
  274. package/dist/tools/goal-mode.test.d.ts.map +0 -1
  275. package/dist/tools/goal-mode.test.js +0 -121
  276. package/dist/tools/goal-mode.test.js.map +0 -1
  277. package/dist/tools/goals.d.ts +0 -143
  278. package/dist/tools/goals.d.ts.map +0 -1
  279. package/dist/tools/goals.js +0 -1038
  280. package/dist/tools/goals.js.map +0 -1
  281. package/dist/tools/goals.test.d.ts +0 -2
  282. package/dist/tools/goals.test.d.ts.map +0 -1
  283. package/dist/tools/goals.test.js +0 -1444
  284. package/dist/tools/goals.test.js.map +0 -1
  285. package/dist/ui/components/GoalOverlay.d.ts +0 -83
  286. package/dist/ui/components/GoalOverlay.d.ts.map +0 -1
  287. package/dist/ui/components/GoalOverlay.js +0 -710
  288. package/dist/ui/components/GoalOverlay.js.map +0 -1
  289. package/dist/ui/components/GoalPickerMenu.d.ts +0 -9
  290. package/dist/ui/components/GoalPickerMenu.d.ts.map +0 -1
  291. package/dist/ui/components/GoalPickerMenu.js +0 -37
  292. package/dist/ui/components/GoalPickerMenu.js.map +0 -1
  293. package/dist/ui/components/GoalStatusBar.d.ts +0 -26
  294. package/dist/ui/components/GoalStatusBar.d.ts.map +0 -1
  295. package/dist/ui/components/GoalStatusBar.js +0 -130
  296. package/dist/ui/components/GoalStatusBar.js.map +0 -1
  297. package/dist/ui/components/GoalStatusBar.test.d.ts +0 -2
  298. package/dist/ui/components/GoalStatusBar.test.d.ts.map +0 -1
  299. package/dist/ui/components/GoalStatusBar.test.js +0 -17
  300. package/dist/ui/components/GoalStatusBar.test.js.map +0 -1
  301. package/dist/ui/goal-events.d.ts +0 -125
  302. package/dist/ui/goal-events.d.ts.map +0 -1
  303. package/dist/ui/goal-events.js +0 -407
  304. package/dist/ui/goal-events.js.map +0 -1
  305. package/dist/ui/goal-events.test.d.ts +0 -2
  306. package/dist/ui/goal-events.test.d.ts.map +0 -1
  307. package/dist/ui/goal-events.test.js +0 -416
  308. package/dist/ui/goal-events.test.js.map +0 -1
  309. package/dist/ui/goal-lifecycle-orchestration.test.d.ts +0 -2
  310. package/dist/ui/goal-lifecycle-orchestration.test.d.ts.map +0 -1
  311. package/dist/ui/goal-lifecycle-orchestration.test.js +0 -555
  312. package/dist/ui/goal-lifecycle-orchestration.test.js.map +0 -1
  313. package/dist/ui/goal-overlay.test.d.ts +0 -2
  314. package/dist/ui/goal-overlay.test.d.ts.map +0 -1
  315. package/dist/ui/goal-overlay.test.js +0 -384
  316. package/dist/ui/goal-overlay.test.js.map +0 -1
  317. package/dist/ui/goal-progress.d.ts +0 -31
  318. package/dist/ui/goal-progress.d.ts.map +0 -1
  319. package/dist/ui/goal-progress.js +0 -149
  320. package/dist/ui/goal-progress.js.map +0 -1
  321. package/dist/ui/goal-run-helpers.d.ts +0 -12
  322. package/dist/ui/goal-run-helpers.d.ts.map +0 -1
  323. package/dist/ui/goal-run-helpers.js +0 -42
  324. package/dist/ui/goal-run-helpers.js.map +0 -1
  325. package/dist/ui/goal-status-bar.test.d.ts +0 -2
  326. package/dist/ui/goal-status-bar.test.d.ts.map +0 -1
  327. package/dist/ui/goal-status-bar.test.js +0 -174
  328. package/dist/ui/goal-status-bar.test.js.map +0 -1
  329. package/dist/ui/goal-summary.d.ts +0 -14
  330. package/dist/ui/goal-summary.d.ts.map +0 -1
  331. package/dist/ui/goal-summary.js +0 -194
  332. package/dist/ui/goal-summary.js.map +0 -1
  333. package/dist/ui/hooks/useGoalOrchestration.d.ts +0 -82
  334. package/dist/ui/hooks/useGoalOrchestration.d.ts.map +0 -1
  335. package/dist/ui/hooks/useGoalOrchestration.js +0 -863
  336. package/dist/ui/hooks/useGoalOrchestration.js.map +0 -1
  337. package/dist/ui/hooks/useGoalPickerController.d.ts +0 -22
  338. package/dist/ui/hooks/useGoalPickerController.d.ts.map +0 -1
  339. package/dist/ui/hooks/useGoalPickerController.js +0 -35
  340. package/dist/ui/hooks/useGoalPickerController.js.map +0 -1
  341. package/dist/ui/prompt-routing.test.d.ts +0 -2
  342. package/dist/ui/prompt-routing.test.d.ts.map +0 -1
  343. package/dist/ui/prompt-routing.test.js +0 -48
  344. package/dist/ui/prompt-routing.test.js.map +0 -1
  345. package/dist/ui/transcript/GoalRows.d.ts +0 -10
  346. package/dist/ui/transcript/GoalRows.d.ts.map +0 -1
  347. package/dist/ui/transcript/GoalRows.js +0 -35
  348. package/dist/ui/transcript/GoalRows.js.map +0 -1
@@ -1,863 +0,0 @@
1
- import { useCallback, useEffect, } from "react";
2
- import { log } from "../../core/logger.js";
3
- import { appendGoalDecision, appendGoalEvidence, formatGoalBlockingPrerequisites, goalHasBlockingPrerequisites, loadGoalRuns, reconcileActiveGoalRuns, recordGoalSubstantiveWorker, setGoalIntegrationState, updateGoalTask, upsertGoalRun, } from "../../core/goal-store.js";
4
- import { APPLY_INTEGRATION_TO_MAIN_TASK_TITLE, FINAL_COMPLETION_AUDIT_TASK_TITLE, canCompleteGoalRun, decideGoalNextAction, } from "../../core/goal-controller.js";
5
- import { confirmAndCommitMainIntegration, discardStagedIntegration, finalizeStagedIntegration, stageGoalIntegration, } from "../../core/goal-integration.js";
6
- import { runGoalPrerequisiteChecks } from "../../core/goal-prerequisites.js";
7
- import { runGoalVerifierCommand } from "../../core/goal-verifier.js";
8
- import { checkGoalWorktreeIntegration, isGoalWorktreeDirtyError, removeGoalRunWorktrees, } from "../../core/goal-worktree.js";
9
- import { listGoalWorkers, startGoalWorker, stopGoalWorker, subscribeGoalWorkerCompletions, } from "../../core/goal-worker.js";
10
- import { parseGoalSyntheticEvent } from "../goal-events.js";
11
- import { completedItemsWithDurableGoalTerminalProgress, formatGoalTerminalProgress, formatGoalWorkerFinishedTitle, getGoalContinuationChoiceKey, goalTerminalProgressId, routeGoalSyntheticEvent, summarizeGoalCompletion, } from "../goal-progress.js";
12
- import { buildGoalTaskPromptWithReferences, buildGoalUserPauseRun, goalRunNeedsExplicitContinuationAfterWorker, goalTaskProgress, shouldKeepGoalRunTrackedAfterDecision, shouldRunGoalTaskInMainCheckout, } from "../goal-run-helpers.js";
13
- import { toErrorItem } from "../error-item.js";
14
- /**
15
- * Owns the entire Goal orchestration lifecycle — synthetic-event routing,
16
- * continuation, worker-completion handling, the worker-completion subscription,
17
- * starting runs/tasks/workers, verifier execution, and pausing. Extracted
18
- * verbatim from `App.tsx`; the mutual recursion between these callbacks is
19
- * preserved via `startGoalRunRef`/`startTaskRef`.
20
- */
21
- export function useGoalOrchestration({ cwd, resetUI, sessionStore, currentProvider, currentModel, thinkingLevel, agentLoop, appendGoalProgress, goalNumberForRun, clearGoalStatusEntry, upsertGoalStatusEntry, setGoalModeAndPrompt, clearGoalModeIfIdle, agentRunningRef, runningGoalIdsRef, activeVerifierRunIdsRef, queuedGoalSyntheticEventsRef, goalContinuationFlightsRef, goalContinuationRecentChoicesRef, startGoalRunRef, startTaskRef, messagesRef, persistedIndexRef, sessionManagerRef, sessionPathRef, cwdRef, setLiveItems, setHistory, setLastUserMessage, setDoneStatus, getId, clearPendingHistory, }) {
22
- const runGoalSyntheticEvent = useCallback((eventText) => {
23
- const eventInfo = parseGoalSyntheticEvent(eventText);
24
- const detail = eventInfo?.kind === "worker"
25
- ? `Inspecting worker result${eventInfo.task ? ` for ${eventInfo.task}` : ""}.`
26
- : `Inspecting verifier result${eventInfo?.status ? ` (${eventInfo.status})` : ""}.`;
27
- const route = routeGoalSyntheticEvent({
28
- agentRunning: agentRunningRef.current,
29
- queuedSyntheticEvents: queuedGoalSyntheticEventsRef.current,
30
- });
31
- if (route.action === "queue") {
32
- queuedGoalSyntheticEventsRef.current = route.nextQueuedSyntheticEvents;
33
- void setGoalModeAndPrompt(route.nextGoalMode);
34
- appendGoalProgress({
35
- kind: "goal_progress",
36
- phase: "orchestrator_reviewing",
37
- title: "Goal update queued for orchestrator",
38
- detail: `${detail} It will report back after the current turn.`,
39
- workerId: eventInfo?.worker,
40
- status: eventInfo?.status,
41
- });
42
- agentLoop.queueMessage(eventText);
43
- return;
44
- }
45
- appendGoalProgress({
46
- kind: "goal_progress",
47
- phase: "orchestrator_reviewing",
48
- title: "Orchestrator reviewing Goal update",
49
- detail,
50
- workerId: eventInfo?.worker,
51
- status: eventInfo?.status,
52
- });
53
- setLastUserMessage("");
54
- setDoneStatus(null);
55
- void (async () => {
56
- await setGoalModeAndPrompt("coordinator");
57
- await agentLoop.run(eventText);
58
- })().catch((err) => {
59
- log("ERROR", "goal", err instanceof Error ? err.message : String(err));
60
- setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal")]);
61
- clearGoalModeIfIdle();
62
- });
63
- }, [agentLoop, appendGoalProgress, clearGoalModeIfIdle, setGoalModeAndPrompt]);
64
- const continueGoalRun = useCallback((runId) => {
65
- if (goalContinuationFlightsRef.current.has(runId))
66
- return;
67
- goalContinuationFlightsRef.current.add(runId);
68
- void (async () => {
69
- const latestRun = await reconcileActiveGoalRuns(cwd, {
70
- isWorkerActive: (workerId) => listGoalWorkers(cwd).some((worker) => worker.id === workerId && worker.status === "running"),
71
- }).then(({ runs }) => runs.find((item) => item.id === runId) ?? null);
72
- if (!latestRun) {
73
- runningGoalIdsRef.current.delete(runId);
74
- clearGoalStatusEntry(runId);
75
- clearGoalModeIfIdle();
76
- return;
77
- }
78
- const decision = decideGoalNextAction(latestRun);
79
- if (!shouldKeepGoalRunTrackedAfterDecision(decision)) {
80
- runningGoalIdsRef.current.delete(runId);
81
- clearGoalModeIfIdle();
82
- }
83
- if (decision.kind === "wait")
84
- return;
85
- const choiceKey = getGoalContinuationChoiceKey({ runId: latestRun.id, decision });
86
- const now = Date.now();
87
- const recentChoiceAt = goalContinuationRecentChoicesRef.current.get(choiceKey);
88
- if (recentChoiceAt !== undefined && now - recentChoiceAt < 5000)
89
- return;
90
- goalContinuationRecentChoicesRef.current.set(choiceKey, now);
91
- if (goalContinuationRecentChoicesRef.current.size > 100) {
92
- for (const [key, startedAt] of goalContinuationRecentChoicesRef.current) {
93
- if (now - startedAt > 60_000)
94
- goalContinuationRecentChoicesRef.current.delete(key);
95
- }
96
- }
97
- if (decision.kind === "terminal" || decision.kind === "blocked") {
98
- const status = decision.kind === "terminal" ? decision.status : "blocked";
99
- let runWithDiagnosis = latestRun;
100
- if (decision.kind === "terminal" && status === "failed") {
101
- runWithDiagnosis =
102
- (await appendGoalEvidence(cwd, latestRun.id, {
103
- kind: "summary",
104
- label: "Goal failure diagnosis",
105
- content: decision.reason,
106
- })) ?? latestRun;
107
- }
108
- const nextRun = {
109
- ...runWithDiagnosis,
110
- status,
111
- continueRequestedAt: undefined,
112
- blockers: decision.kind === "blocked" || status === "failed"
113
- ? Array.from(new Set([...runWithDiagnosis.blockers, decision.reason]))
114
- : runWithDiagnosis.blockers,
115
- };
116
- await upsertGoalRun(cwd, nextRun);
117
- await appendGoalDecision(cwd, latestRun.id, {
118
- kind: "continuation_stopped",
119
- reason: decision.reason,
120
- content: `terminal=${status}`,
121
- });
122
- const terminalProgress = formatGoalTerminalProgress(nextRun);
123
- if (terminalProgress) {
124
- const item = { ...terminalProgress, id: goalTerminalProgressId(nextRun) };
125
- setLiveItems((prev) => completedItemsWithDurableGoalTerminalProgress([...prev, item], [nextRun]));
126
- }
127
- runningGoalIdsRef.current.delete(runId);
128
- clearGoalStatusEntry(runId);
129
- clearGoalModeIfIdle();
130
- return;
131
- }
132
- let runForNextAction = latestRun;
133
- if (latestRun.continueRequestedAt &&
134
- !listGoalWorkers(cwd).some((worker) => worker.status === "running") &&
135
- activeVerifierRunIdsRef.current.size === 0) {
136
- await appendGoalDecision(cwd, latestRun.id, {
137
- kind: "continuation_consumed",
138
- reason: `Continuation request consumed by ${decision.kind}.`,
139
- });
140
- runForNextAction = await upsertGoalRun(cwd, {
141
- ...latestRun,
142
- continueRequestedAt: undefined,
143
- });
144
- }
145
- appendGoalProgress({
146
- kind: "goal_progress",
147
- phase: "continuing",
148
- title: `Choosing next Goal step: ${latestRun.title}`,
149
- detail: "Latest result is recorded; starting the next worker task or verifier automatically.",
150
- status: latestRun.status,
151
- });
152
- upsertGoalStatusEntry({
153
- runId: latestRun.id,
154
- label: latestRun.title,
155
- phase: "orchestrating",
156
- startedAt: Date.now(),
157
- detail: "choosing next step",
158
- });
159
- startGoalRunRef.current(runForNextAction);
160
- })()
161
- .catch((err) => {
162
- runningGoalIdsRef.current.delete(runId);
163
- clearGoalStatusEntry(runId);
164
- log("ERROR", "goal", err instanceof Error ? err.message : String(err));
165
- setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal")]);
166
- })
167
- .finally(() => {
168
- goalContinuationFlightsRef.current.delete(runId);
169
- clearGoalModeIfIdle();
170
- });
171
- }, [appendGoalProgress, clearGoalModeIfIdle, clearGoalStatusEntry, cwd, upsertGoalStatusEntry]);
172
- const handleGoalWorkerComplete = useCallback((run, completion) => {
173
- const taskTitle = run.tasks.find((task) => task.id === completion.worker.goalTaskId)?.title ??
174
- completion.worker.goalTaskId;
175
- appendGoalProgress({
176
- kind: "goal_progress",
177
- phase: "worker_finished",
178
- title: formatGoalWorkerFinishedTitle(taskTitle, completion.status),
179
- detail: summarizeGoalCompletion(completion.summary),
180
- workerId: completion.worker.id,
181
- status: completion.status,
182
- });
183
- const taskProgress = goalTaskProgress(run, run.tasks.find((task) => task.id === completion.worker.goalTaskId));
184
- upsertGoalStatusEntry({
185
- runId: run.id,
186
- label: run.title,
187
- phase: completion.status === "done" ? "reviewing" : "failed",
188
- startedAt: Date.now(),
189
- detail: completion.status === "done" ? "reviewing result" : "task failed",
190
- workerId: completion.worker.id,
191
- goalNumber: goalNumberForRun(run.id),
192
- ...taskProgress,
193
- });
194
- void (async () => {
195
- // Deterministic integration gate: if an apply-integration worker just
196
- // finished, confirm via git that main actually contains the changes,
197
- // commit anything left uncommitted, and record canonical applied/
198
- // committed evidence ourselves — never trust the worker to emit exact
199
- // evidence labels. This must happen before the continuation re-decides.
200
- const completedTask = run.tasks.find((task) => task.id === completion.worker.goalTaskId);
201
- if (completion.status === "done" &&
202
- completedTask?.title === APPLY_INTEGRATION_TO_MAIN_TASK_TITLE) {
203
- const baseRef = run.tasks
204
- .map((task) => task.candidate?.baseRef)
205
- .find((value) => !!value);
206
- if (baseRef) {
207
- try {
208
- const confirmed = await confirmAndCommitMainIntegration({
209
- projectPath: completion.worker.projectPath,
210
- baseRef,
211
- message: `goal(${run.id}): commit integrated changes`,
212
- });
213
- if (confirmed.applied) {
214
- await setGoalIntegrationState(completion.worker.projectPath, run.id, {
215
- status: confirmed.committed ? "committed" : "applied",
216
- baseRef,
217
- ...(confirmed.sha ? { headSha: confirmed.sha } : {}),
218
- files: confirmed.files,
219
- updatedAt: new Date().toISOString(),
220
- });
221
- await appendGoalEvidence(completion.worker.projectPath, run.id, {
222
- kind: "summary",
223
- label: "Integrated worktree applied to main",
224
- content: `Deterministically confirmed main contains the integrated changes; commit=${confirmed.sha ?? ""}; files=${confirmed.files.join(", ")}`,
225
- });
226
- await appendGoalEvidence(completion.worker.projectPath, run.id, {
227
- kind: "summary",
228
- label: "Integrated Goal changes committed",
229
- content: `Deterministic integration commit=${confirmed.sha ?? ""}.`,
230
- });
231
- }
232
- }
233
- catch (err) {
234
- log("ERROR", "goal", `Integration finalize failed: ${err instanceof Error ? err.message : String(err)}`);
235
- }
236
- }
237
- }
238
- // Stamp the substantive-worker clock for any worker that is neither the
239
- // final read-only audit nor an integration task, so verifier/audit
240
- // staleness is driven by typed state instead of evidence-label scans.
241
- const completedTitle = completedTask?.title;
242
- if (completedTitle &&
243
- completedTitle !== FINAL_COMPLETION_AUDIT_TASK_TITLE &&
244
- !shouldRunGoalTaskInMainCheckout(completedTitle)) {
245
- await recordGoalSubstantiveWorker(completion.worker.projectPath, run.id, new Date().toISOString());
246
- }
247
- if (listGoalWorkers(completion.worker.projectPath).some((worker) => worker.status === "running"))
248
- return;
249
- if (activeVerifierRunIdsRef.current.size > 0)
250
- return;
251
- const runs = await loadGoalRuns(completion.worker.projectPath);
252
- const queued = runs.find((item) => goalRunNeedsExplicitContinuationAfterWorker(item));
253
- if (queued)
254
- setTimeout(() => continueGoalRun(queued.id), 750);
255
- })().catch((err) => log("ERROR", "goal", err instanceof Error ? err.message : String(err)));
256
- }, [appendGoalProgress, continueGoalRun, goalNumberForRun, upsertGoalStatusEntry]);
257
- useEffect(() => {
258
- return subscribeGoalWorkerCompletions((completion) => {
259
- void (async () => {
260
- const latestRun = (await loadGoalRuns(completion.worker.projectPath)).find((item) => item.id === completion.worker.goalRunId) ?? null;
261
- if (!latestRun) {
262
- log("WARN", "goal", `Worker completion for unknown Goal ${completion.worker.goalRunId}`);
263
- return;
264
- }
265
- runningGoalIdsRef.current.add(latestRun.id);
266
- handleGoalWorkerComplete(latestRun, completion);
267
- })().catch((err) => {
268
- log("ERROR", "goal", err instanceof Error ? err.message : String(err));
269
- setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal")]);
270
- });
271
- }, cwd);
272
- }, [handleGoalWorkerComplete, cwd]);
273
- const startGoalRun = useCallback((run) => {
274
- runningGoalIdsRef.current.add(run.id);
275
- upsertGoalStatusEntry({
276
- runId: run.id,
277
- label: run.title,
278
- phase: "orchestrating",
279
- startedAt: Date.now(),
280
- detail: "choosing next step",
281
- goalNumber: goalNumberForRun(run.id),
282
- });
283
- void (async () => {
284
- await setGoalModeAndPrompt("coordinator");
285
- const currentRun = (await loadGoalRuns(cwd)).find((item) => item.id === run.id) ?? run;
286
- const prereqCheck = await runGoalPrerequisiteChecks(cwd, currentRun);
287
- const checkedRun = prereqCheck.checkedCount > 0
288
- ? await upsertGoalRun(cwd, {
289
- ...prereqCheck.run,
290
- status: goalHasBlockingPrerequisites(prereqCheck.run) ? "blocked" : "ready",
291
- })
292
- : currentRun;
293
- if (goalHasBlockingPrerequisites(checkedRun)) {
294
- const detail = formatGoalBlockingPrerequisites(checkedRun);
295
- await upsertGoalRun(cwd, {
296
- ...checkedRun,
297
- status: "blocked",
298
- blockers: Array.from(new Set([...checkedRun.blockers, detail])),
299
- });
300
- appendGoalProgress({
301
- kind: "goal_progress",
302
- phase: "terminal",
303
- title: `Goal blocked: ${checkedRun.title}`,
304
- detail,
305
- status: "blocked",
306
- });
307
- runningGoalIdsRef.current.delete(checkedRun.id);
308
- clearGoalStatusEntry(checkedRun.id);
309
- clearGoalModeIfIdle();
310
- return;
311
- }
312
- const decision = decideGoalNextAction(checkedRun);
313
- await appendGoalDecision(cwd, checkedRun.id, decision);
314
- if (!shouldKeepGoalRunTrackedAfterDecision(decision)) {
315
- runningGoalIdsRef.current.delete(checkedRun.id);
316
- }
317
- if (decision.kind === "terminal") {
318
- let terminalRun = checkedRun;
319
- if (decision.status === "failed") {
320
- const runWithDiagnosis = (await appendGoalEvidence(cwd, checkedRun.id, {
321
- kind: "summary",
322
- label: "Goal failure diagnosis",
323
- content: decision.reason,
324
- })) ?? checkedRun;
325
- terminalRun = await upsertGoalRun(cwd, {
326
- ...runWithDiagnosis,
327
- status: "failed",
328
- activeWorkerId: undefined,
329
- continueRequestedAt: undefined,
330
- blockers: Array.from(new Set([...runWithDiagnosis.blockers, decision.reason])),
331
- });
332
- }
333
- const terminalProgress = formatGoalTerminalProgress(terminalRun);
334
- if (terminalProgress) {
335
- const item = { ...terminalProgress, id: goalTerminalProgressId(terminalRun) };
336
- setLiveItems((prev) => completedItemsWithDurableGoalTerminalProgress([...prev, item], [terminalRun]));
337
- }
338
- runningGoalIdsRef.current.delete(terminalRun.id);
339
- clearGoalStatusEntry(terminalRun.id);
340
- clearGoalModeIfIdle();
341
- return;
342
- }
343
- if (decision.kind === "wait") {
344
- appendGoalProgress({
345
- kind: "goal_progress",
346
- phase: "worker_started",
347
- title: decision.workerId
348
- ? `Goal working: ${checkedRun.title}`
349
- : `Goal needs orchestration: ${checkedRun.title}`,
350
- detail: decision.workerId
351
- ? decision.reason
352
- : `${decision.reason} Asking the orchestrator to unblock or revise the Goal plan.`,
353
- workerId: decision.workerId,
354
- });
355
- upsertGoalStatusEntry({
356
- runId: checkedRun.id,
357
- label: checkedRun.title,
358
- phase: decision.workerId ? "worker" : "orchestrating",
359
- startedAt: Date.now(),
360
- detail: decision.reason,
361
- workerId: decision.workerId,
362
- goalNumber: goalNumberForRun(checkedRun.id),
363
- });
364
- if (!decision.workerId) {
365
- const eventText = `Goal continuation is waiting with no active worker for Goal ${checkedRun.id} (${checkedRun.title}).\n` +
366
- `Reason: ${decision.reason}\n\n` +
367
- `Inspect the durable Goal state with the goals tool, resolve blocked dependencies by creating or updating concrete worker tasks, and then continue the Goal. If no local/free action can proceed, record an explicit blocker with exact user instructions. Do not stop after only explaining the state.`;
368
- setLastUserMessage("");
369
- setDoneStatus(null);
370
- await agentLoop.run(eventText);
371
- }
372
- return;
373
- }
374
- if (decision.kind === "complete") {
375
- await upsertGoalRun(cwd, { ...checkedRun, status: "passed" });
376
- try {
377
- const cleanup = await removeGoalRunWorktrees(cwd, checkedRun);
378
- if (cleanup.removedPaths.length > 0) {
379
- await appendGoalEvidence(cwd, checkedRun.id, {
380
- kind: "summary",
381
- label: "Goal worktrees cleaned up",
382
- content: `Removed ${cleanup.removedPaths.length} worktree(s) and ${cleanup.removedBranches.length} branch(es) after the Goal passed.`,
383
- });
384
- }
385
- }
386
- catch (cleanupErr) {
387
- log("WARN", "goal", `Worktree cleanup failed: ${cleanupErr instanceof Error ? cleanupErr.message : String(cleanupErr)}`);
388
- }
389
- appendGoalProgress({
390
- kind: "goal_progress",
391
- phase: "terminal",
392
- title: `Goal passed: ${checkedRun.title}`,
393
- detail: decision.reason,
394
- status: "passed",
395
- });
396
- runningGoalIdsRef.current.delete(checkedRun.id);
397
- clearGoalStatusEntry(checkedRun.id);
398
- clearGoalModeIfIdle();
399
- return;
400
- }
401
- if (decision.kind === "run_verifier") {
402
- await verifyGoalRun(checkedRun);
403
- return;
404
- }
405
- if (decision.kind === "create_task") {
406
- if (decision.title === APPLY_INTEGRATION_TO_MAIN_TASK_TITLE) {
407
- // Stage the deterministic integration on a throwaway branch, verify it
408
- // there, and only fast-forward main on pass — main never holds
409
- // unverified changes. Ambiguous cases fall through to the LLM apply task.
410
- const staged = await stageGoalIntegration({ projectPath: cwd, run: checkedRun });
411
- if (staged.status === "staged") {
412
- const stagedRun = (await appendGoalEvidence(cwd, checkedRun.id, {
413
- kind: "summary",
414
- label: "Integration staged",
415
- content: `Staged ${staged.integratedTaskIds.length} candidate(s) on ${staged.stagingBranch} for verify-before-fast-forward; files=${staged.changedFiles.join(", ")}.`,
416
- path: staged.stagingPath,
417
- })) ?? checkedRun;
418
- await verifyGoalRun(stagedRun, {
419
- stagingBranch: staged.stagingBranch,
420
- stagingPath: staged.stagingPath,
421
- mainBase: staged.mainBase,
422
- integratedTaskIds: staged.integratedTaskIds,
423
- changedFiles: staged.changedFiles,
424
- });
425
- return;
426
- }
427
- if (staged.status === "fallback") {
428
- await appendGoalDecision(cwd, checkedRun.id, {
429
- kind: "staged_integration_fallback",
430
- reason: staged.reason,
431
- });
432
- }
433
- }
434
- const latestRunBeforeCreate = (await loadGoalRuns(cwd)).find((item) => item.id === checkedRun.id) ?? checkedRun;
435
- const existingSameTitleTask = latestRunBeforeCreate.tasks.find((item) => item.title === decision.title);
436
- if (existingSameTitleTask) {
437
- const runWithExistingTask = await upsertGoalRun(cwd, {
438
- ...latestRunBeforeCreate,
439
- status: "ready",
440
- });
441
- appendGoalProgress({
442
- kind: "goal_progress",
443
- phase: "continuing",
444
- title: `Goal task already exists: ${decision.title}`,
445
- detail: "Reusing the existing Goal task instead of creating a duplicate.",
446
- status: "ready",
447
- });
448
- startGoalRunRef.current(runWithExistingTask);
449
- return;
450
- }
451
- await updateGoalTask(cwd, checkedRun.id, `auto-${Date.now()}`, {
452
- title: decision.title,
453
- prompt: decision.prompt,
454
- status: "pending",
455
- });
456
- const latestRun = (await loadGoalRuns(cwd)).find((item) => item.id === checkedRun.id) ?? checkedRun;
457
- const runWithTask = await upsertGoalRun(cwd, { ...latestRun, status: "ready" });
458
- appendGoalProgress({
459
- kind: "goal_progress",
460
- phase: "continuing",
461
- title: `Goal task created: ${decision.title}`,
462
- detail: "Starting the new Goal task now.",
463
- status: "ready",
464
- });
465
- startGoalRunRef.current(runWithTask);
466
- return;
467
- }
468
- if (decision.kind === "blocked") {
469
- await upsertGoalRun(cwd, {
470
- ...checkedRun,
471
- status: "blocked",
472
- blockers: [...checkedRun.blockers, decision.reason],
473
- });
474
- appendGoalProgress({
475
- kind: "goal_progress",
476
- phase: "terminal",
477
- title: `Goal blocked: ${checkedRun.title}`,
478
- detail: decision.reason,
479
- status: "blocked",
480
- });
481
- runningGoalIdsRef.current.delete(checkedRun.id);
482
- clearGoalStatusEntry(checkedRun.id);
483
- clearGoalModeIfIdle();
484
- return;
485
- }
486
- const runWithAttempt = (await updateGoalTask(cwd, checkedRun.id, decision.task.id, {
487
- attempts: decision.attempts,
488
- })) ?? checkedRun;
489
- const worker = await startGoalWorker({
490
- cwd,
491
- provider: currentProvider,
492
- model: currentModel,
493
- thinkingLevel,
494
- goalRunId: checkedRun.id,
495
- goalTaskId: decision.task.id,
496
- taskTitle: decision.task.title,
497
- prompt: buildGoalTaskPromptWithReferences(checkedRun, decision.task.prompt),
498
- isolateWorktree: shouldRunGoalTaskInMainCheckout(decision.task.title) ? false : undefined,
499
- });
500
- const latestRun = (await loadGoalRuns(cwd)).find((item) => item.id === checkedRun.id) ?? runWithAttempt;
501
- await upsertGoalRun(cwd, {
502
- ...latestRun,
503
- status: "running",
504
- activeWorkerId: worker.id,
505
- continueRequestedAt: undefined,
506
- tasks: latestRun.tasks.map((item) => item.id === decision.task.id
507
- ? { ...item, status: "running", workerId: worker.id, attempts: decision.attempts }
508
- : item),
509
- });
510
- appendGoalProgress({
511
- kind: "goal_progress",
512
- phase: "worker_started",
513
- title: `Worker started: ${decision.task.title}`,
514
- detail: "Task is running in the background.",
515
- workerId: worker.id,
516
- status: worker.status,
517
- });
518
- upsertGoalStatusEntry({
519
- runId: checkedRun.id,
520
- label: checkedRun.title,
521
- phase: "worker",
522
- startedAt: Date.now(),
523
- detail: "background worker running",
524
- workerId: worker.id,
525
- goalNumber: goalNumberForRun(checkedRun.id),
526
- ...goalTaskProgress(checkedRun, decision.task),
527
- });
528
- })().catch(async (err) => {
529
- clearGoalStatusEntry(run.id);
530
- clearGoalModeIfIdle();
531
- log("ERROR", "goal", err instanceof Error ? err.message : String(err));
532
- if (isGoalWorktreeDirtyError(err)) {
533
- const latestRun = (await loadGoalRuns(cwd)).find((item) => item.id === run.id) ?? run;
534
- const reason = `Goal worker startup could not establish a clean working tree even after an auto-checkpoint commit: ${err.message}`;
535
- const runWithEvidence = (await appendGoalEvidence(cwd, latestRun.id, {
536
- kind: "summary",
537
- label: "Goal failure diagnosis",
538
- content: reason,
539
- })) ?? latestRun;
540
- const failedRun = await upsertGoalRun(cwd, {
541
- ...runWithEvidence,
542
- status: "failed",
543
- activeWorkerId: undefined,
544
- continueRequestedAt: undefined,
545
- blockers: Array.from(new Set([...runWithEvidence.blockers, reason])),
546
- });
547
- runningGoalIdsRef.current.delete(failedRun.id);
548
- appendGoalProgress({
549
- kind: "goal_progress",
550
- phase: "terminal",
551
- title: `Goal failed: ${failedRun.title}`,
552
- detail: reason,
553
- status: "failed",
554
- });
555
- return;
556
- }
557
- setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal")]);
558
- });
559
- }, [
560
- cwd,
561
- currentProvider,
562
- currentModel,
563
- thinkingLevel,
564
- agentLoop,
565
- appendGoalProgress,
566
- clearGoalModeIfIdle,
567
- clearGoalStatusEntry,
568
- goalNumberForRun,
569
- setGoalModeAndPrompt,
570
- upsertGoalStatusEntry,
571
- ]);
572
- const verifyGoalRun = useCallback(async (run, staging) => {
573
- await setGoalModeAndPrompt("coordinator");
574
- if (!run.verifier?.command) {
575
- await appendGoalEvidence(cwd, run.id, {
576
- kind: "summary",
577
- label: "Missing verifier",
578
- content: "No verifier command is configured.",
579
- });
580
- await upsertGoalRun(cwd, {
581
- ...run,
582
- status: "blocked",
583
- blockers: [...run.blockers, "No verifier command configured."],
584
- });
585
- appendGoalProgress({
586
- kind: "goal_progress",
587
- phase: "terminal",
588
- title: `Goal blocked: ${run.title}`,
589
- detail: "No verifier command is configured.",
590
- status: "blocked",
591
- });
592
- runningGoalIdsRef.current.delete(run.id);
593
- clearGoalStatusEntry(run.id);
594
- clearGoalModeIfIdle();
595
- return;
596
- }
597
- const integration = await checkGoalWorktreeIntegration(cwd, run);
598
- if (!integration.ok) {
599
- const runWithEvidence = (await appendGoalEvidence(cwd, run.id, {
600
- kind: "summary",
601
- label: "Goal worktree integration required",
602
- content: integration.summary,
603
- })) ?? run;
604
- await upsertGoalRun(cwd, {
605
- ...runWithEvidence,
606
- status: "blocked",
607
- blockers: Array.from(new Set([...runWithEvidence.blockers, integration.summary])),
608
- });
609
- appendGoalProgress({
610
- kind: "goal_progress",
611
- phase: "terminal",
612
- title: `Goal blocked before verifier: ${run.title}`,
613
- detail: integration.summary,
614
- status: "blocked",
615
- });
616
- runningGoalIdsRef.current.delete(run.id);
617
- clearGoalStatusEntry(run.id);
618
- clearGoalModeIfIdle();
619
- return;
620
- }
621
- activeVerifierRunIdsRef.current.add(run.id);
622
- await upsertGoalRun(cwd, {
623
- ...run,
624
- status: "verifying",
625
- continueRequestedAt: undefined,
626
- });
627
- appendGoalProgress({
628
- kind: "goal_progress",
629
- phase: "verifier_started",
630
- title: `Verifier started: ${run.title}`,
631
- detail: run.verifier.command,
632
- status: "verifying",
633
- });
634
- const startedAt = Date.now();
635
- const verifierTimeoutMs = Number(process.env.GG_GOAL_VERIFIER_TIMEOUT_MS ?? 10 * 60 * 1000);
636
- upsertGoalStatusEntry({
637
- runId: run.id,
638
- label: run.title,
639
- phase: "verifier",
640
- startedAt,
641
- detail: run.verifier.command,
642
- goalNumber: goalNumberForRun(run.id),
643
- });
644
- void runGoalVerifierCommand({
645
- cwd: staging?.stagingPath ?? run.verifier.cwd ?? cwd,
646
- runId: run.id,
647
- command: run.verifier.command,
648
- timeoutMs: verifierTimeoutMs,
649
- now: () => startedAt,
650
- })
651
- .then(async ({ verification, failureClass, durationMs }) => {
652
- activeVerifierRunIdsRef.current.delete(run.id);
653
- const status = verification.status;
654
- const summary = verification.summary;
655
- const outputPath = verification.outputPath;
656
- // Verify-then-fast-forward: only advance main once the staged
657
- // integration verifies green; on failure main is left untouched.
658
- if (staging) {
659
- if (status === "pass") {
660
- try {
661
- const ff = await finalizeStagedIntegration({ projectPath: cwd, staging });
662
- await setGoalIntegrationState(cwd, run.id, {
663
- status: "committed",
664
- headSha: ff.commitSha,
665
- baseRef: staging.mainBase,
666
- files: staging.changedFiles,
667
- updatedAt: new Date().toISOString(),
668
- });
669
- await appendGoalEvidence(cwd, run.id, {
670
- kind: "summary",
671
- label: "Integrated worktree applied to main",
672
- content: `Verified staged integration fast-forwarded to main. tasks=${staging.integratedTaskIds.join(", ")}; files=${staging.changedFiles.join(", ")}; commit=${ff.commitSha}`,
673
- });
674
- await appendGoalEvidence(cwd, run.id, {
675
- kind: "summary",
676
- label: "Integrated Goal changes committed",
677
- content: `Fast-forwarded ${staging.changedFiles.length} file(s) to main; commit=${ff.commitSha}.`,
678
- });
679
- }
680
- catch (ffErr) {
681
- await discardStagedIntegration({ projectPath: cwd, staging });
682
- await appendGoalEvidence(cwd, run.id, {
683
- kind: "summary",
684
- label: "Integration fast-forward failed",
685
- content: `Staged integration verified but main could not fast-forward; will retry or apply. ${ffErr instanceof Error ? ffErr.message : String(ffErr)}`,
686
- });
687
- }
688
- }
689
- else {
690
- await discardStagedIntegration({ projectPath: cwd, staging });
691
- await appendGoalEvidence(cwd, run.id, {
692
- kind: "summary",
693
- label: "Staged integration discarded",
694
- content: "Verifier failed on the staged integration; discarded the staging branch and left main unchanged.",
695
- });
696
- }
697
- }
698
- const latestRun = (await loadGoalRuns(cwd)).find((item) => item.id === run.id) ?? run;
699
- const runWithVerifier = {
700
- ...latestRun,
701
- verifier: {
702
- ...latestRun.verifier,
703
- description: latestRun.verifier?.description ?? "Goal verifier",
704
- command: run.verifier?.command,
705
- ...(!staging && run.verifier?.cwd ? { cwd: run.verifier.cwd } : {}),
706
- lastResult: verification,
707
- },
708
- ...(status === "pass"
709
- ? {
710
- completionAudit: {
711
- status: "unknown",
712
- summary: "Final completion audit pending for latest verifier result.",
713
- checkedAt: verification.checkedAt,
714
- verifierCheckedAt: verification.checkedAt,
715
- ...(verification.outputPath ? { outputPath: verification.outputPath } : {}),
716
- },
717
- }
718
- : {}),
719
- };
720
- const completionCheck = canCompleteGoalRun(runWithVerifier);
721
- await upsertGoalRun(cwd, {
722
- ...runWithVerifier,
723
- continueRequestedAt: latestRun.continueRequestedAt,
724
- status: status === "pass" && completionCheck.ok ? "passed" : "ready",
725
- });
726
- await appendGoalEvidence(cwd, run.id, {
727
- kind: "command",
728
- label: `Verifier ${status}`,
729
- content: `${failureClass}: ${summary}`.slice(0, 4000),
730
- path: outputPath,
731
- });
732
- await appendGoalDecision(cwd, run.id, {
733
- kind: `verifier_${status}`,
734
- reason: `${failureClass}: verifier exited with code ${verification.exitCode ?? 1}.`,
735
- content: `outputPath=${outputPath ?? ""}; cwd=${run.verifier?.cwd ?? cwd}; durationMs=${durationMs}`,
736
- });
737
- appendGoalProgress({
738
- kind: "goal_progress",
739
- phase: "verifier_finished",
740
- title: `Verifier ${status}: ${run.title}`,
741
- detail: summarizeGoalCompletion(summary),
742
- status,
743
- });
744
- upsertGoalStatusEntry({
745
- runId: run.id,
746
- label: run.title,
747
- phase: status === "pass" ? "reviewing" : "failed",
748
- startedAt: Date.now(),
749
- detail: status === "pass" ? "reviewing verifier evidence" : "verifier failed",
750
- goalNumber: goalNumberForRun(run.id),
751
- });
752
- const continuationRun = (await loadGoalRuns(cwd)).find((item) => item.id === run.id);
753
- if (continuationRun?.continueRequestedAt || status === "fail" || status === "pass") {
754
- setTimeout(() => continueGoalRun(run.id), 500);
755
- }
756
- })
757
- .catch((err) => {
758
- activeVerifierRunIdsRef.current.delete(run.id);
759
- clearGoalStatusEntry(run.id);
760
- clearGoalModeIfIdle();
761
- log("ERROR", "goal", err instanceof Error ? err.message : String(err));
762
- setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal verifier")]);
763
- });
764
- }, [
765
- cwd,
766
- appendGoalProgress,
767
- clearGoalModeIfIdle,
768
- clearGoalStatusEntry,
769
- goalNumberForRun,
770
- setGoalModeAndPrompt,
771
- upsertGoalStatusEntry,
772
- ]);
773
- const pauseGoalRun = useCallback((run) => {
774
- void (async () => {
775
- runningGoalIdsRef.current.delete(run.id);
776
- if (run.activeWorkerId)
777
- await stopGoalWorker(run.activeWorkerId);
778
- const latestRun = (await loadGoalRuns(cwd)).find((item) => item.id === run.id) ?? run;
779
- await upsertGoalRun(cwd, buildGoalUserPauseRun(latestRun));
780
- appendGoalProgress({
781
- kind: "goal_progress",
782
- phase: "terminal",
783
- title: `Goal paused: ${run.title}`,
784
- detail: "Auto-continuation stopped until resumed.",
785
- status: "paused",
786
- });
787
- clearGoalStatusEntry(run.id);
788
- clearGoalModeIfIdle();
789
- })().catch((err) => {
790
- log("ERROR", "goal", err instanceof Error ? err.message : String(err));
791
- setLiveItems((prev) => [...prev, toErrorItem(err, getId(), "Goal")]);
792
- });
793
- }, [appendGoalProgress, clearGoalModeIfIdle, clearGoalStatusEntry, cwd]);
794
- const startTask = useCallback((title, prompt, taskId) => {
795
- const taskCwd = cwdRef.current;
796
- const shortId = taskId.slice(0, 8);
797
- const completionHint = `\n\n---\nWhen you have fully completed this task, call the tasks tool to mark it done:\n` +
798
- `tasks({ action: "done", id: "${shortId}" })`;
799
- const fullPrompt = prompt + completionHint;
800
- if (resetUI && sessionStore) {
801
- const sysMsg = messagesRef.current[0];
802
- const newMessages = sysMsg && sysMsg.role === "system" ? [sysMsg] : messagesRef.current.slice(0, 1);
803
- const taskItem = { kind: "task", title, id: getId() };
804
- const sm = sessionManagerRef.current;
805
- void (async () => {
806
- let newSessionPath;
807
- if (sm) {
808
- try {
809
- const session = await sm.create(taskCwd, currentProvider, currentModel);
810
- newSessionPath = session.path;
811
- log("INFO", "tasks", "New session for task", { path: session.path });
812
- }
813
- catch {
814
- // Session creation is best-effort.
815
- }
816
- }
817
- if (sessionStore)
818
- sessionStore.overlay = null;
819
- resetUI?.({
820
- wipeSession: true,
821
- messages: newMessages,
822
- history: [{ kind: "banner", id: "banner" }, taskItem],
823
- sessionPath: newSessionPath,
824
- pendingAction: { prompt: fullPrompt },
825
- });
826
- })();
827
- return;
828
- }
829
- clearPendingHistory();
830
- setHistory([{ kind: "banner", id: "banner" }]);
831
- setLiveItems([]);
832
- messagesRef.current = messagesRef.current.slice(0, 1);
833
- agentLoop.reset();
834
- persistedIndexRef.current = messagesRef.current.length;
835
- const sm = sessionManagerRef.current;
836
- if (sm) {
837
- void sm.create(taskCwd, currentProvider, currentModel).then((session) => {
838
- sessionPathRef.current = session.path;
839
- log("INFO", "tasks", "New session for task", { path: session.path });
840
- });
841
- }
842
- const taskItem = { kind: "task", title, id: getId() };
843
- setLastUserMessage(title);
844
- setDoneStatus(null);
845
- setLiveItems([taskItem]);
846
- void agentLoop.run(fullPrompt).catch((err) => {
847
- setLiveItems((prev) => [...prev, toErrorItem(err, getId())]);
848
- });
849
- }, [agentLoop, currentModel, currentProvider, resetUI, sessionStore]);
850
- // Keep refs in sync for access from stale closures (onDone).
851
- startTaskRef.current = startTask;
852
- startGoalRunRef.current = startGoalRun;
853
- return {
854
- runGoalSyntheticEvent,
855
- continueGoalRun,
856
- handleGoalWorkerComplete,
857
- startGoalRun,
858
- verifyGoalRun,
859
- pauseGoalRun,
860
- startTask,
861
- };
862
- }
863
- //# sourceMappingURL=useGoalOrchestration.js.map