@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,21 +1,42 @@
1
- import { existsSync } from 'node:fs';
1
+ import { existsSync, realpathSync } from 'node:fs';
2
+ import { dirname } from 'node:path';
2
3
  import { realpath } from 'node:fs/promises';
3
4
  import { createHash } from 'node:crypto';
4
- import { sessionProvider, type WorkspaceCommand, type WorkspaceSnapshot, type WorkerWorkspace } from '@lucidity/shared';
5
+ import { RepoSettingsSchema, sessionProvider, type RepoSettings, type RunReview, type UnmergedWork, type WorkspaceCommand, type WorkspaceSnapshot, type WorkerWorkspace } from '@lucidity/shared';
5
6
  import { RuntimeStore, conversationKey } from '../runtimeStore.js';
6
7
  import type { RepoEntry } from '../config.js';
7
8
  import { LaneQueue } from '../queue.js';
8
9
  import { resolveRepo } from './repos.js';
9
- import { ensureWorkspace, sessionWorktreePath, workspaceBase, workspaceBranchExists, type Workspace } from './worktree.js';
10
+ import { archiveWorktree, archivedHead, deleteArchivedWorktree, ensureWorkspace, headSha, restoreArchivedFiles, sessionBranch, sessionWorktreePath, unmergedArchivedWork, workspaceBase, workspaceBranchExists, type Workspace } from './worktree.js';
10
11
  import type { CodeTurnRequest } from './runCodeTurn.js';
12
+ import { copyIncludedFiles, matchedFiles, runSetupScript } from './worktreeSetup.js';
13
+ import { inspectRun, continuationRequest } from './runReview.js';
11
14
 
12
- const cities = ['Delhi', 'Chicago', 'San Diego', 'Lisbon', 'Kyoto', 'Oslo', 'Lima', 'Perth'];
15
+ /** "Worktree 3": the next number this repository has not used. */
16
+ export function nextWorkerTitle(titles: string[]): string {
17
+ const used = titles.map((title) => (title.startsWith('Worktree ') ? Number(title.slice(9)) : 0));
18
+ return `Worktree ${Math.max(0, ...used.filter(Number.isInteger)) + 1}`;
19
+ }
20
+ // Two checkouts fighting over :3001 and :8081 is half of CLAUDE.md's gotchas. Every worktree
21
+ // gets ten ports of its own, kept for its lifetime, well away from those defaults and from the
22
+ // owner's phone Metro on 8090.
23
+ const PORT_BASE = 4100;
24
+ const PORT_BLOCK = 10;
25
+
26
+ /** The lowest block of ports no other worktree on this computer holds. */
27
+ export function nextPortBlock(taken: Array<number | undefined>): number {
28
+ const used = new Set(taken);
29
+ let port = PORT_BASE;
30
+ while (used.has(port)) port += PORT_BLOCK;
31
+ return port;
32
+ }
13
33
  type SavedWorker = WorkerWorkspace & { path?: string; sessionCheckout?: boolean; legacy?: boolean; legacyMessages?: NonNullable<WorkspaceSnapshot['legacyMessages']> };
14
34
  type SavedCheckout = { revision: string; clearedThrough?: string; legacyMessages?: WorkspaceSnapshot['legacyMessages']; resume?: string };
15
35
 
16
36
  /** Workspace lifetime is independent of runs, provider sessions, PRs, and phone storage. */
