@opencorelabs/lucidity 0.8.0 → 0.9.5

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/README.md +2 -2
  2. package/dist/assets/speech/lucidity-speech +0 -0
  3. package/dist/automations/service.d.ts +4 -0
  4. package/dist/automations/service.d.ts.map +1 -1
  5. package/dist/automations/service.js +60 -22
  6. package/dist/automations/store.d.ts +9 -3
  7. package/dist/automations/store.d.ts.map +1 -1
  8. package/dist/automations/store.js +45 -32
  9. package/dist/automations/workflow.d.ts +14 -0
  10. package/dist/automations/workflow.d.ts.map +1 -0
  11. package/dist/automations/workflow.js +57 -0
  12. package/dist/coding/listPrs.d.ts +2 -0
  13. package/dist/coding/listPrs.d.ts.map +1 -1
  14. package/dist/coding/listPrs.js +10 -0
  15. package/dist/coding/runCodeTurn.d.ts +3 -14
  16. package/dist/coding/runCodeTurn.d.ts.map +1 -1
  17. package/dist/coding/runCodeTurn.js +21 -86
  18. package/dist/coding/runReview.d.ts +10 -0
  19. package/dist/coding/runReview.d.ts.map +1 -0
  20. package/dist/coding/runReview.js +87 -0
  21. package/dist/coding/workspaceRegistry.d.ts +49 -1
  22. package/dist/coding/workspaceRegistry.d.ts.map +1 -1
  23. package/dist/coding/workspaceRegistry.js +208 -17
  24. package/dist/coding/worktree.d.ts +61 -18
  25. package/dist/coding/worktree.d.ts.map +1 -1
  26. package/dist/coding/worktree.js +149 -17
  27. package/dist/coding/worktreeSetup.d.ts +7 -0
  28. package/dist/coding/worktreeSetup.d.ts.map +1 -0
  29. package/dist/coding/worktreeSetup.js +49 -0
  30. package/dist/index.js +21 -28
  31. package/dist/jobs/briefing.d.ts +2 -16
  32. package/dist/jobs/briefing.d.ts.map +1 -1
  33. package/dist/jobs/briefing.js +65 -93
  34. package/dist/logTimestamps.d.ts +10 -0
  35. package/dist/logTimestamps.d.ts.map +1 -0
  36. package/dist/logTimestamps.js +12 -0
  37. package/dist/providerRecovery.d.ts +48 -0
  38. package/dist/providerRecovery.d.ts.map +1 -0
  39. package/dist/providerRecovery.js +100 -0
  40. package/dist/room/client.d.ts +2 -20
  41. package/dist/room/client.d.ts.map +1 -1
  42. package/dist/room/client.js +18 -29
  43. package/dist/room/computer.d.ts.map +1 -1
  44. package/dist/room/computer.js +1 -2
  45. package/dist/room/incidents.d.ts +3 -0
  46. package/dist/room/incidents.d.ts.map +1 -1
  47. package/dist/room/incidents.js +1 -0
  48. package/dist/room/turnQueue.d.ts.map +1 -1
  49. package/dist/room/turnQueue.js +28 -22
  50. package/dist/runtimeStore.d.ts +2 -0
  51. package/dist/runtimeStore.d.ts.map +1 -1
  52. package/dist/runtimeStore.js +17 -0
  53. package/dist/vault.d.ts +6 -3
  54. package/dist/vault.d.ts.map +1 -1
  55. package/dist/vault.js +18 -4
  56. package/package.json +1 -1
  57. package/src/automations/service.ts +47 -21
  58. package/src/automations/store.ts +41 -50
  59. package/src/automations/workflow.ts +49 -0
  60. package/src/coding/listPrs.ts +14 -0
  61. package/src/coding/runCodeTurn.ts +26 -95
  62. package/src/coding/runReview.ts +83 -0
  63. package/src/coding/workspaceRegistry.ts +186 -16
  64. package/src/coding/worktree.ts +161 -20
  65. package/src/coding/worktreeSetup.ts +50 -0
  66. package/src/index.ts +22 -31
  67. package/src/jobs/briefing.ts +62 -109
  68. package/src/logTimestamps.ts +14 -0
  69. package/src/providerRecovery.ts +99 -0
  70. package/src/room/client.ts +19 -54
  71. package/src/room/computer.ts +1 -2
  72. package/src/room/incidents.ts +4 -0
  73. package/src/room/turnQueue.ts +27 -29
  74. package/src/runtimeStore.ts +18 -1
  75. package/src/vault.ts +16 -7
  76. package/vendor/mcp-server/package.json +1 -1
  77. package/vendor/runtime/README.md +34 -0
  78. package/vendor/runtime/dist/executor/claudeAgent.d.ts +4 -0
  79. package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
  80. package/vendor/runtime/dist/executor/claudeAgent.js +57 -4
  81. package/vendor/runtime/dist/executor/codex.d.ts +7 -2
  82. package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
  83. package/vendor/runtime/dist/executor/codex.js +47 -4
  84. package/vendor/runtime/dist/executor/codexProtocol/AgentPath.d.ts +2 -0
  85. package/vendor/runtime/dist/executor/codexProtocol/AgentPath.d.ts.map +1 -0
  86. package/vendor/runtime/dist/executor/codexProtocol/AgentPath.js +2 -0
  87. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.d.ts +6 -0
  88. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.d.ts.map +1 -0
  89. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.js +2 -0
  90. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.d.ts +12 -0
  91. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.d.ts.map +1 -0
  92. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.js +2 -0
  93. package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.d.ts +24 -0
  94. package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.d.ts.map +1 -0
  95. package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.js +2 -0
  96. package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.d.ts +8 -0
  97. package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.d.ts.map +1 -0
  98. package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.js +2 -0
  99. package/vendor/runtime/dist/executor/codexProtocol/SleepItem.d.ts +8 -0
  100. package/vendor/runtime/dist/executor/codexProtocol/SleepItem.d.ts.map +1 -0
  101. package/vendor/runtime/dist/executor/codexProtocol/SleepItem.js +2 -0
  102. package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.d.ts +14 -0
  103. package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.d.ts.map +1 -0
  104. package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.js +2 -0
  105. package/vendor/runtime/dist/executor/codexProtocol/ThreadId.d.ts +7 -0
  106. package/vendor/runtime/dist/executor/codexProtocol/ThreadId.d.ts.map +1 -0
  107. package/vendor/runtime/dist/executor/codexProtocol/ThreadId.js +2 -0
  108. package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.d.ts +15 -0
  109. package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.d.ts.map +1 -0
  110. package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.js +2 -0
  111. package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.d.ts +2 -0
  112. package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.d.ts.map +1 -0
  113. package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.js +2 -0
  114. package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.d.ts +5 -0
  115. package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.d.ts.map +1 -0
  116. package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.js +2 -0
  117. package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.d.ts +29 -0
  118. package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.d.ts.map +1 -0
  119. package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.js +2 -0
  120. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.d.ts +6 -0
  121. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.d.ts.map +1 -0
  122. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.js +2 -0
  123. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.d.ts +2 -0
  124. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.d.ts.map +1 -0
  125. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.js +2 -0
  126. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.d.ts +2 -0
  127. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.d.ts.map +1 -0
  128. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.js +2 -0
  129. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.d.ts +2 -0
  130. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.d.ts.map +1 -0
  131. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.js +2 -0
  132. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.d.ts +20 -0
  133. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.d.ts.map +1 -0
  134. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.js +2 -0
  135. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.d.ts +2 -0
  136. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.d.ts.map +1 -0
  137. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.js +2 -0
  138. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.d.ts +2 -0
  139. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.d.ts.map +1 -0
  140. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.js +2 -0
  141. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.d.ts +11 -0
  142. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.d.ts.map +1 -0
  143. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.js +2 -0
  144. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.d.ts +2 -0
  145. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.d.ts.map +1 -0
  146. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.js +2 -0
  147. package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.d.ts +7 -0
  148. package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.d.ts.map +1 -0
  149. package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.js +2 -0
  150. package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.d.ts +6 -0
  151. package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.d.ts.map +1 -0
  152. package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.js +2 -0
  153. package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.d.ts +5 -0
  154. package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.d.ts.map +1 -0
  155. package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.js +2 -0
  156. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.d.ts +2 -0
  157. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.d.ts.map +1 -0
  158. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.js +2 -0
  159. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.d.ts +9 -0
  160. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.d.ts.map +1 -0
  161. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.js +2 -0
  162. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.d.ts +8 -0
  163. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.d.ts.map +1 -0
  164. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.js +2 -0
  165. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.d.ts +4 -0
  166. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.d.ts.map +1 -0
  167. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.js +2 -0
  168. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.d.ts +7 -0
  169. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.d.ts.map +1 -0
  170. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.js +2 -0
  171. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.d.ts +2 -0
  172. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.d.ts.map +1 -0
  173. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.js +2 -0
  174. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.d.ts +6 -0
  175. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.d.ts.map +1 -0
  176. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.js +2 -0
  177. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.d.ts +7 -0
  178. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.d.ts.map +1 -0
  179. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.js +2 -0
  180. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.d.ts +16 -0
  181. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.d.ts.map +1 -0
  182. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.js +2 -0
  183. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.d.ts +4 -0
  184. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.d.ts.map +1 -0
  185. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.js +2 -0
  186. package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.d.ts +2 -0
  187. package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.d.ts.map +1 -0
  188. package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.js +2 -0
  189. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.d.ts +2 -0
  190. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.d.ts.map +1 -0
  191. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.js +2 -0
  192. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.d.ts +9 -0
  193. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.d.ts.map +1 -0
  194. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.js +2 -0
  195. package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.d.ts +7 -0
  196. package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.d.ts.map +1 -0
  197. package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.js +2 -0
  198. package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.d.ts +2 -0
  199. package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.d.ts.map +1 -0
  200. package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.js +2 -0
  201. package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.d.ts +100 -0
  202. package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.d.ts.map +1 -0
  203. package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.js +2 -0
  204. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.d.ts +2 -0
  205. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.d.ts.map +1 -0
  206. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.js +2 -0
  207. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.d.ts +2 -0
  208. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.d.ts.map +1 -0
  209. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.js +2 -0
  210. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.d.ts +216 -0
  211. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.d.ts.map +1 -0
  212. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.js +2 -0
  213. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.d.ts +11 -0
  214. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.d.ts.map +1 -0
  215. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.js +2 -0
  216. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.d.ts +5 -0
  217. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.d.ts.map +1 -0
  218. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.js +2 -0
  219. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.d.ts +19 -0
  220. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.d.ts.map +1 -0
  221. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.js +2 -0
  222. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.d.ts +8 -0
  223. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.d.ts.map +1 -0
  224. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.js +2 -0
  225. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.d.ts +12 -0
  226. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.d.ts.map +1 -0
  227. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.js +2 -0
  228. package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.d.ts +36 -0
  229. package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.d.ts.map +1 -0
  230. package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.js +2 -0
  231. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.d.ts +12 -0
  232. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.d.ts.map +1 -0
  233. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.js +2 -0
  234. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.d.ts +2 -0
  235. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.d.ts.map +1 -0
  236. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.js +2 -0
  237. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.d.ts +2 -0
  238. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.d.ts.map +1 -0
  239. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.js +2 -0
  240. package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.d.ts +15 -0
  241. package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.d.ts.map +1 -0
  242. package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.js +2 -0
  243. package/vendor/runtime/dist/executor/codexRpc.d.ts +3 -1
  244. package/vendor/runtime/dist/executor/codexRpc.d.ts.map +1 -1
  245. package/vendor/runtime/dist/executor/codexRpc.js +3 -2
  246. package/vendor/runtime/dist/executor/health.d.ts +6 -1
  247. package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
  248. package/vendor/runtime/dist/executor/health.js +4 -0
  249. package/vendor/runtime/dist/executor/ownership.d.ts +6 -1
  250. package/vendor/runtime/dist/executor/ownership.d.ts.map +1 -1
  251. package/vendor/runtime/dist/executor/ownership.js +7 -0
  252. package/vendor/runtime/dist/executor/types.d.ts +25 -0
  253. package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
  254. package/vendor/runtime/dist/harness/index.d.ts.map +1 -1
  255. package/vendor/runtime/dist/harness/index.js +1 -0
  256. package/vendor/runtime/dist/index.d.ts +1 -1
  257. package/vendor/runtime/dist/index.d.ts.map +1 -1
  258. package/vendor/runtime/src/executor/claudeAgent.ts +50 -4
  259. package/vendor/runtime/src/executor/codex.ts +51 -5
  260. package/vendor/runtime/src/executor/codexProtocol/AgentPath.ts +5 -0
  261. package/vendor/runtime/src/executor/codexProtocol/ImageGenerationFailure.ts +5 -0
  262. package/vendor/runtime/src/executor/codexProtocol/ImageGenerationItem.ts +7 -0
  263. package/vendor/runtime/src/executor/codexProtocol/LegacyAppPathString.ts +27 -0
  264. package/vendor/runtime/src/executor/codexProtocol/MessagePhase.ts +11 -0
  265. package/vendor/runtime/src/executor/codexProtocol/SleepItem.ts +8 -0
  266. package/vendor/runtime/src/executor/codexProtocol/SubAgentSource.ts +7 -0
  267. package/vendor/runtime/src/executor/codexProtocol/ThreadId.ts +10 -0
  268. package/vendor/runtime/src/executor/codexProtocol/WebSearchItem.ts +14 -0
  269. package/vendor/runtime/src/executor/codexProtocol/v2/AgentMessageDelivery.ts +5 -0
  270. package/vendor/runtime/src/executor/codexProtocol/v2/AsyncUserInputQuestion.ts +5 -0
  271. package/vendor/runtime/src/executor/codexProtocol/v2/CodexErrorInfo.ts +12 -0
  272. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentState.ts +6 -0
  273. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentStatus.ts +5 -0
  274. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentTool.ts +5 -0
  275. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentToolCallStatus.ts +5 -0
  276. package/vendor/runtime/src/executor/codexProtocol/v2/CommandAction.ts +6 -0
  277. package/vendor/runtime/src/executor/codexProtocol/v2/CommandExecutionSource.ts +5 -0
  278. package/vendor/runtime/src/executor/codexProtocol/v2/CommandExecutionStatus.ts +5 -0
  279. package/vendor/runtime/src/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.ts +5 -0
  280. package/vendor/runtime/src/executor/codexProtocol/v2/DynamicToolCallStatus.ts +5 -0
  281. package/vendor/runtime/src/executor/codexProtocol/v2/FileUpdateChange.ts +6 -0
  282. package/vendor/runtime/src/executor/codexProtocol/v2/GitInfo.ts +5 -0
  283. package/vendor/runtime/src/executor/codexProtocol/v2/HookPromptFragment.ts +5 -0
  284. package/vendor/runtime/src/executor/codexProtocol/v2/McpAppDisplayMode.ts +5 -0
  285. package/vendor/runtime/src/executor/codexProtocol/v2/McpAppUi.ts +9 -0
  286. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallAppContext.ts +5 -0
  287. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallError.ts +5 -0
  288. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallResult.ts +6 -0
  289. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallStatus.ts +5 -0
  290. package/vendor/runtime/src/executor/codexProtocol/v2/MemoryCitation.ts +6 -0
  291. package/vendor/runtime/src/executor/codexProtocol/v2/MemoryCitationEntry.ts +5 -0
  292. package/vendor/runtime/src/executor/codexProtocol/v2/MisalignmentErrorDetails.ts +18 -0
  293. package/vendor/runtime/src/executor/codexProtocol/v2/MisalignmentSteer.ts +5 -0
  294. package/vendor/runtime/src/executor/codexProtocol/v2/NonSteerableTurnKind.ts +5 -0
  295. package/vendor/runtime/src/executor/codexProtocol/v2/PatchApplyStatus.ts +5 -0
  296. package/vendor/runtime/src/executor/codexProtocol/v2/PatchChangeKind.ts +5 -0
  297. package/vendor/runtime/src/executor/codexProtocol/v2/SessionSource.ts +6 -0
  298. package/vendor/runtime/src/executor/codexProtocol/v2/SubAgentActivityKind.ts +5 -0
  299. package/vendor/runtime/src/executor/codexProtocol/v2/Thread.ts +104 -0
  300. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadActiveFlag.ts +5 -0
  301. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadHistoryMode.ts +5 -0
  302. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadItem.ts +125 -0
  303. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadReadParams.ts +12 -0
  304. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadReadResponse.ts +6 -0
  305. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSection.ts +21 -0
  306. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSectionAppearance.ts +8 -0
  307. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStatus.ts +6 -0
  308. package/vendor/runtime/src/executor/codexProtocol/v2/Turn.ts +37 -0
  309. package/vendor/runtime/src/executor/codexProtocol/v2/TurnError.ts +11 -0
  310. package/vendor/runtime/src/executor/codexProtocol/v2/TurnItemsView.ts +5 -0
  311. package/vendor/runtime/src/executor/codexProtocol/v2/TurnStatus.ts +5 -0
  312. package/vendor/runtime/src/executor/codexProtocol/v2/WebSearchAction.ts +5 -0
  313. package/vendor/runtime/src/executor/codexRpc.ts +4 -2
  314. package/vendor/runtime/src/executor/health.ts +5 -1
  315. package/vendor/runtime/src/executor/ownership.ts +8 -1
  316. package/vendor/runtime/src/executor/types.ts +18 -1
  317. package/vendor/runtime/src/harness/index.ts +1 -0
  318. package/vendor/runtime/src/index.ts +1 -1
  319. package/vendor/shared/dist/automations.d.ts +34 -0
  320. package/vendor/shared/dist/automations.d.ts.map +1 -1
  321. package/vendor/shared/dist/automations.js +12 -0
  322. package/vendor/shared/dist/computer.d.ts +1 -1
  323. package/vendor/shared/dist/computer.d.ts.map +1 -1
  324. package/vendor/shared/dist/computer.js +1 -2
  325. package/vendor/shared/dist/constants.d.ts +1 -1
  326. package/vendor/shared/dist/constants.d.ts.map +1 -1
  327. package/vendor/shared/dist/constants.js +3 -10
  328. package/vendor/shared/dist/index.d.ts +4 -2
  329. package/vendor/shared/dist/index.d.ts.map +1 -1
  330. package/vendor/shared/dist/index.js +3 -1
  331. package/vendor/shared/dist/journal-vault.d.ts +1 -1
  332. package/vendor/shared/dist/messagingSafety.d.ts +21 -0
  333. package/vendor/shared/dist/messagingSafety.d.ts.map +1 -0
  334. package/vendor/shared/dist/messagingSafety.js +8 -0
  335. package/vendor/shared/dist/schemas/harness.d.ts +98 -169
  336. package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
  337. package/vendor/shared/dist/schemas/harness.js +19 -124
  338. package/vendor/shared/dist/smartCapture.d.ts +24 -0
  339. package/vendor/shared/dist/smartCapture.d.ts.map +1 -1
  340. package/vendor/shared/dist/smartCapture.js +15 -0
  341. package/vendor/shared/dist/taskSync.d.ts +342 -0
  342. package/vendor/shared/dist/taskSync.d.ts.map +1 -0
  343. package/vendor/shared/dist/taskSync.js +111 -0
  344. package/vendor/shared/dist/types.d.ts +1 -4
  345. package/vendor/shared/dist/types.d.ts.map +1 -1
  346. package/vendor/shared/dist/voiceCapture.d.ts +1 -1
  347. package/vendor/shared/dist/workspaces.d.ts +117 -0
  348. package/vendor/shared/dist/workspaces.d.ts.map +1 -1
  349. package/vendor/shared/dist/workspaces.js +50 -1
  350. package/vendor/shared/src/automations.ts +12 -0
  351. package/vendor/shared/src/computer.ts +3 -3
  352. package/vendor/shared/src/constants.ts +3 -10
  353. package/vendor/shared/src/index.ts +3 -6
  354. package/vendor/shared/src/messagingSafety.ts +11 -0
  355. package/vendor/shared/src/schemas/harness.ts +18 -130
  356. package/vendor/shared/src/smartCapture.ts +27 -0
  357. package/vendor/shared/src/taskSync.ts +81 -0
  358. package/vendor/shared/src/types.ts +0 -6
  359. package/vendor/shared/src/workspaces.ts +56 -1
  360. package/dist/coding/conduct.d.ts +0 -48
  361. package/dist/coding/conduct.d.ts.map +0 -1
  362. package/dist/coding/conduct.js +0 -263
  363. package/dist/coding/fleetPlan.d.ts +0 -20
  364. package/dist/coding/fleetPlan.d.ts.map +0 -1
  365. package/dist/coding/fleetPlan.js +0 -125
  366. package/dist/coding/fleetTasks.d.ts +0 -33
  367. package/dist/coding/fleetTasks.d.ts.map +0 -1
  368. package/dist/coding/fleetTasks.js +0 -75
  369. package/src/coding/conduct.ts +0 -325
  370. package/src/coding/fleetPlan.ts +0 -135
  371. package/src/coding/fleetTasks.ts +0 -109
