@opencorelabs/lucidity 0.7.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 (502) hide show
  1. package/README.md +9 -2
  2. package/dist/assets/speech/lucidity-speech +0 -0
  3. package/dist/automations/agent.d.ts.map +1 -1
  4. package/dist/automations/agent.js +2 -0
  5. package/dist/automations/designer.d.ts +1 -1
  6. package/dist/automations/service.d.ts +4 -0
  7. package/dist/automations/service.d.ts.map +1 -1
  8. package/dist/automations/service.js +60 -22
  9. package/dist/automations/store.d.ts +9 -3
  10. package/dist/automations/store.d.ts.map +1 -1
  11. package/dist/automations/store.js +45 -32
  12. package/dist/automations/workflow.d.ts +14 -0
  13. package/dist/automations/workflow.d.ts.map +1 -0
  14. package/dist/automations/workflow.js +57 -0
  15. package/dist/chat/server.d.ts +1 -0
  16. package/dist/chat/server.d.ts.map +1 -1
  17. package/dist/chat/server.js +6 -1
  18. package/dist/coding/listPrs.d.ts +2 -0
  19. package/dist/coding/listPrs.d.ts.map +1 -1
  20. package/dist/coding/listPrs.js +10 -0
  21. package/dist/coding/runCodeTurn.d.ts +6 -30
  22. package/dist/coding/runCodeTurn.d.ts.map +1 -1
  23. package/dist/coding/runCodeTurn.js +145 -218
  24. package/dist/coding/runReview.d.ts +10 -0
  25. package/dist/coding/runReview.d.ts.map +1 -0
  26. package/dist/coding/runReview.js +87 -0
  27. package/dist/coding/workspaceRegistry.d.ts +72 -0
  28. package/dist/coding/workspaceRegistry.d.ts.map +1 -0
  29. package/dist/coding/workspaceRegistry.js +421 -0
  30. package/dist/coding/worktree.d.ts +72 -32
  31. package/dist/coding/worktree.d.ts.map +1 -1
  32. package/dist/coding/worktree.js +190 -38
  33. package/dist/coding/worktreeSetup.d.ts +7 -0
  34. package/dist/coding/worktreeSetup.d.ts.map +1 -0
  35. package/dist/coding/worktreeSetup.js +49 -0
  36. package/dist/config.d.ts +2 -0
  37. package/dist/config.d.ts.map +1 -1
  38. package/dist/daemonLease.d.ts +12 -0
  39. package/dist/daemonLease.d.ts.map +1 -0
  40. package/dist/daemonLease.js +32 -0
  41. package/dist/goals/assessment.d.ts +115 -0
  42. package/dist/goals/assessment.d.ts.map +1 -0
  43. package/dist/goals/assessment.js +67 -0
  44. package/dist/goals/notes.d.ts +18 -0
  45. package/dist/goals/notes.d.ts.map +1 -0
  46. package/dist/goals/notes.js +72 -0
  47. package/dist/index.js +75 -40
  48. package/dist/jobs/briefing.d.ts +2 -16
  49. package/dist/jobs/briefing.d.ts.map +1 -1
  50. package/dist/jobs/briefing.js +65 -93
  51. package/dist/jobs/goals.d.ts +15 -0
  52. package/dist/jobs/goals.d.ts.map +1 -0
  53. package/dist/jobs/goals.js +286 -0
  54. package/dist/jobs/weeklyReview.d.ts.map +1 -1
  55. package/dist/jobs/weeklyReview.js +3 -2
  56. package/dist/logTimestamps.d.ts +10 -0
  57. package/dist/logTimestamps.d.ts.map +1 -0
  58. package/dist/logTimestamps.js +12 -0
  59. package/dist/providerRecovery.d.ts +48 -0
  60. package/dist/providerRecovery.d.ts.map +1 -0
  61. package/dist/providerRecovery.js +100 -0
  62. package/dist/queue.d.ts +1 -0
  63. package/dist/queue.d.ts.map +1 -1
  64. package/dist/queue.js +4 -0
  65. package/dist/room/client.d.ts +6 -19
  66. package/dist/room/client.d.ts.map +1 -1
  67. package/dist/room/client.js +127 -123
  68. package/dist/room/computer.js +1 -1
  69. package/dist/room/durablePublish.d.ts +6 -0
  70. package/dist/room/durablePublish.d.ts.map +1 -0
  71. package/dist/room/durablePublish.js +19 -0
  72. package/dist/room/incidents.d.ts +4 -1
  73. package/dist/room/incidents.d.ts.map +1 -1
  74. package/dist/room/incidents.js +15 -7
  75. package/dist/room/turnQueue.d.ts.map +1 -1
  76. package/dist/room/turnQueue.js +55 -46
  77. package/dist/runtimeStore.d.ts +46 -0
  78. package/dist/runtimeStore.d.ts.map +1 -0
  79. package/dist/runtimeStore.js +205 -0
  80. package/dist/setup/server.js +1 -1
  81. package/dist/turnLog.d.ts +10 -40
  82. package/dist/turnLog.d.ts.map +1 -1
  83. package/dist/turnLog.js +33 -56
  84. package/dist/vault.d.ts +6 -3
  85. package/dist/vault.d.ts.map +1 -1
  86. package/dist/vault.js +18 -4
  87. package/package.json +4 -4
  88. package/src/automations/agent.ts +2 -0
  89. package/src/automations/service.ts +47 -21
  90. package/src/automations/store.ts +41 -50
  91. package/src/automations/workflow.ts +49 -0
  92. package/src/chat/server.ts +7 -1
  93. package/src/coding/listPrs.ts +14 -0
  94. package/src/coding/runCodeTurn.ts +51 -139
  95. package/src/coding/runReview.ts +83 -0
  96. package/src/coding/workspaceRegistry.ts +380 -0
  97. package/src/coding/worktree.ts +205 -40
  98. package/src/coding/worktreeSetup.ts +50 -0
  99. package/src/config.ts +2 -0
  100. package/src/daemonLease.ts +33 -0
  101. package/src/goals/assessment.ts +106 -0
  102. package/src/goals/notes.ts +88 -0
  103. package/src/index.ts +76 -46
  104. package/src/jobs/briefing.ts +62 -109
  105. package/src/jobs/goals.ts +384 -0
  106. package/src/jobs/weeklyReview.ts +4 -3
  107. package/src/logTimestamps.ts +14 -0
  108. package/src/providerRecovery.ts +99 -0
  109. package/src/queue.ts +4 -0
  110. package/src/room/client.ts +84 -116
  111. package/src/room/computer.ts +1 -1
  112. package/src/room/durablePublish.ts +25 -0
  113. package/src/room/incidents.ts +20 -8
  114. package/src/room/turnQueue.ts +53 -56
  115. package/src/runtimeStore.ts +207 -0
  116. package/src/setup/server.ts +1 -1
  117. package/src/turnLog.ts +32 -75
  118. package/src/vault.ts +16 -7
  119. package/vendor/mcp-server/dist/index.js +2 -0
  120. package/vendor/mcp-server/dist/tools/goals.d.ts +4 -0
  121. package/vendor/mcp-server/dist/tools/goals.d.ts.map +1 -0
  122. package/vendor/mcp-server/dist/tools/goals.js +38 -0
  123. package/vendor/mcp-server/package.json +1 -1
  124. package/vendor/mcp-server/src/index.ts +2 -0
  125. package/vendor/mcp-server/src/tools/goals.ts +62 -0
  126. package/vendor/runtime/README.md +36 -2
  127. package/vendor/runtime/dist/executor/asyncQueue.d.ts +1 -0
  128. package/vendor/runtime/dist/executor/asyncQueue.d.ts.map +1 -1
  129. package/vendor/runtime/dist/executor/asyncQueue.js +3 -0
  130. package/vendor/runtime/dist/executor/claudeAgent.d.ts +5 -1
  131. package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
  132. package/vendor/runtime/dist/executor/claudeAgent.js +77 -13
  133. package/vendor/runtime/dist/executor/codex.d.ts +8 -2
  134. package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
  135. package/vendor/runtime/dist/executor/codex.js +113 -38
  136. package/vendor/runtime/dist/executor/codexProtocol/AgentPath.d.ts +2 -0
  137. package/vendor/runtime/dist/executor/codexProtocol/AgentPath.d.ts.map +1 -0
  138. package/vendor/runtime/dist/executor/codexProtocol/AgentPath.js +2 -0
  139. package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts +4 -1
  140. package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts.map +1 -1
  141. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.d.ts +6 -0
  142. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.d.ts.map +1 -0
  143. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.js +2 -0
  144. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.d.ts +12 -0
  145. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.d.ts.map +1 -0
  146. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.js +2 -0
  147. package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.d.ts +24 -0
  148. package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.d.ts.map +1 -0
  149. package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.js +2 -0
  150. package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.d.ts +8 -0
  151. package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.d.ts.map +1 -0
  152. package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.js +2 -0
  153. package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts +3 -0
  154. package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts.map +1 -1
  155. package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts +1 -1
  156. package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts.map +1 -1
  157. package/vendor/runtime/dist/executor/codexProtocol/SleepItem.d.ts +8 -0
  158. package/vendor/runtime/dist/executor/codexProtocol/SleepItem.d.ts.map +1 -0
  159. package/vendor/runtime/dist/executor/codexProtocol/SleepItem.js +2 -0
  160. package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.d.ts +14 -0
  161. package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.d.ts.map +1 -0
  162. package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.js +2 -0
  163. package/vendor/runtime/dist/executor/codexProtocol/ThreadId.d.ts +7 -0
  164. package/vendor/runtime/dist/executor/codexProtocol/ThreadId.d.ts.map +1 -0
  165. package/vendor/runtime/dist/executor/codexProtocol/ThreadId.js +2 -0
  166. package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.d.ts +15 -0
  167. package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.d.ts.map +1 -0
  168. package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.js +2 -0
  169. package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.d.ts +2 -0
  170. package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.d.ts.map +1 -0
  171. package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.js +2 -0
  172. package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.d.ts +5 -0
  173. package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.d.ts.map +1 -0
  174. package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.js +2 -0
  175. package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.d.ts +29 -0
  176. package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.d.ts.map +1 -0
  177. package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.js +2 -0
  178. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.d.ts +6 -0
  179. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.d.ts.map +1 -0
  180. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.js +2 -0
  181. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.d.ts +2 -0
  182. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.d.ts.map +1 -0
  183. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.js +2 -0
  184. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.d.ts +2 -0
  185. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.d.ts.map +1 -0
  186. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.js +2 -0
  187. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.d.ts +2 -0
  188. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.d.ts.map +1 -0
  189. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.js +2 -0
  190. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.d.ts +20 -0
  191. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.d.ts.map +1 -0
  192. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.js +2 -0
  193. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.d.ts +2 -0
  194. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.d.ts.map +1 -0
  195. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.js +2 -0
  196. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.d.ts +2 -0
  197. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.d.ts.map +1 -0
  198. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.js +2 -0
  199. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts +6 -0
  200. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts.map +1 -0
  201. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.js +2 -0
  202. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.d.ts +11 -0
  203. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.d.ts.map +1 -0
  204. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.js +2 -0
  205. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.d.ts +2 -0
  206. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.d.ts.map +1 -0
  207. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.js +2 -0
  208. package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.d.ts +7 -0
  209. package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.d.ts.map +1 -0
  210. package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.js +2 -0
  211. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts +5 -0
  212. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts.map +1 -1
  213. package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.d.ts +6 -0
  214. package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.d.ts.map +1 -0
  215. package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.js +2 -0
  216. package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.d.ts +5 -0
  217. package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.d.ts.map +1 -0
  218. package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.js +2 -0
  219. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.d.ts +2 -0
  220. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.d.ts.map +1 -0
  221. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.js +2 -0
  222. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.d.ts +9 -0
  223. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.d.ts.map +1 -0
  224. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.js +2 -0
  225. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.d.ts +8 -0
  226. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.d.ts.map +1 -0
  227. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.js +2 -0
  228. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.d.ts +4 -0
  229. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.d.ts.map +1 -0
  230. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.js +2 -0
  231. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.d.ts +7 -0
  232. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.d.ts.map +1 -0
  233. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.js +2 -0
  234. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.d.ts +2 -0
  235. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.d.ts.map +1 -0
  236. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.js +2 -0
  237. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.d.ts +6 -0
  238. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.d.ts.map +1 -0
  239. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.js +2 -0
  240. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.d.ts +7 -0
  241. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.d.ts.map +1 -0
  242. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.js +2 -0
  243. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.d.ts +16 -0
  244. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.d.ts.map +1 -0
  245. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.js +2 -0
  246. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.d.ts +4 -0
  247. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.d.ts.map +1 -0
  248. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.js +2 -0
  249. package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts +8 -0
  250. package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts.map +1 -1
  251. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts +11 -0
  252. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts.map +1 -0
  253. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.js +2 -0
  254. package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.d.ts +2 -0
  255. package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.d.ts.map +1 -0
  256. package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.js +2 -0
  257. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.d.ts +2 -0
  258. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.d.ts.map +1 -0
  259. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.js +2 -0
  260. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.d.ts +9 -0
  261. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.d.ts.map +1 -0
  262. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.js +2 -0
  263. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts +4 -0
  264. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts.map +1 -1
  265. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts +2 -0
  266. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts.map +1 -1
  267. package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.d.ts +7 -0
  268. package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.d.ts.map +1 -0
  269. package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.js +2 -0
  270. package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.d.ts +2 -0
  271. package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.d.ts.map +1 -0
  272. package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.js +2 -0
  273. package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.d.ts +100 -0
  274. package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.d.ts.map +1 -0
  275. package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.js +2 -0
  276. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.d.ts +2 -0
  277. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.d.ts.map +1 -0
  278. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.js +2 -0
  279. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.d.ts +2 -0
  280. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.d.ts.map +1 -0
  281. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.js +2 -0
  282. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.d.ts +216 -0
  283. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.d.ts.map +1 -0
  284. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.js +2 -0
  285. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.d.ts +11 -0
  286. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.d.ts.map +1 -0
  287. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.js +2 -0
  288. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.d.ts +5 -0
  289. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.d.ts.map +1 -0
  290. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.js +2 -0
  291. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts +4 -1
  292. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts.map +1 -1
  293. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.d.ts +19 -0
  294. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.d.ts.map +1 -0
  295. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.js +2 -0
  296. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.d.ts +8 -0
  297. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.d.ts.map +1 -0
  298. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.js +2 -0
  299. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts +3 -1
  300. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts.map +1 -1
  301. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.d.ts +12 -0
  302. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.d.ts.map +1 -0
  303. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.js +2 -0
  304. package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.d.ts +36 -0
  305. package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.d.ts.map +1 -0
  306. package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.js +2 -0
  307. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.d.ts +12 -0
  308. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.d.ts.map +1 -0
  309. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.js +2 -0
  310. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.d.ts +2 -0
  311. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.d.ts.map +1 -0
  312. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.js +2 -0
  313. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts +7 -2
  314. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts.map +1 -1
  315. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.d.ts +2 -0
  316. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.d.ts.map +1 -0
  317. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.js +2 -0
  318. package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts +3 -0
  319. package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts.map +1 -1
  320. package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.d.ts +15 -0
  321. package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.d.ts.map +1 -0
  322. package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.js +2 -0
  323. package/vendor/runtime/dist/executor/codexRpc.d.ts +13 -4
  324. package/vendor/runtime/dist/executor/codexRpc.d.ts.map +1 -1
  325. package/vendor/runtime/dist/executor/codexRpc.js +21 -5
  326. package/vendor/runtime/dist/executor/codexSessions.d.ts +30 -0
  327. package/vendor/runtime/dist/executor/codexSessions.d.ts.map +1 -0
  328. package/vendor/runtime/dist/executor/codexSessions.js +88 -0
  329. package/vendor/runtime/dist/executor/health.d.ts +8 -2
  330. package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
  331. package/vendor/runtime/dist/executor/health.js +21 -5
  332. package/vendor/runtime/dist/executor/liveTurns.d.ts +2 -1
  333. package/vendor/runtime/dist/executor/liveTurns.d.ts.map +1 -1
  334. package/vendor/runtime/dist/executor/liveTurns.js +12 -5
  335. package/vendor/runtime/dist/executor/ownership.d.ts +40 -0
  336. package/vendor/runtime/dist/executor/ownership.d.ts.map +1 -0
  337. package/vendor/runtime/dist/executor/ownership.js +106 -0
  338. package/vendor/runtime/dist/executor/providerRouter.d.ts +1 -0
  339. package/vendor/runtime/dist/executor/providerRouter.d.ts.map +1 -1
  340. package/vendor/runtime/dist/executor/providerRouter.js +5 -0
  341. package/vendor/runtime/dist/executor/types.d.ts +27 -0
  342. package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
  343. package/vendor/runtime/dist/harness/index.d.ts.map +1 -1
  344. package/vendor/runtime/dist/harness/index.js +1 -0
  345. package/vendor/runtime/dist/index.d.ts +2 -1
  346. package/vendor/runtime/dist/index.d.ts.map +1 -1
  347. package/vendor/runtime/dist/index.js +1 -0
  348. package/vendor/runtime/src/executor/asyncQueue.ts +3 -0
  349. package/vendor/runtime/src/executor/claudeAgent.ts +66 -13
  350. package/vendor/runtime/src/executor/codex.ts +124 -47
  351. package/vendor/runtime/src/executor/codexProtocol/AgentPath.ts +5 -0
  352. package/vendor/runtime/src/executor/codexProtocol/FunctionCallOutputContentItem.ts +1 -1
  353. package/vendor/runtime/src/executor/codexProtocol/ImageGenerationFailure.ts +5 -0
  354. package/vendor/runtime/src/executor/codexProtocol/ImageGenerationItem.ts +7 -0
  355. package/vendor/runtime/src/executor/codexProtocol/LegacyAppPathString.ts +27 -0
  356. package/vendor/runtime/src/executor/codexProtocol/MessagePhase.ts +11 -0
  357. package/vendor/runtime/src/executor/codexProtocol/Personality.ts +3 -0
  358. package/vendor/runtime/src/executor/codexProtocol/PlanType.ts +1 -1
  359. package/vendor/runtime/src/executor/codexProtocol/README.md +2 -2
  360. package/vendor/runtime/src/executor/codexProtocol/SleepItem.ts +8 -0
  361. package/vendor/runtime/src/executor/codexProtocol/SubAgentSource.ts +7 -0
  362. package/vendor/runtime/src/executor/codexProtocol/ThreadId.ts +10 -0
  363. package/vendor/runtime/src/executor/codexProtocol/WebSearchItem.ts +14 -0
  364. package/vendor/runtime/src/executor/codexProtocol/v2/AgentMessageDelivery.ts +5 -0
  365. package/vendor/runtime/src/executor/codexProtocol/v2/AsyncUserInputQuestion.ts +5 -0
  366. package/vendor/runtime/src/executor/codexProtocol/v2/CodexErrorInfo.ts +12 -0
  367. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentState.ts +6 -0
  368. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentStatus.ts +5 -0
  369. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentTool.ts +5 -0
  370. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentToolCallStatus.ts +5 -0
  371. package/vendor/runtime/src/executor/codexProtocol/v2/CommandAction.ts +6 -0
  372. package/vendor/runtime/src/executor/codexProtocol/v2/CommandExecutionSource.ts +5 -0
  373. package/vendor/runtime/src/executor/codexProtocol/v2/CommandExecutionStatus.ts +5 -0
  374. package/vendor/runtime/src/executor/codexProtocol/v2/CyberAccessProgram.ts +9 -0
  375. package/vendor/runtime/src/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.ts +5 -0
  376. package/vendor/runtime/src/executor/codexProtocol/v2/DynamicToolCallStatus.ts +5 -0
  377. package/vendor/runtime/src/executor/codexProtocol/v2/FileUpdateChange.ts +6 -0
  378. package/vendor/runtime/src/executor/codexProtocol/v2/GetAccountRateLimitsResponse.ts +5 -0
  379. package/vendor/runtime/src/executor/codexProtocol/v2/GitInfo.ts +5 -0
  380. package/vendor/runtime/src/executor/codexProtocol/v2/HookPromptFragment.ts +5 -0
  381. package/vendor/runtime/src/executor/codexProtocol/v2/McpAppDisplayMode.ts +5 -0
  382. package/vendor/runtime/src/executor/codexProtocol/v2/McpAppUi.ts +9 -0
  383. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallAppContext.ts +5 -0
  384. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallError.ts +5 -0
  385. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallResult.ts +6 -0
  386. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallStatus.ts +5 -0
  387. package/vendor/runtime/src/executor/codexProtocol/v2/MemoryCitation.ts +6 -0
  388. package/vendor/runtime/src/executor/codexProtocol/v2/MemoryCitationEntry.ts +5 -0
  389. package/vendor/runtime/src/executor/codexProtocol/v2/MisalignmentErrorDetails.ts +18 -0
  390. package/vendor/runtime/src/executor/codexProtocol/v2/MisalignmentSteer.ts +5 -0
  391. package/vendor/runtime/src/executor/codexProtocol/v2/Model.ts +11 -2
  392. package/vendor/runtime/src/executor/codexProtocol/v2/ModelAccessPrograms.ts +13 -0
  393. package/vendor/runtime/src/executor/codexProtocol/v2/NonSteerableTurnKind.ts +5 -0
  394. package/vendor/runtime/src/executor/codexProtocol/v2/PatchApplyStatus.ts +5 -0
  395. package/vendor/runtime/src/executor/codexProtocol/v2/PatchChangeKind.ts +5 -0
  396. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitSnapshot.ts +5 -1
  397. package/vendor/runtime/src/executor/codexProtocol/v2/ReviewStartParams.ts +2 -0
  398. package/vendor/runtime/src/executor/codexProtocol/v2/SessionSource.ts +6 -0
  399. package/vendor/runtime/src/executor/codexProtocol/v2/SubAgentActivityKind.ts +5 -0
  400. package/vendor/runtime/src/executor/codexProtocol/v2/Thread.ts +104 -0
  401. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadActiveFlag.ts +5 -0
  402. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadHistoryMode.ts +5 -0
  403. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadItem.ts +125 -0
  404. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadReadParams.ts +12 -0
  405. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadReadResponse.ts +6 -0
  406. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadResumeParams.ts +5 -1
  407. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSection.ts +21 -0
  408. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSectionAppearance.ts +8 -0
  409. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStartParams.ts +4 -1
  410. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStatus.ts +6 -0
  411. package/vendor/runtime/src/executor/codexProtocol/v2/Turn.ts +37 -0
  412. package/vendor/runtime/src/executor/codexProtocol/v2/TurnError.ts +11 -0
  413. package/vendor/runtime/src/executor/codexProtocol/v2/TurnItemsView.ts +5 -0
  414. package/vendor/runtime/src/executor/codexProtocol/v2/TurnStartParams.ts +7 -2
  415. package/vendor/runtime/src/executor/codexProtocol/v2/TurnStatus.ts +5 -0
  416. package/vendor/runtime/src/executor/codexProtocol/v2/UserInput.ts +1 -1
  417. package/vendor/runtime/src/executor/codexProtocol/v2/WebSearchAction.ts +5 -0
  418. package/vendor/runtime/src/executor/codexRpc.ts +26 -6
  419. package/vendor/runtime/src/executor/codexSessions.ts +108 -0
  420. package/vendor/runtime/src/executor/health.ts +21 -7
  421. package/vendor/runtime/src/executor/liveTurns.ts +12 -5
  422. package/vendor/runtime/src/executor/ownership.ts +83 -0
  423. package/vendor/runtime/src/executor/providerRouter.ts +6 -0
  424. package/vendor/runtime/src/executor/types.ts +20 -1
  425. package/vendor/runtime/src/harness/index.ts +1 -0
  426. package/vendor/runtime/src/index.ts +2 -1
  427. package/vendor/shared/dist/agentCommands.d.ts +1 -0
  428. package/vendor/shared/dist/agentCommands.d.ts.map +1 -1
  429. package/vendor/shared/dist/automations.d.ts +34 -0
  430. package/vendor/shared/dist/automations.d.ts.map +1 -1
  431. package/vendor/shared/dist/automations.js +12 -0
  432. package/vendor/shared/dist/cardStudio.d.ts +41 -0
  433. package/vendor/shared/dist/cardStudio.d.ts.map +1 -1
  434. package/vendor/shared/dist/cardStudio.js +13 -3
  435. package/vendor/shared/dist/computer.d.ts +7 -1
  436. package/vendor/shared/dist/computer.d.ts.map +1 -1
  437. package/vendor/shared/dist/computer.js +13 -4
  438. package/vendor/shared/dist/constants.d.ts +3 -3
  439. package/vendor/shared/dist/constants.d.ts.map +1 -1
  440. package/vendor/shared/dist/constants.js +8 -14
  441. package/vendor/shared/dist/goalNotes.d.ts +4 -0
  442. package/vendor/shared/dist/goalNotes.d.ts.map +1 -0
  443. package/vendor/shared/dist/goalNotes.js +23 -0
  444. package/vendor/shared/dist/goals.d.ts +835 -0
  445. package/vendor/shared/dist/goals.d.ts.map +1 -0
  446. package/vendor/shared/dist/goals.js +198 -0
  447. package/vendor/shared/dist/index.d.ts +7 -2
  448. package/vendor/shared/dist/index.d.ts.map +1 -1
  449. package/vendor/shared/dist/index.js +6 -1
  450. package/vendor/shared/dist/journal-vault.d.ts +1 -1
  451. package/vendor/shared/dist/messagingSafety.d.ts +21 -0
  452. package/vendor/shared/dist/messagingSafety.d.ts.map +1 -0
  453. package/vendor/shared/dist/messagingSafety.js +8 -0
  454. package/vendor/shared/dist/schemas/harness.d.ts +199 -169
  455. package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
  456. package/vendor/shared/dist/schemas/harness.js +25 -124
  457. package/vendor/shared/dist/smartCapture.d.ts +24 -0
  458. package/vendor/shared/dist/smartCapture.d.ts.map +1 -1
  459. package/vendor/shared/dist/smartCapture.js +15 -0
  460. package/vendor/shared/dist/taskSync.d.ts +342 -0
  461. package/vendor/shared/dist/taskSync.d.ts.map +1 -0
  462. package/vendor/shared/dist/taskSync.js +111 -0
  463. package/vendor/shared/dist/types.d.ts +1 -4
  464. package/vendor/shared/dist/types.d.ts.map +1 -1
  465. package/vendor/shared/dist/voiceCapture.d.ts +1 -1
  466. package/vendor/shared/dist/workspaces.d.ts +255 -0
  467. package/vendor/shared/dist/workspaces.d.ts.map +1 -0
  468. package/vendor/shared/dist/workspaces.js +89 -0
  469. package/vendor/shared/src/agentCommands.ts +1 -0
  470. package/vendor/shared/src/automations.ts +12 -0
  471. package/vendor/shared/src/cardStudio.ts +13 -3
  472. package/vendor/shared/src/computer.ts +19 -5
  473. package/vendor/shared/src/constants.ts +8 -14
  474. package/vendor/shared/src/goalNotes.ts +23 -0
  475. package/vendor/shared/src/goals.ts +237 -0
  476. package/vendor/shared/src/index.ts +7 -6
  477. package/vendor/shared/src/messagingSafety.ts +11 -0
  478. package/vendor/shared/src/schemas/harness.ts +24 -130
  479. package/vendor/shared/src/smartCapture.ts +27 -0
  480. package/vendor/shared/src/taskSync.ts +81 -0
  481. package/vendor/shared/src/types.ts +0 -6
  482. package/vendor/shared/src/workspaces.ts +103 -0
  483. package/dist/coding/conduct.d.ts +0 -69
  484. package/dist/coding/conduct.d.ts.map +0 -1
  485. package/dist/coding/conduct.js +0 -348
  486. package/dist/coding/fleetIntegrate.d.ts +0 -37
  487. package/dist/coding/fleetIntegrate.d.ts.map +0 -1
  488. package/dist/coding/fleetIntegrate.js +0 -64
  489. package/dist/coding/fleetPlan.d.ts +0 -20
  490. package/dist/coding/fleetPlan.d.ts.map +0 -1
  491. package/dist/coding/fleetPlan.js +0 -125
  492. package/dist/coding/fleetTasks.d.ts +0 -33
  493. package/dist/coding/fleetTasks.d.ts.map +0 -1
  494. package/dist/coding/fleetTasks.js +0 -75
  495. package/dist/coding/openFleetPr.d.ts +0 -41
  496. package/dist/coding/openFleetPr.d.ts.map +0 -1
  497. package/dist/coding/openFleetPr.js +0 -121
  498. package/src/coding/conduct.ts +0 -462
  499. package/src/coding/fleetIntegrate.ts +0 -95
  500. package/src/coding/fleetPlan.ts +0 -135
  501. package/src/coding/fleetTasks.ts +0 -109
  502. package/src/coding/openFleetPr.ts +0 -148
