@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":"pool.js","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,UAAU,IAAI,iBAAiB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAqB,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC1G,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,U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E,WAAW,EAAE,oBAAoB,EAAE,aAAa,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAC5G,CAAC;IACF,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC;AAClF,CAAC","sourcesContent":["import { createHash, randomUUID } from \"node:crypto\";\nimport { link, mkdir, readdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, join, resolve } from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\nimport { failureDebugFields, reportDebugAsync as reportDebug } from \"../debug.ts\";\nimport { renameWithRetry } from \"../rename-retry.ts\";\nimport { isWorkspaceRestoreError } from \"./errors.ts\";\nimport { nulFields, runGit } from \"./git.ts\";\nimport { processesWorkIn } from \"./in-use.ts\";\nimport { canonicalizeWorktreePathAsync } from \"./paths.ts\";\nimport { isDeniedSnapshotPath } from \"./policy.ts\";\nimport { HOST, holderRuns as processHolderRuns, thisProcess } from \"./process-holder.js\";\nimport { type RepositoryId, sharedRepositoryIdOf, sharedRepositoryIdsOf } from \"./repository-identity.ts\";\nimport { pooledWorktreeStore, resetPooledWorktree, verifyWorktree } from \"./restore.ts\";\nimport { lockShared, sharedClockNow } from \"./shared-clock.ts\";\nimport type { SnapshotBlobStore, WorktreeRestoreWarning, WorktreeSnapshot, WorktreeSnapshotSettings } from \"./types.ts\";\n\nexport { processStartToken } from \"../process-start-token.js\";\n\n/**\n * The per-machine pool of restored worktrees (#4748). A session resume restores into a slot at a stable path,\n * `<storeDir>/worktrees/<repositoryId>-<n>`, described by one record, `<storeDir>/pool/<repositoryId>/<n>.json`, and\n * leased while a session works in it: each process that holds a slot has a lease lock of its own next to the record,\n * and a lock on the record itself serializes changes to the slot. Only session resumes admit slots: worktrees restored\n * for workflow runs, by the SDK into a chosen directory, or by earlier versions have no record and are never pooled.\n *\n * A slot's owner is the holder that last took it, whether it still holds the lease or released it when it closed;\n * only the owner continues in it. {@link claimIdleWorktree} is the one way an existing worktree is rewritten: it takes\n * an idle slot that holds nothing but its recorded state for another snapshot, and the slot's owner with it.\n *\n * Only checkouts of one repository share slots (#4989): those whose remotes name it, local paths resolved against the\n * checkout's root. A checkout without remotes is never pooled: nothing on record tells its repository apart from\n * another remote-less one, so its slots and their ignored files, such as secrets and dependencies, would go to them.\n */\n\nexport type { RepositoryId } from \"./repository-identity.ts\";\nexport { repositoryIdOf } from \"./repository-identity.ts\";\n\nexport type SlotNumber = number & { readonly __brand: \"SlotNumber\" };\n\n/** Who holds a slot: a session, by its id, or a prebuild. */\nexport interface PoolOwner {\n\treadonly kind: \"session\" | \"prebuild\";\n\treadonly id: string;\n}\n\n/** The state a slot was left in: its HEAD and policy tree, and the snapshot that recorded them when known. */\nexport interface PoolLastState {\n\treadonly snapshotId: string | null;\n\treadonly head: string;\n\treadonly tree: string;\n}\n\nexport interface PoolSlotRecord {\n\treadonly version: 1;\n\treadonly repository: RepositoryId;\n\treadonly slot: SlotNumber;\n\treadonly path: string;\n\treadonly holder: PoolOwner;\n\treadonly lastState: PoolLastState;\n\treadonly envHash: string;\n\treadonly blueprintDigest: string | null;\n\t/** When the holder released the slot; null while it is held, or when its holder stopped without releasing it. */\n\treadonly releasedAt: string | null;\n\t/**\n\t * The state a claim is resetting the slot to, set before its files change and cleared once they verify: a slot that\n\t * still has it holds a mix of two recorded states, never anything else, and is never claimed.\n\t */\n\treadonly resetting?: PoolLastState;\n\t/**\n\t * Names the take of the slot by its holder (#4830): a new one each time a holder admits or claims the slot, kept when\n\t * the same holder holds it again. A process whose copy of the record no longer matches it lost the slot. Records\n\t * written before #4830 have none.\n\t */\n\treadonly tenancy?: string;\n}\n\n/** What a session resume restores into a new slot. */\nexport interface PoolAdmission {\n\treadonly storeDir: string;\n\treadonly remotes: readonly string[];\n\t/** The checkout's root, which relative-path remotes such as `../upstream` are relative to (#4989). */\n\treadonly root?: string;\n\t/** The state the restore is about to publish. */\n\treadonly lastState: PoolLastState;\n\treadonly envHash: string;\n\treadonly signal?: AbortSignal;\n}\n\n/** A slot this process holds for an owner. Release it exactly once. */\nexport interface WorktreeLease {\n\treadonly storeDir: string;\n\treadonly repository: RepositoryId;\n\treadonly slot: SlotNumber;\n\treadonly path: string;\n\treadonly owner: PoolOwner;\n}\n\n/** Who owns the worktree at a path: no pool record (`\"unpooled\"`), or its owner and whether a live process holds it. */\nexport type PooledWorktreeHolder =\n\t| \"unpooled\"\n\t| {\n\t\t\t/** The holder that last took the slot; null when its record cannot be read, which no session owns. */\n\t\t\treadonly owner: PoolOwner | null;\n\t\t\treadonly held: boolean;\n\t };\n\n/** `snapshots.pool` settings. */\nexport interface WorktreePoolSettings {\n\t/** Idle pooled worktrees kept per repository; the oldest unchanged ones beyond it are removed. Default 2. */\n\treadonly maxIdlePerRepository: number;\n}\n\n/** Default of `snapshots.pool.maxIdlePerRepository`. */\nexport const DEFAULT_MAX_IDLE_PER_REPOSITORY = 2;\n\n/** The lease constants of restore records: a stopped process loses its lease after 30 seconds. */\nconst LEASE_STALE_MS = 30_000;\nconst LEASE_UPDATE_MS = 10_000;\nconst POOL_LOCK_POLL_MS = 50;\nconst POOL_LOCK_WAIT_MS = 60_000;\nexport const POOL_LOCK_REFUSED_MS = 10_000;\n/**\n * How long after a lease went stale it still keeps its slot from being claimed or evicted, and its lock from being\n * removed (#4830): a holder stalled for a short while, by an overloaded host or a debugger, keeps its slot and its lease.\n * Only a lease last refreshed more than `LEASE_STALE_MS + LEASE_CLAIM_GRACE_MS` ago lets another process take the slot.\n */\nexport const LEASE_CLAIM_GRACE_MS = 60_000;\n/**\n * How long a lease of this host that names no start of its process keeps its slot without being refreshed while a\n * process of its id runs (#4990): such a lease, written where the start cannot be read or before #4990, cannot tell its\n * holder from a later process given the same id after a container restart or a reboot, so past this it is judged by\n * its age alone. A lease that names its holder's start is kept for as long as that process runs, however long it was\n * suspended.\n */\nexport const UNSTARTED_LEASE_LIMIT_MS = 24 * 60 * 60_000;\nconst SLOT_NAME = /^([0-9a-f]{24})-(\\d{1,6})$/;\nconst RECORD_NAME = /^(\\d{1,6})\\.json$/;\n\nexport function pooledWorktreePath(storeDir: string, repository: RepositoryId, slot: SlotNumber): string {\n\treturn join(resolve(storeDir), \"worktrees\", `${repository}-${slot}`);\n}\n\nfunction recordFile(storeDir: string, repository: RepositoryId, slot: SlotNumber): string {\n\treturn join(resolve(storeDir), \"pool\", repository, `${slot}.json`);\n}\n\ninterface HeldSlot {\n\treadonly owner: PoolOwner;\n\treferences: number;\n\t/** The record as this process last wrote it: its holder and tenancy say whose the slot is. */\n\trecord: PoolSlotRecord;\n\t/** Releases this process's lease of the slot. */\n\tunlease: () => Promise<void>;\n\t/** Another process removed this process's lease once it went stale: the slot may have been taken (#4830). */\n\tcompromised: boolean;\n\t/** The slot was taken from this hold, or its record removed: nothing of the hold writes to it again (#4830). */\n\tlost: boolean;\n}\n\n/** The slots this process holds, by record file. A second hold of a slot by its owner shares the lease. */\nconst heldSlots = new Map<string, HeldSlot>();\n/** The hold each lease of this process shares. */\nconst leaseHolds = new WeakMap<WorktreeLease, HeldSlot>();\nconst released = new WeakSet<WorktreeLease>();\nlet processLease: Promise<string> | undefined;\n/**\n * Names this process's leases: its host and pid, a random part, as the pid alone could be reused by a later process,\n * and when this process started, where that can be read (#4990, #5141). Read once, on first use.\n */\nfunction ownLease(): Promise<string> {\n\tprocessLease ??= thisProcess().then(\n\t\t({ start: started }) =>\n\t\t\t`${HOST}-${process.pid}-${randomUUID().slice(0, 8)}${started === undefined ? \"\" : `-${started}`}`,\n\t);\n\treturn processLease;\n}\n/**\n * A lease name after the record's: the holder's host and pid, and when the holder started. Leases written before\n * #4830 name no host, and those written before #4990 no start.\n */\nconst LEASE_NAME = /^([0-9a-f]{12})-(\\d+)-[0-9a-f]{8}(?:-([0-9a-f]{12}))?\\.lease\\.lock$/;\n\n/**\n * Whether the lease named `name` belongs to a process of this host that still runs (#4830): a holder stalled for\n * minutes may still write to its slot. A process this one may not signal runs too. A lease that names when its holder\n * started belongs to a process of that id that started then, never to a later one given the id (#4990), on Windows too\n * (#5141). A lease of another host, or one naming no host, is judged by its age alone.\n */\nasync function holderRuns(name: string, age: number): Promise<boolean> {\n\tconst lease = LEASE_NAME.exec(name);\n\tif (lease === null) return false;\n\treturn processHolderRuns({ host: lease[1]!, pid: Number(lease[2]), start: lease[3] }, age, UNSTARTED_LEASE_LIMIT_MS);\n}\n\nfunction sameOwner(a: PoolOwner, b: PoolOwner): boolean {\n\treturn a.kind === b.kind && a.id === b.id;\n}\n\nexport interface SetAsideNote {\n\treadonly startedAt: string;\n\treadonly logs: string;\n}\n\nconst setAsideHere = new Map<string, string | undefined>();\n\nfunction setAsideFile(storeDir: string, path: string): string {\n\tconst key = createHash(\"sha256\").update(resolve(path)).digest(\"hex\").slice(0, 16);\n\treturn join(resolve(storeDir), \"pool\", \"set-aside\", `${key}.json`);\n}\n\nasync function directoryIdentity(path: string): Promise<string | undefined> {\n\ttry {\n\t\tconst found = await stat(path);\n\t\treturn `${found.dev}:${found.ino}:${Math.trunc(found.birthtimeMs)}`;\n\t} catch (error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\tif (code === \"ENOENT\" || code === \"ENOTDIR\") return undefined;\n\t\tthrow error;\n\t}\n}\n\nexport async function setAsideWorktree(storeDir: string, path: string, note: SetAsideNote): Promise<void> {\n\tconst directory = await directoryIdentity(path).catch(() => undefined);\n\tsetAsideHere.set(resolve(path), directory);\n\tconst file = setAsideFile(storeDir, path);\n\tawait mkdir(dirname(file), { recursive: true });\n\tconst temporary = `${file}.${randomUUID()}.tmp`;\n\tawait writeFile(temporary, JSON.stringify({ path: resolve(path), directory, ...note }), { mode: 0o600 });\n\tawait renameWithRetry(temporary, file);\n}\n\nasync function readSetAsideNote(\n\tstoreDir: string,\n\tpath: string,\n): Promise<(Partial<SetAsideNote> & { directory?: unknown }) | \"absent\" | \"unreadable\"> {\n\tlet text: string;\n\ttry {\n\t\ttext = await readFile(setAsideFile(storeDir, path), \"utf8\");\n\t} catch (error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code === \"ENOENT\" || code === \"ENOTDIR\" ? \"absent\" : \"unreadable\";\n\t}\n\ttry {\n\t\tconst note = JSON.parse(text) as unknown;\n\t\treturn typeof note === \"object\" && note !== null ? note : {};\n\t} catch {\n\t\treturn {};\n\t}\n}\n\nasync function sameDirectory(path: string, directory: unknown): Promise<boolean> {\n\tif (typeof directory !== \"string\") return true;\n\ttry {\n\t\treturn (await directoryIdentity(path)) === directory;\n\t} catch {\n\t\treturn true;\n\t}\n}\n\nexport async function worktreeSetAside(storeDir: string, path: string): Promise<boolean> {\n\tif (setAsideHere.has(resolve(path)) && (await sameDirectory(path, setAsideHere.get(resolve(path))))) return true;\n\tconst note = await readSetAsideNote(storeDir, path);\n\tif (note === \"absent\") return false;\n\tif (note === \"unreadable\") return true;\n\treturn sameDirectory(path, note.directory);\n}\n\nasync function exists(path: string): Promise<boolean> {\n\ttry {\n\t\tawait stat(path);\n\t\treturn true;\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return false;\n\t\tthrow error;\n\t}\n}\n\nfunction refusedForAMoment(error: unknown, since: number): boolean {\n\treturn (\n\t\t(error as NodeJS.ErrnoException).code === \"EPERM\" &&\n\t\tprocess.platform === \"win32\" &&\n\t\tDate.now() - since < POOL_LOCK_REFUSED_MS\n\t);\n}\n\nfunction lockHeldAndWaiting(error: unknown, wait: boolean, startedAt: number): boolean {\n\treturn wait && (error as NodeJS.ErrnoException).code === \"ELOCKED\" && Date.now() - startedAt < POOL_LOCK_WAIT_MS;\n}\n\n/**\n * Locks `path` with the restore-record constants: a stopped process loses the lock after 30 seconds. `wait` retries a\n * lock another process holds for up to 60 seconds with 50 ms polls, as when a slot's record is briefly being written.\n */\nasync function lockPath(\n\tpath: string,\n\twait: boolean,\n\tonLost?: (error: Error) => void,\n\tsignal?: AbortSignal,\n): Promise<() => Promise<void>> {\n\tconst startedAt = Date.now();\n\tlet refusedSince: number | undefined;\n\tfor (;;) {\n\t\tsignal?.throwIfAborted();\n\t\ttry {\n\t\t\treturn await lockShared(path, {\n\t\t\t\trealpath: false,\n\t\t\t\tstale: LEASE_STALE_MS,\n\t\t\t\tupdate: LEASE_UPDATE_MS,\n\t\t\t\tretries: 0,\n\t\t\t\tonCompromised: (error) => {\n\t\t\t\t\treportDebug(\"storage\", \"worktree-pool-lock-lost\", { path, ...failureDebugFields(error) });\n\t\t\t\t\tonLost?.(error);\n\t\t\t\t},\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconst since = refusedSince ?? Date.now();\n\t\t\tif (refusedForAMoment(error, since)) refusedSince = since;\n\t\t\telse if (lockHeldAndWaiting(error, wait, startedAt)) refusedSince = undefined;\n\t\t\telse throw error;\n\t\t}\n\t\tawait sleep(POOL_LOCK_POLL_MS, undefined, { signal });\n\t}\n}\n\n/** A slot's record lock as {@link withSlotLock} holds it. */\ninterface SlotLock {\n\t/**\n\t * Whether this process still holds the lock (#4991): false once it was compromised, or once another process broke it\n\t * as stale and took it, as while this one was suspended past the stale time. Checked right before each change to\n\t * the slot, its record or its files, which is never made without the lock.\n\t */\n\theld(): Promise<boolean>;\n}\n\n/**\n * Where the holder of the slot's record lock `file` names its take of the lock: a random token each take writes once it\n * holds the lock, so a process that lost the lock to another, even to a new lock directory at the same place, reads\n * another token or none (#4991). It sits beside the lock directory, which must stay empty for a stale lock to be\n * removable.\n */\nfunction lockTokenFile(file: string): string {\n\treturn `${file}.lock-holder`;\n}\n\nasync function readLockToken(file: string): Promise<string | undefined> {\n\ttry {\n\t\treturn await readFile(lockTokenFile(file), \"utf8\");\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Runs `action` holding the slot's record lock, which serializes changes to one slot across processes: leases are\n * taken and released, and slots evicted, only under it. Without `wait`, a busy slot rejects with `ELOCKED`. The lock is\n * only removed while this process still holds it, so a lock another process took over is never removed under it.\n */\nasync function withSlotLock<T>(\n\tfile: string,\n\twait: boolean,\n\taction: (lock: SlotLock) => Promise<T>,\n\tsignal?: AbortSignal,\n): Promise<T> {\n\tlet lost = false;\n\tconst unlock = await lockPath(\n\t\tfile,\n\t\twait,\n\t\t() => {\n\t\t\tlost = true;\n\t\t},\n\t\tsignal,\n\t);\n\tconst token = randomUUID();\n\tlet named = false;\n\ttry {\n\t\tconst temporary = `${lockTokenFile(file)}.${await ownLease()}.tmp`;\n\t\tawait writeFile(temporary, token, { mode: 0o600 });\n\t\tawait renameWithRetry(temporary, lockTokenFile(file));\n\t\tnamed = true;\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-lock-token-failed\", { file, ...failureDebugFields(error) });\n\t}\n\tconst lock: SlotLock = { held: async () => named && !lost && (await readLockToken(file)) === token };\n\ttry {\n\t\treturn await action(lock);\n\t} finally {\n\t\tif (!named) await unlock().catch(() => {});\n\t\telse if (await lock.held()) {\n\t\t\tawait rm(lockTokenFile(file), { force: true }).catch(() => {});\n\t\t\tawait unlock().catch(() => {});\n\t\t}\n\t}\n}\n\n/**\n * Moves the record at `file` aside when it still is `expected`, in one rename no other writer interleaves with, and\n * resolves to where it went; a record that changed, or is gone, is put back as it is and resolves to undefined (#4991).\n * Until {@link giveBackRecord} or {@link putRecord}, the slot has no record: no hold, claim or eviction takes it.\n */\nasync function takeRecord(file: string, expected: PoolSlotRecord): Promise<string | undefined> {\n\tconst taken = `${file}.${await ownLease()}.taken`;\n\ttry {\n\t\tawait renameWithRetry(file, taken);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\tthrow error;\n\t}\n\tconst text = await readFile(taken, \"utf8\").catch(() => undefined);\n\tlet same = false;\n\ttry {\n\t\tsame = text !== undefined && JSON.stringify(JSON.parse(text)) === JSON.stringify(expected);\n\t} catch {\n\t\tsame = false;\n\t}\n\tif (same) return taken;\n\tawait giveBackRecord(file, taken);\n\treturn undefined;\n}\n\n/** Puts a taken record back, unless a writer wrote the slot's record meanwhile: then that record stands. */\nasync function giveBackRecord(file: string, taken: string): Promise<void> {\n\ttry {\n\t\tawait link(taken, file);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"EEXIST\") throw error;\n\t}\n\tawait rm(taken, { force: true });\n}\n\n/**\n * Writes `record` as the slot's record in place of the one {@link takeRecord} moved to `taken`, only when no writer\n * wrote one meanwhile; resolves to false, writing nothing, when one did, whose record stands (#4991).\n */\nasync function putRecord(file: string, taken: string, record: PoolSlotRecord): Promise<boolean> {\n\ttry {\n\t\tconst published = await createRecord(file, record);\n\t\tawait rm(taken, { force: true }).catch((error) => {\n\t\t\treportDebug(\"storage\", \"worktree-pool-taken-cleanup-failed\", { file, ...failureDebugFields(error) });\n\t\t});\n\t\treturn published;\n\t} catch (error) {\n\t\tawait giveBackRecord(file, taken).catch(() => {});\n\t\tthrow error;\n\t}\n}\n\n/** The error an action that lost its slot's record lock stops with, which callers treat as a busy slot (#4991). */\nfunction lockLostError(file: string): NodeJS.ErrnoException {\n\treturn Object.assign(new Error(`lost the record lock of ${file}`), { code: \"ELOCKED\" });\n}\n\n/**\n * Takes this process's lease of the slot whose record is `file` for `held`: a lock of its own, so other processes can\n * share it. Losing the lock marks `held` compromised. Ending the lease removes its lock even once it was compromised.\n */\nasync function leaseSlot(\n\tfile: string,\n\theld: Pick<HeldSlot, \"compromised\">,\n\tsignal?: AbortSignal,\n): Promise<() => Promise<void>> {\n\tconst lease = `${file}.${await ownLease()}.lease`;\n\tconst unlock = await lockPath(\n\t\tlease,\n\t\tfalse,\n\t\t() => {\n\t\t\theld.compromised = true;\n\t\t},\n\t\tsignal,\n\t);\n\treturn () => unlock().catch(() => rm(`${lease}.lock`, { recursive: true, force: true }));\n}\n\n/** A hold of the slot whose record is `file` for `owner`, with this process's lease of it taken. */\nasync function takeSlot(\n\tfile: string,\n\towner: PoolOwner,\n\trecord: PoolSlotRecord,\n\tsignal?: AbortSignal,\n): Promise<HeldSlot> {\n\tconst held: HeldSlot = { owner, references: 1, record, unlease: async () => {}, compromised: false, lost: false };\n\theld.unlease = await leaseSlot(file, held, signal);\n\treturn held;\n}\n\n/**\n * The leases other processes hold on the slot whose record is `file`, removing those last refreshed more than\n * {@link LEASE_CLAIM_GRACE_MS} after they went stale. A lease that cannot be read counts as held, and so does one whose\n * holder still runs on this host, as {@link holderRuns} tells (#4990). With `grace`, as before a\n * claim or an eviction, a lease that went stale within the grace period counts as held too (#4830).\n */\nasync function otherLeases(file: string, grace: boolean): Promise<number> {\n\tconst prefix = `${basename(file)}.`;\n\tconst own = `${basename(file)}.${await ownLease()}.lease.lock`;\n\tlet live = 0;\n\t// Ages are measured by the clock of the filesystem holding the leases, which their holders stamp refreshes in, so a\n\t// holder on a host whose clock is off is judged by when it last refreshed its lease (#5050).\n\tconst now = await sharedClockNow(dirname(file));\n\tfor (const name of await readdir(dirname(file))) {\n\t\tif (!name.startsWith(prefix) || !name.endsWith(\".lease.lock\") || name === own) continue;\n\t\tconst lock = join(dirname(file), name);\n\t\tlet age: number;\n\t\ttry {\n\t\t\tage = now - (await stat(lock)).mtimeMs;\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") live++;\n\t\t\tcontinue;\n\t\t}\n\t\tconst expired = age > LEASE_STALE_MS + LEASE_CLAIM_GRACE_MS;\n\t\tif (age <= LEASE_STALE_MS || (grace && !expired) || (await holderRuns(name.slice(prefix.length), age))) live++;\n\t\telse if (expired) await rm(lock, { recursive: true, force: true }).catch(() => {});\n\t}\n\treturn live;\n}\n\n/**\n * Whether a live process holds the slot whose record is `file`: this one, or another whose lease is not stale or, with\n * `grace`, went stale within the grace period.\n */\nasync function isHeld(file: string, grace: boolean): Promise<boolean> {\n\tif (heldSlots.has(file)) return true;\n\treturn (await otherLeases(file, grace).catch(() => 1)) > 0;\n}\n\n/**\n * Under the slot's record lock: whether `held` still holds the slot, its record naming the same holder and tenancy as\n * this process's copy (#4830). When it does not, as when another process claimed the slot while this one was stalled,\n * the hold is lost: this process's lease ends, and nothing of the hold writes to the slot again. A record that is there\n * but cannot be read rejects, keeping the hold.\n */\nasync function stillHolds(file: string, storeDir: string, held: HeldSlot): Promise<boolean> {\n\tif (held.lost) return false;\n\tconst { repository, slot } = held.record;\n\tlet current: PoolSlotRecord | undefined;\n\ttry {\n\t\tcurrent = await readRecord(file, storeDir, repository, slot);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t}\n\tif (current !== undefined && sameOwner(current.holder, held.owner) && current.tenancy === held.record.tenancy) {\n\t\treturn true;\n\t}\n\theld.lost = true;\n\tif (heldSlots.get(file) === held) heldSlots.delete(file);\n\tawait held.unlease().catch(() => {});\n\treportDebug(\"storage\", \"worktree-pool-slot-lost\", { file, holder: current?.holder.id ?? null });\n\treturn false;\n}\n\nasync function writeRecord(file: string, record: PoolSlotRecord): Promise<void> {\n\tconst temporary = `${file}.${await ownLease()}.tmp`;\n\tawait writeFile(temporary, JSON.stringify(record), { mode: 0o600 });\n\tawait renameWithRetry(temporary, file);\n}\n\nasync function createRecord(file: string, record: PoolSlotRecord): Promise<boolean> {\n\tconst temporary = `${file}.${randomUUID()}.tmp`;\n\ttry {\n\t\tawait writeFile(temporary, JSON.stringify(record), { mode: 0o600 });\n\t\ttry {\n\t\t\tawait link(temporary, file);\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code === \"EEXIST\") return false;\n\t\t\tthrow error;\n\t\t}\n\t} finally {\n\t\tawait rm(temporary, { force: true }).catch((error) => {\n\t\t\treportDebug(\"storage\", \"worktree-pool-temporary-cleanup-failed\", { file, ...failureDebugFields(error) });\n\t\t});\n\t}\n}\n\nfunction isOwner(value: unknown): value is PoolOwner {\n\tconst owner = value as Partial<PoolOwner> | null | undefined;\n\treturn (owner?.kind === \"session\" || owner?.kind === \"prebuild\") && typeof owner.id === \"string\";\n}\n\nfunction isState(value: unknown): value is PoolLastState {\n\tconst state = value as Partial<PoolLastState> | null | undefined;\n\treturn (\n\t\ttypeof state?.head === \"string\" &&\n\t\ttypeof state.tree === \"string\" &&\n\t\t(state.snapshotId === null || typeof state.snapshotId === \"string\")\n\t);\n}\n\nasync function readRecord(file: string, storeDir: string, repository: RepositoryId, slot: SlotNumber) {\n\tconst record = JSON.parse(await readFile(file, \"utf8\")) as Partial<PoolSlotRecord> | null;\n\tconst valid =\n\t\trecord?.version === 1 &&\n\t\trecord.repository === repository &&\n\t\trecord.slot === slot &&\n\t\trecord.path === pooledWorktreePath(storeDir, repository, slot) &&\n\t\tisOwner(record.holder) &&\n\t\tisState(record.lastState) &&\n\t\ttypeof record.envHash === \"string\" &&\n\t\t(record.blueprintDigest === null || typeof record.blueprintDigest === \"string\") &&\n\t\t(record.releasedAt === null || typeof record.releasedAt === \"string\") &&\n\t\t(record.resetting === undefined || isState(record.resetting)) &&\n\t\t(record.tenancy === undefined || typeof record.tenancy === \"string\");\n\treturn valid ? (record as PoolSlotRecord) : undefined;\n}\n\nfunction newLease(record: PoolSlotRecord, storeDir: string, held: HeldSlot): WorktreeLease {\n\tconst lease: WorktreeLease = Object.freeze({\n\t\tstoreDir: resolve(storeDir),\n\t\trepository: record.repository,\n\t\tslot: record.slot,\n\t\tpath: record.path,\n\t\towner: held.owner,\n\t});\n\tleaseHolds.set(lease, held);\n\treturn lease;\n}\n\n/**\n * Takes the lowest free slot of the repository `admission.remotes` name and holds it for `owner`, before the restore\n * publishes into its path. A slot is free when it has neither a record nor a directory, and no other process is\n * changing it. Choosing and taking a slot run under a per-repository lock, so concurrent restores, in this process or\n * others, get different slots. Rejects when the remotes name no one repository, as for a checkout without remotes,\n * which is never pooled (#4989).\n */\nexport async function admitPooledWorktree(admission: PoolAdmission, owner: PoolOwner): Promise<WorktreeLease> {\n\tconst storeDir = resolve(admission.storeDir);\n\tconst repository = sharedRepositoryIdOf(admission.remotes, admission.root);\n\tif (repository === undefined) {\n\t\tthrow new Error(\"the checkout's remotes name no one repository; its worktrees are not pooled\");\n\t}\n\tconst directory = join(storeDir, \"pool\", repository);\n\tawait mkdir(directory, { recursive: true });\n\tlet repositoryLost: Error | undefined;\n\tconst unlockRepository = await lockPath(\n\t\tdirectory,\n\t\ttrue,\n\t\t(error) => {\n\t\t\trepositoryLost ??= error;\n\t\t},\n\t\tadmission.signal,\n\t);\n\ttry {\n\t\tfor (let n = 0; ; n++) {\n\t\t\tif (repositoryLost !== undefined) throw repositoryLost;\n\t\t\tconst slot = n as SlotNumber;\n\t\t\tconst file = recordFile(storeDir, repository, slot);\n\t\t\tconst path = pooledWorktreePath(storeDir, repository, slot);\n\t\t\tif ((await exists(file)) || (await exists(path))) continue;\n\t\t\tconst record: PoolSlotRecord = {\n\t\t\t\tversion: 1,\n\t\t\t\trepository,\n\t\t\t\tslot,\n\t\t\t\tpath,\n\t\t\t\tholder: owner,\n\t\t\t\tlastState: admission.lastState,\n\t\t\t\tenvHash: admission.envHash,\n\t\t\t\tblueprintDigest: null,\n\t\t\t\treleasedAt: null,\n\t\t\t\ttenancy: randomUUID(),\n\t\t\t};\n\t\t\tlet held: HeldSlot | undefined;\n\t\t\ttry {\n\t\t\t\theld = await withSlotLock(\n\t\t\t\t\tfile,\n\t\t\t\t\tfalse,\n\t\t\t\t\tasync (lock) => {\n\t\t\t\t\t\tif (repositoryLost !== undefined) throw repositoryLost;\n\t\t\t\t\t\tif (!(await lock.held())) throw lockLostError(file);\n\t\t\t\t\t\tif ((await exists(file)) || (await exists(path))) return undefined;\n\t\t\t\t\t\tconst taken = await takeSlot(file, owner, record, admission.signal);\n\t\t\t\t\t\tlet published = false;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (repositoryLost !== undefined) throw repositoryLost;\n\t\t\t\t\t\t\tif (!(await lock.held())) throw lockLostError(file);\n\t\t\t\t\t\t\tif ((await exists(file)) || (await exists(path))) {\n\t\t\t\t\t\t\t\tawait taken.unlease().catch(() => {});\n\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tpublished = await createRecord(file, record);\n\t\t\t\t\t\t\tif (!(await lock.held())) throw lockLostError(file);\n\t\t\t\t\t\t\tif (repositoryLost !== undefined) throw repositoryLost;\n\t\t\t\t\t\t\tif (!published) {\n\t\t\t\t\t\t\t\tawait taken.unlease().catch(() => {});\n\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (published) {\n\t\t\t\t\t\t\t\tconst abandoned = await takeRecord(file, record).catch(() => undefined);\n\t\t\t\t\t\t\t\tif (abandoned !== undefined) await rm(abandoned, { force: true }).catch(() => {});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tawait taken.unlease().catch(() => {});\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t\theldSlots.set(file, taken);\n\t\t\t\t\t\treturn taken;\n\t\t\t\t\t},\n\t\t\t\t\tadmission.signal,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif ((error as NodeJS.ErrnoException).code === \"ELOCKED\") continue;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (held === undefined) continue;\n\t\t\treturn newLease(record, storeDir, held);\n\t\t}\n\t} finally {\n\t\tawait unlockRepository().catch(() => {});\n\t}\n}\n\n/** The repository and slot of a pooled worktree path under `storeDir`, or undefined for any other path. */\nasync function slotOf(\n\tstoreDir: string,\n\troot: string,\n): Promise<{ repository: RepositoryId; slot: SlotNumber } | undefined> {\n\tconst worktrees = join(resolve(storeDir), \"worktrees\");\n\tconst match = SLOT_NAME.exec(basename(root));\n\tif (!match) return undefined;\n\ttry {\n\t\tconst [parent, pooled] = await Promise.all([\n\t\t\tcanonicalizeWorktreePathAsync(dirname(root)),\n\t\t\tcanonicalizeWorktreePathAsync(worktrees),\n\t\t]);\n\t\tif (parent !== pooled) return undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n\treturn { repository: match[1] as RepositoryId, slot: Number(match[2]) as SlotNumber };\n}\n\n/** Who owns the worktree at `root`, and whether a live process holds it. Reads, never writes, and never throws. */\nexport async function pooledWorktreeHolder(storeDir: string, root: string): Promise<PooledWorktreeHolder> {\n\tconst slot = await slotOf(storeDir, root);\n\tif (slot === undefined) return \"unpooled\";\n\tconst file = recordFile(storeDir, slot.repository, slot.slot);\n\tlet record: PoolSlotRecord | undefined;\n\ttry {\n\t\trecord = await readRecord(file, storeDir, slot.repository, slot.slot);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return \"unpooled\";\n\t\trecord = undefined;\n\t}\n\treturn { owner: record?.holder ?? null, held: await isHeld(file, false) };\n}\n\n/**\n * Holds the existing pooled slot at `root` for `owner`, who must own it, as when a session continues in its worktree.\n * Processes of the same owner share the slot, each with a lease of its own, so it stays held until the last one\n * releases it or stops. Undefined when `root` is not pooled or another holder owns it.\n */\nexport async function holdRestoredWorktree(\n\tstoreDir: string,\n\troot: string,\n\towner: PoolOwner,\n\tsignal?: AbortSignal,\n): Promise<WorktreeLease | undefined> {\n\tconst slot = await slotOf(storeDir, root);\n\tif (slot === undefined) return undefined;\n\tconst file = recordFile(storeDir, slot.repository, slot.slot);\n\t// Every change to the slot, this process's share of it included, happens under its record lock, so concurrent\n\t// holds, releases and evictions in this process or others see each other.\n\treturn withSlotLock(\n\t\tfile,\n\t\ttrue,\n\t\tasync (lock) => {\n\t\t\tconst shared = heldSlots.get(file);\n\t\t\t// A hold whose slot another holder took meanwhile is lost, never shared: the record says who holds it (#4830).\n\t\t\tif (shared !== undefined && (await stillHolds(file, storeDir, shared))) {\n\t\t\t\tif (!sameOwner(shared.owner, owner)) return undefined;\n\t\t\t\tshared.references++;\n\t\t\t\treturn newLease(shared.record, storeDir, shared);\n\t\t\t}\n\t\t\tconst record = await readRecord(file, storeDir, slot.repository, slot.slot).catch(() => undefined);\n\t\t\tif (record === undefined || !sameOwner(record.holder, owner)) return undefined;\n\t\t\t// The lease comes first, so a claim or an eviction from here on sees the slot held; the record is then written\n\t\t\t// only in place of the one read, so a hold that lost the record lock while suspended, and a claimer took the slot\n\t\t\t// meanwhile, takes nothing back: it gives up its lease and its session restores elsewhere (#4991).\n\t\t\tif (!(await lock.held())) return undefined;\n\t\t\tconst taken = await takeSlot(file, owner, { ...record, releasedAt: null }, signal);\n\t\t\tlet put = false;\n\t\t\ttry {\n\t\t\t\tconst read = await takeRecord(file, record);\n\t\t\t\tif (read !== undefined) {\n\t\t\t\t\tif (await lock.held()) put = await putRecord(file, read, taken.record);\n\t\t\t\t\telse await giveBackRecord(file, read);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tawait taken.unlease().catch(() => {});\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (!put) {\n\t\t\t\tawait taken.unlease().catch(() => {});\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\theldSlots.set(file, taken);\n\t\t\treturn newLease(taken.record, storeDir, taken);\n\t\t},\n\t\tsignal,\n\t);\n}\n\n/**\n * Records the state a degraded restore published into a held slot, which differs from the admitted one. Writes only\n * while `lease` still holds the slot (#4830): resolves to false, writing nothing, once the lease was released or the\n * slot was lost to another holder.\n */\nexport async function recordPooledWorktreeState(lease: WorktreeLease, state: PoolLastState): Promise<boolean> {\n\tconst held = leaseHolds.get(lease);\n\tif (held === undefined) return false;\n\tconst file = recordFile(lease.storeDir, lease.repository, lease.slot);\n\treturn withSlotLock(file, true, async (lock) => {\n\t\tif (released.has(lease) || !(await stillHolds(file, lease.storeDir, held))) return false;\n\t\tif (!(await lock.held())) return false;\n\t\theld.record = { ...held.record, lastState: state };\n\t\tawait writeRecord(file, held.record);\n\t\treturn true;\n\t});\n}\n\n/**\n * Whether `lease` still holds its slot, checked against the slot's record under its lock (#4830): false once it was\n * released, or once another holder took the slot, as a claim does when a stalled holder's lease went stale. Then the\n * slot is another session's, and its former holder must not use it: it restores fresh instead. A lease another process\n * removed while the slot is still this holder's is taken again. When the record cannot be checked, the lease counts as\n * held unless it was removed. Never throws.\n */\nexport async function confirmPooledWorktreeLease(lease: WorktreeLease): Promise<boolean> {\n\tconst held = leaseHolds.get(lease);\n\tif (held === undefined || released.has(lease) || held.lost) return false;\n\tconst file = recordFile(lease.storeDir, lease.repository, lease.slot);\n\ttry {\n\t\treturn await withSlotLock(file, true, async () => {\n\t\t\tif (!(await stillHolds(file, lease.storeDir, held))) return false;\n\t\t\tif (held.compromised) {\n\t\t\t\theld.unlease = await leaseSlot(file, held);\n\t\t\t\theld.compromised = false;\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-confirm-failed\", { file, ...failureDebugFields(error) });\n\t\treturn !held.compromised;\n\t}\n}\n\n/**\n * Releases `lease`. When it was this process's last hold of the slot, this process's lease ends, and the record takes\n * `last` as the slot's known state, kept from the record when `last` is the snapshot the slot was restored or recorded\n * with. The slot becomes idle once no other process holds it either. A write failure keeps the record's earlier state,\n * which only makes the slot look changed, and the lease ends all the same. The record is written only while the lease\n * still holds the slot (#4830): a slot another holder took keeps its record. Resolves to false when the slot was lost,\n * and to true otherwise once the lease was this process's last hold, or another hold remains.\n */\nexport async function releaseRestoredWorktree(lease: WorktreeLease, last?: PoolLastState): Promise<boolean> {\n\tif (released.has(lease)) return false;\n\treleased.add(lease);\n\tconst held = leaseHolds.get(lease);\n\tif (held === undefined || held.lost) return false;\n\tconst file = recordFile(lease.storeDir, lease.repository, lease.slot);\n\tif (last !== undefined && last.snapshotId !== held.record.lastState.snapshotId) {\n\t\theld.record = { ...held.record, lastState: last };\n\t}\n\tlet counted = false;\n\tlet kept = false;\n\ttry {\n\t\tawait withSlotLock(file, true, async (lock) => {\n\t\t\tcounted = true;\n\t\t\tif (--held.references > 0) {\n\t\t\t\tkept = !held.lost;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\t// A slot another holder took while this one was stalled is its: this hold never writes it back (#4830).\n\t\t\t\tif (!(await stillHolds(file, lease.storeDir, held))) return;\n\t\t\t\tkept = true;\n\t\t\t\tconst idle = (await otherLeases(file, false)) === 0;\n\t\t\t\tif (!(await lock.held())) return;\n\t\t\t\tawait writeRecord(file, { ...held.record, releasedAt: idle ? new Date().toISOString() : null });\n\t\t\t} finally {\n\t\t\t\t// Inside the record lock, so a new hold in this process never meets this lease still taken.\n\t\t\t\tif (heldSlots.get(file) === held) heldSlots.delete(file);\n\t\t\t\tawait held.unlease().catch(() => {});\n\t\t\t}\n\t\t});\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-release-failed\", { file, ...failureDebugFields(error) });\n\t\t// The record lock was never taken: end this process's share all the same; the slot then only looks changed.\n\t\tif (!counted && --held.references <= 0) {\n\t\t\tif (heldSlots.get(file) === held) heldSlots.delete(file);\n\t\t\tawait held.unlease().catch(() => {});\n\t\t}\n\t}\n\treturn kept;\n}\n\n/**\n * Gives up the slot of `lease` whose worktree was never published or has been removed: deletes its record and ends this\n * process's lease, so the slot is free again, whatever other holds of it this process has. Never throws: a record left\n * behind belongs to a slot without a directory, which eviction removes.\n */\nexport async function discardPooledWorktree(lease: WorktreeLease): Promise<void> {\n\treleased.add(lease);\n\tconst held = leaseHolds.get(lease);\n\tif (held === undefined || held.lost) return;\n\tconst file = recordFile(lease.storeDir, lease.repository, lease.slot);\n\tconst end = async () => {\n\t\theld.lost = true;\n\t\tif (heldSlots.get(file) !== held) return;\n\t\theldSlots.delete(file);\n\t\tawait held.unlease().catch(() => {});\n\t};\n\ttry {\n\t\tawait withSlotLock(file, true, async (lock) => {\n\t\t\ttry {\n\t\t\t\t// A slot another holder took meanwhile keeps its record (#4830).\n\t\t\t\tif (heldSlots.get(file) === held && (await stillHolds(file, lease.storeDir, held)) && (await lock.held())) {\n\t\t\t\t\tawait rm(file, { force: true });\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tawait end();\n\t\t\t}\n\t\t});\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-discard-failed\", { file, ...failureDebugFields(error) });\n\t\tawait end();\n\t}\n}\n\nexport interface EvictIdleWorktreesOptions {\n\t/** Idle slots to keep: `snapshots.pool.maxIdlePerRepository`. */\n\treadonly maxIdle: number;\n\t/** The snapshot settings a slot's last state was recorded under, to tell an unchanged slot from a changed one. */\n\treadonly settings: WorktreeSnapshotSettings;\n\treadonly signal?: AbortSignal;\n}\n\n/** The readable records of the slots of `repository`. Rejects when the pool cannot be listed. */\nasync function slotRecords(storeDir: string, repository: RepositoryId): Promise<PoolSlotRecord[]> {\n\tconst records: PoolSlotRecord[] = [];\n\tfor (const name of await readdir(join(resolve(storeDir), \"pool\", repository))) {\n\t\tconst match = RECORD_NAME.exec(name);\n\t\tif (!match) continue;\n\t\tconst slot = Number(match[1]) as SlotNumber;\n\t\tconst record = await readRecord(recordFile(storeDir, repository, slot), storeDir, repository, slot).catch(\n\t\t\t() => undefined,\n\t\t);\n\t\tif (record !== undefined) records.push(record);\n\t}\n\treturn records;\n}\n\n/** The records of the slots of `repository` no live process holds. Rejects when the pool cannot be listed. */\nasync function idleRecords(storeDir: string, repository: RepositoryId): Promise<PoolSlotRecord[]> {\n\tconst idle: PoolSlotRecord[] = [];\n\tfor (const record of await slotRecords(storeDir, repository)) {\n\t\tif (!(await isHeld(recordFile(storeDir, repository, record.slot), true))) idle.push(record);\n\t}\n\treturn idle;\n}\n\n/** Newest released first; a slot whose holder stopped without releasing it counts as the oldest. */\nfunction byNewestRelease(a: PoolSlotRecord, b: PoolSlotRecord): number {\n\treturn (b.releasedAt ?? \"\").localeCompare(a.releasedAt ?? \"\") || a.slot - b.slot;\n}\n\n/**\n * Removes the oldest idle slots of `repository` beyond `maxIdle`, each under its record lock and only while no process\n * leases it: a slot whose directory\n * is gone loses its record, and a slot still exactly in its last state loses its worktree and record. A slot that\n * changed since, which may hold work no snapshot recorded, is kept. A slot a claim stopped resetting holds nothing but\n * recorded states and is never claimed, so it goes whatever `maxIdle` says. Resolves to the paths it removed; a failure\n * keeps that slot and never throws.\n */\nexport async function evictIdleWorktrees(\n\tstoreDir: string,\n\trepository: RepositoryId,\n\toptions: EvictIdleWorktreesOptions,\n): Promise<string[]> {\n\tlet idle: PoolSlotRecord[];\n\ttry {\n\t\tidle = await idleRecords(storeDir, repository);\n\t} catch (error) {\n\t\tconst directory = join(resolve(storeDir), \"pool\", repository);\n\t\treportDebug(\"storage\", \"worktree-pool-evict-failed\", { directory, ...failureDebugFields(error) });\n\t\treturn [];\n\t}\n\tconst removed: string[] = [];\n\tconst setAside: PoolSlotRecord[] = [];\n\tconst usable: PoolSlotRecord[] = [];\n\tfor (const record of idle) ((await worktreeSetAside(storeDir, record.path)) ? setAside : usable).push(record);\n\tfor (const record of setAside) {\n\t\tif (await processesWorkIn(record.path)) continue;\n\t\tif (await evictSlot(storeDir, record, options)) {\n\t\t\tremoved.push(record.path);\n\t\t\tsetAsideHere.delete(resolve(record.path));\n\t\t\tawait rm(setAsideFile(storeDir, record.path), { force: true }).catch(() => {});\n\t\t}\n\t}\n\tfor (const record of usable.filter((slot) => slot.resetting !== undefined)) {\n\t\tif (await evictSlot(storeDir, record, options)) removed.push(record.path);\n\t}\n\tconst kept = usable.filter((slot) => slot.resetting === undefined).sort(byNewestRelease);\n\tlet excess = kept.length - options.maxIdle;\n\tfor (const record of kept.reverse()) {\n\t\tif (excess <= 0) break;\n\t\tif (await evictSlot(storeDir, record, options)) {\n\t\t\tremoved.push(record.path);\n\t\t\texcess--;\n\t\t}\n\t}\n\treturn removed;\n}\n\nasync function evictSlot(storeDir: string, record: PoolSlotRecord, options: EvictIdleWorktreesOptions) {\n\tconst file = recordFile(storeDir, record.repository, record.slot);\n\ttry {\n\t\treturn await withSlotLock(\n\t\t\tfile,\n\t\t\tfalse,\n\t\t\tasync (lock) => {\n\t\t\t\tif (heldSlots.has(file)) return false;\n\t\t\t\tconst current = await readRecord(file, storeDir, record.repository, record.slot);\n\t\t\t\tif (current === undefined || (await otherLeases(file, true)) > 0) return false;\n\t\t\t\tlet store: string | undefined;\n\t\t\t\tif (await exists(current.path)) {\n\t\t\t\t\tconst stopped = current.resetting !== undefined;\n\t\t\t\t\tif (!stopped && !(await holdsRecordedStateOnly(current, options.settings, options.signal))) return false;\n\t\t\t\t\tstore = await pooledWorktreeStore(storeDir, current.path, options.signal);\n\t\t\t\t}\n\t\t\t\treturn removeSlot(file, current, store, lock);\n\t\t\t},\n\t\t\toptions.signal,\n\t\t);\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-evict-kept\", { path: record.path, ...failureDebugFields(error) });\n\t\treturn false;\n\t}\n}\n\n/**\n * Removes the slot of `current`, whose worktree, when it has one, belongs to `store` (#4991). Its record is taken aside\n * first, only while it is still `current`, the lock still this process's and no other process leases the slot, and the\n * worktree is moved aside in one rename; a holder that took the slot from a record read before then wrote it back, and\n * keeps it, worktree and all. Only then are the moved worktree and record deleted, which no hold, claim or admission\n * can reach: a process suspended while deleting them deletes nothing anyone holds.\n */\nasync function removeSlot(\n\tfile: string,\n\tcurrent: PoolSlotRecord,\n\tstore: string | undefined,\n\tlock: SlotLock,\n): Promise<boolean> {\n\tif (!(await lock.held())) return false;\n\tconst taken = await takeRecord(file, current);\n\tif (taken === undefined) return false;\n\tif ((await otherLeases(file, true)) > 0 || !(await lock.held())) {\n\t\tawait giveBackRecord(file, taken);\n\t\treturn false;\n\t}\n\tconst removed = store === undefined ? undefined : `${current.path}.removed-${randomUUID().slice(0, 8)}`;\n\ttry {\n\t\tif (removed !== undefined) await renameWithRetry(current.path, removed);\n\t} catch (error) {\n\t\tawait giveBackRecord(file, taken);\n\t\tthrow error;\n\t}\n\tif ((await exists(file)) || !(await lock.held())) {\n\t\tif (removed !== undefined) await renameWithRetry(removed, current.path);\n\t\tawait giveBackRecord(file, taken);\n\t\treturn false;\n\t}\n\tawait rm(taken, { force: true });\n\tif (removed !== undefined && store !== undefined) {\n\t\tawait rm(removed, { recursive: true, force: true });\n\t\tawait runGit([\"worktree\", \"prune\"], { cwd: dirname(store), env: { GIT_DIR: store } }).catch(() => {});\n\t}\n\treturn true;\n}\n\n/**\n * Whether the slot of `record` holds exactly its last state: its HEAD and policy tree, and nothing verification leaves\n * out that no snapshot recorded. Rejects when it cannot tell, as when the slot's HEAD or files changed.\n */\nasync function holdsRecordedStateOnly(\n\trecord: PoolSlotRecord,\n\tsettings: WorktreeSnapshotSettings,\n\tsignal: AbortSignal | undefined,\n): Promise<boolean> {\n\tconst { head, tree } = record.lastState;\n\tawait verifyWorktree({ remotes: [], head, tree, envHash: record.envHash }, record.path, { settings, signal });\n\treturn !(await holdsUnrecordedFiles(record.path, tree, signal));\n}\n\n/**\n * Why {@link claimIdleWorktree} took no slot. `foreign`: the slot's worktree belongs to another repository's object\n * store, as a slot an earlier version pooled under an identity several repositories shared may (#4989).\n */\nexport type NoIdleWorktreeReason =\n\t| \"none\"\n\t| \"busy\"\n\t| \"dirty\"\n\t| \"foreign\"\n\t| \"fetch-failed\"\n\t| \"reset-failed\"\n\t| \"verify-failed\";\n\nexport interface NoIdleWorktree {\n\treadonly claimed: false;\n\t/** Why the last candidate was not taken, or `none` when the repository has no idle slot. */\n\treadonly reason: NoIdleWorktreeReason;\n}\n\n/** A slot a claim reset to the snapshot, held for the claiming owner: release `lease` exactly once. */\nexport interface ClaimedWorktree {\n\treadonly claimed: true;\n\treadonly lease: WorktreeLease;\n\treadonly warnings: readonly WorktreeRestoreWarning[];\n}\n\nexport interface ClaimIdleWorktreeOptions {\n\treadonly storeDir: string;\n\treadonly owner: PoolOwner;\n\t/** The snapshot settings each slot's last state was recorded under, to tell an unchanged slot from a changed one. */\n\treadonly settings: WorktreeSnapshotSettings;\n\t/** Blob storage holding the snapshot's patches and bundle. */\n\treadonly blobs?: SnapshotBlobStore;\n\treadonly signal?: AbortSignal;\n}\n\n/**\n * Takes an idle slot of `snapshot`'s repository for `options.owner` and resets it to the snapshot (#4748), keeping the\n * files Git ignores, such as dependencies and build output, so the blueprint's maintenance has little to rebuild.\n * Candidates are the slots of the repository, those last restored for the snapshot's environment first, then the most\n * recently released; a slot a live process holds is busy. Only a slot that holds exactly its recorded last state, and\n * nothing no snapshot recorded, is taken, so its previous owner restores its snapshot elsewhere and loses nothing. The slot is marked before its files\n * change and unmarked once they verify, so a claim stopped half way leaves a slot no claim takes and eviction removes.\n * Only a slot of the snapshot's repository is a candidate, and only one whose worktree belongs to an object store of\n * that repository is taken (#4989): a snapshot of a checkout without remotes claims nothing. Resolves to the held slot\n * with HEAD and tree equal to the snapshot's, or to why none was taken: then the caller restores fresh. Rejects only\n * when `signal` aborted.\n */\nexport async function claimIdleWorktree(\n\tsnapshot: WorktreeSnapshot,\n\toptions: ClaimIdleWorktreeOptions,\n): Promise<ClaimedWorktree | NoIdleWorktree> {\n\tconst storeDir = resolve(options.storeDir);\n\t// Slots an earlier version admitted under the remotes as spelled are the repository's too (#4748), when that spelling\n\t// named this repository alone (#4989).\n\tconst repositories = sharedRepositoryIdsOf(snapshot.remotes, snapshot.root);\n\tconst stores = new Set(await Promise.all(repositories.map((repository) => repositoryStore(storeDir, repository))));\n\tconst candidates: PoolSlotRecord[] = [];\n\tfor (const repository of repositories) {\n\t\tcandidates.push(...(await slotRecords(storeDir, repository).catch(() => [])));\n\t}\n\tconst sameEnvironment = (record: PoolSlotRecord) => (record.envHash === snapshot.envHash ? 0 : 1);\n\tcandidates.sort((a, b) => sameEnvironment(a) - sameEnvironment(b) || byNewestRelease(a, b));\n\t// A slot a live process holds is busy: each candidate's lease is checked under its record lock.\n\tlet reason: NoIdleWorktreeReason = \"none\";\n\tfor (const candidate of candidates) {\n\t\toptions.signal?.throwIfAborted();\n\t\tconst outcome = await claimSlot(storeDir, candidate, snapshot, stores, options);\n\t\tif (outcome.claimed) return outcome;\n\t\treason = outcome.reason;\n\t}\n\toptions.signal?.throwIfAborted();\n\treturn { claimed: false, reason };\n}\n\n/** The object store, as a canonical path, that pooled worktrees of `repository` belong to. */\nfunction repositoryStore(storeDir: string, repository: RepositoryId): Promise<string> {\n\treturn canonicalizeWorktreePathAsync(join(storeDir, \"repositories\", `${repository}.git`));\n}\n\n/** Whether the worktree at `path` belongs to one of `stores`; false when that cannot be told. */\nasync function belongsTo(storeDir: string, path: string, stores: ReadonlySet<string>, signal?: AbortSignal) {\n\ttry {\n\t\treturn stores.has(await canonicalizeWorktreePathAsync(await pooledWorktreeStore(storeDir, path, signal)));\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function claimSlot(\n\tstoreDir: string,\n\tcandidate: PoolSlotRecord,\n\tsnapshot: WorktreeSnapshot,\n\tstores: ReadonlySet<string>,\n\toptions: ClaimIdleWorktreeOptions,\n): Promise<ClaimedWorktree | NoIdleWorktree> {\n\tconst file = recordFile(storeDir, candidate.repository, candidate.slot);\n\tconst target: PoolLastState = { snapshotId: snapshot.id, head: snapshot.head, tree: snapshot.tree };\n\tlet taken: { before: PoolSlotRecord; held: HeldSlot } | NoIdleWorktreeReason;\n\ttry {\n\t\t// The owner and the mark change with the lease, under the record lock, so the previous owner never holds the slot\n\t\t// again once the claim took it.\n\t\ttaken = await withSlotLock(\n\t\t\tfile,\n\t\t\tfalse,\n\t\t\tasync (lock) => {\n\t\t\t\t// A lease that went stale only a short while ago still keeps the slot: its holder may be writing to it (#4830).\n\t\t\t\tif (heldSlots.has(file) || (await otherLeases(file, true)) > 0) return \"busy\";\n\t\t\t\tconst before = await readRecord(file, storeDir, candidate.repository, candidate.slot);\n\t\t\t\tif (before === undefined || before.resetting !== undefined) return \"dirty\";\n\t\t\t\tif (await worktreeSetAside(storeDir, before.path)) return \"busy\";\n\t\t\t\t// Another repository's slot is never reset, nor marked: its record and files stay as they are (#4989).\n\t\t\t\tif (!(await belongsTo(storeDir, before.path, stores, options.signal))) return \"foreign\";\n\t\t\t\tif (!(await holdsRecordedStateOnly(before, options.settings, options.signal).catch(() => false))) {\n\t\t\t\t\treturn \"dirty\";\n\t\t\t\t}\n\t\t\t\t// Its owner may have held the slot again while this process was suspended past the lock's stale time: the mark\n\t\t\t\t// replaces only the record checked, taken aside and compared, and never one a holder wrote meanwhile (#4991).\n\t\t\t\tif (!(await lock.held())) return \"busy\";\n\t\t\t\tconst taken = await takeRecord(file, before);\n\t\t\t\tif (taken === undefined) return \"busy\";\n\t\t\t\tif ((await otherLeases(file, true)) > 0 || !(await lock.held())) {\n\t\t\t\t\tawait giveBackRecord(file, taken);\n\t\t\t\t\treturn \"busy\";\n\t\t\t\t}\n\t\t\t\tconst marked: PoolSlotRecord = {\n\t\t\t\t\t...before,\n\t\t\t\t\tholder: options.owner,\n\t\t\t\t\treleasedAt: null,\n\t\t\t\t\tresetting: target,\n\t\t\t\t\ttenancy: randomUUID(),\n\t\t\t\t};\n\t\t\t\tlet held: HeldSlot;\n\t\t\t\ttry {\n\t\t\t\t\theld = await takeSlot(file, options.owner, marked, options.signal);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tawait giveBackRecord(file, taken);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tlet put: boolean;\n\t\t\t\ttry {\n\t\t\t\t\tput = await putRecord(file, taken, marked);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tawait held.unlease().catch(() => {});\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tif (!put) {\n\t\t\t\t\tawait held.unlease().catch(() => {});\n\t\t\t\t\treturn \"busy\";\n\t\t\t\t}\n\t\t\t\theldSlots.set(file, held);\n\t\t\t\treturn { before, held };\n\t\t\t},\n\t\t\toptions.signal,\n\t\t);\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-claim-skipped\", { file, ...failureDebugFields(error) });\n\t\treturn { claimed: false, reason: (error as NodeJS.ErrnoException).code === \"ELOCKED\" ? \"busy\" : \"dirty\" };\n\t}\n\tif (typeof taken === \"string\") return { claimed: false, reason: taken };\n\tconst { before, held } = taken;\n\tlet resetting = false;\n\ttry {\n\t\tconst warnings = await resetPooledWorktree(snapshot, before.path, before.lastState, {\n\t\t\tstoreDir,\n\t\t\tblobs: options.blobs,\n\t\t\tsignal: options.signal,\n\t\t\tbeforeReset: async () => {\n\t\t\t\tresetting = true;\n\t\t\t},\n\t\t});\n\t\tconst claimed: PoolSlotRecord = {\n\t\t\t...before,\n\t\t\tholder: options.owner,\n\t\t\tlastState: target,\n\t\t\tenvHash: snapshot.envHash,\n\t\t\treleasedAt: null,\n\t\t\ttenancy: held.record.tenancy,\n\t\t};\n\t\t// A claim stalled past its lease may have lost the slot meanwhile: then the slot is not its to record (#4830).\n\t\tconst kept = await withSlotLock(file, true, async (lock) => {\n\t\t\tif (!(await stillHolds(file, storeDir, held))) return false;\n\t\t\tif (!(await lock.held())) return false;\n\t\t\tawait writeRecord(file, claimed);\n\t\t\treturn true;\n\t\t});\n\t\tif (!kept) {\n\t\t\t// The slot stays marked: no claim takes it, and eviction removes it once this lease ends.\n\t\t\tif (heldSlots.get(file) === held) heldSlots.delete(file);\n\t\t\tawait held.unlease().catch(() => {});\n\t\t\treturn { claimed: false, reason: \"busy\" };\n\t\t}\n\t\theld.record = claimed;\n\t\treturn { claimed: true, lease: newLease(claimed, storeDir, held), warnings };\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-claim-failed\", { file, ...failureDebugFields(error) });\n\t\t// A slot whose files never changed goes back to its owner as it was; one changed half way stays marked.\n\t\tconst end = async () => {\n\t\t\tif (heldSlots.get(file) === held) heldSlots.delete(file);\n\t\t\tawait held.unlease().catch(() => {});\n\t\t};\n\t\ttry {\n\t\t\tawait withSlotLock(file, true, async (lock) => {\n\t\t\t\ttry {\n\t\t\t\t\t// A slot another holder took meanwhile is never handed back to its previous owner (#4830).\n\t\t\t\t\tif (!resetting && (await stillHolds(file, storeDir, held)) && (await lock.held())) {\n\t\t\t\t\t\tawait writeRecord(file, before);\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tawait end();\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (cause) {\n\t\t\treportDebug(\"storage\", \"worktree-pool-claim-undo-failed\", { file, ...failureDebugFields(cause) });\n\t\t\tawait end();\n\t\t}\n\t\tconst verifyFailed = isWorkspaceRestoreError(error) && error.code === \"tree-mismatch\";\n\t\treturn { claimed: false, reason: !resetting ? \"fetch-failed\" : verifyFailed ? \"verify-failed\" : \"reset-failed\" };\n\t}\n}\n\n/**\n * Whether the worktree at `path` holds files its recorded `tree` does not, that verification leaves out: staged content\n * that is neither HEAD's nor the tree's, a tracked file whose content is neither HEAD's nor the tree's, as an edit to a\n * file snapshots omit, such as a tracked `.env.example`, one under `.atomic/snapshot-ignore` or one over the size cap\n * (#4897), an untracked file outside the tree, as when untracked files are not captured or are on the deny list, or an ignored file on the\n * deny list, such as `.env`. Other ignored files, build output and dependencies, are rebuilt and may go.\n */\nasync function holdsUnrecordedFiles(path: string, tree: string, signal: AbortSignal | undefined): Promise<boolean> {\n\tconst git = { cwd: path, signal };\n\t// Staged content lives only in the index: it is recorded only when it is HEAD's or the recorded tree's.\n\tconst stagedDiffers = async (base: string) =>\n\t\t(await runGit([\"diff\", \"--cached\", \"--quiet\", base, \"--\"], { ...git, allowExitCodes: [1] })).exitCode !== 0;\n\tif ((await stagedDiffers(\"HEAD\")) && (await stagedDiffers(tree))) return true;\n\t// Verification compares omitted files as HEAD's, so a tracked file is checked against the tree itself: one that\n\t// changed since HEAD is recorded only when the tree holds its content (#4897).\n\tconst changedFrom = async (base: string) =>\n\t\tnulFields((await runGit([\"diff\", \"--name-only\", \"-z\", \"--no-renames\", \"--no-ext-diff\", base, \"--\"], git)).stdout);\n\tconst changed = await changedFrom(\"HEAD\");\n\tif (changed.length > 0) {\n\t\tconst unrecorded = new Set(await changedFrom(tree));\n\t\tif (changed.some((file) => unrecorded.has(file))) return true;\n\t}\n\tconst recorded = new Set(nulFields((await runGit([\"ls-tree\", \"-r\", \"-z\", \"--name-only\", tree], git)).stdout));\n\tconst untracked = nulFields((await runGit([\"ls-files\", \"-z\", \"--others\", \"--exclude-standard\"], git)).stdout);\n\tif (untracked.some((file) => !recorded.has(file))) return true;\n\tconst ignored = nulFields(\n\t\t(await runGit([\"ls-files\", \"-z\", \"--others\", \"--ignored\", \"--exclude-standard\", \"--directory\"], git)).stdout,\n\t);\n\treturn ignored.some((file) => !file.endsWith(\"/\") && isDeniedSnapshotPath(file));\n}\n"]}
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,UAAU,IAAI,iBAAiB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAqB,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,0B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AAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/D,MAAM,OAAO,GAAG,SAAS,CACxB,CAAC,MAAM,MAAM,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,EAAE,aAAa,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAC5G,CAAC;IACF,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC;AAClF,CAAC","sourcesContent":["import { createHash, randomUUID } from \"node:crypto\";\nimport { link, mkdir, readdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, join, resolve, toNamespacedPath } from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\nimport { failureDebugFields, reportDebugAsync as reportDebug } from \"../debug.ts\";\nimport { renameWithRetry } from \"../rename-retry.ts\";\nimport { isWorkspaceRestoreError } from \"./errors.ts\";\nimport { nulFields, runGit } from \"./git.ts\";\nimport { processesWorkIn } from \"./in-use.ts\";\nimport { canonicalizeWorktreePathAsync } from \"./paths.ts\";\nimport { isDeniedSnapshotPath } from \"./policy.ts\";\nimport { HOST, holderRuns as processHolderRuns, thisProcess } from \"./process-holder.js\";\nimport { type RepositoryId, sharedRepositoryIdOf, sharedRepositoryIdsOf } from \"./repository-identity.ts\";\nimport { pooledWorktreeStore, resetPooledWorktree, verifyWorktree } from \"./restore.ts\";\nimport { lockShared, sharedClockNow, windowsTemporaryFiles } from \"./shared-clock.ts\";\nimport type { SnapshotBlobStore, WorktreeRestoreWarning, WorktreeSnapshot, WorktreeSnapshotSettings } from \"./types.ts\";\n\nexport { processStartToken } from \"../process-start-token.js\";\n\n/**\n * The per-machine pool of restored worktrees (#4748). A session resume restores into a slot at a stable path,\n * `<storeDir>/worktrees/<repositoryId>-<n>`, described by one record, `<storeDir>/pool/<repositoryId>/<n>.json`, and\n * leased while a session works in it: each process that holds a slot has a lease lock of its own next to the record,\n * and a lock on the record itself serializes changes to the slot. Only session resumes admit slots: worktrees restored\n * for workflow runs, by the SDK into a chosen directory, or by earlier versions have no record and are never pooled.\n *\n * A slot's owner is the holder that last took it, whether it still holds the lease or released it when it closed;\n * only the owner continues in it. {@link claimIdleWorktree} is the one way an existing worktree is rewritten: it takes\n * an idle slot that holds nothing but its recorded state for another snapshot, and the slot's owner with it.\n *\n * Only checkouts of one repository share slots (#4989): those whose remotes name it, local paths resolved against the\n * checkout's root. A checkout without remotes is never pooled: nothing on record tells its repository apart from\n * another remote-less one, so its slots and their ignored files, such as secrets and dependencies, would go to them.\n */\n\nexport type { RepositoryId } from \"./repository-identity.ts\";\nexport { repositoryIdOf } from \"./repository-identity.ts\";\n\nexport type SlotNumber = number & { readonly __brand: \"SlotNumber\" };\n\n/** Who holds a slot: a session, by its id, or a prebuild. */\nexport interface PoolOwner {\n\treadonly kind: \"session\" | \"prebuild\";\n\treadonly id: string;\n}\n\n/** The state a slot was left in: its HEAD and policy tree, and the snapshot that recorded them when known. */\nexport interface PoolLastState {\n\treadonly snapshotId: string | null;\n\treadonly head: string;\n\treadonly tree: string;\n}\n\nexport interface PoolSlotRecord {\n\treadonly version: 1;\n\treadonly repository: RepositoryId;\n\treadonly slot: SlotNumber;\n\treadonly path: string;\n\treadonly holder: PoolOwner;\n\treadonly lastState: PoolLastState;\n\treadonly envHash: string;\n\treadonly blueprintDigest: string | null;\n\t/** When the holder released the slot; null while it is held, or when its holder stopped without releasing it. */\n\treadonly releasedAt: string | null;\n\t/**\n\t * The state a claim is resetting the slot to, set before its files change and cleared once they verify: a slot that\n\t * still has it holds a mix of two recorded states, never anything else, and is never claimed.\n\t */\n\treadonly resetting?: PoolLastState;\n\t/**\n\t * Names the take of the slot by its holder (#4830): a new one each time a holder admits or claims the slot, kept when\n\t * the same holder holds it again. A process whose copy of the record no longer matches it lost the slot. Records\n\t * written before #4830 have none.\n\t */\n\treadonly tenancy?: string;\n}\n\n/** What a session resume restores into a new slot. */\nexport interface PoolAdmission {\n\treadonly storeDir: string;\n\treadonly remotes: readonly string[];\n\t/** The checkout's root, which relative-path remotes such as `../upstream` are relative to (#4989). */\n\treadonly root?: string;\n\t/** The state the restore is about to publish. */\n\treadonly lastState: PoolLastState;\n\treadonly envHash: string;\n\treadonly signal?: AbortSignal;\n}\n\n/** A slot this process holds for an owner. Release it exactly once. */\nexport interface WorktreeLease {\n\treadonly storeDir: string;\n\treadonly repository: RepositoryId;\n\treadonly slot: SlotNumber;\n\treadonly path: string;\n\treadonly owner: PoolOwner;\n}\n\n/** Who owns the worktree at a path: no pool record (`\"unpooled\"`), or its owner and whether a live process holds it. */\nexport type PooledWorktreeHolder =\n\t| \"unpooled\"\n\t| {\n\t\t\t/** The holder that last took the slot; null when its record cannot be read, which no session owns. */\n\t\t\treadonly owner: PoolOwner | null;\n\t\t\treadonly held: boolean;\n\t };\n\n/** `snapshots.pool` settings. */\nexport interface WorktreePoolSettings {\n\t/** Idle pooled worktrees kept per repository; the oldest unchanged ones beyond it are removed. Default 2. */\n\treadonly maxIdlePerRepository: number;\n}\n\n/** Default of `snapshots.pool.maxIdlePerRepository`. */\nexport const DEFAULT_MAX_IDLE_PER_REPOSITORY = 2;\n\n/** The lease constants of restore records: a stopped process loses its lease after 30 seconds. */\nconst LEASE_STALE_MS = 30_000;\nconst LEASE_UPDATE_MS = 10_000;\nconst POOL_LOCK_POLL_MS = 50;\nconst POOL_LOCK_WAIT_MS = 60_000;\nexport const POOL_LOCK_REFUSED_MS = 10_000;\n/**\n * How long after a lease went stale it still keeps its slot from being claimed or evicted, and its lock from being\n * removed (#4830): a holder stalled for a short while, by an overloaded host or a debugger, keeps its slot and its lease.\n * Only a lease last refreshed more than `LEASE_STALE_MS + LEASE_CLAIM_GRACE_MS` ago lets another process take the slot.\n */\nexport const LEASE_CLAIM_GRACE_MS = 60_000;\n/**\n * How long a lease of this host that names no start of its process keeps its slot without being refreshed while a\n * process of its id runs (#4990): such a lease, written where the start cannot be read or before #4990, cannot tell its\n * holder from a later process given the same id after a container restart or a reboot, so past this it is judged by\n * its age alone. A lease that names its holder's start is kept for as long as that process runs, however long it was\n * suspended.\n */\nexport const UNSTARTED_LEASE_LIMIT_MS = 24 * 60 * 60_000;\nconst SLOT_NAME = /^([0-9a-f]{24})-(\\d{1,6})$/;\nconst RECORD_NAME = /^(\\d{1,6})\\.json$/;\n\nexport function pooledWorktreePath(storeDir: string, repository: RepositoryId, slot: SlotNumber): string {\n\treturn join(resolve(storeDir), \"worktrees\", `${repository}-${slot}`);\n}\n\nfunction recordFile(storeDir: string, repository: RepositoryId, slot: SlotNumber): string {\n\treturn join(resolve(storeDir), \"pool\", repository, `${slot}.json`);\n}\n\ninterface HeldSlot {\n\treadonly owner: PoolOwner;\n\treferences: number;\n\t/** The record as this process last wrote it: its holder and tenancy say whose the slot is. */\n\trecord: PoolSlotRecord;\n\t/** Releases this process's lease of the slot. */\n\tunlease: () => Promise<void>;\n\t/** Another process removed this process's lease once it went stale: the slot may have been taken (#4830). */\n\tcompromised: boolean;\n\t/** The slot was taken from this hold, or its record removed: nothing of the hold writes to it again (#4830). */\n\tlost: boolean;\n}\n\n/** The slots this process holds, by record file. A second hold of a slot by its owner shares the lease. */\nconst heldSlots = new Map<string, HeldSlot>();\n/** The hold each lease of this process shares. */\nconst leaseHolds = new WeakMap<WorktreeLease, HeldSlot>();\nconst released = new WeakSet<WorktreeLease>();\nlet processLease: Promise<string> | undefined;\n/**\n * Names this process's leases: its host and pid, a random part, as the pid alone could be reused by a later process,\n * and when this process started, where that can be read (#4990, #5141). Read once, on first use.\n */\nfunction ownLease(): Promise<string> {\n\tprocessLease ??= thisProcess().then(\n\t\t({ start: started }) =>\n\t\t\t`${HOST}-${process.pid}-${randomUUID().slice(0, 8)}${started === undefined ? \"\" : `-${started}`}`,\n\t);\n\treturn processLease;\n}\n/**\n * A lease name after the record's: the holder's host and pid, and when the holder started. Leases written before\n * #4830 name no host, and those written before #4990 no start.\n */\nconst LEASE_NAME = /^([0-9a-f]{12})-(\\d+)-[0-9a-f]{8}(?:-([0-9a-f]{12}))?\\.lease\\.lock$/;\n\n/**\n * Whether the lease named `name` belongs to a process of this host that still runs (#4830): a holder stalled for\n * minutes may still write to its slot. A process this one may not signal runs too. A lease that names when its holder\n * started belongs to a process of that id that started then, never to a later one given the id (#4990), on Windows too\n * (#5141). A lease of another host, or one naming no host, is judged by its age alone.\n */\nasync function holderRuns(name: string, age: number): Promise<boolean> {\n\tconst lease = LEASE_NAME.exec(name);\n\tif (lease === null) return false;\n\treturn processHolderRuns({ host: lease[1]!, pid: Number(lease[2]), start: lease[3] }, age, UNSTARTED_LEASE_LIMIT_MS);\n}\n\nfunction sameOwner(a: PoolOwner, b: PoolOwner): boolean {\n\treturn a.kind === b.kind && a.id === b.id;\n}\n\nexport interface SetAsideNote {\n\treadonly startedAt: string;\n\treadonly logs: string;\n}\n\nconst setAsideHere = new Map<string, string | undefined>();\n\nfunction setAsideFile(storeDir: string, path: string): string {\n\tconst key = createHash(\"sha256\").update(resolve(path)).digest(\"hex\").slice(0, 16);\n\treturn join(resolve(storeDir), \"pool\", \"set-aside\", `${key}.json`);\n}\n\nasync function directoryIdentity(path: string): Promise<string | undefined> {\n\ttry {\n\t\tconst found = await stat(path);\n\t\treturn `${found.dev}:${found.ino}:${Math.trunc(found.birthtimeMs)}`;\n\t} catch (error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\tif (code === \"ENOENT\" || code === \"ENOTDIR\") return undefined;\n\t\tthrow error;\n\t}\n}\n\nexport async function setAsideWorktree(storeDir: string, path: string, note: SetAsideNote): Promise<void> {\n\tconst directory = await directoryIdentity(path).catch(() => undefined);\n\tsetAsideHere.set(resolve(path), directory);\n\tconst file = setAsideFile(storeDir, path);\n\tawait mkdir(dirname(file), { recursive: true });\n\tconst temporary = `${file}.${randomUUID()}.tmp`;\n\tawait writeFile(temporary, JSON.stringify({ path: resolve(path), directory, ...note }), { mode: 0o600 });\n\tawait renameWithRetry(temporary, file);\n}\n\nasync function readSetAsideNote(\n\tstoreDir: string,\n\tpath: string,\n): Promise<(Partial<SetAsideNote> & { directory?: unknown }) | \"absent\" | \"unreadable\"> {\n\tlet text: string;\n\ttry {\n\t\ttext = await readFile(setAsideFile(storeDir, path), \"utf8\");\n\t} catch (error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code === \"ENOENT\" || code === \"ENOTDIR\" ? \"absent\" : \"unreadable\";\n\t}\n\ttry {\n\t\tconst note = JSON.parse(text) as unknown;\n\t\treturn typeof note === \"object\" && note !== null ? note : {};\n\t} catch {\n\t\treturn {};\n\t}\n}\n\nasync function sameDirectory(path: string, directory: unknown): Promise<boolean> {\n\tif (typeof directory !== \"string\") return true;\n\ttry {\n\t\treturn (await directoryIdentity(path)) === directory;\n\t} catch {\n\t\treturn true;\n\t}\n}\n\nexport async function worktreeSetAside(storeDir: string, path: string): Promise<boolean> {\n\tif (setAsideHere.has(resolve(path)) && (await sameDirectory(path, setAsideHere.get(resolve(path))))) return true;\n\tconst note = await readSetAsideNote(storeDir, path);\n\tif (note === \"absent\") return false;\n\tif (note === \"unreadable\") return true;\n\treturn sameDirectory(path, note.directory);\n}\n\nasync function exists(path: string): Promise<boolean> {\n\ttry {\n\t\tawait stat(path);\n\t\treturn true;\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return false;\n\t\tthrow error;\n\t}\n}\n\nfunction refusedForAMoment(error: unknown, since: number): boolean {\n\treturn (\n\t\t(error as NodeJS.ErrnoException).code === \"EPERM\" &&\n\t\tprocess.platform === \"win32\" &&\n\t\tDate.now() - since < POOL_LOCK_REFUSED_MS\n\t);\n}\n\nfunction lockHeldAndWaiting(error: unknown, wait: boolean, startedAt: number): boolean {\n\treturn wait && (error as NodeJS.ErrnoException).code === \"ELOCKED\" && Date.now() - startedAt < POOL_LOCK_WAIT_MS;\n}\n\n/**\n * Locks `path` with the restore-record constants: a stopped process loses the lock after 30 seconds. `wait` retries a\n * lock another process holds for up to 60 seconds with 50 ms polls, as when a slot's record is briefly being written.\n */\nasync function lockPath(\n\tpath: string,\n\twait: boolean,\n\tonLost?: (error: Error) => void,\n\tsignal?: AbortSignal,\n): Promise<() => Promise<void>> {\n\tconst startedAt = Date.now();\n\tlet refusedSince: number | undefined;\n\tfor (;;) {\n\t\tsignal?.throwIfAborted();\n\t\ttry {\n\t\t\treturn await lockShared(path, {\n\t\t\t\trealpath: false,\n\t\t\t\tstale: LEASE_STALE_MS,\n\t\t\t\tupdate: LEASE_UPDATE_MS,\n\t\t\t\tretries: 0,\n\t\t\t\tonCompromised: (error) => {\n\t\t\t\t\treportDebug(\"storage\", \"worktree-pool-lock-lost\", { path, ...failureDebugFields(error) });\n\t\t\t\t\tonLost?.(error);\n\t\t\t\t},\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconst since = refusedSince ?? Date.now();\n\t\t\tif (refusedForAMoment(error, since)) refusedSince = since;\n\t\t\telse if (lockHeldAndWaiting(error, wait, startedAt)) refusedSince = undefined;\n\t\t\telse throw error;\n\t\t}\n\t\tawait sleep(POOL_LOCK_POLL_MS, undefined, { signal });\n\t}\n}\n\n/** A slot's record lock as {@link withSlotLock} holds it. */\ninterface SlotLock {\n\t/**\n\t * Whether this process still holds the lock (#4991): false once it was compromised, or once another process broke it\n\t * as stale and took it, as while this one was suspended past the stale time. Checked right before each change to\n\t * the slot, its record or its files, which is never made without the lock.\n\t */\n\theld(): Promise<boolean>;\n}\n\n/**\n * Where the holder of the slot's record lock `file` names its take of the lock: a random token each take writes once it\n * holds the lock, so a process that lost the lock to another, even to a new lock directory at the same place, reads\n * another token or none (#4991). It sits beside the lock directory, which must stay empty for a stale lock to be\n * removable.\n */\nfunction lockTokenFile(file: string): string {\n\treturn `${file}.lock-holder`;\n}\n\nasync function readLockToken(file: string): Promise<string | undefined> {\n\ttry {\n\t\treturn await readFile(lockTokenFile(file), \"utf8\");\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Runs `action` holding the slot's record lock, which serializes changes to one slot across processes: leases are\n * taken and released, and slots evicted, only under it. Without `wait`, a busy slot rejects with `ELOCKED`. The lock is\n * only removed while this process still holds it, so a lock another process took over is never removed under it.\n */\nasync function withSlotLock<T>(\n\tfile: string,\n\twait: boolean,\n\taction: (lock: SlotLock) => Promise<T>,\n\tsignal?: AbortSignal,\n): Promise<T> {\n\tlet lost = false;\n\tconst unlock = await lockPath(\n\t\tfile,\n\t\twait,\n\t\t() => {\n\t\t\tlost = true;\n\t\t},\n\t\tsignal,\n\t);\n\tconst token = randomUUID();\n\tlet named = false;\n\ttry {\n\t\tconst temporary = `${lockTokenFile(file)}.${await ownLease()}.tmp`;\n\t\tawait writeFile(temporary, token, { mode: 0o600 });\n\t\tawait renameWithRetry(temporary, lockTokenFile(file));\n\t\tnamed = true;\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-lock-token-failed\", { file, ...failureDebugFields(error) });\n\t}\n\tconst lock: SlotLock = { held: async () => named && !lost && (await readLockToken(file)) === token };\n\ttry {\n\t\treturn await action(lock);\n\t} finally {\n\t\tif (!named) await unlock().catch(() => {});\n\t\telse if (await lock.held()) {\n\t\t\tawait rm(lockTokenFile(file), { force: true }).catch(() => {});\n\t\t\tawait unlock().catch(() => {});\n\t\t}\n\t}\n}\n\n/**\n * Moves the record at `file` aside when it still is `expected`, in one rename no other writer interleaves with, and\n * resolves to where it went; a record that changed, or is gone, is put back as it is and resolves to undefined (#4991).\n * Until {@link giveBackRecord} or {@link putRecord}, the slot has no record: no hold, claim or eviction takes it.\n */\nasync function takeRecord(file: string, expected: PoolSlotRecord): Promise<string | undefined> {\n\tconst taken = `${file}.${await ownLease()}.taken`;\n\ttry {\n\t\tawait renameWithRetry(file, taken);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n\t\tthrow error;\n\t}\n\tconst text = await readFile(taken, \"utf8\").catch(() => undefined);\n\tlet same = false;\n\ttry {\n\t\tsame = text !== undefined && JSON.stringify(JSON.parse(text)) === JSON.stringify(expected);\n\t} catch {\n\t\tsame = false;\n\t}\n\tif (same) return taken;\n\tawait giveBackRecord(file, taken);\n\treturn undefined;\n}\n\n/** Puts a taken record back, unless a writer wrote the slot's record meanwhile: then that record stands. */\nasync function giveBackRecord(file: string, taken: string): Promise<void> {\n\ttry {\n\t\tawait link(taken, file);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"EEXIST\") throw error;\n\t}\n\tawait rm(taken, { force: true });\n}\n\n/**\n * Writes `record` as the slot's record in place of the one {@link takeRecord} moved to `taken`, only when no writer\n * wrote one meanwhile; resolves to false, writing nothing, when one did, whose record stands (#4991).\n */\nasync function putRecord(file: string, taken: string, record: PoolSlotRecord): Promise<boolean> {\n\ttry {\n\t\tconst published = await createRecord(file, record);\n\t\tawait rm(taken, { force: true }).catch((error) => {\n\t\t\treportDebug(\"storage\", \"worktree-pool-taken-cleanup-failed\", { file, ...failureDebugFields(error) });\n\t\t});\n\t\treturn published;\n\t} catch (error) {\n\t\tawait giveBackRecord(file, taken).catch(() => {});\n\t\tthrow error;\n\t}\n}\n\n/** The error an action that lost its slot's record lock stops with, which callers treat as a busy slot (#4991). */\nfunction lockLostError(file: string): NodeJS.ErrnoException {\n\treturn Object.assign(new Error(`lost the record lock of ${file}`), { code: \"ELOCKED\" });\n}\n\n/**\n * Takes this process's lease of the slot whose record is `file` for `held`: a lock of its own, so other processes can\n * share it. Losing the lock marks `held` compromised. Ending the lease removes its lock even once it was compromised.\n */\nasync function leaseSlot(\n\tfile: string,\n\theld: Pick<HeldSlot, \"compromised\">,\n\tsignal?: AbortSignal,\n): Promise<() => Promise<void>> {\n\tconst lease = `${file}.${await ownLease()}.lease`;\n\tconst unlock = await lockPath(\n\t\tlease,\n\t\tfalse,\n\t\t() => {\n\t\t\theld.compromised = true;\n\t\t},\n\t\tsignal,\n\t);\n\treturn () => unlock().catch(() => rm(`${lease}.lock`, { recursive: true, force: true }));\n}\n\n/** A hold of the slot whose record is `file` for `owner`, with this process's lease of it taken. */\nasync function takeSlot(\n\tfile: string,\n\towner: PoolOwner,\n\trecord: PoolSlotRecord,\n\tsignal?: AbortSignal,\n): Promise<HeldSlot> {\n\tconst held: HeldSlot = { owner, references: 1, record, unlease: async () => {}, compromised: false, lost: false };\n\theld.unlease = await leaseSlot(file, held, signal);\n\treturn held;\n}\n\n/**\n * The leases other processes hold on the slot whose record is `file`, removing those last refreshed more than\n * {@link LEASE_CLAIM_GRACE_MS} after they went stale. A lease that cannot be read counts as held, and so does one whose\n * holder still runs on this host, as {@link holderRuns} tells (#4990). With `grace`, as before a\n * claim or an eviction, a lease that went stale within the grace period counts as held too (#4830).\n */\nasync function otherLeases(file: string, grace: boolean): Promise<number> {\n\tconst prefix = `${basename(file)}.`;\n\tconst own = `${basename(file)}.${await ownLease()}.lease.lock`;\n\tlet live = 0;\n\t// Ages are measured by the clock of the filesystem holding the leases, which their holders stamp refreshes in, so a\n\t// holder on a host whose clock is off is judged by when it last refreshed its lease (#5050).\n\tconst now = await sharedClockNow(dirname(file));\n\tfor (const name of await readdir(dirname(file))) {\n\t\tif (!name.startsWith(prefix) || !name.endsWith(\".lease.lock\") || name === own) continue;\n\t\tconst lock = join(dirname(file), name);\n\t\tlet age: number;\n\t\ttry {\n\t\t\tage = now - (await stat(lock)).mtimeMs;\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") live++;\n\t\t\tcontinue;\n\t\t}\n\t\tconst expired = age > LEASE_STALE_MS + LEASE_CLAIM_GRACE_MS;\n\t\tif (age <= LEASE_STALE_MS || (grace && !expired) || (await holderRuns(name.slice(prefix.length), age))) live++;\n\t\telse if (expired) await rm(lock, { recursive: true, force: true }).catch(() => {});\n\t}\n\treturn live;\n}\n\n/**\n * Whether a live process holds the slot whose record is `file`: this one, or another whose lease is not stale or, with\n * `grace`, went stale within the grace period.\n */\nasync function isHeld(file: string, grace: boolean): Promise<boolean> {\n\tif (heldSlots.has(file)) return true;\n\treturn (await otherLeases(file, grace).catch(() => 1)) > 0;\n}\n\n/**\n * Under the slot's record lock: whether `held` still holds the slot, its record naming the same holder and tenancy as\n * this process's copy (#4830). When it does not, as when another process claimed the slot while this one was stalled,\n * the hold is lost: this process's lease ends, and nothing of the hold writes to the slot again. A record that is there\n * but cannot be read rejects, keeping the hold.\n */\nasync function stillHolds(file: string, storeDir: string, held: HeldSlot): Promise<boolean> {\n\tif (held.lost) return false;\n\tconst { repository, slot } = held.record;\n\tlet current: PoolSlotRecord | undefined;\n\ttry {\n\t\tcurrent = await readRecord(file, storeDir, repository, slot);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n\t}\n\tif (current !== undefined && sameOwner(current.holder, held.owner) && current.tenancy === held.record.tenancy) {\n\t\treturn true;\n\t}\n\theld.lost = true;\n\tif (heldSlots.get(file) === held) heldSlots.delete(file);\n\tawait held.unlease().catch(() => {});\n\treportDebug(\"storage\", \"worktree-pool-slot-lost\", { file, holder: current?.holder.id ?? null });\n\treturn false;\n}\n\nasync function writeRecord(file: string, record: PoolSlotRecord): Promise<void> {\n\tconst temporary = `${file}.${await ownLease()}.tmp`;\n\tawait writeFile(temporary, JSON.stringify(record), { mode: 0o600 });\n\tawait renameWithRetry(temporary, file);\n}\n\nasync function createRecord(file: string, record: PoolSlotRecord): Promise<boolean> {\n\tconst temporary = `${file}.${randomUUID()}.tmp`;\n\tconst windows = process.platform === \"win32\";\n\tconst data = JSON.stringify(record);\n\tlet created = false;\n\tlet published = false;\n\tlet original: import(\"@bastani/atomic-natives\").WindowsFileIdentity | null | undefined;\n\ttry {\n\t\t// Let the runtime apply its actual umask at creation and write through the handle granted there.\n\t\ttry {\n\t\t\tawait writeFile(temporary, data, { mode: 0o600, flag: windows ? \"wx\" : \"w\" });\n\t\t\tcreated = true;\n\t\t} catch (error) {\n\t\t\tconst { code, syscall } = error as NodeJS.ErrnoException;\n\t\t\tcreated = code !== \"EEXIST\" && syscall !== \"open\";\n\t\t\tthrow error;\n\t\t}\n\t\tconst binding = windowsTemporaryFiles();\n\t\tif (binding) original = await binding.pinWindowsFile(toNamespacedPath(temporary)).catch(() => null);\n\t\ttry {\n\t\t\tawait link(temporary, file);\n\t\t\tpublished = true;\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tif ((error as NodeJS.ErrnoException).code === \"EEXIST\") return false;\n\t\t\tthrow error;\n\t\t}\n\t} finally {\n\t\ttry {\n\t\t\tif (created || !windows) await rm(temporary, { force: true });\n\t\t} catch (error) {\n\t\t\tconst { code } = error as NodeJS.ErrnoException;\n\t\t\tconst refused = code === \"EPERM\" || code === \"EACCES\" || code === \"EBUSY\";\n\t\t\tif (\n\t\t\t\t!published ||\n\t\t\t\t!refused ||\n\t\t\t\t!original ||\n\t\t\t\t!(await original.removeHardLink(toNamespacedPath(temporary), toNamespacedPath(file)).catch(() => false))\n\t\t\t) {\n\t\t\t\treportDebug(\"storage\", \"worktree-pool-temporary-cleanup-failed\", { file, ...failureDebugFields(error) });\n\t\t\t}\n\t\t} finally {\n\t\t\toriginal?.close();\n\t\t}\n\t}\n}\n\nfunction isOwner(value: unknown): value is PoolOwner {\n\tconst owner = value as Partial<PoolOwner> | null | undefined;\n\treturn (owner?.kind === \"session\" || owner?.kind === \"prebuild\") && typeof owner.id === \"string\";\n}\n\nfunction isState(value: unknown): value is PoolLastState {\n\tconst state = value as Partial<PoolLastState> | null | undefined;\n\treturn (\n\t\ttypeof state?.head === \"string\" &&\n\t\ttypeof state.tree === \"string\" &&\n\t\t(state.snapshotId === null || typeof state.snapshotId === \"string\")\n\t);\n}\n\nasync function readRecord(file: string, storeDir: string, repository: RepositoryId, slot: SlotNumber) {\n\tconst record = JSON.parse(await readFile(file, \"utf8\")) as Partial<PoolSlotRecord> | null;\n\tconst valid =\n\t\trecord?.version === 1 &&\n\t\trecord.repository === repository &&\n\t\trecord.slot === slot &&\n\t\trecord.path === pooledWorktreePath(storeDir, repository, slot) &&\n\t\tisOwner(record.holder) &&\n\t\tisState(record.lastState) &&\n\t\ttypeof record.envHash === \"string\" &&\n\t\t(record.blueprintDigest === null || typeof record.blueprintDigest === \"string\") &&\n\t\t(record.releasedAt === null || typeof record.releasedAt === \"string\") &&\n\t\t(record.resetting === undefined || isState(record.resetting)) &&\n\t\t(record.tenancy === undefined || typeof record.tenancy === \"string\");\n\treturn valid ? (record as PoolSlotRecord) : undefined;\n}\n\nfunction newLease(record: PoolSlotRecord, storeDir: string, held: HeldSlot): WorktreeLease {\n\tconst lease: WorktreeLease = Object.freeze({\n\t\tstoreDir: resolve(storeDir),\n\t\trepository: record.repository,\n\t\tslot: record.slot,\n\t\tpath: record.path,\n\t\towner: held.owner,\n\t});\n\tleaseHolds.set(lease, held);\n\treturn lease;\n}\n\n/**\n * Takes the lowest free slot of the repository `admission.remotes` name and holds it for `owner`, before the restore\n * publishes into its path. A slot is free when it has neither a record nor a directory, and no other process is\n * changing it. Choosing and taking a slot run under a per-repository lock, so concurrent restores, in this process or\n * others, get different slots. Rejects when the remotes name no one repository, as for a checkout without remotes,\n * which is never pooled (#4989).\n */\nexport async function admitPooledWorktree(admission: PoolAdmission, owner: PoolOwner): Promise<WorktreeLease> {\n\tconst storeDir = resolve(admission.storeDir);\n\tconst repository = sharedRepositoryIdOf(admission.remotes, admission.root);\n\tif (repository === undefined) {\n\t\tthrow new Error(\"the checkout's remotes name no one repository; its worktrees are not pooled\");\n\t}\n\tconst directory = join(storeDir, \"pool\", repository);\n\tawait mkdir(directory, { recursive: true });\n\tlet repositoryLost: Error | undefined;\n\tconst unlockRepository = await lockPath(\n\t\tdirectory,\n\t\ttrue,\n\t\t(error) => {\n\t\t\trepositoryLost ??= error;\n\t\t},\n\t\tadmission.signal,\n\t);\n\ttry {\n\t\tfor (let n = 0; ; n++) {\n\t\t\tif (repositoryLost !== undefined) throw repositoryLost;\n\t\t\tconst slot = n as SlotNumber;\n\t\t\tconst file = recordFile(storeDir, repository, slot);\n\t\t\tconst path = pooledWorktreePath(storeDir, repository, slot);\n\t\t\tif ((await exists(file)) || (await exists(path))) continue;\n\t\t\tconst record: PoolSlotRecord = {\n\t\t\t\tversion: 1,\n\t\t\t\trepository,\n\t\t\t\tslot,\n\t\t\t\tpath,\n\t\t\t\tholder: owner,\n\t\t\t\tlastState: admission.lastState,\n\t\t\t\tenvHash: admission.envHash,\n\t\t\t\tblueprintDigest: null,\n\t\t\t\treleasedAt: null,\n\t\t\t\ttenancy: randomUUID(),\n\t\t\t};\n\t\t\tlet held: HeldSlot | undefined;\n\t\t\ttry {\n\t\t\t\theld = await withSlotLock(\n\t\t\t\t\tfile,\n\t\t\t\t\tfalse,\n\t\t\t\t\tasync (lock) => {\n\t\t\t\t\t\tif (repositoryLost !== undefined) throw repositoryLost;\n\t\t\t\t\t\tif (!(await lock.held())) throw lockLostError(file);\n\t\t\t\t\t\tif ((await exists(file)) || (await exists(path))) return undefined;\n\t\t\t\t\t\tconst taken = await takeSlot(file, owner, record, admission.signal);\n\t\t\t\t\t\tlet published = false;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (repositoryLost !== undefined) throw repositoryLost;\n\t\t\t\t\t\t\tif (!(await lock.held())) throw lockLostError(file);\n\t\t\t\t\t\t\tif ((await exists(file)) || (await exists(path))) {\n\t\t\t\t\t\t\t\tawait taken.unlease().catch(() => {});\n\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tpublished = await createRecord(file, record);\n\t\t\t\t\t\t\tif (!(await lock.held())) throw lockLostError(file);\n\t\t\t\t\t\t\tif (repositoryLost !== undefined) throw repositoryLost;\n\t\t\t\t\t\t\tif (!published) {\n\t\t\t\t\t\t\t\tawait taken.unlease().catch(() => {});\n\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (published) {\n\t\t\t\t\t\t\t\tconst abandoned = await takeRecord(file, record).catch(() => undefined);\n\t\t\t\t\t\t\t\tif (abandoned !== undefined) await rm(abandoned, { force: true }).catch(() => {});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tawait taken.unlease().catch(() => {});\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t\theldSlots.set(file, taken);\n\t\t\t\t\t\treturn taken;\n\t\t\t\t\t},\n\t\t\t\t\tadmission.signal,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif ((error as NodeJS.ErrnoException).code === \"ELOCKED\") continue;\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (held === undefined) continue;\n\t\t\treturn newLease(record, storeDir, held);\n\t\t}\n\t} finally {\n\t\tawait unlockRepository().catch(() => {});\n\t}\n}\n\n/** The repository and slot of a pooled worktree path under `storeDir`, or undefined for any other path. */\nasync function slotOf(\n\tstoreDir: string,\n\troot: string,\n): Promise<{ repository: RepositoryId; slot: SlotNumber } | undefined> {\n\tconst worktrees = join(resolve(storeDir), \"worktrees\");\n\tconst match = SLOT_NAME.exec(basename(root));\n\tif (!match) return undefined;\n\ttry {\n\t\tconst [parent, pooled] = await Promise.all([\n\t\t\tcanonicalizeWorktreePathAsync(dirname(root)),\n\t\t\tcanonicalizeWorktreePathAsync(worktrees),\n\t\t]);\n\t\tif (parent !== pooled) return undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n\treturn { repository: match[1] as RepositoryId, slot: Number(match[2]) as SlotNumber };\n}\n\n/** Who owns the worktree at `root`, and whether a live process holds it. Reads, never writes, and never throws. */\nexport async function pooledWorktreeHolder(storeDir: string, root: string): Promise<PooledWorktreeHolder> {\n\tconst slot = await slotOf(storeDir, root);\n\tif (slot === undefined) return \"unpooled\";\n\tconst file = recordFile(storeDir, slot.repository, slot.slot);\n\tlet record: PoolSlotRecord | undefined;\n\ttry {\n\t\trecord = await readRecord(file, storeDir, slot.repository, slot.slot);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return \"unpooled\";\n\t\trecord = undefined;\n\t}\n\treturn { owner: record?.holder ?? null, held: await isHeld(file, false) };\n}\n\n/**\n * Holds the existing pooled slot at `root` for `owner`, who must own it, as when a session continues in its worktree.\n * Processes of the same owner share the slot, each with a lease of its own, so it stays held until the last one\n * releases it or stops. Undefined when `root` is not pooled or another holder owns it.\n */\nexport async function holdRestoredWorktree(\n\tstoreDir: string,\n\troot: string,\n\towner: PoolOwner,\n\tsignal?: AbortSignal,\n): Promise<WorktreeLease | undefined> {\n\tconst slot = await slotOf(storeDir, root);\n\tif (slot === undefined) return undefined;\n\tconst file = recordFile(storeDir, slot.repository, slot.slot);\n\t// Every change to the slot, this process's share of it included, happens under its record lock, so concurrent\n\t// holds, releases and evictions in this process or others see each other.\n\treturn withSlotLock(\n\t\tfile,\n\t\ttrue,\n\t\tasync (lock) => {\n\t\t\tconst shared = heldSlots.get(file);\n\t\t\t// A hold whose slot another holder took meanwhile is lost, never shared: the record says who holds it (#4830).\n\t\t\tif (shared !== undefined && (await stillHolds(file, storeDir, shared))) {\n\t\t\t\tif (!sameOwner(shared.owner, owner)) return undefined;\n\t\t\t\tshared.references++;\n\t\t\t\treturn newLease(shared.record, storeDir, shared);\n\t\t\t}\n\t\t\tconst record = await readRecord(file, storeDir, slot.repository, slot.slot).catch(() => undefined);\n\t\t\tif (record === undefined || !sameOwner(record.holder, owner)) return undefined;\n\t\t\t// The lease comes first, so a claim or an eviction from here on sees the slot held; the record is then written\n\t\t\t// only in place of the one read, so a hold that lost the record lock while suspended, and a claimer took the slot\n\t\t\t// meanwhile, takes nothing back: it gives up its lease and its session restores elsewhere (#4991).\n\t\t\tif (!(await lock.held())) return undefined;\n\t\t\tconst taken = await takeSlot(file, owner, { ...record, releasedAt: null }, signal);\n\t\t\tlet put = false;\n\t\t\ttry {\n\t\t\t\tconst read = await takeRecord(file, record);\n\t\t\t\tif (read !== undefined) {\n\t\t\t\t\tif (await lock.held()) put = await putRecord(file, read, taken.record);\n\t\t\t\t\telse await giveBackRecord(file, read);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tawait taken.unlease().catch(() => {});\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tif (!put) {\n\t\t\t\tawait taken.unlease().catch(() => {});\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\theldSlots.set(file, taken);\n\t\t\treturn newLease(taken.record, storeDir, taken);\n\t\t},\n\t\tsignal,\n\t);\n}\n\n/**\n * Records the state a degraded restore published into a held slot, which differs from the admitted one. Writes only\n * while `lease` still holds the slot (#4830): resolves to false, writing nothing, once the lease was released or the\n * slot was lost to another holder.\n */\nexport async function recordPooledWorktreeState(lease: WorktreeLease, state: PoolLastState): Promise<boolean> {\n\tconst held = leaseHolds.get(lease);\n\tif (held === undefined) return false;\n\tconst file = recordFile(lease.storeDir, lease.repository, lease.slot);\n\treturn withSlotLock(file, true, async (lock) => {\n\t\tif (released.has(lease) || !(await stillHolds(file, lease.storeDir, held))) return false;\n\t\tif (!(await lock.held())) return false;\n\t\theld.record = { ...held.record, lastState: state };\n\t\tawait writeRecord(file, held.record);\n\t\treturn true;\n\t});\n}\n\n/**\n * Whether `lease` still holds its slot, checked against the slot's record under its lock (#4830): false once it was\n * released, or once another holder took the slot, as a claim does when a stalled holder's lease went stale. Then the\n * slot is another session's, and its former holder must not use it: it restores fresh instead. A lease another process\n * removed while the slot is still this holder's is taken again. When the record cannot be checked, the lease counts as\n * held unless it was removed. Never throws.\n */\nexport async function confirmPooledWorktreeLease(lease: WorktreeLease): Promise<boolean> {\n\tconst held = leaseHolds.get(lease);\n\tif (held === undefined || released.has(lease) || held.lost) return false;\n\tconst file = recordFile(lease.storeDir, lease.repository, lease.slot);\n\ttry {\n\t\treturn await withSlotLock(file, true, async () => {\n\t\t\tif (!(await stillHolds(file, lease.storeDir, held))) return false;\n\t\t\tif (held.compromised) {\n\t\t\t\theld.unlease = await leaseSlot(file, held);\n\t\t\t\theld.compromised = false;\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-confirm-failed\", { file, ...failureDebugFields(error) });\n\t\treturn !held.compromised;\n\t}\n}\n\n/**\n * Releases `lease`. When it was this process's last hold of the slot, this process's lease ends, and the record takes\n * `last` as the slot's known state, kept from the record when `last` is the snapshot the slot was restored or recorded\n * with. The slot becomes idle once no other process holds it either. A write failure keeps the record's earlier state,\n * which only makes the slot look changed, and the lease ends all the same. The record is written only while the lease\n * still holds the slot (#4830): a slot another holder took keeps its record. Resolves to false when the slot was lost,\n * and to true otherwise once the lease was this process's last hold, or another hold remains.\n */\nexport async function releaseRestoredWorktree(lease: WorktreeLease, last?: PoolLastState): Promise<boolean> {\n\tif (released.has(lease)) return false;\n\treleased.add(lease);\n\tconst held = leaseHolds.get(lease);\n\tif (held === undefined || held.lost) return false;\n\tconst file = recordFile(lease.storeDir, lease.repository, lease.slot);\n\tif (last !== undefined && last.snapshotId !== held.record.lastState.snapshotId) {\n\t\theld.record = { ...held.record, lastState: last };\n\t}\n\tlet counted = false;\n\tlet kept = false;\n\ttry {\n\t\tawait withSlotLock(file, true, async (lock) => {\n\t\t\tcounted = true;\n\t\t\tif (--held.references > 0) {\n\t\t\t\tkept = !held.lost;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\t// A slot another holder took while this one was stalled is its: this hold never writes it back (#4830).\n\t\t\t\tif (!(await stillHolds(file, lease.storeDir, held))) return;\n\t\t\t\tkept = true;\n\t\t\t\tconst idle = (await otherLeases(file, false)) === 0;\n\t\t\t\tif (!(await lock.held())) return;\n\t\t\t\tawait writeRecord(file, { ...held.record, releasedAt: idle ? new Date().toISOString() : null });\n\t\t\t} finally {\n\t\t\t\t// Inside the record lock, so a new hold in this process never meets this lease still taken.\n\t\t\t\tif (heldSlots.get(file) === held) heldSlots.delete(file);\n\t\t\t\tawait held.unlease().catch(() => {});\n\t\t\t}\n\t\t});\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-release-failed\", { file, ...failureDebugFields(error) });\n\t\t// The record lock was never taken: end this process's share all the same; the slot then only looks changed.\n\t\tif (!counted && --held.references <= 0) {\n\t\t\tif (heldSlots.get(file) === held) heldSlots.delete(file);\n\t\t\tawait held.unlease().catch(() => {});\n\t\t}\n\t}\n\treturn kept;\n}\n\n/**\n * Gives up the slot of `lease` whose worktree was never published or has been removed: deletes its record and ends this\n * process's lease, so the slot is free again, whatever other holds of it this process has. Never throws: a record left\n * behind belongs to a slot without a directory, which eviction removes.\n */\nexport async function discardPooledWorktree(lease: WorktreeLease): Promise<void> {\n\treleased.add(lease);\n\tconst held = leaseHolds.get(lease);\n\tif (held === undefined || held.lost) return;\n\tconst file = recordFile(lease.storeDir, lease.repository, lease.slot);\n\tconst end = async () => {\n\t\theld.lost = true;\n\t\tif (heldSlots.get(file) !== held) return;\n\t\theldSlots.delete(file);\n\t\tawait held.unlease().catch(() => {});\n\t};\n\ttry {\n\t\tawait withSlotLock(file, true, async (lock) => {\n\t\t\ttry {\n\t\t\t\t// A slot another holder took meanwhile keeps its record (#4830).\n\t\t\t\tif (heldSlots.get(file) === held && (await stillHolds(file, lease.storeDir, held)) && (await lock.held())) {\n\t\t\t\t\tawait rm(file, { force: true });\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tawait end();\n\t\t\t}\n\t\t});\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-discard-failed\", { file, ...failureDebugFields(error) });\n\t\tawait end();\n\t}\n}\n\nexport interface EvictIdleWorktreesOptions {\n\t/** Idle slots to keep: `snapshots.pool.maxIdlePerRepository`. */\n\treadonly maxIdle: number;\n\t/** The snapshot settings a slot's last state was recorded under, to tell an unchanged slot from a changed one. */\n\treadonly settings: WorktreeSnapshotSettings;\n\treadonly signal?: AbortSignal;\n}\n\n/** The readable records of the slots of `repository`. Rejects when the pool cannot be listed. */\nasync function slotRecords(storeDir: string, repository: RepositoryId): Promise<PoolSlotRecord[]> {\n\tconst records: PoolSlotRecord[] = [];\n\tfor (const name of await readdir(join(resolve(storeDir), \"pool\", repository))) {\n\t\tconst match = RECORD_NAME.exec(name);\n\t\tif (!match) continue;\n\t\tconst slot = Number(match[1]) as SlotNumber;\n\t\tconst record = await readRecord(recordFile(storeDir, repository, slot), storeDir, repository, slot).catch(\n\t\t\t() => undefined,\n\t\t);\n\t\tif (record !== undefined) records.push(record);\n\t}\n\treturn records;\n}\n\n/** The records of the slots of `repository` no live process holds. Rejects when the pool cannot be listed. */\nasync function idleRecords(storeDir: string, repository: RepositoryId): Promise<PoolSlotRecord[]> {\n\tconst idle: PoolSlotRecord[] = [];\n\tfor (const record of await slotRecords(storeDir, repository)) {\n\t\tif (!(await isHeld(recordFile(storeDir, repository, record.slot), true))) idle.push(record);\n\t}\n\treturn idle;\n}\n\n/** Newest released first; a slot whose holder stopped without releasing it counts as the oldest. */\nfunction byNewestRelease(a: PoolSlotRecord, b: PoolSlotRecord): number {\n\treturn (b.releasedAt ?? \"\").localeCompare(a.releasedAt ?? \"\") || a.slot - b.slot;\n}\n\n/**\n * Removes the oldest idle slots of `repository` beyond `maxIdle`, each under its record lock and only while no process\n * leases it: a slot whose directory\n * is gone loses its record, and a slot still exactly in its last state loses its worktree and record. A slot that\n * changed since, which may hold work no snapshot recorded, is kept. A slot a claim stopped resetting holds nothing but\n * recorded states and is never claimed, so it goes whatever `maxIdle` says. Resolves to the paths it removed; a failure\n * keeps that slot and never throws.\n */\nexport async function evictIdleWorktrees(\n\tstoreDir: string,\n\trepository: RepositoryId,\n\toptions: EvictIdleWorktreesOptions,\n): Promise<string[]> {\n\tlet idle: PoolSlotRecord[];\n\ttry {\n\t\tidle = await idleRecords(storeDir, repository);\n\t} catch (error) {\n\t\tconst directory = join(resolve(storeDir), \"pool\", repository);\n\t\treportDebug(\"storage\", \"worktree-pool-evict-failed\", { directory, ...failureDebugFields(error) });\n\t\treturn [];\n\t}\n\tconst removed: string[] = [];\n\tconst setAside: PoolSlotRecord[] = [];\n\tconst usable: PoolSlotRecord[] = [];\n\tfor (const record of idle) ((await worktreeSetAside(storeDir, record.path)) ? setAside : usable).push(record);\n\tfor (const record of setAside) {\n\t\tif (await processesWorkIn(record.path)) continue;\n\t\tif (await evictSlot(storeDir, record, options)) {\n\t\t\tremoved.push(record.path);\n\t\t\tsetAsideHere.delete(resolve(record.path));\n\t\t\tawait rm(setAsideFile(storeDir, record.path), { force: true }).catch(() => {});\n\t\t}\n\t}\n\tfor (const record of usable.filter((slot) => slot.resetting !== undefined)) {\n\t\tif (await evictSlot(storeDir, record, options)) removed.push(record.path);\n\t}\n\tconst kept = usable.filter((slot) => slot.resetting === undefined).sort(byNewestRelease);\n\tlet excess = kept.length - options.maxIdle;\n\tfor (const record of kept.reverse()) {\n\t\tif (excess <= 0) break;\n\t\tif (await evictSlot(storeDir, record, options)) {\n\t\t\tremoved.push(record.path);\n\t\t\texcess--;\n\t\t}\n\t}\n\treturn removed;\n}\n\nasync function evictSlot(storeDir: string, record: PoolSlotRecord, options: EvictIdleWorktreesOptions) {\n\tconst file = recordFile(storeDir, record.repository, record.slot);\n\ttry {\n\t\treturn await withSlotLock(\n\t\t\tfile,\n\t\t\tfalse,\n\t\t\tasync (lock) => {\n\t\t\t\tif (heldSlots.has(file)) return false;\n\t\t\t\tconst current = await readRecord(file, storeDir, record.repository, record.slot);\n\t\t\t\tif (current === undefined || (await otherLeases(file, true)) > 0) return false;\n\t\t\t\tlet store: string | undefined;\n\t\t\t\tif (await exists(current.path)) {\n\t\t\t\t\tconst stopped = current.resetting !== undefined;\n\t\t\t\t\tif (!stopped && !(await holdsRecordedStateOnly(current, options.settings, options.signal))) return false;\n\t\t\t\t\tstore = await pooledWorktreeStore(storeDir, current.path, options.signal);\n\t\t\t\t}\n\t\t\t\treturn removeSlot(file, current, store, lock);\n\t\t\t},\n\t\t\toptions.signal,\n\t\t);\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-evict-kept\", { path: record.path, ...failureDebugFields(error) });\n\t\treturn false;\n\t}\n}\n\n/**\n * Removes the slot of `current`, whose worktree, when it has one, belongs to `store` (#4991). Its record is taken aside\n * first, only while it is still `current`, the lock still this process's and no other process leases the slot, and the\n * worktree is moved aside in one rename; a holder that took the slot from a record read before then wrote it back, and\n * keeps it, worktree and all. Only then are the moved worktree and record deleted, which no hold, claim or admission\n * can reach: a process suspended while deleting them deletes nothing anyone holds.\n */\nasync function removeSlot(\n\tfile: string,\n\tcurrent: PoolSlotRecord,\n\tstore: string | undefined,\n\tlock: SlotLock,\n): Promise<boolean> {\n\tif (!(await lock.held())) return false;\n\tconst taken = await takeRecord(file, current);\n\tif (taken === undefined) return false;\n\tif ((await otherLeases(file, true)) > 0 || !(await lock.held())) {\n\t\tawait giveBackRecord(file, taken);\n\t\treturn false;\n\t}\n\tconst removed = store === undefined ? undefined : `${current.path}.removed-${randomUUID().slice(0, 8)}`;\n\ttry {\n\t\tif (removed !== undefined) await renameWithRetry(current.path, removed);\n\t} catch (error) {\n\t\tawait giveBackRecord(file, taken);\n\t\tthrow error;\n\t}\n\tif ((await exists(file)) || !(await lock.held())) {\n\t\tif (removed !== undefined) await renameWithRetry(removed, current.path);\n\t\tawait giveBackRecord(file, taken);\n\t\treturn false;\n\t}\n\tawait rm(taken, { force: true });\n\tif (removed !== undefined && store !== undefined) {\n\t\tawait rm(removed, { recursive: true, force: true });\n\t\tawait runGit([\"worktree\", \"prune\"], { cwd: dirname(store), env: { GIT_DIR: store } }).catch(() => {});\n\t}\n\treturn true;\n}\n\n/**\n * Whether the slot of `record` holds exactly its last state: its HEAD and policy tree, and nothing verification leaves\n * out that no snapshot recorded. Rejects when it cannot tell, as when the slot's HEAD or files changed.\n */\nasync function holdsRecordedStateOnly(\n\trecord: PoolSlotRecord,\n\tsettings: WorktreeSnapshotSettings,\n\tsignal: AbortSignal | undefined,\n): Promise<boolean> {\n\tconst { head, tree } = record.lastState;\n\tawait verifyWorktree({ remotes: [], head, tree, envHash: record.envHash }, record.path, { settings, signal });\n\treturn !(await holdsUnrecordedFiles(record.path, tree, signal));\n}\n\n/**\n * Why {@link claimIdleWorktree} took no slot. `foreign`: the slot's worktree belongs to another repository's object\n * store, as a slot an earlier version pooled under an identity several repositories shared may (#4989).\n */\nexport type NoIdleWorktreeReason =\n\t| \"none\"\n\t| \"busy\"\n\t| \"dirty\"\n\t| \"foreign\"\n\t| \"fetch-failed\"\n\t| \"reset-failed\"\n\t| \"verify-failed\";\n\nexport interface NoIdleWorktree {\n\treadonly claimed: false;\n\t/** Why the last candidate was not taken, or `none` when the repository has no idle slot. */\n\treadonly reason: NoIdleWorktreeReason;\n}\n\n/** A slot a claim reset to the snapshot, held for the claiming owner: release `lease` exactly once. */\nexport interface ClaimedWorktree {\n\treadonly claimed: true;\n\treadonly lease: WorktreeLease;\n\treadonly warnings: readonly WorktreeRestoreWarning[];\n}\n\nexport interface ClaimIdleWorktreeOptions {\n\treadonly storeDir: string;\n\treadonly owner: PoolOwner;\n\t/** The snapshot settings each slot's last state was recorded under, to tell an unchanged slot from a changed one. */\n\treadonly settings: WorktreeSnapshotSettings;\n\t/** Blob storage holding the snapshot's patches and bundle. */\n\treadonly blobs?: SnapshotBlobStore;\n\treadonly signal?: AbortSignal;\n}\n\n/**\n * Takes an idle slot of `snapshot`'s repository for `options.owner` and resets it to the snapshot (#4748), keeping the\n * files Git ignores, such as dependencies and build output, so the blueprint's maintenance has little to rebuild.\n * Candidates are the slots of the repository, those last restored for the snapshot's environment first, then the most\n * recently released; a slot a live process holds is busy. Only a slot that holds exactly its recorded last state, and\n * nothing no snapshot recorded, is taken, so its previous owner restores its snapshot elsewhere and loses nothing. The slot is marked before its files\n * change and unmarked once they verify, so a claim stopped half way leaves a slot no claim takes and eviction removes.\n * Only a slot of the snapshot's repository is a candidate, and only one whose worktree belongs to an object store of\n * that repository is taken (#4989): a snapshot of a checkout without remotes claims nothing. Resolves to the held slot\n * with HEAD and tree equal to the snapshot's, or to why none was taken: then the caller restores fresh. Rejects only\n * when `signal` aborted.\n */\nexport async function claimIdleWorktree(\n\tsnapshot: WorktreeSnapshot,\n\toptions: ClaimIdleWorktreeOptions,\n): Promise<ClaimedWorktree | NoIdleWorktree> {\n\tconst storeDir = resolve(options.storeDir);\n\t// Slots an earlier version admitted under the remotes as spelled are the repository's too (#4748), when that spelling\n\t// named this repository alone (#4989).\n\tconst repositories = sharedRepositoryIdsOf(snapshot.remotes, snapshot.root);\n\tconst stores = new Set(await Promise.all(repositories.map((repository) => repositoryStore(storeDir, repository))));\n\tconst candidates: PoolSlotRecord[] = [];\n\tfor (const repository of repositories) {\n\t\tcandidates.push(...(await slotRecords(storeDir, repository).catch(() => [])));\n\t}\n\tconst sameEnvironment = (record: PoolSlotRecord) => (record.envHash === snapshot.envHash ? 0 : 1);\n\tcandidates.sort((a, b) => sameEnvironment(a) - sameEnvironment(b) || byNewestRelease(a, b));\n\t// A slot a live process holds is busy: each candidate's lease is checked under its record lock.\n\tlet reason: NoIdleWorktreeReason = \"none\";\n\tfor (const candidate of candidates) {\n\t\toptions.signal?.throwIfAborted();\n\t\tconst outcome = await claimSlot(storeDir, candidate, snapshot, stores, options);\n\t\tif (outcome.claimed) return outcome;\n\t\treason = outcome.reason;\n\t}\n\toptions.signal?.throwIfAborted();\n\treturn { claimed: false, reason };\n}\n\n/** The object store, as a canonical path, that pooled worktrees of `repository` belong to. */\nfunction repositoryStore(storeDir: string, repository: RepositoryId): Promise<string> {\n\treturn canonicalizeWorktreePathAsync(join(storeDir, \"repositories\", `${repository}.git`));\n}\n\n/** Whether the worktree at `path` belongs to one of `stores`; false when that cannot be told. */\nasync function belongsTo(storeDir: string, path: string, stores: ReadonlySet<string>, signal?: AbortSignal) {\n\ttry {\n\t\treturn stores.has(await canonicalizeWorktreePathAsync(await pooledWorktreeStore(storeDir, path, signal)));\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nasync function claimSlot(\n\tstoreDir: string,\n\tcandidate: PoolSlotRecord,\n\tsnapshot: WorktreeSnapshot,\n\tstores: ReadonlySet<string>,\n\toptions: ClaimIdleWorktreeOptions,\n): Promise<ClaimedWorktree | NoIdleWorktree> {\n\tconst file = recordFile(storeDir, candidate.repository, candidate.slot);\n\tconst target: PoolLastState = { snapshotId: snapshot.id, head: snapshot.head, tree: snapshot.tree };\n\tlet taken: { before: PoolSlotRecord; held: HeldSlot } | NoIdleWorktreeReason;\n\ttry {\n\t\t// The owner and the mark change with the lease, under the record lock, so the previous owner never holds the slot\n\t\t// again once the claim took it.\n\t\ttaken = await withSlotLock(\n\t\t\tfile,\n\t\t\tfalse,\n\t\t\tasync (lock) => {\n\t\t\t\t// A lease that went stale only a short while ago still keeps the slot: its holder may be writing to it (#4830).\n\t\t\t\tif (heldSlots.has(file) || (await otherLeases(file, true)) > 0) return \"busy\";\n\t\t\t\tconst before = await readRecord(file, storeDir, candidate.repository, candidate.slot);\n\t\t\t\tif (before === undefined || before.resetting !== undefined) return \"dirty\";\n\t\t\t\tif (await worktreeSetAside(storeDir, before.path)) return \"busy\";\n\t\t\t\t// Another repository's slot is never reset, nor marked: its record and files stay as they are (#4989).\n\t\t\t\tif (!(await belongsTo(storeDir, before.path, stores, options.signal))) return \"foreign\";\n\t\t\t\tif (!(await holdsRecordedStateOnly(before, options.settings, options.signal).catch(() => false))) {\n\t\t\t\t\treturn \"dirty\";\n\t\t\t\t}\n\t\t\t\t// Its owner may have held the slot again while this process was suspended past the lock's stale time: the mark\n\t\t\t\t// replaces only the record checked, taken aside and compared, and never one a holder wrote meanwhile (#4991).\n\t\t\t\tif (!(await lock.held())) return \"busy\";\n\t\t\t\tconst taken = await takeRecord(file, before);\n\t\t\t\tif (taken === undefined) return \"busy\";\n\t\t\t\tif ((await otherLeases(file, true)) > 0 || !(await lock.held())) {\n\t\t\t\t\tawait giveBackRecord(file, taken);\n\t\t\t\t\treturn \"busy\";\n\t\t\t\t}\n\t\t\t\tconst marked: PoolSlotRecord = {\n\t\t\t\t\t...before,\n\t\t\t\t\tholder: options.owner,\n\t\t\t\t\treleasedAt: null,\n\t\t\t\t\tresetting: target,\n\t\t\t\t\ttenancy: randomUUID(),\n\t\t\t\t};\n\t\t\t\tlet held: HeldSlot;\n\t\t\t\ttry {\n\t\t\t\t\theld = await takeSlot(file, options.owner, marked, options.signal);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tawait giveBackRecord(file, taken);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tlet put: boolean;\n\t\t\t\ttry {\n\t\t\t\t\tput = await putRecord(file, taken, marked);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tawait held.unlease().catch(() => {});\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tif (!put) {\n\t\t\t\t\tawait held.unlease().catch(() => {});\n\t\t\t\t\treturn \"busy\";\n\t\t\t\t}\n\t\t\t\theldSlots.set(file, held);\n\t\t\t\treturn { before, held };\n\t\t\t},\n\t\t\toptions.signal,\n\t\t);\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-claim-skipped\", { file, ...failureDebugFields(error) });\n\t\treturn { claimed: false, reason: (error as NodeJS.ErrnoException).code === \"ELOCKED\" ? \"busy\" : \"dirty\" };\n\t}\n\tif (typeof taken === \"string\") return { claimed: false, reason: taken };\n\tconst { before, held } = taken;\n\tlet resetting = false;\n\ttry {\n\t\tconst warnings = await resetPooledWorktree(snapshot, before.path, before.lastState, {\n\t\t\tstoreDir,\n\t\t\tblobs: options.blobs,\n\t\t\tsignal: options.signal,\n\t\t\tbeforeReset: async () => {\n\t\t\t\tresetting = true;\n\t\t\t},\n\t\t});\n\t\tconst claimed: PoolSlotRecord = {\n\t\t\t...before,\n\t\t\tholder: options.owner,\n\t\t\tlastState: target,\n\t\t\tenvHash: snapshot.envHash,\n\t\t\treleasedAt: null,\n\t\t\ttenancy: held.record.tenancy,\n\t\t};\n\t\t// A claim stalled past its lease may have lost the slot meanwhile: then the slot is not its to record (#4830).\n\t\tconst kept = await withSlotLock(file, true, async (lock) => {\n\t\t\tif (!(await stillHolds(file, storeDir, held))) return false;\n\t\t\tif (!(await lock.held())) return false;\n\t\t\tawait writeRecord(file, claimed);\n\t\t\treturn true;\n\t\t});\n\t\tif (!kept) {\n\t\t\t// The slot stays marked: no claim takes it, and eviction removes it once this lease ends.\n\t\t\tif (heldSlots.get(file) === held) heldSlots.delete(file);\n\t\t\tawait held.unlease().catch(() => {});\n\t\t\treturn { claimed: false, reason: \"busy\" };\n\t\t}\n\t\theld.record = claimed;\n\t\treturn { claimed: true, lease: newLease(claimed, storeDir, held), warnings };\n\t} catch (error) {\n\t\treportDebug(\"storage\", \"worktree-pool-claim-failed\", { file, ...failureDebugFields(error) });\n\t\t// A slot whose files never changed goes back to its owner as it was; one changed half way stays marked.\n\t\tconst end = async () => {\n\t\t\tif (heldSlots.get(file) === held) heldSlots.delete(file);\n\t\t\tawait held.unlease().catch(() => {});\n\t\t};\n\t\ttry {\n\t\t\tawait withSlotLock(file, true, async (lock) => {\n\t\t\t\ttry {\n\t\t\t\t\t// A slot another holder took meanwhile is never handed back to its previous owner (#4830).\n\t\t\t\t\tif (!resetting && (await stillHolds(file, storeDir, held)) && (await lock.held())) {\n\t\t\t\t\t\tawait writeRecord(file, before);\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tawait end();\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (cause) {\n\t\t\treportDebug(\"storage\", \"worktree-pool-claim-undo-failed\", { file, ...failureDebugFields(cause) });\n\t\t\tawait end();\n\t\t}\n\t\tconst verifyFailed = isWorkspaceRestoreError(error) && error.code === \"tree-mismatch\";\n\t\treturn { claimed: false, reason: !resetting ? \"fetch-failed\" : verifyFailed ? \"verify-failed\" : \"reset-failed\" };\n\t}\n}\n\n/**\n * Whether the worktree at `path` holds files its recorded `tree` does not, that verification leaves out: staged content\n * that is neither HEAD's nor the tree's, a tracked file whose content is neither HEAD's nor the tree's, as an edit to a\n * file snapshots omit, such as a tracked `.env.example`, one under `.atomic/snapshot-ignore` or one over the size cap\n * (#4897), an untracked file outside the tree, as when untracked files are not captured or are on the deny list, or an ignored file on the\n * deny list, such as `.env`. Other ignored files, build output and dependencies, are rebuilt and may go.\n */\nasync function holdsUnrecordedFiles(path: string, tree: string, signal: AbortSignal | undefined): Promise<boolean> {\n\tconst git = { cwd: path, signal };\n\t// Staged content lives only in the index: it is recorded only when it is HEAD's or the recorded tree's.\n\tconst stagedDiffers = async (base: string) =>\n\t\t(await runGit([\"diff\", \"--cached\", \"--quiet\", base, \"--\"], { ...git, allowExitCodes: [1] })).exitCode !== 0;\n\tif ((await stagedDiffers(\"HEAD\")) && (await stagedDiffers(tree))) return true;\n\t// Verification compares omitted files as HEAD's, so a tracked file is checked against the tree itself: one that\n\t// changed since HEAD is recorded only when the tree holds its content (#4897).\n\tconst changedFrom = async (base: string) =>\n\t\tnulFields((await runGit([\"diff\", \"--name-only\", \"-z\", \"--no-renames\", \"--no-ext-diff\", base, \"--\"], git)).stdout);\n\tconst changed = await changedFrom(\"HEAD\");\n\tif (changed.length > 0) {\n\t\tconst unrecorded = new Set(await changedFrom(tree));\n\t\tif (changed.some((file) => unrecorded.has(file))) return true;\n\t}\n\tconst recorded = new Set(nulFields((await runGit([\"ls-tree\", \"-r\", \"-z\", \"--name-only\", tree], git)).stdout));\n\tconst untracked = nulFields((await runGit([\"ls-files\", \"-z\", \"--others\", \"--exclude-standard\"], git)).stdout);\n\tif (untracked.some((file) => !recorded.has(file))) return true;\n\tconst ignored = nulFields(\n\t\t(await runGit([\"ls-files\", \"-z\", \"--others\", \"--ignored\", \"--exclude-standard\", \"--directory\"], git)).stdout,\n\t);\n\treturn ignored.some((file) => !file.endsWith(\"/\") && isDeniedSnapshotPath(file));\n}\n"]}
@@ -1,4 +1,6 @@
1
+ import type * as native from "@bastani/atomic-natives";
1
2
  import { type LockOptions } from "proper-lockfile";
