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