@@ -1,462 +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 {
7
- commitSubjects,
8
- commitsAhead,
9
- currentBranch,
10
- removeWorktree,
11
- sessionBranch,
12
- sessionWorktreePath,
13
- } from './worktree.js';
14
- import { buildConductPlanPrompt, parseFleetPlan } from './fleetPlan.js';
15
- import { createFleetTasks, syncWorkerStatus } from './fleetTasks.js';
16
- import { openFleetPr, workerPrSummary, type FleetPrResult } from './openFleetPr.js';
17
- import { runCodeTurn, type CodeTurnRequest, type RunCodeTurnDeps } from './runCodeTurn.js';
18
-
19
- /**
20
- * The conductor: one Lucid "lead" that decomposes a goal, fans it out to isolated worker
21
- * worktrees, and integrates them back onto lucid/<repo> in order. Daemon-side authority — the
22
- * daemon owns every worker's resume handle and its lane; the phone is a thin client that sees
23
- * a plan, approves it, then watches the fleet.
24
- *
25
- * Two phases over one turn. `plan` runs a read-only lead turn to produce a FleetPlan (streamed
26
- * back as a fleet_plan event; nothing is created, so a discarded plan leaves no trace). `run`
27
- * takes the approved plan and: creates the task graph (worker = subtask), dispatches the workers
28
- * in parallel up to a cap (isolated worktrees make that safe), then integrates sequentially in
29
- * merge order — the one place overlap can bite. Each worker's own code frames stream under
30
- * `requestId === workerId`, so a worker reuses the entire existing code-turn pipeline; this
31
- * layer only adds the fleet-level events (plan, worker_status, conflict, done).
32
- */
33
-
34
- export interface ConductTurnRequest {
35
- id: string;
36
- repoId: string;
37
- phase: 'plan' | 'run' | 'setup' | 'integrate';
38
- prompt: string;
39
- images?: HarnessImage[];
40
- plan?: FleetPlan;
41
- resume?: string;
42
- /** Skip the dogfood task graph (quick incremental spawn — the fleet UI tracks it anyway). */
43
- ephemeral?: boolean;
44
- }
45
-
46
- type Api = { request<T>(endpoint: string, options?: RequestInit): Promise<T> };
47
-
48
- export interface RunConductTurnDeps {
49
- repos: RepoEntry[];
50
- executor: AgentExecutor;
51
- onWorkerApproval?: (requestId: string, approval: import('@lucidity/runtime').ExecutorApproval) => Promise<boolean>;
52
- onEnd?: (requestId: string) => void;
53
- send: (obj: unknown) => void;
54
- signal?: AbortSignal;
55
- model?: string;
56
- effort?: string;
57
- /** Task API for the dogfood (goal + subtasks). Absent → tasks are skipped, fleet still runs. */
58
- api?: Api;
59
- /** Project the fleet's tasks land in. Absent → the Inbox (projectId null). */
60
- projectId?: string | null;
61
- /** Default parallel-worker cap when the plan doesn't set one (quota guard). */
62
- maxParallel?: number;
63
- /** Worktree base override (tests point it at a temp dir). */
64
- baseDir?: string;
65
- /** Seam: run one worker's coding turn. Defaults to {@link runCodeTurn}. */
66
- runWorker?: (req: CodeTurnRequest, deps: RunCodeTurnDeps) => Promise<void>;
67
- /** Seam: open one worker's PR (push its branch + open/reuse a PR). Defaults to {@link openFleetPr}. */
68
- openPr?: typeof openFleetPr;
69
- /** Seam: how many commits a worker's branch carries. Defaults to {@link commitsAhead}. */
70
- commitsAhead?: typeof commitsAhead;
71
- /** Seam: the subjects of those commits, for the PR title. Defaults to {@link commitSubjects}. */
72
- commitSubjects?: typeof commitSubjects;
73
- }
74
-
75
- const DEFAULT_MAX_PARALLEL = 2;
76
-
77
- function msg(e: unknown): string {
78
- return e instanceof Error ? e.message : String(e);
79
- }
80
-
81
- /** Count +/- lines and files in a unified diff, for a worker card's "+N −M". */
82
- export function diffStat(diff: string): { added: number; removed: number; files: number } {
83
- let added = 0;
84
- let removed = 0;
85
- let files = 0;
86
- for (const line of diff.split('\n')) {
87
- if (line.startsWith('+++') || line.startsWith('---')) continue;
88
- if (line.startsWith('diff --git')) files++;
89
- else if (line.startsWith('+')) added++;
90
- else if (line.startsWith('-')) removed++;
91
- }
92
- return { added, removed, files };
93
- }
94
-
95
- /** Run `fn` over `items` with at most `cap` in flight. */
96
- async function runWithCap<T>(
97
- items: T[],
98
- cap: number,
99
- fn: (item: T) => Promise<void>,
100
- ): Promise<void> {
101
- const queue = [...items];
102
- const lanes = Array.from(
103
- { length: Math.max(1, Math.min(cap, items.length || 1)) },
104
- async () => {
105
- for (let item = queue.shift(); item !== undefined; item = queue.shift()) {
106
- await fn(item);
107
- }
108
- },
109
- );
110
- await Promise.all(lanes);
111
- }
112
-
113
- export async function runConductTurn(
114
- req: ConductTurnRequest,
115
- deps: RunConductTurnDeps,
116
- ): Promise<void> {
117
- const repo = resolveRepo(req.repoId, deps.repos);
118
- if (!repo) {
119
- deps.send({
120
- type: 'error',
121
- requestId: req.id,
122
- message: `Repo "${req.repoId}" isn't on this daemon's allowlist.`,
123
- });
124
- return;
125
- }
126
- if (!deps.executor.runStream) {
127
- deps.send({
128
- type: 'error',
129
- requestId: req.id,
130
- message: 'The conductor needs a streaming executor.',
131
- });
132
- return;
133
- }
134
-
135
- if (req.phase === 'plan') return planPhase(req, deps, repo.root);
136
- if (req.phase === 'setup') return setupPhase(req, deps);
137
- if (req.phase === 'integrate') return integratePhase(req, deps, repo.root);
138
- return runPhase(req, deps, repo.root);
139
- }
140
-
141
- /**
142
- * Design-first flow: materialize an approved plan WITHOUT writing any code. Create the task graph
143
- * (worker = subtask) and announce each worker as `queued`, then finish. The phone drives each
144
- * worker from here with `code` turns carrying its `workerId` (a conversation, in the worker's own
145
- * `fleet/<repo>/<workerId>` worktree), and merges with a later `integrate`. The counterpart to
146
- * `run`, which instead codes everything itself.
147
- */
148
- async function setupPhase(
149
- req: ConductTurnRequest,
150
- deps: RunConductTurnDeps,
151
- ): Promise<void> {
152
- const plan = req.plan;
153
- if (!plan) {
154
- deps.send({ type: 'error', requestId: req.id, message: 'Setup needs an approved plan.' });
155
- return;
156
- }
157
- let parentTaskId: string | undefined;
158
- if (deps.api) {
159
- try {
160
- ({ parentTaskId } = await createFleetTasks(deps.api, plan, { projectId: deps.projectId }));
161
- } catch (err) {
162
- console.error(`[conduct] couldn't create the fleet task graph: ${msg(err)}`);
163
- }
164
- }
165
- deps.send({
166
- type: 'fleet_plan',
167
- requestId: req.id,
168
- plan: { ...plan, ...(parentTaskId ? { parentTaskId } : {}) },
169
- });
170
- for (const w of plan.workers) {
171
- deps.send({ type: 'worker_status', requestId: req.id, workerId: w.workerId, status: 'queued' });
172
- if (deps.api) void syncWorkerStatus(deps.api, w.workerId, 'queued');
173
- }
174
- deps.send({
175
- type: 'done',
176
- requestId: req.id,
177
- text: `Fleet set up: ${plan.workers.length} worker${plan.workers.length === 1 ? '' : 's'} ready to brief.`,
178
- });
179
- }
180
-
181
- /** Design-first flow: deliver the plan's workers as their own PRs on the user's "Deliver" tap.
182
- * Same per-feature delivery + cleanup as the tail of `run`, run on demand instead. */
183
- async function integratePhase(
184
- req: ConductTurnRequest,
185
- deps: RunConductTurnDeps,
186
- repoRoot: string,
187
- ): Promise<void> {
188
- const plan = req.plan;
189
- if (!plan) {
190
- deps.send({ type: 'error', requestId: req.id, message: 'Deliver needs the fleet plan.' });
191
- return;
192
- }
193
- const sync = (workerId: string, status: WorkerStatus): Promise<void> =>
194
- deps.api ? syncWorkerStatus(deps.api, workerId, status) : Promise.resolve();
195
- await deliverAndReport(req, deps, repoRoot, plan, sync);
196
- }
197
-
198
- /** Read-only lead turn → a FleetPlan, streamed back as a fleet_plan event. Creates nothing. */
199
- async function planPhase(
200
- req: ConductTurnRequest,
201
- deps: RunConductTurnDeps,
202
- repoRoot: string,
203
- ): Promise<void> {
204
- let text = '';
205
- let sessionId: string | undefined;
206
- try {
207
- for await (const ev of deps.executor.runStream!({
208
- requestId: req.id,
209
- userPrompt: buildConductPlanPrompt(req.prompt),
210
- cwd: repoRoot,
211
- // Auto mode lets the lead READ the repo (ls/grep/cat) to inform the split; a mutating
212
- // tool has no approver here, so the prompt tells it to plan only, never edit.
213
- // Read-only: the lead may ls/grep/cat the repo to inform the split but must never edit
214
- // the user's live checkout. `plan` mode blocks every mutating tool, so even an off-script
215
- // or prompt-injected planning turn can't touch the working tree.
216
- permissionMode: 'plan',
217
- model: deps.model,
218
- effort: deps.effort,
219
- resume: req.resume,
220
- signal: deps.signal,
221
- })) {
222
- if (ev.type === 'session') {
223
- deps.send({ type: 'session', requestId: req.id, sessionId: ev.sessionId });
224
- } else if (ev.type === 'delta') {
225
- text += ev.text;
226
- deps.send({ type: 'delta', requestId: req.id, text: ev.text });
227
- } else if (ev.type === 'tool_call') {
228
- deps.send({ type: 'tool_call', requestId: req.id, name: ev.name, phase: ev.phase });
229
- } else if (ev.type === 'done') {
230
- sessionId = ev.sessionId;
231
- }
232
- }
233
- } catch (err) {
234
- if (isAbortError(err)) return;
235
- deps.send({ type: 'error', requestId: req.id, message: msg(err) });
236
- return;
237
- }
238
-
239
- let plan: FleetPlan;
240
- try {
241
- plan = parseFleetPlan(text, { goal: req.prompt });
242
- } catch (err) {
243
- deps.send({
244
- type: 'error',
245
- requestId: req.id,
246
- message: `Couldn't turn that into a fan-out plan: ${msg(err)}`,
247
- });
248
- return;
249
- }
250
-
251
- deps.send({ type: 'fleet_plan', requestId: req.id, plan });
252
- deps.send({ type: 'done', requestId: req.id, text, sessionId });
253
- }
254
-
255
- /** Execute an approved plan: create tasks, run workers, integrate, report. */
256
- async function runPhase(
257
- req: ConductTurnRequest,
258
- deps: RunConductTurnDeps,
259
- repoRoot: string,
260
- ): Promise<void> {
261
- const plan = req.plan;
262
- if (!plan) {
263
- deps.send({
264
- type: 'error',
265
- requestId: req.id,
266
- message: 'A run needs an approved plan.',
267
- });
268
- return;
269
- }
270
-
271
- const emitStatus = (
272
- workerId: string,
273
- status: WorkerStatus,
274
- extra?: { detail?: string; diffStat?: { added: number; removed: number; files: number } },
275
- ) =>
276
- deps.send({
277
- type: 'worker_status',
278
- requestId: req.id,
279
- workerId,
280
- status,
281
- ...(extra?.detail ? { detail: extra.detail } : {}),
282
- ...(extra?.diffStat ? { diffStat: extra.diffStat } : {}),
283
- });
284
- const sync = (workerId: string, status: WorkerStatus): Promise<void> =>
285
- deps.api && !req.ephemeral ? syncWorkerStatus(deps.api, workerId, status) : Promise.resolve();
286
-
287
- // Dogfood: the goal + one subtask per worker (worker = subtask). Skipped for ephemeral spawns so
288
- // quick incremental tasks don't spam the board. Best-effort; a fleet still runs if it can't write.
289
- let parentTaskId: string | undefined;
290
- if (deps.api && !req.ephemeral) {
291
- try {
292
- ({ parentTaskId } = await createFleetTasks(deps.api, plan, {
293
- projectId: deps.projectId,
294
- }));
295
- } catch (err) {
296
- console.error(`[conduct] couldn't create the fleet task graph: ${msg(err)}`);
297
- }
298
- }
299
- // Echo the plan with the parent id so the phone can link the Fleet board to the goal task.
300
- deps.send({
301
- type: 'fleet_plan',
302
- requestId: req.id,
303
- plan: { ...plan, ...(parentTaskId ? { parentTaskId } : {}) },
304
- });
305
-
306
- const runWorker = deps.runWorker ?? runCodeTurn;
307
- const cap = plan.maxParallel ?? deps.maxParallel ?? DEFAULT_MAX_PARALLEL;
308
- const diffStats = new Map<string, { added: number; removed: number; files: number }>();
309
- const failed = new Set<string>();
310
-
311
- await runWithCap(plan.workers, cap, async (w) => {
312
- // A cancel mid-fleet drops the workers still queued behind the cap — we don't spin up new
313
- // worktrees for a run the user has already stopped.
314
- if (deps.signal?.aborted) return;
315
- emitStatus(w.workerId, 'working');
316
- await sync(w.workerId, 'working');
317
-
318
- // The worker's code frames already carry requestId === workerId (we set the turn id to it),
319
- // so we forward them verbatim — the phone routes them to the worker's lane through the
320
- // existing code-turn rendering. We only peek to capture the diff size and any error.
321
- let sawError = false;
322
- let wasCancelled = false;
323
- const workerSend = (obj: unknown) => {
324
- const o = obj as { type?: string; diff?: string };
325
- if (o?.type === 'code_result' && typeof o.diff === 'string') {
326
- diffStats.set(w.workerId, diffStat(o.diff));
327
- }
328
- if (o?.type === 'error') sawError = true;
329
- if (o?.type === 'cancelled') { wasCancelled = true; sawError = true; }
330
- deps.send(obj);
331
- };
332
-
333
- try {
334
- await runWorker(
335
- {
336
- id: w.workerId,
337
- repoId: req.repoId,
338
- workerId: w.workerId,
339
- prompt: w.brief,
340
- },
341
- {
342
- repos: deps.repos,
343
- executor: deps.executor,
344
- onApproval: deps.onWorkerApproval ? (approval) => deps.onWorkerApproval!(w.workerId, approval) : undefined,
345
- send: workerSend,
346
- signal: deps.signal,
347
- model: deps.model,
348
- effort: deps.effort,
349
- baseDir: deps.baseDir,
350
- },
351
- );
352
- } catch (err) {
353
- if (!isAbortError(err)) sawError = true;
354
- } finally { deps.onEnd?.(w.workerId); }
355
-
356
- if (sawError) {
357
- failed.add(w.workerId);
358
- emitStatus(w.workerId, 'failed', wasCancelled ? { detail: 'Stopped' } : undefined);
359
- await sync(w.workerId, 'failed');
360
- } else {
361
- emitStatus(w.workerId, 'review', { diffStat: diffStats.get(w.workerId) });
362
- await sync(w.workerId, 'review');
363
- }
364
- });
365
-
366
- // A cancel during the worker phase must stop here — never mutate git or the backlog for a
367
- // run the user halted. (Without this, integration would still reset lucid/<repo> and mark
368
- // every subtask completed.)
369
- if (deps.signal?.aborted) return;
370
-
371
- await deliverAndReport(req, deps, repoRoot, plan, sync, failed);
372
- }
373
-
374
- /**
375
- * Per-feature delivery: push each successful worker's OWN branch and open its OWN PR against the
376
- * base branch, then reclaim its worktree (keeping the branch — the PR points at it). Independent
377
- * features become independent, separately-reviewable PRs instead of one combined branch, which is
378
- * how you actually want a set of unrelated changes to land. No cross-worker merge, so nothing
379
- * conflicts locally (any overlap surfaces when the PRs are merged on GitHub, per-PR, the user's
380
- * call). Reports a `worker_pr` per delivered worker + `worker_status: merged`, then `fleet_done`
381
- * (delivered/total) + `done`. Shared by the auto `run` (with the run's `failed` set) and the
382
- * on-demand `integrate` phase. A failed/no-commit worker can't open a PR — it's skipped and its
383
- * `worker_pr` carries the reason.
384
- */
385
- async function deliverAndReport(
386
- req: ConductTurnRequest,
387
- deps: RunConductTurnDeps,
388
- repoRoot: string,
389
- plan: FleetPlan,
390
- sync: (workerId: string, status: WorkerStatus) => Promise<void>,
391
- failed?: Set<string>,
392
- ): Promise<void> {
393
- const openPr = deps.openPr ?? openFleetPr;
394
- // Base = the branch each worker forked from (repo HEAD), so a worker's PR is only its own work,
395
- // not everything the checkout is ahead of the remote default by.
396
- const base = await currentBranch(repoRoot).then(
397
- (b) => (b && b !== 'HEAD' ? b : undefined),
398
- () => undefined,
399
- );
400
- const toDeliver = plan.workers.filter((w) => !failed?.has(w.workerId));
401
- let delivered = 0;
402
-
403
- for (const w of toDeliver) {
404
- if (deps.signal?.aborted) return;
405
- const worktree = sessionWorktreePath(req.repoId, deps.baseDir, w.workerId);
406
- const branch = sessionBranch(req.repoId, w.workerId);
407
- // A worker that stopped to ask you something never committed anything: its branch still sits
408
- // on base. Delivering it opens an empty PR that fails, and parks it under DELIVERED wearing
409
- // that error while it's actually waiting for an answer. Leave it in review, keep its worktree
410
- // (a steer continues in it), and say nothing — it isn't done, so it isn't delivered.
411
- if (base && (await (deps.commitsAhead ?? commitsAhead)(worktree, base)) === 0) {
412
- deps.send({
413
- type: 'worker_status',
414
- requestId: req.id,
415
- workerId: w.workerId,
416
- status: 'review',
417
- detail: 'Waiting on you — nothing committed yet.',
418
- });
419
- void sync(w.workerId, 'review');
420
- continue;
421
- }
422
- // A worker's commit subjects are the only account of what it actually CHANGED, and they're
423
- // on its branch in both delivery paths (#308): a spawn delivering itself at the tail of its
424
- // own run, and a steered worker delivered later from the phone in a different turn, possibly
425
- // a different daemon process. Nothing from the run survives that second path, git does.
426
- const subjects = base ? await (deps.commitSubjects ?? commitSubjects)(worktree, base) : [];
427
- const pr: FleetPrResult = await openPr(
428
- worktree,
429
- branch,
430
- workerPrSummary(w.title, w.brief, subjects),
431
- base,
432
- ).catch((e) => ({ error: msg(e) }));
433
- if (pr.url) delivered++;
434
- deps.send({
435
- type: 'worker_pr',
436
- requestId: req.id,
437
- workerId: w.workerId,
438
- ...(pr.url ? { url: pr.url } : {}),
439
- ...(pr.error ? { error: pr.error } : {}),
440
- });
441
- deps.send({ type: 'worker_status', requestId: req.id, workerId: w.workerId, status: 'merged' });
442
- void sync(w.workerId, 'merged');
443
- // Reclaim the worktree, KEEP the branch — the open PR points at it.
444
- await removeWorktree(
445
- repoRoot,
446
- { path: worktree, branch, mode: 'worktree' },
447
- { keepBranch: true },
448
- ).catch(() => {});
449
- }
450
-
451
- deps.send({
452
- type: 'fleet_done',
453
- requestId: req.id,
454
- delivered,
455
- total: plan.workers.length,
456
- });
457
- deps.send({
458
- type: 'done',
459
- requestId: req.id,
460
- text: `Fleet finished: ${delivered} of ${plan.workers.length} delivered as pull requests.`,
461
- });
462
- }
@@ -1,95 +0,0 @@
1
- import { execFile } from 'node:child_process';
2
- import { promisify } from 'node:util';
3
- import { ensureWorkspace, sessionBranch } from './worktree.js';
4
-
5
- const exec = promisify(execFile);
6
-
7
- async function git(cwd: string, args: string[]): Promise<string> {
8
- const { stdout } = await exec('git', args, { cwd, maxBuffer: 32 * 1024 * 1024 });
9
- return stdout;
10
- }
11
-
12
- export interface FleetConflict {
13
- workerId: string;
14
- /** The files that couldn't merge cleanly. */
15
- paths: string[];
16
- }
17
-
18
- export interface IntegrationResult {
19
- /** The branch the workers were integrated onto — the bare `lucid/<repo>` session, which
20
- * is also where the fleet's single PR opens from. */
21
- branch: string;
22
- /** Worker ids that merged cleanly, in the order they landed. */
23
- merged: string[];
24
- /** Workers whose branch conflicted; their merge was aborted and left for the user to hand
25
- * back to the worker as a fresh turn. */
26
- conflicts: FleetConflict[];
27
- }
28
-
29
- /**
30
- * Integrate finished workers onto the fleet branch, one at a time in merge order.
31
- *
32
- * The integration worktree is the bare repo session (`lucid/<repo>`), reset to HEAD, so the
33
- * fan-out's result is a single branch cut fresh from where the user started — clean history to
34
- * open one PR from. Each worker's `fleet/<repo>/<workerId>` branch is merged in; a conflict is
35
- * caught (not thrown), the merge aborted so the next worker can still land, and reported via
36
- * `onConflict` so the conductor surfaces it in the feed rather than silently dropping work.
37
- *
38
- * Sequential and in order because that's where overlap actually bites: the workers ran in
39
- * isolated worktrees and never raced each other on disk — only the merge can conflict, and only
40
- * against what already landed.
41
- */
42
- export async function integrateWorkers(
43
- repoRoot: string,
44
- repoId: string,
45
- workers: { workerId: string; mergeOrder: number }[],
46
- opts: {
47
- baseDir?: string;
48
- onMerged?: (workerId: string) => void;
49
- onConflict?: (conflict: FleetConflict) => void;
50
- } = {},
51
- ): Promise<IntegrationResult> {
52
- const branch = sessionBranch(repoId);
53
- // Fresh bare session = lucid/<repo> reset to HEAD: the integration target.
54
- const ws = await ensureWorkspace(repoRoot, repoId, {
55
- fresh: true,
56
- baseDir: opts.baseDir,
57
- });
58
-
59
- const ordered = [...workers].sort((a, b) => a.mergeOrder - b.mergeOrder);
60
- const merged: string[] = [];
61
- const conflicts: FleetConflict[] = [];
62
-
63
- for (const w of ordered) {
64
- const workerBranch = sessionBranch(repoId, w.workerId);
65
- try {
66
- await git(ws.path, [
67
- 'merge',
68
- '--no-ff',
69
- '-m',
70
- `Merge fleet worker ${w.workerId}`,
71
- workerBranch,
72
- ]);
73
- merged.push(w.workerId);
74
- opts.onMerged?.(w.workerId);
75
- } catch {
76
- // A conflict (or any merge failure): record the unmerged paths, abort so the branch is
77
- // clean for the next worker, and report. Never fatal — one bad lane can't sink the fleet.
78
- const unmerged = await git(ws.path, [
79
- 'diff',
80
- '--name-only',
81
- '--diff-filter=U',
82
- ]).catch(() => '');
83
- const paths = unmerged
84
- .split('\n')
85
- .map((s) => s.trim())
86
- .filter(Boolean);
87
- await git(ws.path, ['merge', '--abort']).catch(() => {});
88
- const conflict: FleetConflict = { workerId: w.workerId, paths };
89
- conflicts.push(conflict);
90
- opts.onConflict?.(conflict);
91
- }
92
- }
93
-
94
- return { branch, merged, conflicts };
95
- }
@@ -1,135 +0,0 @@
1
- import { z } from 'zod';
2
- import { uuidv7 } from 'uuidv7';
3
- import { FleetPlanSchema, type FleetPlan } from '@lucidity/shared';
4
-
5
- /**
6
- * The conductor's planning brain, kept pure so it's unit-testable without a model or a repo.
7
- *
8
- * A `conduct` `plan` turn asks the lead to decompose a goal into independent workers; this
9
- * module builds that prompt, parses the lead's JSON answer into a validated {@link FleetPlan}
10
- * (minting a stable workerId per worker), and derives the owned-path overlaps that become the
11
- * Fan-out card's ⚠ and the reason a merge order exists. Nothing here runs code or touches git.
12
- */
13
-
14
- /** The lead's JSON, before we mint ids — what we ask the model to emit. Lenient on purpose:
15
- * a missing mergeOrder falls back to array order, so a terse model still yields a usable plan. */
16
- const RawWorkerSchema = z.object({
17
- title: z.string().min(1).max(200),
18
- brief: z.string().min(1).max(8000),
19
- ownedPaths: z.array(z.string()).max(200).default([]),
20
- mergeOrder: z.number().int().optional(),
21
- });
22
- const RawPlanSchema = z.object({
23
- workers: z.array(RawWorkerSchema).min(1).max(16),
24
- maxParallel: z.number().int().positive().max(16).optional(),
25
- });
26
-
27
- export function buildConductPlanPrompt(goal: string): string {
28
- return [
29
- 'You are the lead engineer of a small fleet of coding agents working in one repository.',
30
- 'Decompose the goal below into independent WORKERS that can each run in its own git worktree.',
31
- '',
32
- 'Rules:',
33
- '- Prefer the FEWEST workers that cleanly cover the goal. A goal that is really one coherent',
34
- ' change is ONE worker — do not split for the sake of it.',
35
- '- Give each worker a set of owned paths (files or directories it may touch). Keep owned',
36
- ' paths DISJOINT between workers wherever you can; two workers that must touch the same file',
37
- ' will be integrated one after another, so note that by giving them different merge orders.',
38
- '- `mergeOrder` is the order their branches integrate back (lower first). Put a worker whose',
39
- ' work others build on earlier.',
40
- '',
41
- 'Answer with a short sentence of reasoning, then a single fenced ```json block of the form:',
42
- '{ "workers": [ { "title": "...", "brief": "the full instruction for this worker",',
43
- ' "ownedPaths": ["path/or/dir", "..."], "mergeOrder": 1 } ] }',
44
- '',
45
- `GOAL: ${goal}`,
46
- ].join('\n');
47
- }
48
-
49
- /** Strip a path down to what it "covers" for overlap purposes — drop a trailing glob/slash. */
50
- function pathBase(p: string): string {
51
- return p
52
- .trim()
53
- .replace(/\/+$/, '')
54
- .replace(/\/\*\*?$/, '')
55
- .replace(/\/+$/, '');
56
- }
57
-
58
- /** Do two owned-path entries cover any of the same tree — the same file, or one a directory of
59
- * the other? (`src/config.ts` vs `src/config.ts`; `src` vs `src/config.ts`.) */
60
- export function pathsOverlap(a: string, b: string): boolean {
61
- const x = pathBase(a);
62
- const y = pathBase(b);
63
- if (!x || !y) return false;
64
- return x === y || x.startsWith(`${y}/`) || y.startsWith(`${x}/`);
65
- }
66
-
67
- /** Every worker pair whose owned paths intersect, with the offending paths — the Fan-out card's
68
- * ⚠, and what tells the runner these two must integrate sequentially rather than race a merge. */
69
- export function detectOverlaps(
70
- workers: FleetPlan['workers'],
71
- ): FleetPlan['overlaps'] {
72
- const out: NonNullable<FleetPlan['overlaps']> = [];
73
- for (let i = 0; i < workers.length; i++) {
74
- for (let j = i + 1; j < workers.length; j++) {
75
- const paths: string[] = [];
76
- for (const pa of workers[i]!.ownedPaths) {
77
- for (const pb of workers[j]!.ownedPaths) {
78
- if (pathsOverlap(pa, pb)) paths.push(pathBase(pa));
79
- }
80
- }
81
- if (paths.length) {
82
- out.push({
83
- a: workers[i]!.workerId,
84
- b: workers[j]!.workerId,
85
- paths: [...new Set(paths)],
86
- });
87
- }
88
- }
89
- }
90
- return out.length ? out : undefined;
91
- }
92
-
93
- /** Pull the first JSON object out of the lead's answer — a fenced ```json block if present,
94
- * else the first balanced `{…}`. Returns the raw string or throws a readable error. */
95
- function extractJson(text: string): string {
96
- const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/i);
97
- if (fenced?.[1]) return fenced[1].trim();
98
- const start = text.indexOf('{');
99
- const end = text.lastIndexOf('}');
100
- if (start !== -1 && end > start) return text.slice(start, end + 1);
101
- throw new Error('the plan had no JSON block');
102
- }
103
-
104
- /**
105
- * Parse the lead's answer into a validated FleetPlan, minting a stable `workerId` (uuidv7) per
106
- * worker — the id doubles as the fleet subtask's id and the stream id its code frames arrive
107
- * under. `genId` is injectable so tests get deterministic ids. Throws on unparseable output.
108
- */
109
- export function parseFleetPlan(
110
- modelText: string,
111
- opts: { goal: string; genId?: () => string },
112
- ): FleetPlan {
113
- const genId = opts.genId ?? uuidv7;
114
- const raw = RawPlanSchema.parse(JSON.parse(extractJson(modelText)));
115
- const workers = raw.workers.map((w, i) => ({
116
- workerId: genId(),
117
- title: w.title,
118
- brief: w.brief,
119
- ownedPaths: w.ownedPaths,
120
- mergeOrder: w.mergeOrder ?? i + 1,
121
- }));
122
- const plan: FleetPlan = {
123
- goal: opts.goal,
124
- workers,
125
- overlaps: detectOverlaps(workers),
126
- maxParallel: raw.maxParallel,
127
- };
128
- // Validate the assembled plan against the wire schema before it leaves the daemon.
129
- return FleetPlanSchema.parse(plan);
130
- }
131
-
132
- /** Workers in the order their branches should integrate (lower mergeOrder first, stable). */
133
- export function integrationOrder(plan: FleetPlan): FleetPlan['workers'] {
134
- return [...plan.workers].sort((a, b) => a.mergeOrder - b.mergeOrder);
135
- }