17
37
  export class WorkspaceRegistry {
18
38
  private lanes = new LaneQueue();
39
+ private setups = new Map<string, Promise<void>>();
19
40
  constructor(private readonly store: RuntimeStore, private readonly repos: () => RepoEntry[], private readonly baseDir?: string) {}
20
41
 
21
42
  private repo(id: string) {
@@ -25,13 +46,92 @@ export class WorkspaceRegistry {
25
46
  }
26
47
  private public(worker: SavedWorker): WorkerWorkspace {
27
48
  const { path: _, legacyMessages: __, sessionCheckout: ___, legacy: ____, ...row } = worker;
28
- return { ...row, resume: this.store.latestSession(worker.conversationId) ?? row.resume };
49
+ return { ...row, resume: this.store.latestSession(worker.conversationId) ?? row.resume,
50
+ ...(this.setups.has(worker.workerId) ? { setup: 'running' as const } : {}) };
29
51
  }
30
52
  list(repoId?: string): WorkerWorkspace[] {
31
53
  return this.store.list<SavedWorker>('workers')
32
54
  .filter((w) => (!repoId || w.repoId === repoId) && this.repos().some((r) => r.id === w.repoId))
33
55
  .map((w) => this.public(w));
34
56
  }
57
+ /** How this repository's worktrees are prepared. Nothing is copied or run until the owner sets it. */
58
+ settings(repoId: string): RepoSettings {
59
+ return RepoSettingsSchema.parse(this.store.get<RepoSettings>('repo-settings', repoId) ?? {});
60
+ }
61
+ private places(repoId: string) {
62
+ const root = this.repo(repoId).root;
63
+ return { root, worktrees: dirname(sessionWorktreePath(repoId, this.baseDir, 'x')),
64
+ copyMatches: matchedFiles(root, this.settings(repoId).copy) };
65
+ }
66
+ /** Run the archive command, then free the folder. Shared by the phone's Archive and archive-on-merge. */
67
+ private async archive(worker: SavedWorker): Promise<void> {
68
+ const { repoId, workerId } = worker;
69
+ if (worker.state === 'creating' || this.setups.has(workerId)) throw new Error('Wait for workspace setup to finish before archiving.');
70
+ if (this.store.unfinished(worker.conversationId))
71
+ throw new Error('Stop this worker and its queued messages before archiving it.');
72
+ // The session checkout is shared with the classic single session, so its folder stays.
73
+ if (!worker.sessionCheckout) {
74
+ const root = this.repo(repoId).root;
75
+ const settings = this.settings(repoId);
76
+ const path = sessionWorktreePath(repoId, this.baseDir, workerId);
77
+ if (settings.archiveScript && existsSync(path))
78
+ await runSetupScript(root, path, worker.title, settings.archiveScript, worker.port).catch((error) => {
79
+ const detail = String((error as { stderr?: string }).stderr || (error as Error).message).trim().slice(-600);
80
+ throw new Error(`The archive command failed, so this worktree was kept. ${detail}`);
81
+ });
82
+ await archiveWorktree(root, { path, branch: worker.branch ?? sessionBranch(repoId, workerId), mode: 'worktree' },
83
+ workerId, { deleteBranch: settings.deleteBranchOnArchive });
84
+ }
85
+ this.save({ ...worker, state: 'archived' });
86
+ }
87
+ /** Remove an archived worktree for good: its local branch, its snapshot and its record. Answers
88
+ * with the work that would be lost, deleting nothing, unless there is none or `force` is set. */
89
+ private delete(repoId: string, workerId: string, force?: boolean): Promise<UnmergedWork | undefined> {
90
+ const root = this.repo(repoId).root;
91
+ // Queued behind create, so a restore that is already under way finishes first and is seen here.
92
+ return this.lanes.run(root, async () => {
93
+ const worker = this.store.get<SavedWorker>('workers', workerId);
94
+ // Already gone: another device may still list a worktree that was deleted from this one.
95
+ if (!worker) return undefined;
96
+ if (worker.repoId !== repoId) throw new Error('This worker is not registered in this repository.');
97
+ if (worker.state !== 'archived') throw new Error('Archive this worktree before deleting it.');
98
+ // The session checkout's branch and folder belong to the classic single session, so they stay.
99
+ if (!worker.sessionCheckout) {
100
+ const branch = worker.branch ?? sessionBranch(repoId, workerId);
101
+ if (!force) {
102
+ const unmerged = await unmergedArchivedWork(root, workerId, branch,
103
+ [worker.baseRef, this.settings(repoId).baseRef, this.repos().find((r) => r.id === repoId)?.baseRef]);
104
+ if (unmerged.commits || unmerged.uncommitted) return unmerged;
105
+ }
106
+ await deleteArchivedWorktree(root, workerId, branch).catch((error) => {
107
+ const detail = String((error as { stderr?: string }).stderr || (error as Error).message).trim().slice(-600);
108
+ throw new Error(`This worktree's branch could not be deleted, so it was kept. ${detail}`);
109
+ });
110
+ }
111
+ // The conversation's runs stay: they are the receipts that stop a replayed request running twice.
112
+ this.store.transaction(() => {
113
+ this.store.delete('workers', workerId);
114
+ this.store.delete('workspaces', worker.conversationId);
115
+ });
116
+ return undefined;
117
+ });
118
+ }
119
+ /** Archive ready worktrees whose pull request has merged, in repositories that asked for it.
120
+ * A worktree with commits past the merged head, or a turn in flight, is left alone. */
121
+ async archiveMerged(mergedHead: (repoRoot: string, branch: string) => Promise<string | undefined>): Promise<string[]> {
122
+ const archived: string[] = [];
123
+ for (const worker of this.store.list<SavedWorker>('workers')) {
124
+ if (worker.state !== 'ready' || worker.sessionCheckout || !worker.path || !worker.branch) continue;
125
+ try {
126
+ if (!this.settings(worker.repoId).archiveOnMerge || !existsSync(worker.path)) continue;
127
+ const merged = await mergedHead(this.repo(worker.repoId).root, worker.branch);
128
+ if (!merged || merged !== await headSha(worker.path)) continue;
129
+ await this.archive(worker);
130
+ archived.push(worker.workerId);
131
+ } catch { /* busy, or the repository is gone: try again on the next sweep */ }
132
+ }
133
+ return archived;
134
+ }
35
135
  private save(worker: SavedWorker): void {
36
136
  this.store.set('workers', worker.workerId, { ...worker, updatedAt: new Date().toISOString() });
37
137
  }
@@ -60,7 +160,7 @@ export class WorkspaceRegistry {
60
160
  if (previous?.state === 'ready') return this.public(previous);
61
161
  const now = new Date().toISOString();
62
162
  const worker: SavedWorker = previous ?? {
63
- workerId, repoId, title: title || cities[this.store.list('workers').length % cities.length]!, brief,
163
+ workerId, repoId, title: title || nextWorkerTitle(this.store.list<SavedWorker>('workers').filter((w) => w.repoId === repoId).map((w) => w.title)), brief,
64
164
  workspaceId: workerId, conversationId: conversationKey({ kind: 'code', repoId, workerId }),
65
165
  state: 'creating', createdAt: now, updatedAt: now,
66
166
  };
@@ -69,17 +169,22 @@ export class WorkspaceRegistry {
69
169
  const gitWorkerId = worker.sessionCheckout ? undefined : workerId;
70
170
  const path = sessionWorktreePath(repoId, this.baseDir, gitWorkerId);
71
171
  const branchExists = await workspaceBranchExists(repo.root, repoId, gitWorkerId);
72
- if (worker.legacy && !existsSync(path) && !branchExists)
172
+ // A branch deleted on archive is re-created from the commit its snapshot was taken on.
173
+ const archivedTip = gitWorkerId && !branchExists && !existsSync(path) ? await archivedHead(repo.root, workerId) : undefined;
174
+ if (worker.legacy && !existsSync(path) && !branchExists && !archivedTip)
73
175
  throw new Error('The original worker branch and files are missing. Its conversation is preserved; create a new worker for new work.');
74
176
  // A known legacy directory is adopted without fetching or resetting it.
75
- const base = existsSync(path) || branchExists || previous?.baseSha
177
+ const base = existsSync(path) || branchExists || archivedTip || previous?.baseSha
76
178
  ? previous?.baseSha ? { ref: previous.baseRef!, sha: previous.baseSha } : undefined
77
- : await workspaceBase(repo.root, this.repos().find((r) => r.id === repoId)?.baseRef);
179
+ : await workspaceBase(repo.root, this.settings(repoId).baseRef || this.repos().find((r) => r.id === repoId)?.baseRef);
78
180
  if (base) this.save({ ...worker, state: 'creating', baseRef: base.ref, baseSha: base.sha });
79
- const workspace = await ensureWorkspace(repo.root, repoId, { workerId: gitWorkerId, baseDir: this.baseDir, startPoint: base?.sha });
181
+ const fresh = !existsSync(path);
182
+ const workspace = await ensureWorkspace(repo.root, repoId, { workerId: gitWorkerId, baseDir: this.baseDir, startPoint: archivedTip ?? base?.sha });
183
+ if (gitWorkerId) await restoreArchivedFiles(repo.root, workspace, workerId);
80
184
  const ready: SavedWorker = { ...worker, state: 'ready', error: undefined, path: await realpath(workspace.path),
81
- branch: workspace.branch, ...(base ? { baseRef: base.ref, baseSha: base.sha } : {}) };
185
+ port: this.portOf(worker), branch: workspace.branch, ...(base ? { baseRef: base.ref, baseSha: base.sha } : {}) };
82
186
  this.save(ready);
187
+ if (fresh && gitWorkerId) this.setUp(repo.root, ready);
83
188
  return this.public(ready);
84
189
  } catch (error) {
85
190
  const reserved = this.store.get<SavedWorker>('workers', workerId) ?? worker;
@@ -89,11 +194,37 @@ export class WorkspaceRegistry {
89
194
  });
90
195
  }
91
196
 
197
+ /** A worktree's port block. Archived worktrees keep theirs so a restore comes back on the same ports. */
198
+ private portOf(worker: SavedWorker): number {
199
+ return worker.port ?? nextPortBlock(this.store.list<SavedWorker>('workers').map((w) => w.port));
200
+ }
201
+
202
+ /** Fill in a worktree: the repository's listed files, then its setup command. This runs after the
203
+ * worktree is reported ready so the phone is not kept waiting; a turn waits for it in prepare().
204
+ * A failure is noted on the worker and never fails the worktree. */
205
+ private setUp(repoRoot: string, worker: SavedWorker): void {
206
+ const settings = this.settings(worker.repoId);
207
+ if (!settings.copy.length && !settings.setup) return;
208
+ this.save({ ...worker, setup: undefined, error: undefined });
209
+ const run = (async () => {
210
+ copyIncludedFiles(repoRoot, worker.path!, settings.copy);
211
+ if (settings.setup) await runSetupScript(repoRoot, worker.path!, worker.title, settings.setup, worker.port);
212
+ })().catch((error) => {
213
+ const detail = String((error as { stderr?: string }).stderr || (error as Error).message).trim().slice(-600);
214
+ console.error(`[workspaces] setup failed for ${worker.workerId}: ${detail}`);
215
+ const current = this.store.get<SavedWorker>('workers', worker.workerId);
216
+ if (current?.state === 'ready') this.save({ ...current, setup: 'failed', error: detail });
217
+ }).finally(() => this.setups.delete(worker.workerId));
218
+ this.setups.set(worker.workerId, run);
219
+ }
220
+
92
221
  async prepare(request: CodeTurnRequest): Promise<Workspace> {
222
+ this.checkRecoveryWorkspace(request);
93
223
  const repo = this.repo(request.repoId);
94
224
  let gitWorkerId = request.workerId;
95
225
  if (request.workerId) {
96
226
  await this.create(request.repoId, request.workerId, undefined, request.prompt);
227
+ await this.setups.get(request.workerId);
97
228
  const worker = this.store.get<SavedWorker>('workers', request.workerId)!;
98
229
  if (worker.sessionCheckout) gitWorkerId = undefined;
99
230
  if (!worker.path || !existsSync(worker.path)) {
@@ -105,7 +236,12 @@ export class WorkspaceRegistry {
105
236
  mode: request.workerId ? 'worktree' : request.mode, workerId: gitWorkerId, baseDir: this.baseDir,
106
237
  });
107
238
  this.store.set('workspaces', conversationKey({ ...request, kind: 'code' }), { ...workspace, repoId: request.repoId });
108
- return workspace;
239
+ const worker = request.workerId ? this.store.get<SavedWorker>('workers', request.workerId) : undefined;
240
+ if (!worker || worker.sessionCheckout) return workspace;
241
+ // Worktrees made before ports existed get their block on their next turn.
242
+ const port = this.portOf(worker);
243
+ if (worker.port !== port) this.save({ ...worker, port });
244
+ return { ...workspace, env: { LUCIDITY_PORT: String(port), LUCIDITY_WORKTREE_NAME: worker.title } };
109
245
  }
110
246
 
111
247
  private checkout(command: WorkspaceCommand, commandId?: string): WorkspaceSnapshot {
@@ -159,11 +295,24 @@ export class WorkspaceRegistry {
159
295
  }
160
296
 
161
297
  async command(command: WorkspaceCommand, commandId?: string): Promise<WorkspaceSnapshot> {
298
+ if (command.action === 'inspect-run' || command.action === 'continue-run') {
299
+ if (!command.repoId) throw new Error('Select a repository.');
300
+ const repo = this.repo(command.repoId);
301
+ const path = command.checkout ? repo.root : command.workerId ? this.store.get<SavedWorker>('workers', command.workerId)?.path : undefined;
302
+ if (command.action === 'continue-run') return { workers: this.list(command.repoId), review: this.store.get('run-reviews', command.requestId!) };
303
+ return { workers: this.list(command.repoId), review: await inspectRun(this.store, command, path) };
304
+ }
162
305
  if (command.checkout) return this.checkout(command, commandId);
163
306
  if (command.action === 'clear-history') throw new Error('Select Main checkout to clear its history.');
164
307
  const { action, repoId } = command;
165
308
  let workerId = command.workerId;
166
309
  if (action === 'list') return { workers: this.list(repoId) };
310
+ if (action === 'settings' || action === 'save-settings') {
311
+ if (!repoId) throw new Error('Select a repository.');
312
+ this.repo(repoId);
313
+ if (action === 'save-settings') this.store.set('repo-settings', repoId, RepoSettingsSchema.parse(command.settings ?? {}));
314
+ return { workers: this.list(repoId), settings: this.settings(repoId), places: this.places(repoId) };
315
+ }
167
316
  if (action === 'import' && repoId && command.legacy?.sessionCheckout) {
168
317
  const key = createHash('sha256').update(this.repo(repoId).root).digest('hex');
169
318
  workerId = `${key.slice(0, 8)}-${key.slice(8, 12)}-7${key.slice(13, 16)}-8${key.slice(17, 20)}-${key.slice(20, 32)}`;
@@ -183,6 +332,9 @@ export class WorkspaceRegistry {
183
332
  sessionCheckout: command.legacy?.sessionCheckout, legacy: true });
184
333
  await this.create(repoId, workerId).catch(() => {});
185
334
  }
335
+ } else if (action === 'delete') {
336
+ const unmerged = await this.delete(repoId, workerId, command.force);
337
+ return { workers: this.list(repoId), ...(unmerged ? { unmerged } : {}) };
186
338
  } else {
187
339
  const worker = this.store.get<SavedWorker>('workers', workerId);
188
340
  if (!worker || worker.repoId !== repoId) throw new Error('This worker is not registered in this repository.');
@@ -196,10 +348,10 @@ export class WorkspaceRegistry {
196
348
  ...(page.length === 10 ? { nextBefore: page[0]!.request.id } : {}) };
197
349
  }
198
350
  if (action === 'archive') {
199
- if (worker.state === 'creating') throw new Error('Wait for workspace setup to finish before archiving.');
200
- if (this.store.unfinished(worker.conversationId))
201
- throw new Error('Stop this worker and its queued messages before archiving it.');
202
- this.save({ ...worker, state: 'archived' });
351
+ await this.archive(worker);
352
+ } else if (action === 'setup') {
353
+ if (worker.state !== 'ready' || worker.sessionCheckout || !worker.path) throw new Error('This worktree is not ready for setup.');
354
+ if (!this.setups.has(workerId)) this.setUp(this.repo(repoId).root, worker);
203
355
  } else if (action === 'restore') {
204
356
  this.save({ ...worker, state: 'creating' });
205
357
  await this.create(repoId, workerId);
@@ -207,4 +359,22 @@ export class WorkspaceRegistry {
207
359
  }
208
360
  return { workers: this.list(repoId) };
209
361
  }
362
+ continuation(command: WorkspaceCommand) {
363
+ if (!command.repoId) throw new Error('Select a repository.');
364
+ this.repo(command.repoId);
365
+ if (command.workerId && this.store.get<SavedWorker>('workers', command.workerId)?.state !== 'ready')
366
+ throw new Error('Restore this worker before continuing.');
367
+ const request = continuationRequest(this.store, command);
368
+ this.checkRecoveryWorkspace(request);
369
+ return request;
370
+ }
371
+ private checkRecoveryWorkspace(request: CodeTurnRequest) {
372
+ if (!request.recoveryOf) return;
373
+ const review = this.store.get<RunReview>('run-reviews', request.recoveryOf);
374
+ const worker = request.workerId ? this.store.get<SavedWorker>('workers', request.workerId) : undefined;
375
+ const path = !request.workerId && request.mode === 'in-place' ? this.repo(request.repoId).root :
376
+ sessionWorktreePath(request.repoId, this.baseDir, worker?.sessionCheckout ? undefined : request.workerId);
377
+ if (!review?.workspace || !existsSync(review.workspace) || !existsSync(path) || realpathSync(path) !== realpathSync(review.workspace))
378
+ throw new Error('The configured workspace changed since this turn. Restore the reviewed workspace before continuing.');
379
+ }
210
380
  }
@@ -21,6 +21,8 @@ export interface Workspace {
21
21
  /** The branch commits land on. `HEAD` when the in-place checkout is detached. */
22
22
  branch: string;
23
23
  mode: WorkspaceMode;
24
+ /** Variables the turn's agent runs with, such as the worktree's port block. */
25
+ env?: Record<string, string>;
24
26
  }
25
27
 
26
28
  async function git(cwd: string, args: string[], env?: NodeJS.ProcessEnv): Promise<string> {
@@ -33,35 +35,29 @@ function slug(repoId: string): string {
33
35
  return repoId.replace(/[^A-Za-z0-9._-]/g, '-');
34
36
  }
35
37
 
36
- /** The stable branch name for a coding session. A bare repo session is `lucid/<repo>`;
37
- * a conductor's worker gets `fleet/<repo>/<workerId>` (the workerId is the fleet
38
- * subtask's id), so N workers on one repo hold N isolated branches.
38
+ /** The stable branch name for a coding session. The repository's main session is
39
+ * `lucid/<repo>`; a worktree gets `wt/<repo>/<workerId>`.
39
40
  *
40
- * Workers deliberately live under a SEPARATE `fleet/` namespace rather than nested
41
- * under `lucid/<repo>/…`: a git ref can't be both a leaf and a directory, so a
42
- * branch `lucid/<repo>` and a branch `lucid/<repo>/<workerId>` are mutually
43
- * exclusive (the D/F conflict). Keeping workers under `fleet/` leaves the bare
44
- * `lucid/<repo>` — the classic single session AND the fleet's integration target,
45
- * the one branch a fleet PR opens from — untouched. `workerId` absent → the classic
46
- * branch, byte-for-byte as before. */
41
+ * Worktrees live under their own `wt/` namespace instead of `lucid/<repo>/…` because a git
42
+ * ref can't be both a leaf and a directory, so `lucid/<repo>` and `lucid/<repo>/<workerId>`
43
+ * cannot both exist. */
47
44
  export function sessionBranch(repoId: string, workerId?: string): string {
48
45
  return workerId
49
- ? `fleet/${slug(repoId)}/${slug(workerId)}`
46
+ ? `wt/${slug(repoId)}/${slug(workerId)}`
50
47
  : `lucid/${slug(repoId)}`;
51
48
  }
52
49
 
53
- /** The stable worktree path for a coding session (constant across turns, so `--resume`
54
- * resolves). A bare session lives at `<base>/<repo>`; a worker at
55
- * `<base>/fleet/<repo>/<workerId>` — a sibling of the bare worktree, never nested
56
- * inside it (which would put a checkout within a checkout). `baseDir` overrides the
57
- * default root (tests point it at a temp dir); `workerId` absent → the classic path. */
50
+ /** The stable folder for a coding session (constant across turns, so `--resume` resolves).
51
+ * The main session lives at `<base>/<repo>`; a worktree at `<base>/wt/<repo>/<workerId>`, a
52
+ * sibling of it and never nested inside it (which would put a checkout within a checkout).
53
+ * `baseDir` overrides the default root (tests point it at a temp dir). */
58
54
  export function sessionWorktreePath(
59
55
  repoId: string,
60
56
  baseDir: string = WORKTREE_BASE,
61
57
  workerId?: string,
62
58
  ): string {
63
59
  return workerId
64
- ? join(baseDir, 'fleet', slug(repoId), slug(workerId))
60
+ ? join(baseDir, 'wt', slug(repoId), slug(workerId))
65
61
  : join(baseDir, slug(repoId));
66
62
  }
67
63
 
@@ -172,9 +168,7 @@ export async function ensureWorkspace(
172
168
  fresh?: boolean;
173
169
  startPoint?: string;
174
170
  baseDir?: string;
175
- /** Conductor worker id (the fleet subtask's id). Present → an isolated per-worker
176
- * worktree/branch so N workers run in parallel on one repo. Absent → the classic
177
- * single session, unchanged. */
171
+ /** Present → that worktree's own folder and branch. Absent → the main session. */
178
172
  workerId?: string;
179
173
  } = {},
180
174
  ): Promise<Workspace> {
@@ -321,6 +315,153 @@ export async function removeWorktree(
321
315
  }
322
316
  }
323
317
 
318
+ /** Where an archived worker's files are parked. Under `refs/lucid/`, so no branch or push sees it. */
319
+ export function archivedWorktreeRef(workerId: string): string {
320
+ return `refs/lucid/archived/${slug(workerId)}`;
321
+ }
322
+
323
+ /**
324
+ * Free an archived worker's folder. Its full working state (tracked, staged and untracked,
325
+ * gitignored files excluded) is parked first as a commit on top of the worktree's HEAD, so
326
+ * uncommitted work survives. The branch stays. Throws before removing anything if the
327
+ * snapshot cannot be written.
328
+ */
329
+ export async function archiveWorktree(repoRoot: string, ws: Workspace, workerId: string, opts: { deleteBranch?: boolean } = {}): Promise<void> {
330
+ if (ws.mode === 'in-place' || resolve(ws.path) === resolve(repoRoot)) {
331
+ throw new Error(`refusing to remove the repo checkout itself: ${ws.path}`);
332
+ }
333
+ if (!existsSync(ws.path)) return;
334
+ const tree = await snapshotTree(ws);
335
+ const head = (await git(ws.path, ['rev-parse', 'HEAD'])).trim();
336
+ const sha = (await git(ws.path, ['commit-tree', tree, '-p', head, '-m', 'Archived worktree'])).trim();
337
+ await git(repoRoot, ['update-ref', archivedWorktreeRef(workerId), sha]);
338
+ await git(repoRoot, ['worktree', 'remove', '--force', ws.path]);
339
+ // The snapshot's parent is the branch tip, so the branch can be re-created from it on restore.
340
+ if (opts.deleteBranch) await git(repoRoot, ['branch', '-D', ws.branch]).catch(() => {});
341
+ }
342
+
343
+ /** The commit an archived worker's branch pointed at, for re-creating a branch deleted on archive. */
344
+ export async function archivedHead(repoRoot: string, workerId: string): Promise<string | undefined> {
345
+ return git(repoRoot, ['rev-parse', '--verify', '--quiet', `${archivedWorktreeRef(workerId)}^`]).then((s) => s.trim() || undefined, () => undefined);
346
+ }
347
+
348
+ /**
349
+ * What deleting an archived worker would lose: commits on its branch (or, when the branch was
350
+ * deleted on archive, on the commit its snapshot was taken from) that are in none of `baseRefs`,
351
+ * the remote default branch or the branch's own remote copy, plus whether the snapshot holds
352
+ * files that were never committed.
353
+ *
354
+ * A commit whose change is already in the base under another sha does not count, so a branch
355
+ * that was rebase-merged reads as merged. A squash merge cannot be recognised this way and
356
+ * still counts. Remote refs are refreshed first when anything looks unmerged, since a pull
357
+ * request merged on GitHub is only visible after a fetch; offline, the last fetched state is used.
358
+ */
359
+ export async function unmergedArchivedWork(
360
+ repoRoot: string,
361
+ workerId: string,
362
+ branch: string,
363
+ baseRefs: (string | undefined)[] = [],
364
+ ): Promise<{ commits: number; uncommitted: boolean }> {
365
+ const sha = (ref: string) =>
366
+ git(repoRoot, ['rev-parse', '--verify', '--quiet', '--end-of-options', `${ref}^{commit}`]).then((s) => s.trim() || undefined, () => undefined);
367
+ const present = async (refs: (string | undefined)[]) =>
368
+ [...new Set((await Promise.all(refs.map((ref) => (ref ? sha(ref) : undefined)))).filter((s): s is string => !!s))];
369
+ const snapshot = archivedWorktreeRef(workerId);
370
+ const trees = await git(repoRoot, ['rev-parse', '--verify', '--quiet', `${snapshot}^{tree}`])
371
+ .then(async (tree) => [tree.trim(), (await git(repoRoot, ['rev-parse', '--verify', '--quiet', `${snapshot}^^{tree}`])).trim()], () => []);
372
+ const uncommitted = trees.length === 2 && trees[0] !== trees[1];
373
+ const tips = await present([`refs/heads/${branch}`, `${snapshot}^`]);
374
+ if (!tips.length) return { commits: 0, uncommitted };
375
+ const kept = async () => {
376
+ const remoteDefault = await git(repoRoot, ['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD']).then((s) => s.trim(), () => '');
377
+ const refs = await present([
378
+ ...baseRefs.flatMap((ref) => (!ref || ref === 'HEAD' || ref.startsWith('origin/') ? [ref] : [`origin/${ref}`, ref])),
379
+ remoteDefault, remoteDefault && `refs/heads/${remoteDefault.replace(/^origin\//, '')}`,
380
+ `refs/remotes/origin/${branch}`, `${branch}@{upstream}`,
381
+ ]);
382
+ // A repository with no remote and no configured base has only its own checkout to compare against.
383
+ return refs.length ? refs : present(['HEAD']);
384
+ };
385
+ const ahead = async (bases: string[]) =>
386
+ (await git(repoRoot, ['rev-list', '--no-merges', ...tips, '--not', ...bases])).split('\n').filter(Boolean);
387
+ let bases = await kept();
388
+ let commits = await ahead(bases);
389
+ if (commits.length) {
390
+ await exec('git', ['fetch', 'origin'], { cwd: repoRoot, timeout: 20_000 }).catch(() => {});
391
+ bases = await kept();
392
+ commits = await ahead(bases);
393
+ }
394
+ if (commits.length && bases[0]) {
395
+ const applied = new Set(commits);
396
+ for (const tip of tips) {
397
+ const fresh = await git(repoRoot, ['rev-list', '--no-merges', '--cherry-pick', '--right-only', `${bases[0]}...${tip}`]);
398
+ for (const commit of fresh.split('\n')) applied.delete(commit);
399
+ }
400
+ commits = commits.filter((commit) => !applied.has(commit));
401
+ }
402
+ return { commits: commits.length, uncommitted };
403
+ }
404
+
405
+ /** Remove what an archived worker left in the repository: its local branch, if it still has one,
406
+ * and its snapshot. The remote branch is not touched. */
407
+ export async function deleteArchivedWorktree(repoRoot: string, workerId: string, branch: string): Promise<void> {
408
+ // A folder removed by hand still holds its branch until its worktree entry is pruned.
409
+ await git(repoRoot, ['worktree', 'prune']).catch(() => {});
410
+ const exists = await git(repoRoot, ['show-ref', '--verify', `refs/heads/${branch}`]).then(() => true, () => false);
411
+ if (exists) await git(repoRoot, ['branch', '-D', '--end-of-options', branch]);
412
+ await git(repoRoot, ['update-ref', '-d', archivedWorktreeRef(workerId)]);
413
+ }
414
+
415
+ /** Per-file added and removed line counts for everything in a folder that differs from `base`,
416
+ * committed or not. Tracked files only; a binary file counts as zero lines. */
417
+ export async function numstatSince(path: string, base: string): Promise<Map<string, [added: number, removed: number]>> {
418
+ const out = await git(path, ['diff', '--numstat', '-z', base]);
419
+ const stats = new Map<string, [number, number]>();
420
+ for (const row of out.split('\0')) {
421
+ const [added, removed, file] = row.split('\t');
422
+ if (file) stats.set(file, [Number(added) || 0, Number(removed) || 0]);
423
+ }
424
+ return stats;
425
+ }
426
+
427
+ /** What changed between two readings of {@link numstatSince} taken against the same base: the
428
+ * turn's own work, with whatever was already uncommitted when it started taken out. */
429
+ export function turnChangeCounts(
430
+ before: Map<string, [number, number]>,
431
+ after: Map<string, [number, number]>,
432
+ ): { added: number; removed: number; files: string[] } | undefined {
433
+ let added = 0;
434
+ let removed = 0;
435
+ const files: string[] = [];
436
+ for (const file of new Set([...before.keys(), ...after.keys()])) {
437
+ const [a0, r0] = before.get(file) ?? [0, 0];
438
+ const [a1, r1] = after.get(file) ?? [0, 0];
439
+ if (a0 === a1 && r0 === r1) continue;
440
+ added += Math.max(0, a1 - a0);
441
+ removed += Math.max(0, r1 - r0);
442
+ if (files.length < 40) files.push(file);
443
+ }
444
+ return files.length ? { added, removed, files } : undefined;
445
+ }
446
+
447
+ /** The commit checked out in a folder. */
448
+ export async function headSha(path: string): Promise<string> {
449
+ return (await git(path, ['rev-parse', 'HEAD'])).trim();
450
+ }
451
+
452
+ /**
453
+ * Put an archived worker's uncommitted files back into its re-created worktree. They return
454
+ * unstaged. If the branch moved while the worker was archived the snapshot no longer fits, so
455
+ * it is left under its ref for a manual `git restore --source` and nothing is overwritten.
456
+ */
457
+ export async function restoreArchivedFiles(repoRoot: string, ws: Workspace, workerId: string): Promise<void> {
458
+ const ref = archivedWorktreeRef(workerId);
459
+ const parent = await git(repoRoot, ['rev-parse', '--verify', '--quiet', `${ref}^`]).then((s) => s.trim(), () => '');
460
+ if (!parent) return;
461
+ if (parent !== (await git(ws.path, ['rev-parse', 'HEAD'])).trim()) return;
462
+ await git(ws.path, ['restore', `--source=${ref}`, '--worktree', '--', '.']);
463
+ await git(repoRoot, ['update-ref', '-d', ref]);
464
+ }
324
465
 
325
466
  /** A review can inspect tracked changes without staging or reading unrelated untracked files. */
326
467
  export async function reviewDiff(ws: Workspace): Promise<string> {
@@ -0,0 +1,50 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, statSync } from 'node:fs';
4
+ import { dirname, join, posix } from 'node:path';
5
+
6
+ const exec = promisify(execFile);
7
+ const SETUP_TIMEOUT_MS = 15 * 60 * 1000;
8
+
9
+ /** Wildcards are honoured in the file name only: `.env*` and `apps/api/.env.*` work, `**` does not. */
10
+ function matches(repoRoot: string, pattern: string): string[] {
11
+ const clean = posix.normalize(pattern);
12
+ if (clean.startsWith('..') || clean.startsWith('/')) return [];
13
+ const dir = posix.dirname(clean);
14
+ if (/[*?]/.test(dir)) return [];
15
+ const name = new RegExp(`^${posix.basename(clean).replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*').replace(/\?/g, '.')}$`);
16
+ const from = join(repoRoot, dir);
17
+ if (!existsSync(from)) return [];
18
+ return readdirSync(from)
19
+ .filter((entry) => name.test(entry) && statSync(join(from, entry)).isFile())
20
+ .map((entry) => posix.join(dir, entry));
21
+ }
22
+
23
+ /** The files the copy list matches in the repository right now. */
24
+ export function matchedFiles(repoRoot: string, include: string[]): string[] {
25
+ return [...new Set(include.flatMap((pattern) => matches(repoRoot, pattern)))];
26
+ }
27
+
28
+ /** Copy the repository's listed files into the worktree. A file already there is never overwritten. */
29
+ export function copyIncludedFiles(repoRoot: string, worktree: string, include: string[]): string[] {
30
+ const copied: string[] = [];
31
+ for (const file of matchedFiles(repoRoot, include)) {
32
+ const to = join(worktree, file);
33
+ if (existsSync(to)) continue;
34
+ mkdirSync(dirname(to), { recursive: true });
35
+ copyFileSync(join(repoRoot, file), to);
36
+ copied.push(file);
37
+ }
38
+ return copied;
39
+ }
40
+
41
+ /** Run one of the repository's commands (setup or archive) in the worktree. */
42
+ export async function runSetupScript(repoRoot: string, worktree: string, name: string, setup: string, port?: number): Promise<void> {
43
+ await exec('/bin/sh', ['-c', setup], {
44
+ cwd: worktree,
45
+ timeout: SETUP_TIMEOUT_MS,
46
+ maxBuffer: 32 * 1024 * 1024,
47
+ env: { ...process.env, LUCIDITY_ROOT_PATH: repoRoot, LUCIDITY_WORKTREE_PATH: worktree, LUCIDITY_WORKTREE_NAME: name,
48
+ ...(port ? { LUCIDITY_PORT: String(port) } : {}) },
49
+ });
50
+ }