@bastani/atomic 0.9.89 → 0.9.90-alpha.1

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 (868) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +13 -0
  3. package/dist/builtin/intercom/README.md +3 -1
  4. package/dist/builtin/intercom/broker/broker.ts +35 -10
  5. package/dist/builtin/intercom/broker/client.ts +42 -1
  6. package/dist/builtin/intercom/index.bundle.mjs +400 -67
  7. package/dist/builtin/intercom/package.json +1 -1
  8. package/dist/builtin/intercom/skills/intercom/SKILL.md +24 -5
  9. package/dist/builtin/intercom/types.ts +5 -0
  10. package/dist/builtin/mcp/package.json +1 -1
  11. package/dist/builtin/subagents/CHANGELOG.md +27 -0
  12. package/dist/builtin/subagents/README.md +18 -20
  13. package/dist/builtin/subagents/agents/worker.md +1 -1
  14. package/dist/builtin/subagents/package.json +1 -1
  15. package/dist/builtin/subagents/skills/feedback/SKILL.md +2 -2
  16. package/dist/builtin/subagents/skills/qlty/SKILL.md +2 -2
  17. package/dist/builtin/subagents/skills/qlty/references/commands.md +45 -12
  18. package/dist/builtin/subagents/skills/qlty/references/quickstart.md +102 -21
  19. package/dist/builtin/subagents/skills/subagent/SKILL.md +18 -17
  20. package/dist/builtin/subagents/skills/tdd/LICENSE.txt +50 -0
  21. package/dist/builtin/subagents/skills/tdd/SKILL.md +10 -0
  22. package/dist/builtin/subagents/skills/tdd/tests.md +16 -0
  23. package/dist/builtin/subagents/skills/tmux/LICENSE.txt +24 -0
  24. package/dist/builtin/subagents/skills/tmux/SKILL.md +20 -1
  25. package/dist/builtin/subagents/skills/tmux/scripts/find-sessions.sh +19 -10
  26. package/dist/builtin/subagents/skills/tmux/scripts/wait-for-text.sh +231 -19
  27. package/dist/builtin/subagents/src/extension/index.bundle.mjs +1911 -845
  28. package/dist/builtin/web-access/CHANGELOG.md +6 -0
  29. package/dist/builtin/web-access/index.bundle.mjs +158 -34
  30. package/dist/builtin/web-access/package.json +1 -1
  31. package/dist/builtin/workflows/CHANGELOG.md +36 -0
  32. package/dist/builtin/workflows/builtin/{chunk-tjk7jp9a.js → chunk-akmcsx14.js} +1 -1
  33. package/dist/builtin/workflows/builtin/{chunk-913nwrzq.js → chunk-erpybg3c.js} +109 -30
  34. package/dist/builtin/workflows/builtin/{chunk-e07n7en6.js → chunk-wpgpr31s.js} +1 -1
  35. package/dist/builtin/workflows/builtin/goal.js +2 -2
  36. package/dist/builtin/workflows/builtin/index.js +3 -3
  37. package/dist/builtin/workflows/builtin/ralph.js +2 -2
  38. package/dist/builtin/workflows/package.json +1 -1
  39. package/dist/builtin/workflows/skills/bro/SKILL.md +1 -1
  40. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_fable_5_2.md +19 -19
  41. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_haiku_5_5.md +2 -2
  42. package/dist/builtin/workflows/skills/prompt-engineer/references/claude_opus_5_5.md +3 -3
  43. package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6.md +2 -2
  44. package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_1_sol.md +2 -2
  45. package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_1_terra.md +3 -3
  46. package/dist/builtin/workflows/skills/prompt-engineer/references/gpt_6_2.md +3 -2
  47. package/dist/builtin/workflows/skills/show-me/SKILL.md +2 -2
  48. package/dist/builtin/workflows/skills/skill-creator/scripts/run_eval.py +29 -24
  49. package/dist/builtin/workflows/skills/teach/SKILL.md +8 -8
  50. package/dist/builtin/workflows/skills/unslop/SKILL.md +29 -51
  51. package/dist/builtin/workflows/src/durable/journal/internal.d.ts +10 -5
  52. package/dist/builtin/workflows/src/durable/journal/sharded-run-journal.d.ts +6 -3
  53. package/dist/builtin/workflows/src/durable/journal/sql-run-journal.d.ts +25 -3
  54. package/dist/builtin/workflows/src/extension/index.bundle.mjs +4444 -1356
  55. package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +2544 -568
  56. package/dist/builtin/workflows/src/index.js +2467 -549
  57. package/dist/builtin/workflows/src/local-worker-entry.mjs +2544 -568
  58. package/dist/cli/storage-command.d.ts +6 -0
  59. package/dist/cli/storage-command.d.ts.map +1 -1
  60. package/dist/cli/storage-command.js +11 -0
  61. package/dist/cli/storage-command.js.map +1 -1
  62. package/dist/cli/storage-search-database.d.ts +18 -0
  63. package/dist/cli/storage-search-database.d.ts.map +1 -0
  64. package/dist/cli/storage-search-database.js +90 -0
  65. package/dist/cli/storage-search-database.js.map +1 -0
  66. package/dist/cli/storage-search-session.d.ts +5 -0
  67. package/dist/cli/storage-search-session.d.ts.map +1 -0
  68. package/dist/cli/storage-search-session.js +133 -0
  69. package/dist/cli/storage-search-session.js.map +1 -0
  70. package/dist/core/agent-session-accessors.d.ts.map +1 -1
  71. package/dist/core/agent-session-accessors.js +107 -1
  72. package/dist/core/agent-session-accessors.js.map +1 -1
  73. package/dist/core/agent-session-bash.d.ts.map +1 -1
  74. package/dist/core/agent-session-bash.js +2 -0
  75. package/dist/core/agent-session-bash.js.map +1 -1
  76. package/dist/core/agent-session-boundaries.d.ts +2 -0
  77. package/dist/core/agent-session-boundaries.d.ts.map +1 -1
  78. package/dist/core/agent-session-boundaries.js +9 -4
  79. package/dist/core/agent-session-boundaries.js.map +1 -1
  80. package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -1
  81. package/dist/core/agent-session-custom-message-commit.js +2 -1
  82. package/dist/core/agent-session-custom-message-commit.js.map +1 -1
  83. package/dist/core/agent-session-detached-tools.d.ts +3 -2
  84. package/dist/core/agent-session-detached-tools.d.ts.map +1 -1
  85. package/dist/core/agent-session-detached-tools.js +156 -41
  86. package/dist/core/agent-session-detached-tools.js.map +1 -1
  87. package/dist/core/agent-session-events.d.ts +2 -1
  88. package/dist/core/agent-session-events.d.ts.map +1 -1
  89. package/dist/core/agent-session-events.js +59 -23
  90. package/dist/core/agent-session-events.js.map +1 -1
  91. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  92. package/dist/core/agent-session-extension-bindings.js +53 -4
  93. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  94. package/dist/core/agent-session-message-queue.d.ts.map +1 -1
  95. package/dist/core/agent-session-message-queue.js +2 -1
  96. package/dist/core/agent-session-message-queue.js.map +1 -1
  97. package/dist/core/agent-session-methods.d.ts +23 -3
  98. package/dist/core/agent-session-methods.d.ts.map +1 -1
  99. package/dist/core/agent-session-methods.js.map +1 -1
  100. package/dist/core/agent-session-models.d.ts.map +1 -1
  101. package/dist/core/agent-session-models.js +2 -0
  102. package/dist/core/agent-session-models.js.map +1 -1
  103. package/dist/core/agent-session-prompt.d.ts +1 -1
  104. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  105. package/dist/core/agent-session-prompt.js +14 -3
  106. package/dist/core/agent-session-prompt.js.map +1 -1
  107. package/dist/core/agent-session-queue-pause.d.ts +2 -1
  108. package/dist/core/agent-session-queue-pause.d.ts.map +1 -1
  109. package/dist/core/agent-session-queue-pause.js +8 -4
  110. package/dist/core/agent-session-queue-pause.js.map +1 -1
  111. package/dist/core/agent-session-retry.d.ts +7 -3
  112. package/dist/core/agent-session-retry.d.ts.map +1 -1
  113. package/dist/core/agent-session-retry.js +113 -112
  114. package/dist/core/agent-session-retry.js.map +1 -1
  115. package/dist/core/agent-session-runtime.d.ts +15 -0
  116. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  117. package/dist/core/agent-session-runtime.js +26 -0
  118. package/dist/core/agent-session-runtime.js.map +1 -1
  119. package/dist/core/agent-session-services.d.ts +5 -2
  120. package/dist/core/agent-session-services.d.ts.map +1 -1
  121. package/dist/core/agent-session-services.js +6 -6
  122. package/dist/core/agent-session-services.js.map +1 -1
  123. package/dist/core/agent-session-tasks.js.map +1 -1
  124. package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
  125. package/dist/core/agent-session-tool-registry.js +4 -2
  126. package/dist/core/agent-session-tool-registry.js.map +1 -1
  127. package/dist/core/agent-session-types.d.ts +19 -1
  128. package/dist/core/agent-session-types.d.ts.map +1 -1
  129. package/dist/core/agent-session-types.js.map +1 -1
  130. package/dist/core/agent-session.d.ts +11 -0
  131. package/dist/core/agent-session.d.ts.map +1 -1
  132. package/dist/core/agent-session.js +8 -0
  133. package/dist/core/agent-session.js.map +1 -1
  134. package/dist/core/anthropic-thinking-guard.d.ts +16 -1
  135. package/dist/core/anthropic-thinking-guard.d.ts.map +1 -1
  136. package/dist/core/anthropic-thinking-guard.js +124 -7
  137. package/dist/core/anthropic-thinking-guard.js.map +1 -1
  138. package/dist/core/auth-storage.d.ts +3 -0
  139. package/dist/core/auth-storage.d.ts.map +1 -1
  140. package/dist/core/auth-storage.js +10 -0
  141. package/dist/core/auth-storage.js.map +1 -1
  142. package/dist/core/detached-tool-output.d.ts +4 -0
  143. package/dist/core/detached-tool-output.d.ts.map +1 -0
  144. package/dist/core/detached-tool-output.js +48 -0
  145. package/dist/core/detached-tool-output.js.map +1 -0
  146. package/dist/core/event-loop-monitor.d.ts +4 -1
  147. package/dist/core/event-loop-monitor.d.ts.map +1 -1
  148. package/dist/core/event-loop-monitor.js +84 -159
  149. package/dist/core/event-loop-monitor.js.map +1 -1
  150. package/dist/core/export-html/index.d.ts.map +1 -1
  151. package/dist/core/export-html/index.js +26 -4
  152. package/dist/core/export-html/index.js.map +1 -1
  153. package/dist/core/export-html/saved-agent-cards.d.ts +15 -0
  154. package/dist/core/export-html/saved-agent-cards.d.ts.map +1 -0
  155. package/dist/core/export-html/saved-agent-cards.js +255 -0
  156. package/dist/core/export-html/saved-agent-cards.js.map +1 -0
  157. package/dist/core/export-html/saved-agent-viewer.js +101 -0
  158. package/dist/core/extensions/builtin-subagent-record-writer.d.ts +11 -0
  159. package/dist/core/extensions/builtin-subagent-record-writer.d.ts.map +1 -0
  160. package/dist/core/extensions/builtin-subagent-record-writer.js +33 -0
  161. package/dist/core/extensions/builtin-subagent-record-writer.js.map +1 -0
  162. package/dist/core/extensions/loader-api.d.ts +1 -1
  163. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  164. package/dist/core/extensions/loader-api.js +9 -2
  165. package/dist/core/extensions/loader-api.js.map +1 -1
  166. package/dist/core/extensions/loader-bindings.d.ts +7 -0
  167. package/dist/core/extensions/loader-bindings.d.ts.map +1 -1
  168. package/dist/core/extensions/loader-bindings.js +42 -1
  169. package/dist/core/extensions/loader-bindings.js.map +1 -1
  170. package/dist/core/extensions/loader-core.d.ts.map +1 -1
  171. package/dist/core/extensions/loader-core.js +33 -12
  172. package/dist/core/extensions/loader-core.js.map +1 -1
  173. package/dist/core/extensions/runner-events.d.ts +2 -0
  174. package/dist/core/extensions/runner-events.d.ts.map +1 -1
  175. package/dist/core/extensions/runner-events.js +17 -7
  176. package/dist/core/extensions/runner-events.js.map +1 -1
  177. package/dist/core/extensions/runner.d.ts +6 -2
  178. package/dist/core/extensions/runner.d.ts.map +1 -1
  179. package/dist/core/extensions/runner.js +5 -2
  180. package/dist/core/extensions/runner.js.map +1 -1
  181. package/dist/core/extensions/ui-types.d.ts +4 -0
  182. package/dist/core/extensions/ui-types.d.ts.map +1 -1
  183. package/dist/core/extensions/ui-types.js.map +1 -1
  184. package/dist/core/extensions/workflow-run-control-hub.d.ts +2 -2
  185. package/dist/core/extensions/workflow-run-control-hub.d.ts.map +1 -1
  186. package/dist/core/extensions/workflow-run-control-hub.js +2 -2
  187. package/dist/core/extensions/workflow-run-control-hub.js.map +1 -1
  188. package/dist/core/extensions/workflow-run-control.d.ts +10 -3
  189. package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
  190. package/dist/core/extensions/workflow-run-control.js.map +1 -1
  191. package/dist/core/first-prompt-model.d.ts +22 -0
  192. package/dist/core/first-prompt-model.d.ts.map +1 -0
  193. package/dist/core/first-prompt-model.js +84 -0
  194. package/dist/core/first-prompt-model.js.map +1 -0
  195. package/dist/core/footer-data-provider.d.ts.map +1 -1
  196. package/dist/core/footer-data-provider.js +11 -7
  197. package/dist/core/footer-data-provider.js.map +1 -1
  198. package/dist/core/fork-replay-pair.d.ts +22 -0
  199. package/dist/core/fork-replay-pair.d.ts.map +1 -0
  200. package/dist/core/fork-replay-pair.js +174 -0
  201. package/dist/core/fork-replay-pair.js.map +1 -0
  202. package/dist/core/fork-replay-wire.d.ts +11 -0
  203. package/dist/core/fork-replay-wire.d.ts.map +1 -0
  204. package/dist/core/fork-replay-wire.js +116 -0
  205. package/dist/core/fork-replay-wire.js.map +1 -0
  206. package/dist/core/messages.d.ts +2 -0
  207. package/dist/core/messages.d.ts.map +1 -1
  208. package/dist/core/messages.js +8 -4
  209. package/dist/core/messages.js.map +1 -1
  210. package/dist/core/model-runtime.d.ts +10 -1
  211. package/dist/core/model-runtime.d.ts.map +1 -1
  212. package/dist/core/model-runtime.js +76 -11
  213. package/dist/core/model-runtime.js.map +1 -1
  214. package/dist/core/package-manager-auto-resources.d.ts.map +1 -1
  215. package/dist/core/package-manager-auto-resources.js +3 -2
  216. package/dist/core/package-manager-auto-resources.js.map +1 -1
  217. package/dist/core/package-manager-resource-files.js +7 -8
  218. package/dist/core/package-manager-resource-files.js.map +1 -1
  219. package/dist/core/project-trust-state.d.ts +90 -0
  220. package/dist/core/project-trust-state.d.ts.map +1 -0
  221. package/dist/core/project-trust-state.js +65 -0
  222. package/dist/core/project-trust-state.js.map +1 -0
  223. package/dist/core/provider-rate-limits.d.ts +6 -0
  224. package/dist/core/provider-rate-limits.d.ts.map +1 -1
  225. package/dist/core/provider-rate-limits.js +43 -0
  226. package/dist/core/provider-rate-limits.js.map +1 -1
  227. package/dist/core/provider-request-admission.d.ts.map +1 -1
  228. package/dist/core/provider-request-admission.js +10 -1
  229. package/dist/core/provider-request-admission.js.map +1 -1
  230. package/dist/core/remote-catalog-provider.d.ts +6 -1
  231. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  232. package/dist/core/remote-catalog-provider.js +22 -1
  233. package/dist/core/remote-catalog-provider.js.map +1 -1
  234. package/dist/core/resolve-config-value.d.ts.map +1 -1
  235. package/dist/core/resolve-config-value.js +5 -2
  236. package/dist/core/resolve-config-value.js.map +1 -1
  237. package/dist/core/resource-loader-core.d.ts.map +1 -1
  238. package/dist/core/resource-loader-core.js +3 -0
  239. package/dist/core/resource-loader-core.js.map +1 -1
  240. package/dist/core/resource-loader-extensions.d.ts +2 -2
  241. package/dist/core/resource-loader-extensions.d.ts.map +1 -1
  242. package/dist/core/resource-loader-extensions.js +6 -4
  243. package/dist/core/resource-loader-extensions.js.map +1 -1
  244. package/dist/core/resource-loader-package-resources.d.ts +1 -0
  245. package/dist/core/resource-loader-package-resources.d.ts.map +1 -1
  246. package/dist/core/resource-loader-package-resources.js +2 -1
  247. package/dist/core/resource-loader-package-resources.js.map +1 -1
  248. package/dist/core/resource-loader-reload.d.ts +1 -1
  249. package/dist/core/resource-loader-reload.d.ts.map +1 -1
  250. package/dist/core/resource-loader-reload.js +3 -2
  251. package/dist/core/resource-loader-reload.js.map +1 -1
  252. package/dist/core/resource-loader-types.d.ts +2 -0
  253. package/dist/core/resource-loader-types.d.ts.map +1 -1
  254. package/dist/core/resource-loader-types.js.map +1 -1
  255. package/dist/core/resume/blueprint/actions.d.ts.map +1 -1
  256. package/dist/core/resume/blueprint/actions.js +15 -15
  257. package/dist/core/resume/blueprint/actions.js.map +1 -1
  258. package/dist/core/resume/blueprint/process.d.ts +6 -1
  259. package/dist/core/resume/blueprint/process.d.ts.map +1 -1
  260. package/dist/core/resume/blueprint/process.js +132 -21
  261. package/dist/core/resume/blueprint/process.js.map +1 -1
  262. package/dist/core/runtime-credentials.d.ts +5 -0
  263. package/dist/core/runtime-credentials.d.ts.map +1 -1
  264. package/dist/core/runtime-credentials.js +34 -0
  265. package/dist/core/runtime-credentials.js.map +1 -1
  266. package/dist/core/sdk-types.d.ts +2 -0
  267. package/dist/core/sdk-types.d.ts.map +1 -1
  268. package/dist/core/sdk-types.js.map +1 -1
  269. package/dist/core/sdk.d.ts +1 -1
  270. package/dist/core/sdk.d.ts.map +1 -1
  271. package/dist/core/sdk.js +187 -32
  272. package/dist/core/sdk.js.map +1 -1
  273. package/dist/core/session-account-model.d.ts +15 -0
  274. package/dist/core/session-account-model.d.ts.map +1 -0
  275. package/dist/core/session-account-model.js +105 -0
  276. package/dist/core/session-account-model.js.map +1 -0
  277. package/dist/core/session-lifecycle-scope.d.ts +5 -0
  278. package/dist/core/session-lifecycle-scope.d.ts.map +1 -1
  279. package/dist/core/session-lifecycle-scope.js.map +1 -1
  280. package/dist/core/session-manager-core.d.ts +21 -2
  281. package/dist/core/session-manager-core.d.ts.map +1 -1
  282. package/dist/core/session-manager-core.js +64 -8
  283. package/dist/core/session-manager-core.js.map +1 -1
  284. package/dist/core/session-manager-history.d.ts +3 -1
  285. package/dist/core/session-manager-history.d.ts.map +1 -1
  286. package/dist/core/session-manager-history.js +19 -5
  287. package/dist/core/session-manager-history.js.map +1 -1
  288. package/dist/core/session-manager-types.d.ts +2 -0
  289. package/dist/core/session-manager-types.d.ts.map +1 -1
  290. package/dist/core/session-manager-types.js.map +1 -1
  291. package/dist/core/session-retry-status.d.ts +22 -0
  292. package/dist/core/session-retry-status.d.ts.map +1 -0
  293. package/dist/core/session-retry-status.js +25 -0
  294. package/dist/core/session-retry-status.js.map +1 -0
  295. package/dist/core/session-worktree-snapshots.d.ts +4 -2
  296. package/dist/core/session-worktree-snapshots.d.ts.map +1 -1
  297. package/dist/core/session-worktree-snapshots.js +8 -4
  298. package/dist/core/session-worktree-snapshots.js.map +1 -1
  299. package/dist/core/settings-manager-core.d.ts +4 -0
  300. package/dist/core/settings-manager-core.d.ts.map +1 -1
  301. package/dist/core/settings-manager-core.js +73 -1
  302. package/dist/core/settings-manager-core.js.map +1 -1
  303. package/dist/core/settings-schema.js +1 -1
  304. package/dist/core/settings-schema.js.map +1 -1
  305. package/dist/core/slash-commands.d.ts +2 -2
  306. package/dist/core/slash-commands.d.ts.map +1 -1
  307. package/dist/core/slash-commands.js +15 -4
  308. package/dist/core/slash-commands.js.map +1 -1
  309. package/dist/core/storage/database.d.ts +14 -2
  310. package/dist/core/storage/database.d.ts.map +1 -1
  311. package/dist/core/storage/database.js.map +1 -1
  312. package/dist/core/storage/dialect.d.ts +13 -0
  313. package/dist/core/storage/dialect.d.ts.map +1 -1
  314. package/dist/core/storage/dialect.js +9 -1
  315. package/dist/core/storage/dialect.js.map +1 -1
  316. package/dist/core/storage/errors.d.ts +23 -1
  317. package/dist/core/storage/errors.d.ts.map +1 -1
  318. package/dist/core/storage/errors.js +28 -5
  319. package/dist/core/storage/errors.js.map +1 -1
  320. package/dist/core/storage/journal-transfer.d.ts.map +1 -1
  321. package/dist/core/storage/journal-transfer.js +90 -5
  322. package/dist/core/storage/journal-transfer.js.map +1 -1
  323. package/dist/core/storage/node-sqlite.d.ts.map +1 -1
  324. package/dist/core/storage/node-sqlite.js +61 -1
  325. package/dist/core/storage/node-sqlite.js.map +1 -1
  326. package/dist/core/storage/session/chunked-resume-projection.d.ts +4 -0
  327. package/dist/core/storage/session/chunked-resume-projection.d.ts.map +1 -0
  328. package/dist/core/storage/session/chunked-resume-projection.js +369 -0
  329. package/dist/core/storage/session/chunked-resume-projection.js.map +1 -0
  330. package/dist/core/storage/session/legacy-session-store.d.ts +5 -0
  331. package/dist/core/storage/session/legacy-session-store.d.ts.map +1 -1
  332. package/dist/core/storage/session/legacy-session-store.js +10 -2
  333. package/dist/core/storage/session/legacy-session-store.js.map +1 -1
  334. package/dist/core/storage/session/memory-session-store.d.ts.map +1 -1
  335. package/dist/core/storage/session/memory-session-store.js +6 -1
  336. package/dist/core/storage/session/memory-session-store.js.map +1 -1
  337. package/dist/core/storage/session/snapshot-generation.d.ts +8 -0
  338. package/dist/core/storage/session/snapshot-generation.d.ts.map +1 -0
  339. package/dist/core/storage/session/snapshot-generation.js +17 -0
  340. package/dist/core/storage/session/snapshot-generation.js.map +1 -0
  341. package/dist/core/storage/session/sql-session-store.d.ts +12 -0
  342. package/dist/core/storage/session/sql-session-store.d.ts.map +1 -1
  343. package/dist/core/storage/session/sql-session-store.js +243 -46
  344. package/dist/core/storage/session/sql-session-store.js.map +1 -1
  345. package/dist/core/storage/sqlite-facade.d.ts +17 -2
  346. package/dist/core/storage/sqlite-facade.d.ts.map +1 -1
  347. package/dist/core/storage/sqlite-facade.js +17 -1
  348. package/dist/core/storage/sqlite-facade.js.map +1 -1
  349. package/dist/core/tasks/agent-adapter.d.ts +13 -2
  350. package/dist/core/tasks/agent-adapter.d.ts.map +1 -1
  351. package/dist/core/tasks/agent-adapter.js +25 -8
  352. package/dist/core/tasks/agent-adapter.js.map +1 -1
  353. package/dist/core/tasks/agent-panel-rules.d.ts +77 -0
  354. package/dist/core/tasks/agent-panel-rules.d.ts.map +1 -0
  355. package/dist/core/tasks/agent-panel-rules.js +88 -0
  356. package/dist/core/tasks/agent-panel-rules.js.map +1 -0
  357. package/dist/core/tasks/agent-panel-source.d.ts +19 -0
  358. package/dist/core/tasks/agent-panel-source.d.ts.map +1 -1
  359. package/dist/core/tasks/agent-panel-source.js +50 -9
  360. package/dist/core/tasks/agent-panel-source.js.map +1 -1
  361. package/dist/core/tasks/command-output.d.ts +17 -2
  362. package/dist/core/tasks/command-output.d.ts.map +1 -1
  363. package/dist/core/tasks/command-output.js +59 -3
  364. package/dist/core/tasks/command-output.js.map +1 -1
  365. package/dist/core/tasks/completion-message.d.ts +8 -3
  366. package/dist/core/tasks/completion-message.d.ts.map +1 -1
  367. package/dist/core/tasks/completion-message.js +14 -10
  368. package/dist/core/tasks/completion-message.js.map +1 -1
  369. package/dist/core/tasks/completion.d.ts +14 -4
  370. package/dist/core/tasks/completion.d.ts.map +1 -1
  371. package/dist/core/tasks/completion.js +58 -17
  372. package/dist/core/tasks/completion.js.map +1 -1
  373. package/dist/core/tasks/contracts.d.ts +10 -1
  374. package/dist/core/tasks/contracts.d.ts.map +1 -1
  375. package/dist/core/tasks/contracts.js +3 -1
  376. package/dist/core/tasks/contracts.js.map +1 -1
  377. package/dist/core/tasks/heartbeat.js +2 -1
  378. package/dist/core/tasks/heartbeat.js.map +1 -1
  379. package/dist/core/tasks/live-elapsed.d.ts +16 -1
  380. package/dist/core/tasks/live-elapsed.d.ts.map +1 -1
  381. package/dist/core/tasks/live-elapsed.js +43 -4
  382. package/dist/core/tasks/live-elapsed.js.map +1 -1
  383. package/dist/core/tasks/owner-store.d.ts +8 -0
  384. package/dist/core/tasks/owner-store.d.ts.map +1 -1
  385. package/dist/core/tasks/owner-store.js +34 -4
  386. package/dist/core/tasks/owner-store.js.map +1 -1
  387. package/dist/core/tasks/session-scope.d.ts +7 -0
  388. package/dist/core/tasks/session-scope.d.ts.map +1 -1
  389. package/dist/core/tasks/session-scope.js +15 -9
  390. package/dist/core/tasks/session-scope.js.map +1 -1
  391. package/dist/core/tasks/supervisor.d.ts +7 -3
  392. package/dist/core/tasks/supervisor.d.ts.map +1 -1
  393. package/dist/core/tasks/supervisor.js +92 -17
  394. package/dist/core/tasks/supervisor.js.map +1 -1
  395. package/dist/core/tasks/task-archive-snapshot.d.ts +7 -0
  396. package/dist/core/tasks/task-archive-snapshot.d.ts.map +1 -0
  397. package/dist/core/tasks/task-archive-snapshot.js +33 -0
  398. package/dist/core/tasks/task-archive-snapshot.js.map +1 -0
  399. package/dist/core/tasks/task-resumer.d.ts +5 -3
  400. package/dist/core/tasks/task-resumer.d.ts.map +1 -1
  401. package/dist/core/tasks/task-resumer.js +37 -13
  402. package/dist/core/tasks/task-resumer.js.map +1 -1
  403. package/dist/core/tasks/task-view-source.d.ts +25 -3
  404. package/dist/core/tasks/task-view-source.d.ts.map +1 -1
  405. package/dist/core/tasks/task-view-source.js +144 -44
  406. package/dist/core/tasks/task-view-source.js.map +1 -1
  407. package/dist/core/tasks/transcript.d.ts +3 -1
  408. package/dist/core/tasks/transcript.d.ts.map +1 -1
  409. package/dist/core/tasks/transcript.js +27 -0
  410. package/dist/core/tasks/transcript.js.map +1 -1
  411. package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts.map +1 -1
  412. package/dist/core/tools/ask-user-question/view/dialog-builder.js +2 -1
  413. package/dist/core/tools/ask-user-question/view/dialog-builder.js.map +1 -1
  414. package/dist/core/tools/bash.d.ts.map +1 -1
  415. package/dist/core/tools/bash.js +2 -1
  416. package/dist/core/tools/bash.js.map +1 -1
  417. package/dist/core/tools/history-protocol.d.ts.map +1 -1
  418. package/dist/core/tools/history-protocol.js +130 -29
  419. package/dist/core/tools/history-protocol.js.map +1 -1
  420. package/dist/core/tools/history-search-position.d.ts +30 -0
  421. package/dist/core/tools/history-search-position.d.ts.map +1 -0
  422. package/dist/core/tools/history-search-position.js +161 -0
  423. package/dist/core/tools/history-search-position.js.map +1 -0
  424. package/dist/core/tools/history-search-wire.d.ts +25 -0
  425. package/dist/core/tools/history-search-wire.d.ts.map +1 -0
  426. package/dist/core/tools/history-search-wire.js +210 -0
  427. package/dist/core/tools/history-search-wire.js.map +1 -0
  428. package/dist/core/tools/resource-selectors.d.ts +7 -1
  429. package/dist/core/tools/resource-selectors.d.ts.map +1 -1
  430. package/dist/core/tools/resource-selectors.js +18 -11
  431. package/dist/core/tools/resource-selectors.js.map +1 -1
  432. package/dist/core/tools/search.d.ts.map +1 -1
  433. package/dist/core/tools/search.js +24 -3
  434. package/dist/core/tools/search.js.map +1 -1
  435. package/dist/core/tools/sqlite-selector-connection.d.ts +3 -0
  436. package/dist/core/tools/sqlite-selector-connection.d.ts.map +1 -1
  437. package/dist/core/tools/sqlite-selector-connection.js +4 -0
  438. package/dist/core/tools/sqlite-selector-connection.js.map +1 -1
  439. package/dist/core/tools/tool-abort-grace.d.ts +13 -0
  440. package/dist/core/tools/tool-abort-grace.d.ts.map +1 -0
  441. package/dist/core/tools/tool-abort-grace.js +72 -0
  442. package/dist/core/tools/tool-abort-grace.js.map +1 -0
  443. package/dist/core/tools/tool-concurrency.d.ts +5 -1
  444. package/dist/core/tools/tool-concurrency.d.ts.map +1 -1
  445. package/dist/core/tools/tool-concurrency.js +36 -6
  446. package/dist/core/tools/tool-concurrency.js.map +1 -1
  447. package/dist/core/workflow-resume.d.ts +1 -1
  448. package/dist/core/workflow-resume.d.ts.map +1 -1
  449. package/dist/core/workflow-resume.js +13 -3
  450. package/dist/core/workflow-resume.js.map +1 -1
  451. package/dist/core/workflow-summary-lifecycle.d.ts.map +1 -1
  452. package/dist/core/workflow-summary-lifecycle.js +8 -2
  453. package/dist/core/workflow-summary-lifecycle.js.map +1 -1
  454. package/dist/core/workspace/errors.d.ts +5 -2
  455. package/dist/core/workspace/errors.d.ts.map +1 -1
  456. package/dist/core/workspace/errors.js +59 -5
  457. package/dist/core/workspace/errors.js.map +1 -1
  458. package/dist/core/worktree-snapshot/blob-store.d.ts +138 -17
  459. package/dist/core/worktree-snapshot/blob-store.d.ts.map +1 -1
  460. package/dist/core/worktree-snapshot/blob-store.js +788 -82
  461. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  462. package/dist/core/worktree-snapshot/garbage.d.ts +17 -2
  463. package/dist/core/worktree-snapshot/garbage.d.ts.map +1 -1
  464. package/dist/core/worktree-snapshot/garbage.js +20 -4
  465. package/dist/core/worktree-snapshot/garbage.js.map +1 -1
  466. package/dist/core/worktree-snapshot/index.d.ts +1 -1
  467. package/dist/core/worktree-snapshot/index.d.ts.map +1 -1
  468. package/dist/core/worktree-snapshot/index.js +1 -1
  469. package/dist/core/worktree-snapshot/index.js.map +1 -1
  470. package/dist/core/worktree-snapshot/pool.d.ts.map +1 -1
  471. package/dist/core/worktree-snapshot/pool.js +38 -6
  472. package/dist/core/worktree-snapshot/pool.js.map +1 -1
  473. package/dist/core/worktree-snapshot/shared-clock.d.ts +3 -1
  474. package/dist/core/worktree-snapshot/shared-clock.d.ts.map +1 -1
  475. package/dist/core/worktree-snapshot/shared-clock.js +116 -26
  476. package/dist/core/worktree-snapshot/shared-clock.js.map +1 -1
  477. package/dist/core/worktree-snapshot/types.d.ts +4 -1
  478. package/dist/core/worktree-snapshot/types.d.ts.map +1 -1
  479. package/dist/core/worktree-snapshot/types.js.map +1 -1
  480. package/dist/extensions/llama/huggingface-ui.d.ts.map +1 -1
  481. package/dist/extensions/llama/huggingface-ui.js +2 -2
  482. package/dist/extensions/llama/huggingface-ui.js.map +1 -1
  483. package/dist/extensions/llama/index.d.ts +2 -0
  484. package/dist/extensions/llama/index.d.ts.map +1 -1
  485. package/dist/extensions/llama/index.js +19 -2
  486. package/dist/extensions/llama/index.js.map +1 -1
  487. package/dist/index.d.ts +9 -6
  488. package/dist/index.d.ts.map +1 -1
  489. package/dist/index.js +8 -4
  490. package/dist/index.js.map +1 -1
  491. package/dist/main.d.ts.map +1 -1
  492. package/dist/main.js +74 -15
  493. package/dist/main.js.map +1 -1
  494. package/dist/modes/interactive/components/agent-panel.d.ts +22 -6
  495. package/dist/modes/interactive/components/agent-panel.d.ts.map +1 -1
  496. package/dist/modes/interactive/components/agent-panel.js +80 -23
  497. package/dist/modes/interactive/components/agent-panel.js.map +1 -1
  498. package/dist/modes/interactive/components/assistant-message.d.ts +2 -0
  499. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  500. package/dist/modes/interactive/components/assistant-message.js +11 -0
  501. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  502. package/dist/modes/interactive/components/atomic-working-status.d.ts.map +1 -1
  503. package/dist/modes/interactive/components/atomic-working-status.js +10 -3
  504. package/dist/modes/interactive/components/atomic-working-status.js.map +1 -1
  505. package/dist/modes/interactive/components/bash-execution.d.ts +3 -2
  506. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  507. package/dist/modes/interactive/components/bash-execution.js +7 -7
  508. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  509. package/dist/modes/interactive/components/branch-summary-message.d.ts +6 -0
  510. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  511. package/dist/modes/interactive/components/branch-summary-message.js +12 -7
  512. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  513. package/dist/modes/interactive/components/chat-message-renderer.d.ts +2 -0
  514. package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
  515. package/dist/modes/interactive/components/chat-message-renderer.js +24 -3
  516. package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
  517. package/dist/modes/interactive/components/chat-session-host-actions.d.ts +1 -1
  518. package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
  519. package/dist/modes/interactive/components/chat-session-host-actions.js +16 -10
  520. package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
  521. package/dist/modes/interactive/components/chat-session-host-events.d.ts +10 -0
  522. package/dist/modes/interactive/components/chat-session-host-events.d.ts.map +1 -1
  523. package/dist/modes/interactive/components/chat-session-host-events.js +76 -31
  524. package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
  525. package/dist/modes/interactive/components/chat-session-host-rendering.d.ts +17 -5
  526. package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
  527. package/dist/modes/interactive/components/chat-session-host-rendering.js +79 -24
  528. package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
  529. package/dist/modes/interactive/components/chat-session-host-runtime.d.ts.map +1 -1
  530. package/dist/modes/interactive/components/chat-session-host-runtime.js +5 -4
  531. package/dist/modes/interactive/components/chat-session-host-runtime.js.map +1 -1
  532. package/dist/modes/interactive/components/chat-session-host-state.d.ts +16 -1
  533. package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
  534. package/dist/modes/interactive/components/chat-session-host-state.js +22 -0
  535. package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
  536. package/dist/modes/interactive/components/chat-session-host-types.d.ts +8 -2
  537. package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -1
  538. package/dist/modes/interactive/components/chat-session-host-types.js.map +1 -1
  539. package/dist/modes/interactive/components/chat-session-host-utils.d.ts +1 -0
  540. package/dist/modes/interactive/components/chat-session-host-utils.d.ts.map +1 -1
  541. package/dist/modes/interactive/components/chat-session-host-utils.js +2 -1
  542. package/dist/modes/interactive/components/chat-session-host-utils.js.map +1 -1
  543. package/dist/modes/interactive/components/chat-session-host.d.ts +35 -9
  544. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  545. package/dist/modes/interactive/components/chat-session-host.js +129 -35
  546. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  547. package/dist/modes/interactive/components/chat-transcript.d.ts +13 -2
  548. package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
  549. package/dist/modes/interactive/components/chat-transcript.js +24 -4
  550. package/dist/modes/interactive/components/chat-transcript.js.map +1 -1
  551. package/dist/modes/interactive/components/compaction-boundary-message.d.ts +6 -0
  552. package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -1
  553. package/dist/modes/interactive/components/compaction-boundary-message.js +12 -7
  554. package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -1
  555. package/dist/modes/interactive/components/composer-rule.d.ts +0 -2
  556. package/dist/modes/interactive/components/composer-rule.d.ts.map +1 -1
  557. package/dist/modes/interactive/components/composer-rule.js +4 -6
  558. package/dist/modes/interactive/components/composer-rule.js.map +1 -1
  559. package/dist/modes/interactive/components/countdown-timer.d.ts +5 -9
  560. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  561. package/dist/modes/interactive/components/countdown-timer.js +32 -23
  562. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  563. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  564. package/dist/modes/interactive/components/custom-editor.js +4 -3
  565. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  566. package/dist/modes/interactive/components/custom-entry.d.ts +6 -0
  567. package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
  568. package/dist/modes/interactive/components/custom-entry.js +15 -0
  569. package/dist/modes/interactive/components/custom-entry.js.map +1 -1
  570. package/dist/modes/interactive/components/custom-message.d.ts +7 -3
  571. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  572. package/dist/modes/interactive/components/custom-message.js +17 -15
  573. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  574. package/dist/modes/interactive/components/footer.d.ts +10 -3
  575. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  576. package/dist/modes/interactive/components/footer.js +37 -45
  577. package/dist/modes/interactive/components/footer.js.map +1 -1
  578. package/dist/modes/interactive/components/heartbeat-block.d.ts.map +1 -1
  579. package/dist/modes/interactive/components/heartbeat-block.js +3 -1
  580. package/dist/modes/interactive/components/heartbeat-block.js.map +1 -1
  581. package/dist/modes/interactive/components/host-input-form.d.ts.map +1 -1
  582. package/dist/modes/interactive/components/host-input-form.js +3 -3
  583. package/dist/modes/interactive/components/host-input-form.js.map +1 -1
  584. package/dist/modes/interactive/components/index.d.ts +1 -1
  585. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  586. package/dist/modes/interactive/components/index.js.map +1 -1
  587. package/dist/modes/interactive/components/input-label.d.ts.map +1 -1
  588. package/dist/modes/interactive/components/input-label.js +4 -5
  589. package/dist/modes/interactive/components/input-label.js.map +1 -1
  590. package/dist/modes/interactive/components/keybinding-hints.d.ts +7 -0
  591. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  592. package/dist/modes/interactive/components/keybinding-hints.js +27 -6
  593. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  594. package/dist/modes/interactive/components/main-composer-keys.d.ts +17 -2
  595. package/dist/modes/interactive/components/main-composer-keys.d.ts.map +1 -1
  596. package/dist/modes/interactive/components/main-composer-keys.js +44 -27
  597. package/dist/modes/interactive/components/main-composer-keys.js.map +1 -1
  598. package/dist/modes/interactive/components/model-selector.d.ts +6 -1
  599. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  600. package/dist/modes/interactive/components/model-selector.js +13 -7
  601. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  602. package/dist/modes/interactive/components/nav-keys.d.ts +7 -2
  603. package/dist/modes/interactive/components/nav-keys.d.ts.map +1 -1
  604. package/dist/modes/interactive/components/nav-keys.js +51 -17
  605. package/dist/modes/interactive/components/nav-keys.js.map +1 -1
  606. package/dist/modes/interactive/components/notice-line.d.ts +8 -0
  607. package/dist/modes/interactive/components/notice-line.d.ts.map +1 -1
  608. package/dist/modes/interactive/components/notice-line.js +6 -1
  609. package/dist/modes/interactive/components/notice-line.js.map +1 -1
  610. package/dist/modes/interactive/components/selector.d.ts +3 -0
  611. package/dist/modes/interactive/components/selector.d.ts.map +1 -1
  612. package/dist/modes/interactive/components/selector.js +30 -7
  613. package/dist/modes/interactive/components/selector.js.map +1 -1
  614. package/dist/modes/interactive/components/session-selector-list.d.ts.map +1 -1
  615. package/dist/modes/interactive/components/session-selector-list.js +11 -11
  616. package/dist/modes/interactive/components/session-selector-list.js.map +1 -1
  617. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  618. package/dist/modes/interactive/components/session-selector.js +2 -2
  619. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  620. package/dist/modes/interactive/components/settings-picker.d.ts +5 -0
  621. package/dist/modes/interactive/components/settings-picker.d.ts.map +1 -1
  622. package/dist/modes/interactive/components/settings-picker.js +36 -2
  623. package/dist/modes/interactive/components/settings-picker.js.map +1 -1
  624. package/dist/modes/interactive/components/settings-selector-submenus.d.ts +10 -0
  625. package/dist/modes/interactive/components/settings-selector-submenus.d.ts.map +1 -1
  626. package/dist/modes/interactive/components/settings-selector-submenus.js +89 -19
  627. package/dist/modes/interactive/components/settings-selector-submenus.js.map +1 -1
  628. package/dist/modes/interactive/components/settings-selector-types.d.ts +6 -0
  629. package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
  630. package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
  631. package/dist/modes/interactive/components/settings-selector.d.ts +7 -0
  632. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  633. package/dist/modes/interactive/components/settings-selector.js +12 -0
  634. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  635. package/dist/modes/interactive/components/skill-invocation-message.d.ts +6 -0
  636. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  637. package/dist/modes/interactive/components/skill-invocation-message.js +12 -7
  638. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  639. package/dist/modes/interactive/components/task-board.d.ts.map +1 -1
  640. package/dist/modes/interactive/components/task-board.js +9 -2
  641. package/dist/modes/interactive/components/task-board.js.map +1 -1
  642. package/dist/modes/interactive/components/task-completion-message.d.ts +10 -3
  643. package/dist/modes/interactive/components/task-completion-message.d.ts.map +1 -1
  644. package/dist/modes/interactive/components/task-completion-message.js +173 -19
  645. package/dist/modes/interactive/components/task-completion-message.js.map +1 -1
  646. package/dist/modes/interactive/components/task-inspector.d.ts +1 -1
  647. package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -1
  648. package/dist/modes/interactive/components/task-inspector.js +28 -19
  649. package/dist/modes/interactive/components/task-inspector.js.map +1 -1
  650. package/dist/modes/interactive/components/task-list.d.ts +7 -3
  651. package/dist/modes/interactive/components/task-list.d.ts.map +1 -1
  652. package/dist/modes/interactive/components/task-list.js +60 -33
  653. package/dist/modes/interactive/components/task-list.js.map +1 -1
  654. package/dist/modes/interactive/components/task-row.d.ts +7 -0
  655. package/dist/modes/interactive/components/task-row.d.ts.map +1 -1
  656. package/dist/modes/interactive/components/task-row.js +25 -11
  657. package/dist/modes/interactive/components/task-row.js.map +1 -1
  658. package/dist/modes/interactive/components/task-transcript-notices.d.ts +16 -0
  659. package/dist/modes/interactive/components/task-transcript-notices.d.ts.map +1 -0
  660. package/dist/modes/interactive/components/task-transcript-notices.js +74 -0
  661. package/dist/modes/interactive/components/task-transcript-notices.js.map +1 -0
  662. package/dist/modes/interactive/components/task-transcript-page.d.ts +11 -6
  663. package/dist/modes/interactive/components/task-transcript-page.d.ts.map +1 -1
  664. package/dist/modes/interactive/components/task-transcript-page.js +48 -21
  665. package/dist/modes/interactive/components/task-transcript-page.js.map +1 -1
  666. package/dist/modes/interactive/components/tool-block-families.d.ts.map +1 -1
  667. package/dist/modes/interactive/components/tool-block-families.js +2 -1
  668. package/dist/modes/interactive/components/tool-block-families.js.map +1 -1
  669. package/dist/modes/interactive/components/tool-execution.d.ts +3 -2
  670. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  671. package/dist/modes/interactive/components/tool-execution.js +23 -9
  672. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  673. package/dist/modes/interactive/components/transcript-block-clicks.d.ts +54 -14
  674. package/dist/modes/interactive/components/transcript-block-clicks.d.ts.map +1 -1
  675. package/dist/modes/interactive/components/transcript-block-clicks.js +151 -16
  676. package/dist/modes/interactive/components/transcript-block-clicks.js.map +1 -1
  677. package/dist/modes/interactive/components/tree-selector-help.d.ts.map +1 -1
  678. package/dist/modes/interactive/components/tree-selector-help.js +25 -30
  679. package/dist/modes/interactive/components/tree-selector-help.js.map +1 -1
  680. package/dist/modes/interactive/components/tree-selector-list.d.ts +4 -0
  681. package/dist/modes/interactive/components/tree-selector-list.d.ts.map +1 -1
  682. package/dist/modes/interactive/components/tree-selector-list.js +21 -21
  683. package/dist/modes/interactive/components/tree-selector-list.js.map +1 -1
  684. package/dist/modes/interactive/components/working-run-meter.d.ts +31 -2
  685. package/dist/modes/interactive/components/working-run-meter.d.ts.map +1 -1
  686. package/dist/modes/interactive/components/working-run-meter.js +81 -10
  687. package/dist/modes/interactive/components/working-run-meter.js.map +1 -1
  688. package/dist/modes/interactive/interactive-agent-events.js +67 -14
  689. package/dist/modes/interactive/interactive-agent-events.js.map +1 -1
  690. package/dist/modes/interactive/interactive-autocomplete.js +2 -2
  691. package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
  692. package/dist/modes/interactive/interactive-deferred-startup.d.ts.map +1 -1
  693. package/dist/modes/interactive/interactive-deferred-startup.js +10 -4
  694. package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
  695. package/dist/modes/interactive/interactive-editor-actions.js +4 -1
  696. package/dist/modes/interactive/interactive-editor-actions.js.map +1 -1
  697. package/dist/modes/interactive/interactive-extension-custom-ui.js +13 -3
  698. package/dist/modes/interactive/interactive-extension-custom-ui.js.map +1 -1
  699. package/dist/modes/interactive/interactive-extension-runtime.js +4 -2
  700. package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
  701. package/dist/modes/interactive/interactive-extension-widgets.js +6 -8
  702. package/dist/modes/interactive/interactive-extension-widgets.js.map +1 -1
  703. package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
  704. package/dist/modes/interactive/interactive-input-handling.js +43 -3
  705. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  706. package/dist/modes/interactive/interactive-mode-base.d.ts +7 -0
  707. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  708. package/dist/modes/interactive/interactive-mode-base.js +9 -2
  709. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  710. package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
  711. package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
  712. package/dist/modes/interactive/interactive-mode-deps.js +1 -1
  713. package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
  714. package/dist/modes/interactive/interactive-mode-helpers.d.ts +5 -0
  715. package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
  716. package/dist/modes/interactive/interactive-mode-helpers.js +9 -0
  717. package/dist/modes/interactive/interactive-mode-helpers.js.map +1 -1
  718. package/dist/modes/interactive/interactive-mode-surface.d.ts +10 -2
  719. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  720. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  721. package/dist/modes/interactive/interactive-model-routing.d.ts.map +1 -1
  722. package/dist/modes/interactive/interactive-model-routing.js +63 -21
  723. package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
  724. package/dist/modes/interactive/interactive-prompt-turn.js +1 -1
  725. package/dist/modes/interactive/interactive-prompt-turn.js.map +1 -1
  726. package/dist/modes/interactive/interactive-render-chat.d.ts.map +1 -1
  727. package/dist/modes/interactive/interactive-render-chat.js +71 -10
  728. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  729. package/dist/modes/interactive/interactive-resource-rendering.js +9 -18
  730. package/dist/modes/interactive/interactive-resource-rendering.js.map +1 -1
  731. package/dist/modes/interactive/interactive-selectors.js +106 -57
  732. package/dist/modes/interactive/interactive-selectors.js.map +1 -1
  733. package/dist/modes/interactive/interactive-session-routing.js +10 -5
  734. package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
  735. package/dist/modes/interactive/interactive-session-runtime.d.ts +3 -0
  736. package/dist/modes/interactive/interactive-session-runtime.d.ts.map +1 -1
  737. package/dist/modes/interactive/interactive-session-runtime.js +11 -0
  738. package/dist/modes/interactive/interactive-session-runtime.js.map +1 -1
  739. package/dist/modes/interactive/interactive-slash-commands.js +3 -0
  740. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  741. package/dist/modes/interactive/interactive-startup-chat-container.d.ts +5 -1
  742. package/dist/modes/interactive/interactive-startup-chat-container.d.ts.map +1 -1
  743. package/dist/modes/interactive/interactive-startup-chat-container.js +8 -3
  744. package/dist/modes/interactive/interactive-startup-chat-container.js.map +1 -1
  745. package/dist/modes/interactive/interactive-startup-trust.d.ts +2 -0
  746. package/dist/modes/interactive/interactive-startup-trust.d.ts.map +1 -1
  747. package/dist/modes/interactive/interactive-startup-trust.js +21 -0
  748. package/dist/modes/interactive/interactive-startup-trust.js.map +1 -1
  749. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  750. package/dist/modes/interactive/interactive-startup.js +39 -17
  751. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  752. package/dist/modes/interactive/interactive-task-projection.d.ts.map +1 -1
  753. package/dist/modes/interactive/interactive-task-projection.js +11 -1
  754. package/dist/modes/interactive/interactive-task-projection.js.map +1 -1
  755. package/dist/modes/interactive/resume-catalog.d.ts.map +1 -1
  756. package/dist/modes/interactive/resume-catalog.js +1 -0
  757. package/dist/modes/interactive/resume-catalog.js.map +1 -1
  758. package/dist/modes/interactive/theme/theme-controller.d.ts +6 -1
  759. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  760. package/dist/modes/interactive/theme/theme-controller.js +19 -1
  761. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  762. package/dist/modes/interactive-engine/engine-child-liveness.d.ts +2 -0
  763. package/dist/modes/interactive-engine/engine-child-liveness.d.ts.map +1 -1
  764. package/dist/modes/interactive-engine/engine-child-liveness.js +2 -0
  765. package/dist/modes/interactive-engine/engine-child-liveness.js.map +1 -1
  766. package/dist/modes/interactive-engine/engine-custom-ui.d.ts.map +1 -1
  767. package/dist/modes/interactive-engine/engine-custom-ui.js +54 -4
  768. package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
  769. package/dist/modes/interactive-engine/engine-render-service.d.ts.map +1 -1
  770. package/dist/modes/interactive-engine/engine-render-service.js +21 -2
  771. package/dist/modes/interactive-engine/engine-render-service.js.map +1 -1
  772. package/dist/modes/interactive-engine/extension-ui-bridge.d.ts +4 -2
  773. package/dist/modes/interactive-engine/extension-ui-bridge.d.ts.map +1 -1
  774. package/dist/modes/interactive-engine/extension-ui-bridge.js +4 -0
  775. package/dist/modes/interactive-engine/extension-ui-bridge.js.map +1 -1
  776. package/dist/modes/interactive-engine/isolated-runtime.d.ts +39 -3
  777. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  778. package/dist/modes/interactive-engine/isolated-runtime.js +219 -29
  779. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  780. package/dist/modes/interactive-engine/protocol.d.ts +33 -1
  781. package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
  782. package/dist/modes/interactive-engine/protocol.js +40 -2
  783. package/dist/modes/interactive-engine/protocol.js.map +1 -1
  784. package/dist/modes/interactive-engine/remote-command-catalog.d.ts +2 -2
  785. package/dist/modes/interactive-engine/remote-command-catalog.d.ts.map +1 -1
  786. package/dist/modes/interactive-engine/remote-command-catalog.js +7 -3
  787. package/dist/modes/interactive-engine/remote-command-catalog.js.map +1 -1
  788. package/dist/modes/interactive-engine/remote-component.d.ts.map +1 -1
  789. package/dist/modes/interactive-engine/remote-component.js +31 -5
  790. package/dist/modes/interactive-engine/remote-component.js.map +1 -1
  791. package/dist/modes/interactive-engine/remote-renderer.d.ts +20 -12
  792. package/dist/modes/interactive-engine/remote-renderer.d.ts.map +1 -1
  793. package/dist/modes/interactive-engine/remote-renderer.js +100 -34
  794. package/dist/modes/interactive-engine/remote-renderer.js.map +1 -1
  795. package/dist/modes/print-mode.d.ts.map +1 -1
  796. package/dist/modes/print-mode.js +4 -1
  797. package/dist/modes/print-mode.js.map +1 -1
  798. package/dist/modes/rpc/agent-panel-bridge.d.ts +7 -0
  799. package/dist/modes/rpc/agent-panel-bridge.d.ts.map +1 -1
  800. package/dist/modes/rpc/agent-panel-bridge.js +119 -114
  801. package/dist/modes/rpc/agent-panel-bridge.js.map +1 -1
  802. package/dist/modes/rpc/rpc-client-process.d.ts +2 -1
  803. package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
  804. package/dist/modes/rpc/rpc-client-process.js +2 -1
  805. package/dist/modes/rpc/rpc-client-process.js.map +1 -1
  806. package/dist/modes/rpc/rpc-client.d.ts +8 -0
  807. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  808. package/dist/modes/rpc/rpc-client.js +5 -1
  809. package/dist/modes/rpc/rpc-client.js.map +1 -1
  810. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  811. package/dist/modes/rpc/rpc-command-handler.js +19 -2
  812. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  813. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  814. package/dist/modes/rpc/rpc-mode.js +4 -2
  815. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  816. package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
  817. package/dist/modes/rpc/rpc-session-binding.js +7 -0
  818. package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
  819. package/dist/modes/rpc/rpc-types.d.ts +13 -1
  820. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  821. package/dist/modes/rpc/rpc-types.js.map +1 -1
  822. package/dist/utils/interactive-engine-bootstrap.d.ts +3 -0
  823. package/dist/utils/interactive-engine-bootstrap.d.ts.map +1 -1
  824. package/dist/utils/interactive-engine-bootstrap.js +25 -0
  825. package/dist/utils/interactive-engine-bootstrap.js.map +1 -1
  826. package/dist/utils/interactive-engine-env.d.ts +3 -0
  827. package/dist/utils/interactive-engine-env.d.ts.map +1 -1
  828. package/dist/utils/interactive-engine-env.js +1 -0
  829. package/dist/utils/interactive-engine-env.js.map +1 -1
  830. package/dist/utils/shell.d.ts +2 -0
  831. package/dist/utils/shell.d.ts.map +1 -1
  832. package/dist/utils/shell.js +3 -3
  833. package/dist/utils/shell.js.map +1 -1
  834. package/docs/background-tasks.md +32 -37
  835. package/docs/compaction.md +2 -2
  836. package/docs/computer-use.md +2 -0
  837. package/docs/development.md +11 -1
  838. package/docs/environment-variables.md +2 -0
  839. package/docs/extensions/api-reference.md +7 -3
  840. package/docs/extensions/authoring.md +3 -1
  841. package/docs/extensions/events.md +3 -1
  842. package/docs/extensions/ui.md +2 -0
  843. package/docs/guides/resume-on-any-machine.md +3 -1
  844. package/docs/intercom/reference.md +1 -1
  845. package/docs/intercom.md +3 -3
  846. package/docs/keybindings.md +6 -2
  847. package/docs/libraries/tui.md +4 -0
  848. package/docs/providers.md +1 -1
  849. package/docs/rpc/protocol.md +6 -4
  850. package/docs/sdk/reference.md +10 -4
  851. package/docs/sdk.md +5 -2
  852. package/docs/security.md +5 -1
  853. package/docs/session-format.md +1 -1
  854. package/docs/sessions.md +16 -0
  855. package/docs/settings.md +2 -2
  856. package/docs/skills.md +3 -3
  857. package/docs/storage.md +25 -4
  858. package/docs/subagents.md +42 -45
  859. package/docs/tui.md +1 -1
  860. package/docs/usage.md +3 -1
  861. package/docs/workflows/api-reference.md +3 -1
  862. package/docs/workflows/authoring.md +1 -1
  863. package/docs/workflows/operations.md +21 -14
  864. package/docs/workflows.md +1 -1
  865. package/docs/worktree-snapshots.md +10 -8
  866. package/npm-shrinkwrap.json +71 -49
  867. package/package.json +9 -8
  868. package/schemas/settings.schema.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"session-worktree-snapshots.js","sourceRoot":"","sources":["../../src/core/session-worktree-snapshots.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAEtE,OAAO,EAEN,2BAA2B,EAE3B,mBAAmB,EACnB,gBAAgB,GAChB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,+BAA+B,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACxG,OAAO,EAEN,sBAAsB,EACtB,uBAAuB,EACvB,cAAc,EACd,qBAAqB,EAErB,oBAAoB,EACpB,gBAAgB,GAChB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EACN,kBAAkB,EAElB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EAEnB,qBAAqB,EACrB,sBAAsB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAA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ourcesContent":["import { access, stat } from \"node:fs/promises\";\nimport { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport type { AssistantMessage } from \"@bastani/atomic-ai/compat\";\nimport { failureDebugFields, reportDebugAsync as reportDebug } from \"./debug.ts\";\nimport { timeCheckoutRestore } from \"./resume/timings.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport type { SessionEntry, WorktreeRestoreHostWarning } from \"./session-manager-types.ts\";\nimport { isStorageError } from \"./storage/errors.js\";\nimport { readSessionTail } from \"./storage/session/session-resume.js\";\nimport type { SessionRecordHeader, SessionStore } from \"./storage/session/types.js\";\nimport {\n\ttype BestWorktreeRestore,\n\tisRecoverableRestoreFailure,\n\ttype RestoreBestWorktreeOptions,\n\trestoreBestWorktree,\n\tunrestoredRecord,\n} from \"./worktree-snapshot/best-restore.ts\";\nimport { DEGRADED_RESTORE_RETENTION_DAYS, snapshotBlobHashes } from \"./worktree-snapshot/blob-store.ts\";\nimport {\n\ttype Checkout,\n\tcaptureLocatedCheckout,\n\tcaptureWorktreeSnapshot,\n\tlocateCheckout,\n\trecordWorktreeCapture,\n\ttype WorktreeSnapshotUnavailableReason,\n\twithScratchDirectory,\n\twriteWorkingTree,\n} from \"./worktree-snapshot/capture.ts\";\nimport { carryOverDegradedWork } from \"./worktree-snapshot/degraded-work.ts\";\nimport { sha256Hex } from \"./worktree-snapshot/env-hash.ts\";\nimport {\n\tfindWorkspaceError,\n\ttype GitUnavailableError,\n\tisGitUnavailableError,\n\tisWorkspaceDriftError,\n\tisWorkspaceError,\n\tisWorkspaceSnapshotError,\n\tunreadablePathError,\n\tWorkspaceDriftError,\n\ttype WorkspaceError,\n\tWorkspaceRestoreError,\n\tWorkspaceSnapshotError,\n} from \"./worktree-snapshot/errors.ts\";\nimport { scheduleSnapshotCollection } from \"./worktree-snapshot/garbage.ts\";\nimport { gitText, runGit } from \"./worktree-snapshot/git.ts\";\nimport { isHeadOnlyAdvance } from \"./worktree-snapshot/head-advance.ts\";\nimport {\n\ttype CanonicalSteps,\n\tcanonicalizeWorktreePathAsync,\n\tcanonicalPaths,\n\trunCanonicalSteps,\n\trunCanonicalStepsAsync,\n} from \"./worktree-snapshot/paths.ts\";\nimport { loadSnapshotPathPolicy } from \"./worktree-snapshot/policy.ts\";\nimport {\n\tadmitPooledWorktree,\n\tclaimIdleWorktree,\n\tconfirmPooledWorktreeLease,\n\tdiscardPooledWorktree,\n\tevictIdleWorktrees,\n\tholdRestoredWorktree,\n\ttype PoolOwner,\n\tpooledWorktreeHolder,\n\ttype RepositoryId,\n\trecordPooledWorktreeState,\n\treleaseRestoredWorktree,\n\ttype WorktreeLease,\n\tworktreeSetAside,\n} from \"./worktree-snapshot/pool.ts\";\nimport {\n\tdefaultWorktreeSnapshotStoreDir,\n\ttype RestoreWorktreeSnapshotOptions,\n\tremoveRestoredWorktree,\n\trestoreDegradedWorktreeAt,\n\trestoreWorktree,\n\trestoreWorktreeAt,\n\tsnapshotRestoreWarnings,\n\tverifyWorktree,\n} from \"./worktree-snapshot/restore.ts\";\nimport { adoptPrebuiltSeed } from \"./worktree-snapshot/seeds.ts\";\nimport { keepSessionSnapshotCommit, releaseSessionSnapshotRefs } from \"./worktree-snapshot/session-refs.ts\";\nimport type {\n\tSnapshotBlob,\n\tSnapshotBlobStore,\n\tWorktreeDegradedRestore,\n\tWorktreeDegradedWork,\n\tWorktreeRestoreWarning,\n\tWorktreeRootMapping,\n\tWorktreeSnapshot,\n\tWorktreeSnapshotSettings,\n\tWorktreeUnrestored,\n} from \"./worktree-snapshot/types.ts\";\n\nexport { isRecoverableRestoreFailure };\n\n/** Why a turn's snapshot could not be recorded: Git is unavailable, or a typed workspace failure. */\nexport type WorktreeSnapshotUnavailable = WorkspaceError | GitUnavailableError;\n\n/** Built-in tools that can change files: a turn that called one records a snapshot. */\nexport const FILE_WRITING_TOOLS: ReadonlySet<string> = new Set([\"bash\", \"edit\", \"write\", \"powershell\"]);\nconst PATH_TOOLS: ReadonlySet<string> = new Set([\"edit\", \"write\"]);\n\nexport interface TurnSnapshotDependencies {\n\treadonly sessionManager: SessionManager;\n\treadonly cwd: () => string;\n\treadonly settings: () => WorktreeSnapshotSettings;\n\t/** Whether a registered tool declares `writesFiles`. */\n\treadonly declaresWrites: (toolName: string) => boolean;\n\t/** Called once per distinct reason a snapshot could not be recorded. */\n\treadonly onUnavailable: (reason: WorktreeSnapshotUnavailable) => void;\n}\n\nfunction* isInside(parent: string, child: string): CanonicalSteps<boolean> {\n\tconst path = relative(yield parent, yield child);\n\treturn path === \"\" || (!path.startsWith(`..${sep}`) && path !== \"..\" && !isAbsolute(path));\n}\n\n/**\n * Records a `worktree_snapshot` entry per checkout at the end of each turn that called a file-writing tool. In-memory\n * sessions, which cannot be resumed elsewhere, record nothing.\n */\nexport class SessionWorktreeSnapshotRecorder {\n\tprivate readonly deps: TurnSnapshotDependencies;\n\tprivate readonly reported = new Set<string>();\n\n\tconstructor(deps: TurnSnapshotDependencies) {\n\t\tthis.deps = deps;\n\t}\n\n\tprivate report(reason: WorktreeSnapshotUnavailable): void {\n\t\tconst key = `${reason.code}\\0${JSON.stringify(reason.fields)}`;\n\t\tif (this.reported.has(key)) return;\n\t\tthis.reported.add(key);\n\t\tthis.deps.onUnavailable(reason);\n\t}\n\n\t/** Directories whose checkouts a turn may have changed: the session cwd and the targets of path-taking tools. */\n\tprivate touchedDirectories(message: AssistantMessage): string[] | undefined {\n\t\tconst cwd = this.deps.cwd();\n\t\tconst directories = new Set<string>();\n\t\tfor (const part of message.content) {\n\t\t\tif (part.type !== \"toolCall\") continue;\n\t\t\tif (!FILE_WRITING_TOOLS.has(part.name) && !this.deps.declaresWrites(part.name)) continue;\n\t\t\tdirectories.add(cwd);\n\t\t\tconst path = PATH_TOOLS.has(part.name) ? part.arguments.path : undefined;\n\t\t\tif (typeof path === \"string\" && path.length > 0) directories.add(resolve(cwd, path, \"..\"));\n\t\t}\n\t\treturn directories.size === 0 ? undefined : [...directories];\n\t}\n\n\t/** Whether the turn may record a snapshot when it ends: a persisted session called a tool that can change files. */\n\tcallsFileWritingTool(message: AssistantMessage): boolean {\n\t\treturn this.deps.sessionManager.isPersisted() && this.touchedDirectories(message) !== undefined;\n\t}\n\n\tasync recordTurn(message: AssistantMessage): Promise<void> {\n\t\tconst directories = this.touchedDirectories(message);\n\t\tif (!directories) return;\n\t\tlet settings: WorktreeSnapshotSettings;\n\t\ttry {\n\t\t\tsettings = this.deps.settings();\n\t\t} catch (error) {\n\t\t\tthis.reportFailure(error);\n\t\t\treturn;\n\t\t}\n\t\tif (!settings.enabled || !this.deps.sessionManager.isPersisted()) return;\n\t\tconst blobs = this.deps.sessionManager.getSessionStore().snapshotBlobs;\n\t\tif (!blobs) {\n\t\t\tthis.report(\n\t\t\t\tnew WorkspaceSnapshotError(\n\t\t\t\t\t\"blob-store-unsupported\",\n\t\t\t\t\tthis.deps.sessionManager.getSessionStore().descriptor.adapter,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst checkouts = new Map<string, Checkout>();\n\t\tfor (const directory of directories) {\n\t\t\ttry {\n\t\t\t\tconst checkout = await locateCheckout(await nearestExisting(directory));\n\t\t\t\tif (checkout instanceof Error) this.report(checkout);\n\t\t\t\telse if (!checkouts.has(checkout.root)) checkouts.set(checkout.root, checkout);\n\t\t\t} catch (error) {\n\t\t\t\tthis.reportFailure(error);\n\t\t\t}\n\t\t}\n\t\tfor (const [root, checkout] of checkouts) {\n\t\t\t// A pooled worktree this session no longer holds may be another session's work: never recorded as its (#4830).\n\t\t\tif (!(await holdsSessionWorktree(this.deps.sessionManager, root))) {\n\t\t\t\tthis.report(new WorkspaceSnapshotError(\"pooled-worktree-lost\", root));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst previous = this.deps.sessionManager.getLatestWorktreeSnapshots().get(root);\n\t\t\t// A capture in a partly restored worktree records it as derived from the snapshot it lacks (#4922); one of a\n\t\t\t// full restore that carried work over records the merged worktree, or keeps naming the work it kept (#5009).\n\t\t\tconst pin = await degradedRestorePinAsync(this.deps.sessionManager, root);\n\t\t\ttry {\n\t\t\t\tlet captureMs = 0;\n\t\t\t\t// The first capture uses the lookup above; one that a collection makes run again looks the checkout up anew.\n\t\t\t\tlet located: Checkout | undefined = checkout;\n\t\t\t\tawait recordWorktreeCapture(\n\t\t\t\t\tblobs,\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tconst started = performance.now();\n\t\t\t\t\t\tconst result =\n\t\t\t\t\t\t\tlocated === undefined\n\t\t\t\t\t\t\t\t? await captureWorktreeSnapshot(root, { settings, previous, blobs })\n\t\t\t\t\t\t\t\t: await captureLocatedCheckout(located, { settings, previous, blobs });\n\t\t\t\t\t\tlocated = undefined;\n\t\t\t\t\t\tcaptureMs = Math.floor(performance.now() - started);\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t},\n\t\t\t\t\tasync (result) => {\n\t\t\t\t\t\tif (result.status === \"captured\" || result.status === \"unchanged\") {\n\t\t\t\t\t\t\tawait this.deps.sessionManager.appendWorktreeSnapshot(\n\t\t\t\t\t\t\t\troot,\n\t\t\t\t\t\t\t\tresult.snapshot.id,\n\t\t\t\t\t\t\t\tresult.status === \"captured\" ? result.snapshot : undefined,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\tcaptureMs,\n\t\t\t\t\t\t\t\tcaptureDegradedFrom(pin, result.snapshot.id),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tawait keepLatestSnapshotCommit(this.deps.sessionManager, root, result.snapshot);\n\t\t\t\t\t\t} else if (result.status === \"unavailable\") {\n\t\t\t\t\t\t\tthis.report(result.reason);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tthis.reportFailure(error);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Starts an automatic collection of the session store's unreferenced snapshot blobs when one is due, and returns\n\t * without waiting for it. Called when the session closes.\n\t */\n\tscheduleCollection(): void {\n\t\tlet settings: WorktreeSnapshotSettings;\n\t\ttry {\n\t\t\tsettings = this.deps.settings();\n\t\t} catch (error) {\n\t\t\tthis.reportFailure(error);\n\t\t\treturn;\n\t\t}\n\t\tvoid scheduleSnapshotCollection(this.deps.sessionManager.getSessionStore().snapshotBlobs, settings);\n\t}\n\n\t/**\n\t * Releases the pooled worktrees this session holds (#4748), each with the latest snapshot the session recorded of\n\t * it as its known state. Called when the session closes; never throws.\n\t */\n\tasync releaseWorktrees(): Promise<void> {\n\t\tawait releaseSessionWorktrees(this.deps.sessionManager);\n\t}\n\n\t/**\n\t * Reports a typed reason once. A storage failure, such as a store that is unreachable or refuses a payload, is a\n\t * `blob-store-failed` reason: recording a snapshot never fails the turn (#4954). Any other error is a defect.\n\t */\n\tprivate reportFailure(error: unknown): void {\n\t\tconst reason = isGitUnavailableError(error) ? error : findWorkspaceError(error);\n\t\tif (reason) {\n\t\t\tthis.report(reason);\n\t\t\treturn;\n\t\t}\n\t\tif (!isStorageFailure(error)) throw error;\n\t\tthis.report(\n\t\t\tnew WorkspaceSnapshotError(\n\t\t\t\t\"blob-store-failed\",\n\t\t\t\tthis.deps.sessionManager.getSessionStore().descriptor.adapter,\n\t\t\t\terror as Error,\n\t\t\t),\n\t\t);\n\t}\n}\n\n/** Whether `error`, or a cause of it, is a failure of the storage: a storage error, or a session store's. */\nfunction isStorageFailure(error: unknown): boolean {\n\tlet current = error;\n\tfor (let depth = 0; depth < 8 && current instanceof Error; depth++) {\n\t\tif (isStorageError(current) || current.name.startsWith(\"Storage\") || current.name === \"StoreClosedError\")\n\t\t\treturn true;\n\t\tcurrent = current.cause;\n\t}\n\treturn false;\n}\n\n/**\n * Keeps the commit of `snapshot`, the session's latest of the checkout at `root`, reachable from the session's ref in\n * that repository, so `git gc` does not prune it and resume still recognises the checkout (#4923). The ref of each\n * checkout the session's work in `root` came from through restores is released, as retention releases its snapshot.\n */\nasync function keepLatestSnapshotCommit(\n\tsessionManager: SessionManager,\n\troot: string,\n\tsnapshot: WorktreeSnapshot,\n): Promise<void> {\n\tconst sessionId = sessionManager.getSessionId();\n\tawait keepSessionSnapshotCommit(sessionId, root, snapshot.snapshot);\n\tawait releaseSessionSnapshotRefs(sessionId, restoredLineage(root, sessionManager.getWorktreeRootMappings()));\n}\n\n/**\n * The other checkouts that restores connect `root` to: walking the mappings newest first, each one the work in a\n * connected checkout was restored from or moved to.\n */\nfunction restoredLineage(root: string, mappings: readonly WorktreeRootMapping[]): string[] {\n\tconst connected = new Set([resolve(root)]);\n\tfor (const mapping of [...mappings].reverse()) {\n\t\tconst from = resolve(mapping.from);\n\t\tconst to = resolve(mapping.to);\n\t\tif (connected.has(from) || connected.has(to)) connected.add(from).add(to);\n\t}\n\tconnected.delete(resolve(root));\n\treturn [...connected];\n}\n\n/**\n * Deletes session `sessionId` from `store`, then the refs that kept its snapshot commits in the repositories of the\n * checkouts it recorded on this node (#4923). Rejects as `store.delete` does; releasing the refs never fails it.\n */\nexport async function deleteSessionWithSnapshotRefs(\n\tstore: Pick<SessionStore, \"load\" | \"delete\">,\n\tsessionId: string,\n): Promise<void> {\n\tconst roots = await store.load(sessionId).then(\n\t\t({ entries }) => entries.flatMap((entry) => (entry.type === \"worktree_snapshot\" ? [entry.root] : [])),\n\t\t() => [],\n\t);\n\tawait store.delete(sessionId);\n\tawait releaseSessionSnapshotRefs(sessionId, new Set(roots));\n}\n\nasync function nearestExisting(directory: string): Promise<string> {\n\tfor (let current = directory; ; current = resolve(current, \"..\")) {\n\t\ttry {\n\t\t\tif ((await stat(current)).isDirectory()) return current;\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\" && (error as NodeJS.ErrnoException).code !== \"ENOTDIR\")\n\t\t\t\tthrow unreadablePathError(current, error);\n\t\t}\n\t\tif (resolve(current, \"..\") === current) return current;\n\t}\n}\n\n/** The pooled worktrees each open session holds, released when it closes (#4748). */\nconst sessionLeases = new WeakMap<SessionManager, WorktreeLease[]>();\n\nfunction sessionOwner(sessionManager: Pick<SessionManager, \"getSessionId\">): PoolOwner {\n\treturn { kind: \"session\", id: sessionManager.getSessionId() };\n}\n\nfunction holdFor(sessionManager: SessionManager, lease: WorktreeLease): void {\n\tconst leases = sessionLeases.get(sessionManager) ?? [];\n\tleases.push(lease);\n\tsessionLeases.set(sessionManager, leases);\n}\n\n/**\n * The pooled worktrees, by canonical root, each session of this process holds no lease of though its record may still\n * name it (#4830): its lease was lost to another holder, or holding it failed. The session no longer works in them.\n */\nconst forfeitedWorktrees = new Map<string, Set<string>>();\n\nasync function worktreeKey(root: string): Promise<string> {\n\ttry {\n\t\treturn await canonicalizeWorktreePathAsync(root);\n\t} catch {\n\t\treturn resolve(root);\n\t}\n}\n\nasync function forfeit(sessionId: string, root: string): Promise<void> {\n\tconst key = await worktreeKey(root);\n\tconst roots = forfeitedWorktrees.get(sessionId) ?? new Set();\n\troots.add(key);\n\tforfeitedWorktrees.set(sessionId, roots);\n}\n\nasync function forfeited(sessionId: string, root: string): Promise<boolean> {\n\treturn forfeitedWorktrees.get(sessionId)?.has(await worktreeKey(root)) === true;\n}\n\n/**\n * Whether `lease`, held by `sessionManager`, still holds its slot (#4830). A lease whose slot another holder took is\n * dropped, and its worktree forfeited: the session must not continue in it.\n */\nasync function keepsLease(sessionManager: SessionManager, lease: WorktreeLease): Promise<boolean> {\n\tif (await confirmPooledWorktreeLease(lease)) return true;\n\tconst leases = sessionLeases.get(sessionManager) ?? [];\n\tleases.splice(leases.indexOf(lease), 1);\n\tawait forfeit(sessionManager.getSessionId(), lease.path);\n\treportDebug(\"storage\", \"worktree-pool-lease-lost\", { path: lease.path });\n\treturn false;\n}\n\n/**\n * Whether `sessionManager` may still work in the checkout at `root` (#4830): false for a pooled worktree whose lease it\n * lost to another holder, or could not take, checked against the slot's record. True for any other checkout.\n */\nasync function holdsSessionWorktree(sessionManager: SessionManager, root: string): Promise<boolean> {\n\tif (await forfeited(sessionManager.getSessionId(), root)) return false;\n\tconst key = await worktreeKey(root);\n\tconst held = sessionLeases.get(sessionManager) ?? [];\n\tconst keys = await Promise.all(held.map((lease) => worktreeKey(lease.path)));\n\tconst lease = held.find((_, index) => keys[index] === key);\n\treturn lease === undefined || (await keepsLease(sessionManager, lease));\n}\n\n/**\n * Whether the worktree at `root` is a pooled slot that another session owns (#4748), or that session `sessionId`\n * could not hold or lost while it was stalled (#4830): this session must not continue in it, and restores its checkout\n * fresh as if the worktree were gone. Reads only; false for any unpooled path.\n */\nexport async function pooledWorktreeOwnedElsewhere(\n\tstoreDir: string,\n\troot: string,\n\tsessionId: string,\n): Promise<boolean> {\n\tif (await worktreeSetAside(storeDir, root)) return true;\n\tconst holder = await pooledWorktreeHolder(storeDir, root);\n\tif (holder === \"unpooled\") return false;\n\treturn holder.owner?.kind !== \"session\" || holder.owner.id !== sessionId || (await forfeited(sessionId, root));\n}\n\n/**\n * Makes `to`, the session a resume opened, hold every pooled worktree of its checkouts that it owns, then releases what\n * `from`, the session the resume restored on, held, when it is another object (#4748). A slot leased by a live process\n * of the same session stays with that process. A lease `to` already holds is checked first: one whose slot another\n * holder took is dropped (#4830). Never throws: a resume continues without a lease, and then treats each pooled\n * worktree it could not hold as another session's, restoring it fresh instead of working in it unleased (#4830).\n */\nexport async function holdSessionWorktrees(\n\tfrom: SessionManager,\n\tto: SessionManager,\n\tstoreDir: string = defaultWorktreeSnapshotStoreDir(),\n\tsignal?: AbortSignal,\n): Promise<void> {\n\ttry {\n\t\tconst owner = sessionOwner(to);\n\t\tconst held = new Set<string>();\n\t\tfor (const lease of [...(sessionLeases.get(to) ?? [])]) {\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (await keepsLease(to, lease)) held.add(lease.path);\n\t\t}\n\t\tfor (const root of (await currentWorktreeSnapshots(to)).keys()) {\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (held.has(root)) continue;\n\t\t\ttry {\n\t\t\t\tconst lease = await holdRestoredWorktree(storeDir, root, owner, signal);\n\t\t\t\tif (lease !== undefined) {\n\t\t\t\t\tholdFor(to, lease);\n\t\t\t\t\tconst key = await worktreeKey(root);\n\t\t\t\t\tforfeitedWorktrees.get(owner.id)?.delete(key);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (signal?.aborted) break;\n\t\t\t\treportDebug(\"storage\", \"worktree-pool-hold-failed\", { root, ...failureDebugFields(error) });\n\t\t\t\tawait forfeit(owner.id, root);\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-hold-failed\", failureDebugFields(error));\n\t}\n\tif (from !== to) await releaseSessionWorktrees(from);\n}\n\n/** Releases every pooled worktree `sessionManager` holds, with the latest snapshot it recorded of each. Never throws. */\nexport async function releaseSessionWorktrees(sessionManager: SessionManager): Promise<void> {\n\tconst leases = sessionLeases.get(sessionManager) ?? [];\n\tsessionLeases.delete(sessionManager);\n\tif (leases.length === 0) return;\n\tconst latest = [...sessionManager.getLatestWorktreeSnapshots()];\n\tfor (const lease of leases) {\n\t\ttry {\n\t\t\tconst canonical = canonicalPaths();\n\t\t\tconst path = await canonical(lease.path);\n\t\t\tlet snapshot: WorktreeSnapshot | undefined;\n\t\t\tfor (const [root, candidate] of latest) {\n\t\t\t\tif ((await canonical(root)) !== path) continue;\n\t\t\t\tsnapshot = candidate;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tawait releaseRestoredWorktree(\n\t\t\t\tlease,\n\t\t\t\tsnapshot && { snapshotId: snapshot.id, head: snapshot.head, tree: snapshot.tree },\n\t\t\t);\n\t\t} catch (error) {\n\t\t\treportDebug(\"storage\", \"worktree-pool-release-failed\", failureDebugFields(error));\n\t\t}\n\t}\n}\n\n/** `path` rewritten through each restore in order: a path under `from` moves to the same place under `to`. */\nexport function mapRestoredPath(path: string, mappings: readonly Pick<WorktreeRootMapping, \"from\" | \"to\">[]): string {\n\treturn runCanonicalSteps(restoredPath(path, mappings));\n}\n\nexport function mapRestoredPathAsync(\n\tpath: string,\n\tmappings: readonly Pick<WorktreeRootMapping, \"from\" | \"to\">[],\n): Promise<string> {\n\treturn runCanonicalStepsAsync(restoredPath(path, mappings));\n}\n\nfunction* restoredPath(\n\tpath: string,\n\tmappings: readonly Pick<WorktreeRootMapping, \"from\" | \"to\">[],\n): CanonicalSteps<string> {\n\tlet mapped = resolve(path);\n\tlet next = 0;\n\twhile (next < mappings.length) {\n\t\tconst current = yield mapped;\n\t\tlet best: { index: number; source: string } | undefined;\n\t\tfor (let index = next; index < mappings.length; index++) {\n\t\t\tconst source = yield mappings[index]!.from;\n\t\t\tif ((yield* isInside(source, current)) && (best === undefined || source.length > best.source.length)) {\n\t\t\t\tbest = { index, source };\n\t\t\t}\n\t\t}\n\t\tif (best === undefined) break;\n\t\tmapped = resolve(mappings[best.index]!.to, relative(best.source, current));\n\t\tnext = best.index + 1;\n\t}\n\treturn mapped;\n}\n\n/** Recover the original root of a sequence of restores, so a restored root supersedes its earlier location. */\nfunction* originalRoot(root: string, mappings: readonly WorktreeRootMapping[]): CanonicalSteps<string> {\n\tlet current = yield root;\n\tfor (let index = mappings.length - 1; index >= 0; index--) {\n\t\tconst mapping = mappings[index]!;\n\t\tif ((yield mapping.to) === current) current = yield mapping.from;\n\t}\n\treturn current;\n}\n\nexport { DEGRADED_RESTORE_RETENTION_DAYS };\n\nconst DEGRADED_RESTORE_RETENTION_MS = DEGRADED_RESTORE_RETENTION_DAYS * 24 * 60 * 60 * 1000;\n\n/**\n * A checkout a resume restored with less than its snapshot (#4922): the snapshot stays the checkout's restore target\n * while the session records the partly restored worktree as it is.\n */\nexport interface DegradedRestorePin {\n\t/** The snapshot restored only partly. */\n\treadonly snapshotId: string;\n\t/** When the partial restore happened. */\n\treadonly since: string;\n\t/** What the partial restore put into the worktree, when the session recorded it: the base of the work done there. */\n\treadonly base?: { readonly head: string; readonly tree: string };\n\t/** Whether {@link DEGRADED_RESTORE_RETENTION_DAYS} have passed since the partial restore, which ends the pin. */\n\treadonly lapsed: boolean;\n\t/**\n\t * After a full restore of `snapshotId` carried the work of the partly restored worktree over (#5009): the snapshot\n\t * of that work, which stays kept until the merged worktree is recorded, so a resume elsewhere carries it over again.\n\t */\n\treadonly work?: string;\n\t/**\n\t * Whether that work conflicted with the full restore and was kept apart (#5009): it stays kept, and the checkout\n\t * continues from its latest snapshot, until `discardDegradedRestore` releases it.\n\t */\n\treadonly kept?: boolean;\n}\n\n/** What the active branch records of one checkout: its latest snapshot, and the pin of a partial restore, if any. */\ninterface CheckoutRecord {\n\t/** The latest snapshot recorded of the checkout: what its worktree holds. */\n\treadonly latest: string;\n\treadonly pin?: DegradedRestorePin;\n}\n\nfunction isLapsed(since: string, now: number): boolean {\n\tconst started = Date.parse(since);\n\t// A time that cannot be read never ends the pin: keeping the snapshot is the safe side.\n\treturn Number.isFinite(started) && now - started > DEGRADED_RESTORE_RETENTION_MS;\n}\n\n/**\n * What the active branch records of each checkout, keyed by the root it was first recorded under. A restore with less\n * than its snapshot pins the snapshot (#4922); entries naming it in `degradedFrom` keep the pin, and any other entry\n * of the checkout ends it.\n */\nfunction* checkoutRecords(\n\tsessionManager: Pick<SessionManager, \"getBranch\">,\n\tmappings: readonly WorktreeRootMapping[],\n\tnow = Date.now(),\n): CanonicalSteps<Map<string, CheckoutRecord>> {\n\tconst checkouts = new Map<string, CheckoutRecord>();\n\tconst originals = new Map<string, string>();\n\tfor (const entry of sessionManager.getBranch()) {\n\t\tif (entry.type !== \"worktree_snapshot\") continue;\n\t\tconst original = originals.get(entry.root) ?? (yield* originalRoot(entry.root, mappings));\n\t\toriginals.set(entry.root, original);\n\t\tconst previous = checkouts.get(original)?.pin;\n\t\tlet pin: DegradedRestorePin | undefined;\n\t\tconst carried = entry.restore?.degradedWork;\n\t\tif (\n\t\t\tentry.degradedFrom !== undefined &&\n\t\t\tcarried?.snapshotId === entry.degradedFrom &&\n\t\t\tcarried.outcome !== \"unavailable\"\n\t\t) {\n\t\t\t// A full restore that carried the work over keeps that work until the merged worktree is recorded (#5009).\n\t\t\tpin = {\n\t\t\t\tsnapshotId: entry.snapshotId,\n\t\t\t\tsince: entry.timestamp,\n\t\t\t\tbase: previous?.base,\n\t\t\t\tlapsed: isLapsed(entry.timestamp, now),\n\t\t\t\twork: entry.degradedFrom,\n\t\t\t\t...(carried.outcome === \"kept\" ? { kept: true } : {}),\n\t\t\t};\n\t\t} else if (entry.degradedFrom !== undefined) {\n\t\t\tpin =\n\t\t\t\tprevious?.snapshotId === entry.degradedFrom || (previous?.kept && previous.work === entry.degradedFrom)\n\t\t\t\t\t? previous\n\t\t\t\t\t: { snapshotId: entry.degradedFrom, since: entry.timestamp, lapsed: isLapsed(entry.timestamp, now) };\n\t\t} else if (entry.restore?.degraded) {\n\t\t\tconst { degraded, restoredAt } = entry.restore;\n\t\t\tpin = {\n\t\t\t\tsnapshotId: entry.snapshotId,\n\t\t\t\tsince: restoredAt,\n\t\t\t\tbase: { head: degraded.head, tree: degraded.tree },\n\t\t\t\tlapsed: isLapsed(restoredAt, now),\n\t\t\t};\n\t\t}\n\t\tcheckouts.set(original, { latest: entry.snapshotId, ...(pin === undefined ? {} : { pin }) });\n\t}\n\treturn checkouts;\n}\n\n/** The snapshot a resume restores for `checkout`: the pinned one while its pin stands, else the latest (#4922). */\nfunction restoreTargetId(checkout: CheckoutRecord): string {\n\treturn checkout.pin !== undefined && !checkout.pin.lapsed && !checkout.pin.kept\n\t\t? checkout.pin.snapshotId\n\t\t: checkout.latest;\n}\n\n/**\n * The snapshot a capture of the checkout pinned by `pin` names in `degradedFrom`, given that it records `snapshotId`:\n * the snapshot a partial restore lacks, or kept conflicting work (#5009); none once a capture records the merged\n * worktree of a full restore that carried the work over, which ends the pin.\n */\nfunction captureDegradedFrom(pin: DegradedRestorePin | undefined, snapshotId: string): string | undefined {\n\tconst named =\n\t\tpin === undefined ? undefined : pin.work === undefined ? pin.snapshotId : pin.kept ? pin.work : undefined;\n\treturn named === snapshotId ? undefined : named;\n}\n\n/**\n * Records again the checkouts whose full restore carried the work of a partly restored worktree over but whose merged\n * worktree a capture has not recorded yet (#5009), where that worktree is still here holding the restored snapshot's\n * commit; a worktree that is not here fails its capture, which changes nothing. Recording it ends the pin. A checkout that cannot be recorded keeps its pin; the reason goes to the debug log.\n */\nexport async function recordPendingCarriedWork(\n\tsessionManager: SessionManager,\n\toptions: { readonly settings: WorktreeSnapshotSettings; readonly storeDir: string; readonly signal?: AbortSignal },\n): Promise<void> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tfor (const [original, checkout] of await runCanonicalStepsAsync(checkoutRecords(sessionManager, mappings))) {\n\t\tconst pin = checkout.pin;\n\t\tif (pin?.work === undefined || pin.kept || pin.lapsed) continue;\n\t\tconst root = await mapRestoredPathAsync(original, mappings);\n\t\tif (await pooledWorktreeOwnedElsewhere(options.storeDir, root, sessionManager.getSessionId())) continue;\n\t\tawait recordCarriedWork(sessionManager, root, records.get(pin.snapshotId)?.head, options);\n\t}\n}\n\n/**\n * The pin of the checkout recorded at `root` while it stands (#4922): the snapshot a resume restored only partly, which\n * stays the checkout's restore target. Undefined when the checkout holds what its latest snapshot records.\n */\nexport function degradedRestorePin(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n\troot: string,\n): DegradedRestorePin | undefined {\n\treturn runCanonicalSteps(pinOf(sessionManager, root));\n}\n\nfunction degradedRestorePinAsync(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n\troot: string,\n): Promise<DegradedRestorePin | undefined> {\n\treturn runCanonicalStepsAsync(pinOf(sessionManager, root));\n}\n\nfunction* pinOf(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n\troot: string,\n): CanonicalSteps<DegradedRestorePin | undefined> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst checkouts = yield* checkoutRecords(sessionManager, mappings);\n\tconst pin = checkouts.get(yield* originalRoot(root, mappings))?.pin;\n\treturn pin !== undefined && !pin.lapsed ? pin : undefined;\n}\n\n/**\n * The id of the snapshot a resume restores for each checkout on the active branch, keyed by the root it was first\n * recorded under: its latest, or the snapshot a resume restored only partly while that pin stands (#4922).\n */\nfunction* latestSnapshotIdsByCheckout(\n\tsessionManager: Pick<SessionManager, \"getBranch\">,\n\tmappings: readonly WorktreeRootMapping[],\n): CanonicalSteps<Map<string, string>> {\n\tconst latestIds = new Map<string, string>();\n\tfor (const [original, checkout] of yield* checkoutRecords(sessionManager, mappings)) {\n\t\tlatestIds.set(original, restoreTargetId(checkout));\n\t}\n\treturn latestIds;\n}\n\n/**\n * The snapshot a resume restores for each root the active branch last recorded a snapshot under, keyed as\n * `getLatestWorktreeSnapshots` keys them: the latest, or the snapshot a resume restored only partly while that pin\n * stands (#4922). A pinned snapshot whose record is missing leaves the latest in its place.\n */\nexport function latestRestoreTargets(\n\tsessionManager: Pick<\n\t\tSessionManager,\n\t\t\"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\" | \"getLatestWorktreeSnapshots\"\n\t>,\n): Promise<Map<string, WorktreeSnapshot>> {\n\treturn runCanonicalStepsAsync(restoreTargets(sessionManager));\n}\n\nfunction* restoreTargets(\n\tsessionManager: Pick<\n\t\tSessionManager,\n\t\t\"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\" | \"getLatestWorktreeSnapshots\"\n\t>,\n): CanonicalSteps<Map<string, WorktreeSnapshot>> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst checkouts = yield* checkoutRecords(sessionManager, mappings);\n\tconst targets = new Map<string, WorktreeSnapshot>();\n\tfor (const [root, snapshot] of sessionManager.getLatestWorktreeSnapshots()) {\n\t\tconst checkout = checkouts.get(yield* originalRoot(root, mappings));\n\t\tconst target = checkout === undefined ? undefined : records.get(restoreTargetId(checkout));\n\t\ttargets.set(root, target ?? snapshot);\n\t}\n\treturn targets;\n}\n\nexport interface DiscardDegradedRestoreOptions {\n\treadonly settings: WorktreeSnapshotSettings;\n\t/** The partly restored worktree to release, where the session works in it now. Default: every one the session has. */\n\treadonly root?: string;\n\treadonly signal?: AbortSignal;\n}\n\n/**\n * Gives up on the snapshots a resume could restore only partly (#4922): records each partly restored worktree as it is\n * now, as a turn's capture would, without naming the snapshot it lacks, so that worktree's state becomes the\n * checkout's restore target and collection releases the snapshot it lacked. Resolves with the roots it recorded.\n * Rejects with `blob-store-unsupported` when the session's storage holds no snapshot content, and with the reason a\n * worktree could not be captured.\n */\nexport async function discardDegradedRestore(\n\tsessionManager: SessionManager,\n\toptions: DiscardDegradedRestoreOptions,\n): Promise<string[]> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst released: string[] = [];\n\tfor (const [original, checkout] of await runCanonicalStepsAsync(checkoutRecords(sessionManager, mappings))) {\n\t\tif (checkout.pin === undefined) continue;\n\t\tconst root = await mapRestoredPathAsync(original, mappings);\n\t\tif (\n\t\t\toptions.root !== undefined &&\n\t\t\t(await canonicalizeWorktreePathAsync(root)) !== (await canonicalizeWorktreePathAsync(options.root))\n\t\t)\n\t\t\tcontinue;\n\t\tconst store = sessionManager.getSessionStore();\n\t\tif (store.snapshotBlobs === undefined)\n\t\t\tthrow new WorkspaceSnapshotError(\"blob-store-unsupported\", store.descriptor.adapter);\n\t\tconst blobs = store.snapshotBlobs;\n\t\tconst previous = sessionManager.getLatestWorktreeSnapshots().get(root);\n\t\tlet recorded = false;\n\t\tawait recordWorktreeCapture(\n\t\t\tblobs,\n\t\t\t() => captureWorktreeSnapshot(root, { settings: options.settings, previous, blobs, signal: options.signal }),\n\t\t\tasync (result) => {\n\t\t\t\tif (result.status === \"unavailable\") throw result.reason;\n\t\t\t\tif (result.status === \"disabled\") return;\n\t\t\t\tawait sessionManager.appendWorktreeSnapshot(\n\t\t\t\t\troot,\n\t\t\t\t\tresult.snapshot.id,\n\t\t\t\t\tresult.status === \"captured\" ? result.snapshot : undefined,\n\t\t\t\t);\n\t\t\t\trecorded = true;\n\t\t\t},\n\t\t);\n\t\tif (recorded) released.push(root);\n\t}\n\treturn released;\n}\n\n/**\n * The checkouts whose partial restore has been pinned for longer than {@link DEGRADED_RESTORE_RETENTION_DAYS} and\n * that the session has not recorded since (#4922), where they are now: their pinned snapshot is no longer the restore\n * target, and collection no longer keeps it.\n */\nexport function lapsedDegradedRestores(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n): Promise<{ readonly root: string; readonly pin: DegradedRestorePin; readonly latest: string }[]> {\n\treturn runCanonicalStepsAsync(lapsedRestores(sessionManager));\n}\n\nfunction* lapsedRestores(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n): CanonicalSteps<{ readonly root: string; readonly pin: DegradedRestorePin; readonly latest: string }[]> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst lapsed: { readonly root: string; readonly pin: DegradedRestorePin; readonly latest: string }[] = [];\n\tfor (const [original, checkout] of yield* checkoutRecords(sessionManager, mappings)) {\n\t\tif (checkout.pin?.lapsed && checkout.pin.work === undefined && checkout.pin.snapshotId !== checkout.latest)\n\t\t\tlapsed.push({ root: yield* restoredPath(original, mappings), pin: checkout.pin, latest: checkout.latest });\n\t}\n\treturn lapsed;\n}\n\n/** The checkouts on the active branch whose latest snapshot the session holds no record of, where they are now (#4733). */\nexport function missingSnapshotRecords(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\">,\n): Promise<MissingSnapshotRecord[]> {\n\treturn runCanonicalStepsAsync(missingRecordsOf(sessionManager));\n}\n\nfunction* missingRecordsOf(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\">,\n): CanonicalSteps<MissingSnapshotRecord[]> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst missing: MissingSnapshotRecord[] = [];\n\tfor (const [original, snapshotId] of yield* latestSnapshotIdsByCheckout(sessionManager, mappings)) {\n\t\tif (!records.has(snapshotId)) missing.push({ root: yield* restoredPath(original, mappings), snapshotId });\n\t}\n\treturn missing;\n}\n\n/**\n * The latest snapshot of each checkout on the active branch, keyed by where that checkout is now: a checkout restored\n * elsewhere appears once, under its newest location. A snapshot whose record is missing is left out.\n */\nexport function currentWorktreeSnapshots(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\">,\n): Promise<Map<string, WorktreeSnapshot>> {\n\treturn runCanonicalStepsAsync(currentSnapshots(sessionManager));\n}\n\nfunction* currentSnapshots(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\">,\n): CanonicalSteps<Map<string, WorktreeSnapshot>> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst current = new Map<string, WorktreeSnapshot>();\n\tfor (const [original, snapshotId] of yield* latestSnapshotIdsByCheckout(sessionManager, mappings)) {\n\t\tconst snapshot = records.get(snapshotId);\n\t\tif (snapshot) current.set(yield* restoredPath(original, mappings), snapshot);\n\t}\n\treturn current;\n}\n\n/** A checkout a resume continued without, because nothing of its snapshot could be restored here (#4733). */\nexport interface UnrestoredWorktree {\n\treadonly root: string;\n\treadonly snapshot: WorktreeSnapshot;\n\t/** Why: the restore error, or Git being unavailable. */\n\treadonly reason: Error;\n\t/** The record the resume wrote for it in the session. */\n\treadonly record: WorktreeUnrestored;\n}\n\n/** A checkout whose latest snapshot the session refers to without holding its record (#4733). */\nexport interface MissingSnapshotRecord {\n\treadonly root: string;\n\treadonly snapshotId: string;\n}\n\nexport type SessionWorktreeResume =\n\t| { readonly status: \"none\"; readonly missingRecords?: readonly MissingSnapshotRecord[] }\n\t| {\n\t\t\treadonly status: \"verified\";\n\t\t\treadonly snapshot: WorktreeSnapshot;\n\t\t\treadonly cwd: string;\n\t\t\treadonly unrestored: readonly UnrestoredWorktree[];\n\t\t\treadonly missingRecords?: readonly MissingSnapshotRecord[];\n\t }\n\t| {\n\t\t\treadonly status: \"restored\";\n\t\t\treadonly snapshot: WorktreeSnapshot;\n\t\t\treadonly mappings: readonly WorktreeRootMapping[];\n\t\t\treadonly cwd: string;\n\t\t\treadonly warnings: readonly WorktreeRestoreWarning[];\n\t\t\treadonly unrestored: readonly UnrestoredWorktree[];\n\t\t\treadonly missingRecords?: readonly MissingSnapshotRecord[];\n\t };\n\nexport interface ResumeSessionWorktreeOptions {\n\treadonly settings: WorktreeSnapshotSettings;\n\t/** Host directory for shared object stores and restored worktrees. Default ~/.atomic/agent/worktree-snapshots. */\n\treadonly storeDir?: string;\n\treadonly signal?: AbortSignal;\n\t/**\n\t * Called with the new mappings, none when nothing needed restoring, once every checkout is restored and before any\n\t * of them is recorded. When it throws, nothing is recorded and the restored worktrees are removed, as for a failed\n\t * restore.\n\t */\n\treadonly beforeRecord?: (mappings: readonly WorktreeRootMapping[]) => Promise<void>;\n\t/**\n\t * Where the exact fresh restore of a checkout hands its Git LFS download instead of running it (#5099); see\n\t * `RestoreWorktreeSnapshotOptions.deferLfs`. Its `lfs-objects-unavailable` warning is then not recorded with the\n\t * restore. A claimed or degraded restore, and one that carries over work, still downloads before it returns.\n\t */\n\treadonly deferLfs?: RestoreWorktreeSnapshotOptions[\"deferLfs\"];\n\t/**\n\t * Mappings to checkouts already here that the session continues in, applied as if recorded while deciding what to\n\t * restore, and recorded first, with the restores, only once every checkout is restored and `beforeRecord` passed.\n\t */\n\treadonly pendingMappings?: readonly WorktreeRootMapping[];\n\t/** Checkouts, by the root the session's restores put them at, to continue in as they are without verifying them. */\n\treadonly keepInPlace?: ReadonlySet<string>;\n\t/**\n\t * Checkouts, by the same roots, that cannot be restored on this host, with the reason, such as Git being\n\t * unavailable: the resume continues without them, as for a restore that gives nothing (#4733).\n\t */\n\treadonly cannotRestore?: ReadonlyMap<string, Error>;\n\t/**\n\t * Where the session continues when the checkout it works in is not restored and its working directory is not on\n\t * this host: the directory the resume started from. Default: the recorded working directory.\n\t */\n\treadonly fallbackCwd?: string;\n\t/**\n\t * Continue without a checkout whose latest snapshot the session holds no record of, listing it in `missingRecords`,\n\t * instead of failing with `snapshot-not-found` before anything is restored (#4733).\n\t */\n\treadonly skipMissingRecords?: boolean;\n\t/**\n\t * Restore into pooled slots at stable paths, leased by this session until it closes (#4748), keeping at most\n\t * `maxIdlePerRepository` idle slots of each repository restored into. A restore first claims an idle slot of the\n\t * repository that holds only its recorded state, reset to the snapshot with its ignored files kept, and restores\n\t * into a new slot when none can be claimed. A recorded checkout in a slot another session owns is restored the same\n\t * way. The session holds the pooled worktrees it owns, compared or restored, until it closes. Without it, restores go\n\t * to new paths outside the pool, as for workflow runs.\n\t */\n\treadonly pool?: { readonly maxIdlePerRepository: number };\n}\n\n/**\n * The commits of every earlier snapshot of the checkout on the branch, newest first and each once, to restore when its\n * own is out of reach (#4744). The restore stops at the first it holds or fetches, so a nearer one costs no more.\n */\nfunction* earlierSnapshotHeads(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeSnapshotRecords\">,\n\toriginal: string,\n\tmappings: readonly WorktreeRootMapping[],\n\tsnapshot: WorktreeSnapshot,\n): CanonicalSteps<string[]> {\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst heads: string[] = [];\n\tfor (const entry of [...sessionManager.getBranch()].reverse()) {\n\t\tif (entry.type !== \"worktree_snapshot\" || (yield* originalRoot(entry.root, mappings)) !== original) continue;\n\t\tconst head = records.get(entry.snapshotId)?.head;\n\t\tif (head !== undefined && head !== snapshot.head) heads.push(head);\n\t}\n\treturn [...new Set(heads)];\n}\n\n/**\n * Checks the latest recorded snapshot of each checkout on the active session branch. Drifted or missing checkouts are\n * restored into fresh worktrees, and each old→new mapping is recorded only after all checkouts have been restored.\n * The returned cwd follows those mappings. A HEAD-only advance over identical content also resumes in place.\n */\nexport async function resumeSessionWorktree(\n\tsessionManager: SessionManager,\n\toptions: ResumeSessionWorktreeOptions,\n): Promise<SessionWorktreeResume> {\n\tif (!options.settings.enabled) return { status: \"none\" };\n\tconst storeDir = resolve(options.storeDir ?? defaultWorktreeSnapshotStoreDir());\n\t// The session holds the pooled slots it owns before comparing them, so no claim resets one it continues in (#4748).\n\tif (options.pool) await holdSessionWorktrees(sessionManager, sessionManager, storeDir, options.signal);\n\tconst pending = options.pendingMappings ?? [];\n\tconst existing = [...sessionManager.getWorktreeRootMappings(), ...pending];\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst checkouts = await runCanonicalStepsAsync(checkoutRecords(sessionManager, existing));\n\tconst latestIds = await runCanonicalStepsAsync(latestSnapshotIdsByCheckout(sessionManager, existing));\n\tconst latest = new Map<string, WorktreeSnapshot>();\n\t// The work done in a partly restored worktree of the pinned snapshot `snapshot`, which this resume restores when\n\t// `snapshot` cannot be, and puts on top of it when it can (#4922).\n\tconst pinnedWork = (original: string, snapshot: WorktreeSnapshot) => {\n\t\tconst checkout = checkouts.get(original)!;\n\t\tconst pin = checkout.pin;\n\t\tif (pin === undefined || pin.lapsed || pin.snapshotId !== snapshot.id) return undefined;\n\t\t// After a full restore whose merged worktree is not recorded yet, the work it carried over (#5009).\n\t\tconst workId = pin.work ?? checkout.latest;\n\t\tif (workId === snapshot.id) return undefined;\n\t\tconst work = records.get(workId);\n\t\treturn work === undefined ? undefined : { pin, work };\n\t};\n\tconst missingRecords: MissingSnapshotRecord[] = [];\n\tfor (const [root, snapshotId] of latestIds) {\n\t\tconst snapshot = records.get(snapshotId);\n\t\tif (!snapshot && options.skipMissingRecords) {\n\t\t\tmissingRecords.push({ root: await mapRestoredPathAsync(root, existing), snapshotId });\n\t\t\tcontinue;\n\t\t}\n\t\tif (!snapshot) throw new WorkspaceRestoreError(\"snapshot-not-found\", { snapshotId, target: root });\n\t\tlatest.set(root, snapshot);\n\t}\n\tif (latest.size === 0) return missingRecords.length === 0 ? { status: \"none\" } : { status: \"none\", missingRecords };\n\tconst cwd = await mapRestoredPathAsync(sessionManager.getCwd(), existing);\n\tconst mappings: WorktreeRootMapping[] = [];\n\tconst warnings: WorktreeRestoreWarning[] = [];\n\tconst hostWarnings = new Map<WorktreeRootMapping, WorktreeRestoreHostWarning[]>();\n\tconst reportedLeftovers = new Set<string>();\n\tconst left: { root: string; snapshot: WorktreeSnapshot; reason: Error; degradedFrom?: string }[] = [];\n\tconst pinnedTo = new Map<WorktreeRootMapping, string | undefined>();\n\tconst unrestored: UnrestoredWorktree[] = [];\n\tlet continuedIn: string;\n\tlet selected: { root: string; snapshot: WorktreeSnapshot } | undefined;\n\tconst owner = sessionOwner(sessionManager);\n\tconst leases = new Map<WorktreeRootMapping, WorktreeLease>();\n\tconst admitted = new Set<RepositoryId>();\n\ttry {\n\t\tfor (const [original, snapshot] of latest) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tconst root = await mapRestoredPathAsync(original, existing);\n\t\t\tif ((await runCanonicalStepsAsync(isInside(root, cwd))) && (!selected || root.length > selected.root.length))\n\t\t\t\tselected = { root, snapshot };\n\t\t\tif (options.keepInPlace?.has(root)) continue;\n\t\t\tconst pinned = pinnedWork(original, snapshot);\n\t\t\t// Conflicting work a full restore kept apart stays kept, whatever the checkout is restored from (#5009).\n\t\t\tconst pin = checkouts.get(original)!.pin;\n\t\t\tconst keptWork = pin?.kept && !pin.lapsed && pin.work !== snapshot.id ? pin.work : undefined;\n\t\t\t// A pinned checkout left unrestored keeps its pin and the work done in its partly restored worktree (#4922).\n\t\t\tconst leave = (reason: Error) =>\n\t\t\t\tleft.push(\n\t\t\t\t\tpinned === undefined\n\t\t\t\t\t\t? { root, snapshot, reason, ...(keptWork === undefined ? {} : { degradedFrom: keptWork }) }\n\t\t\t\t\t\t: { root, snapshot: pinned.work, reason, degradedFrom: snapshot.id },\n\t\t\t\t);\n\t\t\tconst cannot = options.cannotRestore?.get(root);\n\t\t\tif (cannot !== undefined) {\n\t\t\t\tleave(cannot);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst gone = (cause?: Error) =>\n\t\t\t\tnew WorkspaceDriftError(\n\t\t\t\t\t{\n\t\t\t\t\t\troot,\n\t\t\t\t\t\texpectedHead: snapshot.head,\n\t\t\t\t\t\tactualHead: null,\n\t\t\t\t\t\texpectedTree: snapshot.tree,\n\t\t\t\t\t\tactualTree: null,\n\t\t\t\t\t\tsnapshotId: snapshot.id,\n\t\t\t\t\t},\n\t\t\t\t\tcause,\n\t\t\t\t);\n\t\t\tlet drift: WorkspaceDriftError;\n\t\t\t// A slot another session owns holds its work, not this one's: restore fresh, as if it were gone (#4748).\n\t\t\tif (options.pool && (await pooledWorktreeOwnedElsewhere(storeDir, root, owner.id))) drift = gone();\n\t\t\telse {\n\t\t\t\ttry {\n\t\t\t\t\tawait verifyWorktree(snapshot, root, { settings: options.settings, signal: options.signal });\n\t\t\t\t\tcontinue;\n\t\t\t\t} catch (error) {\n\t\t\t\t\toptions.signal?.throwIfAborted();\n\t\t\t\t\tif (isWorkspaceDriftError(error)) {\n\t\t\t\t\t\tif (await isHeadOnlyAdvance(error, options.signal)) continue;\n\t\t\t\t\t\tdrift = error;\n\t\t\t\t\t} else if (isWorkspaceSnapshotError(error)) drift = gone(error);\n\t\t\t\t\telse throw error;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst refused = (error: Error) =>\n\t\t\t\tnew WorkspaceDriftError(\n\t\t\t\t\t{\n\t\t\t\t\t\troot: drift.root,\n\t\t\t\t\t\texpectedHead: drift.expectedHead,\n\t\t\t\t\t\tactualHead: drift.actualHead,\n\t\t\t\t\t\texpectedTree: drift.expectedTree,\n\t\t\t\t\t\tactualTree: drift.actualTree,\n\t\t\t\t\t\tsnapshotId: drift.snapshotId,\n\t\t\t\t\t\treason: \"restore-failed\",\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\tconst blobs = sessionSnapshotBlobs(\n\t\t\t\tsessionManager.getSessionStore().snapshotBlobs,\n\t\t\t\tsessionManager.getEntries(),\n\t\t\t);\n\t\t\tlet restored: Extract<BestWorktreeRestore, { status: \"restored\" }>;\n\t\t\tlet lease: WorktreeLease | undefined;\n\t\t\tlet claimed = false;\n\t\t\tlet seeded = false;\n\t\t\t// The snapshot the worktree holds: the one restored, or the work done since its partial restore (#4922).\n\t\t\tlet restoredFrom = snapshot;\n\t\t\t// The exact state, else the best this host can restore, else continue without the checkout.\n\t\t\tconst restoreFresh = async (slot: WorktreeLease | undefined) => {\n\t\t\t\tconst ladder: RestoreBestWorktreeOptions = {\n\t\t\t\t\tblobs,\n\t\t\t\t\tstoreDir: options.storeDir,\n\t\t\t\t\tsignal: options.signal,\n\t\t\t\t\tcandidates: await runCanonicalStepsAsync(\n\t\t\t\t\t\tearlierSnapshotHeads(sessionManager, original, existing, snapshot),\n\t\t\t\t\t),\n\t\t\t\t\t// Carrying work over writes into the worktree, so a pinned restore downloads first.\n\t\t\t\t\t...(pinned === undefined ? { deferLfs: options.deferLfs } : {}),\n\t\t\t\t\t...(slot === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\trestore: (target, restoreOptions) => restoreWorktreeAt(target, slot.path, restoreOptions),\n\t\t\t\t\t\t\t\trestoreDegraded: (degraded, failure, restoreOptions) =>\n\t\t\t\t\t\t\t\t\trestoreDegradedWorktreeAt(degraded, failure, slot.path, restoreOptions),\n\t\t\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t\tif (pinned === undefined) return restoreBestWorktree(snapshot, ladder);\n\t\t\t\treturn restorePinnedWorktree(snapshot, pinned.work, ladder, (work) => {\n\t\t\t\t\trestoredFrom = work;\n\t\t\t\t});\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tconst best = await timeCheckoutRestore(\n\t\t\t\t\troot,\n\t\t\t\t\tasync (): Promise<BestWorktreeRestore> => {\n\t\t\t\t\t\tif (!options.pool) return restoreFresh(undefined);\n\t\t\t\t\t\t// An idle slot of the repository keeps its dependencies and build output; else a new slot (#4748).\n\t\t\t\t\t\tconst claimOptions = { storeDir, owner, settings: options.settings, blobs, signal: options.signal };\n\t\t\t\t\t\tlet claim = await claimIdleWorktree(snapshot, claimOptions);\n\t\t\t\t\t\t// Without one, prebuilt build output parked as a seed becomes an idle slot to claim (#4748).\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!claim.claimed &&\n\t\t\t\t\t\t\t(await adoptPrebuiltSeed(snapshot, { storeDir, signal: options.signal })).adopted\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tclaim = await claimIdleWorktree(snapshot, claimOptions);\n\t\t\t\t\t\t\tseeded = claim.claimed;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (claim.claimed) {\n\t\t\t\t\t\t\tlease = claim.lease;\n\t\t\t\t\t\t\tclaimed = true;\n\t\t\t\t\t\t\treturn { status: \"restored\", path: claim.lease.path, warnings: claim.warnings };\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlease = await admitSlot(storeDir, snapshot, owner, options.signal);\n\t\t\t\t\t\treturn restoreFresh(lease);\n\t\t\t\t\t},\n\t\t\t\t\t(outcome) =>\n\t\t\t\t\t\toutcome.status === \"unrestored\"\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: seeded\n\t\t\t\t\t\t\t\t? \"seeded\"\n\t\t\t\t\t\t\t\t: claimed\n\t\t\t\t\t\t\t\t\t? \"claimed\"\n\t\t\t\t\t\t\t\t\t: outcome.degraded === undefined\n\t\t\t\t\t\t\t\t\t\t? \"fresh\"\n\t\t\t\t\t\t\t\t\t\t: \"degraded\",\n\t\t\t\t);\n\t\t\t\tif (best.status === \"unrestored\") {\n\t\t\t\t\tif (lease) await discardPooledWorktree(lease);\n\t\t\t\t\tleave(best.reason);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\trestored = best;\n\t\t\t} catch (error) {\n\t\t\t\tif (lease) await discardPooledWorktree(lease).catch(() => {});\n\t\t\t\toptions.signal?.throwIfAborted();\n\t\t\t\tif (!(error instanceof Error)) throw error;\n\t\t\t\tthrow refused(error);\n\t\t\t}\n\t\t\t// A full restore of a pinned snapshot carries the work done in its partly restored worktree over (#4922).\n\t\t\tconst degradedWork =\n\t\t\t\tpinned !== undefined &&\n\t\t\t\trestoredFrom === snapshot &&\n\t\t\t\trestored.degraded === undefined &&\n\t\t\t\tpinned.work.tree !== pinned.pin.base?.tree\n\t\t\t\t\t? await carryOverDegradedWork({\n\t\t\t\t\t\t\tworktree: restored.path,\n\t\t\t\t\t\t\twork: pinned.work,\n\t\t\t\t\t\t\tbase: pinned.pin.base?.tree,\n\t\t\t\t\t\t\tblobs,\n\t\t\t\t\t\t\tstoreDir,\n\t\t\t\t\t\t\tsignal: options.signal,\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined;\n\t\t\tconst mapping: WorktreeRootMapping = {\n\t\t\t\tfrom: root,\n\t\t\t\tto: restored.path,\n\t\t\t\tsnapshotId: restoredFrom.id,\n\t\t\t\ttree: restoredFrom.tree,\n\t\t\t\trestoredAt: new Date().toISOString(),\n\t\t\t\t...(restored.degraded === undefined ? {} : { degraded: restored.degraded }),\n\t\t\t\t...(degradedWork === undefined ? {} : { degradedWork }),\n\t\t\t};\n\t\t\tmappings.push(mapping);\n\t\t\tpinnedTo.set(mapping, restoredFrom !== snapshot ? snapshot.id : keptWork);\n\t\t\tif (lease) {\n\t\t\t\tleases.set(mapping, lease);\n\t\t\t\tadmitted.add(lease.repository);\n\t\t\t\tif (restored.degraded !== undefined || restoredFrom !== snapshot) {\n\t\t\t\t\tawait recordPooledWorktreeState(lease, {\n\t\t\t\t\t\tsnapshotId: restoredFrom.id,\n\t\t\t\t\t\thead: restored.degraded?.head ?? restoredFrom.head,\n\t\t\t\t\t\ttree: restored.degraded?.tree ?? restoredFrom.tree,\n\t\t\t\t\t}).catch((error: unknown) =>\n\t\t\t\t\t\treportDebug(\"storage\", \"worktree-pool-state-failed\", failureDebugFields(error)),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\twarnings.push(...restored.warnings);\n\t\t\thostWarnings.set(\n\t\t\t\tmapping,\n\t\t\t\trestored.warnings.filter((warning): warning is WorktreeRestoreHostWarning => {\n\t\t\t\t\tif (warning.code === \"lfs-objects-unavailable\") return true;\n\t\t\t\t\tif (warning.code !== \"stale-restore-retained\" || reportedLeftovers.has(warning.path)) return false;\n\t\t\t\t\treportedLeftovers.add(warning.path);\n\t\t\t\t\treturn true;\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tawait options.beforeRecord?.(mappings);\n\t\tfor (const mapping of [...pending, ...mappings]) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tawait sessionManager.appendWorktreeSnapshot(\n\t\t\t\tmapping.to,\n\t\t\t\tmapping.snapshotId,\n\t\t\t\tundefined,\n\t\t\t\tmapping,\n\t\t\t\thostWarnings.get(mapping),\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t// Work carried over stays kept until the merged worktree is recorded, or released when it conflicted (#5009).\n\t\t\t\tpinnedTo.get(mapping) ??\n\t\t\t\t\t(mapping.degradedWork === undefined || mapping.degradedWork.outcome === \"unavailable\"\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: mapping.degradedWork.snapshotId),\n\t\t\t);\n\t\t\tif (mapping.degradedWork?.outcome === \"applied\") {\n\t\t\t\tawait recordCarriedWork(sessionManager, mapping.to, records.get(mapping.snapshotId)!.head, options);\n\t\t\t}\n\t\t}\n\t\tconst continuing = await mapRestoredPathAsync(cwd, mappings);\n\t\tconst recordedHere = selected !== undefined && left.some((checkout) => checkout.root === selected!.root);\n\t\tconst launch =\n\t\t\trecordedHere &&\n\t\t\toptions.fallbackCwd !== undefined &&\n\t\t\t(!(await access(continuing).then(\n\t\t\t\t() => true,\n\t\t\t\t() => false,\n\t\t\t)) ||\n\t\t\t\t(await pooledWorktreeOwnedElsewhere(storeDir, selected!.root, owner.id)));\n\t\tcontinuedIn = launch ? resolve(options.fallbackCwd!) : continuing;\n\t\tfor (const checkout of left) {\n\t\t\tconst record = unrestoredRecord(\n\t\t\t\tcheckout.snapshot,\n\t\t\t\tcheckout.reason,\n\t\t\t\tcontinuedIn,\n\t\t\t\tlaunch ? \"launch\" : \"recorded\",\n\t\t\t\tundefined,\n\t\t\t\tlaunch && checkout.root === selected?.root ? continuing : undefined,\n\t\t\t);\n\t\t\tawait sessionManager.appendWorktreeSnapshot(\n\t\t\t\tcheckout.root,\n\t\t\t\tcheckout.snapshot.id,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\trecord,\n\t\t\t\tundefined,\n\t\t\t\tcheckout.degradedFrom,\n\t\t\t);\n\t\t\tunrestored.push({ ...checkout, record });\n\t\t}\n\t} catch (error) {\n\t\tconst cleanupFailures: unknown[] = [];\n\t\tfor (const mapping of [...mappings].reverse()) {\n\t\t\ttry {\n\t\t\t\tawait removeRestoredWorktree(mapping.to, { storeDir: options.storeDir });\n\t\t\t} catch (cleanupCause) {\n\t\t\t\tcleanupFailures.push(cleanupCause);\n\t\t\t}\n\t\t\tconst lease = leases.get(mapping);\n\t\t\tif (lease) await discardPooledWorktree(lease).catch(() => {});\n\t\t}\n\t\tif (cleanupFailures.length > 0 && error instanceof Error && Object.isExtensible(error)) {\n\t\t\tObject.defineProperty(error, \"cleanupCause\", {\n\t\t\t\tvalue: cleanupFailures.length === 1 ? cleanupFailures[0] : new AggregateError(cleanupFailures),\n\t\t\t\tconfigurable: true,\n\t\t\t});\n\t\t}\n\t\tthrow error;\n\t}\n\tfor (const lease of leases.values()) holdFor(sessionManager, lease);\n\tif (options.pool) {\n\t\tfor (const repository of admitted) {\n\t\t\tawait evictIdleWorktrees(storeDir, repository, {\n\t\t\t\tmaxIdle: options.pool.maxIdlePerRepository,\n\t\t\t\tsettings: options.settings,\n\t\t\t\tsignal: options.signal,\n\t\t\t});\n\t\t}\n\t}\n\tconst snapshot = selected?.snapshot ?? [...latest.values()].at(-1)!;\n\tconst missing = missingRecords.length === 0 ? {} : { missingRecords };\n\treturn mappings.length === 0\n\t\t? { status: \"verified\", snapshot, cwd: continuedIn, unrestored, ...missing }\n\t\t: { status: \"restored\", snapshot, mappings, cwd: continuedIn, warnings, unrestored, ...missing };\n}\n\n/**\n * Restores a pinned `snapshot` (#4922): exactly, else `work`, the latest snapshot of its partly restored worktree, as\n * well as this host can, calling `restoredWork` when it does; else nothing, resolving `unrestored` with the exact\n * restore's failure. `work` shares `snapshot`'s remotes, so a commit a degraded restore of `snapshot` could fall back to\n * is one a degraded restore of `work` falls back to as well.\n */\nasync function restorePinnedWorktree(\n\tsnapshot: WorktreeSnapshot,\n\twork: WorktreeSnapshot,\n\toptions: RestoreBestWorktreeOptions,\n\trestoredWork: (work: WorktreeSnapshot) => void,\n): Promise<BestWorktreeRestore> {\n\tconst { restore = restoreWorktree, restoreDegraded: _degraded, candidates: _candidates, ...shared } = options;\n\ttry {\n\t\tconst exact = await restore(snapshot, shared);\n\t\treturn { status: \"restored\", path: exact.path, warnings: exact.warnings ?? [] };\n\t} catch (error) {\n\t\tif (options.signal?.aborted || !isRecoverableRestoreFailure(error)) throw error;\n\t\tconst best = await restoreBestWorktree(work, options);\n\t\tif (best.status === \"unrestored\") return { status: \"unrestored\", reason: error };\n\t\trestoredWork(work);\n\t\treturn best;\n\t}\n}\n\n/**\n * Records the restored worktree at `root` as it is once a restore carried the work of a partly restored worktree over\n * (#4922), so the session holds that work without waiting for a turn, which ends the pin. A worktree whose HEAD is no\n * longer `head` is left alone. A capture that fails keeps the pin, and with it the carried work, for the next turn's\n * capture or resume to record (#5009); the reason goes to the debug log.\n */\nasync function recordCarriedWork(\n\tsessionManager: SessionManager,\n\troot: string,\n\thead: string | undefined,\n\toptions: Pick<ResumeSessionWorktreeOptions, \"settings\" | \"signal\">,\n): Promise<void> {\n\tconst blobs = sessionManager.getSessionStore().snapshotBlobs;\n\tif (blobs === undefined) return;\n\ttry {\n\t\tawait recordWorktreeCapture(\n\t\t\tblobs,\n\t\t\t() => captureWorktreeSnapshot(root, { settings: options.settings, blobs, signal: options.signal }),\n\t\t\tasync (result) => {\n\t\t\t\t// Without a previous snapshot to compare with, a capture never resolves unchanged.\n\t\t\t\tif (result.status === \"captured\" && result.snapshot.head === head) {\n\t\t\t\t\tawait sessionManager.appendWorktreeSnapshot(root, result.snapshot.id, result.snapshot);\n\t\t\t\t} else if (result.status === \"unavailable\") {\n\t\t\t\t\treportDebug(\"storage\", \"degraded-work-capture-failed\", failureDebugFields(result.reason));\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t} catch (error) {\n\t\toptions.signal?.throwIfAborted();\n\t\tif (!isWorkspaceError(error) && !isGitUnavailableError(error)) throw error;\n\t\treportDebug(\"storage\", \"degraded-work-capture-failed\", failureDebugFields(error));\n\t}\n}\n\n/**\n * Takes a new pooled slot for a restore of `snapshot` (#4748). When the pool cannot be used, the restore goes to a new\n * path outside it, as before the pool: undefined, with the reason in the debug log.\n */\nasync function admitSlot(\n\tstoreDir: string,\n\tsnapshot: WorktreeSnapshot,\n\towner: PoolOwner,\n\tsignal?: AbortSignal,\n): Promise<WorktreeLease | undefined> {\n\ttry {\n\t\treturn await admitPooledWorktree(\n\t\t\t{\n\t\t\t\tstoreDir,\n\t\t\t\tremotes: snapshot.remotes,\n\t\t\t\troot: snapshot.root,\n\t\t\t\tlastState: { snapshotId: snapshot.id, head: snapshot.head, tree: snapshot.tree },\n\t\t\t\tenvHash: snapshot.envHash,\n\t\t\t\tsignal,\n\t\t\t},\n\t\t\towner,\n\t\t);\n\t} catch (error) {\n\t\tsignal?.throwIfAborted();\n\t\treportDebug(\"storage\", \"worktree-pool-admit-failed\", failureDebugFields(error));\n\t\treturn undefined;\n\t}\n}\n\n/** The one-line notice shown when a session or run continues in a restored worktree. */\nexport function formatWorktreeRestoreNotice(mapping: WorktreeRootMapping): string {\n\treturn `Restored worktree snapshot ${mapping.snapshotId.slice(0, 12)} of ${mapping.from} into ${mapping.to}`;\n}\n\n/** One line per restore warning, for the notices shown after a restore. */\nexport function formatWorktreeRestoreWarning(warning: WorktreeRestoreWarning): string {\n\tswitch (warning.code) {\n\t\tcase \"omitted-content\":\n\t\t\treturn `The restored snapshot left out ${warning.omitted.length} item(s): ${warning.omitted\n\t\t\t\t.map((omission) => (\"path\" in omission ? `${omission.path} (${omission.reason})` : omission.reason))\n\t\t\t\t.join(\", \")}`;\n\t\tcase \"filters\":\n\t\t\treturn `The source checkout used conversion settings (${[\n\t\t\t\twarning.filters.autocrlf === null ? undefined : `core.autocrlf=${warning.filters.autocrlf}`,\n\t\t\t\twarning.filters.eol === null ? undefined : `core.eol=${warning.filters.eol}`,\n\t\t\t\t...warning.filters.drivers.map((driver) => `filter=${driver}`),\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(\", \")}); the restore holds Git's stored content with LF line endings`;\n\t\tcase \"lfs-objects-unavailable\":\n\t\t\treturn `Git LFS objects could not be fetched; these files hold LFS pointers: ${warning.paths.join(\", \")}`;\n\t\tcase \"stale-restore-retained\":\n\t\t\tswitch (warning.kind) {\n\t\t\t\tcase \"worktree\":\n\t\t\t\t\treturn `A restore interrupted earlier left ${warning.path}, which may hold your files; check them, then delete the directory yourself`;\n\t\t\t\tcase \"record\":\n\t\t\t\t\treturn `A restore interrupted earlier left the crash record ${warning.path}, which cannot be read; delete the file`;\n\t\t\t\tcase \"records-directory\":\n\t\t\t\t\treturn `The restore crash records in ${warning.path} cannot be read; make the directory readable or remove it`;\n\t\t\t}\n\t}\n}\n\n/** The first 12 characters of a commit or snapshot id, as notices show them. */\nfunction short(id: string): string {\n\treturn id.slice(0, 12);\n}\n\n/** Whose checkout a restore notice is about: a session's, or a workflow run's (#4738). */\nexport type WorktreeRestoreOwner = \"session\" | \"workflow run\";\n\n/** What a degraded restore checked out, for its notice. */\nfunction degradedBasis(\n\tdegraded: WorktreeDegradedRestore,\n\tsnapshot: WorktreeSnapshot | undefined,\n\towner: WorktreeRestoreOwner,\n): string {\n\tswitch (degraded.basis) {\n\t\tcase \"pushed-base\":\n\t\t\treturn `the last pushed commit before it, ${short(degraded.head)}`;\n\t\tcase \"earlier-snapshot\":\n\t\t\treturn `${short(degraded.head)}, the commit of an earlier snapshot of this ${owner}`;\n\t\tdefault:\n\t\t\treturn `${short(degraded.head)}, the tip of ${snapshot?.branch ? `branch ${snapshot.branch}` : \"the default branch\"} on its remote`;\n\t}\n}\n\nfunction listed(items: readonly string[], limit = 5): string {\n\treturn items.length <= limit\n\t\t? items.join(\", \")\n\t\t: `${items.slice(0, limit).join(\", \")} and ${items.length - limit} more`;\n}\n\n/**\n * The one notice for a worktree restored with less than its snapshot (#4733): what it holds, what is missing and what\n * to do to get the rest.\n */\nexport function formatDegradedRestoreNotice(\n\tmapping: WorktreeRootMapping,\n\tsnapshot: WorktreeSnapshot | undefined,\n\twarnings: readonly WorktreeRestoreHostWarning[] = [],\n\towner: WorktreeRestoreOwner = \"session\",\n): string {\n\tconst lfs = warnings\n\t\t.filter((warning) => warning.code === \"lfs-objects-unavailable\")\n\t\t.map((warning) => ` ${formatWorktreeRestoreWarning(warning)}.`)\n\t\t.join(\"\");\n\treturn `${degradedRestoreSummary(mapping, snapshot, owner)}${lfs}`;\n}\n\nfunction degradedRestoreSummary(\n\tmapping: WorktreeRootMapping,\n\tsnapshot: WorktreeSnapshot | undefined,\n\towner: WorktreeRestoreOwner,\n): string {\n\tconst degraded = mapping.degraded!;\n\tconst links = snapshot?.chain.length ?? 0;\n\tconst restored = `Restored ${mapping.from} into ${mapping.to}`;\n\tconst missingPaths = degraded.missingPaths.length > 0 ? `: ${listed(degraded.missingPaths)}` : \"\";\n\tif (degraded.stage === \"partial-changes\") {\n\t\tconst missing =\n\t\t\tdegraded.missingLinks.length > 0\n\t\t\t\t? `change set${degraded.missingLinks.length === 1 ? \"\" : \"s\"} ${degraded.missingLinks.join(\", \")}${missingPaths}`\n\t\t\t\t: `the recorded content of ${listed(degraded.missingPaths)}, which differs on this machine`;\n\t\treturn `${restored} at its recorded commit ${short(degraded.head)} with ${links - degraded.missingLinks.length} of the ${links} change sets of snapshot ${short(mapping.snapshotId)}. Not restored: ${missing}. ${degraded.hint}`;\n\t}\n\tconst commits = degraded.missingCommits.length;\n\tconst recorded = snapshot === undefined ? \"\" : ` instead of the recorded commit ${short(snapshot.head)}`;\n\tconst changes = degraded.missingLinks.length > 0 ? \" and the snapshot's uncommitted changes\" : \"\";\n\treturn `${restored} at ${degradedBasis(degraded, snapshot, owner)}${recorded}, the closest commit available here. Not restored: ${commits} commit${commits === 1 ? \"\" : \"s\"} (${listed(degraded.missingCommits.map(short), 3)})${changes} of snapshot ${short(mapping.snapshotId)}. ${degraded.hint}`;\n}\n\n/** The notice for a checkout whose snapshot the session holds no record of, which a resume continued without. */\nexport function formatMissingRecordNotice(missing: MissingSnapshotRecord): string {\n\treturn `Continuing without restoring ${missing.root}: the session holds no record of its snapshot ${short(missing.snapshotId)}. Resume on the machine that recorded it, or import (\\`atomic --import <file>\\`) a session saved there with \\`/export <file>.jsonl\\`, which carries its snapshots.`;\n}\n\n/** The one notice for a checkout a resume continued without (#4733). */\nexport function formatUnrestoredNotice(\n\troot: string,\n\tunrestored: WorktreeUnrestored,\n\towner: WorktreeRestoreOwner = \"session\",\n): string {\n\tconst place =\n\t\tunrestored.place === \"launch\"\n\t\t\t? \"the directory the resume started from\"\n\t\t\t: owner === \"session\"\n\t\t\t\t? \"the session's own directory\"\n\t\t\t\t: \"the run's own directory\";\n\treturn `Continuing in ${unrestored.continuedIn} (${place}) without restoring ${root} from snapshot ${short(unrestored.snapshotId)}: ${unrestored.detail}. ${unrestored.hint}`.trimEnd();\n}\n\n/**\n * One informational line per worktree restored since `since`, each followed by its snapshot's warnings and what the\n * restore itself reported; one notice per worktree restored with less than its snapshot, and per checkout a resume\n * continued without, since `since` (#4733).\n */\nexport function worktreeRestoreNotices(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeSnapshotRecords\">,\n\tsince: string,\n): { readonly type: \"info\" | \"warning\"; readonly message: string }[] {\n\treturn restoreNotices(sessionManager, (entry) =>\n\t\tentry.restore\n\t\t\t? entry.restore.restoredAt >= since\n\t\t\t: entry.unrestored !== undefined && entry.unrestored.at >= since,\n\t);\n}\n\nfunction restoreNotices(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeSnapshotRecords\">,\n\tinclude: (entry: Extract<SessionEntry, { type: \"worktree_snapshot\" }>) => boolean,\n): { readonly type: \"info\" | \"warning\"; readonly message: string }[] {\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst branch = sessionManager.getBranch();\n\t// The snapshots of conflicting work a full restore kept apart, which later entries go on naming, and the last entry\n\t// of each root, after which nothing recorded the worktree (#5009).\n\tconst keptWork = new Set<string>();\n\tconst last = new Map<string, SessionEntry>();\n\tfor (const entry of branch) {\n\t\tif (entry.type !== \"worktree_snapshot\") continue;\n\t\tif (entry.restore?.degradedWork?.outcome === \"kept\") keptWork.add(entry.restore.degradedWork.snapshotId);\n\t\tlast.set(entry.root, entry);\n\t}\n\treturn branch.flatMap((entry) => {\n\t\tif (entry.type !== \"worktree_snapshot\" || !include(entry)) return [];\n\t\tif (entry.unrestored) {\n\t\t\treturn [{ type: \"warning\" as const, message: formatUnrestoredNotice(entry.root, entry.unrestored) }];\n\t\t}\n\t\tif (!entry.restore) return [];\n\t\tconst snapshot = records.get(entry.snapshotId);\n\t\tconst work = entry.restore.degradedWork;\n\t\tconst pinned =\n\t\t\tentry.degradedFrom === undefined || entry.degradedFrom === work?.snapshotId || keptWork.has(entry.degradedFrom)\n\t\t\t\t? []\n\t\t\t\t: [{ type: \"warning\" as const, message: formatPinnedRestoreNotice(entry.restore, entry.degradedFrom) }];\n\t\tif (entry.restore.degraded) {\n\t\t\tconst message = formatDegradedRestoreNotice(entry.restore, snapshot, entry.restoreWarnings);\n\t\t\treturn [{ type: \"warning\" as const, message }, ...pinned];\n\t\t}\n\t\t// Applied work no capture recorded since, whose pin stands until one does (#5009).\n\t\tconst unrecorded = work?.outcome === \"applied\" && last.get(entry.root) === entry ? work : undefined;\n\t\treturn [\n\t\t\t{ type: \"info\" as const, message: formatWorktreeRestoreNotice(entry.restore) },\n\t\t\t...pinned,\n\t\t\t...(work === undefined\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: work.outcome === \"applied\" ? (\"info\" as const) : (\"warning\" as const),\n\t\t\t\t\t\t\tmessage: formatDegradedWorkNotice(entry.restore, work),\n\t\t\t\t\t\t},\n\t\t\t\t\t]),\n\t\t\t...(unrecorded === undefined\n\t\t\t\t? []\n\t\t\t\t: [{ type: \"warning\" as const, message: formatUnrecordedWorkNotice(entry.restore, unrecorded) }]),\n\t\t\t...[...(snapshot ? snapshotRestoreWarnings(snapshot) : []), ...(entry.restoreWarnings ?? [])].map(\n\t\t\t\t(warning) => ({ type: \"warning\" as const, message: formatWorktreeRestoreWarning(warning) }),\n\t\t\t),\n\t\t];\n\t});\n}\n\n/**\n * The notice for a checkout restored from the work done in a partly restored worktree, because the snapshot that\n * worktree lacks still cannot be restored here (#4922).\n */\nexport function formatPinnedRestoreNotice(mapping: WorktreeRootMapping, pinnedSnapshotId: string): string {\n\treturn `${mapping.to} holds snapshot ${short(mapping.snapshotId)}, the work recorded since snapshot ${short(pinnedSnapshotId)} of ${mapping.from} was restored only partly; snapshot ${short(pinnedSnapshotId)} itself still cannot be restored here. It stays this checkout's restore target and is kept for ${DEGRADED_RESTORE_RETENTION_DAYS} days after its partial restore, until a resume restores it fully or discardDegradedRestore releases it.`;\n}\n\n/** The notice for the work of a partly restored worktree that a full restore of its snapshot found (#4922). */\nexport function formatDegradedWorkNotice(mapping: WorktreeRootMapping, work: WorktreeDegradedWork): string {\n\tconst files = work.paths.length === 0 ? \"\" : ` (${listed(work.paths)})`;\n\tconst done = `the work done in the partly restored worktree ${work.root}, snapshot ${short(work.snapshotId)}${files}`;\n\tswitch (work.outcome) {\n\t\tcase \"applied\":\n\t\t\treturn `Also applied ${done}, on top of snapshot ${short(mapping.snapshotId)} in ${mapping.to}.`;\n\t\tcase \"kept\":\n\t\t\treturn `Did not apply ${done}: it conflicts with snapshot ${short(mapping.snapshotId)}. Commit ${short(work.commit ?? \"\")} (ref ${work.ref}) holds it; run \\`git diff ${work.base} ${work.commit} | git apply --3way\\` in ${mapping.to} to apply it. Snapshot ${short(work.snapshotId)} stays in the session's storage, so a resume on another machine keeps it as such a commit too, until discardDegradedRestore releases it.`;\n\t\tcase \"unavailable\":\n\t\t\treturn `Could not read ${done} here (${work.reason}), so it is not in ${mapping.to}; it is still in that worktree on the machine where it was done.`;\n\t}\n}\n\n/**\n * The notice for work a full restore carried over whose merged worktree could not be recorded yet (#5009): the restored\n * snapshot stays the restore target and the work stays kept until the next turn or resume records it.\n */\nexport function formatUnrecordedWorkNotice(mapping: WorktreeRootMapping, work: WorktreeDegradedWork): string {\n\treturn `The work applied in ${mapping.to} is not recorded yet: snapshot ${short(work.snapshotId)} stays kept, and a resume elsewhere applies it on top of snapshot ${short(mapping.snapshotId)} again, until the next turn or resume records the worktree.`;\n}\n\n/**\n * The notice for a checkout whose partial restore was pinned for longer than {@link DEGRADED_RESTORE_RETENTION_DAYS}\n * (#4922): the snapshot it lacked is no longer its restore target, and collection no longer keeps it.\n */\nexport function formatLapsedPinNotice(lapsed: {\n\treadonly root: string;\n\treadonly pin: DegradedRestorePin;\n\treadonly latest: string;\n}): string {\n\treturn `Snapshot ${short(lapsed.pin.snapshotId)} of ${lapsed.root}, restored only partly on ${lapsed.pin.since.slice(0, 10)}, is no longer kept: ${DEGRADED_RESTORE_RETENTION_DAYS} days have passed. The checkout continues from snapshot ${short(lapsed.latest)}, the work recorded in its partly restored worktree.`;\n}\n\n/**\n * `entries` with each snapshot's record and blobs from `store` carried inline, each once, so the exported file\n * restores without the source storage. Without a store only the records are carried. A blob the store no longer has\n * is left out; restoring that snapshot then fails with `blob-missing`.\n */\nexport async function inlineSnapshotBlobs(\n\tentries: readonly SessionEntry[],\n\trecords: ReadonlyMap<string, WorktreeSnapshot>,\n\tstore: SnapshotBlobStore | undefined,\n): Promise<SessionEntry[]> {\n\tconst emittedRecords = new Set<string>();\n\tconst emittedBlobs = new Set<string>();\n\tconst result: SessionEntry[] = [];\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"worktree_snapshot\") {\n\t\t\tresult.push(entry);\n\t\t\tcontinue;\n\t\t}\n\t\tconst record = entry.snapshot ?? records.get(entry.snapshotId);\n\t\tconst { blobs: _carried, snapshot: _record, ...rest } = entry;\n\t\tconst blobs: Record<string, string> = {};\n\t\tif (record && store) {\n\t\t\tfor (const hash of snapshotBlobHashes(record)) {\n\t\t\t\tif (emittedBlobs.has(hash)) continue;\n\t\t\t\tconst data = await store.getBlob(hash);\n\t\t\t\tif (data === undefined) continue;\n\t\t\t\tblobs[hash] = Buffer.from(data).toString(\"base64\");\n\t\t\t\temittedBlobs.add(hash);\n\t\t\t}\n\t\t}\n\t\tconst carryRecord = record !== undefined && !emittedRecords.has(record.id);\n\t\tif (record) emittedRecords.add(record.id);\n\t\tresult.push({\n\t\t\t...rest,\n\t\t\t...(carryRecord ? { snapshot: record } : {}),\n\t\t\t...(Object.keys(blobs).length > 0 ? { blobs } : {}),\n\t\t});\n\t}\n\treturn result;\n}\n\n/**\n * Moves inline blobs into `store` after checking each against its hash, and returns the entries without them.\n * Without a store the entries keep their blobs, which restore reads directly. Throws `blob-corrupt` before writing\n * anything when a blob does not match its hash.\n */\nexport async function adoptInlineSnapshotBlobs(\n\tentries: readonly SessionEntry[],\n\tstore: SnapshotBlobStore | undefined,\n): Promise<SessionEntry[]> {\n\tconst blobs: SnapshotBlob[] = [];\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"worktree_snapshot\" || !entry.blobs) continue;\n\t\tfor (const [hash, base64] of Object.entries(entry.blobs)) {\n\t\t\tconst data = new Uint8Array(Buffer.from(base64, \"base64\"));\n\t\t\tif (sha256Hex(data) !== hash) {\n\t\t\t\tthrow new WorkspaceRestoreError(\"blob-corrupt\", { snapshotId: entry.snapshotId, blob: hash });\n\t\t\t}\n\t\t\tblobs.push({ hash, data });\n\t\t}\n\t}\n\tif (!store || blobs.length === 0) return [...entries];\n\tawait store.putBlobs(blobs);\n\treturn entries.map((entry) => {\n\t\tif (entry.type !== \"worktree_snapshot\" || !entry.blobs) return entry;\n\t\tconst { blobs: _moved, ...rest } = entry;\n\t\treturn rest;\n\t});\n}\n\n/** A read-only view of the blobs carried inline by `entries`. */\nexport function inlineBlobStore(entries: readonly SessionEntry[]): SnapshotBlobStore {\n\tconst blobs = new Map<string, string>();\n\tfor (const entry of entries) {\n\t\tif (entry.type === \"worktree_snapshot\" && entry.blobs) {\n\t\t\tfor (const [hash, base64] of Object.entries(entry.blobs)) blobs.set(hash, base64);\n\t\t}\n\t}\n\treturn {\n\t\tasync putBlobs() {\n\t\t\tthrow new WorkspaceSnapshotError(\"blob-store-unsupported\", \"inline\");\n\t\t},\n\t\tasync getBlob(hash) {\n\t\t\tconst base64 = blobs.get(hash);\n\t\t\treturn base64 === undefined ? undefined : new Uint8Array(Buffer.from(base64, \"base64\"));\n\t\t},\n\t\tasync refreshBlobs(hashes) {\n\t\t\treturn hashes.every((hash) => blobs.has(hash));\n\t\t},\n\t\tasync listBlobHashes() {\n\t\t\treturn [...blobs.keys()];\n\t\t},\n\t};\n}\n\n/** Reads `primary` first, then the blobs carried inline by `entries`. */\nexport function sessionSnapshotBlobs(\n\tprimary: SnapshotBlobStore | undefined,\n\tentries: readonly SessionEntry[],\n): SnapshotBlobStore {\n\tconst inline = inlineBlobStore(entries);\n\tif (!primary) return inline;\n\treturn {\n\t\tputBlobs: (blobs) => primary.putBlobs(blobs),\n\t\tgetBlob: async (hash) => (await primary.getBlob(hash)) ?? (await inline.getBlob(hash)),\n\t\trefreshBlobs: (hashes) => primary.refreshBlobs(hashes),\n\t\tlistBlobHashes: () => primary.listBlobHashes(),\n\t};\n}\n\n/** What an export of `entries` carries: checkouts, snapshots and the bytes of patch and bundle content. */\nexport function describeSnapshotExport(\n\tentries: readonly SessionEntry[],\n\trecords: ReadonlyMap<string, WorktreeSnapshot>,\n): string | undefined {\n\tconst roots = new Set<string>();\n\tconst snapshots = new Set<string>();\n\tconst blobBytes = new Map<string, number>();\n\tlet omitted = 0;\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"worktree_snapshot\" || snapshots.has(entry.snapshotId)) continue;\n\t\tsnapshots.add(entry.snapshotId);\n\t\tconst record = entry.snapshot ?? records.get(entry.snapshotId);\n\t\tif (!record) continue;\n\t\troots.add(record.root);\n\t\tomitted += record.omitted.length;\n\t\tfor (const link of record.chain) if (link.patch) blobBytes.set(link.patch, link.bytes);\n\t\tif (record.bundle) blobBytes.set(record.bundle.blob, record.bundle.bytes);\n\t}\n\tif (snapshots.size === 0) return undefined;\n\tconst bytes = [...blobBytes.values()].reduce((sum, size) => sum + size, 0);\n\treturn `Includes ${snapshots.size} worktree snapshot(s) of ${[...roots].join(\", \")}: ${bytes} bytes of patch and bundle content${omitted > 0 ? `, ${omitted} omitted item(s) not included` : \"\"}`;\n}\n\nexport type WorktreeSnapshotComparison =\n\t| { readonly status: \"match\"; readonly tree: string; readonly head?: string }\n\t| { readonly status: \"missing\"; readonly reason: WorktreeSnapshotUnavailableReason }\n\t| {\n\t\t\treadonly status: \"differs\";\n\t\t\treadonly head: string;\n\t\t\treadonly tree: string;\n\t\t\t/** `git diff --stat` from the snapshot's tree to the current one, when the snapshot's tree is present locally. */\n\t\t\treadonly stat: string | undefined;\n\t };\n\n/** Compares the checkout at `dir` with `snapshot`, for `/session snapshot`. */\nexport async function compareWorktreeSnapshot(\n\tsnapshot: WorktreeSnapshot,\n\tdir: string,\n\tsettings: WorktreeSnapshotSettings,\n): Promise<WorktreeSnapshotComparison> {\n\tconst checkout = await locateCheckout(dir);\n\tif (checkout instanceof Error) return { status: \"missing\", reason: checkout };\n\tconst present = await runGit([\"cat-file\", \"-e\", `${snapshot.tree}^{tree}`], {\n\t\tcwd: checkout.root,\n\t\tallowExitCodes: [1, 128],\n\t});\n\tconst policy = await loadSnapshotPathPolicy(checkout.root);\n\tconst state = await withScratchDirectory((scratch) =>\n\t\twriteWorkingTree(checkout, settings, policy, scratch, present.exitCode === 0 ? { seedTree: snapshot.tree } : {}),\n\t);\n\tif (state.tree === snapshot.tree) {\n\t\tif (checkout.head === snapshot.head) return { status: \"match\", tree: state.tree };\n\t\tconst drift = new WorkspaceDriftError({\n\t\t\troot: checkout.root,\n\t\t\texpectedHead: snapshot.head,\n\t\t\tactualHead: checkout.head,\n\t\t\texpectedTree: snapshot.tree,\n\t\t\tactualTree: state.tree,\n\t\t\tsnapshotId: snapshot.id,\n\t\t});\n\t\tif (await isHeadOnlyAdvance(drift)) return { status: \"match\", tree: state.tree, head: checkout.head };\n\t}\n\tconst stat =\n\t\tpresent.exitCode === 0\n\t\t\t? await gitText([\"diff-tree\", \"--stat\", \"--no-renames\", \"--no-ext-diff\", \"-r\", snapshot.tree, state.tree], {\n\t\t\t\t\tcwd: checkout.root,\n\t\t\t\t})\n\t\t\t: undefined;\n\treturn { status: \"differs\", head: checkout.head, tree: state.tree, stat };\n}\n\n/**\n * What the last resume did about the checkout now at `root`, for `/session snapshot`, when it restored less than the\n * snapshot or nothing of it (#4733): the notice that resume showed. Undefined after a complete restore, or none.\n */\nexport function describeWorktreeRestoreStatus(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeSnapshotRecords\">,\n\troot: string,\n): string | undefined {\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tlet status: { readonly snapshotId: string; readonly message: string } | undefined;\n\tfor (const entry of sessionManager.getBranch()) {\n\t\tif (entry.type !== \"worktree_snapshot\") continue;\n\t\tif (entry.restore && resolve(entry.restore.to) === resolve(root)) {\n\t\t\tstatus = entry.restore.degraded\n\t\t\t\t? {\n\t\t\t\t\t\tsnapshotId: entry.snapshotId,\n\t\t\t\t\t\tmessage: formatDegradedRestoreNotice(\n\t\t\t\t\t\t\tentry.restore,\n\t\t\t\t\t\t\trecords.get(entry.snapshotId),\n\t\t\t\t\t\t\tentry.restoreWarnings,\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\t} else if (entry.unrestored && resolve(entry.root) === resolve(root)) {\n\t\t\tstatus = { snapshotId: entry.snapshotId, message: formatUnrestoredNotice(entry.root, entry.unrestored) };\n\t\t} else if (\n\t\t\tstatus &&\n\t\t\tresolve(entry.root) === resolve(root) &&\n\t\t\tentry.snapshotId !== status.snapshotId &&\n\t\t\tentry.degradedFrom !== status.snapshotId\n\t\t) {\n\t\t\t// A later snapshot of the checkout records what it holds now, which replaces what the resume left out, unless\n\t\t\t// it records the partly restored worktree, whose snapshot stays its restore target (#4922).\n\t\t\tstatus = undefined;\n\t\t}\n\t}\n\treturn status?.message;\n}\n\n/** Lines describing `snapshot` for `/session snapshot`. */\nexport function describeWorktreeSnapshot(root: string, snapshot: WorktreeSnapshot): string[] {\n\tconst omitted = snapshot.omitted.map((omission) =>\n\t\t\"path\" in omission\n\t\t\t? `${omission.path} (${omission.reason})`\n\t\t\t: `${omission.commits.length} commit(s) (${omission.reason})`,\n\t);\n\treturn [\n\t\t`${root}`,\n\t\t` snapshot ${snapshot.id} captured ${snapshot.capturedAt}`,\n\t\t` ${snapshot.branch ?? \"detached\"} at ${snapshot.head.slice(0, 12)}, tree ${snapshot.tree.slice(0, 12)}`,\n\t\t` delta chain ${snapshot.chain.length} link(s), ${snapshot.chain.reduce((sum, link) => sum + link.bytes, 0)} bytes; ${\n\t\t\tsnapshot.bundle\n\t\t\t\t? `${snapshot.bundle.commits.length} unpushed commit(s) bundled`\n\t\t\t\t: \"no unpushed commits bundled\"\n\t\t}`,\n\t\t...(omitted.length > 0 ? [` omitted: ${omitted.join(\", \")}`] : []),\n\t\t...(snapshot.filters\n\t\t\t? snapshotRestoreWarnings({ ...snapshot, omitted: [] }).map(formatWorktreeRestoreWarning)\n\t\t\t: []),\n\t];\n}\n\n/**\n * How long the latest turn's capture of the checkout now at `root` took, as a line, also when that capture was of the\n * checkout before a restore moved it to `root`; undefined when no capture recorded it.\n */\nexport async function describeLastCapture(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n\troot: string,\n): Promise<string | undefined> {\n\tconst branch = sessionManager.getBranch();\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tfor (let index = branch.length - 1; index >= 0; index--) {\n\t\tconst entry = branch[index]!;\n\t\tif (\n\t\t\tentry.type === \"worktree_snapshot\" &&\n\t\t\ttypeof entry.captureMs === \"number\" &&\n\t\t\t(await mapRestoredPathAsync(entry.root, mappings)) === resolve(root)\n\t\t) {\n\t\t\treturn `last capture took ${(entry.captureMs / 1000).toFixed(1)} s`;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Opens `sessionManager`'s session where it should continue: in place when its checkout matches the last snapshot,\n * in the restored worktree otherwise. With `pool`, the opened session holds its pooled worktrees until it closes.\n * Returns the notices to show for a restore it performed.\n */\nexport async function openSessionInWorktree(\n\tsessionManager: SessionManager,\n\toptions: ResumeSessionWorktreeOptions & { readonly sessionDirectory?: string },\n): Promise<{\n\treadonly sessionManager: SessionManager;\n\treadonly notices: { readonly type: \"info\" | \"warning\"; readonly message: string }[];\n}> {\n\tconst resume = await resumeSessionWorktree(sessionManager, options);\n\tconst opened = await openResumedSession(\n\t\tsessionManager,\n\t\tresume.status === \"none\" ? sessionManager.getCwd() : resume.cwd,\n\t\tresume.status === \"restored\" ? resume.mappings : [],\n\t\toptions.sessionDirectory,\n\t\tresume.status === \"none\" ? [] : resume.unrestored.map((checkout) => checkout.record),\n\t);\n\t// The opened session takes over the pooled slots, held until it closes (#4748).\n\tif (options.pool) {\n\t\tawait holdSessionWorktrees(\n\t\t\tsessionManager,\n\t\t\topened.sessionManager,\n\t\t\toptions.storeDir ?? defaultWorktreeSnapshotStoreDir(),\n\t\t);\n\t}\n\treturn opened;\n}\n\n/**\n * Opens `sessionManager`'s session in `cwd`, where resuming it left its working directory, and returns the notices to\n * show for the worktrees that resuming `restored` it into.\n */\nexport async function openResumedSession(\n\tsessionManager: SessionManager,\n\tcwd: string,\n\trestored: readonly WorktreeRootMapping[],\n\tsessionDirectory?: string,\n\tunrestored: readonly WorktreeUnrestored[] = [],\n): Promise<{\n\treadonly sessionManager: SessionManager;\n\treadonly notices: { readonly type: \"info\" | \"warning\"; readonly message: string }[];\n}> {\n\tconst opened =\n\t\tcwd !== sessionManager.getCwd()\n\t\t\t? await sessionManager.openSessionById(sessionManager.getSessionId(), cwd, sessionDirectory, {\n\t\t\t\t\thistory: \"tail\",\n\t\t\t\t})\n\t\t\t: sessionManager;\n\tconst restoredHere = new Set(restored.map((mapping) => mapping.to));\n\tconst leftHere = new Set(unrestored.map((record) => `${record.snapshotId}\\0${record.at}`));\n\treturn {\n\t\tsessionManager: opened,\n\t\tnotices: restoreNotices(opened, (entry) =>\n\t\t\tentry.restore\n\t\t\t\t? restoredHere.has(entry.restore.to)\n\t\t\t\t: entry.unrestored !== undefined && leftHere.has(`${entry.unrestored.snapshotId}\\0${entry.unrestored.at}`),\n\t\t),\n\t};\n}\n\n/**\n * Whether a session recorded elsewhere continues in `cwd` because a restore moved its checkout there, so opening it\n * from `cwd` resumes it rather than forking it into another project.\n */\nexport async function sessionContinuesIn(store: SessionStore, sessionId: string, cwd: string): Promise<boolean> {\n\tconst stored = await storedSnapshotEntries(store, sessionId);\n\treturn runCanonicalStepsAsync(snapshotsContinueIn(stored.header.cwd, stored.entries, cwd));\n}\n\nexport function sessionManagerContinuesIn(\n\tsessionManager: Pick<SessionManager, \"getHeader\" | \"getEntries\">,\n\tcwd: string,\n): boolean {\n\tconst header = sessionManager.getHeader();\n\treturn header !== null && runCanonicalSteps(snapshotsContinueIn(header.cwd, sessionManager.getEntries(), cwd));\n}\n\nfunction* snapshotsContinueIn(\n\trecordedCwd: string,\n\tentries: readonly SessionEntry[],\n\tcwd: string,\n): CanonicalSteps<boolean> {\n\tconst mappings = entries.flatMap((entry) =>\n\t\tentry.type === \"worktree_snapshot\" && entry.restore ? [entry.restore] : [],\n\t);\n\tif (mappings.length === 0) return false;\n\tconst mapped = yield* restoredPath(recordedCwd, mappings);\n\treturn (yield mapped) === (yield cwd);\n}\n\nasync function storedSnapshotEntries(\n\tstore: SessionStore,\n\tsessionId: string,\n): Promise<{\n\treadonly header: SessionRecordHeader;\n\treadonly entries: SessionEntry[];\n\treadonly branch: SessionEntry[];\n}> {\n\tconst { header, state } = await readSessionTail(store, sessionId, Number.MAX_SAFE_INTEGER);\n\tconst snapshots = state.filter(({ entry }) => entry.type === \"worktree_snapshot\");\n\treturn {\n\t\theader,\n\t\tentries: snapshots.map(({ entry }) => entry),\n\t\tbranch: snapshots.filter(({ onBranch }) => onBranch).map(({ entry }) => entry),\n\t};\n}\n\n/** The restores recorded on `branch`, oldest first. */\nfunction restoreMappings(branch: readonly SessionEntry[]): WorktreeRootMapping[] {\n\treturn branch.flatMap((entry) => (entry.type === \"worktree_snapshot\" && entry.restore ? [entry.restore] : []));\n}\n\nfunction* storedBranchSnapshots(\n\tentries: readonly SessionEntry[],\n\tbranch: readonly SessionEntry[],\n): CanonicalSteps<{ readonly mappings: WorktreeRootMapping[]; readonly current: Map<string, WorktreeSnapshot> }> {\n\tconst records = new Map<string, WorktreeSnapshot>();\n\tfor (const entry of entries) {\n\t\tif (entry.type === \"worktree_snapshot\" && entry.snapshot) records.set(entry.snapshotId, entry.snapshot);\n\t}\n\tconst mappings = restoreMappings(branch);\n\tconst current = yield* currentSnapshots({\n\t\tgetBranch: () => [...branch],\n\t\tgetWorktreeRootMappings: () => mappings,\n\t\tgetWorktreeSnapshotRecords: () => records,\n\t});\n\treturn { mappings, current };\n}\n\n/**\n * Whether a session runs in a checkout it recorded snapshots of: its working directory, followed through the restores\n * it recorded, lies inside a checkout the branch it reopens on recorded a snapshot of. Opening such a session from\n * another directory resumes it against that checkout, verified in place or restored into a fresh worktree, instead of\n * forking it into the other directory.\n */\nexport async function sessionRunsInRecordedCheckout(store: SessionStore, sessionId: string): Promise<boolean> {\n\tconst { header, entries, branch } = await storedSnapshotEntries(store, sessionId);\n\treturn runCanonicalStepsAsync(snapshotsRunInRecordedCheckout(header.cwd, entries, branch));\n}\n\nexport function sessionManagerRunsInRecordedCheckout(\n\tsessionManager: Pick<SessionManager, \"getHeader\" | \"getEntries\" | \"getBranch\">,\n): boolean {\n\tconst header = sessionManager.getHeader();\n\treturn (\n\t\theader !== null &&\n\t\trunCanonicalSteps(\n\t\t\tsnapshotsRunInRecordedCheckout(header.cwd, sessionManager.getEntries(), sessionManager.getBranch()),\n\t\t)\n\t);\n}\n\nfunction* snapshotsRunInRecordedCheckout(\n\trecordedCwd: string,\n\tentries: readonly SessionEntry[],\n\tbranch: readonly SessionEntry[],\n): CanonicalSteps<boolean> {\n\tconst { mappings, current } = yield* storedBranchSnapshots(entries, branch);\n\tconst cwd = yield* restoredPath(recordedCwd, mappings);\n\tfor (const root of current.keys()) if (yield* isInside(root, cwd)) return true;\n\treturn false;\n}\n"]}
