@andorra-labs/code 0.1.11 → 0.1.13

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 (614) hide show
  1. package/README.md +8 -2
  2. package/THIRD_PARTY_NOTICES.md +15 -0
  3. package/dist/src/account-presentation.d.ts +1 -37
  4. package/dist/src/account-presentation.js +2 -42
  5. package/dist/src/activity.d.ts +0 -25
  6. package/dist/src/activity.js +1 -23
  7. package/dist/src/agent-definitions.d.ts +0 -26
  8. package/dist/src/agent-definitions.js +0 -43
  9. package/dist/src/agent-execution.d.ts +0 -2
  10. package/dist/src/agent-execution.js +59 -414
  11. package/dist/src/agent-mcp-catalog.d.ts +0 -8
  12. package/dist/src/agent-mcp-catalog.js +0 -2
  13. package/dist/src/agent-mcp.d.ts +0 -56
  14. package/dist/src/agent-mcp.js +14 -153
  15. package/dist/src/agent-modifiers.d.ts +0 -1
  16. package/dist/src/agent-modifiers.js +25 -68
  17. package/dist/src/analytics.d.ts +0 -66
  18. package/dist/src/analytics.js +0 -45
  19. package/dist/src/anthropic-console-auth.d.ts +0 -24
  20. package/dist/src/anthropic-console-auth.js +0 -37
  21. package/dist/src/anthropic-credentials.d.ts +0 -25
  22. package/dist/src/anthropic-credentials.js +0 -28
  23. package/dist/src/app-server/protocol.d.ts +19 -244
  24. package/dist/src/app-server/protocol.js +1 -132
  25. package/dist/src/app-server/reasoning.d.ts +0 -31
  26. package/dist/src/app-server/reasoning.js +0 -54
  27. package/dist/src/app-server/terminal.d.ts +0 -36
  28. package/dist/src/app-server/terminal.js +3 -39
  29. package/dist/src/app-server/workspace.d.ts +0 -167
  30. package/dist/src/app-server/workspace.js +4 -406
  31. package/dist/src/app-server.d.ts +33 -918
  32. package/dist/src/app-server.js +608 -2984
  33. package/dist/src/artifacts.d.ts +0 -10
  34. package/dist/src/artifacts.js +1 -11
  35. package/dist/src/attachments.d.ts +4 -98
  36. package/dist/src/attachments.js +10 -130
  37. package/dist/src/auth/AuthManager.d.ts +0 -93
  38. package/dist/src/auth/AuthManager.js +3 -165
  39. package/dist/src/auth/callback-page.d.ts +0 -1
  40. package/dist/src/auth/callback-page.js +0 -4
  41. package/dist/src/auth/callback.d.ts +0 -25
  42. package/dist/src/auth/callback.js +1 -29
  43. package/dist/src/auth/deployment.d.ts +0 -16
  44. package/dist/src/auth/deployment.js +0 -16
  45. package/dist/src/auth/index.d.ts +0 -11
  46. package/dist/src/auth/index.js +0 -11
  47. package/dist/src/auth/lock.d.ts +0 -1
  48. package/dist/src/auth/lock.js +0 -1
  49. package/dist/src/auth/store.d.ts +7 -108
  50. package/dist/src/auth/store.js +21 -129
  51. package/dist/src/auth/types.d.ts +0 -8
  52. package/dist/src/auth-commands.d.ts +0 -5
  53. package/dist/src/auth-commands.js +0 -1
  54. package/dist/src/automation-runner.d.ts +0 -9
  55. package/dist/src/automation-runner.js +0 -11
  56. package/dist/src/automation-service.d.ts +0 -10
  57. package/dist/src/automation-service.js +3 -17
  58. package/dist/src/automation-tool.js +0 -5
  59. package/dist/src/automation-worker-shutdown.d.ts +0 -1
  60. package/dist/src/automation-worker-shutdown.js +0 -3
  61. package/dist/src/automations.d.ts +23 -2
  62. package/dist/src/automations.js +91 -12
  63. package/dist/src/background-tasks.d.ts +0 -23
  64. package/dist/src/background-tasks.js +0 -11
  65. package/dist/src/boot-trace.d.ts +0 -13
  66. package/dist/src/boot-trace.js +1 -14
  67. package/dist/src/browser-activity.js +0 -2
  68. package/dist/src/browser-bridge.d.ts +0 -2
  69. package/dist/src/browser-bridge.js +0 -27
  70. package/dist/src/browser-captcha-tool.d.ts +0 -13
  71. package/dist/src/browser-captcha-tool.js +3 -35
  72. package/dist/src/browser-extensions-tool.d.ts +24 -0
  73. package/dist/src/browser-extensions-tool.js +137 -0
  74. package/dist/src/browser-extensions.d.ts +127 -0
  75. package/dist/src/browser-extensions.js +729 -0
  76. package/dist/src/browser-observation.d.ts +0 -15
  77. package/dist/src/browser-observation.js +1 -22
  78. package/dist/src/browser-panel-tool.d.ts +10 -25
  79. package/dist/src/browser-panel-tool.js +64 -60
  80. package/dist/src/browser-runner.d.ts +0 -1
  81. package/dist/src/browser-runner.js +7 -46
  82. package/dist/src/browser-server.d.ts +0 -6
  83. package/dist/src/browser-server.js +6 -229
  84. package/dist/src/browser-session.d.ts +0 -25
  85. package/dist/src/browser-session.js +1 -71
  86. package/dist/src/browser-stealth.d.ts +0 -12
  87. package/dist/src/browser-stealth.js +0 -36
  88. package/dist/src/browser-ui/app.js +7 -174
  89. package/dist/src/browser-ui/style.css +0 -68
  90. package/dist/src/browser-ui/tokens.css +11 -93
  91. package/dist/src/browser-view.d.ts +52 -290
  92. package/dist/src/browser-view.js +354 -567
  93. package/dist/src/capabilities.d.ts +0 -8
  94. package/dist/src/capabilities.js +0 -29
  95. package/dist/src/capsolver.d.ts +0 -13
  96. package/dist/src/capsolver.js +0 -15
  97. package/dist/src/clarification-ui.d.ts +0 -7
  98. package/dist/src/clarification-ui.js +0 -8
  99. package/dist/src/claude-executable.d.ts +0 -1
  100. package/dist/src/claude-executable.js +1 -2
  101. package/dist/src/claude-provider.d.ts +6 -19
  102. package/dist/src/claude-provider.js +166 -61
  103. package/dist/src/cli-executable.d.ts +0 -16
  104. package/dist/src/cli-executable.js +0 -7
  105. package/dist/src/cli-process.d.ts +0 -26
  106. package/dist/src/cli-process.js +0 -18
  107. package/dist/src/cli-sign-in.d.ts +0 -20
  108. package/dist/src/cli-sign-in.js +1 -17
  109. package/dist/src/cli.d.ts +3 -56
  110. package/dist/src/cli.js +193 -702
  111. package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +4 -59
  112. package/dist/src/code-intelligence/CodeIntelligenceManager.js +27 -100
  113. package/dist/src/code-intelligence/ContextLedger.d.ts +0 -4
  114. package/dist/src/code-intelligence/ContextLedger.js +0 -10
  115. package/dist/src/code-intelligence/ContextRouter.d.ts +0 -6
  116. package/dist/src/code-intelligence/ContextRouter.js +0 -8
  117. package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.d.ts +0 -2
  118. package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.js +5 -12
  119. package/dist/src/code-intelligence/codegraph/CodeGraphProvider.d.ts +0 -6
  120. package/dist/src/code-intelligence/codegraph/CodeGraphProvider.js +0 -6
  121. package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.d.ts +0 -5
  122. package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.js +1 -17
  123. package/dist/src/code-intelligence/codegraph/repoExploreTool.d.ts +0 -5
  124. package/dist/src/code-intelligence/codegraph/repoExploreTool.js +0 -5
  125. package/dist/src/code-intelligence/repository.d.ts +0 -9
  126. package/dist/src/code-intelligence/repository.js +1 -11
  127. package/dist/src/code-intelligence/types.d.ts +0 -8
  128. package/dist/src/codex-auth.d.ts +0 -44
  129. package/dist/src/codex-auth.js +0 -45
  130. package/dist/src/codex-browser-auth.d.ts +0 -13
  131. package/dist/src/codex-browser-auth.js +3 -20
  132. package/dist/src/codex-errors.js +0 -2
  133. package/dist/src/codex-executable.d.ts +0 -2
  134. package/dist/src/codex-executable.js +1 -7
  135. package/dist/src/codex-provider.d.ts +0 -13
  136. package/dist/src/codex-provider.js +1 -26
  137. package/dist/src/codex-rpc.d.ts +0 -10
  138. package/dist/src/codex-rpc.js +0 -12
  139. package/dist/src/coding-tools.d.ts +6 -27
  140. package/dist/src/coding-tools.js +193 -205
  141. package/dist/src/command-metrics.d.ts +0 -4
  142. package/dist/src/command-output-tap.d.ts +0 -11
  143. package/dist/src/command-output-tap.js +0 -3
  144. package/dist/src/command-screens.d.ts +24 -0
  145. package/dist/src/command-screens.js +132 -100
  146. package/dist/src/commands.d.ts +6 -63
  147. package/dist/src/commands.js +20 -100
  148. package/dist/src/completion-gates.d.ts +0 -47
  149. package/dist/src/completion-gates.js +0 -14
  150. package/dist/src/completion.d.ts +2 -58
  151. package/dist/src/completion.js +90 -186
  152. package/dist/src/config.d.ts +12 -116
  153. package/dist/src/config.js +41 -171
  154. package/dist/src/context-budget.d.ts +0 -22
  155. package/dist/src/context-budget.js +0 -44
  156. package/dist/src/context-compaction.d.ts +29 -6
  157. package/dist/src/context-compaction.js +94 -25
  158. package/dist/src/context-selection.d.ts +0 -24
  159. package/dist/src/context-selection.js +0 -34
  160. package/dist/src/dashboard-view.d.ts +0 -2
  161. package/dist/src/dashboard-view.js +0 -35
  162. package/dist/src/dashboard.d.ts +0 -2
  163. package/dist/src/dashboard.js +0 -9
  164. package/dist/src/deadline.d.ts +0 -45
  165. package/dist/src/deadline.js +0 -54
  166. package/dist/src/decision/ContinuationAdapter.d.ts +0 -5
  167. package/dist/src/decision/ContinuationAdapter.js +0 -5
  168. package/dist/src/decision/DecisionEngine.d.ts +0 -4
  169. package/dist/src/decision/DecisionManager.d.ts +0 -1
  170. package/dist/src/decision/DecisionManager.js +2 -7
  171. package/dist/src/decision/DecisionPolicy.d.ts +0 -1
  172. package/dist/src/decision/DecisionPolicy.js +0 -1
  173. package/dist/src/decision/FactContinuations.d.ts +11 -43
  174. package/dist/src/decision/FactContinuations.js +126 -95
  175. package/dist/src/decision/FactServiceGate.d.ts +0 -1
  176. package/dist/src/decision/FactServiceGate.js +0 -4
  177. package/dist/src/decision/PreparedSteps.d.ts +0 -15
  178. package/dist/src/decision/PreparedSteps.js +1 -11
  179. package/dist/src/decision/applyToolMenu.d.ts +0 -1
  180. package/dist/src/decision/applyToolMenu.js +1 -5
  181. package/dist/src/decision/checks.d.ts +15 -28
  182. package/dist/src/decision/checks.js +118 -49
  183. package/dist/src/decision/facts.d.ts +0 -16
  184. package/dist/src/decision/facts.js +0 -30
  185. package/dist/src/decision/guidancePolicy.js +0 -1
  186. package/dist/src/decision/hostedPolicy.d.ts +0 -6
  187. package/dist/src/decision/hostedPolicy.js +0 -7
  188. package/dist/src/decision/hostedSkills.d.ts +0 -19
  189. package/dist/src/decision/hostedSkills.js +0 -19
  190. package/dist/src/decision/optimizationPolicy.d.ts +0 -3
  191. package/dist/src/decision/optimizationPolicy.js +1 -4
  192. package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +0 -7
  193. package/dist/src/decision/providers/AndorraDecisionProvider.js +4 -27
  194. package/dist/src/decision/providers/HttpDecisionProvider.d.ts +0 -2
  195. package/dist/src/decision/providers/HttpDecisionProvider.js +0 -6
  196. package/dist/src/decision/routeTools.d.ts +0 -8
  197. package/dist/src/decision/routeTools.js +1 -8
  198. package/dist/src/decision/toolFamilies.d.ts +0 -1
  199. package/dist/src/decision/toolFamilies.js +0 -1
  200. package/dist/src/decision/toolMenu.d.ts +0 -3
  201. package/dist/src/decision/toolMenu.js +0 -4
  202. package/dist/src/decision/types.d.ts +0 -6
  203. package/dist/src/default-graph.d.ts +0 -9
  204. package/dist/src/default-graph.js +0 -9
  205. package/dist/src/delegation-changes.d.ts +0 -56
  206. package/dist/src/delegation-changes.js +15 -124
  207. package/dist/src/diff-preview.d.ts +1 -1
  208. package/dist/src/diff-preview.js +4 -12
  209. package/dist/src/duration.d.ts +0 -50
  210. package/dist/src/duration.js +0 -50
  211. package/dist/src/efficiency.d.ts +0 -39
  212. package/dist/src/efficiency.js +0 -16
  213. package/dist/src/engine/protocol.d.ts +0 -2
  214. package/dist/src/engine/protocol.js +0 -2
  215. package/dist/src/engine-streams.d.ts +13 -0
  216. package/dist/src/engine-streams.js +16 -0
  217. package/dist/src/extensions.d.ts +3 -2
  218. package/dist/src/extensions.js +76 -37
  219. package/dist/src/favicons.d.ts +0 -26
  220. package/dist/src/favicons.js +0 -34
  221. package/dist/src/file-diff.d.ts +2 -58
  222. package/dist/src/file-diff.js +0 -32
  223. package/dist/src/file-read-key.d.ts +1 -0
  224. package/dist/src/file-read-key.js +5 -0
  225. package/dist/src/file-read-state.d.ts +0 -1
  226. package/dist/src/file-read-state.js +0 -4
  227. package/dist/src/firefox-cookies.d.ts +0 -34
  228. package/dist/src/firefox-cookies.js +1 -55
  229. package/dist/src/git-identity-audit.d.ts +27 -0
  230. package/dist/src/git-identity-audit.js +286 -0
  231. package/dist/src/git-identity-guard.d.ts +4 -0
  232. package/dist/src/git-identity-guard.js +998 -0
  233. package/dist/src/git-identity-hold.d.ts +12 -0
  234. package/dist/src/git-identity-hold.js +81 -0
  235. package/dist/src/git-summary.d.ts +0 -58
  236. package/dist/src/git-summary.js +2 -212
  237. package/dist/src/goal-completion-verification.d.ts +2 -2
  238. package/dist/src/goal-completion-verification.js +3 -6
  239. package/dist/src/graph-account.d.ts +0 -21
  240. package/dist/src/graph-account.js +0 -17
  241. package/dist/src/graph-editor-session.d.ts +0 -1
  242. package/dist/src/graph-editor-session.js +1 -3
  243. package/dist/src/graph-health.d.ts +7 -49
  244. package/dist/src/graph-health.js +35 -46
  245. package/dist/src/graph-manager-chat.d.ts +27 -128
  246. package/dist/src/graph-manager-chat.js +36 -166
  247. package/dist/src/graph-provider-portability.d.ts +1 -21
  248. package/dist/src/graph-provider-portability.js +6 -45
  249. package/dist/src/graph-quota.d.ts +0 -33
  250. package/dist/src/graph-quota.js +1 -44
  251. package/dist/src/graph-runner.d.ts +0 -1
  252. package/dist/src/graph-runner.js +47 -387
  253. package/dist/src/graph-selection.d.ts +0 -14
  254. package/dist/src/graph-selection.js +0 -14
  255. package/dist/src/graph-server.d.ts +3 -11
  256. package/dist/src/graph-server.js +70 -111
  257. package/dist/src/graph-studio-features.d.ts +0 -5
  258. package/dist/src/graph-studio-features.js +2 -42
  259. package/dist/src/graph-sync.d.ts +0 -78
  260. package/dist/src/graph-sync.js +5 -201
  261. package/dist/src/graph-tool.d.ts +0 -18
  262. package/dist/src/graph-tool.js +0 -27
  263. package/dist/src/graph-ui/app.js +229 -498
  264. package/dist/src/graph-ui/compat.js +0 -7
  265. package/dist/src/graph-ui/controls.css +47 -43
  266. package/dist/src/graph-ui/controls.js +0 -88
  267. package/dist/src/graph-ui/drafts.js +0 -12
  268. package/dist/src/graph-ui/edge-router.js +0 -62
  269. package/dist/src/graph-ui/embed.js +0 -59
  270. package/dist/src/graph-ui/icons.js +2 -7
  271. package/dist/src/graph-ui/index.html +2 -2
  272. package/dist/src/graph-ui/library.css +0 -5
  273. package/dist/src/graph-ui/manager-markdown.js +0 -11
  274. package/dist/src/graph-ui/manager-state.js +110 -49
  275. package/dist/src/graph-ui/manager.css +2 -20
  276. package/dist/src/graph-ui/manager.js +251 -166
  277. package/dist/src/graph-ui/model-picker.js +250 -0
  278. package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
  279. package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
  280. package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
  281. package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
  282. package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
  283. package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
  284. package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
  285. package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
  286. package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
  287. package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
  288. package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
  289. package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
  290. package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
  291. package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
  292. package/dist/src/graph-ui/sidebar.js +2 -3
  293. package/dist/src/graph-ui/skill-picker.js +373 -39
  294. package/dist/src/graph-ui/studio-canvas.js +3 -38
  295. package/dist/src/graph-ui/studio.css +0 -18
  296. package/dist/src/graph-ui/studio.js +3 -71
  297. package/dist/src/graph-ui/style.css +11 -134
  298. package/dist/src/graph-ui/theme.js +1 -26
  299. package/dist/src/graph-ui/tokens.css +15 -114
  300. package/dist/src/graphs.d.ts +7 -156
  301. package/dist/src/graphs.js +72 -273
  302. package/dist/src/grep-regex-worker.js +0 -2
  303. package/dist/src/grep-regex.d.ts +1 -5
  304. package/dist/src/grep-regex.js +6 -8
  305. package/dist/src/grok-provider.d.ts +0 -17
  306. package/dist/src/grok-provider.js +1 -26
  307. package/dist/src/handoffs.d.ts +0 -11
  308. package/dist/src/handoffs.js +0 -13
  309. package/dist/src/hardened-runtime.d.ts +0 -10
  310. package/dist/src/hardened-runtime.js +8 -46
  311. package/dist/src/harness-home.d.ts +21 -0
  312. package/dist/src/harness-home.js +87 -0
  313. package/dist/src/host-process-guard.d.ts +0 -50
  314. package/dist/src/host-process-guard.js +0 -641
  315. package/dist/src/limits.d.ts +0 -64
  316. package/dist/src/limits.js +0 -62
  317. package/dist/src/managed-sign-in.d.ts +0 -12
  318. package/dist/src/managed-sign-in.js +0 -16
  319. package/dist/src/markdown.d.ts +0 -28
  320. package/dist/src/markdown.js +1 -175
  321. package/dist/src/mcp.d.ts +21 -82
  322. package/dist/src/mcp.js +228 -237
  323. package/dist/src/membership-errors.d.ts +0 -14
  324. package/dist/src/membership-errors.js +0 -13
  325. package/dist/src/membership.d.ts +2 -60
  326. package/dist/src/membership.js +0 -85
  327. package/dist/src/memory/LocalToolMemory.d.ts +0 -1
  328. package/dist/src/memory/LocalToolMemory.js +2 -7
  329. package/dist/src/memory/MemoryDistiller.js +0 -15
  330. package/dist/src/memory/MemoryManager.d.ts +0 -3
  331. package/dist/src/memory/MemoryManager.js +6 -18
  332. package/dist/src/memory/MemoryPolicy.d.ts +0 -2
  333. package/dist/src/memory/MemoryPolicy.js +0 -2
  334. package/dist/src/memory/MemoryProvider.d.ts +0 -6
  335. package/dist/src/memory/MemoryRetriever.js +0 -7
  336. package/dist/src/memory/PermissionMemoryProvider.d.ts +0 -1
  337. package/dist/src/memory/PermissionMemoryProvider.js +0 -1
  338. package/dist/src/memory/ProjectMemory.d.ts +42 -0
  339. package/dist/src/memory/ProjectMemory.js +285 -0
  340. package/dist/src/memory/ToolFailureLessons.d.ts +0 -3
  341. package/dist/src/memory/ToolFailureLessons.js +0 -6
  342. package/dist/src/memory/index.d.ts +1 -0
  343. package/dist/src/memory/index.js +1 -0
  344. package/dist/src/memory/providers/NoOpMemoryProvider.d.ts +0 -1
  345. package/dist/src/memory/providers/NoOpMemoryProvider.js +0 -1
  346. package/dist/src/memory/redaction.d.ts +0 -5
  347. package/dist/src/memory/redaction.js +0 -11
  348. package/dist/src/memory/repository.d.ts +0 -6
  349. package/dist/src/memory/repository.js +2 -12
  350. package/dist/src/memory/types.d.ts +0 -1
  351. package/dist/src/model-health-cache.d.ts +0 -38
  352. package/dist/src/model-health-cache.js +1 -49
  353. package/dist/src/model-metadata.d.ts +0 -18
  354. package/dist/src/model-metadata.js +2 -42
  355. package/dist/src/model-override.d.ts +0 -36
  356. package/dist/src/model-override.js +0 -43
  357. package/dist/src/model-tiers.d.ts +0 -13
  358. package/dist/src/model-tiers.js +0 -23
  359. package/dist/src/opencode-catalog.d.ts +0 -2
  360. package/dist/src/opencode-catalog.js +0 -11
  361. package/dist/src/opencode-cli-provider.d.ts +0 -35
  362. package/dist/src/opencode-cli-provider.js +1 -44
  363. package/dist/src/opencode-provider.d.ts +0 -2
  364. package/dist/src/opencode-provider.js +6 -22
  365. package/dist/src/package-name.d.ts +1 -0
  366. package/dist/src/package-name.js +1 -0
  367. package/dist/src/paged-transcript.d.ts +0 -11
  368. package/dist/src/paged-transcript.js +2 -20
  369. package/dist/src/palette.d.ts +0 -63
  370. package/dist/src/palette.js +0 -63
  371. package/dist/src/permissions.d.ts +0 -15
  372. package/dist/src/permissions.js +0 -17
  373. package/dist/src/powershell-pool.d.ts +0 -9
  374. package/dist/src/powershell-pool.js +3 -26
  375. package/dist/src/process-warnings.d.ts +4 -0
  376. package/dist/src/process-warnings.js +103 -0
  377. package/dist/src/profile.d.ts +0 -43
  378. package/dist/src/profile.js +0 -43
  379. package/dist/src/project-reservation.d.ts +11 -0
  380. package/dist/src/project-reservation.js +143 -0
  381. package/dist/src/provider-connection.d.ts +0 -18
  382. package/dist/src/provider-connection.js +0 -39
  383. package/dist/src/provider-engine.d.ts +0 -21
  384. package/dist/src/provider-engine.js +3 -98
  385. package/dist/src/provider-import.d.ts +0 -49
  386. package/dist/src/provider-import.js +0 -60
  387. package/dist/src/provider-keys.d.ts +1 -36
  388. package/dist/src/provider-keys.js +5 -48
  389. package/dist/src/provider-settings.d.ts +0 -2
  390. package/dist/src/provider-settings.js +0 -32
  391. package/dist/src/providers.d.ts +0 -217
  392. package/dist/src/providers.js +0 -315
  393. package/dist/src/pull-requests.d.ts +0 -173
  394. package/dist/src/pull-requests.js +5 -195
  395. package/dist/src/qa/browser/PlaywrightRunner.d.ts +0 -7
  396. package/dist/src/qa/browser/PlaywrightRunner.js +2 -16
  397. package/dist/src/qa/command-policy.d.ts +0 -23
  398. package/dist/src/qa/command-policy.js +0 -30
  399. package/dist/src/qa/guidance.d.ts +0 -21
  400. package/dist/src/qa/guidance.js +0 -20
  401. package/dist/src/qa/profile/ProjectInspector.d.ts +0 -4
  402. package/dist/src/qa/profile/ProjectInspector.js +0 -6
  403. package/dist/src/qa/profile/QaConfigLoader.d.ts +0 -7
  404. package/dist/src/qa/profile/QaConfigLoader.js +0 -6
  405. package/dist/src/qa/profile/QaProfile.d.ts +0 -7
  406. package/dist/src/qa/profile/QaProfile.js +0 -7
  407. package/dist/src/qa/profile/yaml.d.ts +0 -9
  408. package/dist/src/qa/profile/yaml.js +0 -13
  409. package/dist/src/qa/qa-authorize.d.ts +0 -19
  410. package/dist/src/qa/qa-authorize.js +4 -11
  411. package/dist/src/qa/runtime/ProcessManager.d.ts +0 -31
  412. package/dist/src/qa/runtime/ProcessManager.js +4 -41
  413. package/dist/src/qa/runtime/PtyManager.d.ts +0 -4
  414. package/dist/src/qa/runtime/PtyManager.js +2 -7
  415. package/dist/src/qa/runtime/changes.d.ts +0 -11
  416. package/dist/src/qa/runtime/changes.js +1 -3
  417. package/dist/src/qa/tools.d.ts +0 -10
  418. package/dist/src/qa/tools.js +0 -12
  419. package/dist/src/qa/types.d.ts +0 -13
  420. package/dist/src/react-runtime.d.ts +2 -21
  421. package/dist/src/react-runtime.js +106 -418
  422. package/dist/src/read-document-doc.d.ts +0 -6
  423. package/dist/src/read-document-doc.js +0 -55
  424. package/dist/src/read-document-docx.d.ts +0 -16
  425. package/dist/src/read-document-docx.js +2 -69
  426. package/dist/src/read-document-text.d.ts +0 -17
  427. package/dist/src/read-document-text.js +0 -22
  428. package/dist/src/read-document-tool.d.ts +0 -31
  429. package/dist/src/read-document-tool.js +0 -30
  430. package/dist/src/read-document.d.ts +0 -49
  431. package/dist/src/read-document.js +1 -67
  432. package/dist/src/read-image.d.ts +0 -32
  433. package/dist/src/read-image.js +0 -33
  434. package/dist/src/remote/cert.d.ts +1 -19
  435. package/dist/src/remote/cert.js +2 -51
  436. package/dist/src/remote/client.d.ts +0 -70
  437. package/dist/src/remote/client.js +2 -117
  438. package/dist/src/remote/command.js +0 -17
  439. package/dist/src/remote/engine-pool.d.ts +0 -152
  440. package/dist/src/remote/engine-pool.js +17 -335
  441. package/dist/src/remote/errors.d.ts +0 -15
  442. package/dist/src/remote/errors.js +0 -7
  443. package/dist/src/remote/network.d.ts +0 -26
  444. package/dist/src/remote/network.js +1 -34
  445. package/dist/src/remote/pairing.d.ts +16 -51
  446. package/dist/src/remote/pairing.js +50 -57
  447. package/dist/src/remote/pem.d.ts +2 -0
  448. package/dist/src/remote/pem.js +7 -0
  449. package/dist/src/remote/roots.d.ts +0 -20
  450. package/dist/src/remote/roots.js +0 -8
  451. package/dist/src/remote/serve.d.ts +0 -47
  452. package/dist/src/remote/serve.js +0 -30
  453. package/dist/src/remote/server.d.ts +0 -14
  454. package/dist/src/remote/server.js +1 -79
  455. package/dist/src/remote/types.d.ts +1 -32
  456. package/dist/src/remote/types.js +0 -10
  457. package/dist/src/run-control.d.ts +0 -7
  458. package/dist/src/run-control.js +0 -7
  459. package/dist/src/run-progress.d.ts +0 -170
  460. package/dist/src/run-progress.js +0 -285
  461. package/dist/src/run-records.d.ts +0 -443
  462. package/dist/src/run-records.js +44 -678
  463. package/dist/src/run-temp.d.ts +12 -0
  464. package/dist/src/run-temp.js +50 -0
  465. package/dist/src/runtime.d.ts +11 -227
  466. package/dist/src/runtime.js +0 -127
  467. package/dist/src/sandbox-child.js +0 -1
  468. package/dist/src/save-lock.d.ts +0 -12
  469. package/dist/src/save-lock.js +0 -28
  470. package/dist/src/screen-selection.d.ts +0 -23
  471. package/dist/src/screen-selection.js +0 -22
  472. package/dist/src/secret-redaction.d.ts +0 -12
  473. package/dist/src/secret-redaction.js +0 -45
  474. package/dist/src/session-changes.d.ts +4 -80
  475. package/dist/src/session-changes.js +25 -130
  476. package/dist/src/session-goal.d.ts +129 -0
  477. package/dist/src/session-goal.js +230 -0
  478. package/dist/src/session-monitor.d.ts +1 -10
  479. package/dist/src/session-monitor.js +2 -39
  480. package/dist/src/session-reaper.d.ts +0 -15
  481. package/dist/src/session-reaper.js +0 -14
  482. package/dist/src/session-skills.d.ts +15 -44
  483. package/dist/src/session-skills.js +75 -60
  484. package/dist/src/session-summary.d.ts +0 -26
  485. package/dist/src/session-summary.js +0 -32
  486. package/dist/src/session-title.d.ts +0 -1
  487. package/dist/src/session-title.js +0 -2
  488. package/dist/src/sessions.d.ts +2 -120
  489. package/dist/src/sessions.js +9 -178
  490. package/dist/src/shell.d.ts +3 -20
  491. package/dist/src/shell.js +8 -72
  492. package/dist/src/side-panel.d.ts +5 -99
  493. package/dist/src/side-panel.js +76 -133
  494. package/dist/src/sign-in-detection.d.ts +43 -0
  495. package/dist/src/sign-in-detection.js +154 -0
  496. package/dist/src/sign-in-offer.d.ts +17 -0
  497. package/dist/src/sign-in-offer.js +103 -0
  498. package/dist/src/skill-commands.d.ts +0 -1
  499. package/dist/src/skill-commands.js +1 -4
  500. package/dist/src/skills/bundled/control-browser/SKILL.md +1 -1
  501. package/dist/src/skills/bundled/graph-manager/SKILL.md +22 -4
  502. package/dist/src/skills/bundled/provenance.json +2 -2
  503. package/dist/src/skills/invocable-skills.d.ts +0 -18
  504. package/dist/src/skills/invocable-skills.js +0 -17
  505. package/dist/src/skills/project-skills.d.ts +0 -1
  506. package/dist/src/skills/project-skills.js +0 -3
  507. package/dist/src/skills/prompt-skills.js +0 -14
  508. package/dist/src/skills/runtime-skills.d.ts +1 -8
  509. package/dist/src/skills/runtime-skills.js +8 -32
  510. package/dist/src/stall-recovery.d.ts +0 -25
  511. package/dist/src/stall-recovery.js +0 -38
  512. package/dist/src/stray-files.d.ts +5 -0
  513. package/dist/src/stray-files.js +65 -0
  514. package/dist/src/structured-step.d.ts +0 -22
  515. package/dist/src/structured-step.js +0 -22
  516. package/dist/src/subagent-run.d.ts +0 -163
  517. package/dist/src/subagent-run.js +10 -374
  518. package/dist/src/subagent-tree.d.ts +32 -0
  519. package/dist/src/subagent-tree.js +128 -0
  520. package/dist/src/telemetry/aggregate.d.ts +0 -37
  521. package/dist/src/telemetry/aggregate.js +0 -40
  522. package/dist/src/telemetry/capture-core.d.ts +0 -87
  523. package/dist/src/telemetry/capture-core.js +0 -67
  524. package/dist/src/telemetry/capture.d.ts +0 -1
  525. package/dist/src/telemetry/capture.js +0 -3
  526. package/dist/src/telemetry/classify.d.ts +0 -58
  527. package/dist/src/telemetry/classify.js +0 -60
  528. package/dist/src/telemetry/decision-capture.d.ts +0 -1
  529. package/dist/src/telemetry/emitter.d.ts +0 -30
  530. package/dist/src/telemetry/emitter.js +1 -62
  531. package/dist/src/telemetry/gate.d.ts +0 -29
  532. package/dist/src/telemetry/gate.js +0 -22
  533. package/dist/src/telemetry/identity.d.ts +0 -13
  534. package/dist/src/telemetry/identity.js +0 -29
  535. package/dist/src/telemetry/outbox.d.ts +0 -64
  536. package/dist/src/telemetry/outbox.js +1 -108
  537. package/dist/src/telemetry/schema.d.ts +1 -49
  538. package/dist/src/telemetry/schema.js +1 -82
  539. package/dist/src/telemetry/state.d.ts +0 -53
  540. package/dist/src/telemetry/state.js +0 -64
  541. package/dist/src/telemetry/surface.d.ts +0 -31
  542. package/dist/src/telemetry/surface.js +1 -39
  543. package/dist/src/telemetry/uploader.d.ts +0 -11
  544. package/dist/src/telemetry/uploader.js +0 -46
  545. package/dist/src/telemetry/uploads.d.ts +0 -11
  546. package/dist/src/telemetry/uploads.js +0 -11
  547. package/dist/src/telemetry/version.d.ts +0 -4
  548. package/dist/src/telemetry/version.js +0 -14
  549. package/dist/src/telemetry/workspace.d.ts +0 -7
  550. package/dist/src/telemetry/workspace.js +1 -22
  551. package/dist/src/terminal-ui.d.ts +15 -524
  552. package/dist/src/terminal-ui.js +80 -876
  553. package/dist/src/test-edit-guard.d.ts +74 -0
  554. package/dist/src/test-edit-guard.js +269 -0
  555. package/dist/src/text.d.ts +0 -1
  556. package/dist/src/text.js +0 -1
  557. package/dist/src/time-limit.d.ts +0 -36
  558. package/dist/src/time-limit.js +0 -37
  559. package/dist/src/timers.d.ts +0 -161
  560. package/dist/src/timers.js +0 -126
  561. package/dist/src/todos.d.ts +0 -1
  562. package/dist/src/todos.js +0 -3
  563. package/dist/src/token-rate.d.ts +0 -94
  564. package/dist/src/token-rate.js +0 -154
  565. package/dist/src/tool-activity.d.ts +0 -6
  566. package/dist/src/tool-activity.js +1 -8
  567. package/dist/src/tool-availability.d.ts +0 -13
  568. package/dist/src/tool-availability.js +1 -14
  569. package/dist/src/tool-call-clock.d.ts +1 -4
  570. package/dist/src/tool-call-clock.js +0 -13
  571. package/dist/src/tool-catalog.d.ts +0 -11
  572. package/dist/src/tool-catalog.js +0 -23
  573. package/dist/src/tool-dependencies.d.ts +0 -5
  574. package/dist/src/tool-dependencies.js +0 -4
  575. package/dist/src/tool-diff-stats.d.ts +0 -23
  576. package/dist/src/tool-diff-stats.js +0 -49
  577. package/dist/src/tool-errors.d.ts +9 -7
  578. package/dist/src/tool-errors.js +13 -6
  579. package/dist/src/tool-failure-tracker.d.ts +3 -11
  580. package/dist/src/tool-failure-tracker.js +19 -27
  581. package/dist/src/tool-names.d.ts +0 -16
  582. package/dist/src/tool-names.js +0 -12
  583. package/dist/src/tool-profile.d.ts +6 -0
  584. package/dist/src/tool-profile.js +23 -0
  585. package/dist/src/tool-result-filter.d.ts +0 -19
  586. package/dist/src/tool-result-filter.js +1 -66
  587. package/dist/src/tool-schema-compatibility.d.ts +1 -2
  588. package/dist/src/tool-schema-compatibility.js +2 -7
  589. package/dist/src/tools.d.ts +0 -4
  590. package/dist/src/tools.js +11 -114
  591. package/dist/src/trajectory.d.ts +0 -13
  592. package/dist/src/trajectory.js +23 -79
  593. package/dist/src/transcript.d.ts +1 -37
  594. package/dist/src/transcript.js +11 -61
  595. package/dist/src/types.d.ts +2 -167
  596. package/dist/src/untracked-file-removal.d.ts +3 -0
  597. package/dist/src/untracked-file-removal.js +105 -0
  598. package/dist/src/update-check.d.ts +0 -14
  599. package/dist/src/update-check.js +2 -16
  600. package/dist/src/update.d.ts +4 -29
  601. package/dist/src/update.js +20 -98
  602. package/dist/src/usage-analytics.d.ts +17 -17
  603. package/dist/src/usage-analytics.js +168 -209
  604. package/dist/src/web-search.d.ts +0 -23
  605. package/dist/src/web-search.js +1 -27
  606. package/dist/src/widgets.d.ts +0 -25
  607. package/dist/src/widgets.js +0 -24
  608. package/dist/src/workspace-facts.d.ts +0 -12
  609. package/dist/src/workspace-facts.js +1 -18
  610. package/dist/src/workspace-git-metadata.d.ts +4 -5
  611. package/dist/src/workspace-git-metadata.js +37 -9
  612. package/dist/src/workspace-instructions.d.ts +3 -15
  613. package/dist/src/workspace-instructions.js +7 -20
  614. package/package.json +2 -2
