@opencorelabs/lucidity 0.7.0 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (502) hide show
  1. package/README.md +9 -2
  2. package/dist/assets/speech/lucidity-speech +0 -0
  3. package/dist/automations/agent.d.ts.map +1 -1
  4. package/dist/automations/agent.js +2 -0
  5. package/dist/automations/designer.d.ts +1 -1
  6. package/dist/automations/service.d.ts +4 -0
  7. package/dist/automations/service.d.ts.map +1 -1
  8. package/dist/automations/service.js +60 -22
  9. package/dist/automations/store.d.ts +9 -3
  10. package/dist/automations/store.d.ts.map +1 -1
  11. package/dist/automations/store.js +45 -32
  12. package/dist/automations/workflow.d.ts +14 -0
  13. package/dist/automations/workflow.d.ts.map +1 -0
  14. package/dist/automations/workflow.js +57 -0
  15. package/dist/chat/server.d.ts +1 -0
  16. package/dist/chat/server.d.ts.map +1 -1
  17. package/dist/chat/server.js +6 -1
  18. package/dist/coding/listPrs.d.ts +2 -0
  19. package/dist/coding/listPrs.d.ts.map +1 -1
  20. package/dist/coding/listPrs.js +10 -0
  21. package/dist/coding/runCodeTurn.d.ts +6 -30
  22. package/dist/coding/runCodeTurn.d.ts.map +1 -1
  23. package/dist/coding/runCodeTurn.js +145 -218
  24. package/dist/coding/runReview.d.ts +10 -0
  25. package/dist/coding/runReview.d.ts.map +1 -0
  26. package/dist/coding/runReview.js +87 -0
  27. package/dist/coding/workspaceRegistry.d.ts +72 -0
  28. package/dist/coding/workspaceRegistry.d.ts.map +1 -0
  29. package/dist/coding/workspaceRegistry.js +421 -0
  30. package/dist/coding/worktree.d.ts +72 -32
  31. package/dist/coding/worktree.d.ts.map +1 -1
  32. package/dist/coding/worktree.js +190 -38
  33. package/dist/coding/worktreeSetup.d.ts +7 -0
  34. package/dist/coding/worktreeSetup.d.ts.map +1 -0
  35. package/dist/coding/worktreeSetup.js +49 -0
  36. package/dist/config.d.ts +2 -0
  37. package/dist/config.d.ts.map +1 -1
  38. package/dist/daemonLease.d.ts +12 -0
  39. package/dist/daemonLease.d.ts.map +1 -0
  40. package/dist/daemonLease.js +32 -0
  41. package/dist/goals/assessment.d.ts +115 -0
  42. package/dist/goals/assessment.d.ts.map +1 -0
  43. package/dist/goals/assessment.js +67 -0
  44. package/dist/goals/notes.d.ts +18 -0
  45. package/dist/goals/notes.d.ts.map +1 -0
  46. package/dist/goals/notes.js +72 -0
  47. package/dist/index.js +75 -40
  48. package/dist/jobs/briefing.d.ts +2 -16
  49. package/dist/jobs/briefing.d.ts.map +1 -1
  50. package/dist/jobs/briefing.js +65 -93
  51. package/dist/jobs/goals.d.ts +15 -0
  52. package/dist/jobs/goals.d.ts.map +1 -0
  53. package/dist/jobs/goals.js +286 -0
  54. package/dist/jobs/weeklyReview.d.ts.map +1 -1
  55. package/dist/jobs/weeklyReview.js +3 -2
  56. package/dist/logTimestamps.d.ts +10 -0
  57. package/dist/logTimestamps.d.ts.map +1 -0
  58. package/dist/logTimestamps.js +12 -0
  59. package/dist/providerRecovery.d.ts +48 -0
  60. package/dist/providerRecovery.d.ts.map +1 -0
  61. package/dist/providerRecovery.js +100 -0
  62. package/dist/queue.d.ts +1 -0
  63. package/dist/queue.d.ts.map +1 -1
  64. package/dist/queue.js +4 -0
  65. package/dist/room/client.d.ts +6 -19
  66. package/dist/room/client.d.ts.map +1 -1
  67. package/dist/room/client.js +127 -123
  68. package/dist/room/computer.js +1 -1
  69. package/dist/room/durablePublish.d.ts +6 -0
  70. package/dist/room/durablePublish.d.ts.map +1 -0
  71. package/dist/room/durablePublish.js +19 -0
  72. package/dist/room/incidents.d.ts +4 -1
  73. package/dist/room/incidents.d.ts.map +1 -1
  74. package/dist/room/incidents.js +15 -7
  75. package/dist/room/turnQueue.d.ts.map +1 -1
  76. package/dist/room/turnQueue.js +55 -46
  77. package/dist/runtimeStore.d.ts +46 -0
  78. package/dist/runtimeStore.d.ts.map +1 -0
  79. package/dist/runtimeStore.js +205 -0
  80. package/dist/setup/server.js +1 -1
  81. package/dist/turnLog.d.ts +10 -40
  82. package/dist/turnLog.d.ts.map +1 -1
  83. package/dist/turnLog.js +33 -56
  84. package/dist/vault.d.ts +6 -3
  85. package/dist/vault.d.ts.map +1 -1
  86. package/dist/vault.js +18 -4
  87. package/package.json +4 -4
  88. package/src/automations/agent.ts +2 -0
  89. package/src/automations/service.ts +47 -21
  90. package/src/automations/store.ts +41 -50
  91. package/src/automations/workflow.ts +49 -0
  92. package/src/chat/server.ts +7 -1
  93. package/src/coding/listPrs.ts +14 -0
  94. package/src/coding/runCodeTurn.ts +51 -139
  95. package/src/coding/runReview.ts +83 -0
  96. package/src/coding/workspaceRegistry.ts +380 -0
  97. package/src/coding/worktree.ts +205 -40
  98. package/src/coding/worktreeSetup.ts +50 -0
  99. package/src/config.ts +2 -0
  100. package/src/daemonLease.ts +33 -0
  101. package/src/goals/assessment.ts +106 -0
  102. package/src/goals/notes.ts +88 -0
  103. package/src/index.ts +76 -46
  104. package/src/jobs/briefing.ts +62 -109
  105. package/src/jobs/goals.ts +384 -0
  106. package/src/jobs/weeklyReview.ts +4 -3
  107. package/src/logTimestamps.ts +14 -0
  108. package/src/providerRecovery.ts +99 -0
  109. package/src/queue.ts +4 -0
  110. package/src/room/client.ts +84 -116
  111. package/src/room/computer.ts +1 -1
  112. package/src/room/durablePublish.ts +25 -0
  113. package/src/room/incidents.ts +20 -8
  114. package/src/room/turnQueue.ts +53 -56
  115. package/src/runtimeStore.ts +207 -0
  116. package/src/setup/server.ts +1 -1
  117. package/src/turnLog.ts +32 -75
  118. package/src/vault.ts +16 -7
  119. package/vendor/mcp-server/dist/index.js +2 -0
  120. package/vendor/mcp-server/dist/tools/goals.d.ts +4 -0
  121. package/vendor/mcp-server/dist/tools/goals.d.ts.map +1 -0
  122. package/vendor/mcp-server/dist/tools/goals.js +38 -0
  123. package/vendor/mcp-server/package.json +1 -1
  124. package/vendor/mcp-server/src/index.ts +2 -0
  125. package/vendor/mcp-server/src/tools/goals.ts +62 -0
  126. package/vendor/runtime/README.md +36 -2
  127. package/vendor/runtime/dist/executor/asyncQueue.d.ts +1 -0
  128. package/vendor/runtime/dist/executor/asyncQueue.d.ts.map +1 -1
  129. package/vendor/runtime/dist/executor/asyncQueue.js +3 -0
  130. package/vendor/runtime/dist/executor/claudeAgent.d.ts +5 -1
  131. package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
  132. package/vendor/runtime/dist/executor/claudeAgent.js +77 -13
  133. package/vendor/runtime/dist/executor/codex.d.ts +8 -2
  134. package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
  135. package/vendor/runtime/dist/executor/codex.js +113 -38
  136. package/vendor/runtime/dist/executor/codexProtocol/AgentPath.d.ts +2 -0
  137. package/vendor/runtime/dist/executor/codexProtocol/AgentPath.d.ts.map +1 -0
  138. package/vendor/runtime/dist/executor/codexProtocol/AgentPath.js +2 -0
  139. package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts +4 -1
  140. package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts.map +1 -1
  141. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.d.ts +6 -0
  142. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.d.ts.map +1 -0
  143. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationFailure.js +2 -0
  144. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.d.ts +12 -0
  145. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.d.ts.map +1 -0
  146. package/vendor/runtime/dist/executor/codexProtocol/ImageGenerationItem.js +2 -0
  147. package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.d.ts +24 -0
  148. package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.d.ts.map +1 -0
  149. package/vendor/runtime/dist/executor/codexProtocol/LegacyAppPathString.js +2 -0
  150. package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.d.ts +8 -0
  151. package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.d.ts.map +1 -0
  152. package/vendor/runtime/dist/executor/codexProtocol/MessagePhase.js +2 -0
  153. package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts +3 -0
  154. package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts.map +1 -1
  155. package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts +1 -1
  156. package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts.map +1 -1
  157. package/vendor/runtime/dist/executor/codexProtocol/SleepItem.d.ts +8 -0
  158. package/vendor/runtime/dist/executor/codexProtocol/SleepItem.d.ts.map +1 -0
  159. package/vendor/runtime/dist/executor/codexProtocol/SleepItem.js +2 -0
  160. package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.d.ts +14 -0
  161. package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.d.ts.map +1 -0
  162. package/vendor/runtime/dist/executor/codexProtocol/SubAgentSource.js +2 -0
  163. package/vendor/runtime/dist/executor/codexProtocol/ThreadId.d.ts +7 -0
  164. package/vendor/runtime/dist/executor/codexProtocol/ThreadId.d.ts.map +1 -0
  165. package/vendor/runtime/dist/executor/codexProtocol/ThreadId.js +2 -0
  166. package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.d.ts +15 -0
  167. package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.d.ts.map +1 -0
  168. package/vendor/runtime/dist/executor/codexProtocol/WebSearchItem.js +2 -0
  169. package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.d.ts +2 -0
  170. package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.d.ts.map +1 -0
  171. package/vendor/runtime/dist/executor/codexProtocol/v2/AgentMessageDelivery.js +2 -0
  172. package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.d.ts +5 -0
  173. package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.d.ts.map +1 -0
  174. package/vendor/runtime/dist/executor/codexProtocol/v2/AsyncUserInputQuestion.js +2 -0
  175. package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.d.ts +29 -0
  176. package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.d.ts.map +1 -0
  177. package/vendor/runtime/dist/executor/codexProtocol/v2/CodexErrorInfo.js +2 -0
  178. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.d.ts +6 -0
  179. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.d.ts.map +1 -0
  180. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentState.js +2 -0
  181. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.d.ts +2 -0
  182. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.d.ts.map +1 -0
  183. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentStatus.js +2 -0
  184. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.d.ts +2 -0
  185. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.d.ts.map +1 -0
  186. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentTool.js +2 -0
  187. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.d.ts +2 -0
  188. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.d.ts.map +1 -0
  189. package/vendor/runtime/dist/executor/codexProtocol/v2/CollabAgentToolCallStatus.js +2 -0
  190. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.d.ts +20 -0
  191. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.d.ts.map +1 -0
  192. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandAction.js +2 -0
  193. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.d.ts +2 -0
  194. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.d.ts.map +1 -0
  195. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionSource.js +2 -0
  196. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.d.ts +2 -0
  197. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.d.ts.map +1 -0
  198. package/vendor/runtime/dist/executor/codexProtocol/v2/CommandExecutionStatus.js +2 -0
  199. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts +6 -0
  200. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts.map +1 -0
  201. package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.js +2 -0
  202. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.d.ts +11 -0
  203. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.d.ts.map +1 -0
  204. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.js +2 -0
  205. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.d.ts +2 -0
  206. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.d.ts.map +1 -0
  207. package/vendor/runtime/dist/executor/codexProtocol/v2/DynamicToolCallStatus.js +2 -0
  208. package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.d.ts +7 -0
  209. package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.d.ts.map +1 -0
  210. package/vendor/runtime/dist/executor/codexProtocol/v2/FileUpdateChange.js +2 -0
  211. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts +5 -0
  212. package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts.map +1 -1
  213. package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.d.ts +6 -0
  214. package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.d.ts.map +1 -0
  215. package/vendor/runtime/dist/executor/codexProtocol/v2/GitInfo.js +2 -0
  216. package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.d.ts +5 -0
  217. package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.d.ts.map +1 -0
  218. package/vendor/runtime/dist/executor/codexProtocol/v2/HookPromptFragment.js +2 -0
  219. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.d.ts +2 -0
  220. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.d.ts.map +1 -0
  221. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppDisplayMode.js +2 -0
  222. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.d.ts +9 -0
  223. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.d.ts.map +1 -0
  224. package/vendor/runtime/dist/executor/codexProtocol/v2/McpAppUi.js +2 -0
  225. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.d.ts +8 -0
  226. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.d.ts.map +1 -0
  227. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallAppContext.js +2 -0
  228. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.d.ts +4 -0
  229. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.d.ts.map +1 -0
  230. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallError.js +2 -0
  231. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.d.ts +7 -0
  232. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.d.ts.map +1 -0
  233. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallResult.js +2 -0
  234. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.d.ts +2 -0
  235. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.d.ts.map +1 -0
  236. package/vendor/runtime/dist/executor/codexProtocol/v2/McpToolCallStatus.js +2 -0
  237. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.d.ts +6 -0
  238. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.d.ts.map +1 -0
  239. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitation.js +2 -0
  240. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.d.ts +7 -0
  241. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.d.ts.map +1 -0
  242. package/vendor/runtime/dist/executor/codexProtocol/v2/MemoryCitationEntry.js +2 -0
  243. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.d.ts +16 -0
  244. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.d.ts.map +1 -0
  245. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentErrorDetails.js +2 -0
  246. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.d.ts +4 -0
  247. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.d.ts.map +1 -0
  248. package/vendor/runtime/dist/executor/codexProtocol/v2/MisalignmentSteer.js +2 -0
  249. package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts +8 -0
  250. package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts.map +1 -1
  251. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts +11 -0
  252. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts.map +1 -0
  253. package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.js +2 -0
  254. package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.d.ts +2 -0
  255. package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.d.ts.map +1 -0
  256. package/vendor/runtime/dist/executor/codexProtocol/v2/NonSteerableTurnKind.js +2 -0
  257. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.d.ts +2 -0
  258. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.d.ts.map +1 -0
  259. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchApplyStatus.js +2 -0
  260. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.d.ts +9 -0
  261. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.d.ts.map +1 -0
  262. package/vendor/runtime/dist/executor/codexProtocol/v2/PatchChangeKind.js +2 -0
  263. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts +4 -0
  264. package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts.map +1 -1
  265. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts +2 -0
  266. package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts.map +1 -1
  267. package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.d.ts +7 -0
  268. package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.d.ts.map +1 -0
  269. package/vendor/runtime/dist/executor/codexProtocol/v2/SessionSource.js +2 -0
  270. package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.d.ts +2 -0
  271. package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.d.ts.map +1 -0
  272. package/vendor/runtime/dist/executor/codexProtocol/v2/SubAgentActivityKind.js +2 -0
  273. package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.d.ts +100 -0
  274. package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.d.ts.map +1 -0
  275. package/vendor/runtime/dist/executor/codexProtocol/v2/Thread.js +2 -0
  276. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.d.ts +2 -0
  277. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.d.ts.map +1 -0
  278. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadActiveFlag.js +2 -0
  279. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.d.ts +2 -0
  280. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.d.ts.map +1 -0
  281. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadHistoryMode.js +2 -0
  282. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.d.ts +216 -0
  283. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.d.ts.map +1 -0
  284. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadItem.js +2 -0
  285. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.d.ts +11 -0
  286. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.d.ts.map +1 -0
  287. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadParams.js +2 -0
  288. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.d.ts +5 -0
  289. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.d.ts.map +1 -0
  290. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadReadResponse.js +2 -0
  291. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts +4 -1
  292. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts.map +1 -1
  293. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.d.ts +19 -0
  294. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.d.ts.map +1 -0
  295. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSection.js +2 -0
  296. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.d.ts +8 -0
  297. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.d.ts.map +1 -0
  298. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadSectionAppearance.js +2 -0
  299. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts +3 -1
  300. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts.map +1 -1
  301. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.d.ts +12 -0
  302. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.d.ts.map +1 -0
  303. package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStatus.js +2 -0
  304. package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.d.ts +36 -0
  305. package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.d.ts.map +1 -0
  306. package/vendor/runtime/dist/executor/codexProtocol/v2/Turn.js +2 -0
  307. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.d.ts +12 -0
  308. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.d.ts.map +1 -0
  309. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnError.js +2 -0
  310. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.d.ts +2 -0
  311. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.d.ts.map +1 -0
  312. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnItemsView.js +2 -0
  313. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts +7 -2
  314. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts.map +1 -1
  315. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.d.ts +2 -0
  316. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.d.ts.map +1 -0
  317. package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStatus.js +2 -0
  318. package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts +3 -0
  319. package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts.map +1 -1
  320. package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.d.ts +15 -0
  321. package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.d.ts.map +1 -0
  322. package/vendor/runtime/dist/executor/codexProtocol/v2/WebSearchAction.js +2 -0
  323. package/vendor/runtime/dist/executor/codexRpc.d.ts +13 -4
  324. package/vendor/runtime/dist/executor/codexRpc.d.ts.map +1 -1
  325. package/vendor/runtime/dist/executor/codexRpc.js +21 -5
  326. package/vendor/runtime/dist/executor/codexSessions.d.ts +30 -0
  327. package/vendor/runtime/dist/executor/codexSessions.d.ts.map +1 -0
  328. package/vendor/runtime/dist/executor/codexSessions.js +88 -0
  329. package/vendor/runtime/dist/executor/health.d.ts +8 -2
  330. package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
  331. package/vendor/runtime/dist/executor/health.js +21 -5
  332. package/vendor/runtime/dist/executor/liveTurns.d.ts +2 -1
  333. package/vendor/runtime/dist/executor/liveTurns.d.ts.map +1 -1
  334. package/vendor/runtime/dist/executor/liveTurns.js +12 -5
  335. package/vendor/runtime/dist/executor/ownership.d.ts +40 -0
  336. package/vendor/runtime/dist/executor/ownership.d.ts.map +1 -0
  337. package/vendor/runtime/dist/executor/ownership.js +106 -0
  338. package/vendor/runtime/dist/executor/providerRouter.d.ts +1 -0
  339. package/vendor/runtime/dist/executor/providerRouter.d.ts.map +1 -1
  340. package/vendor/runtime/dist/executor/providerRouter.js +5 -0
  341. package/vendor/runtime/dist/executor/types.d.ts +27 -0
  342. package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
  343. package/vendor/runtime/dist/harness/index.d.ts.map +1 -1
  344. package/vendor/runtime/dist/harness/index.js +1 -0
  345. package/vendor/runtime/dist/index.d.ts +2 -1
  346. package/vendor/runtime/dist/index.d.ts.map +1 -1
  347. package/vendor/runtime/dist/index.js +1 -0
  348. package/vendor/runtime/src/executor/asyncQueue.ts +3 -0
  349. package/vendor/runtime/src/executor/claudeAgent.ts +66 -13
  350. package/vendor/runtime/src/executor/codex.ts +124 -47
  351. package/vendor/runtime/src/executor/codexProtocol/AgentPath.ts +5 -0
  352. package/vendor/runtime/src/executor/codexProtocol/FunctionCallOutputContentItem.ts +1 -1
  353. package/vendor/runtime/src/executor/codexProtocol/ImageGenerationFailure.ts +5 -0
  354. package/vendor/runtime/src/executor/codexProtocol/ImageGenerationItem.ts +7 -0
  355. package/vendor/runtime/src/executor/codexProtocol/LegacyAppPathString.ts +27 -0
  356. package/vendor/runtime/src/executor/codexProtocol/MessagePhase.ts +11 -0
  357. package/vendor/runtime/src/executor/codexProtocol/Personality.ts +3 -0
  358. package/vendor/runtime/src/executor/codexProtocol/PlanType.ts +1 -1
  359. package/vendor/runtime/src/executor/codexProtocol/README.md +2 -2
  360. package/vendor/runtime/src/executor/codexProtocol/SleepItem.ts +8 -0
  361. package/vendor/runtime/src/executor/codexProtocol/SubAgentSource.ts +7 -0
  362. package/vendor/runtime/src/executor/codexProtocol/ThreadId.ts +10 -0
  363. package/vendor/runtime/src/executor/codexProtocol/WebSearchItem.ts +14 -0
  364. package/vendor/runtime/src/executor/codexProtocol/v2/AgentMessageDelivery.ts +5 -0
  365. package/vendor/runtime/src/executor/codexProtocol/v2/AsyncUserInputQuestion.ts +5 -0
  366. package/vendor/runtime/src/executor/codexProtocol/v2/CodexErrorInfo.ts +12 -0
  367. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentState.ts +6 -0
  368. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentStatus.ts +5 -0
  369. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentTool.ts +5 -0
  370. package/vendor/runtime/src/executor/codexProtocol/v2/CollabAgentToolCallStatus.ts +5 -0
  371. package/vendor/runtime/src/executor/codexProtocol/v2/CommandAction.ts +6 -0
  372. package/vendor/runtime/src/executor/codexProtocol/v2/CommandExecutionSource.ts +5 -0
  373. package/vendor/runtime/src/executor/codexProtocol/v2/CommandExecutionStatus.ts +5 -0
  374. package/vendor/runtime/src/executor/codexProtocol/v2/CyberAccessProgram.ts +9 -0
  375. package/vendor/runtime/src/executor/codexProtocol/v2/DynamicToolCallOutputContentItem.ts +5 -0
  376. package/vendor/runtime/src/executor/codexProtocol/v2/DynamicToolCallStatus.ts +5 -0
  377. package/vendor/runtime/src/executor/codexProtocol/v2/FileUpdateChange.ts +6 -0
  378. package/vendor/runtime/src/executor/codexProtocol/v2/GetAccountRateLimitsResponse.ts +5 -0
  379. package/vendor/runtime/src/executor/codexProtocol/v2/GitInfo.ts +5 -0
  380. package/vendor/runtime/src/executor/codexProtocol/v2/HookPromptFragment.ts +5 -0
  381. package/vendor/runtime/src/executor/codexProtocol/v2/McpAppDisplayMode.ts +5 -0
  382. package/vendor/runtime/src/executor/codexProtocol/v2/McpAppUi.ts +9 -0
  383. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallAppContext.ts +5 -0
  384. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallError.ts +5 -0
  385. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallResult.ts +6 -0
  386. package/vendor/runtime/src/executor/codexProtocol/v2/McpToolCallStatus.ts +5 -0
  387. package/vendor/runtime/src/executor/codexProtocol/v2/MemoryCitation.ts +6 -0
  388. package/vendor/runtime/src/executor/codexProtocol/v2/MemoryCitationEntry.ts +5 -0
  389. package/vendor/runtime/src/executor/codexProtocol/v2/MisalignmentErrorDetails.ts +18 -0
  390. package/vendor/runtime/src/executor/codexProtocol/v2/MisalignmentSteer.ts +5 -0
  391. package/vendor/runtime/src/executor/codexProtocol/v2/Model.ts +11 -2
  392. package/vendor/runtime/src/executor/codexProtocol/v2/ModelAccessPrograms.ts +13 -0
  393. package/vendor/runtime/src/executor/codexProtocol/v2/NonSteerableTurnKind.ts +5 -0
  394. package/vendor/runtime/src/executor/codexProtocol/v2/PatchApplyStatus.ts +5 -0
  395. package/vendor/runtime/src/executor/codexProtocol/v2/PatchChangeKind.ts +5 -0
  396. package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitSnapshot.ts +5 -1
  397. package/vendor/runtime/src/executor/codexProtocol/v2/ReviewStartParams.ts +2 -0
  398. package/vendor/runtime/src/executor/codexProtocol/v2/SessionSource.ts +6 -0
  399. package/vendor/runtime/src/executor/codexProtocol/v2/SubAgentActivityKind.ts +5 -0
  400. package/vendor/runtime/src/executor/codexProtocol/v2/Thread.ts +104 -0
  401. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadActiveFlag.ts +5 -0
  402. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadHistoryMode.ts +5 -0
  403. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadItem.ts +125 -0
  404. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadReadParams.ts +12 -0
  405. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadReadResponse.ts +6 -0
  406. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadResumeParams.ts +5 -1
  407. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSection.ts +21 -0
  408. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadSectionAppearance.ts +8 -0
  409. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStartParams.ts +4 -1
  410. package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStatus.ts +6 -0
  411. package/vendor/runtime/src/executor/codexProtocol/v2/Turn.ts +37 -0
  412. package/vendor/runtime/src/executor/codexProtocol/v2/TurnError.ts +11 -0
  413. package/vendor/runtime/src/executor/codexProtocol/v2/TurnItemsView.ts +5 -0
  414. package/vendor/runtime/src/executor/codexProtocol/v2/TurnStartParams.ts +7 -2
  415. package/vendor/runtime/src/executor/codexProtocol/v2/TurnStatus.ts +5 -0
  416. package/vendor/runtime/src/executor/codexProtocol/v2/UserInput.ts +1 -1
  417. package/vendor/runtime/src/executor/codexProtocol/v2/WebSearchAction.ts +5 -0
  418. package/vendor/runtime/src/executor/codexRpc.ts +26 -6
  419. package/vendor/runtime/src/executor/codexSessions.ts +108 -0
  420. package/vendor/runtime/src/executor/health.ts +21 -7
  421. package/vendor/runtime/src/executor/liveTurns.ts +12 -5
  422. package/vendor/runtime/src/executor/ownership.ts +83 -0
  423. package/vendor/runtime/src/executor/providerRouter.ts +6 -0
  424. package/vendor/runtime/src/executor/types.ts +20 -1
  425. package/vendor/runtime/src/harness/index.ts +1 -0
  426. package/vendor/runtime/src/index.ts +2 -1
  427. package/vendor/shared/dist/agentCommands.d.ts +1 -0
  428. package/vendor/shared/dist/agentCommands.d.ts.map +1 -1
  429. package/vendor/shared/dist/automations.d.ts +34 -0
  430. package/vendor/shared/dist/automations.d.ts.map +1 -1
  431. package/vendor/shared/dist/automations.js +12 -0
  432. package/vendor/shared/dist/cardStudio.d.ts +41 -0
  433. package/vendor/shared/dist/cardStudio.d.ts.map +1 -1
  434. package/vendor/shared/dist/cardStudio.js +13 -3
  435. package/vendor/shared/dist/computer.d.ts +7 -1
  436. package/vendor/shared/dist/computer.d.ts.map +1 -1
  437. package/vendor/shared/dist/computer.js +13 -4
  438. package/vendor/shared/dist/constants.d.ts +3 -3
  439. package/vendor/shared/dist/constants.d.ts.map +1 -1
  440. package/vendor/shared/dist/constants.js +8 -14
  441. package/vendor/shared/dist/goalNotes.d.ts +4 -0
  442. package/vendor/shared/dist/goalNotes.d.ts.map +1 -0
  443. package/vendor/shared/dist/goalNotes.js +23 -0
  444. package/vendor/shared/dist/goals.d.ts +835 -0
  445. package/vendor/shared/dist/goals.d.ts.map +1 -0
  446. package/vendor/shared/dist/goals.js +198 -0
  447. package/vendor/shared/dist/index.d.ts +7 -2
  448. package/vendor/shared/dist/index.d.ts.map +1 -1
  449. package/vendor/shared/dist/index.js +6 -1
  450. package/vendor/shared/dist/journal-vault.d.ts +1 -1
  451. package/vendor/shared/dist/messagingSafety.d.ts +21 -0
  452. package/vendor/shared/dist/messagingSafety.d.ts.map +1 -0
  453. package/vendor/shared/dist/messagingSafety.js +8 -0
  454. package/vendor/shared/dist/schemas/harness.d.ts +199 -169
  455. package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
  456. package/vendor/shared/dist/schemas/harness.js +25 -124
  457. package/vendor/shared/dist/smartCapture.d.ts +24 -0
  458. package/vendor/shared/dist/smartCapture.d.ts.map +1 -1
  459. package/vendor/shared/dist/smartCapture.js +15 -0
  460. package/vendor/shared/dist/taskSync.d.ts +342 -0
  461. package/vendor/shared/dist/taskSync.d.ts.map +1 -0
  462. package/vendor/shared/dist/taskSync.js +111 -0
  463. package/vendor/shared/dist/types.d.ts +1 -4
  464. package/vendor/shared/dist/types.d.ts.map +1 -1
  465. package/vendor/shared/dist/voiceCapture.d.ts +1 -1
  466. package/vendor/shared/dist/workspaces.d.ts +255 -0
  467. package/vendor/shared/dist/workspaces.d.ts.map +1 -0
  468. package/vendor/shared/dist/workspaces.js +89 -0
  469. package/vendor/shared/src/agentCommands.ts +1 -0
  470. package/vendor/shared/src/automations.ts +12 -0
  471. package/vendor/shared/src/cardStudio.ts +13 -3
  472. package/vendor/shared/src/computer.ts +19 -5
  473. package/vendor/shared/src/constants.ts +8 -14
  474. package/vendor/shared/src/goalNotes.ts +23 -0
  475. package/vendor/shared/src/goals.ts +237 -0
  476. package/vendor/shared/src/index.ts +7 -6
  477. package/vendor/shared/src/messagingSafety.ts +11 -0
  478. package/vendor/shared/src/schemas/harness.ts +24 -130
  479. package/vendor/shared/src/smartCapture.ts +27 -0
  480. package/vendor/shared/src/taskSync.ts +81 -0
  481. package/vendor/shared/src/types.ts +0 -6
  482. package/vendor/shared/src/workspaces.ts +103 -0
  483. package/dist/coding/conduct.d.ts +0 -69
  484. package/dist/coding/conduct.d.ts.map +0 -1
  485. package/dist/coding/conduct.js +0 -348
  486. package/dist/coding/fleetIntegrate.d.ts +0 -37
  487. package/dist/coding/fleetIntegrate.d.ts.map +0 -1
  488. package/dist/coding/fleetIntegrate.js +0 -64
  489. package/dist/coding/fleetPlan.d.ts +0 -20
  490. package/dist/coding/fleetPlan.d.ts.map +0 -1
  491. package/dist/coding/fleetPlan.js +0 -125
  492. package/dist/coding/fleetTasks.d.ts +0 -33
  493. package/dist/coding/fleetTasks.d.ts.map +0 -1
  494. package/dist/coding/fleetTasks.js +0 -75
  495. package/dist/coding/openFleetPr.d.ts +0 -41
  496. package/dist/coding/openFleetPr.d.ts.map +0 -1
  497. package/dist/coding/openFleetPr.js +0 -121
  498. package/src/coding/conduct.ts +0 -462
  499. package/src/coding/fleetIntegrate.ts +0 -95
  500. package/src/coding/fleetPlan.ts +0 -135
  501. package/src/coding/fleetTasks.ts +0 -109
  502. package/src/coding/openFleetPr.ts +0 -148