1
+ {"version":3,"file":"session-worktree-snapshots.js","sourceRoot":"","sources":["../../src/core/session-worktree-snapshots.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,IAAI,WAAW,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EA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AAG,cAAc,CAAC,SAAS,EAAE,CAAC;IAC1C,OAAO,CACN,MAAM,KAAK,IAAI;QACf,iBAAiB,CAChB,8BAA8B,CAAC,MAAM,CAAC,GAAG,EAAE,cAAc,CAAC,UAAU,EAAE,EAAE,cAAc,CAAC,SAAS,EAAE,CAAC,CACnG,CACD,CAAC;AACH,CAAC;AAED,QAAQ,CAAC,CAAC,8BAA8B,CACvC,WAAmB,EACnB,OAAgC,EAChC,MAA+B;IAE/B,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC5E,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACvD,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE;QAAE,IAAI,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;IAC/E,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import { access, stat } from \"node:fs/promises\";\nimport { isAbsolute, relative, resolve, sep } from \"node:path\";\nimport type { AssistantMessage } from \"@bastani/atomic-ai/compat\";\nimport { failureDebugFields, reportDebugAsync as reportDebug } from \"./debug.ts\";\nimport { timeCheckoutRestore } from \"./resume/timings.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport type { SessionEntry, WorktreeRestoreHostWarning } from \"./session-manager-types.ts\";\nimport { isStorageError } from \"./storage/errors.js\";\nimport { readSessionTail } from \"./storage/session/session-resume.js\";\nimport type { SessionRecordHeader, SessionStore } from \"./storage/session/types.js\";\nimport {\n\ttype BestWorktreeRestore,\n\tisRecoverableRestoreFailure,\n\ttype RestoreBestWorktreeOptions,\n\trestoreBestWorktree,\n\tunrestoredRecord,\n} from \"./worktree-snapshot/best-restore.ts\";\nimport { DEGRADED_RESTORE_RETENTION_DAYS, snapshotBlobHashes } from \"./worktree-snapshot/blob-store.ts\";\nimport {\n\ttype Checkout,\n\tcaptureLocatedCheckout,\n\tcaptureWorktreeSnapshot,\n\tlocateCheckout,\n\trecordWorktreeCapture,\n\ttype WorktreeSnapshotUnavailableReason,\n\twithScratchDirectory,\n\twriteWorkingTree,\n} from \"./worktree-snapshot/capture.ts\";\nimport { carryOverDegradedWork } from \"./worktree-snapshot/degraded-work.ts\";\nimport { sha256Hex } from \"./worktree-snapshot/env-hash.ts\";\nimport {\n\tfindWorkspaceError,\n\ttype GitUnavailableError,\n\tisGitUnavailableError,\n\tisWorkspaceDriftError,\n\tisWorkspaceError,\n\tisWorkspaceSnapshotError,\n\tunreadablePathError,\n\tWorkspaceDriftError,\n\ttype WorkspaceError,\n\tWorkspaceRestoreError,\n\tWorkspaceSnapshotError,\n} from \"./worktree-snapshot/errors.ts\";\nimport { SNAPSHOT_COLLECTION_SESSION_DELAY_MS, scheduleSnapshotCollection } from \"./worktree-snapshot/garbage.ts\";\nimport { gitText, runGit } from \"./worktree-snapshot/git.ts\";\nimport { isHeadOnlyAdvance } from \"./worktree-snapshot/head-advance.ts\";\nimport {\n\ttype CanonicalSteps,\n\tcanonicalizeWorktreePathAsync,\n\tcanonicalPaths,\n\trunCanonicalSteps,\n\trunCanonicalStepsAsync,\n} from \"./worktree-snapshot/paths.ts\";\nimport { loadSnapshotPathPolicy } from \"./worktree-snapshot/policy.ts\";\nimport {\n\tadmitPooledWorktree,\n\tclaimIdleWorktree,\n\tconfirmPooledWorktreeLease,\n\tdiscardPooledWorktree,\n\tevictIdleWorktrees,\n\tholdRestoredWorktree,\n\ttype PoolOwner,\n\tpooledWorktreeHolder,\n\ttype RepositoryId,\n\trecordPooledWorktreeState,\n\treleaseRestoredWorktree,\n\ttype WorktreeLease,\n\tworktreeSetAside,\n} from \"./worktree-snapshot/pool.ts\";\nimport {\n\tdefaultWorktreeSnapshotStoreDir,\n\ttype RestoreWorktreeSnapshotOptions,\n\tremoveRestoredWorktree,\n\trestoreDegradedWorktreeAt,\n\trestoreWorktree,\n\trestoreWorktreeAt,\n\tsnapshotRestoreWarnings,\n\tverifyWorktree,\n} from \"./worktree-snapshot/restore.ts\";\nimport { adoptPrebuiltSeed } from \"./worktree-snapshot/seeds.ts\";\nimport { keepSessionSnapshotCommit, releaseSessionSnapshotRefs } from \"./worktree-snapshot/session-refs.ts\";\nimport type {\n\tSnapshotBlob,\n\tSnapshotBlobStore,\n\tWorktreeDegradedRestore,\n\tWorktreeDegradedWork,\n\tWorktreeRestoreWarning,\n\tWorktreeRootMapping,\n\tWorktreeSnapshot,\n\tWorktreeSnapshotSettings,\n\tWorktreeUnrestored,\n} from \"./worktree-snapshot/types.ts\";\n\nexport { isRecoverableRestoreFailure };\n\n/** Why a turn's snapshot could not be recorded: Git is unavailable, or a typed workspace failure. */\nexport type WorktreeSnapshotUnavailable = WorkspaceError | GitUnavailableError;\n\n/** Built-in tools that can change files: a turn that called one records a snapshot. */\nexport const FILE_WRITING_TOOLS: ReadonlySet<string> = new Set([\"bash\", \"edit\", \"write\", \"powershell\"]);\nconst PATH_TOOLS: ReadonlySet<string> = new Set([\"edit\", \"write\"]);\n\nexport interface TurnSnapshotDependencies {\n\treadonly sessionManager: SessionManager;\n\treadonly cwd: () => string;\n\treadonly settings: () => WorktreeSnapshotSettings;\n\t/** Whether a registered tool declares `writesFiles`. */\n\treadonly declaresWrites: (toolName: string) => boolean;\n\t/** Called once per distinct reason a snapshot could not be recorded. */\n\treadonly onUnavailable: (reason: WorktreeSnapshotUnavailable) => void;\n}\n\nfunction* isInside(parent: string, child: string): CanonicalSteps<boolean> {\n\tconst path = relative(yield parent, yield child);\n\treturn path === \"\" || (!path.startsWith(`..${sep}`) && path !== \"..\" && !isAbsolute(path));\n}\n\n/**\n * Records a `worktree_snapshot` entry per checkout at the end of each turn that called a file-writing tool. In-memory\n * sessions, which cannot be resumed elsewhere, record nothing.\n */\nexport class SessionWorktreeSnapshotRecorder {\n\tprivate readonly deps: TurnSnapshotDependencies;\n\tprivate readonly reported = new Set<string>();\n\n\tconstructor(deps: TurnSnapshotDependencies) {\n\t\tthis.deps = deps;\n\t}\n\n\tprivate report(reason: WorktreeSnapshotUnavailable): void {\n\t\tconst key = `${reason.code}\\0${JSON.stringify(reason.fields)}`;\n\t\tif (this.reported.has(key)) return;\n\t\tthis.reported.add(key);\n\t\tthis.deps.onUnavailable(reason);\n\t}\n\n\t/** Directories whose checkouts a turn may have changed: the session cwd and the targets of path-taking tools. */\n\tprivate touchedDirectories(message: AssistantMessage): string[] | undefined {\n\t\tconst cwd = this.deps.cwd();\n\t\tconst directories = new Set<string>();\n\t\tfor (const part of message.content) {\n\t\t\tif (part.type !== \"toolCall\") continue;\n\t\t\tif (!FILE_WRITING_TOOLS.has(part.name) && !this.deps.declaresWrites(part.name)) continue;\n\t\t\tdirectories.add(cwd);\n\t\t\tconst path = PATH_TOOLS.has(part.name) ? part.arguments.path : undefined;\n\t\t\tif (typeof path === \"string\" && path.length > 0) directories.add(resolve(cwd, path, \"..\"));\n\t\t}\n\t\treturn directories.size === 0 ? undefined : [...directories];\n\t}\n\n\t/** Whether the turn may record a snapshot when it ends: a persisted session called a tool that can change files. */\n\tcallsFileWritingTool(message: AssistantMessage): boolean {\n\t\treturn this.deps.sessionManager.isPersisted() && this.touchedDirectories(message) !== undefined;\n\t}\n\n\tasync recordTurn(message: AssistantMessage): Promise<void> {\n\t\tconst directories = this.touchedDirectories(message);\n\t\tif (!directories) return;\n\t\tlet settings: WorktreeSnapshotSettings;\n\t\ttry {\n\t\t\tsettings = this.deps.settings();\n\t\t} catch (error) {\n\t\t\tthis.reportFailure(error);\n\t\t\treturn;\n\t\t}\n\t\tif (!settings.enabled || !this.deps.sessionManager.isPersisted()) return;\n\t\tconst blobs = this.deps.sessionManager.getSessionStore().snapshotBlobs;\n\t\tif (!blobs) {\n\t\t\tthis.report(\n\t\t\t\tnew WorkspaceSnapshotError(\n\t\t\t\t\t\"blob-store-unsupported\",\n\t\t\t\t\tthis.deps.sessionManager.getSessionStore().descriptor.adapter,\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst checkouts = new Map<string, Checkout>();\n\t\tfor (const directory of directories) {\n\t\t\ttry {\n\t\t\t\tconst checkout = await locateCheckout(await nearestExisting(directory));\n\t\t\t\tif (checkout instanceof Error) this.report(checkout);\n\t\t\t\telse if (!checkouts.has(checkout.root)) checkouts.set(checkout.root, checkout);\n\t\t\t} catch (error) {\n\t\t\t\tthis.reportFailure(error);\n\t\t\t}\n\t\t}\n\t\tfor (const [root, checkout] of checkouts) {\n\t\t\t// A pooled worktree this session no longer holds may be another session's work: never recorded as its (#4830).\n\t\t\tif (!(await holdsSessionWorktree(this.deps.sessionManager, root))) {\n\t\t\t\tthis.report(new WorkspaceSnapshotError(\"pooled-worktree-lost\", root));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst previous = this.deps.sessionManager.getLatestWorktreeSnapshots().get(root);\n\t\t\t// A capture in a partly restored worktree records it as derived from the snapshot it lacks (#4922); one of a\n\t\t\t// full restore that carried work over records the merged worktree, or keeps naming the work it kept (#5009).\n\t\t\tconst pin = await degradedRestorePinAsync(this.deps.sessionManager, root);\n\t\t\ttry {\n\t\t\t\tlet captureMs = 0;\n\t\t\t\t// The first capture uses the lookup above; one that a collection makes run again looks the checkout up anew.\n\t\t\t\tlet located: Checkout | undefined = checkout;\n\t\t\t\tawait recordWorktreeCapture(\n\t\t\t\t\tblobs,\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tconst started = performance.now();\n\t\t\t\t\t\tconst result =\n\t\t\t\t\t\t\tlocated === undefined\n\t\t\t\t\t\t\t\t? await captureWorktreeSnapshot(root, { settings, previous, blobs })\n\t\t\t\t\t\t\t\t: await captureLocatedCheckout(located, { settings, previous, blobs });\n\t\t\t\t\t\tlocated = undefined;\n\t\t\t\t\t\tcaptureMs = Math.floor(performance.now() - started);\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t},\n\t\t\t\t\tasync (result) => {\n\t\t\t\t\t\tif (result.status === \"captured\" || result.status === \"unchanged\") {\n\t\t\t\t\t\t\tawait this.deps.sessionManager.appendWorktreeSnapshot(\n\t\t\t\t\t\t\t\troot,\n\t\t\t\t\t\t\t\tresult.snapshot.id,\n\t\t\t\t\t\t\t\tresult.status === \"captured\" ? result.snapshot : undefined,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\t[],\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\tcaptureMs,\n\t\t\t\t\t\t\t\tcaptureDegradedFrom(pin, result.snapshot.id),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tawait keepLatestSnapshotCommit(this.deps.sessionManager, root, result.snapshot);\n\t\t\t\t\t\t} else if (result.status === \"unavailable\") {\n\t\t\t\t\t\t\tthis.report(result.reason);\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tthis.reportFailure(error);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Schedules an automatic collection of the session store's unreferenced snapshot blobs when one is due, and returns\n\t * without waiting for it. The collection starts {@link SNAPSHOT_COLLECTION_SESSION_DELAY_MS} later, so it competes\n\t * neither with the start of an interactive session nor with opening the next session after this one closes (#5530).\n\t * Called once an interactive session has started, and when a session closes.\n\t */\n\tscheduleCollection(): void {\n\t\tlet settings: WorktreeSnapshotSettings;\n\t\ttry {\n\t\t\tsettings = this.deps.settings();\n\t\t} catch (error) {\n\t\t\tthis.reportFailure(error);\n\t\t\treturn;\n\t\t}\n\t\tvoid scheduleSnapshotCollection(this.deps.sessionManager.getSessionStore().snapshotBlobs, settings, {\n\t\t\tdelayMs: SNAPSHOT_COLLECTION_SESSION_DELAY_MS,\n\t\t});\n\t}\n\n\t/**\n\t * Releases the pooled worktrees this session holds (#4748), each with the latest snapshot the session recorded of\n\t * it as its known state. Called when the session closes; never throws.\n\t */\n\tasync releaseWorktrees(): Promise<void> {\n\t\tawait releaseSessionWorktrees(this.deps.sessionManager);\n\t}\n\n\t/**\n\t * Reports a typed reason once. A storage failure, such as a store that is unreachable or refuses a payload, is a\n\t * `blob-store-failed` reason: recording a snapshot never fails the turn (#4954). Any other error is a defect.\n\t */\n\tprivate reportFailure(error: unknown): void {\n\t\tconst reason = isGitUnavailableError(error) ? error : findWorkspaceError(error);\n\t\tif (reason) {\n\t\t\tthis.report(reason);\n\t\t\treturn;\n\t\t}\n\t\tif (!isStorageFailure(error)) throw error;\n\t\tthis.report(\n\t\t\tnew WorkspaceSnapshotError(\n\t\t\t\t\"blob-store-failed\",\n\t\t\t\tthis.deps.sessionManager.getSessionStore().descriptor.adapter,\n\t\t\t\terror as Error,\n\t\t\t),\n\t\t);\n\t}\n}\n\n/** Whether `error`, or a cause of it, is a failure of the storage: a storage error, or a session store's. */\nfunction isStorageFailure(error: unknown): boolean {\n\tlet current = error;\n\tfor (let depth = 0; depth < 8 && current instanceof Error; depth++) {\n\t\tif (isStorageError(current) || current.name.startsWith(\"Storage\") || current.name === \"StoreClosedError\")\n\t\t\treturn true;\n\t\tcurrent = current.cause;\n\t}\n\treturn false;\n}\n\n/**\n * Keeps the commit of `snapshot`, the session's latest of the checkout at `root`, reachable from the session's ref in\n * that repository, so `git gc` does not prune it and resume still recognises the checkout (#4923). The ref of each\n * checkout the session's work in `root` came from through restores is released, as retention releases its snapshot.\n */\nasync function keepLatestSnapshotCommit(\n\tsessionManager: SessionManager,\n\troot: string,\n\tsnapshot: WorktreeSnapshot,\n): Promise<void> {\n\tconst sessionId = sessionManager.getSessionId();\n\tawait keepSessionSnapshotCommit(sessionId, root, snapshot.snapshot);\n\tawait releaseSessionSnapshotRefs(sessionId, restoredLineage(root, sessionManager.getWorktreeRootMappings()));\n}\n\n/**\n * The other checkouts that restores connect `root` to: walking the mappings newest first, each one the work in a\n * connected checkout was restored from or moved to.\n */\nfunction restoredLineage(root: string, mappings: readonly WorktreeRootMapping[]): string[] {\n\tconst connected = new Set([resolve(root)]);\n\tfor (const mapping of [...mappings].reverse()) {\n\t\tconst from = resolve(mapping.from);\n\t\tconst to = resolve(mapping.to);\n\t\tif (connected.has(from) || connected.has(to)) connected.add(from).add(to);\n\t}\n\tconnected.delete(resolve(root));\n\treturn [...connected];\n}\n\n/**\n * Deletes session `sessionId` from `store`, then the refs that kept its snapshot commits in the repositories of the\n * checkouts it recorded on this node (#4923). Rejects as `store.delete` does; releasing the refs never fails it.\n */\nexport async function deleteSessionWithSnapshotRefs(\n\tstore: Pick<SessionStore, \"load\" | \"delete\">,\n\tsessionId: string,\n): Promise<void> {\n\tconst roots = await store.load(sessionId).then(\n\t\t({ entries }) => entries.flatMap((entry) => (entry.type === \"worktree_snapshot\" ? [entry.root] : [])),\n\t\t() => [],\n\t);\n\tawait store.delete(sessionId);\n\tawait releaseSessionSnapshotRefs(sessionId, new Set(roots));\n}\n\nasync function nearestExisting(directory: string): Promise<string> {\n\tfor (let current = directory; ; current = resolve(current, \"..\")) {\n\t\ttry {\n\t\t\tif ((await stat(current)).isDirectory()) return current;\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\" && (error as NodeJS.ErrnoException).code !== \"ENOTDIR\")\n\t\t\t\tthrow unreadablePathError(current, error);\n\t\t}\n\t\tif (resolve(current, \"..\") === current) return current;\n\t}\n}\n\n/** The pooled worktrees each open session holds, released when it closes (#4748). */\nconst sessionLeases = new WeakMap<SessionManager, WorktreeLease[]>();\n\nfunction sessionOwner(sessionManager: Pick<SessionManager, \"getSessionId\">): PoolOwner {\n\treturn { kind: \"session\", id: sessionManager.getSessionId() };\n}\n\nfunction holdFor(sessionManager: SessionManager, lease: WorktreeLease): void {\n\tconst leases = sessionLeases.get(sessionManager) ?? [];\n\tleases.push(lease);\n\tsessionLeases.set(sessionManager, leases);\n}\n\n/**\n * The pooled worktrees, by canonical root, each session of this process holds no lease of though its record may still\n * name it (#4830): its lease was lost to another holder, or holding it failed. The session no longer works in them.\n */\nconst forfeitedWorktrees = new Map<string, Set<string>>();\n\nasync function worktreeKey(root: string): Promise<string> {\n\ttry {\n\t\treturn await canonicalizeWorktreePathAsync(root);\n\t} catch {\n\t\treturn resolve(root);\n\t}\n}\n\nasync function forfeit(sessionId: string, root: string): Promise<void> {\n\tconst key = await worktreeKey(root);\n\tconst roots = forfeitedWorktrees.get(sessionId) ?? new Set();\n\troots.add(key);\n\tforfeitedWorktrees.set(sessionId, roots);\n}\n\nasync function forfeited(sessionId: string, root: string): Promise<boolean> {\n\treturn forfeitedWorktrees.get(sessionId)?.has(await worktreeKey(root)) === true;\n}\n\n/**\n * Whether `lease`, held by `sessionManager`, still holds its slot (#4830). A lease whose slot another holder took is\n * dropped, and its worktree forfeited: the session must not continue in it.\n */\nasync function keepsLease(sessionManager: SessionManager, lease: WorktreeLease): Promise<boolean> {\n\tif (await confirmPooledWorktreeLease(lease)) return true;\n\tconst leases = sessionLeases.get(sessionManager) ?? [];\n\tleases.splice(leases.indexOf(lease), 1);\n\tawait forfeit(sessionManager.getSessionId(), lease.path);\n\treportDebug(\"storage\", \"worktree-pool-lease-lost\", { path: lease.path });\n\treturn false;\n}\n\n/**\n * Whether `sessionManager` may still work in the checkout at `root` (#4830): false for a pooled worktree whose lease it\n * lost to another holder, or could not take, checked against the slot's record. True for any other checkout.\n */\nasync function holdsSessionWorktree(sessionManager: SessionManager, root: string): Promise<boolean> {\n\tif (await forfeited(sessionManager.getSessionId(), root)) return false;\n\tconst key = await worktreeKey(root);\n\tconst held = sessionLeases.get(sessionManager) ?? [];\n\tconst keys = await Promise.all(held.map((lease) => worktreeKey(lease.path)));\n\tconst lease = held.find((_, index) => keys[index] === key);\n\treturn lease === undefined || (await keepsLease(sessionManager, lease));\n}\n\n/**\n * Whether the worktree at `root` is a pooled slot that another session owns (#4748), or that session `sessionId`\n * could not hold or lost while it was stalled (#4830): this session must not continue in it, and restores its checkout\n * fresh as if the worktree were gone. Reads only; false for any unpooled path.\n */\nexport async function pooledWorktreeOwnedElsewhere(\n\tstoreDir: string,\n\troot: string,\n\tsessionId: string,\n): Promise<boolean> {\n\tif (await worktreeSetAside(storeDir, root)) return true;\n\tconst holder = await pooledWorktreeHolder(storeDir, root);\n\tif (holder === \"unpooled\") return false;\n\treturn holder.owner?.kind !== \"session\" || holder.owner.id !== sessionId || (await forfeited(sessionId, root));\n}\n\n/**\n * Makes `to`, the session a resume opened, hold every pooled worktree of its checkouts that it owns, then releases what\n * `from`, the session the resume restored on, held, when it is another object (#4748). A slot leased by a live process\n * of the same session stays with that process. A lease `to` already holds is checked first: one whose slot another\n * holder took is dropped (#4830). Never throws: a resume continues without a lease, and then treats each pooled\n * worktree it could not hold as another session's, restoring it fresh instead of working in it unleased (#4830).\n */\nexport async function holdSessionWorktrees(\n\tfrom: SessionManager,\n\tto: SessionManager,\n\tstoreDir: string = defaultWorktreeSnapshotStoreDir(),\n\tsignal?: AbortSignal,\n): Promise<void> {\n\ttry {\n\t\tconst owner = sessionOwner(to);\n\t\tconst held = new Set<string>();\n\t\tfor (const lease of [...(sessionLeases.get(to) ?? [])]) {\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (await keepsLease(to, lease)) held.add(lease.path);\n\t\t}\n\t\tfor (const root of (await currentWorktreeSnapshots(to)).keys()) {\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (held.has(root)) continue;\n\t\t\ttry {\n\t\t\t\tconst lease = await holdRestoredWorktree(storeDir, root, owner, signal);\n\t\t\t\tif (lease !== undefined) {\n\t\t\t\t\tholdFor(to, lease);\n\t\t\t\t\tconst key = await worktreeKey(root);\n\t\t\t\t\tforfeitedWorktrees.get(owner.id)?.delete(key);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (signal?.aborted) break;\n\t\t\t\treportDebug(\"storage\", \"worktree-pool-hold-failed\", { root, ...failureDebugFields(error) });\n\t\t\t\tawait forfeit(owner.id, root);\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-hold-failed\", failureDebugFields(error));\n\t}\n\tif (from !== to) await releaseSessionWorktrees(from);\n}\n\n/** Releases every pooled worktree `sessionManager` holds, with the latest snapshot it recorded of each. Never throws. */\nexport async function releaseSessionWorktrees(sessionManager: SessionManager): Promise<void> {\n\tconst leases = sessionLeases.get(sessionManager) ?? [];\n\tsessionLeases.delete(sessionManager);\n\tif (leases.length === 0) return;\n\tconst latest = [...sessionManager.getLatestWorktreeSnapshots()];\n\tfor (const lease of leases) {\n\t\ttry {\n\t\t\tconst canonical = canonicalPaths();\n\t\t\tconst path = await canonical(lease.path);\n\t\t\tlet snapshot: WorktreeSnapshot | undefined;\n\t\t\tfor (const [root, candidate] of latest) {\n\t\t\t\tif ((await canonical(root)) !== path) continue;\n\t\t\t\tsnapshot = candidate;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tawait releaseRestoredWorktree(\n\t\t\t\tlease,\n\t\t\t\tsnapshot && { snapshotId: snapshot.id, head: snapshot.head, tree: snapshot.tree },\n\t\t\t);\n\t\t} catch (error) {\n\t\t\treportDebug(\"storage\", \"worktree-pool-release-failed\", failureDebugFields(error));\n\t\t}\n\t}\n}\n\n/** `path` rewritten through each restore in order: a path under `from` moves to the same place under `to`. */\nexport function mapRestoredPath(path: string, mappings: readonly Pick<WorktreeRootMapping, \"from\" | \"to\">[]): string {\n\treturn runCanonicalSteps(restoredPath(path, mappings));\n}\n\nexport function mapRestoredPathAsync(\n\tpath: string,\n\tmappings: readonly Pick<WorktreeRootMapping, \"from\" | \"to\">[],\n): Promise<string> {\n\treturn runCanonicalStepsAsync(restoredPath(path, mappings));\n}\n\nfunction* restoredPath(\n\tpath: string,\n\tmappings: readonly Pick<WorktreeRootMapping, \"from\" | \"to\">[],\n): CanonicalSteps<string> {\n\tlet mapped = resolve(path);\n\tlet next = 0;\n\twhile (next < mappings.length) {\n\t\tconst current = yield mapped;\n\t\tlet best: { index: number; source: string } | undefined;\n\t\tfor (let index = next; index < mappings.length; index++) {\n\t\t\tconst source = yield mappings[index]!.from;\n\t\t\tif ((yield* isInside(source, current)) && (best === undefined || source.length > best.source.length)) {\n\t\t\t\tbest = { index, source };\n\t\t\t}\n\t\t}\n\t\tif (best === undefined) break;\n\t\tmapped = resolve(mappings[best.index]!.to, relative(best.source, current));\n\t\tnext = best.index + 1;\n\t}\n\treturn mapped;\n}\n\n/** Recover the original root of a sequence of restores, so a restored root supersedes its earlier location. */\nfunction* originalRoot(root: string, mappings: readonly WorktreeRootMapping[]): CanonicalSteps<string> {\n\tlet current = yield root;\n\tfor (let index = mappings.length - 1; index >= 0; index--) {\n\t\tconst mapping = mappings[index]!;\n\t\tif ((yield mapping.to) === current) current = yield mapping.from;\n\t}\n\treturn current;\n}\n\nexport { DEGRADED_RESTORE_RETENTION_DAYS };\n\nconst DEGRADED_RESTORE_RETENTION_MS = DEGRADED_RESTORE_RETENTION_DAYS * 24 * 60 * 60 * 1000;\n\n/**\n * A checkout a resume restored with less than its snapshot (#4922): the snapshot stays the checkout's restore target\n * while the session records the partly restored worktree as it is.\n */\nexport interface DegradedRestorePin {\n\t/** The snapshot restored only partly. */\n\treadonly snapshotId: string;\n\t/** When the partial restore happened. */\n\treadonly since: string;\n\t/** What the partial restore put into the worktree, when the session recorded it: the base of the work done there. */\n\treadonly base?: { readonly head: string; readonly tree: string };\n\t/** Whether {@link DEGRADED_RESTORE_RETENTION_DAYS} have passed since the partial restore, which ends the pin. */\n\treadonly lapsed: boolean;\n\t/**\n\t * After a full restore of `snapshotId` carried the work of the partly restored worktree over (#5009): the snapshot\n\t * of that work, which stays kept until the merged worktree is recorded, so a resume elsewhere carries it over again.\n\t */\n\treadonly work?: string;\n\t/**\n\t * Whether that work conflicted with the full restore and was kept apart (#5009): it stays kept, and the checkout\n\t * continues from its latest snapshot, until `discardDegradedRestore` releases it.\n\t */\n\treadonly kept?: boolean;\n}\n\n/** What the active branch records of one checkout: its latest snapshot, and the pin of a partial restore, if any. */\ninterface CheckoutRecord {\n\t/** The latest snapshot recorded of the checkout: what its worktree holds. */\n\treadonly latest: string;\n\treadonly pin?: DegradedRestorePin;\n}\n\nfunction isLapsed(since: string, now: number): boolean {\n\tconst started = Date.parse(since);\n\t// A time that cannot be read never ends the pin: keeping the snapshot is the safe side.\n\treturn Number.isFinite(started) && now - started > DEGRADED_RESTORE_RETENTION_MS;\n}\n\n/**\n * What the active branch records of each checkout, keyed by the root it was first recorded under. A restore with less\n * than its snapshot pins the snapshot (#4922); entries naming it in `degradedFrom` keep the pin, and any other entry\n * of the checkout ends it.\n */\nfunction* checkoutRecords(\n\tsessionManager: Pick<SessionManager, \"getBranch\">,\n\tmappings: readonly WorktreeRootMapping[],\n\tnow = Date.now(),\n): CanonicalSteps<Map<string, CheckoutRecord>> {\n\tconst checkouts = new Map<string, CheckoutRecord>();\n\tconst originals = new Map<string, string>();\n\tfor (const entry of sessionManager.getBranch()) {\n\t\tif (entry.type !== \"worktree_snapshot\") continue;\n\t\tconst original = originals.get(entry.root) ?? (yield* originalRoot(entry.root, mappings));\n\t\toriginals.set(entry.root, original);\n\t\tconst previous = checkouts.get(original)?.pin;\n\t\tlet pin: DegradedRestorePin | undefined;\n\t\tconst carried = entry.restore?.degradedWork;\n\t\tif (\n\t\t\tentry.degradedFrom !== undefined &&\n\t\t\tcarried?.snapshotId === entry.degradedFrom &&\n\t\t\tcarried.outcome !== \"unavailable\"\n\t\t) {\n\t\t\t// A full restore that carried the work over keeps that work until the merged worktree is recorded (#5009).\n\t\t\tpin = {\n\t\t\t\tsnapshotId: entry.snapshotId,\n\t\t\t\tsince: entry.timestamp,\n\t\t\t\tbase: previous?.base,\n\t\t\t\tlapsed: isLapsed(entry.timestamp, now),\n\t\t\t\twork: entry.degradedFrom,\n\t\t\t\t...(carried.outcome === \"kept\" ? { kept: true } : {}),\n\t\t\t};\n\t\t} else if (entry.degradedFrom !== undefined) {\n\t\t\tpin =\n\t\t\t\tprevious?.snapshotId === entry.degradedFrom || (previous?.kept && previous.work === entry.degradedFrom)\n\t\t\t\t\t? previous\n\t\t\t\t\t: { snapshotId: entry.degradedFrom, since: entry.timestamp, lapsed: isLapsed(entry.timestamp, now) };\n\t\t} else if (entry.restore?.degraded) {\n\t\t\tconst { degraded, restoredAt } = entry.restore;\n\t\t\tpin = {\n\t\t\t\tsnapshotId: entry.snapshotId,\n\t\t\t\tsince: restoredAt,\n\t\t\t\tbase: { head: degraded.head, tree: degraded.tree },\n\t\t\t\tlapsed: isLapsed(restoredAt, now),\n\t\t\t};\n\t\t}\n\t\tcheckouts.set(original, { latest: entry.snapshotId, ...(pin === undefined ? {} : { pin }) });\n\t}\n\treturn checkouts;\n}\n\n/** The snapshot a resume restores for `checkout`: the pinned one while its pin stands, else the latest (#4922). */\nfunction restoreTargetId(checkout: CheckoutRecord): string {\n\treturn checkout.pin !== undefined && !checkout.pin.lapsed && !checkout.pin.kept\n\t\t? checkout.pin.snapshotId\n\t\t: checkout.latest;\n}\n\n/**\n * The snapshot a capture of the checkout pinned by `pin` names in `degradedFrom`, given that it records `snapshotId`:\n * the snapshot a partial restore lacks, or kept conflicting work (#5009); none once a capture records the merged\n * worktree of a full restore that carried the work over, which ends the pin.\n */\nfunction captureDegradedFrom(pin: DegradedRestorePin | undefined, snapshotId: string): string | undefined {\n\tconst named =\n\t\tpin === undefined ? undefined : pin.work === undefined ? pin.snapshotId : pin.kept ? pin.work : undefined;\n\treturn named === snapshotId ? undefined : named;\n}\n\n/**\n * Records again the checkouts whose full restore carried the work of a partly restored worktree over but whose merged\n * worktree a capture has not recorded yet (#5009), where that worktree is still here holding the restored snapshot's\n * commit; a worktree that is not here fails its capture, which changes nothing. Recording it ends the pin. A checkout that cannot be recorded keeps its pin; the reason goes to the debug log.\n */\nexport async function recordPendingCarriedWork(\n\tsessionManager: SessionManager,\n\toptions: { readonly settings: WorktreeSnapshotSettings; readonly storeDir: string; readonly signal?: AbortSignal },\n): Promise<void> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tfor (const [original, checkout] of await runCanonicalStepsAsync(checkoutRecords(sessionManager, mappings))) {\n\t\tconst pin = checkout.pin;\n\t\tif (pin?.work === undefined || pin.kept || pin.lapsed) continue;\n\t\tconst root = await mapRestoredPathAsync(original, mappings);\n\t\tif (await pooledWorktreeOwnedElsewhere(options.storeDir, root, sessionManager.getSessionId())) continue;\n\t\tawait recordCarriedWork(sessionManager, root, records.get(pin.snapshotId)?.head, options);\n\t}\n}\n\n/**\n * The pin of the checkout recorded at `root` while it stands (#4922): the snapshot a resume restored only partly, which\n * stays the checkout's restore target. Undefined when the checkout holds what its latest snapshot records.\n */\nexport function degradedRestorePin(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n\troot: string,\n): DegradedRestorePin | undefined {\n\treturn runCanonicalSteps(pinOf(sessionManager, root));\n}\n\nfunction degradedRestorePinAsync(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n\troot: string,\n): Promise<DegradedRestorePin | undefined> {\n\treturn runCanonicalStepsAsync(pinOf(sessionManager, root));\n}\n\nfunction* pinOf(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n\troot: string,\n): CanonicalSteps<DegradedRestorePin | undefined> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst checkouts = yield* checkoutRecords(sessionManager, mappings);\n\tconst pin = checkouts.get(yield* originalRoot(root, mappings))?.pin;\n\treturn pin !== undefined && !pin.lapsed ? pin : undefined;\n}\n\n/**\n * The id of the snapshot a resume restores for each checkout on the active branch, keyed by the root it was first\n * recorded under: its latest, or the snapshot a resume restored only partly while that pin stands (#4922).\n */\nfunction* latestSnapshotIdsByCheckout(\n\tsessionManager: Pick<SessionManager, \"getBranch\">,\n\tmappings: readonly WorktreeRootMapping[],\n): CanonicalSteps<Map<string, string>> {\n\tconst latestIds = new Map<string, string>();\n\tfor (const [original, checkout] of yield* checkoutRecords(sessionManager, mappings)) {\n\t\tlatestIds.set(original, restoreTargetId(checkout));\n\t}\n\treturn latestIds;\n}\n\n/**\n * The snapshot a resume restores for each root the active branch last recorded a snapshot under, keyed as\n * `getLatestWorktreeSnapshots` keys them: the latest, or the snapshot a resume restored only partly while that pin\n * stands (#4922). A pinned snapshot whose record is missing leaves the latest in its place.\n */\nexport function latestRestoreTargets(\n\tsessionManager: Pick<\n\t\tSessionManager,\n\t\t\"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\" | \"getLatestWorktreeSnapshots\"\n\t>,\n): Promise<Map<string, WorktreeSnapshot>> {\n\treturn runCanonicalStepsAsync(restoreTargets(sessionManager));\n}\n\nfunction* restoreTargets(\n\tsessionManager: Pick<\n\t\tSessionManager,\n\t\t\"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\" | \"getLatestWorktreeSnapshots\"\n\t>,\n): CanonicalSteps<Map<string, WorktreeSnapshot>> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst checkouts = yield* checkoutRecords(sessionManager, mappings);\n\tconst targets = new Map<string, WorktreeSnapshot>();\n\tfor (const [root, snapshot] of sessionManager.getLatestWorktreeSnapshots()) {\n\t\tconst checkout = checkouts.get(yield* originalRoot(root, mappings));\n\t\tconst target = checkout === undefined ? undefined : records.get(restoreTargetId(checkout));\n\t\ttargets.set(root, target ?? snapshot);\n\t}\n\treturn targets;\n}\n\nexport interface DiscardDegradedRestoreOptions {\n\treadonly settings: WorktreeSnapshotSettings;\n\t/** The partly restored worktree to release, where the session works in it now. Default: every one the session has. */\n\treadonly root?: string;\n\treadonly signal?: AbortSignal;\n}\n\n/**\n * Gives up on the snapshots a resume could restore only partly (#4922): records each partly restored worktree as it is\n * now, as a turn's capture would, without naming the snapshot it lacks, so that worktree's state becomes the\n * checkout's restore target and collection releases the snapshot it lacked. Resolves with the roots it recorded.\n * Rejects with `blob-store-unsupported` when the session's storage holds no snapshot content, and with the reason a\n * worktree could not be captured.\n */\nexport async function discardDegradedRestore(\n\tsessionManager: SessionManager,\n\toptions: DiscardDegradedRestoreOptions,\n): Promise<string[]> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst released: string[] = [];\n\tfor (const [original, checkout] of await runCanonicalStepsAsync(checkoutRecords(sessionManager, mappings))) {\n\t\tif (checkout.pin === undefined) continue;\n\t\tconst root = await mapRestoredPathAsync(original, mappings);\n\t\tif (\n\t\t\toptions.root !== undefined &&\n\t\t\t(await canonicalizeWorktreePathAsync(root)) !== (await canonicalizeWorktreePathAsync(options.root))\n\t\t)\n\t\t\tcontinue;\n\t\tconst store = sessionManager.getSessionStore();\n\t\tif (store.snapshotBlobs === undefined)\n\t\t\tthrow new WorkspaceSnapshotError(\"blob-store-unsupported\", store.descriptor.adapter);\n\t\tconst blobs = store.snapshotBlobs;\n\t\tconst previous = sessionManager.getLatestWorktreeSnapshots().get(root);\n\t\tlet recorded = false;\n\t\tawait recordWorktreeCapture(\n\t\t\tblobs,\n\t\t\t() => captureWorktreeSnapshot(root, { settings: options.settings, previous, blobs, signal: options.signal }),\n\t\t\tasync (result) => {\n\t\t\t\tif (result.status === \"unavailable\") throw result.reason;\n\t\t\t\tif (result.status === \"disabled\") return;\n\t\t\t\tawait sessionManager.appendWorktreeSnapshot(\n\t\t\t\t\troot,\n\t\t\t\t\tresult.snapshot.id,\n\t\t\t\t\tresult.status === \"captured\" ? result.snapshot : undefined,\n\t\t\t\t);\n\t\t\t\trecorded = true;\n\t\t\t},\n\t\t);\n\t\tif (recorded) released.push(root);\n\t}\n\treturn released;\n}\n\n/**\n * The checkouts whose partial restore has been pinned for longer than {@link DEGRADED_RESTORE_RETENTION_DAYS} and\n * that the session has not recorded since (#4922), where they are now: their pinned snapshot is no longer the restore\n * target, and collection no longer keeps it.\n */\nexport function lapsedDegradedRestores(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n): Promise<{ readonly root: string; readonly pin: DegradedRestorePin; readonly latest: string }[]> {\n\treturn runCanonicalStepsAsync(lapsedRestores(sessionManager));\n}\n\nfunction* lapsedRestores(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n): CanonicalSteps<{ readonly root: string; readonly pin: DegradedRestorePin; readonly latest: string }[]> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst lapsed: { readonly root: string; readonly pin: DegradedRestorePin; readonly latest: string }[] = [];\n\tfor (const [original, checkout] of yield* checkoutRecords(sessionManager, mappings)) {\n\t\tif (checkout.pin?.lapsed && checkout.pin.work === undefined && checkout.pin.snapshotId !== checkout.latest)\n\t\t\tlapsed.push({ root: yield* restoredPath(original, mappings), pin: checkout.pin, latest: checkout.latest });\n\t}\n\treturn lapsed;\n}\n\n/** The checkouts on the active branch whose latest snapshot the session holds no record of, where they are now (#4733). */\nexport function missingSnapshotRecords(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\">,\n): Promise<MissingSnapshotRecord[]> {\n\treturn runCanonicalStepsAsync(missingRecordsOf(sessionManager));\n}\n\nfunction* missingRecordsOf(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\">,\n): CanonicalSteps<MissingSnapshotRecord[]> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst missing: MissingSnapshotRecord[] = [];\n\tfor (const [original, snapshotId] of yield* latestSnapshotIdsByCheckout(sessionManager, mappings)) {\n\t\tif (!records.has(snapshotId)) missing.push({ root: yield* restoredPath(original, mappings), snapshotId });\n\t}\n\treturn missing;\n}\n\n/**\n * The latest snapshot of each checkout on the active branch, keyed by where that checkout is now: a checkout restored\n * elsewhere appears once, under its newest location. A snapshot whose record is missing is left out.\n */\nexport function currentWorktreeSnapshots(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\">,\n): Promise<Map<string, WorktreeSnapshot>> {\n\treturn runCanonicalStepsAsync(currentSnapshots(sessionManager));\n}\n\nfunction* currentSnapshots(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\" | \"getWorktreeSnapshotRecords\">,\n): CanonicalSteps<Map<string, WorktreeSnapshot>> {\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst current = new Map<string, WorktreeSnapshot>();\n\tfor (const [original, snapshotId] of yield* latestSnapshotIdsByCheckout(sessionManager, mappings)) {\n\t\tconst snapshot = records.get(snapshotId);\n\t\tif (snapshot) current.set(yield* restoredPath(original, mappings), snapshot);\n\t}\n\treturn current;\n}\n\n/** A checkout a resume continued without, because nothing of its snapshot could be restored here (#4733). */\nexport interface UnrestoredWorktree {\n\treadonly root: string;\n\treadonly snapshot: WorktreeSnapshot;\n\t/** Why: the restore error, or Git being unavailable. */\n\treadonly reason: Error;\n\t/** The record the resume wrote for it in the session. */\n\treadonly record: WorktreeUnrestored;\n}\n\n/** A checkout whose latest snapshot the session refers to without holding its record (#4733). */\nexport interface MissingSnapshotRecord {\n\treadonly root: string;\n\treadonly snapshotId: string;\n}\n\nexport type SessionWorktreeResume =\n\t| { readonly status: \"none\"; readonly missingRecords?: readonly MissingSnapshotRecord[] }\n\t| {\n\t\t\treadonly status: \"verified\";\n\t\t\treadonly snapshot: WorktreeSnapshot;\n\t\t\treadonly cwd: string;\n\t\t\treadonly unrestored: readonly UnrestoredWorktree[];\n\t\t\treadonly missingRecords?: readonly MissingSnapshotRecord[];\n\t }\n\t| {\n\t\t\treadonly status: \"restored\";\n\t\t\treadonly snapshot: WorktreeSnapshot;\n\t\t\treadonly mappings: readonly WorktreeRootMapping[];\n\t\t\treadonly cwd: string;\n\t\t\treadonly warnings: readonly WorktreeRestoreWarning[];\n\t\t\treadonly unrestored: readonly UnrestoredWorktree[];\n\t\t\treadonly missingRecords?: readonly MissingSnapshotRecord[];\n\t };\n\nexport interface ResumeSessionWorktreeOptions {\n\treadonly settings: WorktreeSnapshotSettings;\n\t/** Host directory for shared object stores and restored worktrees. Default ~/.atomic/agent/worktree-snapshots. */\n\treadonly storeDir?: string;\n\treadonly signal?: AbortSignal;\n\t/**\n\t * Called with the new mappings, none when nothing needed restoring, once every checkout is restored and before any\n\t * of them is recorded. When it throws, nothing is recorded and the restored worktrees are removed, as for a failed\n\t * restore.\n\t */\n\treadonly beforeRecord?: (mappings: readonly WorktreeRootMapping[]) => Promise<void>;\n\t/**\n\t * Where the exact fresh restore of a checkout hands its Git LFS download instead of running it (#5099); see\n\t * `RestoreWorktreeSnapshotOptions.deferLfs`. Its `lfs-objects-unavailable` warning is then not recorded with the\n\t * restore. A claimed or degraded restore, and one that carries over work, still downloads before it returns.\n\t */\n\treadonly deferLfs?: RestoreWorktreeSnapshotOptions[\"deferLfs\"];\n\t/**\n\t * Mappings to checkouts already here that the session continues in, applied as if recorded while deciding what to\n\t * restore, and recorded first, with the restores, only once every checkout is restored and `beforeRecord` passed.\n\t */\n\treadonly pendingMappings?: readonly WorktreeRootMapping[];\n\t/** Checkouts, by the root the session's restores put them at, to continue in as they are without verifying them. */\n\treadonly keepInPlace?: ReadonlySet<string>;\n\t/**\n\t * Checkouts, by the same roots, that cannot be restored on this host, with the reason, such as Git being\n\t * unavailable: the resume continues without them, as for a restore that gives nothing (#4733).\n\t */\n\treadonly cannotRestore?: ReadonlyMap<string, Error>;\n\t/**\n\t * Where the session continues when the checkout it works in is not restored and its working directory is not on\n\t * this host: the directory the resume started from. Default: the recorded working directory.\n\t */\n\treadonly fallbackCwd?: string;\n\t/**\n\t * Continue without a checkout whose latest snapshot the session holds no record of, listing it in `missingRecords`,\n\t * instead of failing with `snapshot-not-found` before anything is restored (#4733).\n\t */\n\treadonly skipMissingRecords?: boolean;\n\t/**\n\t * Restore into pooled slots at stable paths, leased by this session until it closes (#4748), keeping at most\n\t * `maxIdlePerRepository` idle slots of each repository restored into. A restore first claims an idle slot of the\n\t * repository that holds only its recorded state, reset to the snapshot with its ignored files kept, and restores\n\t * into a new slot when none can be claimed. A recorded checkout in a slot another session owns is restored the same\n\t * way. The session holds the pooled worktrees it owns, compared or restored, until it closes. Without it, restores go\n\t * to new paths outside the pool, as for workflow runs.\n\t */\n\treadonly pool?: { readonly maxIdlePerRepository: number };\n}\n\n/**\n * The commits of every earlier snapshot of the checkout on the branch, newest first and each once, to restore when its\n * own is out of reach (#4744). The restore stops at the first it holds or fetches, so a nearer one costs no more.\n */\nfunction* earlierSnapshotHeads(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeSnapshotRecords\">,\n\toriginal: string,\n\tmappings: readonly WorktreeRootMapping[],\n\tsnapshot: WorktreeSnapshot,\n): CanonicalSteps<string[]> {\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst heads: string[] = [];\n\tfor (const entry of [...sessionManager.getBranch()].reverse()) {\n\t\tif (entry.type !== \"worktree_snapshot\" || (yield* originalRoot(entry.root, mappings)) !== original) continue;\n\t\tconst head = records.get(entry.snapshotId)?.head;\n\t\tif (head !== undefined && head !== snapshot.head) heads.push(head);\n\t}\n\treturn [...new Set(heads)];\n}\n\n/**\n * Checks the latest recorded snapshot of each checkout on the active session branch. Drifted or missing checkouts are\n * restored into fresh worktrees, and each old→new mapping is recorded only after all checkouts have been restored.\n * The returned cwd follows those mappings. A HEAD-only advance over identical content also resumes in place.\n */\nexport async function resumeSessionWorktree(\n\tsessionManager: SessionManager,\n\toptions: ResumeSessionWorktreeOptions,\n): Promise<SessionWorktreeResume> {\n\tif (!options.settings.enabled) return { status: \"none\" };\n\tconst storeDir = resolve(options.storeDir ?? defaultWorktreeSnapshotStoreDir());\n\t// The session holds the pooled slots it owns before comparing them, so no claim resets one it continues in (#4748).\n\tif (options.pool) await holdSessionWorktrees(sessionManager, sessionManager, storeDir, options.signal);\n\tconst pending = options.pendingMappings ?? [];\n\tconst existing = [...sessionManager.getWorktreeRootMappings(), ...pending];\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst checkouts = await runCanonicalStepsAsync(checkoutRecords(sessionManager, existing));\n\tconst latestIds = await runCanonicalStepsAsync(latestSnapshotIdsByCheckout(sessionManager, existing));\n\tconst latest = new Map<string, WorktreeSnapshot>();\n\t// The work done in a partly restored worktree of the pinned snapshot `snapshot`, which this resume restores when\n\t// `snapshot` cannot be, and puts on top of it when it can (#4922).\n\tconst pinnedWork = (original: string, snapshot: WorktreeSnapshot) => {\n\t\tconst checkout = checkouts.get(original)!;\n\t\tconst pin = checkout.pin;\n\t\tif (pin === undefined || pin.lapsed || pin.snapshotId !== snapshot.id) return undefined;\n\t\t// After a full restore whose merged worktree is not recorded yet, the work it carried over (#5009).\n\t\tconst workId = pin.work ?? checkout.latest;\n\t\tif (workId === snapshot.id) return undefined;\n\t\tconst work = records.get(workId);\n\t\treturn work === undefined ? undefined : { pin, work };\n\t};\n\tconst missingRecords: MissingSnapshotRecord[] = [];\n\tfor (const [root, snapshotId] of latestIds) {\n\t\tconst snapshot = records.get(snapshotId);\n\t\tif (!snapshot && options.skipMissingRecords) {\n\t\t\tmissingRecords.push({ root: await mapRestoredPathAsync(root, existing), snapshotId });\n\t\t\tcontinue;\n\t\t}\n\t\tif (!snapshot) throw new WorkspaceRestoreError(\"snapshot-not-found\", { snapshotId, target: root });\n\t\tlatest.set(root, snapshot);\n\t}\n\tif (latest.size === 0) return missingRecords.length === 0 ? { status: \"none\" } : { status: \"none\", missingRecords };\n\tconst cwd = await mapRestoredPathAsync(sessionManager.getCwd(), existing);\n\tconst mappings: WorktreeRootMapping[] = [];\n\tconst warnings: WorktreeRestoreWarning[] = [];\n\tconst hostWarnings = new Map<WorktreeRootMapping, WorktreeRestoreHostWarning[]>();\n\tconst reportedLeftovers = new Set<string>();\n\tconst left: { root: string; snapshot: WorktreeSnapshot; reason: Error; degradedFrom?: string }[] = [];\n\tconst pinnedTo = new Map<WorktreeRootMapping, string | undefined>();\n\tconst unrestored: UnrestoredWorktree[] = [];\n\tlet continuedIn: string;\n\tlet selected: { root: string; snapshot: WorktreeSnapshot } | undefined;\n\tconst owner = sessionOwner(sessionManager);\n\tconst leases = new Map<WorktreeRootMapping, WorktreeLease>();\n\tconst admitted = new Set<RepositoryId>();\n\ttry {\n\t\tfor (const [original, snapshot] of latest) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tconst root = await mapRestoredPathAsync(original, existing);\n\t\t\tif ((await runCanonicalStepsAsync(isInside(root, cwd))) && (!selected || root.length > selected.root.length))\n\t\t\t\tselected = { root, snapshot };\n\t\t\tif (options.keepInPlace?.has(root)) continue;\n\t\t\tconst pinned = pinnedWork(original, snapshot);\n\t\t\t// Conflicting work a full restore kept apart stays kept, whatever the checkout is restored from (#5009).\n\t\t\tconst pin = checkouts.get(original)!.pin;\n\t\t\tconst keptWork = pin?.kept && !pin.lapsed && pin.work !== snapshot.id ? pin.work : undefined;\n\t\t\t// A pinned checkout left unrestored keeps its pin and the work done in its partly restored worktree (#4922).\n\t\t\tconst leave = (reason: Error) =>\n\t\t\t\tleft.push(\n\t\t\t\t\tpinned === undefined\n\t\t\t\t\t\t? { root, snapshot, reason, ...(keptWork === undefined ? {} : { degradedFrom: keptWork }) }\n\t\t\t\t\t\t: { root, snapshot: pinned.work, reason, degradedFrom: snapshot.id },\n\t\t\t\t);\n\t\t\tconst cannot = options.cannotRestore?.get(root);\n\t\t\tif (cannot !== undefined) {\n\t\t\t\tleave(cannot);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst gone = (cause?: Error) =>\n\t\t\t\tnew WorkspaceDriftError(\n\t\t\t\t\t{\n\t\t\t\t\t\troot,\n\t\t\t\t\t\texpectedHead: snapshot.head,\n\t\t\t\t\t\tactualHead: null,\n\t\t\t\t\t\texpectedTree: snapshot.tree,\n\t\t\t\t\t\tactualTree: null,\n\t\t\t\t\t\tsnapshotId: snapshot.id,\n\t\t\t\t\t},\n\t\t\t\t\tcause,\n\t\t\t\t);\n\t\t\tlet drift: WorkspaceDriftError;\n\t\t\t// A slot another session owns holds its work, not this one's: restore fresh, as if it were gone (#4748).\n\t\t\tif (options.pool && (await pooledWorktreeOwnedElsewhere(storeDir, root, owner.id))) drift = gone();\n\t\t\telse {\n\t\t\t\ttry {\n\t\t\t\t\tawait verifyWorktree(snapshot, root, { settings: options.settings, signal: options.signal });\n\t\t\t\t\tcontinue;\n\t\t\t\t} catch (error) {\n\t\t\t\t\toptions.signal?.throwIfAborted();\n\t\t\t\t\tif (isWorkspaceDriftError(error)) {\n\t\t\t\t\t\tif (await isHeadOnlyAdvance(error, options.signal)) continue;\n\t\t\t\t\t\tdrift = error;\n\t\t\t\t\t} else if (isWorkspaceSnapshotError(error)) drift = gone(error);\n\t\t\t\t\telse throw error;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst refused = (error: Error) =>\n\t\t\t\tnew WorkspaceDriftError(\n\t\t\t\t\t{\n\t\t\t\t\t\troot: drift.root,\n\t\t\t\t\t\texpectedHead: drift.expectedHead,\n\t\t\t\t\t\tactualHead: drift.actualHead,\n\t\t\t\t\t\texpectedTree: drift.expectedTree,\n\t\t\t\t\t\tactualTree: drift.actualTree,\n\t\t\t\t\t\tsnapshotId: drift.snapshotId,\n\t\t\t\t\t\treason: \"restore-failed\",\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\tconst blobs = sessionSnapshotBlobs(\n\t\t\t\tsessionManager.getSessionStore().snapshotBlobs,\n\t\t\t\tsessionManager.getEntries(),\n\t\t\t);\n\t\t\tlet restored: Extract<BestWorktreeRestore, { status: \"restored\" }>;\n\t\t\tlet lease: WorktreeLease | undefined;\n\t\t\tlet claimed = false;\n\t\t\tlet seeded = false;\n\t\t\t// The snapshot the worktree holds: the one restored, or the work done since its partial restore (#4922).\n\t\t\tlet restoredFrom = snapshot;\n\t\t\t// The exact state, else the best this host can restore, else continue without the checkout.\n\t\t\tconst restoreFresh = async (slot: WorktreeLease | undefined) => {\n\t\t\t\tconst ladder: RestoreBestWorktreeOptions = {\n\t\t\t\t\tblobs,\n\t\t\t\t\tstoreDir: options.storeDir,\n\t\t\t\t\tsignal: options.signal,\n\t\t\t\t\tcandidates: await runCanonicalStepsAsync(\n\t\t\t\t\t\tearlierSnapshotHeads(sessionManager, original, existing, snapshot),\n\t\t\t\t\t),\n\t\t\t\t\t// Carrying work over writes into the worktree, so a pinned restore downloads first.\n\t\t\t\t\t...(pinned === undefined ? { deferLfs: options.deferLfs } : {}),\n\t\t\t\t\t...(slot === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\trestore: (target, restoreOptions) => restoreWorktreeAt(target, slot.path, restoreOptions),\n\t\t\t\t\t\t\t\trestoreDegraded: (degraded, failure, restoreOptions) =>\n\t\t\t\t\t\t\t\t\trestoreDegradedWorktreeAt(degraded, failure, slot.path, restoreOptions),\n\t\t\t\t\t\t\t}),\n\t\t\t\t};\n\t\t\t\tif (pinned === undefined) return restoreBestWorktree(snapshot, ladder);\n\t\t\t\treturn restorePinnedWorktree(snapshot, pinned.work, ladder, (work) => {\n\t\t\t\t\trestoredFrom = work;\n\t\t\t\t});\n\t\t\t};\n\t\t\ttry {\n\t\t\t\tconst best = await timeCheckoutRestore(\n\t\t\t\t\troot,\n\t\t\t\t\tasync (): Promise<BestWorktreeRestore> => {\n\t\t\t\t\t\tif (!options.pool) return restoreFresh(undefined);\n\t\t\t\t\t\t// An idle slot of the repository keeps its dependencies and build output; else a new slot (#4748).\n\t\t\t\t\t\tconst claimOptions = { storeDir, owner, settings: options.settings, blobs, signal: options.signal };\n\t\t\t\t\t\tlet claim = await claimIdleWorktree(snapshot, claimOptions);\n\t\t\t\t\t\t// Without one, prebuilt build output parked as a seed becomes an idle slot to claim (#4748).\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!claim.claimed &&\n\t\t\t\t\t\t\t(await adoptPrebuiltSeed(snapshot, { storeDir, signal: options.signal })).adopted\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tclaim = await claimIdleWorktree(snapshot, claimOptions);\n\t\t\t\t\t\t\tseeded = claim.claimed;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (claim.claimed) {\n\t\t\t\t\t\t\tlease = claim.lease;\n\t\t\t\t\t\t\tclaimed = true;\n\t\t\t\t\t\t\treturn { status: \"restored\", path: claim.lease.path, warnings: claim.warnings };\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlease = await admitSlot(storeDir, snapshot, owner, options.signal);\n\t\t\t\t\t\treturn restoreFresh(lease);\n\t\t\t\t\t},\n\t\t\t\t\t(outcome) =>\n\t\t\t\t\t\toutcome.status === \"unrestored\"\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: seeded\n\t\t\t\t\t\t\t\t? \"seeded\"\n\t\t\t\t\t\t\t\t: claimed\n\t\t\t\t\t\t\t\t\t? \"claimed\"\n\t\t\t\t\t\t\t\t\t: outcome.degraded === undefined\n\t\t\t\t\t\t\t\t\t\t? \"fresh\"\n\t\t\t\t\t\t\t\t\t\t: \"degraded\",\n\t\t\t\t);\n\t\t\t\tif (best.status === \"unrestored\") {\n\t\t\t\t\tif (lease) await discardPooledWorktree(lease);\n\t\t\t\t\tleave(best.reason);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\trestored = best;\n\t\t\t} catch (error) {\n\t\t\t\tif (lease) await discardPooledWorktree(lease).catch(() => {});\n\t\t\t\toptions.signal?.throwIfAborted();\n\t\t\t\tif (!(error instanceof Error)) throw error;\n\t\t\t\tthrow refused(error);\n\t\t\t}\n\t\t\t// A full restore of a pinned snapshot carries the work done in its partly restored worktree over (#4922).\n\t\t\tconst degradedWork =\n\t\t\t\tpinned !== undefined &&\n\t\t\t\trestoredFrom === snapshot &&\n\t\t\t\trestored.degraded === undefined &&\n\t\t\t\tpinned.work.tree !== pinned.pin.base?.tree\n\t\t\t\t\t? await carryOverDegradedWork({\n\t\t\t\t\t\t\tworktree: restored.path,\n\t\t\t\t\t\t\twork: pinned.work,\n\t\t\t\t\t\t\tbase: pinned.pin.base?.tree,\n\t\t\t\t\t\t\tblobs,\n\t\t\t\t\t\t\tstoreDir,\n\t\t\t\t\t\t\tsignal: options.signal,\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined;\n\t\t\tconst mapping: WorktreeRootMapping = {\n\t\t\t\tfrom: root,\n\t\t\t\tto: restored.path,\n\t\t\t\tsnapshotId: restoredFrom.id,\n\t\t\t\ttree: restoredFrom.tree,\n\t\t\t\trestoredAt: new Date().toISOString(),\n\t\t\t\t...(restored.degraded === undefined ? {} : { degraded: restored.degraded }),\n\t\t\t\t...(degradedWork === undefined ? {} : { degradedWork }),\n\t\t\t};\n\t\t\tmappings.push(mapping);\n\t\t\tpinnedTo.set(mapping, restoredFrom !== snapshot ? snapshot.id : keptWork);\n\t\t\tif (lease) {\n\t\t\t\tleases.set(mapping, lease);\n\t\t\t\tadmitted.add(lease.repository);\n\t\t\t\tif (restored.degraded !== undefined || restoredFrom !== snapshot) {\n\t\t\t\t\tawait recordPooledWorktreeState(lease, {\n\t\t\t\t\t\tsnapshotId: restoredFrom.id,\n\t\t\t\t\t\thead: restored.degraded?.head ?? restoredFrom.head,\n\t\t\t\t\t\ttree: restored.degraded?.tree ?? restoredFrom.tree,\n\t\t\t\t\t}).catch((error: unknown) =>\n\t\t\t\t\t\treportDebug(\"storage\", \"worktree-pool-state-failed\", failureDebugFields(error)),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\twarnings.push(...restored.warnings);\n\t\t\thostWarnings.set(\n\t\t\t\tmapping,\n\t\t\t\trestored.warnings.filter((warning): warning is WorktreeRestoreHostWarning => {\n\t\t\t\t\tif (warning.code === \"lfs-objects-unavailable\") return true;\n\t\t\t\t\tif (warning.code !== \"stale-restore-retained\" || reportedLeftovers.has(warning.path)) return false;\n\t\t\t\t\treportedLeftovers.add(warning.path);\n\t\t\t\t\treturn true;\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tawait options.beforeRecord?.(mappings);\n\t\tfor (const mapping of [...pending, ...mappings]) {\n\t\t\toptions.signal?.throwIfAborted();\n\t\t\tawait sessionManager.appendWorktreeSnapshot(\n\t\t\t\tmapping.to,\n\t\t\t\tmapping.snapshotId,\n\t\t\t\tundefined,\n\t\t\t\tmapping,\n\t\t\t\thostWarnings.get(mapping),\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t// Work carried over stays kept until the merged worktree is recorded, or released when it conflicted (#5009).\n\t\t\t\tpinnedTo.get(mapping) ??\n\t\t\t\t\t(mapping.degradedWork === undefined || mapping.degradedWork.outcome === \"unavailable\"\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: mapping.degradedWork.snapshotId),\n\t\t\t);\n\t\t\tif (mapping.degradedWork?.outcome === \"applied\") {\n\t\t\t\tawait recordCarriedWork(sessionManager, mapping.to, records.get(mapping.snapshotId)!.head, options);\n\t\t\t}\n\t\t}\n\t\tconst continuing = await mapRestoredPathAsync(cwd, mappings);\n\t\tconst recordedHere = selected !== undefined && left.some((checkout) => checkout.root === selected!.root);\n\t\tconst launch =\n\t\t\trecordedHere &&\n\t\t\toptions.fallbackCwd !== undefined &&\n\t\t\t(!(await access(continuing).then(\n\t\t\t\t() => true,\n\t\t\t\t() => false,\n\t\t\t)) ||\n\t\t\t\t(await pooledWorktreeOwnedElsewhere(storeDir, selected!.root, owner.id)));\n\t\tcontinuedIn = launch ? resolve(options.fallbackCwd!) : continuing;\n\t\tfor (const checkout of left) {\n\t\t\tconst record = unrestoredRecord(\n\t\t\t\tcheckout.snapshot,\n\t\t\t\tcheckout.reason,\n\t\t\t\tcontinuedIn,\n\t\t\t\tlaunch ? \"launch\" : \"recorded\",\n\t\t\t\tundefined,\n\t\t\t\tlaunch && checkout.root === selected?.root ? continuing : undefined,\n\t\t\t);\n\t\t\tawait sessionManager.appendWorktreeSnapshot(\n\t\t\t\tcheckout.root,\n\t\t\t\tcheckout.snapshot.id,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\t[],\n\t\t\t\trecord,\n\t\t\t\tundefined,\n\t\t\t\tcheckout.degradedFrom,\n\t\t\t);\n\t\t\tunrestored.push({ ...checkout, record });\n\t\t}\n\t} catch (error) {\n\t\tconst cleanupFailures: unknown[] = [];\n\t\tfor (const mapping of [...mappings].reverse()) {\n\t\t\ttry {\n\t\t\t\tawait removeRestoredWorktree(mapping.to, { storeDir: options.storeDir });\n\t\t\t} catch (cleanupCause) {\n\t\t\t\tcleanupFailures.push(cleanupCause);\n\t\t\t}\n\t\t\tconst lease = leases.get(mapping);\n\t\t\tif (lease) await discardPooledWorktree(lease).catch(() => {});\n\t\t}\n\t\tif (cleanupFailures.length > 0 && error instanceof Error && Object.isExtensible(error)) {\n\t\t\tObject.defineProperty(error, \"cleanupCause\", {\n\t\t\t\tvalue: cleanupFailures.length === 1 ? cleanupFailures[0] : new AggregateError(cleanupFailures),\n\t\t\t\tconfigurable: true,\n\t\t\t});\n\t\t}\n\t\tthrow error;\n\t}\n\tfor (const lease of leases.values()) holdFor(sessionManager, lease);\n\tif (options.pool) {\n\t\tfor (const repository of admitted) {\n\t\t\tawait evictIdleWorktrees(storeDir, repository, {\n\t\t\t\tmaxIdle: options.pool.maxIdlePerRepository,\n\t\t\t\tsettings: options.settings,\n\t\t\t\tsignal: options.signal,\n\t\t\t});\n\t\t}\n\t}\n\tconst snapshot = selected?.snapshot ?? [...latest.values()].at(-1)!;\n\tconst missing = missingRecords.length === 0 ? {} : { missingRecords };\n\treturn mappings.length === 0\n\t\t? { status: \"verified\", snapshot, cwd: continuedIn, unrestored, ...missing }\n\t\t: { status: \"restored\", snapshot, mappings, cwd: continuedIn, warnings, unrestored, ...missing };\n}\n\n/**\n * Restores a pinned `snapshot` (#4922): exactly, else `work`, the latest snapshot of its partly restored worktree, as\n * well as this host can, calling `restoredWork` when it does; else nothing, resolving `unrestored` with the exact\n * restore's failure. `work` shares `snapshot`'s remotes, so a commit a degraded restore of `snapshot` could fall back to\n * is one a degraded restore of `work` falls back to as well.\n */\nasync function restorePinnedWorktree(\n\tsnapshot: WorktreeSnapshot,\n\twork: WorktreeSnapshot,\n\toptions: RestoreBestWorktreeOptions,\n\trestoredWork: (work: WorktreeSnapshot) => void,\n): Promise<BestWorktreeRestore> {\n\tconst { restore = restoreWorktree, restoreDegraded: _degraded, candidates: _candidates, ...shared } = options;\n\ttry {\n\t\tconst exact = await restore(snapshot, shared);\n\t\treturn { status: \"restored\", path: exact.path, warnings: exact.warnings ?? [] };\n\t} catch (error) {\n\t\tif (options.signal?.aborted || !isRecoverableRestoreFailure(error)) throw error;\n\t\tconst best = await restoreBestWorktree(work, options);\n\t\tif (best.status === \"unrestored\") return { status: \"unrestored\", reason: error };\n\t\trestoredWork(work);\n\t\treturn best;\n\t}\n}\n\n/**\n * Records the restored worktree at `root` as it is once a restore carried the work of a partly restored worktree over\n * (#4922), so the session holds that work without waiting for a turn, which ends the pin. A worktree whose HEAD is no\n * longer `head` is left alone. A capture that fails keeps the pin, and with it the carried work, for the next turn's\n * capture or resume to record (#5009); the reason goes to the debug log.\n */\nasync function recordCarriedWork(\n\tsessionManager: SessionManager,\n\troot: string,\n\thead: string | undefined,\n\toptions: Pick<ResumeSessionWorktreeOptions, \"settings\" | \"signal\">,\n): Promise<void> {\n\tconst blobs = sessionManager.getSessionStore().snapshotBlobs;\n\tif (blobs === undefined) return;\n\ttry {\n\t\tawait recordWorktreeCapture(\n\t\t\tblobs,\n\t\t\t() => captureWorktreeSnapshot(root, { settings: options.settings, blobs, signal: options.signal }),\n\t\t\tasync (result) => {\n\t\t\t\t// Without a previous snapshot to compare with, a capture never resolves unchanged.\n\t\t\t\tif (result.status === \"captured\" && result.snapshot.head === head) {\n\t\t\t\t\tawait sessionManager.appendWorktreeSnapshot(root, result.snapshot.id, result.snapshot);\n\t\t\t\t} else if (result.status === \"unavailable\") {\n\t\t\t\t\treportDebug(\"storage\", \"degraded-work-capture-failed\", failureDebugFields(result.reason));\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t} catch (error) {\n\t\toptions.signal?.throwIfAborted();\n\t\tif (!isWorkspaceError(error) && !isGitUnavailableError(error)) throw error;\n\t\treportDebug(\"storage\", \"degraded-work-capture-failed\", failureDebugFields(error));\n\t}\n}\n\n/**\n * Takes a new pooled slot for a restore of `snapshot` (#4748). When the pool cannot be used, the restore goes to a new\n * path outside it, as before the pool: undefined, with the reason in the debug log.\n */\nasync function admitSlot(\n\tstoreDir: string,\n\tsnapshot: WorktreeSnapshot,\n\towner: PoolOwner,\n\tsignal?: AbortSignal,\n): Promise<WorktreeLease | undefined> {\n\ttry {\n\t\treturn await admitPooledWorktree(\n\t\t\t{\n\t\t\t\tstoreDir,\n\t\t\t\tremotes: snapshot.remotes,\n\t\t\t\troot: snapshot.root,\n\t\t\t\tlastState: { snapshotId: snapshot.id, head: snapshot.head, tree: snapshot.tree },\n\t\t\t\tenvHash: snapshot.envHash,\n\t\t\t\tsignal,\n\t\t\t},\n\t\t\towner,\n\t\t);\n\t} catch (error) {\n\t\tsignal?.throwIfAborted();\n\t\treportDebug(\"storage\", \"worktree-pool-admit-failed\", failureDebugFields(error));\n\t\treturn undefined;\n\t}\n}\n\n/** The one-line notice shown when a session or run continues in a restored worktree. */\nexport function formatWorktreeRestoreNotice(mapping: WorktreeRootMapping): string {\n\treturn `Restored worktree snapshot ${mapping.snapshotId.slice(0, 12)} of ${mapping.from} into ${mapping.to}`;\n}\n\n/** One line per restore warning, for the notices shown after a restore. */\nexport function formatWorktreeRestoreWarning(warning: WorktreeRestoreWarning): string {\n\tswitch (warning.code) {\n\t\tcase \"omitted-content\":\n\t\t\treturn `The restored snapshot left out ${warning.omitted.length} item(s): ${warning.omitted\n\t\t\t\t.map((omission) => (\"path\" in omission ? `${omission.path} (${omission.reason})` : omission.reason))\n\t\t\t\t.join(\", \")}`;\n\t\tcase \"filters\":\n\t\t\treturn `The source checkout used conversion settings (${[\n\t\t\t\twarning.filters.autocrlf === null ? undefined : `core.autocrlf=${warning.filters.autocrlf}`,\n\t\t\t\twarning.filters.eol === null ? undefined : `core.eol=${warning.filters.eol}`,\n\t\t\t\t...warning.filters.drivers.map((driver) => `filter=${driver}`),\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(\", \")}); the restore holds Git's stored content with LF line endings`;\n\t\tcase \"lfs-objects-unavailable\":\n\t\t\treturn `Git LFS objects could not be fetched; these files hold LFS pointers: ${warning.paths.join(\", \")}`;\n\t\tcase \"stale-restore-retained\":\n\t\t\tswitch (warning.kind) {\n\t\t\t\tcase \"worktree\":\n\t\t\t\t\treturn `A restore interrupted earlier left ${warning.path}, which may hold your files; check them, then delete the directory yourself`;\n\t\t\t\tcase \"record\":\n\t\t\t\t\treturn `A restore interrupted earlier left the crash record ${warning.path}, which cannot be read; delete the file`;\n\t\t\t\tcase \"records-directory\":\n\t\t\t\t\treturn `The restore crash records in ${warning.path} cannot be read; make the directory readable or remove it`;\n\t\t\t}\n\t}\n}\n\n/** The first 12 characters of a commit or snapshot id, as notices show them. */\nfunction short(id: string): string {\n\treturn id.slice(0, 12);\n}\n\n/** Whose checkout a restore notice is about: a session's, or a workflow run's (#4738). */\nexport type WorktreeRestoreOwner = \"session\" | \"workflow run\";\n\n/** What a degraded restore checked out, for its notice. */\nfunction degradedBasis(\n\tdegraded: WorktreeDegradedRestore,\n\tsnapshot: WorktreeSnapshot | undefined,\n\towner: WorktreeRestoreOwner,\n): string {\n\tswitch (degraded.basis) {\n\t\tcase \"pushed-base\":\n\t\t\treturn `the last pushed commit before it, ${short(degraded.head)}`;\n\t\tcase \"earlier-snapshot\":\n\t\t\treturn `${short(degraded.head)}, the commit of an earlier snapshot of this ${owner}`;\n\t\tdefault:\n\t\t\treturn `${short(degraded.head)}, the tip of ${snapshot?.branch ? `branch ${snapshot.branch}` : \"the default branch\"} on its remote`;\n\t}\n}\n\nfunction listed(items: readonly string[], limit = 5): string {\n\treturn items.length <= limit\n\t\t? items.join(\", \")\n\t\t: `${items.slice(0, limit).join(\", \")} and ${items.length - limit} more`;\n}\n\n/**\n * The one notice for a worktree restored with less than its snapshot (#4733): what it holds, what is missing and what\n * to do to get the rest.\n */\nexport function formatDegradedRestoreNotice(\n\tmapping: WorktreeRootMapping,\n\tsnapshot: WorktreeSnapshot | undefined,\n\twarnings: readonly WorktreeRestoreHostWarning[] = [],\n\towner: WorktreeRestoreOwner = \"session\",\n): string {\n\tconst lfs = warnings\n\t\t.filter((warning) => warning.code === \"lfs-objects-unavailable\")\n\t\t.map((warning) => ` ${formatWorktreeRestoreWarning(warning)}.`)\n\t\t.join(\"\");\n\treturn `${degradedRestoreSummary(mapping, snapshot, owner)}${lfs}`;\n}\n\nfunction degradedRestoreSummary(\n\tmapping: WorktreeRootMapping,\n\tsnapshot: WorktreeSnapshot | undefined,\n\towner: WorktreeRestoreOwner,\n): string {\n\tconst degraded = mapping.degraded!;\n\tconst links = snapshot?.chain.length ?? 0;\n\tconst restored = `Restored ${mapping.from} into ${mapping.to}`;\n\tconst missingPaths = degraded.missingPaths.length > 0 ? `: ${listed(degraded.missingPaths)}` : \"\";\n\tif (degraded.stage === \"partial-changes\") {\n\t\tconst missing =\n\t\t\tdegraded.missingLinks.length > 0\n\t\t\t\t? `change set${degraded.missingLinks.length === 1 ? \"\" : \"s\"} ${degraded.missingLinks.join(\", \")}${missingPaths}`\n\t\t\t\t: `the recorded content of ${listed(degraded.missingPaths)}, which differs on this machine`;\n\t\treturn `${restored} at its recorded commit ${short(degraded.head)} with ${links - degraded.missingLinks.length} of the ${links} change sets of snapshot ${short(mapping.snapshotId)}. Not restored: ${missing}. ${degraded.hint}`;\n\t}\n\tconst commits = degraded.missingCommits.length;\n\tconst recorded = snapshot === undefined ? \"\" : ` instead of the recorded commit ${short(snapshot.head)}`;\n\tconst changes = degraded.missingLinks.length > 0 ? \" and the snapshot's uncommitted changes\" : \"\";\n\treturn `${restored} at ${degradedBasis(degraded, snapshot, owner)}${recorded}, the closest commit available here. Not restored: ${commits} commit${commits === 1 ? \"\" : \"s\"} (${listed(degraded.missingCommits.map(short), 3)})${changes} of snapshot ${short(mapping.snapshotId)}. ${degraded.hint}`;\n}\n\n/** The notice for a checkout whose snapshot the session holds no record of, which a resume continued without. */\nexport function formatMissingRecordNotice(missing: MissingSnapshotRecord): string {\n\treturn `Continuing without restoring ${missing.root}: the session holds no record of its snapshot ${short(missing.snapshotId)}. Resume on the machine that recorded it, or import (\\`atomic --import <file>\\`) a session saved there with \\`/export <file>.jsonl\\`, which carries its snapshots.`;\n}\n\n/** The one notice for a checkout a resume continued without (#4733). */\nexport function formatUnrestoredNotice(\n\troot: string,\n\tunrestored: WorktreeUnrestored,\n\towner: WorktreeRestoreOwner = \"session\",\n): string {\n\tconst place =\n\t\tunrestored.place === \"launch\"\n\t\t\t? \"the directory the resume started from\"\n\t\t\t: owner === \"session\"\n\t\t\t\t? \"the session's own directory\"\n\t\t\t\t: \"the run's own directory\";\n\treturn `Continuing in ${unrestored.continuedIn} (${place}) without restoring ${root} from snapshot ${short(unrestored.snapshotId)}: ${unrestored.detail}. ${unrestored.hint}`.trimEnd();\n}\n\n/**\n * One informational line per worktree restored since `since`, each followed by its snapshot's warnings and what the\n * restore itself reported; one notice per worktree restored with less than its snapshot, and per checkout a resume\n * continued without, since `since` (#4733).\n */\nexport function worktreeRestoreNotices(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeSnapshotRecords\">,\n\tsince: string,\n): { readonly type: \"info\" | \"warning\"; readonly message: string }[] {\n\treturn restoreNotices(sessionManager, (entry) =>\n\t\tentry.restore\n\t\t\t? entry.restore.restoredAt >= since\n\t\t\t: entry.unrestored !== undefined && entry.unrestored.at >= since,\n\t);\n}\n\nfunction restoreNotices(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeSnapshotRecords\">,\n\tinclude: (entry: Extract<SessionEntry, { type: \"worktree_snapshot\" }>) => boolean,\n): { readonly type: \"info\" | \"warning\"; readonly message: string }[] {\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tconst branch = sessionManager.getBranch();\n\t// The snapshots of conflicting work a full restore kept apart, which later entries go on naming, and the last entry\n\t// of each root, after which nothing recorded the worktree (#5009).\n\tconst keptWork = new Set<string>();\n\tconst last = new Map<string, SessionEntry>();\n\tfor (const entry of branch) {\n\t\tif (entry.type !== \"worktree_snapshot\") continue;\n\t\tif (entry.restore?.degradedWork?.outcome === \"kept\") keptWork.add(entry.restore.degradedWork.snapshotId);\n\t\tlast.set(entry.root, entry);\n\t}\n\treturn branch.flatMap((entry) => {\n\t\tif (entry.type !== \"worktree_snapshot\" || !include(entry)) return [];\n\t\tif (entry.unrestored) {\n\t\t\treturn [{ type: \"warning\" as const, message: formatUnrestoredNotice(entry.root, entry.unrestored) }];\n\t\t}\n\t\tif (!entry.restore) return [];\n\t\tconst snapshot = records.get(entry.snapshotId);\n\t\tconst work = entry.restore.degradedWork;\n\t\tconst pinned =\n\t\t\tentry.degradedFrom === undefined || entry.degradedFrom === work?.snapshotId || keptWork.has(entry.degradedFrom)\n\t\t\t\t? []\n\t\t\t\t: [{ type: \"warning\" as const, message: formatPinnedRestoreNotice(entry.restore, entry.degradedFrom) }];\n\t\tif (entry.restore.degraded) {\n\t\t\tconst message = formatDegradedRestoreNotice(entry.restore, snapshot, entry.restoreWarnings);\n\t\t\treturn [{ type: \"warning\" as const, message }, ...pinned];\n\t\t}\n\t\t// Applied work no capture recorded since, whose pin stands until one does (#5009).\n\t\tconst unrecorded = work?.outcome === \"applied\" && last.get(entry.root) === entry ? work : undefined;\n\t\treturn [\n\t\t\t{ type: \"info\" as const, message: formatWorktreeRestoreNotice(entry.restore) },\n\t\t\t...pinned,\n\t\t\t...(work === undefined\n\t\t\t\t? []\n\t\t\t\t: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: work.outcome === \"applied\" ? (\"info\" as const) : (\"warning\" as const),\n\t\t\t\t\t\t\tmessage: formatDegradedWorkNotice(entry.restore, work),\n\t\t\t\t\t\t},\n\t\t\t\t\t]),\n\t\t\t...(unrecorded === undefined\n\t\t\t\t? []\n\t\t\t\t: [{ type: \"warning\" as const, message: formatUnrecordedWorkNotice(entry.restore, unrecorded) }]),\n\t\t\t...[...(snapshot ? snapshotRestoreWarnings(snapshot) : []), ...(entry.restoreWarnings ?? [])].map(\n\t\t\t\t(warning) => ({ type: \"warning\" as const, message: formatWorktreeRestoreWarning(warning) }),\n\t\t\t),\n\t\t];\n\t});\n}\n\n/**\n * The notice for a checkout restored from the work done in a partly restored worktree, because the snapshot that\n * worktree lacks still cannot be restored here (#4922).\n */\nexport function formatPinnedRestoreNotice(mapping: WorktreeRootMapping, pinnedSnapshotId: string): string {\n\treturn `${mapping.to} holds snapshot ${short(mapping.snapshotId)}, the work recorded since snapshot ${short(pinnedSnapshotId)} of ${mapping.from} was restored only partly; snapshot ${short(pinnedSnapshotId)} itself still cannot be restored here. It stays this checkout's restore target and is kept for ${DEGRADED_RESTORE_RETENTION_DAYS} days after its partial restore, until a resume restores it fully or discardDegradedRestore releases it.`;\n}\n\n/** The notice for the work of a partly restored worktree that a full restore of its snapshot found (#4922). */\nexport function formatDegradedWorkNotice(mapping: WorktreeRootMapping, work: WorktreeDegradedWork): string {\n\tconst files = work.paths.length === 0 ? \"\" : ` (${listed(work.paths)})`;\n\tconst done = `the work done in the partly restored worktree ${work.root}, snapshot ${short(work.snapshotId)}${files}`;\n\tswitch (work.outcome) {\n\t\tcase \"applied\":\n\t\t\treturn `Also applied ${done}, on top of snapshot ${short(mapping.snapshotId)} in ${mapping.to}.`;\n\t\tcase \"kept\":\n\t\t\treturn `Did not apply ${done}: it conflicts with snapshot ${short(mapping.snapshotId)}. Commit ${short(work.commit ?? \"\")} (ref ${work.ref}) holds it; run \\`git diff ${work.base} ${work.commit} | git apply --3way\\` in ${mapping.to} to apply it. Snapshot ${short(work.snapshotId)} stays in the session's storage, so a resume on another machine keeps it as such a commit too, until discardDegradedRestore releases it.`;\n\t\tcase \"unavailable\":\n\t\t\treturn `Could not read ${done} here (${work.reason}), so it is not in ${mapping.to}; it is still in that worktree on the machine where it was done.`;\n\t}\n}\n\n/**\n * The notice for work a full restore carried over whose merged worktree could not be recorded yet (#5009): the restored\n * snapshot stays the restore target and the work stays kept until the next turn or resume records it.\n */\nexport function formatUnrecordedWorkNotice(mapping: WorktreeRootMapping, work: WorktreeDegradedWork): string {\n\treturn `The work applied in ${mapping.to} is not recorded yet: snapshot ${short(work.snapshotId)} stays kept, and a resume elsewhere applies it on top of snapshot ${short(mapping.snapshotId)} again, until the next turn or resume records the worktree.`;\n}\n\n/**\n * The notice for a checkout whose partial restore was pinned for longer than {@link DEGRADED_RESTORE_RETENTION_DAYS}\n * (#4922): the snapshot it lacked is no longer its restore target, and collection no longer keeps it.\n */\nexport function formatLapsedPinNotice(lapsed: {\n\treadonly root: string;\n\treadonly pin: DegradedRestorePin;\n\treadonly latest: string;\n}): string {\n\treturn `Snapshot ${short(lapsed.pin.snapshotId)} of ${lapsed.root}, restored only partly on ${lapsed.pin.since.slice(0, 10)}, is no longer kept: ${DEGRADED_RESTORE_RETENTION_DAYS} days have passed. The checkout continues from snapshot ${short(lapsed.latest)}, the work recorded in its partly restored worktree.`;\n}\n\n/**\n * `entries` with each snapshot's record and blobs from `store` carried inline, each once, so the exported file\n * restores without the source storage. Without a store only the records are carried. A blob the store no longer has\n * is left out; restoring that snapshot then fails with `blob-missing`.\n */\nexport async function inlineSnapshotBlobs(\n\tentries: readonly SessionEntry[],\n\trecords: ReadonlyMap<string, WorktreeSnapshot>,\n\tstore: SnapshotBlobStore | undefined,\n): Promise<SessionEntry[]> {\n\tconst emittedRecords = new Set<string>();\n\tconst emittedBlobs = new Set<string>();\n\tconst result: SessionEntry[] = [];\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"worktree_snapshot\") {\n\t\t\tresult.push(entry);\n\t\t\tcontinue;\n\t\t}\n\t\tconst record = entry.snapshot ?? records.get(entry.snapshotId);\n\t\tconst { blobs: _carried, snapshot: _record, ...rest } = entry;\n\t\tconst blobs: Record<string, string> = {};\n\t\tif (record && store) {\n\t\t\tfor (const hash of snapshotBlobHashes(record)) {\n\t\t\t\tif (emittedBlobs.has(hash)) continue;\n\t\t\t\tconst data = await store.getBlob(hash);\n\t\t\t\tif (data === undefined) continue;\n\t\t\t\tblobs[hash] = Buffer.from(data).toString(\"base64\");\n\t\t\t\temittedBlobs.add(hash);\n\t\t\t}\n\t\t}\n\t\tconst carryRecord = record !== undefined && !emittedRecords.has(record.id);\n\t\tif (record) emittedRecords.add(record.id);\n\t\tresult.push({\n\t\t\t...rest,\n\t\t\t...(carryRecord ? { snapshot: record } : {}),\n\t\t\t...(Object.keys(blobs).length > 0 ? { blobs } : {}),\n\t\t});\n\t}\n\treturn result;\n}\n\n/**\n * Moves inline blobs into `store` after checking each against its hash, and returns the entries without them.\n * Without a store the entries keep their blobs, which restore reads directly. Throws `blob-corrupt` before writing\n * anything when a blob does not match its hash.\n */\nexport async function adoptInlineSnapshotBlobs(\n\tentries: readonly SessionEntry[],\n\tstore: SnapshotBlobStore | undefined,\n): Promise<SessionEntry[]> {\n\tconst blobs: SnapshotBlob[] = [];\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"worktree_snapshot\" || !entry.blobs) continue;\n\t\tfor (const [hash, base64] of Object.entries(entry.blobs)) {\n\t\t\tconst data = new Uint8Array(Buffer.from(base64, \"base64\"));\n\t\t\tif (sha256Hex(data) !== hash) {\n\t\t\t\tthrow new WorkspaceRestoreError(\"blob-corrupt\", { snapshotId: entry.snapshotId, blob: hash });\n\t\t\t}\n\t\t\tblobs.push({ hash, data });\n\t\t}\n\t}\n\tif (!store || blobs.length === 0) return [...entries];\n\tawait store.putBlobs(blobs);\n\treturn entries.map((entry) => {\n\t\tif (entry.type !== \"worktree_snapshot\" || !entry.blobs) return entry;\n\t\tconst { blobs: _moved, ...rest } = entry;\n\t\treturn rest;\n\t});\n}\n\n/** A read-only view of the blobs carried inline by `entries`. */\nexport function inlineBlobStore(entries: readonly SessionEntry[]): SnapshotBlobStore {\n\tconst blobs = new Map<string, string>();\n\tfor (const entry of entries) {\n\t\tif (entry.type === \"worktree_snapshot\" && entry.blobs) {\n\t\t\tfor (const [hash, base64] of Object.entries(entry.blobs)) blobs.set(hash, base64);\n\t\t}\n\t}\n\treturn {\n\t\tasync putBlobs() {\n\t\t\tthrow new WorkspaceSnapshotError(\"blob-store-unsupported\", \"inline\");\n\t\t},\n\t\tasync getBlob(hash) {\n\t\t\tconst base64 = blobs.get(hash);\n\t\t\treturn base64 === undefined ? undefined : new Uint8Array(Buffer.from(base64, \"base64\"));\n\t\t},\n\t\tasync refreshBlobs(hashes) {\n\t\t\treturn hashes.every((hash) => blobs.has(hash));\n\t\t},\n\t\tasync listBlobHashes() {\n\t\t\treturn [...blobs.keys()];\n\t\t},\n\t};\n}\n\n/** Reads `primary` first, then the blobs carried inline by `entries`. */\nexport function sessionSnapshotBlobs(\n\tprimary: SnapshotBlobStore | undefined,\n\tentries: readonly SessionEntry[],\n): SnapshotBlobStore {\n\tconst inline = inlineBlobStore(entries);\n\tif (!primary) return inline;\n\treturn {\n\t\tputBlobs: (blobs) => primary.putBlobs(blobs),\n\t\tgetBlob: async (hash) => (await primary.getBlob(hash)) ?? (await inline.getBlob(hash)),\n\t\trefreshBlobs: (hashes) => primary.refreshBlobs(hashes),\n\t\tlistBlobHashes: () => primary.listBlobHashes(),\n\t};\n}\n\n/** What an export of `entries` carries: checkouts, snapshots and the bytes of patch and bundle content. */\nexport function describeSnapshotExport(\n\tentries: readonly SessionEntry[],\n\trecords: ReadonlyMap<string, WorktreeSnapshot>,\n): string | undefined {\n\tconst roots = new Set<string>();\n\tconst snapshots = new Set<string>();\n\tconst blobBytes = new Map<string, number>();\n\tlet omitted = 0;\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"worktree_snapshot\" || snapshots.has(entry.snapshotId)) continue;\n\t\tsnapshots.add(entry.snapshotId);\n\t\tconst record = entry.snapshot ?? records.get(entry.snapshotId);\n\t\tif (!record) continue;\n\t\troots.add(record.root);\n\t\tomitted += record.omitted.length;\n\t\tfor (const link of record.chain) if (link.patch) blobBytes.set(link.patch, link.bytes);\n\t\tif (record.bundle) blobBytes.set(record.bundle.blob, record.bundle.bytes);\n\t}\n\tif (snapshots.size === 0) return undefined;\n\tconst bytes = [...blobBytes.values()].reduce((sum, size) => sum + size, 0);\n\treturn `Includes ${snapshots.size} worktree snapshot(s) of ${[...roots].join(\", \")}: ${bytes} bytes of patch and bundle content${omitted > 0 ? `, ${omitted} omitted item(s) not included` : \"\"}`;\n}\n\nexport type WorktreeSnapshotComparison =\n\t| { readonly status: \"match\"; readonly tree: string; readonly head?: string }\n\t| { readonly status: \"missing\"; readonly reason: WorktreeSnapshotUnavailableReason }\n\t| {\n\t\t\treadonly status: \"differs\";\n\t\t\treadonly head: string;\n\t\t\treadonly tree: string;\n\t\t\t/** `git diff --stat` from the snapshot's tree to the current one, when the snapshot's tree is present locally. */\n\t\t\treadonly stat: string | undefined;\n\t };\n\n/** Compares the checkout at `dir` with `snapshot`, for `/session snapshot`. */\nexport async function compareWorktreeSnapshot(\n\tsnapshot: WorktreeSnapshot,\n\tdir: string,\n\tsettings: WorktreeSnapshotSettings,\n): Promise<WorktreeSnapshotComparison> {\n\tconst checkout = await locateCheckout(dir);\n\tif (checkout instanceof Error) return { status: \"missing\", reason: checkout };\n\tconst present = await runGit([\"cat-file\", \"-e\", `${snapshot.tree}^{tree}`], {\n\t\tcwd: checkout.root,\n\t\tallowExitCodes: [1, 128],\n\t});\n\tconst policy = await loadSnapshotPathPolicy(checkout.root);\n\tconst state = await withScratchDirectory((scratch) =>\n\t\twriteWorkingTree(checkout, settings, policy, scratch, present.exitCode === 0 ? { seedTree: snapshot.tree } : {}),\n\t);\n\tif (state.tree === snapshot.tree) {\n\t\tif (checkout.head === snapshot.head) return { status: \"match\", tree: state.tree };\n\t\tconst drift = new WorkspaceDriftError({\n\t\t\troot: checkout.root,\n\t\t\texpectedHead: snapshot.head,\n\t\t\tactualHead: checkout.head,\n\t\t\texpectedTree: snapshot.tree,\n\t\t\tactualTree: state.tree,\n\t\t\tsnapshotId: snapshot.id,\n\t\t});\n\t\tif (await isHeadOnlyAdvance(drift)) return { status: \"match\", tree: state.tree, head: checkout.head };\n\t}\n\tconst stat =\n\t\tpresent.exitCode === 0\n\t\t\t? await gitText([\"diff-tree\", \"--stat\", \"--no-renames\", \"--no-ext-diff\", \"-r\", snapshot.tree, state.tree], {\n\t\t\t\t\tcwd: checkout.root,\n\t\t\t\t})\n\t\t\t: undefined;\n\treturn { status: \"differs\", head: checkout.head, tree: state.tree, stat };\n}\n\n/**\n * What the last resume did about the checkout now at `root`, for `/session snapshot`, when it restored less than the\n * snapshot or nothing of it (#4733): the notice that resume showed. Undefined after a complete restore, or none.\n */\nexport function describeWorktreeRestoreStatus(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeSnapshotRecords\">,\n\troot: string,\n): string | undefined {\n\tconst records = sessionManager.getWorktreeSnapshotRecords();\n\tlet status: { readonly snapshotId: string; readonly message: string } | undefined;\n\tfor (const entry of sessionManager.getBranch()) {\n\t\tif (entry.type !== \"worktree_snapshot\") continue;\n\t\tif (entry.restore && resolve(entry.restore.to) === resolve(root)) {\n\t\t\tstatus = entry.restore.degraded\n\t\t\t\t? {\n\t\t\t\t\t\tsnapshotId: entry.snapshotId,\n\t\t\t\t\t\tmessage: formatDegradedRestoreNotice(\n\t\t\t\t\t\t\tentry.restore,\n\t\t\t\t\t\t\trecords.get(entry.snapshotId),\n\t\t\t\t\t\t\tentry.restoreWarnings,\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\t} else if (entry.unrestored && resolve(entry.root) === resolve(root)) {\n\t\t\tstatus = { snapshotId: entry.snapshotId, message: formatUnrestoredNotice(entry.root, entry.unrestored) };\n\t\t} else if (\n\t\t\tstatus &&\n\t\t\tresolve(entry.root) === resolve(root) &&\n\t\t\tentry.snapshotId !== status.snapshotId &&\n\t\t\tentry.degradedFrom !== status.snapshotId\n\t\t) {\n\t\t\t// A later snapshot of the checkout records what it holds now, which replaces what the resume left out, unless\n\t\t\t// it records the partly restored worktree, whose snapshot stays its restore target (#4922).\n\t\t\tstatus = undefined;\n\t\t}\n\t}\n\treturn status?.message;\n}\n\n/** Lines describing `snapshot` for `/session snapshot`. */\nexport function describeWorktreeSnapshot(root: string, snapshot: WorktreeSnapshot): string[] {\n\tconst omitted = snapshot.omitted.map((omission) =>\n\t\t\"path\" in omission\n\t\t\t? `${omission.path} (${omission.reason})`\n\t\t\t: `${omission.commits.length} commit(s) (${omission.reason})`,\n\t);\n\treturn [\n\t\t`${root}`,\n\t\t` snapshot ${snapshot.id} captured ${snapshot.capturedAt}`,\n\t\t` ${snapshot.branch ?? \"detached\"} at ${snapshot.head.slice(0, 12)}, tree ${snapshot.tree.slice(0, 12)}`,\n\t\t` delta chain ${snapshot.chain.length} link(s), ${snapshot.chain.reduce((sum, link) => sum + link.bytes, 0)} bytes; ${\n\t\t\tsnapshot.bundle\n\t\t\t\t? `${snapshot.bundle.commits.length} unpushed commit(s) bundled`\n\t\t\t\t: \"no unpushed commits bundled\"\n\t\t}`,\n\t\t...(omitted.length > 0 ? [` omitted: ${omitted.join(\", \")}`] : []),\n\t\t...(snapshot.filters\n\t\t\t? snapshotRestoreWarnings({ ...snapshot, omitted: [] }).map(formatWorktreeRestoreWarning)\n\t\t\t: []),\n\t];\n}\n\n/**\n * How long the latest turn's capture of the checkout now at `root` took, as a line, also when that capture was of the\n * checkout before a restore moved it to `root`; undefined when no capture recorded it.\n */\nexport async function describeLastCapture(\n\tsessionManager: Pick<SessionManager, \"getBranch\" | \"getWorktreeRootMappings\">,\n\troot: string,\n): Promise<string | undefined> {\n\tconst branch = sessionManager.getBranch();\n\tconst mappings = sessionManager.getWorktreeRootMappings();\n\tfor (let index = branch.length - 1; index >= 0; index--) {\n\t\tconst entry = branch[index]!;\n\t\tif (\n\t\t\tentry.type === \"worktree_snapshot\" &&\n\t\t\ttypeof entry.captureMs === \"number\" &&\n\t\t\t(await mapRestoredPathAsync(entry.root, mappings)) === resolve(root)\n\t\t) {\n\t\t\treturn `last capture took ${(entry.captureMs / 1000).toFixed(1)} s`;\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * Opens `sessionManager`'s session where it should continue: in place when its checkout matches the last snapshot,\n * in the restored worktree otherwise. With `pool`, the opened session holds its pooled worktrees until it closes.\n * Returns the notices to show for a restore it performed.\n */\nexport async function openSessionInWorktree(\n\tsessionManager: SessionManager,\n\toptions: ResumeSessionWorktreeOptions & { readonly sessionDirectory?: string },\n): Promise<{\n\treadonly sessionManager: SessionManager;\n\treadonly notices: { readonly type: \"info\" | \"warning\"; readonly message: string }[];\n}> {\n\tconst resume = await resumeSessionWorktree(sessionManager, options);\n\tconst opened = await openResumedSession(\n\t\tsessionManager,\n\t\tresume.status === \"none\" ? sessionManager.getCwd() : resume.cwd,\n\t\tresume.status === \"restored\" ? resume.mappings : [],\n\t\toptions.sessionDirectory,\n\t\tresume.status === \"none\" ? [] : resume.unrestored.map((checkout) => checkout.record),\n\t);\n\t// The opened session takes over the pooled slots, held until it closes (#4748).\n\tif (options.pool) {\n\t\tawait holdSessionWorktrees(\n\t\t\tsessionManager,\n\t\t\topened.sessionManager,\n\t\t\toptions.storeDir ?? defaultWorktreeSnapshotStoreDir(),\n\t\t);\n\t}\n\treturn opened;\n}\n\n/**\n * Opens `sessionManager`'s session in `cwd`, where resuming it left its working directory, and returns the notices to\n * show for the worktrees that resuming `restored` it into.\n */\nexport async function openResumedSession(\n\tsessionManager: SessionManager,\n\tcwd: string,\n\trestored: readonly WorktreeRootMapping[],\n\tsessionDirectory?: string,\n\tunrestored: readonly WorktreeUnrestored[] = [],\n): Promise<{\n\treadonly sessionManager: SessionManager;\n\treadonly notices: { readonly type: \"info\" | \"warning\"; readonly message: string }[];\n}> {\n\tconst opened =\n\t\tcwd !== sessionManager.getCwd()\n\t\t\t? await sessionManager.openSessionById(sessionManager.getSessionId(), cwd, sessionDirectory, {\n\t\t\t\t\thistory: \"tail\",\n\t\t\t\t})\n\t\t\t: sessionManager;\n\tconst restoredHere = new Set(restored.map((mapping) => mapping.to));\n\tconst leftHere = new Set(unrestored.map((record) => `${record.snapshotId}\\0${record.at}`));\n\treturn {\n\t\tsessionManager: opened,\n\t\tnotices: restoreNotices(opened, (entry) =>\n\t\t\tentry.restore\n\t\t\t\t? restoredHere.has(entry.restore.to)\n\t\t\t\t: entry.unrestored !== undefined && leftHere.has(`${entry.unrestored.snapshotId}\\0${entry.unrestored.at}`),\n\t\t),\n\t};\n}\n\n/**\n * Whether a session recorded elsewhere continues in `cwd` because a restore moved its checkout there, so opening it\n * from `cwd` resumes it rather than forking it into another project.\n */\nexport async function sessionContinuesIn(store: SessionStore, sessionId: string, cwd: string): Promise<boolean> {\n\tconst stored = await storedSnapshotEntries(store, sessionId);\n\treturn runCanonicalStepsAsync(snapshotsContinueIn(stored.header.cwd, stored.entries, cwd));\n}\n\nexport function sessionManagerContinuesIn(\n\tsessionManager: Pick<SessionManager, \"getHeader\" | \"getEntries\">,\n\tcwd: string,\n): boolean {\n\tconst header = sessionManager.getHeader();\n\treturn header !== null && runCanonicalSteps(snapshotsContinueIn(header.cwd, sessionManager.getEntries(), cwd));\n}\n\nfunction* snapshotsContinueIn(\n\trecordedCwd: string,\n\tentries: readonly SessionEntry[],\n\tcwd: string,\n): CanonicalSteps<boolean> {\n\tconst mappings = entries.flatMap((entry) =>\n\t\tentry.type === \"worktree_snapshot\" && entry.restore ? [entry.restore] : [],\n\t);\n\tif (mappings.length === 0) return false;\n\tconst mapped = yield* restoredPath(recordedCwd, mappings);\n\treturn (yield mapped) === (yield cwd);\n}\n\nasync function storedSnapshotEntries(\n\tstore: SessionStore,\n\tsessionId: string,\n): Promise<{\n\treadonly header: SessionRecordHeader;\n\treadonly entries: SessionEntry[];\n\treadonly branch: SessionEntry[];\n}> {\n\tconst { header, state } = await readSessionTail(store, sessionId, Number.MAX_SAFE_INTEGER);\n\tconst snapshots = state.filter(({ entry }) => entry.type === \"worktree_snapshot\");\n\treturn {\n\t\theader,\n\t\tentries: snapshots.map(({ entry }) => entry),\n\t\tbranch: snapshots.filter(({ onBranch }) => onBranch).map(({ entry }) => entry),\n\t};\n}\n\n/** The restores recorded on `branch`, oldest first. */\nfunction restoreMappings(branch: readonly SessionEntry[]): WorktreeRootMapping[] {\n\treturn branch.flatMap((entry) => (entry.type === \"worktree_snapshot\" && entry.restore ? [entry.restore] : []));\n}\n\nfunction* storedBranchSnapshots(\n\tentries: readonly SessionEntry[],\n\tbranch: readonly SessionEntry[],\n): CanonicalSteps<{ readonly mappings: WorktreeRootMapping[]; readonly current: Map<string, WorktreeSnapshot> }> {\n\tconst records = new Map<string, WorktreeSnapshot>();\n\tfor (const entry of entries) {\n\t\tif (entry.type === \"worktree_snapshot\" && entry.snapshot) records.set(entry.snapshotId, entry.snapshot);\n\t}\n\tconst mappings = restoreMappings(branch);\n\tconst current = yield* currentSnapshots({\n\t\tgetBranch: () => [...branch],\n\t\tgetWorktreeRootMappings: () => mappings,\n\t\tgetWorktreeSnapshotRecords: () => records,\n\t});\n\treturn { mappings, current };\n}\n\n/**\n * Whether a session runs in a checkout it recorded snapshots of: its working directory, followed through the restores\n * it recorded, lies inside a checkout the branch it reopens on recorded a snapshot of. Opening such a session from\n * another directory resumes it against that checkout, verified in place or restored into a fresh worktree, instead of\n * forking it into the other directory.\n */\nexport async function sessionRunsInRecordedCheckout(store: SessionStore, sessionId: string): Promise<boolean> {\n\tconst { header, entries, branch } = await storedSnapshotEntries(store, sessionId);\n\treturn runCanonicalStepsAsync(snapshotsRunInRecordedCheckout(header.cwd, entries, branch));\n}\n\nexport function sessionManagerRunsInRecordedCheckout(\n\tsessionManager: Pick<SessionManager, \"getHeader\" | \"getEntries\" | \"getBranch\">,\n): boolean {\n\tconst header = sessionManager.getHeader();\n\treturn (\n\t\theader !== null &&\n\t\trunCanonicalSteps(\n\t\t\tsnapshotsRunInRecordedCheckout(header.cwd, sessionManager.getEntries(), sessionManager.getBranch()),\n\t\t)\n\t);\n}\n\nfunction* snapshotsRunInRecordedCheckout(\n\trecordedCwd: string,\n\tentries: readonly SessionEntry[],\n\tbranch: readonly SessionEntry[],\n): CanonicalSteps<boolean> {\n\tconst { mappings, current } = yield* storedBranchSnapshots(entries, branch);\n\tconst cwd = yield* restoredPath(recordedCwd, mappings);\n\tfor (const root of current.keys()) if (yield* isInside(root, cwd)) return true;\n\treturn false;\n}\n"]}