@@ -6,25 +6,11 @@ import { configDirectory } from './config.js';
6
6
  import { writeSessionSnapshot } from './sessions.js';
7
7
  import { ToolFailureTracker } from './tool-failure-tracker.js';
8
8
  import { stopReasonPhrase } from './runtime.js';
9
- /**
10
- * The directory holding one JSON Lines event log and one JSON result per run.
11
- *
12
- * `runs/` sits inside the installation directory, beside `config.json` and `artifacts/`, so the
13
- * identity that names a record is also the last path segment of a file this process writes.
14
- */
15
9
  export function runRecordsDirectory(directory = configDirectory()) {
16
10
  return join(directory, 'runs');
17
11
  }
18
- /** The history entry a session carries while its attempt is in flight, replaced when the attempt lands. */
19
12
  export const RUNNING_TURN_SUMMARY = 'This attempt was interrupted or is still running. Verify the workspace before continuing.';
20
- /** The same entry after recovery classifies the attempt as one the engine never finished. */
21
13
  export const INTERRUPTED_TURN_SUMMARY = 'This attempt stopped unexpectedly before it finished; its work may be incomplete.';
22
- /**
23
- * What a session marker should say when the run record finalized but the session never heard how
24
- * the attempt ended. Stopped outcomes commonly carry no completion object at all — a cancel has
25
- * nothing to summarize — and then the recorded status is the only account left: a sentence about
26
- * the engine stopping unexpectedly would contradict a record that says the user cancelled.
27
- */
28
14
  export function summaryForStoppedRecord(record) {
29
15
  const summary = record.completion?.summary;
30
16
  if (typeof summary === 'string')
@@ -34,10 +20,6 @@ export function summaryForStoppedRecord(record) {
34
20
  if (record.status === 'interrupted')
35
21
  return INTERRUPTED_TURN_SUMMARY;
36
22
  const reason = typeof record.reason === 'string' && record.reason.length > 0 ? record.reason : undefined;
37
- // A record's reason is read after the colon of a sentence about the attempt, so it goes through
38
- // the same classification every other surface uses: an internal code such as
39
- // `maxNodeVisits:qa` becomes the sentence a person can act on, and a failure message is used
40
- // whole. Reading the code raw would leak the identifier this repository never shows a user.
41
23
  return reason === undefined ? 'This attempt did not finish; its work may be incomplete.' : `This attempt did not finish: ${stopReasonPhrase(reason)}.`;
42
24
  }
43
25
  export async function writeStudioRunSummary(directory, record) {
@@ -53,56 +35,25 @@ export async function writeStudioRunSummary(directory, record) {
53
35
  await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 });
54
36
  await writeSessionSnapshot(join(runRecordsDirectory(directory), `${record.id}.studio-summary`), JSON.stringify(projected) + '\n');
55
37
  }