@@ -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
 
@@ -70,6 +66,30 @@ export async function currentBranch(repoRoot: string): Promise<string> {
70
66
  return (await git(repoRoot, ['rev-parse', '--abbrev-ref', 'HEAD'])).trim();
71
67
  }
72
68
 
69
+ export async function workspaceBranchExists(repoRoot: string, repoId: string, workerId?: string): Promise<boolean> {
70
+ return git(repoRoot, ['show-ref', '--verify', `refs/heads/${sessionBranch(repoId, workerId)}`]).then(() => true, () => false);
71
+ }
72
+
73
+ /** Resolve the fetched remote base without changing the existing checkout. */
74
+ export async function workspaceBase(repoRoot: string, configured?: string): Promise<{ ref: string; sha: string }> {
75
+ const remotes = (await git(repoRoot, ['remote'])).trim().split('\n');
76
+ if (!remotes.includes('origin')) {
77
+ if (configured) throw new Error('The configured workspace base requires an origin remote.');
78
+ return { ref: 'HEAD', sha: (await git(repoRoot, ['rev-parse', 'HEAD'])).trim() };
79
+ }
80
+ await git(repoRoot, ['fetch', 'origin']);
81
+ let ref = configured;
82
+ if (!ref) {
83
+ const remoteHead = await git(repoRoot, ['ls-remote', '--symref', 'origin', 'HEAD']);
84
+ const branch = /^ref: refs\/heads\/(.+)\s+HEAD$/m.exec(remoteHead)?.[1];
85
+ if (!branch) throw new Error('Could not resolve the remote default branch. Set this repository\'s baseRef.');
86
+ ref = `origin/${branch}`;
87
+ }
88
+ if (!ref.startsWith('origin/')) ref = `origin/${ref}`;
89
+ const sha = (await git(repoRoot, ['rev-parse', '--verify', '--end-of-options', `${ref}^{commit}`])).trim();
90
+ return { ref, sha };
91
+ }
92
+
73
93
  /**
74
94
  * How many commits this worktree's HEAD carries that `base` doesn't.
75
95
  *
@@ -138,30 +158,17 @@ export async function repoWebUrl(repoRoot: string): Promise<string | undefined>
138
158
  return githubWebUrlFromRemote(raw);
139
159
  }
140
160
 
141
- /**
142
- * Prepare the workspace for a coding turn.
143
- *
144
- * `worktree` (default): ensure the persistent worktree for this repo's session exists
145
- * on its `lucid/<repoId>` branch, at a STABLE path so Claude Code's `--resume` resolves
146
- * across turns. `fresh: true` (a new session — no resume) resets the branch and worktree
147
- * to HEAD, discarding any prior session's state. Otherwise the existing worktree is
148
- * reused as-is so prior turns' commits (files) carry forward; if it's missing (first
149
- * turn, or pruned), it's created off HEAD.
150
- *
151
- * `in-place` (#121): the user's own checkout, on its live branch, uncommitted work and
152
- * all — the point of the mode is that Lucid continues from where the user left off, so
153
- * `fresh` resets NOTHING here. It would mean discarding their work.
154
- */
161
+ /** Resolve a persistent workspace. Provider session changes never reset its files. */
155
162
  export async function ensureWorkspace(
156
163
  repoRoot: string,
157
164
  repoId: string,
158
165
  opts: {
159
166
  mode?: WorkspaceMode;
167
+ /** Legacy callers may pass this; conversation resets never reset a workspace. */
160
168
  fresh?: boolean;
169
+ startPoint?: string;
161
170
  baseDir?: string;
162
- /** Conductor worker id (the fleet subtask's id). Present → an isolated per-worker
163
- * worktree/branch so N workers run in parallel on one repo. Absent → the classic
164
- * single session, unchanged. */
171
+ /** Present → that worktree's own folder and branch. Absent → the main session. */
165
172
  workerId?: string;
166
173
  } = {},
167
174
  ): Promise<Workspace> {
@@ -175,12 +182,15 @@ export async function ensureWorkspace(
175
182
  const path = sessionWorktreePath(repoId, baseDir, opts.workerId);
176
183
  mkdirSync(baseDir, { recursive: true });
177
184
 
178
- const present = existsSync(path);
179
- if (present && !opts.fresh) return { path, branch, mode }; // reuse (resume) — files carry forward
180
-
181
- if (present) await removeWorktree(repoRoot, { path, branch, mode }, { keepBranch: false }); // fresh: wipe old session
182
- // (Re)create the branch + worktree at the stable path off HEAD.
183
- await git(repoRoot, ['worktree', 'add', '-B', branch, path, 'HEAD']);
185
+ if (existsSync(path)) {
186
+ return { path, branch: await currentBranch(path), mode };
187
+ }
188
+ // Recover branches left behind by the old automatic delivery path.
189
+ const existing = await git(repoRoot, ['show-ref', '--verify', `refs/heads/${branch}`])
190
+ .then(() => true, () => false);
191
+ await git(repoRoot, existing
192
+ ? ['worktree', 'add', path, branch]
193
+ : ['worktree', 'add', '-b', branch, path, opts.startPoint ?? 'HEAD']);
184
194
  return { path, branch, mode };
185
195
  }
186
196
 
@@ -304,3 +314,158 @@ export async function removeWorktree(
304
314
  }
305
315
  }
