@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
package/dist/turnLog.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, unlinkSync, } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { TURNS_DIR } from './config.js';
4
+ import { RuntimeStore } from './runtimeStore.js';
4
5
  /** Frame `type`s that end a turn. Mirrors the relay's TERMINAL_TYPES — `code_result`
5
6
  * and `clone_result` are NOT terminal (a `done` follows). */
6
7
  const TERMINAL_TYPES = new Set(['done', 'error', 'cancelled']);
@@ -72,56 +73,13 @@ function appendLine(path, line) {
72
73
  return false;
73
74
  }
74
75
  }
75
- /**
76
- * One turn's log. Owns the per-requestId `seq` counter (a shared handle, NOT a closure
77
- * local, so a concurrent `cancel`'s terminal frame gets the next `seq` on the same
78
- * counter). Seeds itself from any existing file so seq keeps climbing across a daemon
79
- * restart (a re-created handle resumes from the file's `maxSeq`).
80
- */
81
- export class TurnLog {
82
- path;
83
- maxBytes;
84
- nextSeq;
85
- bytes;
86
- terminatedFlag;
87
- constructor(requestId, dir, maxBytes = MAX_TURN_LOG_BYTES) {
88
- this.path = join(dir, `${requestId}.jsonl`);
89
- this.maxBytes = maxBytes;
90
- const st = scanTurnFile(this.path);
91
- this.nextSeq = st.maxSeq + 1;
92
- this.bytes = st.bytes;
93
- this.terminatedFlag = st.terminated;
94
- }
95
- get terminated() {
96
- return this.terminatedFlag;
97
- }
98
- /** Stamp the next `seq`, append the frame (unless a droppable delta past the byte cap),
99
- * and return the stamped frame to put on the wire. */
100
- write(event) {
101
- const seq = this.nextSeq++;
102
- const frame = { ...event, seq };
103
- const type = typeof event.type === 'string' ? event.type : '';
104
- const droppable = type === 'delta' && this.bytes >= this.maxBytes;
105
- if (!droppable) {
106
- const line = JSON.stringify(frame) + '\n';
107
- if (appendLine(this.path, line))
108
- this.bytes += Buffer.byteLength(line, 'utf8');
109
- }
110
- if (isTerminalType(type))
111
- this.terminatedFlag = true;
112
- return frame;
113
- }
114
- }
115
- /**
116
- * All turn logs for this daemon. Keeps an in-memory {@link TurnLog} per in-flight turn
117
- * (the live seq counter), dropped once the turn terminates — the file lives on for 24h.
118
- * The file is the source of truth for replay ({@link read}).
119
- */
76
+ /** Compatibility reader/exporter around the transactional local runtime ledger. */
120
77
  export class TurnLogStore {
121
78
  dir;
122
79
  clock;
123
80
  maxBytes;
124
- logs = new Map();
81
+ exportBytes = new Map();
82
+ runtime;
125
83
  queueDirectory() {
126
84
  return join(this.dir, 'queue');
127
85
  }
@@ -129,6 +87,7 @@ export class TurnLogStore {
129
87
  this.dir = opts.dir ?? TURNS_DIR;
130
88
  this.clock = opts.now ?? Date.now;
131
89
  this.maxBytes = opts.maxBytes ?? MAX_TURN_LOG_BYTES;
90
+ this.runtime = new RuntimeStore(join(this.dir, 'runtime.sqlite'));
132
91
  try {
133
92
  mkdirSync(this.dir, { recursive: true });
134
93
  }
@@ -138,21 +97,39 @@ export class TurnLogStore {
138
97
  }
139
98
  /** Log + stamp one outgoing stream frame; returns the stamped frame to send. */
140
99
  append(requestId, event) {
141
- let log = this.logs.get(requestId);
142
- if (!log) {
143
- log = new TurnLog(requestId, this.dir, this.maxBytes);
144
- this.logs.set(requestId, log);
100
+ if (!this.runtime.status(requestId).exists)
101
+ this.read(requestId);
102
+ const before = this.runtime.status(requestId);
103
+ const frame = this.runtime.append(requestId, event);
104
+ if (before.terminated)
105
+ return frame;
106
+ // Bounded diagnostic exports are optional; a failed export never loses the SQLite event.
107
+ const path = join(this.dir, `${requestId}.jsonl`);
108
+ const bytes = this.exportBytes.get(requestId) ?? (existsSync(path) ? statSync(path).size : 0);
109
+ if (event.type !== 'delta' || bytes < this.maxBytes) {
110
+ const line = JSON.stringify(frame) + '\n';
111
+ if (appendLine(path, line))
112
+ this.exportBytes.set(requestId, bytes + Buffer.byteLength(line));
145
113
  }
146
- const frame = log.write(event);
147
- if (log.terminated)
148
- this.logs.delete(requestId); // free memory; file persists
114
+ if (TERMINAL_TYPES.has(String(event.type)))
115
+ this.exportBytes.delete(requestId);
149
116
  return frame;
150
117
  }
151
- /** The durable state of a turn, read from disk — for serving a `pull`. */
152
118
  read(requestId) {
153
- const { exists, frames, maxSeq, terminated } = scanTurnFile(join(this.dir, `${requestId}.jsonl`));
154
- return { exists, frames, maxSeq, terminated };
119
+ const state = this.runtime.read(requestId);
120
+ if (state.exists)
121
+ return state;
122
+ this.runtime.importLog(requestId, scanTurnFile(join(this.dir, `${requestId}.jsonl`)));
123
+ return this.runtime.read(requestId);
124
+ }
125
+ /** Startup recovery is independent of whether a phone asks to replay a turn. */
126
+ reconcile(owns) {
127
+ for (const name of readdirSync(this.dir))
128
+ if (name.endsWith('.jsonl'))
129
+ this.read(name.slice(0, -6));
130
+ this.runtime.reconcile(owns);
155
131
  }
132
+ close() { this.runtime.close(); }
156
133
  /** Delete turn logs whose file hasn't been touched in `maxAgeMs`. Never throws. */
157
134
  prune(maxAgeMs = TURN_LOG_MAX_AGE_MS) {
158
135
  const now = this.clock();
package/dist/vault.d.ts CHANGED
@@ -19,9 +19,12 @@ export interface Vault {
19
19
  /** SOUL.md if present (and non-empty), else the packaged default — seeding SOUL.md so it's editable. */
20
20
  readPersona(): string;
21
21
  /** Durable facts from MEMORY.md (empty if absent/malformed). */
22
- readMemoryFacts(): string[];
23
- writeMemoryFacts(facts: string[]): void;
24
- writeSessionLog(entry: SessionEntry): void;
22
+ readMemoryFacts(strict?: boolean): string[];
23
+ writeMemoryFacts(facts: string[], strict?: boolean): void;
24
+ writeSessionLog(entry: SessionEntry, receipt?: {
25
+ id: string;
26
+ strict: boolean;
27
+ }): void;
25
28
  }
26
29
  export declare function createVault(vaultPath: string): Vault;
27
30
  //# sourceMappingURL=vault.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wGAAwG;IACxG,WAAW,IAAI,MAAM,CAAC;IACtB,gEAAgE;IAChE,eAAe,IAAI,MAAM,EAAE,CAAC;IAC5B,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACxC,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;CAC5C;AAMD,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CA6DpD"}
1
+ {"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wGAAwG;IACxG,WAAW,IAAI,MAAM,CAAC;IACtB,gEAAgE;IAChE,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAC;IAC5C,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC1D,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CACvF;AAMD,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAsEpD"}
package/dist/vault.js CHANGED
@@ -27,27 +27,31 @@ export function createVault(vaultPath) {
27
27
  }
28
28
  return def;
29
29
  },
30
- readMemoryFacts() {
30
+ readMemoryFacts(strict = false) {
31
31
  if (!existsSync(memoryPath))
32
32
  return [];
33
33
  try {
34
34
  return parseFacts(readFileSync(memoryPath, 'utf8'));
35
35
  }
36
36
  catch (err) {
37
+ if (strict)
38
+ throw err;
37
39
  console.error(`[vault] could not read MEMORY.md: ${msg(err)}`);
38
40
  return [];
39
41
  }
40
42
  },
41
- writeMemoryFacts(facts) {
43
+ writeMemoryFacts(facts, strict = false) {
42
44
  try {
43
45
  mkdirSync(vaultPath, { recursive: true });
44
46
  writeFileSync(memoryPath, renderMemoryFile(facts), 'utf8');
45
47
  }
46
48
  catch (err) {
49
+ if (strict)
50
+ throw err;
47
51
  console.error(`[vault] could not write MEMORY.md: ${msg(err)}`);
48
52
  }
49
53
  },
50
- writeSessionLog(entry) {
54
+ writeSessionLog(entry, receipt) {
51
55
  try {
52
56
  mkdirSync(sessionsDir, { recursive: true });
53
57
  const kind = entry.kind ?? 'briefing';
@@ -59,9 +63,19 @@ export function createVault(vaultPath) {
59
63
  `Delivered via: ${entry.deliveredVia}\n\n` +
60
64
  `## Message\n\n${entry.body.trim()}\n\n` +
61
65
  `## Facts learned\n\n${facts}\n`;
62
- writeFileSync(join(sessionsDir, `${stamp}-${kind}.md`), content, 'utf8');
66
+ if (receipt && !/^[a-zA-Z0-9-]+$/.test(receipt.id))
67
+ throw new Error('Invalid session receipt ID');
68
+ const path = join(sessionsDir, `${receipt?.id ?? stamp}-${kind}.md`);
69
+ if (receipt && existsSync(path)) {
70
+ if (readFileSync(path, 'utf8') !== content)
71
+ throw new Error('The saved briefing was changed outside this run.');
72
+ return;
73
+ }
74
+ writeFileSync(path, content, { encoding: 'utf8', flag: receipt ? 'wx' : 'w' });
63
75
  }
64
76
  catch (err) {
77
+ if (receipt?.strict)
78
+ throw err;
65
79
  console.error(`[vault] could not write session log: ${msg(err)}`);
66
80
  }
67
81
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencorelabs/lucidity",
3
- "version": "0.7.0",
3
+ "version": "0.9.5",
4
4
  "description": "Lucidity's local personal agent, command-line interface, and MCP server",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
@@ -25,7 +25,7 @@
25
25
  "native"
26
26
  ],
27
27
  "engines": {
28
- "node": ">=22"
28
+ "node": ">=22.13.0"
29
29
  },
30
30
  "keywords": [
31
31
  "lucidity",
@@ -42,9 +42,9 @@
42
42
  "chrono-node": "^2.10.1",
43
43
  "zod": "^4.3.5 ^4.3.6",
44
44
  "@js-temporal/polyfill": "^0.5.1",
45
- "@anthropic-ai/claude-agent-sdk": "0.3.267",
45
+ "@anthropic-ai/claude-agent-sdk": "0.3.287",
46
46
  "@modelcontextprotocol/sdk": "1.29.0 ^1.12.1",
47
- "@openai/codex": "0.153.4",
47
+ "@openai/codex": "0.160.0",
48
48
  "croner": "^10.0.0",
49
49
  "uuidv7": "^1.1.0",
50
50
  "ws": "^8.18.1",
@@ -31,6 +31,8 @@ const SOURCE_TOOLS: Partial<Record<AutomationSource, string[]>> = {
31
31
  'get_today',
32
32
  'get_week',
33
33
  'list_projects',
34
+ 'list_goals',
35
+ 'get_goal',
34
36
  'list_milestones',
35
37
  'get_milestone_progress',
36
38
  'get_task_stats',
@@ -11,6 +11,7 @@ import {
11
11
  isDesignerInput,
12
12
  } from '@lucidity/shared';
13
13
  import { AutomationStore } from './store.js';
14
+ import { WorkflowInterrupted } from './workflow.js';
14
15
 
15
16
  export function nextOccurrence(
16
17
  schedule: AutomationSchedule,
@@ -37,6 +38,7 @@ export function nextOccurrence(
37
38
 
38
39
  export interface AutomationServiceDeps {
39
40
  store: AutomationStore;
41
+ resumable?: (job: AutomationJob) => boolean;
40
42
  execute: (
41
43
  job: AutomationJob,
42
44
  run: AutomationRun,
@@ -65,6 +67,7 @@ export class AutomationService {
65
67
  constructor(private readonly deps: AutomationServiceDeps) {
66
68
  this.now = deps.now ?? (() => new Date());
67
69
  for (const run of deps.store.runs()) {
70
+ if (run.status === 'running' && run.workflow) continue;
68
71
  if (run.status === 'running')
69
72
  this.finish(run, {
70
73
  status: 'interrupted',
@@ -180,7 +183,7 @@ export class AutomationService {
180
183
  this.deps.changed?.();
181
184
  }
182
185
  private assertIdle(jobId: string) {
183
- if (this.active.has(jobId))
186
+ if (this.active.has(jobId) || this.deps.store.runs().some((run) => run.jobId === jobId && run.status === 'running'))
184
187
  throw new Error(
185
188
  'This automation already has a running job. Open it or cancel it before starting another.',
186
189
  );
@@ -276,9 +279,10 @@ export class AutomationService {
276
279
  } else if (command.action === 'cancel') {
277
280
  const run = this.deps.store.run(command.runId);
278
281
  const active = this.active.get(run.jobId);
279
- if (!active || active.runId !== run.id)
280
- throw new Error('This run has already ended');
281
- active.controller.abort();
282
+ if (run.status !== 'running') throw new Error('This run has already ended');
283
+ this.deps.store.saveRun({ ...run, cancelRequested: true });
284
+ if (active?.runId === run.id) active.controller.abort();
285
+ else this.finish(run, { status: 'cancelled', cancelRequested: true });
282
286
  message =
283
287
  'Cancellation requested. Completed external edits remain available for review.';
284
288
  } else {
@@ -384,6 +388,7 @@ export class AutomationService {
384
388
  }
385
389
  tick() {
386
390
  const now = this.now();
391
+ this.resumeAccepted(now);
387
392
  for (const job of this.deps.store.jobs()) {
388
393
  if (!this.deps.scheduledWork() && job.id !== 'builtin:prune') continue;
389
394
  if (!job.enabled || (job.pausedUntil && new Date(job.pausedUntil) > now))
@@ -395,15 +400,15 @@ export class AutomationService {
395
400
  }
396
401
  if (new Date(job.nextRunAt) > now) continue;
397
402
  const late = now.getTime() - Date.parse(job.nextRunAt) > 90_000;
398
- // Claim the scheduled occurrence before inference. A crash never replays it.
399
- this.saveJob({
403
+ // The occurrence and its run are admitted in the same transaction.
404
+ const claim = { occurrence: job.nextRunAt, job: {
400
405
  ...job,
401
406
  pausedUntil: undefined,
402
407
  nextRunAt: nextOccurrence(job.schedule, now),
403
- });
404
- if (this.active.has(job.id) || (late && job.catchUp === 'skip')) {
408
+ } };
409
+ if (this.hasAccepted(job.id) || (late && job.catchUp === 'skip')) {
405
410
  const at = now.toISOString();
406
- this.deps.store.saveRun({
411
+ this.deps.store.admit({
407
412
  id: uuidv7(),
408
413
  jobId: job.id,
409
414
  jobName: job.name,
@@ -417,12 +422,12 @@ export class AutomationService {
417
422
  status: 'skipped',
418
423
  startedAt: at,
419
424
  finishedAt: at,
420
- summary: this.active.has(job.id)
425
+ summary: this.hasAccepted(job.id)
421
426
  ? 'Previous run is still active.'
422
427
  : 'Scheduled time was missed while the computer was unavailable. Catch-up is disabled.',
423
428
  directions: [],
424
429
  feedback: [],
425
- });
430
+ }, claim);
426
431
  } else
427
432
  this.launch(
428
433
  job,
@@ -432,6 +437,7 @@ export class AutomationService {
432
437
  ? 'agent'
433
438
  : 'design',
434
439
  late ? 'catch-up' : 'scheduled',
440
+ undefined, claim,
435
441
  );
436
442
  }
437
443
  }
@@ -440,6 +446,7 @@ export class AutomationService {
440
446
  stage: AutomationRun['stage'],
441
447
  trigger: AutomationRun['trigger'],
442
448
  parent?: AutomationRun,
449
+ claim?: { job: AutomationJob; occurrence: string },
443
450
  ): string {
444
451
  this.assertIdle(job.id);
445
452
  const run: AutomationRun = {
@@ -451,6 +458,7 @@ export class AutomationService {
451
458
  status: 'running',
452
459
  startedAt: this.now().toISOString(),
453
460
  summary: 'Starting…',
461
+ ...(this.deps.resumable?.(job) ? { workflow: { version: 1, attempts: 1, possibleAdditionalCost: false, steps: [] } } : {}),
454
462
  input: job.input,
455
463
  parentRunId: parent?.id,
456
464
  feedback: parent?.feedback ?? [],
@@ -458,22 +466,41 @@ export class AutomationService {
458
466
  selectedDirectionId:
459
467
  stage === 'implementation' ? parent?.selectedDirectionId : undefined,
460
468
  };
461
- this.deps.store.saveRun(run);
469
+ if (!this.deps.store.admit(run, claim)) return run.id;
470
+ this.executeAccepted(job, run);
471
+ return run.id;
472
+ }
473
+ private hasAccepted(jobId: string) {
474
+ return this.active.has(jobId) || this.deps.store.runs().some((run) => run.jobId === jobId && run.status === 'running');
475
+ }
476
+ private resumeAccepted(now: Date) {
477
+ for (const run of this.deps.store.runs()) {
478
+ if (run.status !== 'running' || this.active.has(run.jobId)) continue;
479
+ const job = this.deps.store.jobs().find((job) => job.id === run.jobId);
480
+ if (run.cancelRequested) { this.finish(run, { status: 'cancelled' }); continue; }
481
+ if (!job || !this.deps.resumable?.(job) || run.workflow?.version !== 1) {
482
+ this.finish(run, { status: 'interrupted', error: 'This saved workflow cannot resume with the installed version.' });
483
+ continue;
484
+ }
485
+ if (!this.deps.scheduledWork() || !job.enabled || (job.pausedUntil && new Date(job.pausedUntil) > now)) continue;
486
+ const resumed = { ...run, workflow: { ...run.workflow, attempts: run.workflow.attempts + 1 } };
487
+ this.deps.store.saveRun(resumed);
488
+ this.executeAccepted(job, resumed);
489
+ }
490
+ }
491
+ private executeAccepted(job: AutomationJob, run: AutomationRun) {
462
492
  const controller = new AbortController();
463
493
  // Microtask admission makes the active marker visible before any executor can finish.
464
494
  const done = Promise.resolve()
465
495
  .then(async () => {
466
496
  try {
467
497
  const result = await this.deps.execute(job, run, controller.signal);
468
- this.finish(
469
- run,
470
- controller.signal.aborted
471
- ? { ...result, status: 'cancelled' }
472
- : result,
473
- );
498
+ if (controller.signal.aborted && run.workflow && !this.deps.store.run(run.id).cancelRequested) return;
499
+ this.finish(run, controller.signal.aborted ? { ...result, status: 'cancelled' } : result);
474
500
  } catch (error) {
501
+ if (controller.signal.aborted && run.workflow && !this.deps.store.run(run.id).cancelRequested) return;
475
502
  this.finish(run, {
476
- status: controller.signal.aborted ? 'cancelled' : 'failed',
503
+ status: controller.signal.aborted ? 'cancelled' : error instanceof WorkflowInterrupted ? 'interrupted' : 'failed',
477
504
  error: error instanceof Error ? error.message : String(error),
478
505
  });
479
506
  } finally {
@@ -488,12 +515,11 @@ export class AutomationService {
488
515
  });
489
516
  this.active.set(job.id, { runId: run.id, controller, done });
490
517
  this.deps.changed?.();
491
- return run.id;
492
518
  }
493
519
  private finish(run: AutomationRun, patch: Partial<AutomationRun>) {
494
520
  const finishedAt = this.now().toISOString();
495
521
  this.deps.store.saveRun({
496
- ...run,
522
+ ...this.deps.store.run(run.id),
497
523
  status: 'completed',
498
524
  ...patch,
499
525
  id: run.id,
@@ -1,63 +1,54 @@
1
- import {
2
- existsSync,
3
- mkdirSync,
4
- readFileSync,
5
- readdirSync,
6
- renameSync,
7
- writeFileSync,
8
- } from 'node:fs';
1
+ import { existsSync, mkdirSync, readFileSync, readdirSync } from 'node:fs';
9
2
  import { join } from 'node:path';
10
3
  import {
11
- AutomationJobSchema,
12
- AutomationRunSchema,
13
- type AutomationJob,
14
- type AutomationRun,
4
+ AutomationJobSchema, AutomationRunSchema,
5
+ type AutomationJob, type AutomationRun,
15
6
  } from '@lucidity/shared';
7
+ import { RuntimeStore } from '../runtimeStore.js';
16
8
 
17
- /** Only the daemon writes this store; CLI and phone go through its authenticated gateway. */
9
+ /** The daemon owns admission and execution. Legacy JSON remains untouched after import. */
18
10
  export class AutomationStore {
19
- constructor(readonly directory: string) {
11
+ readonly runtime: RuntimeStore;
12
+ constructor(readonly directory: string, runtime?: RuntimeStore) {
20
13
  mkdirSync(join(directory, 'runs'), { recursive: true, mode: 0o700 });
14
+ this.runtime = runtime ?? new RuntimeStore(join(directory, 'automations.sqlite'));
15
+ if (!this.runtime.get('automation-migrations', directory)) {
16
+ const path = join(directory, 'jobs.json');
17
+ const jobs = existsSync(path) ? AutomationJobSchema.array().parse(JSON.parse(readFileSync(path, 'utf8'))) : [];
18
+ const runs = readdirSync(join(directory, 'runs')).filter((name) => name.endsWith('.json')).map((name) =>
19
+ AutomationRunSchema.parse(JSON.parse(readFileSync(join(directory, 'runs', name), 'utf8'))));
20
+ this.runtime.transaction(() => {
21
+ for (const job of jobs) if (!this.runtime.get('automation-jobs', job.id)) this.saveJob(job);
22
+ for (const run of runs) if (!this.runtime.get('automation-runs', run.id)) this.saveRun(run);
23
+ this.runtime.set('automation-migrations', directory, true);
24
+ });
25
+ }
21
26
  }
22
- private write(path: string, value: unknown) {
23
- const temporary = `${path}.tmp`;
24
- writeFileSync(temporary, JSON.stringify(value, null, 2), { mode: 0o600 });
25
- renameSync(temporary, path);
26
- }
27
- jobs(): AutomationJob[] {
28
- const path = join(this.directory, 'jobs.json');
29
- if (!existsSync(path)) return [];
30
- // Corruption must be surfaced, never mistaken for an empty store and overwritten.
31
- return AutomationJobSchema.array().parse(
32
- JSON.parse(readFileSync(path, 'utf8')),
33
- );
34
- }
35
- saveJob(job: AutomationJob) {
36
- const jobs = this.jobs();
37
- this.write(join(this.directory, 'jobs.json'), [
38
- ...jobs.filter((row) => row.id !== job.id),
39
- AutomationJobSchema.parse(job),
40
- ]);
41
- }
27
+ jobs(): AutomationJob[] { return this.runtime.list<AutomationJob>('automation-jobs').map((job) => AutomationJobSchema.parse(job)); }
28
+ saveJob(job: AutomationJob) { this.runtime.set('automation-jobs', job.id, AutomationJobSchema.parse(job)); }
42
29
  run(id: string): AutomationRun {
43
30
  if (!/^[a-zA-Z0-9-]+$/.test(id)) throw new Error('Invalid run ID');
44
- return AutomationRunSchema.parse(
45
- JSON.parse(
46
- readFileSync(join(this.directory, 'runs', `${id}.json`), 'utf8'),
47
- ),
48
- );
49
- }
50
- saveRun(run: AutomationRun) {
51
- if (!/^[a-zA-Z0-9-]+$/.test(run.id)) throw new Error('Invalid run ID');
52
- this.write(
53
- join(this.directory, 'runs', `${run.id}.json`),
54
- AutomationRunSchema.parse(run),
55
- );
31
+ const run = this.runtime.get('automation-runs', id);
32
+ if (!run) throw new Error('Automation run not found');
33
+ return AutomationRunSchema.parse(run);
56
34
  }
35
+ saveRun(run: AutomationRun) { this.runtime.set('automation-runs', run.id, AutomationRunSchema.parse(run)); }
57
36
  runs(): AutomationRun[] {
58
- return readdirSync(join(this.directory, 'runs'))
59
- .filter((name) => name.endsWith('.json'))
60
- .map((name) => this.run(name.slice(0, -5)))
61
- .sort((a, b) => b.id.localeCompare(a.id));
37
+ return this.runtime.list<AutomationRun>('automation-runs').map((run) => AutomationRunSchema.parse(run)).sort((a, b) => b.id.localeCompare(a.id));
38
+ }
39
+ /** Advancing a schedule and accepting its one run commit together, including skipped occurrences. */
40
+ admit(run: AutomationRun, claim?: { job: AutomationJob; occurrence: string }): boolean {
41
+ return this.runtime.transaction(() => {
42
+ if (this.runtime.get('automation-runs', run.id)) return false;
43
+ if (claim) {
44
+ const current = this.runtime.get<AutomationJob>('automation-jobs', claim.job.id);
45
+ const key = JSON.stringify([claim.job.id, claim.occurrence]);
46
+ if (current?.nextRunAt !== claim.occurrence || this.runtime.get('automation-occurrences', key)) return false;
47
+ this.runtime.set('automation-occurrences', key, run.id);
48
+ this.saveJob(claim.job);
49
+ }
50
+ this.saveRun(run);
51
+ return true;
52
+ });
62
53
  }
63
54
  }
@@ -0,0 +1,49 @@
1
+ import type { AutomationRun } from '@lucidity/shared';
2
+ import type { AutomationStore } from './store.js';
3
+
4
+ type Step = NonNullable<AutomationRun['workflow']>['steps'][number] & { value?: unknown };
5
+ interface Checkpoint { version: number; steps: Step[] }
6
+ export class WorkflowInterrupted extends Error {}
7
+
8
+ /** A small ordered-step journal. Only pure reads and tool-less generation may retry. */
9
+ export class SavedWorkflow {
10
+ private checkpoint: Checkpoint;
11
+ constructor(private readonly store: AutomationStore, readonly runId: string, private readonly signal?: AbortSignal) {
12
+ this.checkpoint = store.runtime.get<Checkpoint>('workflow-steps', runId) ?? { version: 1, steps: [] };
13
+ if (this.checkpoint.version !== 1) throw new WorkflowInterrupted('This run uses an incompatible saved workflow version. Its saved output has been retained.');
14
+ }
15
+ private save(step: Step) {
16
+ this.checkpoint.steps = [...this.checkpoint.steps.filter((old) => old.key !== step.key), step];
17
+ this.store.runtime.transaction(() => {
18
+ this.store.runtime.set('workflow-steps', this.runId, this.checkpoint);
19
+ const run = this.store.run(this.runId);
20
+ this.store.saveRun({ ...run, workflow: {
21
+ version: 1, attempts: run.workflow?.attempts ?? 1,
22
+ possibleAdditionalCost: this.checkpoint.steps.some((s) => s.attempts > 1 && ['Generate briefing', 'Reflect'].includes(s.key)),
23
+ steps: this.checkpoint.steps.map(({ value: _, ...progress }) => progress),
24
+ }, ...(step.key === 'Generate briefing' && step.status === 'completed' ? { summary: (step.value as { text: string }).text, costUsd: (step.value as { costUsd?: number }).costUsd, sessionId: (step.value as { sessionId?: string }).sessionId } : {}) });
25
+ });
26
+ }
27
+ async step<T>(key: string, policy: 'retry' | 'effect', action: () => Promise<T> | T): Promise<T> {
28
+ if (this.signal?.aborted || this.store.run(this.runId).cancelRequested) throw new Error('Run stopped.');
29
+ const old = this.checkpoint.steps.find((step) => step.key === key);
30
+ if (old?.status === 'completed') return old.value as T;
31
+ if (old && policy === 'effect') {
32
+ const error = `${key} may already have happened. Review the saved output before doing it again.`;
33
+ this.save({ ...old, status: 'uncertain', error });
34
+ throw new WorkflowInterrupted(error);
35
+ }
36
+ if ((old?.attempts ?? 0) >= 3) throw new WorkflowInterrupted(`${key} reached its three-attempt recovery limit. Saved work has been retained.`);
37
+ const started: Step = { key, status: 'running', attempts: (old?.attempts ?? 0) + 1 };
38
+ this.save(started);
39
+ let value: T;
40
+ try { value = await action(); }
41
+ catch (error) {
42
+ this.save({ ...started, status: policy === 'effect' ? 'uncertain' : 'failed', error: error instanceof Error ? error.message : String(error) });
43
+ if (policy === 'effect') throw new WorkflowInterrupted(`${key} has an uncertain outcome: ${String(error)}`);
44
+ throw error;
45
+ }
46
+ this.save({ ...started, status: 'completed', value });
47
+ return value;
48
+ }
49
+ }
@@ -23,6 +23,7 @@ import type { McpWiring } from '../mcp/config.js';
23
23
  import type { AutomationService } from '../automations/service.js';
24
24
 
25
25
  export interface ChatServerDeps {
26
+ signal?: AbortSignal;
26
27
  automations?: AutomationService;
27
28
  config: DaemonConfig;
28
29
  executor: AgentExecutor;
@@ -73,6 +74,11 @@ export function createChatServer(deps: ChatServerDeps): Server {
73
74
  req: IncomingMessage,
74
75
  res: ServerResponse,
75
76
  ): Promise<void> {
77
+ if (deps.signal?.aborted) {
78
+ res.writeHead(503);
79
+ res.end('Lucidity is restarting. Reconnect before sending.');
80
+ return;
81
+ }
76
82
  if (req.method === 'GET' && req.url === '/health') {
77
83
  res.writeHead(200, { 'Content-Type': 'application/json' });
78
84
  res.end(JSON.stringify({ ok: true }));
@@ -170,7 +176,7 @@ export function createChatServer(deps: ChatServerDeps): Server {
170
176
  const input = await buildChatInput();
171
177
  for await (const ev of executor.runStream!({
172
178
  ...input,
173
- signal: ac.signal,
179
+ signal: deps.signal ? AbortSignal.any([ac.signal, deps.signal]) : ac.signal,
174
180
  })) {
175
181
  if (ev.type === 'session')
176
182
  send({ type: 'session', sessionId: ev.sessionId });
@@ -69,3 +69,17 @@ export async function listPrs(
69
69
  return { branch, prs: [], error: (raw.split('\n')[0] ?? '').slice(0, 200) };
70
70
  }
71
71
  }
72
+
73
+ /** The head commit of the merged pull request opened from `branch`, if there is one. Never throws. */
74
+ export async function mergedPrHead(repoRoot: string, branch: string): Promise<string | undefined> {
75
+ try {
76
+ const { stdout } = await exec(
77
+ 'gh',
78
+ ['pr', 'list', '--head', branch, '--state', 'merged', '--limit', '1', '--json', 'headRefOid'],
79
+ { cwd: repoRoot, env: { ...process.env, PATH: GH_PATH }, maxBuffer: 1024 * 1024 },
80
+ );
81
+ return (JSON.parse(stdout) as { headRefOid?: string }[])[0]?.headRefOid;
82
+ } catch {
83
+ return undefined;
84
+ }
85
+ }