56
- /**
57
- * The claim naming a run open — required, unlike the supplemental studio summary.
58
- *
59
- * The claim is the answer `sessionHasOpenRun` gives every rail mutation, so a run whose claim
60
- * failed to land would be invisible to the guard while its result record says the session is
61
- * live: another process could then archive, rename, or delete the live session, and the run's
62
- * final save would overwrite or recreate what that mutation did. `writeOpenRunRecord` therefore
63
- * publishes the record only once this write has landed; the snapshot layer behind it already
64
- * retries the transient rename failures (Windows AV locks) that a suppressed failure would
65
- * otherwise turn into that state.
66
- */
67
38
  async function writeOpenRunClaim(directory, claim) {
68
39
  const body = { runId: claim.runId, sessionId: claim.sessionId, pid: claim.pid ?? process.pid, claimedAt: new Date().toISOString(), startedAt: processStartedAt(), nonce: PROCESS_NONCE };
69
40
  await writeSessionSnapshot(runRecordPath(directory, claim.runId, 'open-run'), JSON.stringify(body) + '\n');
70
41
  }
71
- /** Drop a run's open claim. A run only ever owns its own claim, so this cannot clobber another's. */
72
42
  export async function clearOpenRunClaim(directory, runId) {
73
43
  await rm(runRecordPath(directory, runId, 'open-run'), { force: true }).catch(() => { });
74
44
  }
75
- /**
76
- * Remove the record of an attempt that never began.
77
- *
78
- * The claim and the record answer one question — is a run live? — and a question with no run behind
79
- * it has to have neither. A record left behind is an attempt the Runs view lists, and its live pid
80
- * tells the recovery that another process owns it, so the attempt stays `running` until that
81
- * process exits.
82
- */
83
45
  export async function removeOpenRunRecord(directory, runId) {
84
- // The claim is released only when the record is gone. A record that still says the run is live,
85
- // with no claim to say so, is a history that contradicts itself — and when the file cannot be
86
- // removed, the claim stays and the recovery classifies the attempt once its owner is gone.
87
46
  const removed = await rm(runRecordPath(directory, runId, 'json'), { force: true }).then(() => true, () => false);
88
47
  await rm(join(runRecordsDirectory(directory), `${runId}.studio-summary`), { force: true }).catch(() => { });
89
48
  if (removed)
90
49
  await clearOpenRunClaim(directory, runId);
91
50
  }
92
- /** The result file written at start; atomic, so a crash mid-write cannot tear the record. */
93
51
  export async function writeOpenRunRecord(directory, record) {
94
52
  await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 });
95
- // The claim lands before the record, and the record is not published without it: from the
96
- // moment any engine can see the open record, the guard already has its index entry. The reverse
97
- // order — or a suppressed claim failure — would leave the state this method's own guard cannot
98
- // answer: the record says the run is live while the claim, the guard's fast answer, is missing,
99
- // and a rail mutation of this session is accepted against a run that trusts the record.
100
53
  await writeOpenRunClaim(directory, { runId: record.id, sessionId: record.sessionId, pid: record.pid });
101
54
  await writeSessionSnapshot(runRecordPath(directory, record.id, 'json'), JSON.stringify(record, null, 2) + '\n');
102
- // Best effort: failure of the supplemental index must not abort a real coding run.
103
55
  await writeStudioRunSummary(directory, record).catch(() => { });
104
56
  }
105
- /** Whether a process is running. A live process owned by another user answers EPERM, not ESRCH. */
106
57
  export function isPidAlive(pid) {
107
58
  if (!Number.isSafeInteger(pid) || pid < 1)
108
59
  return false;
@@ -114,70 +65,29 @@ export function isPidAlive(pid) {
114
65
  return error.code === 'EPERM';
115
66
  }
116
67
  }
117
- /** This process's own start time, as the claims it writes record it. */
118
68
  export function processStartedAt() {
119
69
  return new Date(Date.now() - Math.round(process.uptime() * 1000)).toISOString();
120
70
  }
121
- /**
122
- * This process instance's identity, as the claims it writes record it.
123
- *
124
- * A pid is not an identity — the OS hands a dead process's number to the next one, and a
125
- * container that restarts within seconds reuses the same number for its replacement. A start
126
- * time compared with a tolerance cannot tell those apart either: a restarted PID-1 container
127
- * starts within the tolerance of the one it replaces, so its predecessor's claim would look
128
- * like this process's own. A value that exists only in this instance of the process answers it
129
- * exactly: the claim carries the nonce of the process that wrote it, and a claim this process
130
- * did not write is a claim of a different instance, whatever the number it carried.
131
- */
132
71
  const PROCESS_NONCE = randomUUID();
133
- /** This process instance's nonce, for a claim that carries one. */
134
72
  export function processNonce() {
135
73
  return PROCESS_NONCE;
136
74
  }
137
- /**
138
- * The workspaces this process is working in.
139
- *
140
- * The reservation is the process's rather than an engine's: an app server and an MCP or CLI
141
- * subagent in one process are two engines over one workspace, and two full-access runs in it
142
- * would write the same files at once. The unit the reservation covers is the workspace, because
143
- * that is what two overlapping runs would both write to.
144
- */
145
75
  const processWorkspaces = new Map();
146
- /**
147
- * Reserve a workspace for an engine in this process.
148
- *
149
- * @returns whether the reservation was taken; a workspace another engine in this process is
150
- * working in is not available.
151
- */
152
76
  export function claimProcessWorkspace(workspace, owner) {
153
77
  if (processWorkspaces.has(workspace))
154
78
  return false;
155
79
  processWorkspaces.set(workspace, owner);
156
80
  return true;
157
81
  }
158
- /** Give a workspace back, when the engine releasing it is the one that reserved it. */
159
82
  export function releaseProcessWorkspace(workspace, owner) {
160
83
  if (processWorkspaces.get(workspace) === owner)
161
84
  processWorkspaces.delete(workspace);
162
85
  }