306
316
  }
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
+ }
465
+
466
+ /** A review can inspect tracked changes without staging or reading unrelated untracked files. */
467
+ export async function reviewDiff(ws: Workspace): Promise<string> {
468
+ const diff = await git(ws.path, ['diff', '--no-ext-diff', '--no-textconv', 'HEAD', '--']);
469
+ const limit = 80_000;
470
+ return diff.length > limit ? diff.slice(0, limit) + '\n[Diff truncated. Read the relevant files for the rest.]' : diff;
471
+ }
@@ -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
+ }
package/src/config.ts CHANGED
@@ -44,6 +44,8 @@ export const VOICE_DIAG_DIR = join(CONFIG_DIR, 'voice-diag');
44
44
 
45
45
  /** An allowlisted repo Lucid may code in (M7). The phone sends the `id`, never a path. */
46
46
  export interface RepoEntry {
47
+ /** Remote base for new workers, e.g. origin/main; defaults to origin's HEAD. */
48
+ baseRef?: string;
47
49
  /** Short name the phone selects, e.g. `"lucidity"`. */
48
50
  id: string;
49
51
  /** Absolute path to the repo on this machine. `~` expands. */
@@ -0,0 +1,33 @@
1
+ // @ts-expect-error Node 22 runtime API; the repository's Node type baseline is 20.
2
+ import { DatabaseSync } from 'node:sqlite';
3
+ import { chmodSync, mkdirSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ import { randomUUID } from 'node:crypto';
6
+
7
+ /** The OS releases this lock on exit, including a crash. Never unlink its database. */
8
+ export class DaemonLease {
9
+ readonly owner = { epoch: randomUUID(), pid: process.pid, startedAt: new Date().toISOString() };
10
+ private db: any;
11
+
12
+ constructor(directory: string) {
13
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
14
+ const path = join(directory, 'daemon-owner.sqlite');
15
+ const db = new DatabaseSync(path);
16
+ try {
17
+ chmodSync(path, 0o600);
18
+ db.exec('PRAGMA busy_timeout=0; BEGIN EXCLUSIVE;');
19
+ this.db = db;
20
+ } catch (error) {
21
+ db.close();
22
+ if ((error as { errcode?: number }).errcode === 5)
23
+ throw new Error('Lucidity is already running for this configuration. Stop that daemon before starting another.');
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ close(): void {
29
+ if (!this.db) return;
30
+ this.db.close();
31
+ this.db = undefined;
32
+ }
33
+ }
@@ -0,0 +1,106 @@
1
+ import {
2
+ goalReferenceKey,
3
+ type GoalCandidate,
4
+ type GoalCheck,
5
+ type GoalDetail,
6
+ type GoalEvidence,
7
+ } from '@lucidity/shared';
8
+
9
+ function bounded<T>(items: T[], characters: number, count: number): T[] {
10
+ const result: T[] = [];
11
+ let used = 2;
12
+ for (const item of items) {
13
+ const size = JSON.stringify(item).length + 1;
14
+ if (result.length >= count || used + size > characters) break;
15
+ result.push(item);
16
+ used += size;
17
+ }
18
+ return result;
19
+ }
20
+
21
+ /** Keep stored evidence intact; send a bounded, explicitly partial view to the model. */
22
+ export function goalAssessmentInput(input: {
23
+ detail: GoalDetail;
24
+ period: Pick<GoalCheck, 'cadence' | 'key' | 'start' | 'end'>;
25
+ sources: GoalCandidate[];
26
+ evidence: GoalEvidence[];
27
+ complete: boolean;
28
+ }) {
29
+ const { detail, period, complete } = input;
30
+ const direct = new Set(
31
+ detail.links
32
+ .filter((link) => link.state === 'active')
33
+ .map(goalReferenceKey),
34
+ );
35
+ const dated = new Set(
36
+ input.evidence.map((item) => goalReferenceKey(item.reference)),
37
+ );
38
+ const priority = (source: GoalCandidate) =>
39
+ direct.has(goalReferenceKey(source))
40
+ ? 0
41
+ : dated.has(goalReferenceKey(source))
42
+ ? 1
43
+ : 2;
44
+ const sources = bounded(
45
+ [...input.sources]
46
+ .sort(
47
+ (a, b) =>
48
+ priority(a) - priority(b) ||
49
+ (b.updatedAt ?? '').localeCompare(a.updatedAt ?? ''),
50
+ )
51
+ .map((source) => ({
52
+ ...source,
53
+ title: source.title.slice(0, 240),
54
+ description: source.description?.slice(0, 600) ?? null,
55
+ })),
56
+ 30_000,
57
+ 100,
58
+ );
59
+ const evidence = bounded(
60
+ [...input.evidence]
61
+ .sort((a, b) => b.at.localeCompare(a.at))
62
+ .map((item) => ({ ...item, title: item.title?.slice(0, 240) ?? null })),
63
+ 15_000,
64
+ 100,
65
+ );
66
+ const priorChecks = bounded(
67
+ detail.checks.slice(0, 14).map((check) => ({
68
+ key: check.key,
69
+ cadence: check.cadence,
70
+ start: check.start,
71
+ end: check.end,
72
+ signal: check.signal,
73
+ summary: check.summary.slice(0, 400),
74
+ timeframe: check.timeframe,
75
+ })),
76
+ 6_000,
77
+ 14,
78
+ );
79
+ const allNotes = detail.links.filter(
80
+ (link) => link.kind === 'note' && link.state === 'active',
81
+ );
82
+ const notes = bounded(
83
+ allNotes.map(({ kind, id }) => ({ kind, id })),
84
+ 3_000,
85
+ 40,
86
+ );
87
+ return {
88
+ goal: detail.goal,
89
+ period,
90
+ sources,
91
+ notes,
92
+ evidence,
93
+ priorChecks,
94
+ complete,
95
+ coverage: {
96
+ sources: { provided: sources.length, total: input.sources.length },
97
+ evidence: { provided: evidence.length, total: input.evidence.length },
98
+ priorChecks: {
99
+ provided: priorChecks.length,
100
+ total: detail.checks.length,
101
+ },
102
+ notes: { provided: notes.length, total: allNotes.length },
103
+ descriptionsAreExcerpts: true,
104
+ },
105
+ };
106
+ }
@@ -0,0 +1,88 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { listNotes, readNote, editNote, writeNote } from '@lucidity/notes';
3
+ import {
4
+ goalNoteId,
5
+ withGoalNoteId,
6
+ type GoalCandidate,
7
+ } from '@lucidity/shared';
8
+
9
+ export interface GoalNote extends GoalCandidate {
10
+ kind: 'note';
11
+ path: string;
12
+ content: string;
13
+ }
14
+ export interface GoalNotes {
15
+ list(): { notes: GoalNote[]; complete: boolean };
16
+ link(note: GoalNote): void;
17
+ read(id: string): GoalNote;
18
+ saveDraft(id: string, markdown: string): void;
19
+ }
20
+
21
+ /** Paths and note text never leave this computer for the hosted Goals API. */
22
+ export function createGoalNotes(
23
+ root: string | undefined,
24
+ ): GoalNotes | undefined {
25
+ if (!root) return undefined;
26
+ function scan() {
27
+ const summaries = listNotes(root!, { limit: 2001 });
28
+ const notes: GoalNote[] = [];
29
+ let complete = summaries.length <= 2000;
30
+ for (const summary of summaries.slice(0, 2000)) {
31
+ try {
32
+ const note = readNote(root!, summary.path);
33
+ notes.push({
34
+ kind: 'note',
35
+ id: goalNoteId(note.content) ?? randomUUID(),
36
+ path: note.path,
37
+ content: note.content,
38
+ title: note.title,
39
+ description: note.body.slice(0, 2000),
40
+ updatedAt: note.mtime,
41
+ status: null,
42
+ projectId: null,
43
+ });
44
+ } catch {
45
+ complete = false;
46
+ }
47
+ }
48
+ const counts = new Map<string, number>();
49
+ notes.forEach((note) =>
50
+ counts.set(note.id, (counts.get(note.id) ?? 0) + 1),
51
+ );
52
+ if ([...counts.values()].some((count) => count > 1)) complete = false;
53
+ return {
54
+ notes: notes.filter((note) => counts.get(note.id) === 1),
55
+ complete,
56
+ };
57
+ }
58
+ return {
59
+ list: scan,
60
+ link(note) {
61
+ const current = readNote(root, note.path);
62
+ if (current.content !== note.content)
63
+ throw new Error('The note changed during linking. Try again.');
64
+ const next = withGoalNoteId(current.content, note.id);
65
+ if (next !== current.content) {
66
+ if (!current.content)
67
+ throw new Error('Write something in this note before linking it.');
68
+ editNote(root, note.path, current.content, next);
69
+ }
70
+ },
71
+ read(id) {
72
+ const note = scan().notes.find((item) => goalNoteId(item.content) === id);
73
+ if (!note)
74
+ throw new Error('The linked note is not available in this vault.');
75
+ return note;
76
+ },
77
+ saveDraft(id, markdown) {
78
+ const content = withGoalNoteId(markdown, id);
79
+ const path = `Goals/Draft-${id}.md`;
80
+ try {
81
+ writeNote(root, path, content, 'create');
82
+ } catch (error) {
83
+ // Idempotent retry of our own exact output; never overwrite a user's edits.
84
+ if (readNote(root, path).content !== content) throw error;
85
+ }
86
+ },
87
+ };
88
+ }