@@ -1,125 +0,0 @@
1
- import { z } from 'zod';
2
- import { uuidv7 } from 'uuidv7';
3
- import { FleetPlanSchema } from '@lucidity/shared';
4
- /**
5
- * The conductor's planning brain, kept pure so it's unit-testable without a model or a repo.
6
- *
7
- * A `conduct` `plan` turn asks the lead to decompose a goal into independent workers; this
8
- * module builds that prompt, parses the lead's JSON answer into a validated {@link FleetPlan}
9
- * (minting a stable workerId per worker), and derives the owned-path overlaps that become the
10
- * Fan-out card's ⚠ and the reason a merge order exists. Nothing here runs code or touches git.
11
- */
12
- /** The lead's JSON, before we mint ids — what we ask the model to emit. Lenient on purpose:
13
- * a missing mergeOrder falls back to array order, so a terse model still yields a usable plan. */
14
- const RawWorkerSchema = z.object({
15
- title: z.string().min(1).max(200),
16
- brief: z.string().min(1).max(8000),
17
- ownedPaths: z.array(z.string()).max(200).default([]),
18
- mergeOrder: z.number().int().optional(),
19
- });
20
- const RawPlanSchema = z.object({
21
- workers: z.array(RawWorkerSchema).min(1).max(16),
22
- maxParallel: z.number().int().positive().max(16).optional(),
23
- });
24
- export function buildConductPlanPrompt(goal) {
25
- return [
26
- 'You are the lead engineer of a small fleet of coding agents working in one repository.',
27
- 'Decompose the goal below into independent WORKERS that can each run in its own git worktree.',
28
- '',
29
- 'Rules:',
30
- '- Prefer the FEWEST workers that cleanly cover the goal. A goal that is really one coherent',
31
- ' change is ONE worker — do not split for the sake of it.',
32
- '- Give each worker a set of owned paths (files or directories it may touch). Keep owned',
33
- ' paths DISJOINT between workers wherever you can; two workers that must touch the same file',
34
- ' will be integrated one after another, so note that by giving them different merge orders.',
35
- '- `mergeOrder` is the order their branches integrate back (lower first). Put a worker whose',
36
- ' work others build on earlier.',
37
- '',
38
- 'Answer with a short sentence of reasoning, then a single fenced ```json block of the form:',
39
- '{ "workers": [ { "title": "...", "brief": "the full instruction for this worker",',
40
- ' "ownedPaths": ["path/or/dir", "..."], "mergeOrder": 1 } ] }',
41
- '',
42
- `GOAL: ${goal}`,
43
- ].join('\n');
44
- }
45
- /** Strip a path down to what it "covers" for overlap purposes — drop a trailing glob/slash. */
46
- function pathBase(p) {
47
- return p
48
- .trim()
49
- .replace(/\/+$/, '')
50
- .replace(/\/\*\*?$/, '')
51
- .replace(/\/+$/, '');
52
- }
53
- /** Do two owned-path entries cover any of the same tree — the same file, or one a directory of
54
- * the other? (`src/config.ts` vs `src/config.ts`; `src` vs `src/config.ts`.) */
55
- export function pathsOverlap(a, b) {
56
- const x = pathBase(a);
57
- const y = pathBase(b);
58
- if (!x || !y)
59
- return false;
60
- return x === y || x.startsWith(`${y}/`) || y.startsWith(`${x}/`);
61
- }
62
- /** Every worker pair whose owned paths intersect, with the offending paths — the Fan-out card's
63
- * ⚠, and what tells the runner these two must integrate sequentially rather than race a merge. */
64
- export function detectOverlaps(workers) {
65
- const out = [];
66
- for (let i = 0; i < workers.length; i++) {
67
- for (let j = i + 1; j < workers.length; j++) {
68
- const paths = [];
69
- for (const pa of workers[i].ownedPaths) {
70
- for (const pb of workers[j].ownedPaths) {
71
- if (pathsOverlap(pa, pb))
72
- paths.push(pathBase(pa));
73
- }
74
- }
75
- if (paths.length) {
76
- out.push({
77
- a: workers[i].workerId,
78
- b: workers[j].workerId,
79
- paths: [...new Set(paths)],
80
- });
81
- }
82
- }
83
- }
84
- return out.length ? out : undefined;
85
- }
86
- /** Pull the first JSON object out of the lead's answer — a fenced ```json block if present,
87
- * else the first balanced `{…}`. Returns the raw string or throws a readable error. */
88
- function extractJson(text) {
89
- const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/i);
90
- if (fenced?.[1])
91
- return fenced[1].trim();
92
- const start = text.indexOf('{');
93
- const end = text.lastIndexOf('}');
94
- if (start !== -1 && end > start)
95
- return text.slice(start, end + 1);
96
- throw new Error('the plan had no JSON block');
97
- }
98
- /**
99
- * Parse the lead's answer into a validated FleetPlan, minting a stable `workerId` (uuidv7) per
100
- * worker — the id doubles as the fleet subtask's id and the stream id its code frames arrive
101
- * under. `genId` is injectable so tests get deterministic ids. Throws on unparseable output.
102
- */
103
- export function parseFleetPlan(modelText, opts) {
104
- const genId = opts.genId ?? uuidv7;
105
- const raw = RawPlanSchema.parse(JSON.parse(extractJson(modelText)));
106
- const workers = raw.workers.map((w, i) => ({
107
- workerId: genId(),
108
- title: w.title,
109
- brief: w.brief,
110
- ownedPaths: w.ownedPaths,
111
- mergeOrder: w.mergeOrder ?? i + 1,
112
- }));
113
- const plan = {
114
- goal: opts.goal,
115
- workers,
116
- overlaps: detectOverlaps(workers),
117
- maxParallel: raw.maxParallel,
118
- };
119
- // Validate the assembled plan against the wire schema before it leaves the daemon.
120
- return FleetPlanSchema.parse(plan);
121
- }
122
- /** Workers in the order their branches should integrate (lower mergeOrder first, stable). */
123
- export function integrationOrder(plan) {
124
- return [...plan.workers].sort((a, b) => a.mergeOrder - b.mergeOrder);
125
- }
@@ -1,33 +0,0 @@
1
- import type { FleetPlan, WorkerStatus } from '@lucidity/shared';
2
- /**
3
- * The dogfood: a fan-out's org chart IS the user's Lucidity backlog. A plan becomes a parent
4
- * task (the goal) with one subtask per worker — the subtask's id is the workerId, its
5
- * description is the worker's brief + owned paths, its priority is the merge order. The Fleet
6
- * board is then just "the goal's subtasks", and worker progress writes back as task status.
7
- *
8
- * Everything here is best-effort against the REST API (the same one the phone uses, authed as
9
- * the user via the daemon's `luc_…` key). The fleet must still run if the task API is down, so
10
- * status syncs never throw; task creation does surface its error to the caller, which decides.
11
- */
12
- type Api = {
13
- request<T>(endpoint: string, options?: RequestInit): Promise<T>;
14
- };
15
- type TaskStatus = 'pending' | 'in_progress' | 'completed' | 'blocked' | 'deferred';
16
- export declare function workerStatusToTaskStatus(status: WorkerStatus): TaskStatus;
17
- /**
18
- * Create the goal task and one subtask per worker (subtask id = workerId, so it's stable from
19
- * the plan the user approved). Returns the parent task's id, which the caller stamps back onto
20
- * the plan. Subtasks are created in merge order so the backlog reads top-to-bottom the way the
21
- * fleet integrates. Throws if the parent can't be created (no point running a fleet with no
22
- * home for it); a subtask that fails to create is logged and skipped, not fatal.
23
- */
24
- export declare function createFleetTasks(api: Api, plan: FleetPlan, opts?: {
25
- projectId?: string | null;
26
- }): Promise<{
27
- parentTaskId: string;
28
- }>;
29
- /** Write a worker's lane state back to its subtask. Best-effort — a task API hiccup must never
30
- * stall the fleet, so this swallows its own errors. */
31
- export declare function syncWorkerStatus(api: Api, workerId: string, status: WorkerStatus): Promise<void>;
32
- export {};
33
- //# sourceMappingURL=fleetTasks.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fleetTasks.d.ts","sourceRoot":"","sources":["../../src/coding/fleetTasks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAQ,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGtE;;;;;;;;;GASG;AAEH,KAAK,GAAG,GAAG;IAAE,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAE/E,KAAK,UAAU,GAAG,SAAS,GAAG,aAAa,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;AAcnF,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,YAAY,GAAG,UAAU,CAEzE;AAWD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,SAAS,EACf,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAO,GACvC,OAAO,CAAC;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CAqCnC;AAED;wDACwD;AACxD,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,IAAI,CAAC,CASf"}
@@ -1,75 +0,0 @@
1
- import { integrationOrder } from './fleetPlan.js';
2
- // A worker's lane state → the subtask's status. `review` (done, awaiting the user) stays
3
- // in_progress rather than blocked: the work isn't stuck, it's waiting on a human, and the
4
- // Fleet board carries the finer state itself.
5
- const STATUS_MAP = {
6
- queued: 'pending',
7
- working: 'in_progress',
8
- review: 'in_progress',
9
- merged: 'completed',
10
- blocked: 'blocked',
11
- failed: 'blocked',
12
- };
13
- export function workerStatusToTaskStatus(status) {
14
- return STATUS_MAP[status];
15
- }
16
- function clampPriority(mergeOrder) {
17
- return Math.min(1000, Math.max(1, Math.round(mergeOrder)));
18
- }
19
- function workerDescription(brief, ownedPaths) {
20
- const owned = ownedPaths.length ? `\n\nOwned: ${ownedPaths.join(', ')}` : '';
21
- return `${brief}${owned}`;
22
- }
23
- /**
24
- * Create the goal task and one subtask per worker (subtask id = workerId, so it's stable from
25
- * the plan the user approved). Returns the parent task's id, which the caller stamps back onto
26
- * the plan. Subtasks are created in merge order so the backlog reads top-to-bottom the way the
27
- * fleet integrates. Throws if the parent can't be created (no point running a fleet with no
28
- * home for it); a subtask that fails to create is logged and skipped, not fatal.
29
- */
30
- export async function createFleetTasks(api, plan, opts = {}) {
31
- // Already materialized (a re-sent / resumed plan carries its parentTaskId) — don't create a
32
- // second childless goal task or re-POST the subtasks (whose ids would collide).
33
- if (plan.parentTaskId)
34
- return { parentTaskId: plan.parentTaskId };
35
- const parent = await api.request('/api/tasks', {
36
- method: 'POST',
37
- body: JSON.stringify({
38
- title: plan.goal,
39
- projectId: opts.projectId ?? null,
40
- description: 'Lucid conductor fleet goal.',
41
- }),
42
- });
43
- for (const w of integrationOrder(plan)) {
44
- try {
45
- await api.request('/api/tasks', {
46
- method: 'POST',
47
- body: JSON.stringify({
48
- id: w.workerId,
49
- title: w.title,
50
- parentTaskId: parent.id,
51
- description: workerDescription(w.brief, w.ownedPaths),
52
- priority: clampPriority(w.mergeOrder),
53
- status: 'pending',
54
- }),
55
- });
56
- }
57
- catch (err) {
58
- console.error(`[conduct] could not create subtask for worker "${w.title}": ${err instanceof Error ? err.message : String(err)}`);
59
- }
60
- }
61
- return { parentTaskId: parent.id };
62
- }
63
- /** Write a worker's lane state back to its subtask. Best-effort — a task API hiccup must never
64
- * stall the fleet, so this swallows its own errors. */
65
- export async function syncWorkerStatus(api, workerId, status) {
66
- try {
67
- await api.request(`/api/tasks/${workerId}`, {
68
- method: 'PATCH',
69
- body: JSON.stringify({ status: workerStatusToTaskStatus(status) }),
70
- });
71
- }
72
- catch {
73
- // Best-effort: the fleet runs regardless of whether the backlog can be updated.
74
- }
75
- }
@@ -1,325 +0,0 @@
1
- import type { AgentExecutor } from '@lucidity/runtime';
2
- import type { FleetPlan, HarnessImage, WorkerStatus } from '@lucidity/shared';
3
- import type { RepoEntry } from '../config.js';
4
- import { resolveRepo } from './repos.js';
5
- import { isAbortError } from '../streamDeadline.js';
6
- import { buildConductPlanPrompt, parseFleetPlan } from './fleetPlan.js';
7
- import { createFleetTasks, syncWorkerStatus } from './fleetTasks.js';
8
- import { runCodeTurn, type CodeTurnRequest, type RunCodeTurnDeps } from './runCodeTurn.js';
9
-
10
- /** Compatibility handler for older phones. Workers persist after every turn. */
11
-
12
- export interface ConductTurnRequest {
13
- id: string;
14
- repoId: string;
15
- phase: 'plan' | 'run' | 'setup' | 'integrate';
16
- prompt: string;
17
- images?: HarnessImage[];
18
- plan?: FleetPlan;
19
- resume?: string;
20
- /** Skip the dogfood task graph (quick incremental spawn — the fleet UI tracks it anyway). */
21
- ephemeral?: boolean;
22
- }
23
-
24
- type Api = { request<T>(endpoint: string, options?: RequestInit): Promise<T> };
25
-
26
- export interface RunConductTurnDeps {
27
- repos: RepoEntry[];
28
- executor: AgentExecutor;
29
- onWorkerApproval?: (requestId: string, approval: import('@lucidity/runtime').ExecutorApproval) => Promise<boolean>;
30
- onEnd?: (requestId: string) => void;
31
- send: (obj: unknown) => void;
32
- signal?: AbortSignal;
33
- model?: string;
34
- effort?: string;
35
- /** Task API for the dogfood (goal + subtasks). Absent → tasks are skipped, fleet still runs. */
36
- api?: Api;
37
- /** Project the fleet's tasks land in. Absent → the Inbox (projectId null). */
38
- projectId?: string | null;
39
- /** Default parallel-worker cap when the plan doesn't set one (quota guard). */
40
- maxParallel?: number;
41
- /** Worktree base override (tests point it at a temp dir). */
42
- baseDir?: string;
43
- /** Seam: run one worker's coding turn. Defaults to {@link runCodeTurn}. */
44
- runWorker?: (req: CodeTurnRequest, deps: RunCodeTurnDeps) => Promise<void>;
45
-
46
- }
47
-
48
- const DEFAULT_MAX_PARALLEL = 2;
49
-
50
- function msg(e: unknown): string {
51
- return e instanceof Error ? e.message : String(e);
52
- }
53
-
54
- /** Count +/- lines and files in a unified diff, for a worker card's "+N −M". */
55
- export function diffStat(diff: string): { added: number; removed: number; files: number } {
56
- let added = 0;
57
- let removed = 0;
58
- let files = 0;
59
- for (const line of diff.split('\n')) {
60
- if (line.startsWith('+++') || line.startsWith('---')) continue;
61
- if (line.startsWith('diff --git')) files++;
62
- else if (line.startsWith('+')) added++;
63
- else if (line.startsWith('-')) removed++;
64
- }
65
- return { added, removed, files };
66
- }
67
-
68
- /** Run `fn` over `items` with at most `cap` in flight. */
69
- async function runWithCap<T>(
70
- items: T[],
71
- cap: number,
72
- fn: (item: T) => Promise<void>,
73
- ): Promise<void> {
74
- const queue = [...items];
75
- const lanes = Array.from(
76
- { length: Math.max(1, Math.min(cap, items.length || 1)) },
77
- async () => {
78
- for (let item = queue.shift(); item !== undefined; item = queue.shift()) {
79
- await fn(item);
80
- }
81
- },
82
- );
83
- await Promise.all(lanes);
84
- }
85
-
86
- export async function runConductTurn(
87
- req: ConductTurnRequest,
88
- deps: RunConductTurnDeps,
89
- ): Promise<void> {
90
- const repo = resolveRepo(req.repoId, deps.repos);
91
- if (!repo) {
92
- deps.send({
93
- type: 'error',
94
- requestId: req.id,
95
- message: `Repo "${req.repoId}" isn't on this daemon's allowlist.`,
96
- });
97
- return;
98
- }
99
- if (!deps.executor.runStream) {
100
- deps.send({
101
- type: 'error',
102
- requestId: req.id,
103
- message: 'The conductor needs a streaming executor.',
104
- });
105
- return;
106
- }
107
-
108
- if (req.phase === 'plan') return planPhase(req, deps, repo.root);
109
- if (req.phase === 'setup') return setupPhase(req, deps);
110
- if (req.phase === 'integrate') {
111
- deps.send({ type: 'error', requestId: req.id, message: 'Open a worker chat and ask to create or merge its PR. Workers are kept until archived.' });
112
- return;
113
- }
114
- return runPhase(req, deps);
115
- }
116
-
117
- /**
118
- * Design-first flow: materialize an approved plan WITHOUT writing any code. Create the task graph
119
- * (worker = subtask) and announce each worker as `queued`, then finish. The phone drives each
120
- * worker from here with `code` turns carrying its `workerId` (a conversation, in the worker's own
121
- * `fleet/<repo>/<workerId>` worktree), and merges with a later `integrate`. The counterpart to
122
- * `run`, which instead codes everything itself.
123
- */
124
- async function setupPhase(
125
- req: ConductTurnRequest,
126
- deps: RunConductTurnDeps,
127
- ): Promise<void> {
128
- const plan = req.plan;
129
- if (!plan) {
130
- deps.send({ type: 'error', requestId: req.id, message: 'Setup needs an approved plan.' });
131
- return;
132
- }
133
- let parentTaskId: string | undefined;
134
- if (deps.api) {
135
- try {
136
- ({ parentTaskId } = await createFleetTasks(deps.api, plan, { projectId: deps.projectId }));
137
- } catch (err) {
138
- console.error(`[conduct] couldn't create the fleet task graph: ${msg(err)}`);
139
- }
140
- }
141
- deps.send({
142
- type: 'fleet_plan',
143
- requestId: req.id,
144
- plan: { ...plan, ...(parentTaskId ? { parentTaskId } : {}) },
145
- });
146
- for (const w of plan.workers) {
147
- deps.send({ type: 'worker_status', requestId: req.id, workerId: w.workerId, status: 'queued' });
148
- if (deps.api) void syncWorkerStatus(deps.api, w.workerId, 'queued');
149
- }
150
- deps.send({
151
- type: 'done',
152
- requestId: req.id,
153
- text: `Fleet set up: ${plan.workers.length} worker${plan.workers.length === 1 ? '' : 's'} ready to brief.`,
154
- });
155
- }
156
-
157
- /** Read-only lead turn → a FleetPlan, streamed back as a fleet_plan event. Creates nothing. */
158
- async function planPhase(
159
- req: ConductTurnRequest,
160
- deps: RunConductTurnDeps,
161
- repoRoot: string,
162
- ): Promise<void> {
163
- let text = '';
164
- let sessionId: string | undefined;
165
- try {
166
- for await (const ev of deps.executor.runStream!({
167
- requestId: req.id,
168
- userPrompt: buildConductPlanPrompt(req.prompt),
169
- cwd: repoRoot,
170
- // Auto mode lets the lead READ the repo (ls/grep/cat) to inform the split; a mutating
171
- // tool has no approver here, so the prompt tells it to plan only, never edit.
172
- // Read-only: the lead may ls/grep/cat the repo to inform the split but must never edit
173
- // the user's live checkout. `plan` mode blocks every mutating tool, so even an off-script
174
- // or prompt-injected planning turn can't touch the working tree.
175
- permissionMode: 'plan',
176
- model: deps.model,
177
- effort: deps.effort,
178
- resume: req.resume,
179
- signal: deps.signal,
180
- })) {
181
- if (ev.type === 'session') {
182
- deps.send({ type: 'session', requestId: req.id, sessionId: ev.sessionId });
183
- } else if (ev.type === 'delta') {
184
- text += ev.text;
185
- deps.send({ type: 'delta', requestId: req.id, text: ev.text });
186
- } else if (ev.type === 'tool_call') {
187
- deps.send({ type: 'tool_call', requestId: req.id, name: ev.name, phase: ev.phase });
188
- } else if (ev.type === 'done') {
189
- sessionId = ev.sessionId;
190
- }
191
- }
192
- } catch (err) {
193
- if (isAbortError(err)) return;
194
- deps.send({ type: 'error', requestId: req.id, message: msg(err) });
195
- return;
196
- }
197
-
198
- let plan: FleetPlan;
199
- try {
200
- plan = parseFleetPlan(text, { goal: req.prompt });
201
- } catch (err) {
202
- deps.send({
203
- type: 'error',
204
- requestId: req.id,
205
- message: `Couldn't turn that into a fan-out plan: ${msg(err)}`,
206
- });
207
- return;
208
- }
209
-
210
- deps.send({ type: 'fleet_plan', requestId: req.id, plan });
211
- deps.send({ type: 'done', requestId: req.id, text, sessionId });
212
- }
213
-
214
- /** Run legacy worker requests without publication or workspace cleanup. */
215
- async function runPhase(
216
- req: ConductTurnRequest,
217
- deps: RunConductTurnDeps,
218
- ): Promise<void> {
219
- const plan = req.plan;
220
- if (!plan) {
221
- deps.send({
222
- type: 'error',
223
- requestId: req.id,
224
- message: 'A run needs an approved plan.',
225
- });
226
- return;
227
- }
228
-
229
- const emitStatus = (
230
- workerId: string,
231
- status: WorkerStatus,
232
- extra?: { detail?: string; diffStat?: { added: number; removed: number; files: number } },
233
- ) =>
234
- deps.send({
235
- type: 'worker_status',
236
- requestId: req.id,
237
- workerId,
238
- status,
239
- ...(extra?.detail ? { detail: extra.detail } : {}),
240
- ...(extra?.diffStat ? { diffStat: extra.diffStat } : {}),
241
- });
242
- const sync = (workerId: string, status: WorkerStatus): Promise<void> =>
243
- deps.api && !req.ephemeral ? syncWorkerStatus(deps.api, workerId, status) : Promise.resolve();
244
-
245
- // Dogfood: the goal + one subtask per worker (worker = subtask). Skipped for ephemeral spawns so
246
- // quick incremental tasks don't spam the board. Best-effort; a fleet still runs if it can't write.
247
- let parentTaskId: string | undefined;
248
- if (deps.api && !req.ephemeral) {
249
- try {
250
- ({ parentTaskId } = await createFleetTasks(deps.api, plan, {
251
- projectId: deps.projectId,
252
- }));
253
- } catch (err) {
254
- console.error(`[conduct] couldn't create the fleet task graph: ${msg(err)}`);
255
- }
256
- }
257
- // Echo the plan with the parent id so the phone can link the Fleet board to the goal task.
258
- deps.send({
259
- type: 'fleet_plan',
260
- requestId: req.id,
261
- plan: { ...plan, ...(parentTaskId ? { parentTaskId } : {}) },
262
- });
263
-
264
- const runWorker = deps.runWorker ?? runCodeTurn;
265
- const cap = plan.maxParallel ?? deps.maxParallel ?? DEFAULT_MAX_PARALLEL;
266
- const diffStats = new Map<string, { added: number; removed: number; files: number }>();
267
-
268
- await runWithCap(plan.workers, cap, async (w) => {
269
- // A cancel mid-fleet drops the workers still queued behind the cap — we don't spin up new
270
- // worktrees for a run the user has already stopped.
271
- if (deps.signal?.aborted) return;
272
- emitStatus(w.workerId, 'working');
273
- await sync(w.workerId, 'working');
274
-
275
- // The worker's code frames already carry requestId === workerId (we set the turn id to it),
276
- // so we forward them verbatim — the phone routes them to the worker's lane through the
277
- // existing code-turn rendering. We only peek to capture the diff size and any error.
278
- let sawError = false;
279
- let wasCancelled = false;
280
- const workerSend = (obj: unknown) => {
281
- const o = obj as { type?: string; diff?: string };
282
- if (o?.type === 'code_result' && typeof o.diff === 'string') {
283
- diffStats.set(w.workerId, diffStat(o.diff));
284
- }
285
- if (o?.type === 'error') sawError = true;
286
- if (o?.type === 'cancelled') { wasCancelled = true; sawError = true; }
287
- deps.send(obj);
288
- };
289
-
290
- try {
291
- await runWorker(
292
- {
293
- id: w.workerId,
294
- repoId: req.repoId,
295
- workerId: w.workerId,
296
- prompt: w.brief,
297
- },
298
- {
299
- repos: deps.repos,
300
- executor: deps.executor,
301
- onApproval: deps.onWorkerApproval ? (approval) => deps.onWorkerApproval!(w.workerId, approval) : undefined,
302
- send: workerSend,
303
- signal: deps.signal,
304
- model: deps.model,
305
- effort: deps.effort,
306
- baseDir: deps.baseDir,
307
- },
308
- );
309
- } catch (err) {
310
- if (!isAbortError(err)) sawError = true;
311
- } finally { deps.onEnd?.(w.workerId); }
312
-
313
- if (sawError) {
314
- emitStatus(w.workerId, 'failed', wasCancelled ? { detail: 'Stopped' } : undefined);
315
- await sync(w.workerId, 'failed');
316
- } else {
317
- emitStatus(w.workerId, 'review', { diffStat: diffStats.get(w.workerId) });
318
- await sync(w.workerId, 'review');
319
- }
320
- });
321
-
322
- if (deps.signal?.aborted) return;
323
- deps.send({ type: 'fleet_done', requestId: req.id, delivered: 0, total: plan.workers.length });
324
- deps.send({ type: 'done', requestId: req.id, text: 'Workers are ready for follow-up in their chats.' });
325
- }