@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
@@ -2,8 +2,6 @@ import {
2
2
  mkdirSync,
3
3
  readFileSync,
4
4
  readdirSync,
5
- renameSync,
6
- writeFileSync,
7
5
  statSync,
8
6
  unlinkSync,
9
7
  } from 'node:fs';
@@ -15,9 +13,11 @@ import { LaneQueue } from '../queue.js';
15
13
  type Request = Extract<HarnessRequest, { kind: 'ask' | 'code' }>;
16
14
  type Entry = {
17
15
  request: Request;
18
- state: 'queued' | 'running' | 'steering' | 'done' | 'failed' | 'skipped';
16
+ state: 'queued' | 'held' | 'running' | 'steering' | 'done' | 'failed' | 'skipped';
17
+ blockedBy?: string;
19
18
  action?: 'cancel' | 'steer';
20
19
  resume?: string;
20
+ failure?: { message: string; code?: string };
21
21
  };
22
22
  export function turnLane(req: Request): string {
23
23
  return req.kind === 'ask'
@@ -43,6 +43,8 @@ export class DurableTurnQueue {
43
43
  },
44
44
  ) {
45
45
  mkdirSync(deps.dir, { recursive: true, mode: 0o700 });
46
+ for (const entry of deps.logs.runtime.list<Entry>('queue'))
47
+ this.entries.set(entry.request.id, entry);
46
48
  for (const name of readdirSync(deps.dir)
47
49
  .filter((name) => name.endsWith('.json'))
48
50
  .sort()) {
@@ -56,6 +58,11 @@ export class DurableTurnQueue {
56
58
  unlinkSync(join(deps.dir, name));
57
59
  continue;
58
60
  }
61
+ if (this.entries.has(entry.request.id)) continue;
62
+ this.deps.logs.runtime.set('queue', entry.request.id, entry);
63
+ this.entries.set(entry.request.id, entry);
64
+ }
65
+ for (const entry of this.entries.values()) {
59
66
  const parsed = HarnessRequestSchema.parse(entry.request);
60
67
  if (parsed.kind !== 'ask' && parsed.kind !== 'code')
61
68
  throw new Error('Invalid queued turn');
@@ -72,7 +79,8 @@ export class DurableTurnQueue {
72
79
  } else {
73
80
  this.fail(
74
81
  entry,
75
- 'Lucid restarted during this turn. It was not run again. Review the result before resending.',
82
+ 'Lucid restarted during this turn. It was not run again. Review its work before continuing.',
83
+ 'interrupted_unknown',
76
84
  );
77
85
  }
78
86
  } else if (entry.state === 'skipped' && !terminal) {
@@ -83,8 +91,8 @@ export class DurableTurnQueue {
83
91
  } else if (entry.state === 'failed' && !terminal) {
84
92
  this.publish(parsed.id, {
85
93
  type: 'error',
86
- message:
87
- 'This queued turn could not finish. Review it before resending.',
94
+ ...(entry.failure ?? { message:
95
+ 'This queued turn could not finish. Review it before resending.' }),
88
96
  });
89
97
  }
90
98
  }
@@ -104,12 +112,7 @@ export class DurableTurnQueue {
104
112
  }
105
113
 
106
114
  private save(entry: Entry): void {
107
- const path = join(this.deps.dir, `${entry.request.id}.json`);
108
- writeFileSync(`${path}.tmp`, JSON.stringify(entry), {
109
- mode: 0o600,
110
- flush: true,
111
- });
112
- renameSync(`${path}.tmp`, path);
115
+ this.deps.logs.runtime.set('queue', entry.request.id, entry);
113
116
  this.entries.set(entry.request.id, entry);
114
117
  }
115
118
  private publish(id: string, event: Record<string, unknown>): void {
@@ -137,15 +140,16 @@ export class DurableTurnQueue {
137
140
  .find((frame) => typeof frame.sessionId === 'string')?.sessionId;
138
141
  return typeof value === 'string' ? value : undefined;
139
142
  }
140
- private fail(entry: Entry, message: string): void {
141
- this.save({ ...entry, state: 'failed' });
143
+ private fail(entry: Entry, message: string, code?: string): void {
144
+ const failure = { message, ...(code ? { code } : {}) };
145
+ this.save({ ...entry, state: 'failed', failure });
142
146
  if (!this.deps.logs.read(entry.request.id).terminated)
143
- this.publish(entry.request.id, { type: 'error', message });
147
+ this.publish(entry.request.id, { type: 'error', ...failure });
144
148
  this.wake();
145
149
  }
146
150
  owns(id: string): boolean {
147
151
  const state = this.entries.get(id)?.state;
148
- return state === 'queued' || state === 'running' || state === 'steering';
152
+ return state === 'queued' || state === 'held' || state === 'running' || state === 'steering';
149
153
  }
150
154
  confirm(id: string): void {
151
155
  const entry = this.entries.get(id);
@@ -153,6 +157,7 @@ export class DurableTurnQueue {
153
157
  this.publish(id, {
154
158
  type: 'queue_state',
155
159
  state: entry.state === 'running' ? 'running' : 'queued',
160
+ ...(entry.blockedBy ? { blockedBy: entry.blockedBy, message: 'Held for review of the interrupted turn.' } : {}),
156
161
  });
157
162
  }
158
163
  enqueue(request: Request): void {
@@ -160,7 +165,7 @@ export class DurableTurnQueue {
160
165
  throw new Error('Queued turns require streaming replies.');
161
166
  const existing = this.entries.get(request.id);
162
167
  if (existing) {
163
- if (JSON.stringify(existing.request) !== JSON.stringify(request))
168
+ if (JSON.stringify(HarnessRequestSchema.parse(existing.request)) !== JSON.stringify(HarnessRequestSchema.parse(request)))
164
169
  throw new Error('Request ID already belongs to another message.');
165
170
  for (const frame of this.deps.logs.read(request.id).frames)
166
171
  this.deps.sendRaw(frame);
@@ -186,37 +191,32 @@ export class DurableTurnQueue {
186
191
  scope &&
187
192
  (request.kind === 'ask'
188
193
  ? scope.kind === 'ask'
189
- : (scope.kind === 'code' &&
190
- scope.repoId === request.repoId &&
191
- scope.workerId === request.workerId &&
192
- (scope.mode ?? 'worktree') === (request.mode ?? 'worktree')) ||
193
- (scope.kind === 'conduct' &&
194
- scope.repoId === request.repoId &&
195
- !!request.workerId));
194
+ : scope.kind === 'code' &&
195
+ scope.repoId === request.repoId &&
196
+ scope.workerId === request.workerId &&
197
+ (scope.mode ?? 'worktree') === (request.mode ?? 'worktree'));
196
198
  if (!same)
197
199
  throw new Error(
198
200
  'The preceding turn does not belong to this conversation. Refresh it before sending again.',
199
201
  );
200
202
  }
201
203
  const entry: Entry = { request, state: 'queued' };
202
- this.save(entry);
203
- try {
204
- this.publish(request.id, { type: 'queue_state', state: 'queued' });
205
- } catch (error) {
206
- this.save({ ...entry, state: 'failed' });
207
- throw error;
208
- }
204
+ const accepted = this.deps.logs.runtime.accept(request, entry);
205
+ this.entries.set(request.id, entry);
206
+ for (const frame of accepted.frames) this.deps.sendRaw(frame);
209
207
  this.wake();
210
208
  }
211
209
 
212
210
  /** Skipped queue entries inherit their predecessor, so removing B from A→B→C
213
211
  * never starts a new conversation or strands C. Failed executions stop dependants. */
214
- private predecessor(entry: Entry): { ready: boolean; resume?: string } {
212
+ private predecessor(entry: Entry): { ready: boolean; resume?: string; blockedBy?: string } {
215
213
  const id = entry.request.afterRequestId;
216
214
  if (!id) return { ready: true, resume: entry.request.resume };
217
215
  const previous = this.entries.get(id);
218
216
  if (previous) {
219
217
  if (previous.state === 'skipped') return this.predecessor(previous);
218
+ if (previous.state === 'held') return { ready: false, blockedBy: previous.blockedBy ?? id };
219
+ if (previous.state === 'failed' && this.terminal(id)?.code === 'interrupted_unknown') return { ready: false, blockedBy: id };
220
220
  if (previous.state === 'failed')
221
221
  throw new Error(
222
222
  'The previous turn did not finish. Review it before resending this message.',
@@ -230,23 +230,12 @@ export class DurableTurnQueue {
230
230
  }
231
231
  const terminal = this.terminal(id);
232
232
  if (!terminal) return { ready: false };
233
+ if (terminal.code === 'interrupted_unknown') return { ready: false, blockedBy: id };
233
234
  if (terminal.type !== 'done')
234
235
  throw new Error(
235
236
  'The previous turn did not finish. Review it before resending this message.',
236
237
  );
237
- const receipt = this.deps.logs
238
- .read(id)
239
- .frames.find((frame) => frame.type === 'accepted');
240
- const scope = receipt?.scope as Record<string, unknown> | undefined;
241
- const source =
242
- scope?.kind === 'conduct' && entry.request.kind === 'code'
243
- ? entry.request.workerId!
244
- : id;
245
- if (source !== id && this.terminal(source)?.type !== 'done')
246
- throw new Error(
247
- 'The worker did not finish. Review it before resending this message.',
248
- );
249
- const resume = this.session(source);
238
+ const resume = this.session(id);
250
239
  if (!resume)
251
240
  throw new Error(
252
241
  'The previous turn has no session to continue. Start a new conversation.',
@@ -254,29 +243,37 @@ export class DurableTurnQueue {
254
243
  return { ready: true, resume };
255
244
  }
256
245
  wake(): void {
257
- if (this.stopped || this.pumping) return;
246
+ if (this.stopped || this.pumping || !this.deps.logs.runtime.writable) return;
258
247
  this.pumping = true;
259
248
  queueMicrotask(() => {
260
249
  this.pumping = false;
261
- if (this.stopped) return;
250
+ if (this.stopped || !this.deps.logs.runtime.writable) return;
262
251
  const occupied = new Set<string>();
263
252
  for (const [id, entry] of this.entries) {
264
253
  const lane = turnLane(entry.request);
265
254
  if (!this.owns(id)) continue;
255
+ if (entry.state === 'held') continue;
266
256
  if (occupied.has(lane)) continue;
267
- occupied.add(lane);
268
- if (entry.state !== 'queued' || this.scheduled.has(id)) continue;
257
+ if (entry.state !== 'queued' || this.scheduled.has(id)) { occupied.add(lane); continue; }
269
258
  try {
270
- if (!this.predecessor(entry).ready) continue;
259
+ const previous = this.predecessor(entry);
260
+ if (!previous.ready) {
261
+ if (previous.blockedBy) {
262
+ this.save({ ...entry, state: 'held', blockedBy: previous.blockedBy });
263
+ this.confirm(id);
264
+ }
265
+ continue;
266
+ }
271
267
  } catch (error) {
272
268
  this.fail(entry, String((error as Error).message));
273
269
  continue;
274
270
  }
271
+ occupied.add(lane);
275
272
  this.scheduled.add(id);
276
273
  void this.deps.lanes
277
274
  .run(turnLane(entry.request), async () => {
278
275
  const current = this.entries.get(id)!;
279
- if (this.stopped || current.state !== 'queued') return;
276
+ if (this.stopped || !this.deps.logs.runtime.writable || current.state !== 'queued') return;
280
277
  const previous = this.predecessor(current);
281
278
  if (!previous.ready) return;
282
279
  this.save({ ...current, state: 'running' });
@@ -299,9 +296,9 @@ export class DurableTurnQueue {
299
296
  'The turn ended before completion. Review it before resending.',
300
297
  );
301
298
  })
302
- .catch((error) =>
303
- this.fail(this.entries.get(id)!, String(error.message)),
304
- )
299
+ .catch((error) => {
300
+ if (this.deps.logs.runtime.writable) this.fail(this.entries.get(id)!, String(error.message));
301
+ })
305
302
  .finally(() => {
306
303
  this.scheduled.delete(id);
307
304
  this.wake();
@@ -321,15 +318,15 @@ export class DurableTurnQueue {
321
318
  if (frame) this.deps.sendRaw(frame);
322
319
  return;
323
320
  }
324
- if (entry.state !== 'queued')
321
+ if (entry.state !== 'queued' && entry.state !== 'held')
325
322
  throw new Error('This message has already started or left the queue.');
326
323
  if (action === 'steer') {
324
+ if (entry.state === 'held') throw new Error('Review the interrupted turn before using this follow-up.');
327
325
  if (entry.request.images?.length)
328
326
  throw new Error('Attachments must run as a separate turn.');
329
327
  if (!activeId || !this.deps.steer)
330
328
  throw new Error('There is no active turn to influence.');
331
329
  const active = this.entries.get(activeId);
332
- // For a spawned fleet worker, the active request uses the worker's own ID.
333
330
  if (
334
331
  active
335
332
  ? turnLane(active.request) !== turnLane(entry.request) ||
@@ -0,0 +1,207 @@
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 { dirname } from 'node:path';
5
+ import type { HarnessRequest, RunReview } from '@lucidity/shared';
6
+ import type { TurnFrame, TurnState } from './turnLog.js';
7
+
8
+ const terminalTypes = new Set(['done', 'error', 'cancelled']);
9
+
10
+ function canonical(value: unknown): string {
11
+ if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
12
+ if (value && typeof value === 'object')
13
+ return `{${Object.entries(value).filter(([, v]) => v !== undefined).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(',')}}`;
14
+ return JSON.stringify(value);
15
+ }
16
+
17
+ export function conversationKey(request: { kind: string; repoId?: string; workerId?: string; mode?: string }): string {
18
+ return request.kind === 'code'
19
+ ? JSON.stringify(['code', request.repoId, request.workerId ?? request.mode ?? 'worktree'])
20
+ : request.kind;
21
+ }
22
+
23
+ /** Local execution authority. Transactions commit before their receipts reach the transport. */
24
+ export class RuntimeStore {
25
+ private db: any;
26
+ private storageError?: Error;
27
+ get writable(): boolean { return !this.storageError; }
28
+ private write<T>(action: () => T): T {
29
+ if (this.storageError) throw new Error(`Runtime storage is unavailable until restart: ${this.storageError.message}`);
30
+ try { return action(); }
31
+ catch (error) {
32
+ const code = (error as { code?: string })?.code ?? '';
33
+ if (code.includes('SQLITE') || code === 'ERR_INVALID_STATE')
34
+ this.storageError = error instanceof Error ? error : new Error(String(error));
35
+ throw error;
36
+ }
37
+ }
38
+ constructor(path: string) {
39
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
40
+ this.db = new DatabaseSync(path);
41
+ chmodSync(path, 0o600);
42
+ this.db.exec(`
43
+ PRAGMA journal_mode=WAL;
44
+ PRAGMA synchronous=FULL;
45
+ PRAGMA busy_timeout=5000;
46
+ CREATE TABLE IF NOT EXISTS runs (
47
+ id TEXT PRIMARY KEY, command TEXT, conversation TEXT,
48
+ state TEXT NOT NULL DEFAULT 'accepted', cursor INTEGER NOT NULL DEFAULT 0,
49
+ terminal TEXT, updated INTEGER NOT NULL
50
+ );
51
+ CREATE INDEX IF NOT EXISTS runs_conversation ON runs(conversation, updated);
52
+ CREATE TABLE IF NOT EXISTS events (
53
+ run_id TEXT NOT NULL, seq INTEGER NOT NULL, frame TEXT NOT NULL,
54
+ PRIMARY KEY(run_id, seq)
55
+ );
56
+ CREATE TABLE IF NOT EXISTS records (
57
+ bucket TEXT NOT NULL, id TEXT NOT NULL, value TEXT NOT NULL,
58
+ PRIMARY KEY(bucket, id)
59
+ );
60
+ `);
61
+ }
62
+
63
+ transaction<T>(action: () => T): T {
64
+ return this.write(() => {
65
+ this.db.exec('BEGIN IMMEDIATE');
66
+ try {
67
+ const result = action();
68
+ this.db.exec('COMMIT');
69
+ return result;
70
+ } catch (error) {
71
+ try { this.db.exec('ROLLBACK'); } catch { /* preserve the original storage failure */ }
72
+ throw error;
73
+ }
74
+ });
75
+ }
76
+
77
+ get<T>(bucket: string, id: string): T | undefined {
78
+ const row = this.db.prepare('SELECT value FROM records WHERE bucket=? AND id=?').get(bucket, id);
79
+ return row ? JSON.parse(row.value) as T : undefined;
80
+ }
81
+ set(bucket: string, id: string, value: unknown): void {
82
+ this.write(() => this.db.prepare('INSERT INTO records VALUES (?, ?, ?) ON CONFLICT(bucket,id) DO UPDATE SET value=excluded.value')
83
+ .run(bucket, id, JSON.stringify(value)));
84
+ }
85
+ delete(bucket: string, id: string): void {
86
+ this.write(() => this.db.prepare('DELETE FROM records WHERE bucket=? AND id=?').run(bucket, id));
87
+ }
88
+ list<T>(bucket: string): T[] {
89
+ return this.db.prepare('SELECT value FROM records WHERE bucket=? ORDER BY rowid').all(bucket)
90
+ .map((row: { value: string }) => JSON.parse(row.value) as T);
91
+ }
92
+
93
+ /** The command and its first replayable receipt are one durable operation. */
94
+ accept(request: HarnessRequest, queuedEntry?: unknown): { duplicate: boolean; frames: TurnFrame[] } {
95
+ return this.transaction(() => {
96
+ const payload = canonical(request);
97
+ const old = this.db.prepare('SELECT command, cursor FROM runs WHERE id=?').get(request.id);
98
+ if (old?.command && old.command !== payload)
99
+ throw new Error('This request ID already belongs to different input.');
100
+ if (old) return { duplicate: true, frames: this.read(request.id).frames };
101
+ if (request.kind === 'code' && request.recoveryOf) {
102
+ const review = this.get<RunReview>('run-reviews', request.recoveryOf);
103
+ const source = this.command(request.recoveryOf);
104
+ if (!review || review.reviewId !== request.recoveryReviewId || review.continuationId !== request.id ||
105
+ source?.kind !== 'code' || conversationKey(source) !== conversationKey(request) ||
106
+ this.read(source.id).frames.at(-1)?.code !== 'interrupted_unknown' ||
107
+ review.continuedAt || !request.prompt.trim() || request.prompt.trim().startsWith('/') || request.prompt.trim() === source.prompt.trim())
108
+ throw new Error('A current review is required before continuing this interrupted turn.');
109
+ this.set('run-reviews', source.id, { ...review, continuedAt: new Date().toISOString(), instruction: request.prompt });
110
+ }
111
+ this.db.prepare('INSERT INTO runs (id,command,conversation,updated) VALUES (?,?,?,?)')
112
+ .run(request.id, payload, conversationKey(request), Date.now());
113
+ const scope = {
114
+ kind: request.kind,
115
+ ...('repoId' in request ? { repoId: request.repoId } : {}),
116
+ ...('workerId' in request ? { workerId: request.workerId } : {}),
117
+ ...('mode' in request ? { mode: request.mode } : {}),
118
+ };
119
+ const frames = [this.appendInside(request.id, { type: 'accepted', requestId: request.id, scope })];
120
+ if (queuedEntry) {
121
+ this.set('queue', request.id, queuedEntry);
122
+ frames.push(this.appendInside(request.id, { type: 'queue_state', requestId: request.id, state: 'queued' }));
123
+ }
124
+ return { duplicate: false, frames };
125
+ });
126
+ }
127
+
128
+ private appendInside(id: string, event: Record<string, unknown>): TurnFrame {
129
+ this.db.prepare('INSERT OR IGNORE INTO runs (id,updated) VALUES (?,?)').run(id, Date.now());
130
+ const run = this.db.prepare('SELECT cursor, terminal FROM runs WHERE id=?').get(id);
131
+ if (run.terminal) {
132
+ // Reconfirm the committed outcome, never continue a completed attempt.
133
+ this.set('protocol-fault', id, { type: event.type, at: new Date().toISOString() });
134
+ return JSON.parse(run.terminal);
135
+ }
136
+ const frame = { ...event, seq: run.cursor + 1 };
137
+ const serialized = JSON.stringify(frame);
138
+ const terminal = terminalTypes.has(String(event.type));
139
+ const state = terminal ? String(event.type) : event.type === 'accepted' ? 'accepted' : event.type === 'queue_state' ? String(event.state) : 'running';
140
+ this.db.prepare('INSERT INTO events VALUES (?,?,?)').run(id, frame.seq, serialized);
141
+ this.db.prepare('UPDATE runs SET cursor=?, terminal=?, state=?, updated=? WHERE id=?')
142
+ .run(frame.seq, terminal ? serialized : null, state, Date.now(), id);
143
+ return frame;
144
+ }
145
+ append(id: string, event: Record<string, unknown>): TurnFrame {
146
+ return this.transaction(() => this.appendInside(id, event));
147
+ }
148
+
149
+ status(id: string): Omit<TurnState, 'frames'> {
150
+ const run = this.db.prepare('SELECT cursor, terminal FROM runs WHERE id=?').get(id);
151
+ return { exists: !!run, maxSeq: run?.cursor ?? 0, terminated: !!run?.terminal };
152
+ }
153
+ read(id: string): TurnState {
154
+ const status = this.status(id);
155
+ if (!status.exists) return { ...status, frames: [] };
156
+ const frames = this.db.prepare('SELECT frame FROM events WHERE run_id=? ORDER BY seq').all(id)
157
+ .map((row: { frame: string }) => JSON.parse(row.frame) as TurnFrame);
158
+ return { ...status, frames };
159
+ }
160
+
161
+ importLog(id: string, state: TurnState): void {
162
+ if (!state.exists || this.read(id).exists) return;
163
+ this.transaction(() => {
164
+ const last = [...state.frames].reverse().find((f) => terminalTypes.has(String(f.type)));
165
+ this.db.prepare('INSERT OR IGNORE INTO runs (id,cursor,terminal,state,updated) VALUES (?,?,?,?,?)')
166
+ .run(id, state.maxSeq, last ? JSON.stringify(last) : null, last ? String(last.type) : 'interrupted_unknown', Date.now());
167
+ for (const frame of state.frames)
168
+ this.db.prepare('INSERT OR IGNORE INTO events VALUES (?,?,?)').run(id, frame.seq, JSON.stringify(frame));
169
+ });
170
+ }
171
+
172
+ commands(conversation: string, page?: { before?: string; after?: string; limit: number }): { request: HarnessRequest; state: TurnState }[] {
173
+ const rows: { id: string; command: string }[] = page
174
+ ? this.db.prepare(`SELECT id,command FROM runs WHERE conversation=? AND command IS NOT NULL
175
+ AND rowid < COALESCE((SELECT rowid FROM runs WHERE id=?), 9223372036854775807)
176
+ AND rowid > COALESCE((SELECT rowid FROM runs WHERE id=?), 0)
177
+ ORDER BY rowid DESC LIMIT ?`).all(conversation, page.before ?? '', page.after ?? '', page.limit).reverse()
178
+ : this.db.prepare('SELECT id,command FROM runs WHERE conversation=? AND command IS NOT NULL ORDER BY rowid').all(conversation);
179
+ return rows.map((row) => ({ request: JSON.parse(row.command), state: this.read(row.id) }));
180
+ }
181
+ latestSession(conversation: string, after?: string): string | undefined {
182
+ return this.db.prepare(`SELECT json_extract(events.frame, '$.sessionId') AS session
183
+ FROM runs JOIN events ON events.run_id=runs.id WHERE runs.conversation=?
184
+ AND json_type(events.frame, '$.sessionId')='text'
185
+ AND runs.rowid > COALESCE((SELECT rowid FROM runs WHERE id=?), 0)
186
+ ORDER BY runs.rowid DESC, events.seq DESC LIMIT 1`).get(conversation, after ?? '')?.session;
187
+ }
188
+ lastCommand(conversation: string): string | undefined {
189
+ return this.db.prepare('SELECT id FROM runs WHERE conversation=? AND command IS NOT NULL ORDER BY rowid DESC LIMIT 1').get(conversation)?.id;
190
+ }
191
+ command(id: string): HarnessRequest | undefined {
192
+ const row = this.db.prepare('SELECT command FROM runs WHERE id=?').get(id);
193
+ return row?.command ? JSON.parse(row.command) : undefined;
194
+ }
195
+ unfinished(conversation: string): boolean {
196
+ return !!this.db.prepare('SELECT id FROM runs WHERE conversation=? AND terminal IS NULL LIMIT 1').get(conversation);
197
+ }
198
+
199
+ reconcile(owns: (id: string) => boolean): void {
200
+ for (const row of this.db.prepare('SELECT id FROM runs WHERE terminal IS NULL').all() as { id: string }[]) {
201
+ if (owns(row.id)) continue;
202
+ this.append(row.id, { type: 'error', requestId: row.id, code: 'interrupted_unknown',
203
+ message: 'Lucid restarted before this turn settled. It was not run again. Review its work before continuing.' });
204
+ }
205
+ }
206
+ close(): void { this.db.close(); }
207
+ }
@@ -122,7 +122,7 @@ export async function checkSetupProviders() {
122
122
  message: '',
123
123
  };
124
124
  } catch (e) {
125
- const health = providerFailure(e);
125
+ const health = providerFailure(e) ?? { auth: 'unknown', problem: 'unavailable' };
126
126
  return {
127
127
  id,
128
128
  label: id === 'claude' ? 'Claude' : 'Codex',
package/src/turnLog.ts CHANGED
@@ -9,23 +9,12 @@ import {
9
9
  } from 'node:fs';
10
10
  import { join } from 'node:path';
11
11
  import { TURNS_DIR } from './config.js';
12
+ import { RuntimeStore } from './runtimeStore.js';
12
13
 
13
14
  /**
14
- * Durable per-turn write-ahead log (WAL) so a dropped reply can be pulled back by the
15
- * phone instead of being lost. Each streamed turn gets one append-only file
16
- * `~/.lucidity/turns/<requestId>.jsonl`; every outgoing daemon→phone stream frame is
17
- * appended (with a monotonic `seq`) BEFORE it goes on the socket, so a frame produced
18
- * while the socket is down — or while the phone is away — survives on disk. The phone
19
- * recovers by sending a `pull` request; the daemon replays `readState().frames` after
20
- * the phone's `sinceSeq`.
21
- *
22
- * The daemon OWNS `seq` here (starting at 1, per requestId). This is the linchpin of the
23
- * whole recovery scheme: the same `seq` must appear on the live-forwarded frame, the
24
- * server's replay-on-rejoin, and a daemon pull, so the phone can de-dup across all three.
25
- * The relay forwards frames verbatim (it no longer stamps `seq`).
26
- *
27
- * Never throws — a logging or disk error must not take a turn down; it just makes that
28
- * turn unrecoverable (the live frame still goes out). Mirrors `runlog.ts`.
15
+ * SQLite owns command receipts and ordered run events. JSONL files remain bounded
16
+ * diagnostic exports and are imported once when opening an older installation.
17
+ * A storage failure rejects admission or propagates to the execution owner.
29
18
  */
30
19
 
31
20
  /** A logged frame: the exact wire frame plus its daemon-authored `seq`. */
@@ -114,59 +103,13 @@ function appendLine(path: string, line: string): boolean {
114
103
  }
115
104
  }
116
105
 
117
- /**
118
- * One turn's log. Owns the per-requestId `seq` counter (a shared handle, NOT a closure
119
- * local, so a concurrent `cancel`'s terminal frame gets the next `seq` on the same
120
- * counter). Seeds itself from any existing file so seq keeps climbing across a daemon
121
- * restart (a re-created handle resumes from the file's `maxSeq`).
122
- */
123
- export class TurnLog {
124
- private readonly path: string;
125
- private readonly maxBytes: number;
126
- private nextSeq: number;
127
- private bytes: number;
128
- private terminatedFlag: boolean;
129
-
130
- constructor(requestId: string, dir: string, maxBytes = MAX_TURN_LOG_BYTES) {
131
- this.path = join(dir, `${requestId}.jsonl`);
132
- this.maxBytes = maxBytes;
133
- const st = scanTurnFile(this.path);
134
- this.nextSeq = st.maxSeq + 1;
135
- this.bytes = st.bytes;
136
- this.terminatedFlag = st.terminated;
137
- }
138
-
139
- get terminated(): boolean {
140
- return this.terminatedFlag;
141
- }
142
-
143
- /** Stamp the next `seq`, append the frame (unless a droppable delta past the byte cap),
144
- * and return the stamped frame to put on the wire. */
145
- write(event: Record<string, unknown>): TurnFrame {
146
- const seq = this.nextSeq++;
147
- const frame: TurnFrame = { ...event, seq };
148
- const type = typeof event.type === 'string' ? event.type : '';
149
- const droppable = type === 'delta' && this.bytes >= this.maxBytes;
150
- if (!droppable) {
151
- const line = JSON.stringify(frame) + '\n';
152
- if (appendLine(this.path, line))
153
- this.bytes += Buffer.byteLength(line, 'utf8');
154
- }
155
- if (isTerminalType(type)) this.terminatedFlag = true;
156
- return frame;
157
- }
158
- }
159
-
160
- /**
161
- * All turn logs for this daemon. Keeps an in-memory {@link TurnLog} per in-flight turn
162
- * (the live seq counter), dropped once the turn terminates — the file lives on for 24h.
163
- * The file is the source of truth for replay ({@link read}).
164
- */
106
+ /** Compatibility reader/exporter around the transactional local runtime ledger. */
165
107
  export class TurnLogStore {
166
108
  private readonly dir: string;
167
109
  private readonly clock: () => number;
168
110
  private readonly maxBytes: number;
169
- private readonly logs = new Map<string, TurnLog>();
111
+ private readonly exportBytes = new Map<string, number>();
112
+ readonly runtime: RuntimeStore;
170
113
 
171
114
  queueDirectory(): string {
172
115
  return join(this.dir, 'queue');
@@ -178,6 +121,7 @@ export class TurnLogStore {
178
121
  this.dir = opts.dir ?? TURNS_DIR;
179
122
  this.clock = opts.now ?? Date.now;
180
123
  this.maxBytes = opts.maxBytes ?? MAX_TURN_LOG_BYTES;
124
+ this.runtime = new RuntimeStore(join(this.dir, 'runtime.sqlite'));
181
125
  try {
182
126
  mkdirSync(this.dir, { recursive: true });
183
127
  } catch {
@@ -187,24 +131,37 @@ export class TurnLogStore {
187
131
 
188
132
  /** Log + stamp one outgoing stream frame; returns the stamped frame to send. */
189
133
  append(requestId: string, event: Record<string, unknown>): TurnFrame {
190
- let log = this.logs.get(requestId);
191
- if (!log) {
192
- log = new TurnLog(requestId, this.dir, this.maxBytes);
193
- this.logs.set(requestId, log);
134
+ if (!this.runtime.status(requestId).exists) this.read(requestId);
135
+ const before = this.runtime.status(requestId);
136
+ const frame = this.runtime.append(requestId, event);
137
+ if (before.terminated) return frame;
138
+ // Bounded diagnostic exports are optional; a failed export never loses the SQLite event.
139
+ const path = join(this.dir, `${requestId}.jsonl`);
140
+ const bytes = this.exportBytes.get(requestId) ?? (existsSync(path) ? statSync(path).size : 0);
141
+ if (event.type !== 'delta' || bytes < this.maxBytes) {
142
+ const line = JSON.stringify(frame) + '\n';
143
+ if (appendLine(path, line)) this.exportBytes.set(requestId, bytes + Buffer.byteLength(line));
194
144
  }
195
- const frame = log.write(event);
196
- if (log.terminated) this.logs.delete(requestId); // free memory; file persists
145
+ if (TERMINAL_TYPES.has(String(event.type))) this.exportBytes.delete(requestId);
197
146
  return frame;
198
147
  }
199
148
 
200
- /** The durable state of a turn, read from disk — for serving a `pull`. */
201
149
  read(requestId: string): TurnState {
202
- const { exists, frames, maxSeq, terminated } = scanTurnFile(
203
- join(this.dir, `${requestId}.jsonl`),
204
- );
205
- return { exists, frames, maxSeq, terminated };
150
+ const state = this.runtime.read(requestId);
151
+ if (state.exists) return state;
152
+ this.runtime.importLog(requestId, scanTurnFile(join(this.dir, `${requestId}.jsonl`)));
153
+ return this.runtime.read(requestId);
206
154
  }
207
155
 
156
+ /** Startup recovery is independent of whether a phone asks to replay a turn. */
157
+ reconcile(owns: (id: string) => boolean): void {
158
+ for (const name of readdirSync(this.dir))
159
+ if (name.endsWith('.jsonl')) this.read(name.slice(0, -6));
160
+ this.runtime.reconcile(owns);
161
+ }
162
+
163
+ close(): void { this.runtime.close(); }
164
+
208
165
  /** Delete turn logs whose file hasn't been touched in `maxAgeMs`. Never throws. */
209
166
  prune(maxAgeMs: number = TURN_LOG_MAX_AGE_MS): void {
210
167
  const now = this.clock();