3
+ export declare function windowsTemporaryFiles(): typeof native | undefined;
2
4
  /**
3
5
  * How old, by the filesystem's clock, a probe file is when its process no longer has a use for it: one lives for a
4
6
  * create and a stat, so one this old was left by a process that stopped between creating and removing it.
@@ -12,7 +14,7 @@ export declare const LEFTOVER_PROBE_AGE_MS: number;
12
14
  * filesystem's clock.
13
15
  */
14
16
  export declare function sharedClockOffset(directory: string): Promise<number>;
15
- /** The time now by the clock of the filesystem holding `directory`, which every host sharing it reads alike. */
17
+ /** The shared filesystem's time. Windows advances a measured stamp through cleanup, never through a queued create. */
16
18
  export declare function sharedClockNow(directory: string): Promise<number>;
17
19
  /**
18
20
  * Takes a proper-lockfile lock of `path` whose staleness every host sharing it judges by the clock of the filesystem
@@ -1 +1 @@
1
- {"version":3,"file":"shared-clock.d.ts","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/shared-clock.ts"],"names":[],"mappings":"AAaA,OAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI7D;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAc,CAAC;AAsBjD;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgB1E;AAED,gHAAgH;AAChH,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEvE;AA2DD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAE3F"}
1
+ {"version":3,"file":"shared-clock.d.ts","sourceRoot":"","sources":["../../../src/core/worktree-snapshot/shared-clock.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,KAAK,MAAM,MAAM,yBAAyB,CAAC;AACvD,OAAiB,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI7D,wBAAgB,qBAAqB,IAAI,OAAO,MAAM,GAAG,SAAS,CAQjE;AAID;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAc,CAAC;AA6EjD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEpE;AAED,sHAAsH;AACtH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKjE;AA+FD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAE3F"}