163
- /**
164
- * When a running process started, as the platform can report it, or `undefined` when it cannot.
165
- *
166
- * A pid alone is not an identity: the OS reuses it, so a claim whose holder was killed can appear
167
- * to be held by an unrelated process that inherited the number, and that attempt would refuse to be
168
- * resumed for as long as the impostor lives. Comparing the start time the claim recorded for its
169
- * holder with the start time the OS reports for that pid is what tells the two apart. The probe is
170
- * deliberately best-effort — a platform that cannot answer returns nothing, and the caller falls
171
- * back to pid liveness — because being unable to check must never turn a live holder into a stale
172
- * one (which is the direction that would let two engines resume the same attempt).
173
- */
174
86
  async function processStartedAtFor(pid) {
175
87
  if (!Number.isSafeInteger(pid) || pid < 1)
176
88
  return undefined;
177
89
  try {
178
90
  if (process.platform === 'linux') {
179
- // Field 22 of `/proc/<pid>/stat` is the start time in clock ticks since boot; the process name
180
- // (field 2) may hold spaces and parentheses, so parsing starts after its last `)`.
181
91
  const stat = await readFile(`/proc/${pid}/stat`, 'utf8');
182
92
  const fields = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
183
93
  const ticks = Number(fields[19]);
@@ -200,28 +110,27 @@ async function processStartedAtFor(pid) {
200
110
  return undefined;
201
111
  }
202
112
  }
203
- /** How far a recorded start time may differ from the probed one and still be the same process. */
204
113
  const PROCESS_START_TOLERANCE_MS = 5_000;
205
114
  const validSessionFile = (id) => /^[a-f0-9-]{36}$/i.test(id);
206
- /**
207
- * Classify the runs and session turns a previous process left unfinished.
208
- *
209
- * A run that finalizes replaces its open record and its marker turn together; anything that ends
210
- * that way needs no help here. What this repairs is the other end: a process killed between the
211
- * open record and the finalizer leaves a record stuck at `running` and a session turn claiming the
212
- * attempt "is still running", and neither can tell the difference between live work and a crash on
213
- * its own. The pid answers it — a process this home's engine cannot see is gone — and from there
214
- * the record becomes `interrupted`, the marker entry is upgraded to say so, and a marker whose
215
- * record never landed gets an interrupted record synthesized so the run is at least listable.
216
- *
217
- * A record whose pid is alive is left untouched: another engine on this home may genuinely be
218
- * running it — and it is named in `live`, captured by the same walk, so a caller who wants to
219
- * react when such a holder exits needs no second scan (and no gap between two). `onlyRunIds`
220
- * bounds the rewrite to records the caller already knows its own earlier sweep left open: a
221
- * delayed repair must never touch a record a live process still owns, including the calling
222
- * engine's own active run. The whole pass is best-effort; one damaged record never hides the
223
- * others.
224
- */
115
+ async function scanFiles(paths, pick, concurrency = 32) {
116
+ const contents = new Array(paths.length).fill(undefined);
117
+ let next = 0;
118
+ const worker = async () => {
119
+ while (next < paths.length) {
120
+ const index = next++;
121
+ let text;
122
+ try {
123
+ text = await readFile(paths[index], 'utf8');
124
+ }
125
+ catch {
126
+ continue;
127
+ }
128
+ contents[index] = pick(text);
129
+ }
130
+ };
131
+ await Promise.all(Array.from({ length: Math.min(concurrency, paths.length) }, worker));
132
+ return contents;
133
+ }
225
134
  export async function reconcileInterruptedRuns(directory, onlyRunIds, options) {
226
135
  const recovery = { runs: [], markers: 0, live: [], interrupted: [] };
227
136
  const swept = await markOpenRunsInterrupted(directory, onlyRunIds, options?.skipOwnProcess === true, options?.includePending === true);
@@ -231,41 +140,13 @@ export async function reconcileInterruptedRuns(directory, onlyRunIds, options) {
231
140
  recovery.markers = await upgradeSessionMarkers(directory);
232
141
  return recovery;
233
142
  }
234
- /**
235
- * The open records this process can no longer own, rewritten with status `interrupted`, plus the
236
- * records the same walk left running because a live foreign process owns them.
237
- *
238
- * The live set is what lets a starting engine watch its predecessor without a second scan: the
239
- * sweep either recovers a record whose holder is gone or names it here, so an exit at any moment
240
- * is caught by one pass or the other. `onlyRunIds` bounds the rewrite to records the caller knows
241
- * its own earlier sweep left open — a delayed repair must not touch a record a live process still
242
- * owns, including the calling engine's own active run.
243
- */
244
- /**
245
- * Whether an open run belongs to a run this very process instance is executing.
246
- *
247
- * A pid is not an identity: the OS hands a dead process's number to the next one, and this
248
- * process's own number is no different. The claim beside the record carries the start time its
249
- * owner recorded, so a claim this instance wrote is told apart from one an earlier instance with
250
- * the same number wrote. The first is a live run — an in-process host that starts a second engine
251
- * must not terminalize the first engine's work, which is still executing — and the second is the
252
- * debris of a crash.
253
- *
254
- * A claim with no recorded start time, or one that names another process, proves neither: the
255
- * answer is the conservative one, and the run is classified as a crash.
256
- */
257
143
  async function claimedByThisProcess(directory, runId) {
258
144
  try {
259
145
  const claim = JSON.parse(await readFile(runRecordPath(directory, runId, 'open-run'), 'utf8'));
260
146
  if (claim.pid !== process.pid)
261
147
  return false;
262
- // The nonce is the exact answer: a claim this process instance wrote carries it, and one
263
- // another instance wrote does not — however close its start time is to this one's.
264
148
  if (typeof claim.nonce === 'string')
265
149
  return claim.nonce === PROCESS_NONCE;
266
- // A claim without one was written before the nonce existed, so the start time is all there
267
- // is. The tolerance is the conservative direction: a claim that looks like this process's own
268
- // is left alone rather than terminalized.
269
150
  if (typeof claim.startedAt !== 'string')
270
151
  return false;
271
152
  const claimed = Date.parse(claim.startedAt);
@@ -291,15 +172,16 @@ async function markOpenRunsInterrupted(directory, onlyRunIds, skipOwnProcess = f
291
172
  const ids = [];
292
173
  const live = [];
293
174
  const records = [];
294
- for (const name of names) {
295
- // Only result records: `.json` is the result's extension, and `.checkpoint.json` names only
296
- // ever existed as a checkpoint before the suffix was shortened to keep it out of the scans.
297
- if (!name.endsWith('.json') || name.endsWith('.checkpoint.json'))
298
- continue;
175
+ const results = names.filter(name => name.endsWith('.json') && !name.endsWith('.checkpoint.json'));
176
+ const texts = await scanFiles(results.map(name => join(runs, name)), text => text.includes('running') || text.includes('telemetryPending') ? text : undefined);
177
+ for (const [index, name] of results.entries()) {
299
178
  const path = join(runs, name);
179
+ const text = texts[index];
180
+ if (text === undefined)
181
+ continue;
300
182
  let value;
301
183
  try {
302
- value = JSON.parse(await readFile(path, 'utf8'));
184
+ value = JSON.parse(text);
303
185
  }
304
186
  catch {
305
187
  continue;
@@ -311,35 +193,19 @@ async function markOpenRunsInterrupted(directory, onlyRunIds, skipOwnProcess = f
311
193
  const runId = typeof value.id === 'string' && value.id === name.slice(0, -'.json'.length) ? value.id : undefined;
312
194
  if (runId === undefined)
313
195
  continue;
314
- // A record rewritten by an earlier recovery whose finish was never queued: the pair is still
315
- // owed, and the derived event id makes re-reporting it idempotent.
316
196
  if (value.status === 'interrupted') {
317
197
  records.push(value);
318
198
  continue;
319
199
  }
320
200
  const pid = typeof value.pid === 'number' ? value.pid : undefined;
321
- // A live foreign pid is the only answer that keeps a record open — another engine's run, or
322
- // the predecessor still shutting down, and it is named in `live` for a watcher to hold. This
323
- // process's own pid keeps its active run open too, but it is nobody to watch: the engine is
324
- // the one running this code. Anything else is a crash.
325
201
  if (pid !== undefined && pid !== process.pid && isPidAlive(pid)) {
326
202
  live.push({ runId, pid, sessionId: typeof value.sessionId === 'string' ? value.sessionId : undefined });
327
203
  continue;
328
204
  }
329
- // A run this very process instance is executing is not debris either. A pid is not an
330
- // identity — the OS hands a dead process's number to the next one, and this process's own
331
- // number is no different — so the claim beside the record is what tells the two apart: it
332
- // carries the start time its owner recorded, and a claim this instance wrote is a run that
333
- // is still going. An in-process host that starts a second engine must not terminalize the
334
- // first engine's live work: the claim it would remove is what holds the session against a
335
- // mutation, and the run would save over that mutation when it finished.
336
205
  if (skipOwnProcess && pid === process.pid && await claimedByThisProcess(directory, runId))
337
206
  continue;
338
207
  if (onlyRunIds !== undefined && !onlyRunIds.has(runId))
339
208
  continue;
340
- // Two coordinators can read the same open record before either rewrite lands. The lock makes
341
- // the running-to-interrupted transition single-owner, so only one of them enqueues the finish;
342
- // the loser has nothing to emit and leaves the record to the winner.
343
209
  const lockDirectory = join(runs, `${runId}.recover`);
344
210
  let release;
345
211
  try {
@@ -352,13 +218,8 @@ async function markOpenRunsInterrupted(directory, onlyRunIds, skipOwnProcess = f
352
218
  }
353
219
  const unlock = async () => {
354
220
  await release();
355
- // The lock's own directory is an implementation detail; leaving one empty directory per
356
- // recovered run would clutter `runs/` for no reason.
357
221
  await rm(lockDirectory, { recursive: true, force: true }).catch(() => { });
358
222
  };
359
- // The record was read before the lock. A coordinator that read it, was descheduled, and then
360
- // acquired the lock the winner just released would otherwise rewrite a record that already
361
- // says `interrupted` and enqueue a second finish. Only the reading under the lock counts.
362
223
  let current;
363
224
  try {
364
225
  current = JSON.parse(await readFile(path, 'utf8'));
@@ -371,8 +232,6 @@ async function markOpenRunsInterrupted(directory, onlyRunIds, skipOwnProcess = f
371
232
  await unlock();
372
233
  continue;
373
234
  }
374
- // `telemetryPending` is cleared by whoever queues the finish. A process that dies between the
375
- // rewrite and the enqueue therefore leaves a record a later pass still knows to report.
376
235
  const interrupted = { ...current, status: 'interrupted', telemetryPending: true, reason: 'the engine stopped while this run was active', endedAt: new Date().toISOString() };
377
236
  try {
378
237
  await writeSessionSnapshot(path, JSON.stringify(interrupted, null, 2) + '\n');
@@ -382,25 +241,16 @@ async function markOpenRunsInterrupted(directory, onlyRunIds, skipOwnProcess = f
382
241
  continue;
383
242
  }
384
243
  await unlock();
385
- // Startup recovery can delete the dead claim before MCP monitoring ever
386
- // runs. Preserve the pre-snapshot crash signal from the recovered run record
387
- // so a previous successful session turn cannot hide this interrupted attempt.
388
244
  const crash = await rememberCrashedClaim(directory, {
389
245
  runId, sessionId: value.sessionId, claimedAt: value.startedAt,
390
246
  });
391
- // A marker that could not be persisted leaves the claim as the only
392
- // durable, retryable copy of the signal: removing it here would erase the
393
- // crash from monitoring for good. A later monitor pass retries the write.
394
247
  if (crash?.durable !== false)
395
- // The record says the attempt is over, so its open claim must stop naming it to the guard: a
396
- // claim whose holder later turns out to be alive would otherwise hold the session shut.
397
248
  await rm(join(runs, `${runId}.open-run`), { force: true }).catch(() => { });
398
249
  ids.push(runId);
399
250
  records.push(interrupted);
400
251
  }
401
252
  return { ids, live, records };
402
253
  }
403
- /** The facts a session's own history carries, when a caller already holds the snapshot. */
404
254
  function sessionCrashFacts(history) {
405
255
  const turns = Array.isArray(history) ? history : [];
406
256
  const runIds = new Set();
@@ -429,7 +279,6 @@ async function readSessionCrashFacts(directory, sessionId) {
429
279
  return { kind: 'unreadable' };
430
280
  }
431
281
  }
432
- /** Whether a run that started after `time` has persisted a turn in this session. */
433
282
  async function persistedRunStartedAfter(directory, runId, time) {
434
283
  if (runId === undefined)
435
284
  return false;
@@ -437,23 +286,6 @@ async function persistedRunStartedAfter(directory, runId, time) {
437
286
  const startedAt = typeof record?.startedAt === 'string' ? Date.parse(record.startedAt) : Number.NaN;
438
287
  return Number.isFinite(startedAt) && startedAt > time;
439
288
  }
440
- /**
441
- * A crashed run may die between writing its claim and saving the running turn.
442
- * Keep a small, durable monitor-only signal before cleaning up the dead claim.
443
- *
444
- * The sidecar exists for one state only: an attempt the session snapshot never
445
- * records, hidden behind an older turn. A session that has a turn naming this
446
- * run already reports the attempt — a `running` marker turn included — so a
447
- * finalizer's terminal record left behind by a failed claim removal must not
448
- * become a `crashedAttempt`. A run that started after the claim proves a newer
449
- * attempt was persisted, which supersedes the crash. Startup recovery calls
450
- * this after rewriting its record, so the pre-snapshot test is the same whether
451
- * recovery or a monitor observed the dead claim.
452
- *
453
- * @returns the marker and whether it reached the disk. `undefined` means no
454
- * marker is needed; `durable: false` means the caller must keep its claim, the
455
- * only retryable copy of the signal left.
456
- */
457
289
  async function rememberCrashedClaim(directory, claim, factsFor = sessionId => readSessionCrashFacts(directory, sessionId)) {
458
290
  const runId = claim.runId, sessionId = claim.sessionId, claimedAt = claim.claimedAt;
459
291
  if (typeof runId !== 'string' || typeof sessionId !== 'string'
@@ -461,8 +293,6 @@ async function rememberCrashedClaim(directory, claim, factsFor = sessionId => re
461
293
  || typeof claimedAt !== 'string' || !Number.isFinite(Date.parse(claimedAt)))
462
294
  return undefined;
463
295
  const facts = await factsFor(sessionId);
464
- // A deleted session has no monitor row to report. An unreadable snapshot is
465
- // not proof the attempt was recorded, so only a readable one can answer.
466
296
  if (facts.kind === 'missing')
467
297
  return undefined;
468
298
  if (facts.kind === 'present') {
@@ -477,8 +307,6 @@ async function rememberCrashedClaim(directory, claim, factsFor = sessionId => re
477
307
  return { marker, durable: true };
478
308
  }
479
309
  catch {
480
- // The session layer already retries transient Windows renames; a failure
481
- // that survives that is reported so the caller keeps its claim.
482
310
  return { marker, durable: false };
483
311
  }
484
312
  }
@@ -495,9 +323,6 @@ export async function sessionsWithOpenRunClaims(directory, sessions) {
495
323
  }
496
324
  const active = new Set();
497
325
  const crashed = new Map();
498
- // A query passes the same snapshot its views are built from, so pruning can
499
- // never delete a marker using a save the answer does not reflect. Without one
500
- // (no current caller) the files are the only source.
501
326
  const snapshots = sessions === undefined ? undefined : new Map(sessions.map(session => [session.id, session]));
502
327
  const fileFacts = new Map();
503
328
  const absentFacts = new Map();
@@ -515,10 +340,6 @@ export async function sessionsWithOpenRunClaims(directory, sessions) {
515
340
  const session = snapshots.get(sessionId);
516
341
  if (session !== undefined)
517
342
  return sessionCrashFacts(session.history);
518
- // The store omits unreadable or invalid records from its listing, so
519
- // absence from the snapshot is proof of deletion only when the file
520
- // itself is gone. Anything still on disk stays an unknown state, keeping
521
- // its marker alive for when the record is repaired.
522
343
  let pending = absentFacts.get(sessionId);
523
344
  if (pending === undefined) {
524
345
  pending = confirmAbsent(sessionId);
@@ -533,15 +354,11 @@ export async function sessionsWithOpenRunClaims(directory, sessions) {
533
354
  }
534
355
  return pending;
535
356
  };
536
- // Only the newest unresolved crash per session is actionable. Older sidecars
537
- // can never outlive it (a persisted run that supersedes the newest also
538
- // supersedes them), so keeping them would make every poll reread them forever.
539
357
  const kept = new Map();
540
358
  const keepCrash = async (entry, file) => {
541
359
  const existing = crashed.get(entry.sessionId);
542
360
  const prior = kept.get(entry.sessionId);
543
361
  if (existing !== undefined && Date.parse(existing.claimedAt) >= Date.parse(entry.claimedAt)) {
544
- // The selected crash is at least as new; this sidecar is redundant.
545
362
  if (file !== prior)
546
363
  await rm(join(runs, file), { force: true }).catch(() => { });
547
364
  return;
@@ -565,9 +382,6 @@ export async function sessionsWithOpenRunClaims(directory, sessions) {
565
382
  || name !== entry.runId + '.mcp-crash')
566
383
  continue;
567
384
  const known = await factsFor(entry.sessionId);
568
- // Remove markers nothing can report any more, so the scan stays bounded:
569
- // a deleted session is orphaned, and a session that already records the
570
- // attempt, or a later run that supersedes it, makes the sidecar redundant.
571
385
  if (known.kind === 'missing'
572
386
  || (known.kind === 'present' && (known.runIds.has(entry.runId)
573
387
  || await persistedRunStartedAfter(directory, known.lastRunId, Date.parse(entry.claimedAt))))) {
@@ -576,7 +390,7 @@ export async function sessionsWithOpenRunClaims(directory, sessions) {
576
390
  }
577
391
  await keepCrash({ runId: entry.runId, sessionId: entry.sessionId, claimedAt: entry.claimedAt }, name);
578
392
  }
579
- catch { /* Damaged monitor sidecars must not hide unrelated sessions. */ }
393
+ catch { }
580
394
  }
581
395
  for (const name of names) {
582
396
  if (!name.endsWith('.open-run'))
@@ -586,7 +400,7 @@ export async function sessionsWithOpenRunClaims(directory, sessions) {
586
400
  claim = JSON.parse(await readFile(join(runs, name), 'utf8'));
587
401
  }
588
402
  catch {
589
- continue; /* A torn claim is handled by the per-session legacy fallback. */
403
+ continue;
590
404
  }
591
405
  if (!claim || typeof claim !== 'object' || typeof claim.sessionId !== 'string')
592
406
  continue;
@@ -599,22 +413,12 @@ export async function sessionsWithOpenRunClaims(directory, sessions) {
599
413
  const outcome = await rememberCrashedClaim(directory, claim, factsFor);
600
414
  if (outcome !== undefined)
601
415
  await keepCrash({ ...outcome.marker, sessionId: claim.sessionId }, outcome.marker.runId + '.mcp-crash');
602
- // Keep a claim whose crash marker could not be persisted: the claim is the
603
- // only retryable copy, and removing it would permanently hide the attempt.
604
416
  if (outcome?.durable === false)
605
417
  continue;
606
418
  await rm(join(runs, name), { force: true }).catch(() => { });
607
419
  }
608
420
  return { active, crashed };
609
421
  }
610
- /**
611
- * Whether a live open-run claim still holds this session against mutations.
612
- *
613
- * `ignoreRunId` excuses one run from the answer: the engine that owns that run mutates the session
614
- * safely beside it when its finalizer merges into the record it saves, so it names its own
615
- * in-flight run here instead of being held by its own claim. Every other owner — a second window
616
- * or the CLI sharing the home — answers exactly as before, crash-claim cleanup included.
617
- */
618
422
  export async function sessionHasOpenRun(directory, sessionId, options = {}) {
619
423
  const runs = runRecordsDirectory(directory);
620
424
  let names;
@@ -635,24 +439,15 @@ export async function sessionHasOpenRun(directory, sessionId, options = {}) {
635
439
  try {
636
440
  claim = JSON.parse(await readFile(join(runs, name), 'utf8'));
637
441
  }
638
- // A claim that cannot be parsed proves no owner but hides what the records would say: the scan
639
- // is the conservative answer for this directory, not a silent miss.
640
442
  catch {
641
443
  return scanRunsForOpenRun(directory, sessionId, options.ignoreRunId);
642
444
  }
643
445
  if (!claim || typeof claim !== 'object' || claim.sessionId !== sessionId)
644
446
  continue;
645
- // The named run is the caller's own work, not a stranger: its claim is excused outright, so
646
- // nothing here reclaims or removes it.
647
447
  if (options.ignoreRunId !== undefined && (claim.runId === options.ignoreRunId || name === `${options.ignoreRunId}.open-run`))
648
448
  continue;
649
- // A claim the finalizer failed to remove is not evidence of live work, however alive its owner
650
- // looks: see `claimOutlivedItsRun`. Reclaiming it here is what keeps a transient removal failure
651
- // from holding a session shut for the life of the process that wrote it.
652
449
  if (await claimOutlivedItsRun(directory, claim)) {
653
450
  const outcome = await rememberCrashedClaim(directory, claim);
654
- // A marker that could not be written leaves the claim in place: it is the
655
- // only retryable signal that this attempt never reached the session.
656
451
  if (outcome?.durable !== false)
657
452
  await rm(join(runs, name), { force: true }).catch(() => { });
658
453
  continue;
@@ -666,17 +461,6 @@ export async function sessionHasOpenRun(directory, sessionId, options = {}) {
666
461
  }
667
462
  return false;
668
463
  }
669
- /**
670
- * Whether an armed wake still names this session from any engine.
671
- *
672
- * A wake lives in the registry of the engine that armed it, and every engine sharing the
673
- * installation runs a reaper pass over the same store: asked of its own registry alone, one
674
- * engine's pass would file away a session another engine still owes a prompt. Each arm wrote a
675
- * claim, so the claims are the answer. A claim whose owner is live holds the session; a claim
676
- * whose owner is gone is swept here, because the wake it named was a promise its process held and
677
- * nothing will deliver it now. A claim that cannot be read might name a live wake, so it holds
678
- * the session too.
679
- */
680
464
  export async function sessionHasArmedWake(directory, sessionId) {
681
465
  const runs = runRecordsDirectory(directory);
682
466
  let names;
@@ -705,47 +489,26 @@ export async function sessionHasArmedWake(directory, sessionId) {
705
489
  armed = true;
706
490
  continue;
707
491
  }
708
- // The owner is gone, and with it the wake: the claim it left cannot hold the session against
709
- // every later pass, so the read that proved it dead clears it.
710
492
  await rm(join(runs, name), { force: true }).catch(() => { });
711
493
  }
712
494
  return armed;
713
495
  }
714
- /** The path of one wake's claim, beside the open-run claims it is read with. */
715
496
  function wakeClaimPath(directory, sessionId, timerId) {
716
497
  if (!validSessionFile(sessionId) || !validSessionFile(timerId)) {
717
498
  throw new Error('A wake claim needs a session identity and a timer identity');
718
499
  }
719
500
  return join(runRecordsDirectory(directory), `${sessionId}.${timerId}.wake-claim`);
720
501
  }
721
- /**
722
- * Record that this engine armed a wake for a session.
723
- *
724
- * The wake itself lives in this process's registry, so a reaper pass in another engine cannot see
725
- * it there. The claim is what makes it visible across the engines that share the installation: one
726
- * small file per wake, carrying the writing process's identity, read by `sessionHasArmedWake`. Best
727
- * effort — a claim that fails to land leaves the wake invisible to a foreign pass until its
728
- * delivery lands and reverts the filing, the way the run that armed it would have.
729
- */
730
502
  export async function writeWakeClaim(directory, sessionId, timerId) {
731
503
  const body = { sessionId, timerId, pid: process.pid, claimedAt: new Date().toISOString(), startedAt: processStartedAt(), nonce: PROCESS_NONCE };
732
- // A home with no runs yet has no directory for the claim: the write lands beside the open-run claims.
733
504
  await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 }).catch(() => { });
734
505
  await writeSessionSnapshot(wakeClaimPath(directory, sessionId, timerId), JSON.stringify(body) + '\n');
735
506
  }
736
- /** Drop one wake's claim: the wake was delivered, spent, or canceled by the engine that armed it. */
737
507
  export async function clearWakeClaim(directory, sessionId, timerId) {
738
508
  if (!validSessionFile(sessionId) || !validSessionFile(timerId))
739
509
  return;
740
510
  await rm(wakeClaimPath(directory, sessionId, timerId), { force: true }).catch(() => { });
741
511
  }
742
- /**
743
- * Drop every claim a session's wakes hold, when the wakes go with the session they were armed for.
744
- *
745
- * Deleting a session clears its wakes with the record; the claims have to go with them, or claims
746
- * naming a session that no longer exists would outlive the session that could ever clear them.
747
- * Only claims naming this session are removed: another session's wakes are nobody else's to drop.
748
- */
749
512
  export async function clearWakeClaims(directory, sessionId) {
750
513
  if (!validSessionFile(sessionId))
751
514
  return;
@@ -765,21 +528,6 @@ export async function clearWakeClaims(directory, sessionId) {
765
528
  await rm(join(runs, name), { force: true }).catch(() => { });
766
529
  }
767
530
  }
768
- /**
769
- * Whether this claim's own run record closed after the claim was made, which makes the claim failed
770
- * cleanup rather than live work.
771
- *
772
- * A run finalizes by rewriting its result record and then removing its claim. If that removal fails — a
773
- * scanner holding the file on Windows is enough, and the removal is deliberately best-effort so a
774
- * transient lock cannot abort a finished run — the leftover goes on naming its owner, and nothing else
775
- * sweeps it: the startup repair walks only records that are still `running`, so a claim whose record is
776
- * closed survives every later restart and keeps `sessionHasOpenRun` answering `busy` for this session
777
- * until the process it names exits. Comparing the two stamps is what tells this apart from the claim of
778
- * a run in flight: a resume reuses its attempt's run id, so a record that closed *before* this claim was
779
- * written belongs to that earlier attempt and says nothing about this one. A record that is absent,
780
- * unreadable, or without a closing stamp proves nothing, and the claim stands — the conservative
781
- * direction, because clearing a live claim is what lets a mutation land on a session a run still owns.
782
- */
783
531
  async function claimOutlivedItsRun(directory, claim) {
784
532
  const runId = typeof claim.runId === 'string' ? claim.runId : undefined;
785
533
  if (runId === undefined)
@@ -802,18 +550,6 @@ async function claimOutlivedItsRun(directory, claim) {
802
550
  const endedAt = typeof closed.endedAt === 'string' ? Date.parse(closed.endedAt) : Number.NaN;
803
551
  return Number.isFinite(endedAt) && endedAt > claimedAt;
804
552
  }
805
- /**
806
- * Whether the process an open-run claim names is the one that wrote it.
807
- *
808
- * `isPidAlive` alone is not an identity: the OS reuses numbers, so a claim whose engine crashed
809
- * can come to name an unrelated process that inherited the pid, and treating that as the owner
810
- * would hold the session busy — refusing every rename, archive, and delete — for as long as the
811
- * impostor lives. The start time the owner recorded when it claimed the run is corroborated
812
- * against the one the platform reports for that pid, which is how `inspectClaim` judges a resume
813
- * claim. A claim written before that field existed, and a platform that cannot report a start
814
- * time, fall back to pid liveness: the conservative direction, because a live owner read as
815
- * stale is what lets a rail mutation land while a run still owns the session.
816
- */
817
553
  async function claimOwnerIsLive(pid, startedAt) {
818
554
  if (pid === undefined || !Number.isSafeInteger(pid) || pid < 1)
819
555
  return true;
@@ -822,11 +558,9 @@ async function claimOwnerIsLive(pid, startedAt) {
822
558
  const claimed = typeof startedAt === 'string' ? Date.parse(startedAt) : Number.NaN;
823
559
  if (!Number.isFinite(claimed))
824
560
  return true;
825
- // Our own start time is known without a probe: the common case is this process's own run.
826
561
  const actual = pid === process.pid ? Date.parse(processStartedAt()) : await processStartedAtFor(pid);
827
562
  return actual === undefined || Math.abs(actual - claimed) <= PROCESS_START_TOLERANCE_MS;
828
563
  }
829
- /** The pre-index answer: read the result records themselves. Only the fallback paths reach it. */
830
564
  async function scanRunsForOpenRun(directory, sessionId, ignoreRunId) {
831
565
  const runs = runRecordsDirectory(directory);
832
566
  let names;
@@ -850,7 +584,6 @@ async function scanRunsForOpenRun(directory, sessionId, ignoreRunId) {
850
584
  }
851
585
  if (!value || typeof value !== 'object' || value.status !== 'running' || value.sessionId !== sessionId)
852
586
  continue;
853
- // The caller's own in-flight run is excused from the answer, exactly as in the claim index.
854
587
  if (ignoreRunId !== undefined && (value.id === ignoreRunId || name === `${ignoreRunId}.json`))
855
588
  continue;
856
589
  const pid = typeof value.pid === 'number' ? value.pid : undefined;
@@ -859,25 +592,13 @@ async function scanRunsForOpenRun(directory, sessionId, ignoreRunId) {
859
592
  }
860
593
  return false;
861
594
  }
862
- /** Whether a value is the plain object a completion's `output` is declared to be. */
863
595
  const plainObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
864
- /** Whether a value is the `{ type, ref }` pair a completion's artifact reference is declared to be. */
865
596
  function isArtifactRef(value) {
866
597
  if (!value || typeof value !== 'object')
867
598
  return false;
868
599
  const ref = value;
869
600
  return typeof ref.type === 'string' && typeof ref.ref === 'string';
870
601
  }
871
- /**
872
- * Bring every session's view of unfinished attempts in line with the run records.
873
- *
874
- * A marker turn whose record finalized means the final turn never reached the session file — the
875
- * finalizer saved the record and the session save itself failed — so the marker takes the record's
876
- * own account of the attempt. A marker with no record at all is a crash between the two writes: it
877
- * becomes interrupted, and with a known run identity an interrupted record is synthesized so the
878
- * Runs view shows the attempt instead of only the transcript. A marker whose record is still open
879
- * under a live pid is real in-flight work and stays.
880
- */
881
602
  async function upgradeSessionMarkers(directory, only) {
882
603
  const sessions = join(directory, 'sessions');
883
604
  let names;
@@ -890,10 +611,10 @@ async function upgradeSessionMarkers(directory, only) {
890
611
  throw error;
891
612
  }
892
613
  let markers = 0;
893
- for (const name of names) {
894
- if (!name.endsWith('.json'))
895
- continue;
896
- if (only !== undefined && name !== `${only}.json`)
614
+ const candidates = names.filter(name => name.endsWith('.json') && (only === undefined || name === `${only}.json`));
615
+ const mayHaveMarker = await scanFiles(candidates.map(name => join(sessions, name)), text => text.includes('running') || undefined);
616
+ for (const [index, name] of candidates.entries()) {
617
+ if (!mayHaveMarker[index])
897
618
  continue;
898
619
  try {
899
620
  const session = JSON.parse(await readFile(join(sessions, name), 'utf8'));
@@ -917,32 +638,18 @@ async function upgradeSessionMarkers(directory, only) {
917
638
  if (record && record.status === 'running') {
918
639
  if (typeof record.pid !== 'number' || isPidAlive(record.pid))
919
640
  continue;
920
- // `markOpenRunsInterrupted` already landed, but a record this pass cannot rewrite (a
921
- // locked file on Windows) must not leave the transcript claiming work in flight.
922
641
  }
923
642
  if (record && record.status !== 'running' && typeof record.status === 'string') {
924
- // The attempt finished; only the session never heard how — or what it produced. The
925
- // finalization persisted the whole completion (tests, outcome, artifacts) even when its
926
- // session save failed, so the repaired turn takes it whole rather than only its summary.
927
643
  const finalized = (record.completion && typeof record.completion === 'object' && !Array.isArray(record.completion))
928
644
  ? { ...record.completion }
929
645
  : undefined;
930
646
  if (finalized) {
931
647
  if (record.status === 'succeeded') {
932
- // A successful run: the turn is a normal completed turn, and the desktop labels any
933
- // present non-running status as a stopped one, so it carries the record's completion
934
- // with no status at all.
935
648
  delete finalized.status;
936
649
  }
937
650
  else {
938
651
  finalized.status = record.status;
939
652
  }
940
- // The saved session must stay loadable and renderable: session validation keeps only a
941
- // string summary and a string-array tests list, and clients render the outcome beside
942
- // them, so the fields a hand-edited or damaged record gets wrong are repaired to their
943
- // declared shapes rather than written through verbatim. `output` and `artifacts` are not
944
- // drawn but are serialized into the next run's model context, so they are held to their
945
- // shapes too; a field that cannot be repaired is dropped.
946
653
  if (typeof finalized.summary !== 'string' || finalized.summary.length === 0) {
947
654
  finalized.summary = record.status === 'succeeded'
948
655
  ? (typeof completion.summary === 'string' && completion.summary.length > 0 ? completion.summary : summaryForStoppedRecord(record))
@@ -950,8 +657,6 @@ async function upgradeSessionMarkers(directory, only) {
950
657
  }
951
658
  if (!Array.isArray(finalized.tests) || !finalized.tests.every((test) => typeof test === 'string'))
952
659
  finalized.tests = [];
953
- // A React child must stringify: an object where the outcome belongs throws while the
954
- // transcript renders, which would make the repaired session unusable in the desktop.
955
660
  if (typeof finalized.outcome !== 'string')
956
661
  delete finalized.outcome;
957
662
  if (!plainObject(finalized.output))
@@ -967,9 +672,6 @@ async function upgradeSessionMarkers(directory, only) {
967
672
  completion.summary = summaryForStoppedRecord(record);
968
673
  completion.status = record.status;
969
674
  }
970
- // The session totals are the pre-run snapshot the marker was saved with; the attempt's
971
- // usage lives only in the record. Fold it once per file even when the marker turn sits
972
- // in both history arrays, or the recovery would count the same run twice.
973
675
  if (known && !usageFolded.has(runId)) {
974
676
  usageFolded.add(runId);
975
677
  foldRecordUsage(session, record.usage);
@@ -989,28 +691,13 @@ async function upgradeSessionMarkers(directory, only) {
989
691
  await writeSessionSnapshot(join(sessions, name), JSON.stringify(session) + '\n');
990
692
  markers += changed;
991
693
  }
992
- catch { /* One damaged session must not stop the sweep. */ }
694
+ catch { }
993
695
  }
994
696
  return markers;
995
697
  }
996
- /**
997
- * Bring one session's unfinished turns in line with the run records.
998
- *
999
- * The same repair the startup pass makes, for one session: a run whose final session save failed
1000
- * leaves its turn marked running, and a long-lived server would keep it that way until it was
1001
- * restarted. The attempt's own record says how it ended, so the turn takes that account of it.
1002
- */
1003
698
  export async function repairSessionMarkers(directory, sessionId) {
1004
699
  return await upgradeSessionMarkers(directory, sessionId);
1005
700
  }
1006
- /**
1007
- * Add a finished run's usage to the session totals during recovery.
1008
- *
1009
- * The saved session holds the totals as they were when the marker was written — before the run's
1010
- * model calls — and after a failed final save the attempt's usage exists only on its record. The
1011
- * fold matches the live one: the three required counters always add, a cache counter the provider
1012
- * reported (even as zero) adds, and an unreported one stays absent.
1013
- */
1014
701
  function foldRecordUsage(session, usage) {
1015
702
  if (!usage || typeof usage !== 'object' || Array.isArray(usage))
1016
703
  return;
@@ -1035,12 +722,9 @@ async function readRunRecord(directory, runId) {
1035
722
  return undefined;
1036
723
  }
1037
724
  }
1038
- /** The record a crashed run never wrote, so the attempt is listable and classifiable. */
1039
725
  async function synthesizeInterruptedRecord(directory, runId, sessionId) {
1040
726
  if (await readRunRecord(directory, runId) !== undefined)
1041
727
  return;
1042
- // The crash can land before anything ever created `runs/`: the session marker is written first,
1043
- // and a home whose only run never opened a record has no directory to synthesize into.
1044
728
  await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 });
1045
729
  let startedAt = new Date().toISOString();
1046
730
  try {
@@ -1049,72 +733,34 @@ async function synthesizeInterruptedRecord(directory, runId, sessionId) {
1049
733
  if (typeof time === 'string')
1050
734
  startedAt = time;
1051
735
  }
1052
- catch { /* No journal: the record starts its life at recovery time. */ }
736
+ catch { }
1053
737
  try {
1054
738
  await writeSessionSnapshot(runRecordPath(directory, runId, 'json'), JSON.stringify({
1055
739
  id: runId, status: 'interrupted', reason: 'the engine stopped before the run was recorded', startedAt,
1056
740
  ...(sessionId === undefined ? {} : { sessionId }), usage: { inputTokens: 0, outputTokens: 0, requests: 0 }, toolCalls: 0,
1057
741
  }, null, 2) + '\n');
1058
742
  }
1059
- catch { /* A record that cannot be written must not fail the sweep. */ }
743
+ catch { }
1060
744
  }
1061
- /**
1062
- * The path a run's persisted record lives at.
1063
- *
1064
- * The run identity reaches this path from runtime events, where it is typed `unknown`, so the
1065
- * alphabet is checked here at the sink rather than trusted from every caller. The identity is
1066
- * always a UUID, and the guard admits only `[A-Za-z0-9_-]` -- the same alphabet `ArtifactStore`
1067
- * uses for its own run-scoped directory. That rejects every spelling that could leave `runs/`:
1068
- * `.` and `..` segments (the dot is not in the alphabet, so `..` is not merely resolved away but
1069
- * refused), `/` and `\` separators, an absolute path, and a Windows drive-relative or
1070
- * alternate-data-stream name (`:`).
1071
- * @param directory - the installation directory holding `runs/`.
1072
- * @param runId - the run identity, typically a generated UUID.
1073
- * @param extension - which record per run this path names: the result, the journal, or the
1074
- * checkpoint the resume work leaves behind until the run succeeds.
1075
- * @returns the absolute or installation-relative path of the record.
1076
- */
1077
745
  export function runRecordPath(directory, runId, extension) {
1078
- // The alphabet alone is not the whole test: `$` also matches just before a trailing newline, so
1079
- // `/^…$/` would admit "run\n" as readily as "run". Requiring the value to survive `trim()`
1080
- // unchanged closes that and rejects padded input at the same time.
1081
746
  if (typeof runId !== 'string' || runId.trim() !== runId || !/^[\w-]{1,64}$/.test(runId)) {
1082
- // The rejected value is deliberately not echoed: it is untrusted text, and an error message
1083
- // is rendered to a terminal.
1084
747
  throw new Error('A persisted run record needs a run identity of up to 64 word characters');
1085
748
  }
1086
749
  return join(runRecordsDirectory(directory), `${runId}.${extension}`);
1087
750
  }
1088
- /**
1089
- * Record that a run's journal is missing events, durably and separately from the sink that failed.
1090
- *
1091
- * The engine deliberately keeps running when an append fails (a full disk must not kill the user's
1092
- * work), and the journal writer holds what it could not write and writes it once the file accepts
1093
- * appends again. This marker covers the window in between and the cases that never close: the
1094
- * process dying while events are still held, or the writer giving some up. The lines after such a
1095
- * gap are present, so nothing in the file itself reveals it. The writer removes the marker once
1096
- * everything it held has landed (best effort both ways: if the marker cannot be written, the
1097
- * record's own flag is what stands), and `journalWriteFailed` is what a resume reads to warn that a
1098
- * step may repeat.
1099
- */
1100
751
  export async function noteJournalWriteFailure(directory, runId, detail) {
1101
752
  try {
1102
753
  await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 });
1103
754
  await appendFile(runRecordPath(directory, runId, 'journal-error'), `${new Date().toISOString()}\t${detail.replace(/[\r\n]+/g, ' ')}\n`, { mode: 0o600 });
1104
755
  }
1105
- catch { /* the marker is best effort; the record's own flag covers a write that failed here */ }
756
+ catch { }
1106
757
  }
1107
- /**
1108
- * Whether a run's journal is known to be incomplete: the marker the writer left, or the flag the
1109
- * attempt's result record carries. A resume still continues such an attempt (a session must
1110
- * always be resumable), but it tells the user that a step the missing events recorded may repeat.
1111
- */
1112
758
  export async function journalWriteFailed(directory, runId) {
1113
759
  try {
1114
760
  await stat(runRecordPath(directory, runId, 'journal-error'));
1115
761
  return true;
1116
762
  }
1117
- catch { /* no marker: the record flag is the only other account */ }
763
+ catch { }
1118
764
  try {
1119
765
  const value = JSON.parse(await readFile(runRecordPath(directory, runId, 'json'), 'utf8'));
1120
766
  return value.journalIntegrity === 'failed';
@@ -1123,30 +769,7 @@ export async function journalWriteFailed(directory, runId) {
1123
769
  return false;
1124
770
  }
1125
771
  }
1126
- /** How much a journal writer holds in memory while its file refuses appends, before it gives up. */
1127
772
  const MAX_HELD_JOURNAL_BYTES = 16 * 1024 * 1024;
1128
- /**
1129
- * The journal sink for one run: ordered appends that leave no silent hole.
1130
- *
1131
- * The filesystem does not finish concurrent appends in the order they were started, so events are
1132
- * written one after another. An event the file refuses (a full disk, most often) is held rather
1133
- * than dropped, and each later event first retries everything held, oldest first. A disk that
1134
- * fills for a minute and is then freed leaves a complete journal behind, not a permanently
1135
- * untrusted one.
1136
- *
1137
- * A failed append can still have written part of its line, so after any failed write the next one
1138
- * measures the file before it appends anything. When the file grew past the length the writer last
1139
- * knew to be whole lines, it is cut back first, so a retried event neither merges with its own torn
1140
- * fragment nor appears twice. While the file cannot be measured (or is not a regular file), nothing
1141
- * is appended: the events stay held, and the journal cannot be reported complete. When even the cut
1142
- * fails, the next line starts on a fresh line and the journal is reported as no longer complete: the
1143
- * fragment cannot be told apart from an event that really ran. The same holds when the file turns
1144
- * out shorter than the lines already written to it: something else cut it, and those lines are gone.
1145
- *
1146
- * While anything is held, or after anything was given up, the run's `journal-error` marker says
1147
- * so. Events are given up only when what is held passes `maxHeldBytes`. Once everything held has
1148
- * landed and nothing was given up, the writer removes the marker again.
1149
- */
1150
773
  export function createRunJournalWriter(directory, runId, options = {}) {
1151
774
  const path = runRecordPath(directory, runId, 'jsonl');
1152
775
  const files = {
@@ -1169,25 +792,14 @@ export function createRunJournalWriter(directory, runId, options = {}) {
1169
792
  const limit = options.maxHeldBytes ?? MAX_HELD_JOURNAL_BYTES;
1170
793
  const held = [];
1171
794
  let heldBytes = 0;
1172
- // The file's length as far as this writer knows it: every byte before it is part of a whole line,
1173
- // unless `separate` says a fragment the writer could not cut is at the end. Unknown until the
1174
- // first write measures the file.
1175
795
  let size;
1176
- // The next line must start on a fresh line, because a torn fragment is still at the end of the file.
1177
796
  let separate = false;
1178
- // An event was given up, or a torn fragment could not be cut: the journal can no longer prove it is
1179
- // a complete account, however many later appends succeed.
1180
797
  let lost = false;
1181
- // A write failed since the last time everything held reached the file.
1182
798
  let failing = false;
1183
- // The last write failed, so the file's end is not known to be where `size` says: it may hold a
1184
- // fragment of the refused line, or have changed since. The next write measures it first.
1185
799
  let unverified = false;
1186
800
  let chain = Promise.resolve();
1187
801
  const writeLine = async (line) => {
1188
802
  if (size === undefined || unverified) {
1189
- // A measurement that fails throws before anything is appended: the line stays held, and the
1190
- // next write measures again.
1191
803
  const actual = await files.size(path);
1192
804
  if (actual === undefined) {
1193
805
  throw Object.assign(new Error('The run journal path is not a regular file'), { code: 'EISDIR' });
@@ -1196,8 +808,6 @@ export function createRunJournalWriter(directory, runId, options = {}) {
1196
808
  size = actual;
1197
809
  }
1198
810
  else if (actual > size) {
1199
- // `size` only grows when an append succeeds, so it is still the length before the refused
1200
- // one: everything past it is a torn fragment of a line that is still held.
1201
811
  try {
1202
812
  await files.truncate(path, size);
1203
813
  }
@@ -1208,7 +818,6 @@ export function createRunJournalWriter(directory, runId, options = {}) {
1208
818
  }
1209
819
  }
1210
820
  else if (actual < size) {
1211
- // Something else cut the file, and lines this writer had written are gone.
1212
821
  size = actual;
1213
822
  separate = true;
1214
823
  lost = true;
@@ -1220,8 +829,6 @@ export function createRunJournalWriter(directory, runId, options = {}) {
1220
829
  await files.appendFile(path, data);
1221
830
  }
1222
831
  catch (error) {
1223
- // A configuration home that has never held a run has no `runs/` directory yet. Nothing was
1224
- // written, so the append is simply repeated once the directory exists.
1225
832
  if (error.code !== 'ENOENT')
1226
833
  throw error;
1227
834
  await files.mkdir(runRecordsDirectory(directory));
@@ -1237,8 +844,6 @@ export function createRunJournalWriter(directory, runId, options = {}) {
1237
844
  await writeLine(line);
1238
845
  }
1239
846
  catch (error) {
1240
- // Whatever failed, the file is measured before the next append rather than here: a probe
1241
- // that fails right after a torn append must not let a later retry write after the fragment.
1242
847
  unverified = true;
1243
848
  throw error;
1244
849
  }
@@ -1250,8 +855,6 @@ export function createRunJournalWriter(directory, runId, options = {}) {
1250
855
  try {
1251
856
  await drain();
1252
857
  if (failing && !lost) {
1253
- // Everything the file refused has now landed, in order: the journal is a complete account
1254
- // again, and the marker that said otherwise goes.
1255
858
  failing = false;
1256
859
  await rm(runRecordPath(directory, runId, 'journal-error'), { force: true }).catch(() => { });
1257
860
  }
@@ -1259,8 +862,6 @@ export function createRunJournalWriter(directory, runId, options = {}) {
1259
862
  catch (error) {
1260
863
  failing = true;
1261
864
  if (heldBytes > limit) {
1262
- // Holding more would trade the user's memory for a journal that is already late. What is
1263
- // held is given up, and the marker stays for good.
1264
865
  held.length = 0;
1265
866
  heldBytes = 0;
1266
867
  lost = true;
@@ -1269,13 +870,11 @@ export function createRunJournalWriter(directory, runId, options = {}) {
1269
870
  try {
1270
871
  options.onFailure?.(error);
1271
872
  }
1272
- catch { /* a reporter that throws must not break the chain */ }
873
+ catch { }
1273
874
  }
1274
875
  };
1275
876
  return {
1276
877
  append(event) {
1277
- // Serialized now, not when the chain reaches it: the event is recorded as it was when it
1278
- // happened, even if its object is changed while earlier appends are still landing.
1279
878
  let line;
1280
879
  let unserializable;
1281
880
  try {
@@ -1286,14 +885,13 @@ export function createRunJournalWriter(directory, runId, options = {}) {
1286
885
  }
1287
886
  chain = chain.then(async () => {
1288
887
  if (line === undefined) {
1289
- // An event that cannot be serialized can never be written, so it is a gap like any other.
1290
888
  failing = true;
1291
889
  lost = true;
1292
890
  await noteJournalWriteFailure(directory, runId, unserializable instanceof Error ? unserializable.message : String(unserializable));
1293
891
  try {
1294
892
  options.onFailure?.(unserializable);
1295
893
  }
1296
- catch { /* a reporter that throws must not break the chain */ }
894
+ catch { }
1297
895
  return;
1298
896
  }
1299
897
  held.push(line);
@@ -1311,19 +909,12 @@ export function createRunJournalWriter(directory, runId, options = {}) {
1311
909
  get intact() { return held.length === 0 && !lost; },
1312
910
  };
1313
911
  }
1314
- /** A visit as the record and the marker carry it: no `generation` key when the writer did not know it. */
1315
912
  function checkpointVisit(nodeId, generation) {
1316
913
  return generation === undefined ? { nodeId } : { nodeId, generation };
1317
914
  }
1318
- /**
1319
- * One marker line: when, which visit (as JSON, so any node id survives the tab-separated format),
1320
- * and what failed. Lines from builds that predate the visit column carry the detail in the second
1321
- * field, which never parses as a visit, so their node is unknown.
1322
- */
1323
915
  function checkpointFailureLine(visit, detail) {
1324
916
  return `${new Date().toISOString()}\t${JSON.stringify(visit)}\t${detail.replace(/[\r\n\t]+/g, ' ')}\n`;
1325
917
  }
1326
- /** A visit read back from a record or a marker, or `undefined` when the value is not one. */
1327
918
  function parseCheckpointVisit(value) {
1328
919
  if (typeof value !== 'object' || value === null)
1329
920
  return undefined;
@@ -1334,11 +925,6 @@ function parseCheckpointVisit(value) {
1334
925
  return undefined;
1335
926
  return checkpointVisit(nodeId, generation);
1336
927
  }
1337
- /**
1338
- * Track one run's checkpoint writes. The caller reports every write's outcome in the order the
1339
- * writes ran (the checkpoint writers already serialize them). The run's final record carries
1340
- * `checkpointIntegrity: 'failed'` and the `failures` list while `intact` is false.
1341
- */
1342
928
  export function createCheckpointFailureTracker(directory, runId) {
1343
929
  const marker = runRecordPath(directory, runId, 'checkpoint-error');
1344
930
  const failures = new Map();
@@ -1352,7 +938,7 @@ export function createCheckpointFailureTracker(directory, runId) {
1352
938
  await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 });
1353
939
  await appendFile(marker, line, { mode: 0o600 });
1354
940
  }
1355
- catch { /* the marker is best effort; the final record carries the whole list */ }
941
+ catch { }
1356
942
  },
1357
943
  async succeeded(visit) {
1358
944
  if (!failures.delete(key(visit)))
@@ -1363,33 +949,15 @@ export function createCheckpointFailureTracker(directory, runId) {
1363
949
  else
1364
950
  await writeFile(marker, [...failures.values()].map(entry => entry.line).join(''), { mode: 0o600 });
1365
951
  }
1366
- catch { /* a marker left behind only adds a warning to a later resume */ }
952
+ catch { }
1367
953
  },
1368
954
  get intact() { return failures.size === 0; },
1369
955
  get failures() { return [...failures.values()].map(entry => ({ ...entry.visit })); },
1370
956
  };
1371
957
  }
1372
- /**
1373
- * Whether a run's checkpoints are known to be incomplete: the record's flag, or the marker the
1374
- * tracker left. A resume still continues such an attempt, and tells the user that a visit whose
1375
- * conversation was not saved may repeat work.
1376
- */
1377
958
  export async function checkpointWriteFailed(directory, runId) {
1378
959
  return (await checkpointFailure(directory, runId)) !== undefined;
1379
960
  }
1380
- /**
1381
- * The checkpoint failure a run left unhealed: `undefined` when there is none.
1382
- *
1383
- * The final record comes first. It is written once every checkpoint write has settled, from the
1384
- * tracker itself, so its list is the whole failure set — while the marker is appended as failures
1385
- * happen, and the same full disk that failed a checkpoint can fail the marker line naming it. A
1386
- * record that is flagged but carries no list (a build that predates the list) therefore names
1387
- * nothing and dates nothing: its marker may be missing the very failure that matters. Only a run
1388
- * with no final record (one that crashed) is read from its marker, best effort.
1389
- *
1390
- * `visits` is absent when the failures cannot be named. `at` lets a resume see that a checkpoint
1391
- * saved after the newest failure already replaced whatever the failed write would have written.
1392
- */
1393
961
  export async function checkpointFailure(directory, runId) {
1394
962
  let record;
1395
963
  try {
@@ -1408,7 +976,6 @@ export async function checkpointFailure(directory, runId) {
1408
976
  text = await readFile(runRecordPath(directory, runId, 'checkpoint-error'), 'utf8');
1409
977
  }
1410
978
  catch (error) {
1411
- // A marker that exists but cannot be read is still a failure, only an unnamed one.
1412
979
  return error.code === 'ENOENT' ? undefined : {};
1413
980
  }
1414
981
  const visits = new Map();
@@ -1443,15 +1010,6 @@ export async function checkpointFailure(directory, runId) {
1443
1010
  ...(dated && at !== undefined ? { at } : {}),
1444
1011
  };
1445
1012
  }
1446
- /**
1447
- * The checkpoint file for one node of a run: `<runId>.checkpoint.<node-key>`.
1448
- *
1449
- * Parallel branches checkpoint concurrently, and one shared file per run meant every branch's
1450
- * write overwrote the others' — a crash kept only whichever conversation landed last. Each node
1451
- * owns a file instead, so every unfinished branch survives. Node ids carry arbitrary characters,
1452
- * so the name gets a sanitized prefix for debuggability plus a hash of the exact id for
1453
- * uniqueness: two ids that sanitize to the same prefix still get different files.
1454
- */
1455
1013
  function runCheckpointPath(directory, runId, nodeId) {
1456
1014
  const slug = nodeId.replace(/[^A-Za-z0-9_-]/g, '-').slice(0, 48);
1457
1015
  let hash = 2166136261;
@@ -1461,34 +1019,10 @@ function runCheckpointPath(directory, runId, nodeId) {
1461
1019
  }
1462
1020
  return `${runRecordPath(directory, runId, 'checkpoint')}.${slug}-${(hash >>> 0).toString(36)}`;
1463
1021
  }
1464
- /**
1465
- * Persist the in-flight conversation of the node a run is working on.
1466
- *
1467
- * The write is atomic (a staged rename, the same discipline as every durable record in this
1468
- * directory) at mode 0600: the file carries the node's full message history — including tool
1469
- * outputs — so it is as sensitive as the run journal, and a crash mid-write must never leave a
1470
- * half-file a resume would read back. A new snapshot replaces the last; the runner already
1471
- * sanitizes an interrupted conversation before publishing its checkpoint (stub tool messages are
1472
- * marked as not replayed), so whatever the callback handed over is what belongs on disk.
1473
- */
1474
1022
  export async function writeRunCheckpoint(directory, runId, checkpoint) {
1475
1023
  await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 });
1476
1024
  await writeSessionSnapshot(runCheckpointPath(directory, runId, checkpoint.nodeId), JSON.stringify(checkpoint) + '\n');
1477
1025
  }
1478
- /**
1479
- * Read back one node's checkpoint, or nothing when there is no usable one.
1480
- *
1481
- * Missing and unreadable both mean the same thing to the caller: resume without the prior
1482
- * conversation (the safe restart the runner falls back to). Shape validation is deliberately
1483
- * shallow — a checkpoint from an incompatible build would carry the wrong state fields, and the
1484
- * node re-running from scratch is safer than a seeded conversation whose counters disagree with
1485
- * the graph the run is being replayed onto.
1486
- *
1487
- * One field is rebuilt rather than trusted: the tool-failure tracker is a class whose behavior
1488
- * (and whose Map) JSON does not carry, so a resumed node gets a fresh one. Losing the repeated-
1489
- * failure strike counts is the conservative direction — the worst case is one more retry before
1490
- * the tracker strikes out again, not a crash on a state object without its methods.
1491
- */
1492
1026
  export async function readRunCheckpoint(directory, runId, nodeId) {
1493
1027
  let raw;
1494
1028
  try {
@@ -1499,11 +1033,6 @@ export async function readRunCheckpoint(directory, runId, nodeId) {
1499
1033
  }
1500
1034
  return parseRunCheckpoint(raw);
1501
1035
  }
1502
- /**
1503
- * Read every checkpoint the run kept — one file per node, plus the legacy single-file shape an
1504
- * older build may have left behind. Unreadable or invalid files are skipped individually: a
1505
- * damaged branch costs that branch its conversation, nothing more.
1506
- */
1507
1036
  export async function readRunCheckpoints(directory, runId) {
1508
1037
  const root = runRecordsDirectory(directory);
1509
1038
  const prefix = `${runId}.checkpoint`;
@@ -1516,8 +1045,6 @@ export async function readRunCheckpoints(directory, runId) {
1516
1045
  }
1517
1046
  const checkpoints = [];
1518
1047
  for (const name of names.sort()) {
1519
- // The bare `<runId>.checkpoint` is the pre-per-node shape; a per-node file is
1520
- // `<runId>.checkpoint.<node-key>`. Nothing else the runs directory holds matches either.
1521
1048
  if (name !== prefix && !name.startsWith(`${prefix}.`))
1522
1049
  continue;
1523
1050
  let raw;
@@ -1533,16 +1060,6 @@ export async function readRunCheckpoints(directory, runId) {
1533
1060
  }
1534
1061
  return checkpoints;
1535
1062
  }
1536
- /**
1537
- * Rebuild every tool-failure tracker a persisted continuation state carries.
1538
- *
1539
- * The tracker is a class JSON cannot round-trip, so its strike counts live as plain numbers in the
1540
- * file and its methods do not. A modified agent's state nests one continuation per copy
1541
- * (`state.copies[i].state`), and the runtime reaches into those on the resumed copy's first tool
1542
- * result — where a plain object has no `record`, so the failure lands after the tool already
1543
- * executed and the effect can be repeated by the next resume. The rebuild is recursive for the same
1544
- * reason: whatever state shape nests further, every tracker in it has to come back as a tracker.
1545
- */
1546
1063
  function reviveFailures(state) {
1547
1064
  const revived = { ...state, failures: new ToolFailureTracker() };
1548
1065
  if (Array.isArray(state.copies))
@@ -1558,27 +1075,17 @@ function parseRunCheckpoint(raw) {
1558
1075
  || typeof value.state.directionRevision !== 'number'
1559
1076
  || typeof value.revision !== 'number' || typeof value.savedAt !== 'string')
1560
1077
  return undefined;
1561
- // A checkpoint whose conversation is not a conversation is worse than no checkpoint: the
1562
- // resumed node REPLACES its freshly built system prompt, history and task with this array, so
1563
- // an empty or malformed one would run the node with no task at all. Anything the current
1564
- // runtime could not continue reads as absent — the compatibility contract is a fresh node.
1565
1078
  if (value.messages.length === 0 || value.messages.some(message => !message || typeof message !== 'object'
1566
1079
  || !CHECKPOINT_MESSAGE_ROLES.has(message.role)
1567
1080
  || typeof message.content !== 'string'))
1568
1081
  return undefined;
1569
- // The continuation counters drive the resumed run's limits (iterations, repairs, todo calls);
1570
- // a checkpoint missing them is from a build whose state shape this reader cannot trust.
1571
1082
  if (![value.state.iterations, value.state.repairs, value.state.todoCalls, value.state.directionRevision]
1572
1083
  .every(count => typeof count === 'number' && Number.isFinite(count)))
1573
1084
  return undefined;
1574
- // The model identity stamp is optional: garbage there degrades to "no stamp" (no predecessor-
1575
- // conversation restore for a pending successor) rather than refusing a sound checkpoint file.
1576
1085
  if (typeof value.provider !== 'string')
1577
1086
  delete value.provider;
1578
1087
  if (typeof value.model !== 'string')
1579
1088
  delete value.model;
1580
- // The delivery marker is optional and self-describing: garbage degrades to "no marker", which
1581
- // only means the text fallback is used, never that a sound checkpoint is refused.
1582
1089
  if (Array.isArray(value.steeringDelivered))
1583
1090
  value.steeringDelivered = value.steeringDelivered.filter(id => typeof id === 'string');
1584
1091
  else
@@ -1589,11 +1096,6 @@ function parseRunCheckpoint(raw) {
1589
1096
  return undefined;
1590
1097
  }
1591
1098
  }
1592
- /**
1593
- * Discard a run's checkpoints — every per-node file and the legacy single file. The terminal
1594
- * paths call this once the attempt has finished, so durable checkpoints exist only for attempts
1595
- * a resume can actually pick up again.
1596
- */
1597
1099
  export async function removeRunCheckpoint(directory, runId) {
1598
1100
  const root = runRecordsDirectory(directory);
1599
1101
  const prefix = `${runId}.checkpoint`;
@@ -1610,23 +1112,6 @@ export async function removeRunCheckpoint(directory, runId) {
1610
1112
  await rm(join(root, name), { force: true }).catch(() => { });
1611
1113
  }
1612
1114
  }
1613
- /**
1614
- * Read a claim where it stands.
1615
- *
1616
- * An ordinary read never disturbs the lock path, so a live holder cannot lose its claim merely to
1617
- * being inspected. The identity comes back with the content — and is deliberately read BEFORE the
1618
- * content, so a file replaced underneath the read answers with the identity of the newer file
1619
- * while the caller acts on the older content: a reclaimer re-reads both under its ticket, and that
1620
- * mismatch is what refuses the reclamation instead of letting it delete a claim it never judged.
1621
- * An unreadable file proves no live holder (it is stale); the holder's own pid is stale too,
1622
- * because a crashed process's pid can be recycled to this one.
1623
- *
1624
- * A live pid is corroborated against the start time the claim recorded before it counts as a live
1625
- * holder: a pid the OS handed to an unrelated process that started later cannot be the claim's
1626
- * author, and treating it as one would refuse that attempt's resume for as long as the impostor
1627
- * runs. Where the platform cannot report a start time, the pid stands on its own — the conservative
1628
- * direction, since a live holder treated as stale is what lets two engines resume at once.
1629
- */
1630
1115
  async function inspectClaim(path) {
1631
1116
  let identity;
1632
1117
  try {
@@ -1645,7 +1130,7 @@ async function inspectClaim(path) {
1645
1130
  if (typeof value.startedAt === 'string')
1646
1131
  startedAt = Date.parse(value.startedAt);
1647
1132
  }
1648
- catch { /* an unreadable claim proves no live holder: it is stale */ }
1133
+ catch { }
1649
1134
  let live = pid !== undefined && pid !== process.pid && isPidAlive(pid);
1650
1135
  if (live && startedAt !== undefined && Number.isFinite(startedAt)) {
1651
1136
  const actual = await processStartedAtFor(pid);
@@ -1654,24 +1139,6 @@ async function inspectClaim(path) {
1654
1139
  }
1655
1140
  return { ...identity, live };
1656
1141
  }
1657
- /**
1658
- * Take the exclusive right to reclaim a stale claim, or refuse while another engine holds it.
1659
- *
1660
- * Reclaiming means deleting a file, and no filesystem offers a conditional delete: two processes
1661
- * that both judge the same stale file can both proceed to remove it, and the one that removes
1662
- * second can remove the claim the other has already created and started resuming under — leaving
1663
- * two live resumers. The ticket turns the delete into a serialized step (taken by the same
1664
- * create-exclusive link the claim itself uses), so only one reclaimer at a time may remove
1665
- * anything, and every removal is additionally gated on re-reading the exact file it judged.
1666
- *
1667
- * A ticket left by a reclaimer that died mid-reclaim is taken over the way a stale claim is: its
1668
- * holder is read where it stands, and only a dead one is discarded. Two processes taking over that
1669
- * same dead ticket does not reopen the hole: the ticket guards only the delete, and the delete is
1670
- * still conditional on the identity re-read, so a doubled ticket can at worst make both reclaimers
1671
- * refuse.
1672
- *
1673
- * @returns whether this process holds the ticket, in which case the caller must remove it.
1674
- */
1675
1142
  async function takeReclaimTicket(ticket) {
1676
1143
  for (let attempt = 0; attempt < 3; attempt += 1) {
1677
1144
  const temp = `${ticket}.tmp-${process.pid}-${randomUUID()}`;
@@ -1689,48 +1156,16 @@ async function takeReclaimTicket(ticket) {
1689
1156
  const held = await inspectClaim(ticket);
1690
1157
  if (held === undefined)
1691
1158
  continue;
1692
- // Another engine is reclaiming this run right now: refuse rather than removing anything it
1693
- // may be in the middle of. Its own refusal-or-claim answer arrives for the caller to retry.
1694
1159
  if (held.live)
1695
1160
  return false;
1696
1161
  await rm(ticket, { force: true }).catch(() => { });
1697
1162
  }
1698
1163
  return false;
1699
1164
  }
1700
- /**
1701
- * Take (or refuse) the cross-process claim that this run id is being resumed.
1702
- *
1703
- * Two engines sharing one home can both be asked to resume the same stopped attempt, and the
1704
- * per-process start guard cannot see the other one. The claim is a create-exclusive file: the
1705
- * winner proceeds, and a file left by a process that is gone is stale and gets reclaimed. It is
1706
- * deliberately a separate name from every record the Runs view scans, and it names the original
1707
- * attempt — the thing two resumers would collide over.
1708
- *
1709
- * Reclamation may not be "read the file, then unlink the path", nor "rename whatever is in the
1710
- * way, then read it": the first deletes a claim another engine may have created in between, and
1711
- * the second vacates the canonical path — unlocking a live holder's claim for the rename window,
1712
- * so a third engine linking into it takes the name while the original holder still believes it
1713
- * owns it. What survives both is refusing to act on anything but verified evidence: the claim is
1714
- * read in place (which never disturbs it), the reclamation takes the ticket above, the file is
1715
- * re-read UNDER the ticket so a claim replaced in between refuses instead of being moved, and the
1716
- * moved file's identity is checked before it is discarded. A live claim is never vacated, and the
1717
- * only file ever deleted here is one this process read as stale twice and matched by identity.
1718
- *
1719
- * @returns whether the claim was taken; false means a live process holds it, or another engine is
1720
- * reclaiming it right now.
1721
- */
1722
1165
  export async function claimRunResume(directory, runId) {
1723
1166
  await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 });
1724
1167
  return takeStaleableClaim(runRecordPath(directory, runId, 'claim'));
1725
1168
  }
1726
- /**
1727
- * The generic cross-process exclusive claim over one path.
1728
- *
1729
- * One protocol serves every exclusive claim in this directory: the resume claim above and the
1730
- * per-session mutation lock below. Create-exclusive first; a file left by a dead process is
1731
- * reclaimed only under the reclaim ticket and only when the re-read under the ticket is still the
1732
- * exact file judged stale.
1733
- */
1734
1169
  async function takeStaleableClaim(path) {
1735
1170
  const ticket = `${path}.reclaim`;
1736
1171
  for (let attempt = 0; attempt < 8; attempt += 1) {
@@ -1746,7 +1181,6 @@ async function takeStaleableClaim(path) {
1746
1181
  throw error;
1747
1182
  await rm(temp, { force: true }).catch(() => { });
1748
1183
  }
1749
- // A file is in the way. A live holder answers refusal before anything touches the path.
1750
1184
  const judged = await inspectClaim(path);
1751
1185
  if (judged === undefined)
1752
1186
  continue;
@@ -1755,9 +1189,6 @@ async function takeStaleableClaim(path) {
1755
1189
  if (!await takeReclaimTicket(ticket))
1756
1190
  return false;
1757
1191
  try {
1758
- // Re-read under the ticket: between the judgement above and here another engine may have
1759
- // reclaimed the claim and started resuming under its own file. Only a file that is still
1760
- // stale AND still the exact file judged is acted on; anything else is left untouched.
1761
1192
  const current = await inspectClaim(path);
1762
1193
  if (current === undefined || current.live || current.dev !== judged.dev || current.ino !== judged.ino)
1763
1194
  continue;
@@ -1766,23 +1197,17 @@ async function takeStaleableClaim(path) {
1766
1197
  await rename(path, aside);
1767
1198
  }
1768
1199
  catch (error) {
1769
- // Gone already (a competing reclaim took it): retry the create against the new state.
1770
1200
  if (error.code === 'ENOENT')
1771
1201
  continue;
1772
1202
  throw error;
1773
1203
  }
1774
1204
  const moved = await inspectClaim(aside);
1775
1205
  if (moved === undefined || moved.dev !== judged.dev || moved.ino !== judged.ino) {
1776
- // A file this process never judged stale — an out-of-protocol writer (an older build
1777
- // sharing this home) replaced the claim between the re-read and the rename. It is put back
1778
- // before anything else happens: an unverified file is never deleted. If a third contender
1779
- // took the name in the meantime the displaced file stays under its aside name, intact,
1780
- // rather than being destroyed to make room for this attempt.
1781
1206
  try {
1782
1207
  await link(aside, path);
1783
1208
  await rm(aside, { force: true });
1784
1209
  }
1785
- catch { /* the canonical name is taken again; the displaced claim survives under its own name */ }
1210
+ catch { }
1786
1211
  return false;
1787
1212
  }
1788
1213
  await rm(aside, { force: true });
@@ -1790,17 +1215,9 @@ async function takeStaleableClaim(path) {
1790
1215
  finally {
1791
1216
  await rm(ticket, { force: true }).catch(() => { });
1792
1217
  }
1793
- // The verified stale file is gone. The next pass takes the name with the same create-exclusive
1794
- // link: a fresh contender may win it, and then its live claim is what refuses this resume.
1795
1218
  }
1796
1219
  return false;
1797
1220
  }
1798
- /**
1799
- * Give up a resume claim taken by a start that never reached its run — the claim itself, and the
1800
- * reclaim ticket this process could be holding. A live reclaimer's ticket is left alone: it is
1801
- * what serializes that engine's delete, and removing it early would hand the serialization to a
1802
- * third contender mid-reclaim.
1803
- */
1804
1221
  export async function releaseRunResumeClaim(directory, runId) {
1805
1222
  const path = runRecordPath(directory, runId, 'claim');
1806
1223
  await rm(path, { force: true }).catch(() => { });
@@ -1808,42 +1225,13 @@ export async function releaseRunResumeClaim(directory, runId) {
1808
1225
  if (held !== undefined && !held.live)
1809
1226
  await rm(`${path}.reclaim`, { force: true }).catch(() => { });
1810
1227
  }
1811
- /** Thrown when a session mutation lock is held elsewhere and does not free up within the wait. */
1812
1228
  export class SessionMutationLockHeldError extends Error {
1813
1229
  constructor(sessionId) {
1814
1230
  super(`The session ${sessionId} is being changed by another writer`);
1815
1231
  this.name = 'SessionMutationLockHeldError';
1816
1232
  }
1817
1233
  }
1818
- /**
1819
- * The in-process turnstiles, keyed by directory and session.
1820
- *
1821
- * A create-exclusive claim serializes processes, not the two awaits inside one process: two
1822
- * concurrent requests of the same engine would each try to claim, and a holder's claim carries this
1823
- * very pid, which `inspectClaim` must read as stale (a recycled pid cannot be trusted as ours). So
1824
- * same-process contenders queue here and only the queue's head ever touches the claim.
1825
- */
1826
1234
  const mutationTurns = new Map();
1827
- /**
1828
- * Serialize a session's cross-process read-modify-write mutation.
1829
- *
1830
- * Every rename, archive, and delete reads a session record, edits fields, and saves it back. Two
1831
- * windows doing that to one session can interleave — each save overwrites the whole record, so one
1832
- * loses the other's field, and a save landing after a delete recreates the session the user
1833
- * removed. The answer is one lock per session, held across exactly that window: take it before the
1834
- * busy check, do the check, the fresh re-read, and the save inside it, and release. A fresh read
1835
- * under the lock is what makes two serialized mutations additive rather than lossy: each sees what
1836
- * the last one wrote.
1837
- *
1838
- * The lock is the same claim protocol the resume claim uses — create-exclusive, with verified
1839
- * reclamation of a file left by a dead process — so a holder that dies cannot strand the session:
1840
- * the next contender reclaims and proceeds. It also carries an in-process turnstile, because the
1841
- * app-server can have two concurrent requests for one session, and a request must never judge its
1842
- * own process's live claim stale.
1843
- *
1844
- * @returns the release function. Throws `SessionMutationLockHeldError` when another writer keeps
1845
- * the lock past the wait — the caller owes the user a busy error, not a mutation.
1846
- */
1847
1235
  export async function acquireSessionMutationLock(directory, sessionId, options = {}) {
1848
1236
  const turnKey = `${resolve(directory)}\u0000${sessionId}`;
1849
1237
  const previous = mutationTurns.get(turnKey) ?? Promise.resolve();
@@ -1860,9 +1248,6 @@ export async function acquireSessionMutationLock(directory, sessionId, options =
1860
1248
  mutationTurns.delete(turnKey);
1861
1249
  releaseTurn();
1862
1250
  };
1863
- // A path-unsafe identity — never a real session, which is a UUID — cannot name a claim file. The
1864
- // turnstile above is the only serialization such an id gets; the mutation it guards is itself
1865
- // unreachable through the validated paths that construct these ids.
1866
1251
  let path;
1867
1252
  try {
1868
1253
  path = runRecordPath(directory, sessionId, 'mutation-lock');
@@ -1886,16 +1271,10 @@ export async function acquireSessionMutationLock(directory, sessionId, options =
1886
1271
  }
1887
1272
  }
1888
1273
  catch (error) {
1889
- // Anything thrown on the way to holding the claim — the timeout above, or a transient
1890
- // filesystem or permission error out of the directory write or the claim attempt — must give
1891
- // the turnstile back before it propagates. The map would otherwise keep this unresolved turn,
1892
- // and every later mutation of the session would wait behind a release that never comes: one
1893
- // transient error would shut the session's rail actions for the process lifetime.
1894
1274
  finish();
1895
1275
  throw error;
1896
1276
  }
1897
1277
  }
1898
- /** Remove the claim at `claimPath` and its dead reclaim ticket. False when the filesystem refused the unlink. */
1899
1278
  const removeClaim = async (claimPath) => {
1900
1279
  try {
1901
1280
  await rm(claimPath, { force: true });
@@ -1903,8 +1282,6 @@ export async function acquireSessionMutationLock(directory, sessionId, options =
1903
1282
  catch {
1904
1283
  return false;
1905
1284
  }
1906
- // A reclaim ticket left by a holder that died would keep refusing reclamation for whoever
1907
- // reads it next; drop one only when its holder is provably gone, as the resume release does.
1908
1285
  const held = await inspectClaim(`${claimPath}.reclaim`).catch(() => undefined);
1909
1286
  if (held !== undefined && !held.live)
1910
1287
  await rm(`${claimPath}.reclaim`, { force: true }).catch(() => { });
@@ -1913,11 +1290,6 @@ export async function acquireSessionMutationLock(directory, sessionId, options =
1913
1290
  return async () => {
1914
1291
  const claimPath = path;
1915
1292
  if (claimPath !== undefined && claimHeld) {
1916
- // A release whose unlink is refused must not resolve as though the lock were gone: the claim
1917
- // file names this live pid, so every other process keeps waiting out a mutation that is over.
1918
- // Short retries first — a scanner or indexer holding the file is a matter of moments — and if
1919
- // the filesystem keeps refusing, the in-process turn comes back at once while a detached pass
1920
- // keeps removing the claim until it is gone. The writer is done; only the file owes anyone.
1921
1293
  let removed = await removeClaim(claimPath);
1922
1294
  for (const wait of [50, 100, 200]) {
1923
1295
  if (removed)
@@ -1937,12 +1309,6 @@ export async function acquireSessionMutationLock(directory, sessionId, options =
1937
1309
  finish();
1938
1310
  };
1939
1311
  }
1940
- /**
1941
- * Clear the recovery marker once a record's `interrupted` finish has been queued.
1942
- *
1943
- * Called by the reporter rather than the sweep: the sweep must not claim the work is done, because
1944
- * the finish it returns may never be enqueued if this process dies first.
1945
- */
1946
1312
  export async function clearInterruptedTelemetry(directory, runIds) {
1947
1313
  for (const runId of runIds) {
1948
1314
  const path = runRecordPath(directory, runId, 'json');
@@ -1953,6 +1319,6 @@ export async function clearInterruptedTelemetry(directory, runIds) {
1953
1319
  delete value.telemetryPending;
1954
1320
  await writeSessionSnapshot(path, JSON.stringify(value, null, 2) + '\n');
1955
1321
  }
1956
- catch { /* A record that cannot be rewritten is reported again next time; the id is stable. */ }
1322
+ catch { }
1957
1323
  }
1958
1324
  }