agentrinse 0.8.2 → 1.0.0

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 (571) hide show
  1. package/README.md +84 -7
  2. package/dist/adapters/artifacts/adapter.d.ts +1 -1
  3. package/dist/adapters/artifacts/adapter.d.ts.map +1 -1
  4. package/dist/adapters/artifacts/adapter.js +74 -95
  5. package/dist/adapters/artifacts/adapter.js.map +1 -1
  6. package/dist/adapters/claude-retention.d.ts +0 -1
  7. package/dist/adapters/claude-retention.d.ts.map +1 -1
  8. package/dist/adapters/claude-retention.js +1 -1
  9. package/dist/adapters/claude-retention.js.map +1 -1
  10. package/dist/adapters/codex-database.d.ts +0 -1
  11. package/dist/adapters/codex-database.d.ts.map +1 -1
  12. package/dist/adapters/codex-database.js +1 -1
  13. package/dist/adapters/codex-database.js.map +1 -1
  14. package/dist/adapters/cursor-maintenance.d.ts +2 -1
  15. package/dist/adapters/cursor-maintenance.d.ts.map +1 -1
  16. package/dist/adapters/cursor-maintenance.js +1 -1
  17. package/dist/adapters/cursor-maintenance.js.map +1 -1
  18. package/dist/adapters/docker/adapter.d.ts +0 -1
  19. package/dist/adapters/docker/adapter.d.ts.map +1 -1
  20. package/dist/adapters/docker/adapter.js +8 -73
  21. package/dist/adapters/docker/adapter.js.map +1 -1
  22. package/dist/adapters/docker/owner.d.ts +2 -5
  23. package/dist/adapters/docker/owner.d.ts.map +1 -1
  24. package/dist/adapters/docker/owner.js +5 -5
  25. package/dist/adapters/docker/owner.js.map +1 -1
  26. package/dist/adapters/git/adapter.d.ts +6 -5
  27. package/dist/adapters/git/adapter.d.ts.map +1 -1
  28. package/dist/adapters/git/adapter.js +64 -207
  29. package/dist/adapters/git/adapter.js.map +1 -1
  30. package/dist/adapters/git/inventory-command.d.ts +2 -0
  31. package/dist/adapters/git/inventory-command.d.ts.map +1 -0
  32. package/dist/adapters/git/inventory-command.js +31 -0
  33. package/dist/adapters/git/inventory-command.js.map +1 -0
  34. package/dist/adapters/git/refs.d.ts +3 -1
  35. package/dist/adapters/git/refs.d.ts.map +1 -1
  36. package/dist/adapters/git/refs.js +10 -4
  37. package/dist/adapters/git/refs.js.map +1 -1
  38. package/dist/adapters/git/worktree-admin-size.d.ts +3 -0
  39. package/dist/adapters/git/worktree-admin-size.d.ts.map +1 -0
  40. package/dist/adapters/git/worktree-admin-size.js +72 -0
  41. package/dist/adapters/git/worktree-admin-size.js.map +1 -0
  42. package/dist/adapters/grok-maintenance.d.ts +1 -0
  43. package/dist/adapters/grok-maintenance.d.ts.map +1 -1
  44. package/dist/adapters/grok-maintenance.js +24 -0
  45. package/dist/adapters/grok-maintenance.js.map +1 -1
  46. package/dist/adapters/openclaw-database.d.ts +27 -0
  47. package/dist/adapters/openclaw-database.d.ts.map +1 -0
  48. package/dist/adapters/openclaw-database.js +148 -0
  49. package/dist/adapters/openclaw-database.js.map +1 -0
  50. package/dist/adapters/openclaw-ownership.d.ts +29 -0
  51. package/dist/adapters/openclaw-ownership.d.ts.map +1 -0
  52. package/dist/adapters/openclaw-ownership.js +155 -0
  53. package/dist/adapters/openclaw-ownership.js.map +1 -0
  54. package/dist/adapters/openclaw.d.ts +12 -0
  55. package/dist/adapters/openclaw.d.ts.map +1 -0
  56. package/dist/adapters/openclaw.js +306 -0
  57. package/dist/adapters/openclaw.js.map +1 -0
  58. package/dist/adapters/provider-adapter.d.ts +4 -2
  59. package/dist/adapters/provider-adapter.d.ts.map +1 -1
  60. package/dist/adapters/provider-adapter.js +91 -424
  61. package/dist/adapters/provider-adapter.js.map +1 -1
  62. package/dist/adapters/provider-file-classification.d.ts +6 -0
  63. package/dist/adapters/provider-file-classification.d.ts.map +1 -0
  64. package/dist/adapters/provider-file-classification.js +64 -0
  65. package/dist/adapters/provider-file-classification.js.map +1 -0
  66. package/dist/adapters/provider-file-discovery.d.ts +17 -0
  67. package/dist/adapters/provider-file-discovery.d.ts.map +1 -0
  68. package/dist/adapters/provider-file-discovery.js +143 -0
  69. package/dist/adapters/provider-file-discovery.js.map +1 -0
  70. package/dist/adapters/provider-reachability.d.ts.map +1 -1
  71. package/dist/adapters/provider-reachability.js +35 -2
  72. package/dist/adapters/provider-reachability.js.map +1 -1
  73. package/dist/adapters/provider-root.d.ts.map +1 -1
  74. package/dist/adapters/provider-root.js +27 -23
  75. package/dist/adapters/provider-root.js.map +1 -1
  76. package/dist/adapters/provider-specs.d.ts +4 -14
  77. package/dist/adapters/provider-specs.d.ts.map +1 -1
  78. package/dist/adapters/provider-specs.js +20 -204
  79. package/dist/adapters/provider-specs.js.map +1 -1
  80. package/dist/adapters/registry.d.ts +1 -0
  81. package/dist/adapters/registry.d.ts.map +1 -1
  82. package/dist/adapters/registry.js +12 -6
  83. package/dist/adapters/registry.js.map +1 -1
  84. package/dist/adapters/report-only-finding.d.ts +8 -0
  85. package/dist/adapters/report-only-finding.d.ts.map +1 -0
  86. package/dist/adapters/report-only-finding.js +22 -0
  87. package/dist/adapters/report-only-finding.js.map +1 -0
  88. package/dist/adapters/runtime/adapter.d.ts +2 -0
  89. package/dist/adapters/runtime/adapter.d.ts.map +1 -1
  90. package/dist/adapters/runtime/adapter.js +37 -40
  91. package/dist/adapters/runtime/adapter.js.map +1 -1
  92. package/dist/commands/adapters.d.ts.map +1 -1
  93. package/dist/commands/adapters.js +3 -1
  94. package/dist/commands/adapters.js.map +1 -1
  95. package/dist/commands/apply.d.ts.map +1 -1
  96. package/dist/commands/apply.js +2 -1
  97. package/dist/commands/apply.js.map +1 -1
  98. package/dist/commands/audit.d.ts +3 -0
  99. package/dist/commands/audit.d.ts.map +1 -1
  100. package/dist/commands/audit.js +48 -11
  101. package/dist/commands/audit.js.map +1 -1
  102. package/dist/commands/clean.d.ts +8 -1
  103. package/dist/commands/clean.d.ts.map +1 -1
  104. package/dist/commands/clean.js +86 -34
  105. package/dist/commands/clean.js.map +1 -1
  106. package/dist/commands/completion.d.ts +2 -1
  107. package/dist/commands/completion.d.ts.map +1 -1
  108. package/dist/commands/completion.js +7 -3
  109. package/dist/commands/completion.js.map +1 -1
  110. package/dist/commands/doctor.d.ts.map +1 -1
  111. package/dist/commands/doctor.js +25 -5
  112. package/dist/commands/doctor.js.map +1 -1
  113. package/dist/commands/git-inventory.d.ts +138 -0
  114. package/dist/commands/git-inventory.d.ts.map +1 -0
  115. package/dist/commands/git-inventory.js +310 -0
  116. package/dist/commands/git-inventory.js.map +1 -0
  117. package/dist/commands/history.d.ts +0 -1
  118. package/dist/commands/history.d.ts.map +1 -1
  119. package/dist/commands/history.js +1 -1
  120. package/dist/commands/history.js.map +1 -1
  121. package/dist/commands/purge.d.ts.map +1 -1
  122. package/dist/commands/purge.js +2 -1
  123. package/dist/commands/purge.js.map +1 -1
  124. package/dist/commands/show.d.ts +0 -1
  125. package/dist/commands/show.d.ts.map +1 -1
  126. package/dist/commands/show.js +3 -2
  127. package/dist/commands/show.js.map +1 -1
  128. package/dist/commands/storage-output.d.ts +5 -0
  129. package/dist/commands/storage-output.d.ts.map +1 -0
  130. package/dist/commands/storage-output.js +91 -0
  131. package/dist/commands/storage-output.js.map +1 -0
  132. package/dist/commands/storage-rules.d.ts +178 -0
  133. package/dist/commands/storage-rules.d.ts.map +1 -0
  134. package/dist/commands/storage-rules.js +35 -0
  135. package/dist/commands/storage-rules.js.map +1 -0
  136. package/dist/commands/storage-selection.d.ts +24 -0
  137. package/dist/commands/storage-selection.d.ts.map +1 -0
  138. package/dist/commands/storage-selection.js +52 -0
  139. package/dist/commands/storage-selection.js.map +1 -0
  140. package/dist/commands/storage.d.ts +107 -0
  141. package/dist/commands/storage.d.ts.map +1 -0
  142. package/dist/commands/storage.js +205 -0
  143. package/dist/commands/storage.js.map +1 -0
  144. package/dist/commands/undo.d.ts +1 -1
  145. package/dist/commands/undo.d.ts.map +1 -1
  146. package/dist/commands/undo.js +1 -1
  147. package/dist/commands/undo.js.map +1 -1
  148. package/dist/commands/worktree-lifecycle.d.ts +41 -0
  149. package/dist/commands/worktree-lifecycle.d.ts.map +1 -0
  150. package/dist/commands/worktree-lifecycle.js +97 -0
  151. package/dist/commands/worktree-lifecycle.js.map +1 -0
  152. package/dist/commands/worktrees.d.ts +86 -0
  153. package/dist/commands/worktrees.d.ts.map +1 -0
  154. package/dist/commands/worktrees.js +450 -0
  155. package/dist/commands/worktrees.js.map +1 -0
  156. package/dist/config/defaults.d.ts +4 -0
  157. package/dist/config/defaults.d.ts.map +1 -1
  158. package/dist/config/defaults.js +10 -4
  159. package/dist/config/defaults.js.map +1 -1
  160. package/dist/config/schema.d.ts +15 -4
  161. package/dist/config/schema.d.ts.map +1 -1
  162. package/dist/config/schema.js +24 -16
  163. package/dist/config/schema.js.map +1 -1
  164. package/dist/contracts/action.d.ts +64 -0
  165. package/dist/contracts/action.d.ts.map +1 -1
  166. package/dist/contracts/action.js +5 -12
  167. package/dist/contracts/action.js.map +1 -1
  168. package/dist/contracts/adapter.d.ts +6 -1
  169. package/dist/contracts/adapter.d.ts.map +1 -1
  170. package/dist/contracts/diagnostic.d.ts +2 -1
  171. package/dist/contracts/diagnostic.d.ts.map +1 -1
  172. package/dist/contracts/diagnostic.js +1 -1
  173. package/dist/contracts/diagnostic.js.map +1 -1
  174. package/dist/contracts/finding.d.ts +31 -2
  175. package/dist/contracts/finding.d.ts.map +1 -1
  176. package/dist/contracts/finding.js +2 -8
  177. package/dist/contracts/finding.js.map +1 -1
  178. package/dist/contracts/plan.d.ts +28 -0
  179. package/dist/contracts/plan.d.ts.map +1 -1
  180. package/dist/contracts/provider-file-quarantine.d.ts +8 -0
  181. package/dist/contracts/provider-file-quarantine.d.ts.map +1 -1
  182. package/dist/contracts/report.d.ts +30 -1
  183. package/dist/contracts/report.d.ts.map +1 -1
  184. package/dist/contracts/report.js +1 -7
  185. package/dist/contracts/report.js.map +1 -1
  186. package/dist/contracts/run.d.ts +3 -2
  187. package/dist/contracts/run.d.ts.map +1 -1
  188. package/dist/contracts/run.js +2 -2
  189. package/dist/contracts/run.js.map +1 -1
  190. package/dist/core/apply.d.ts +2 -0
  191. package/dist/core/apply.d.ts.map +1 -1
  192. package/dist/core/apply.js +55 -2
  193. package/dist/core/apply.js.map +1 -1
  194. package/dist/core/artifact-executor.d.ts +4 -4
  195. package/dist/core/artifact-executor.d.ts.map +1 -1
  196. package/dist/core/artifact-executor.js +67 -13
  197. package/dist/core/artifact-executor.js.map +1 -1
  198. package/dist/core/artifact-git-state.d.ts +13 -0
  199. package/dist/core/artifact-git-state.d.ts.map +1 -0
  200. package/dist/core/artifact-git-state.js +65 -0
  201. package/dist/core/artifact-git-state.js.map +1 -0
  202. package/dist/core/artifact-measurement.d.ts +5 -0
  203. package/dist/core/artifact-measurement.d.ts.map +1 -0
  204. package/dist/core/artifact-measurement.js +28 -0
  205. package/dist/core/artifact-measurement.js.map +1 -0
  206. package/dist/core/artifact-protection.d.ts +5 -0
  207. package/dist/core/artifact-protection.d.ts.map +1 -0
  208. package/dist/core/artifact-protection.js +54 -0
  209. package/dist/core/artifact-protection.js.map +1 -0
  210. package/dist/core/artifact-revalidation.d.ts.map +1 -1
  211. package/dist/core/artifact-revalidation.js +26 -5
  212. package/dist/core/artifact-revalidation.js.map +1 -1
  213. package/dist/core/audit.d.ts +33 -0
  214. package/dist/core/audit.d.ts.map +1 -1
  215. package/dist/core/audit.js +294 -4
  216. package/dist/core/audit.js.map +1 -1
  217. package/dist/core/bounded-command.d.ts +1 -0
  218. package/dist/core/bounded-command.d.ts.map +1 -1
  219. package/dist/core/bounded-command.js +10 -1
  220. package/dist/core/bounded-command.js.map +1 -1
  221. package/dist/core/database-revalidation.d.ts +0 -1
  222. package/dist/core/database-revalidation.d.ts.map +1 -1
  223. package/dist/core/database-revalidation.js +1 -1
  224. package/dist/core/database-revalidation.js.map +1 -1
  225. package/dist/core/directory-change-proof.d.ts +12 -0
  226. package/dist/core/directory-change-proof.d.ts.map +1 -0
  227. package/dist/core/directory-change-proof.js +55 -0
  228. package/dist/core/directory-change-proof.js.map +1 -0
  229. package/dist/core/git-operation-state.d.ts +0 -1
  230. package/dist/core/git-operation-state.d.ts.map +1 -1
  231. package/dist/core/git-operation-state.js +1 -1
  232. package/dist/core/git-operation-state.js.map +1 -1
  233. package/dist/core/measure.d.ts +20 -1
  234. package/dist/core/measure.d.ts.map +1 -1
  235. package/dist/core/measure.js +57 -9
  236. package/dist/core/measure.js.map +1 -1
  237. package/dist/core/no-clobber-rename.d.ts +1 -0
  238. package/dist/core/no-clobber-rename.d.ts.map +1 -1
  239. package/dist/core/no-clobber-rename.js +12 -5
  240. package/dist/core/no-clobber-rename.js.map +1 -1
  241. package/dist/core/pinned-file.d.ts +2 -1
  242. package/dist/core/pinned-file.d.ts.map +1 -1
  243. package/dist/core/pinned-file.js +1 -1
  244. package/dist/core/pinned-file.js.map +1 -1
  245. package/dist/core/plan.d.ts.map +1 -1
  246. package/dist/core/plan.js +15 -6
  247. package/dist/core/plan.js.map +1 -1
  248. package/dist/core/process-ownership.d.ts +3 -0
  249. package/dist/core/process-ownership.d.ts.map +1 -1
  250. package/dist/core/process-ownership.js +42 -19
  251. package/dist/core/process-ownership.js.map +1 -1
  252. package/dist/core/project-file.d.ts +6 -0
  253. package/dist/core/project-file.d.ts.map +1 -0
  254. package/dist/core/project-file.js +46 -0
  255. package/dist/core/project-file.js.map +1 -0
  256. package/dist/core/provider-file-identity.d.ts +1 -1
  257. package/dist/core/provider-file-identity.d.ts.map +1 -1
  258. package/dist/core/provider-file-identity.js +9 -1
  259. package/dist/core/provider-file-identity.js.map +1 -1
  260. package/dist/core/provider-file-policy.d.ts +3 -31
  261. package/dist/core/provider-file-policy.d.ts.map +1 -1
  262. package/dist/core/provider-file-policy.js +31 -95
  263. package/dist/core/provider-file-policy.js.map +1 -1
  264. package/dist/core/provider-file-revalidation.d.ts.map +1 -1
  265. package/dist/core/provider-file-revalidation.js +5 -1
  266. package/dist/core/provider-file-revalidation.js.map +1 -1
  267. package/dist/core/provider-processes.d.ts.map +1 -1
  268. package/dist/core/provider-processes.js +7 -0
  269. package/dist/core/provider-processes.js.map +1 -1
  270. package/dist/core/reachability.d.ts +1 -0
  271. package/dist/core/reachability.d.ts.map +1 -1
  272. package/dist/core/reachability.js +17 -10
  273. package/dist/core/reachability.js.map +1 -1
  274. package/dist/core/redaction.d.ts.map +1 -1
  275. package/dist/core/redaction.js +1 -0
  276. package/dist/core/redaction.js.map +1 -1
  277. package/dist/core/safety.js +2 -2
  278. package/dist/core/safety.js.map +1 -1
  279. package/dist/core/storage-area.d.ts +20 -0
  280. package/dist/core/storage-area.d.ts.map +1 -0
  281. package/dist/core/storage-area.js +67 -0
  282. package/dist/core/storage-area.js.map +1 -0
  283. package/dist/core/storage-measurement.d.ts +12 -0
  284. package/dist/core/storage-measurement.d.ts.map +1 -0
  285. package/dist/core/storage-measurement.js +87 -0
  286. package/dist/core/storage-measurement.js.map +1 -0
  287. package/dist/core/storage-mounts.d.ts +14 -0
  288. package/dist/core/storage-mounts.d.ts.map +1 -0
  289. package/dist/core/storage-mounts.js +172 -0
  290. package/dist/core/storage-mounts.js.map +1 -0
  291. package/dist/core/storage-observation.d.ts +45 -0
  292. package/dist/core/storage-observation.d.ts.map +1 -0
  293. package/dist/core/storage-observation.js +136 -0
  294. package/dist/core/storage-observation.js.map +1 -0
  295. package/dist/core/worktree-purge.d.ts +7 -0
  296. package/dist/core/worktree-purge.d.ts.map +1 -0
  297. package/dist/core/worktree-purge.js +281 -0
  298. package/dist/core/worktree-purge.js.map +1 -0
  299. package/dist/core/worktree-recovery-validation.d.ts +9 -0
  300. package/dist/core/worktree-recovery-validation.d.ts.map +1 -0
  301. package/dist/core/worktree-recovery-validation.js +215 -0
  302. package/dist/core/worktree-recovery-validation.js.map +1 -0
  303. package/dist/core/worktree-recovery.d.ts +17 -5
  304. package/dist/core/worktree-recovery.d.ts.map +1 -1
  305. package/dist/core/worktree-recovery.js +16 -843
  306. package/dist/core/worktree-recovery.js.map +1 -1
  307. package/dist/core/worktree-undo.d.ts +4 -0
  308. package/dist/core/worktree-undo.d.ts.map +1 -0
  309. package/dist/core/worktree-undo.js +328 -0
  310. package/dist/core/worktree-undo.js.map +1 -0
  311. package/dist/main.d.ts.map +1 -1
  312. package/dist/main.js +86 -9
  313. package/dist/main.js.map +1 -1
  314. package/dist/output.d.ts +5 -0
  315. package/dist/output.d.ts.map +1 -1
  316. package/dist/output.js +11 -0
  317. package/dist/output.js.map +1 -1
  318. package/dist/rules/build/cache-tag.d.ts +3 -0
  319. package/dist/rules/build/cache-tag.d.ts.map +1 -0
  320. package/dist/rules/build/cache-tag.js +19 -0
  321. package/dist/rules/build/cache-tag.js.map +1 -0
  322. package/dist/rules/build/inspection.d.ts +14 -0
  323. package/dist/rules/build/inspection.d.ts.map +1 -0
  324. package/dist/rules/build/inspection.js +99 -0
  325. package/dist/rules/build/inspection.js.map +1 -0
  326. package/dist/rules/build/project-cache.d.ts +302 -0
  327. package/dist/rules/build/project-cache.d.ts.map +1 -0
  328. package/dist/rules/build/project-cache.js +115 -0
  329. package/dist/rules/build/project-cache.js.map +1 -0
  330. package/dist/rules/builtin.generated.d.ts +77 -0
  331. package/dist/rules/builtin.generated.d.ts.map +1 -0
  332. package/dist/rules/builtin.generated.js +35 -0
  333. package/dist/rules/builtin.generated.js.map +1 -0
  334. package/dist/rules/claude/changelog-cache.json +24 -0
  335. package/dist/rules/claude/debug-log.json +28 -0
  336. package/dist/rules/claude/inventory.d.ts +3 -0
  337. package/dist/rules/claude/inventory.d.ts.map +1 -0
  338. package/dist/rules/claude/inventory.js +37 -0
  339. package/dist/rules/claude/inventory.js.map +1 -0
  340. package/dist/rules/claude/native-maintenance.d.ts +5 -0
  341. package/dist/rules/claude/native-maintenance.d.ts.map +1 -0
  342. package/dist/rules/claude/native-maintenance.js +24 -0
  343. package/dist/rules/claude/native-maintenance.js.map +1 -0
  344. package/dist/rules/claude/project-registration.d.ts +10 -0
  345. package/dist/rules/claude/project-registration.d.ts.map +1 -0
  346. package/dist/rules/claude/project-registration.js +28 -0
  347. package/dist/rules/claude/project-registration.js.map +1 -0
  348. package/dist/rules/codex/database-vacuum.d.ts +5 -0
  349. package/dist/rules/codex/database-vacuum.d.ts.map +1 -0
  350. package/dist/rules/codex/database-vacuum.js +115 -0
  351. package/dist/rules/codex/database-vacuum.js.map +1 -0
  352. package/dist/rules/codex/inventory.d.ts +3 -0
  353. package/dist/rules/codex/inventory.d.ts.map +1 -0
  354. package/dist/rules/codex/inventory.js +46 -0
  355. package/dist/rules/codex/inventory.js.map +1 -0
  356. package/dist/rules/codex/storage-databases.d.ts +2 -0
  357. package/dist/rules/codex/storage-databases.d.ts.map +1 -0
  358. package/dist/rules/codex/storage-databases.js +5 -0
  359. package/dist/rules/codex/storage-databases.js.map +1 -0
  360. package/dist/rules/copilot/inventory.d.ts +3 -0
  361. package/dist/rules/copilot/inventory.d.ts.map +1 -0
  362. package/dist/rules/copilot/inventory.js +22 -0
  363. package/dist/rules/copilot/inventory.js.map +1 -0
  364. package/dist/rules/copilot/native-maintenance.d.ts +5 -0
  365. package/dist/rules/copilot/native-maintenance.d.ts.map +1 -0
  366. package/dist/rules/copilot/native-maintenance.js +21 -0
  367. package/dist/rules/copilot/native-maintenance.js.map +1 -0
  368. package/dist/rules/cursor/inventory.d.ts +3 -0
  369. package/dist/rules/cursor/inventory.d.ts.map +1 -0
  370. package/dist/rules/cursor/inventory.js +34 -0
  371. package/dist/rules/cursor/inventory.js.map +1 -0
  372. package/dist/rules/cursor/native-maintenance.d.ts +5 -0
  373. package/dist/rules/cursor/native-maintenance.d.ts.map +1 -0
  374. package/dist/rules/cursor/native-maintenance.js +18 -0
  375. package/dist/rules/cursor/native-maintenance.js.map +1 -0
  376. package/dist/rules/docker/build-cache.d.ts +5 -0
  377. package/dist/rules/docker/build-cache.d.ts.map +1 -0
  378. package/dist/rules/docker/build-cache.js +43 -0
  379. package/dist/rules/docker/build-cache.js.map +1 -0
  380. package/dist/rules/file-rule.d.ts +190 -0
  381. package/dist/rules/file-rule.d.ts.map +1 -0
  382. package/dist/rules/file-rule.js +71 -0
  383. package/dist/rules/file-rule.js.map +1 -0
  384. package/dist/rules/git/inventory-bytes.d.ts +95 -0
  385. package/dist/rules/git/inventory-bytes.d.ts.map +1 -0
  386. package/dist/rules/git/inventory-bytes.js +134 -0
  387. package/dist/rules/git/inventory-bytes.js.map +1 -0
  388. package/dist/rules/git/inventory-lifecycle.d.ts +60 -0
  389. package/dist/rules/git/inventory-lifecycle.d.ts.map +1 -0
  390. package/dist/rules/git/inventory-lifecycle.js +171 -0
  391. package/dist/rules/git/inventory-lifecycle.js.map +1 -0
  392. package/dist/rules/git/inventory-loose.d.ts +15 -0
  393. package/dist/rules/git/inventory-loose.d.ts.map +1 -0
  394. package/dist/rules/git/inventory-loose.js +103 -0
  395. package/dist/rules/git/inventory-loose.js.map +1 -0
  396. package/dist/rules/git/inventory-owner.d.ts +55 -0
  397. package/dist/rules/git/inventory-owner.d.ts.map +1 -0
  398. package/dist/rules/git/inventory-owner.js +96 -0
  399. package/dist/rules/git/inventory-owner.js.map +1 -0
  400. package/dist/rules/git/inventory-packs.d.ts +23 -0
  401. package/dist/rules/git/inventory-packs.d.ts.map +1 -0
  402. package/dist/rules/git/inventory-packs.js +139 -0
  403. package/dist/rules/git/inventory-packs.js.map +1 -0
  404. package/dist/rules/git/inventory-path.d.ts +3 -0
  405. package/dist/rules/git/inventory-path.d.ts.map +1 -0
  406. package/dist/rules/git/inventory-path.js +30 -0
  407. package/dist/rules/git/inventory-path.js.map +1 -0
  408. package/dist/rules/git/inventory-registrations.d.ts +30 -0
  409. package/dist/rules/git/inventory-registrations.d.ts.map +1 -0
  410. package/dist/rules/git/inventory-registrations.js +313 -0
  411. package/dist/rules/git/inventory-registrations.js.map +1 -0
  412. package/dist/rules/git/pack-storage.d.ts +23 -0
  413. package/dist/rules/git/pack-storage.d.ts.map +1 -0
  414. package/dist/rules/git/pack-storage.js +112 -0
  415. package/dist/rules/git/pack-storage.js.map +1 -0
  416. package/dist/rules/git/project-worktree-roots.d.ts +6 -0
  417. package/dist/rules/git/project-worktree-roots.d.ts.map +1 -0
  418. package/dist/rules/git/project-worktree-roots.js +35 -0
  419. package/dist/rules/git/project-worktree-roots.js.map +1 -0
  420. package/dist/rules/git/registration.d.ts +31 -0
  421. package/dist/rules/git/registration.d.ts.map +1 -0
  422. package/dist/rules/git/registration.js +53 -0
  423. package/dist/rules/git/registration.js.map +1 -0
  424. package/dist/rules/git/worktree.d.ts +5 -0
  425. package/dist/rules/git/worktree.d.ts.map +1 -0
  426. package/dist/rules/git/worktree.js +83 -0
  427. package/dist/rules/git/worktree.js.map +1 -0
  428. package/dist/rules/grok/inventory.d.ts +3 -0
  429. package/dist/rules/grok/inventory.d.ts.map +1 -0
  430. package/dist/rules/grok/inventory.js +42 -0
  431. package/dist/rules/grok/inventory.js.map +1 -0
  432. package/dist/rules/grok/native-maintenance.d.ts +5 -0
  433. package/dist/rules/grok/native-maintenance.d.ts.map +1 -0
  434. package/dist/rules/grok/native-maintenance.js +21 -0
  435. package/dist/rules/grok/native-maintenance.js.map +1 -0
  436. package/dist/rules/jiti/project-cache.d.ts +9 -0
  437. package/dist/rules/jiti/project-cache.d.ts.map +1 -0
  438. package/dist/rules/jiti/project-cache.js +9 -0
  439. package/dist/rules/jiti/project-cache.js.map +1 -0
  440. package/dist/rules/openclaw/crabbox-identity.d.ts +20 -0
  441. package/dist/rules/openclaw/crabbox-identity.d.ts.map +1 -0
  442. package/dist/rules/openclaw/crabbox-identity.js +84 -0
  443. package/dist/rules/openclaw/crabbox-identity.js.map +1 -0
  444. package/dist/rules/openclaw/crabbox-storage.d.ts +28 -0
  445. package/dist/rules/openclaw/crabbox-storage.d.ts.map +1 -0
  446. package/dist/rules/openclaw/crabbox-storage.js +201 -0
  447. package/dist/rules/openclaw/crabbox-storage.js.map +1 -0
  448. package/dist/rules/openclaw/inventory.d.ts +3 -0
  449. package/dist/rules/openclaw/inventory.d.ts.map +1 -0
  450. package/dist/rules/openclaw/inventory.js +35 -0
  451. package/dist/rules/openclaw/inventory.js.map +1 -0
  452. package/dist/rules/openclaw/profile.d.ts +2 -0
  453. package/dist/rules/openclaw/profile.d.ts.map +1 -0
  454. package/dist/rules/openclaw/profile.js +5 -0
  455. package/dist/rules/openclaw/profile.js.map +1 -0
  456. package/dist/rules/openclaw/shell-snapshot.json +24 -0
  457. package/dist/rules/openclaw/storage.d.ts +27 -0
  458. package/dist/rules/openclaw/storage.d.ts.map +1 -0
  459. package/dist/rules/openclaw/storage.js +125 -0
  460. package/dist/rules/openclaw/storage.js.map +1 -0
  461. package/dist/rules/opencode/inventory.d.ts +3 -0
  462. package/dist/rules/opencode/inventory.d.ts.map +1 -0
  463. package/dist/rules/opencode/inventory.js +26 -0
  464. package/dist/rules/opencode/inventory.js.map +1 -0
  465. package/dist/rules/opencode/native-maintenance.d.ts +5 -0
  466. package/dist/rules/opencode/native-maintenance.d.ts.map +1 -0
  467. package/dist/rules/opencode/native-maintenance.js +23 -0
  468. package/dist/rules/opencode/native-maintenance.js.map +1 -0
  469. package/dist/rules/provider.d.ts +20 -0
  470. package/dist/rules/provider.d.ts.map +1 -0
  471. package/dist/rules/provider.js +5 -0
  472. package/dist/rules/provider.js.map +1 -0
  473. package/dist/rules/runtime/tools.d.ts +30 -0
  474. package/dist/rules/runtime/tools.d.ts.map +1 -0
  475. package/dist/rules/runtime/tools.js +10 -0
  476. package/dist/rules/runtime/tools.js.map +1 -0
  477. package/dist/rules/schema.d.ts +130 -0
  478. package/dist/rules/schema.d.ts.map +1 -0
  479. package/dist/rules/schema.js +78 -0
  480. package/dist/rules/schema.js.map +1 -0
  481. package/dist/rules/storage/agent-and-system-storage.d.ts +3 -0
  482. package/dist/rules/storage/agent-and-system-storage.d.ts.map +1 -0
  483. package/dist/rules/storage/agent-and-system-storage.js +81 -0
  484. package/dist/rules/storage/agent-and-system-storage.js.map +1 -0
  485. package/dist/rules/storage/agents-locations.d.ts +2 -0
  486. package/dist/rules/storage/agents-locations.d.ts.map +1 -0
  487. package/dist/rules/storage/agents-locations.js +33 -0
  488. package/dist/rules/storage/agents-locations.js.map +1 -0
  489. package/dist/rules/storage/apple-system-locations.d.ts +2 -0
  490. package/dist/rules/storage/apple-system-locations.d.ts.map +1 -0
  491. package/dist/rules/storage/apple-system-locations.js +17 -0
  492. package/dist/rules/storage/apple-system-locations.js.map +1 -0
  493. package/dist/rules/storage/build-and-browser-caches.d.ts +3 -0
  494. package/dist/rules/storage/build-and-browser-caches.d.ts.map +1 -0
  495. package/dist/rules/storage/build-and-browser-caches.js +89 -0
  496. package/dist/rules/storage/build-and-browser-caches.js.map +1 -0
  497. package/dist/rules/storage/catalog.d.ts +16 -0
  498. package/dist/rules/storage/catalog.d.ts.map +1 -0
  499. package/dist/rules/storage/catalog.js +27 -0
  500. package/dist/rules/storage/catalog.js.map +1 -0
  501. package/dist/rules/storage/desktop-locations.d.ts +2 -0
  502. package/dist/rules/storage/desktop-locations.d.ts.map +1 -0
  503. package/dist/rules/storage/desktop-locations.js +59 -0
  504. package/dist/rules/storage/desktop-locations.js.map +1 -0
  505. package/dist/rules/storage/location.d.ts +15 -0
  506. package/dist/rules/storage/location.d.ts.map +1 -0
  507. package/dist/rules/storage/location.js +18 -0
  508. package/dist/rules/storage/location.js.map +1 -0
  509. package/dist/rules/storage/mobile-locations.d.ts +2 -0
  510. package/dist/rules/storage/mobile-locations.d.ts.map +1 -0
  511. package/dist/rules/storage/mobile-locations.js +43 -0
  512. package/dist/rules/storage/mobile-locations.js.map +1 -0
  513. package/dist/rules/storage/native-volume.d.ts +26 -0
  514. package/dist/rules/storage/native-volume.d.ts.map +1 -0
  515. package/dist/rules/storage/native-volume.js +111 -0
  516. package/dist/rules/storage/native-volume.js.map +1 -0
  517. package/dist/rules/storage/owner-evidence.d.ts +98 -0
  518. package/dist/rules/storage/owner-evidence.d.ts.map +1 -0
  519. package/dist/rules/storage/owner-evidence.js +120 -0
  520. package/dist/rules/storage/owner-evidence.js.map +1 -0
  521. package/dist/rules/storage/package-stores.d.ts +3 -0
  522. package/dist/rules/storage/package-stores.d.ts.map +1 -0
  523. package/dist/rules/storage/package-stores.js +84 -0
  524. package/dist/rules/storage/package-stores.js.map +1 -0
  525. package/dist/rules/storage/packages-locations.d.ts +2 -0
  526. package/dist/rules/storage/packages-locations.d.ts.map +1 -0
  527. package/dist/rules/storage/packages-locations.js +99 -0
  528. package/dist/rules/storage/packages-locations.js.map +1 -0
  529. package/dist/rules/storage/supplied-locations.d.ts +68 -0
  530. package/dist/rules/storage/supplied-locations.d.ts.map +1 -0
  531. package/dist/rules/storage/supplied-locations.js +86 -0
  532. package/dist/rules/storage/supplied-locations.js.map +1 -0
  533. package/dist/rules/storage/toolchains-locations.d.ts +2 -0
  534. package/dist/rules/storage/toolchains-locations.d.ts.map +1 -0
  535. package/dist/rules/storage/toolchains-locations.js +80 -0
  536. package/dist/rules/storage/toolchains-locations.js.map +1 -0
  537. package/dist/rules/vite/project-cache.d.ts +16 -0
  538. package/dist/rules/vite/project-cache.d.ts.map +1 -0
  539. package/dist/rules/vite/project-cache.js +19 -0
  540. package/dist/rules/vite/project-cache.js.map +1 -0
  541. package/dist/rules/zed/inventory.d.ts +3 -0
  542. package/dist/rules/zed/inventory.d.ts.map +1 -0
  543. package/dist/rules/zed/inventory.js +22 -0
  544. package/dist/rules/zed/inventory.js.map +1 -0
  545. package/dist/rules/zed/rotated-log.json +27 -0
  546. package/dist/version.d.ts +1 -1
  547. package/dist/version.js +1 -1
  548. package/package.json +16 -11
  549. package/schemas/audit.schema.json +138 -5
  550. package/schemas/cleanup-rule.schema.json +256 -0
  551. package/schemas/command-envelope.schema.json +2 -2
  552. package/schemas/command-event.schema.json +1 -1
  553. package/schemas/database-backup.schema.json +4 -4
  554. package/schemas/doctor.schema.json +1 -1
  555. package/schemas/plan.schema.json +136 -3
  556. package/schemas/provider-file-quarantine.schema.json +1534 -549
  557. package/schemas/quarantine.schema.json +5 -4
  558. package/schemas/run.schema.json +10 -10
  559. package/skills/agentrinse/SKILL.md +24 -0
  560. package/dist/adapters/claude-cache.d.ts +0 -3
  561. package/dist/adapters/claude-cache.d.ts.map +0 -1
  562. package/dist/adapters/claude-cache.js +0 -67
  563. package/dist/adapters/claude-cache.js.map +0 -1
  564. package/dist/adapters/claude-debug.d.ts +0 -3
  565. package/dist/adapters/claude-debug.d.ts.map +0 -1
  566. package/dist/adapters/claude-debug.js +0 -100
  567. package/dist/adapters/claude-debug.js.map +0 -1
  568. package/dist/adapters/zed-logs.d.ts +0 -8
  569. package/dist/adapters/zed-logs.d.ts.map +0 -1
  570. package/dist/adapters/zed-logs.js +0 -103
  571. package/dist/adapters/zed-logs.js.map +0 -1
@@ -3,15 +3,13 @@ import { lstat } from "node:fs/promises";
3
3
  import { resolve } from "node:path";
4
4
  import { promisify } from "node:util";
5
5
  import { parseWorktreePorcelain } from "../adapters/git/porcelain.js";
6
- import { countStatusSuppressedIndexEntries, parseGitStatusPorcelainV2, } from "../adapters/git/status.js";
7
- import { quarantineEntrySchema, } from "../contracts/quarantine.js";
6
+ import { quarantineEntrySchema } from "../contracts/quarantine.js";
8
7
  import { writeJsonAtomic } from "../state/json-file.js";
9
8
  import { findGitOperations } from "./git-operation-state.js";
10
9
  import { measurePath } from "./measure.js";
11
10
  import { findMountBoundaries } from "./mount-boundaries.js";
12
11
  import { renameNoReplace } from "./no-clobber-rename.js";
13
12
  import { findProcessesUsingPath } from "./process-ownership.js";
14
- import { reconcileOwnedWorktreeLockClaim, unlockOwnedWorktree } from "./worktree-lock.js";
15
13
  const execFileAsync = promisify(execFile);
16
14
  export class WorktreeRecoveryError extends Error {
17
15
  code;
@@ -39,7 +37,7 @@ function isMissingGitRef(error) {
39
37
  }
40
38
  return error.code === 1;
41
39
  }
42
- async function pathExists(path, inspect) {
40
+ export async function pathExists(path, inspect) {
43
41
  try {
44
42
  await inspect(path);
45
43
  return true;
@@ -51,22 +49,22 @@ async function pathExists(path, inspect) {
51
49
  throw error;
52
50
  }
53
51
  }
54
- function branchRef(branch) {
52
+ export function branchRef(branch) {
55
53
  if (branch === undefined) {
56
54
  return undefined;
57
55
  }
58
56
  return branch.startsWith("refs/") ? branch : `refs/heads/${branch}`;
59
57
  }
60
- function assertManifestPath(entry, options) {
58
+ export function assertManifestPath(entry, options) {
61
59
  const expected = resolve(options.quarantineDirectory, `${entry.entryId}.json`);
62
60
  if (resolve(options.manifestPath) !== expected) {
63
61
  throw new WorktreeRecoveryError("QUARANTINE_MANIFEST_PATH_MISMATCH", "quarantine manifest filename does not match its entry ID", entry);
64
62
  }
65
63
  }
66
- function quarantineLockReason(entry) {
64
+ export function quarantineLockReason(entry) {
67
65
  return `AgentRinse quarantine ${entry.entryId}`;
68
66
  }
69
- function lockMatches(actual, expectation, entry) {
67
+ export function lockMatches(actual, expectation, entry) {
70
68
  const owned = actual === quarantineLockReason(entry);
71
69
  if (expectation === "owned") {
72
70
  return owned;
@@ -76,19 +74,19 @@ function lockMatches(actual, expectation, entry) {
76
74
  }
77
75
  return actual === undefined || owned;
78
76
  }
79
- function registrationMatches(output, path, entry, lockExpectation) {
77
+ export function registrationMatches(output, path, entry, lockExpectation) {
80
78
  return parseWorktreePorcelain(output).some((record) => record.path === path &&
81
79
  record.head === entry.target.head &&
82
80
  record.branch === entry.target.branch &&
83
81
  lockMatches(record.locked, lockExpectation, entry));
84
82
  }
85
- async function assertNoGitOperations(entry, worktreePath, dependencies) {
83
+ export async function assertNoGitOperations(entry, worktreePath, dependencies) {
86
84
  const operations = await findGitOperations(worktreePath, dependencies.runGit, (path) => pathExists(path, dependencies.inspect));
87
85
  if (operations.length > 0) {
88
86
  throw new WorktreeRecoveryError("QUARANTINE_GIT_OPERATION_IN_PROGRESS", `Git operation is in progress: ${operations.join(", ")}`, entry);
89
87
  }
90
88
  }
91
- async function assertTargetRegistrationLock(entry, dependencies, lockExpectation, expectedPaths) {
89
+ export async function assertTargetRegistrationLock(entry, dependencies, lockExpectation, expectedPaths) {
92
90
  const records = parseWorktreePorcelain(await dependencies.runGit([
93
91
  "--git-dir",
94
92
  entry.target.repositoryCommonDir,
@@ -105,11 +103,11 @@ async function assertTargetRegistrationLock(entry, dependencies, lockExpectation
105
103
  throw new WorktreeRecoveryError("QUARANTINE_REGISTRATION_CHANGED", "target worktree registration or lock ownership changed before repair", entry);
106
104
  }
107
105
  }
108
- function isImmutableRecoveryProtection(error) {
106
+ export function isImmutableRecoveryProtection(error) {
109
107
  return (error instanceof WorktreeRecoveryError &&
110
108
  ["QUARANTINE_GIT_OPERATION_IN_PROGRESS", "QUARANTINE_REGISTRATION_CHANGED"].includes(error.code));
111
109
  }
112
- function resolveDependencies(options) {
110
+ export function resolveDependencies(options) {
113
111
  return {
114
112
  runGit: options.dependencies?.runGit ?? defaultGitRunner,
115
113
  inspect: options.dependencies?.inspect ?? lstat,
@@ -121,13 +119,13 @@ function resolveDependencies(options) {
121
119
  clock: options.dependencies?.clock ?? (() => new Date()),
122
120
  };
123
121
  }
124
- function assertSupportedPlatform(entry, options) {
122
+ export function assertSupportedPlatform(entry, options) {
125
123
  const platform = options.dependencies?.platform ?? process.platform;
126
124
  if (!["darwin", "linux"].includes(platform)) {
127
125
  throw new WorktreeRecoveryError("WORKTREE_PLATFORM_UNSUPPORTED", `worktree recovery mutation is unsupported on ${platform}`, entry);
128
126
  }
129
127
  }
130
- async function persist(entry, options) {
128
+ export async function persist(entry, options) {
131
129
  const parsed = quarantineEntrySchema.parse(entry);
132
130
  assertManifestPath(parsed, options);
133
131
  await writeJsonAtomic(options.manifestPath, parsed, {
@@ -135,114 +133,7 @@ async function persist(entry, options) {
135
133
  });
136
134
  return parsed;
137
135
  }
138
- async function validateQuarantinedEntry(entry, options, requireOriginalVacant, acceptedStatuses = ["quarantined"], lockExpectation = "owned", worktreePath = entry.quarantinePath) {
139
- const dependencies = resolveDependencies(options);
140
- const fail = (code, message) => {
141
- throw new WorktreeRecoveryError(code, message, entry);
142
- };
143
- assertSupportedPlatform(entry, options);
144
- if (!acceptedStatuses.includes(entry.status)) {
145
- fail("QUARANTINE_NOT_LIVE", `quarantine entry status is ${entry.status}`);
146
- }
147
- assertManifestPath(entry, options);
148
- const quarantineIdentity = entry.quarantineIdentity ??
149
- fail("QUARANTINE_IDENTITY_MISSING", "post-repair quarantine identity is missing");
150
- if (requireOriginalVacant && (await pathExists(entry.originalPath, dependencies.inspect))) {
151
- fail("UNDO_DESTINATION_OCCUPIED", `original path is occupied: ${entry.originalPath}`);
152
- }
153
- const [quarantineStats, commonDirStats] = await Promise.all([
154
- dependencies.inspect(worktreePath),
155
- dependencies.inspect(entry.target.repositoryCommonDir),
156
- ]);
157
- if (!quarantineStats.isDirectory() ||
158
- quarantineStats.isSymbolicLink() ||
159
- quarantineStats.dev !== quarantineIdentity.device ||
160
- quarantineStats.ino !== quarantineIdentity.inode ||
161
- quarantineStats.mtimeMs !== quarantineIdentity.mtimeMs) {
162
- fail("QUARANTINE_IDENTITY_CHANGED", "quarantined worktree filesystem identity changed");
163
- }
164
- if (!commonDirStats.isDirectory() || commonDirStats.isSymbolicLink()) {
165
- fail("QUARANTINE_REPOSITORY_CHANGED", "Git common directory is no longer a real directory");
166
- }
167
- await reconcileOwnedWorktreeLockClaim({
168
- worktreePath,
169
- repositoryCommonDir: entry.target.repositoryCommonDir,
170
- expectedReason: quarantineLockReason(entry),
171
- claimId: entry.entryId,
172
- runGit: dependencies.runGit,
173
- platform: options.dependencies?.platform ?? process.platform,
174
- });
175
- const measurement = await dependencies.measure(worktreePath, {
176
- maxEntries: entry.measurementMaxEntries,
177
- excludeRootEntries: [".git"],
178
- });
179
- if (measurement.truncated ||
180
- measurement.specialEntries > 0 ||
181
- measurement.mountBoundaries > 0 ||
182
- measurement.bytes !== quarantineIdentity.measuredBytes ||
183
- measurement.newestMtimeMs !== quarantineIdentity.newestMtimeMs ||
184
- measurement.fingerprint !== quarantineIdentity.fingerprint) {
185
- fail("QUARANTINE_CONTENT_CHANGED", "quarantined worktree contents changed after apply");
186
- }
187
- const ownership = await dependencies.processProbe(worktreePath);
188
- if (ownership.status !== "idle") {
189
- fail(ownership.status === "busy" ? "QUARANTINE_PROCESS_ACTIVE" : "QUARANTINE_PROCESS_UNKNOWN", ownership.status === "busy"
190
- ? "a live process owns the quarantined worktree"
191
- : "live process ownership could not be proven idle");
192
- }
193
- const mounts = await dependencies.mountProbe(worktreePath);
194
- if (mounts.status !== "clear") {
195
- fail(mounts.status === "blocked"
196
- ? "QUARANTINE_MOUNT_BOUNDARY"
197
- : "QUARANTINE_MOUNT_INSPECTION_UNKNOWN", mounts.status === "blocked"
198
- ? "quarantined worktree contains a mount boundary"
199
- : "mount boundaries could not be proven absent");
200
- }
201
- const status = parseGitStatusPorcelainV2(await dependencies.runGit([
202
- "-C",
203
- worktreePath,
204
- "status",
205
- "--porcelain=v2",
206
- "--branch",
207
- "-z",
208
- "--untracked-files=all",
209
- "--ignored=matching",
210
- ]));
211
- const statusSuppressedEntries = countStatusSuppressedIndexEntries(await dependencies.runGit(["-C", worktreePath, "ls-files", "-z", "-v"]));
212
- if (status.head !== entry.target.head ||
213
- branchRef(status.branch) !== entry.target.branch ||
214
- status.staged + status.modified + status.untracked + status.conflicted + status.ignored > 0 ||
215
- statusSuppressedEntries > 0) {
216
- fail("QUARANTINE_GIT_STATE_CHANGED", "quarantined worktree is no longer clean at planned HEAD");
217
- }
218
- await assertNoGitOperations(entry, worktreePath, dependencies);
219
- const records = parseWorktreePorcelain(await dependencies.runGit([
220
- "--git-dir",
221
- entry.target.repositoryCommonDir,
222
- "worktree",
223
- "list",
224
- "--porcelain",
225
- "-z",
226
- ]));
227
- const registration = records.find((record) => record.path === worktreePath &&
228
- record.head === entry.target.head &&
229
- record.branch === entry.target.branch);
230
- if (registration === undefined) {
231
- throw new WorktreeRecoveryError("QUARANTINE_REGISTRATION_CHANGED", "quarantined worktree is no longer registered", entry);
232
- }
233
- if (!lockMatches(registration.locked, lockExpectation, entry)) {
234
- fail("QUARANTINE_REGISTRATION_CHANGED", "quarantined worktree lock ownership changed");
235
- }
236
- const recoveryHead = await readRecoveryRef(entry, dependencies);
237
- if (recoveryHead === undefined || recoveryHead !== entry.target.head) {
238
- fail("QUARANTINE_RECOVERY_REF_CHANGED", "recovery ref no longer points to the planned HEAD");
239
- }
240
- return {
241
- dependencies,
242
- registrationLocked: registration.locked === quarantineLockReason(entry),
243
- };
244
- }
245
- async function deleteRecoveryRef(entry, dependencies) {
136
+ export async function deleteRecoveryRef(entry, dependencies) {
246
137
  const recoveryHead = await readRecoveryRef(entry, dependencies);
247
138
  if (recoveryHead === undefined) {
248
139
  return;
@@ -259,7 +150,7 @@ async function deleteRecoveryRef(entry, dependencies) {
259
150
  entry.target.head,
260
151
  ]);
261
152
  }
262
- async function ensureRecoveryRef(entry, dependencies) {
153
+ export async function ensureRecoveryRef(entry, dependencies) {
263
154
  const recoveryHead = await readRecoveryRef(entry, dependencies);
264
155
  if (recoveryHead === entry.target.head) {
265
156
  return;
@@ -276,7 +167,7 @@ async function ensureRecoveryRef(entry, dependencies) {
276
167
  "",
277
168
  ]);
278
169
  }
279
- async function readRecoveryRef(entry, dependencies) {
170
+ export async function readRecoveryRef(entry, dependencies) {
280
171
  try {
281
172
  return (await dependencies.runGit([
282
173
  "--git-dir",
@@ -294,725 +185,7 @@ async function readRecoveryRef(entry, dependencies) {
294
185
  throw error;
295
186
  }
296
187
  }
297
- async function verifyLockedRegistration(entry, dependencies) {
298
- const records = await dependencies.runGit([
299
- "--git-dir",
300
- entry.target.repositoryCommonDir,
301
- "worktree",
302
- "list",
303
- "--porcelain",
304
- "-z",
305
- ]);
306
- if (!registrationMatches(records, entry.quarantinePath, entry, "owned")) {
307
- throw new WorktreeRecoveryError("QUARANTINE_REGISTRATION_CHANGED", "quarantined worktree could not be relocked during recovery", entry);
308
- }
309
- }
310
- async function verifyRecoveryPath(entry, options, dependencies, path, identity, allowMissingRecoveryRef, lockExpectation, expectedRegistrationPaths) {
311
- assertSupportedPlatform(entry, options);
312
- assertManifestPath(entry, options);
313
- const [stats, commonDirStats] = await Promise.all([
314
- dependencies.inspect(path),
315
- dependencies.inspect(entry.target.repositoryCommonDir),
316
- ]);
317
- if (!stats.isDirectory() ||
318
- stats.isSymbolicLink() ||
319
- stats.dev !== identity.device ||
320
- stats.ino !== identity.inode ||
321
- stats.mtimeMs !== identity.mtimeMs ||
322
- !commonDirStats.isDirectory() ||
323
- commonDirStats.isSymbolicLink()) {
324
- throw new WorktreeRecoveryError("QUARANTINE_IDENTITY_CHANGED", "recovery worktree filesystem identity changed", entry);
325
- }
326
- await reconcileOwnedWorktreeLockClaim({
327
- worktreePath: path,
328
- repositoryCommonDir: entry.target.repositoryCommonDir,
329
- expectedReason: quarantineLockReason(entry),
330
- claimId: entry.entryId,
331
- runGit: dependencies.runGit,
332
- platform: options.dependencies?.platform ?? process.platform,
333
- });
334
- const measurement = await dependencies.measure(path, {
335
- maxEntries: entry.measurementMaxEntries,
336
- excludeRootEntries: [".git"],
337
- });
338
- if (measurement.truncated ||
339
- measurement.specialEntries > 0 ||
340
- measurement.mountBoundaries > 0 ||
341
- measurement.bytes !== identity.measuredBytes ||
342
- measurement.newestMtimeMs !== identity.newestMtimeMs ||
343
- measurement.fingerprint !== identity.fingerprint) {
344
- throw new WorktreeRecoveryError("QUARANTINE_CONTENT_CHANGED", "recovery worktree contents changed", entry);
345
- }
346
- const ownership = await dependencies.processProbe(path);
347
- if (ownership.status !== "idle") {
348
- throw new WorktreeRecoveryError(ownership.status === "busy" ? "QUARANTINE_PROCESS_ACTIVE" : "QUARANTINE_PROCESS_UNKNOWN", "recovery worktree process ownership is not idle", entry);
349
- }
350
- const mounts = await dependencies.mountProbe(path);
351
- if (mounts.status !== "clear") {
352
- throw new WorktreeRecoveryError(mounts.status === "blocked"
353
- ? "QUARANTINE_MOUNT_BOUNDARY"
354
- : "QUARANTINE_MOUNT_INSPECTION_UNKNOWN", "recovery worktree mount state is not clear", entry);
355
- }
356
- await assertNoGitOperations(entry, path, dependencies);
357
- await assertTargetRegistrationLock(entry, dependencies, lockExpectation, expectedRegistrationPaths);
358
- await dependencies.runGit([
359
- "--git-dir",
360
- entry.target.repositoryCommonDir,
361
- "worktree",
362
- "repair",
363
- path,
364
- ]);
365
- const status = parseGitStatusPorcelainV2(await dependencies.runGit([
366
- "-C",
367
- path,
368
- "status",
369
- "--porcelain=v2",
370
- "--branch",
371
- "-z",
372
- "--untracked-files=all",
373
- "--ignored=matching",
374
- ]));
375
- const statusSuppressedEntries = countStatusSuppressedIndexEntries(await dependencies.runGit(["-C", path, "ls-files", "-z", "-v"]));
376
- if (status.head !== entry.target.head ||
377
- branchRef(status.branch) !== entry.target.branch ||
378
- status.staged + status.modified + status.untracked + status.conflicted + status.ignored > 0 ||
379
- statusSuppressedEntries > 0) {
380
- throw new WorktreeRecoveryError("QUARANTINE_GIT_STATE_CHANGED", "recovery worktree Git state changed", entry);
381
- }
382
- await assertNoGitOperations(entry, path, dependencies);
383
- const records = await dependencies.runGit([
384
- "--git-dir",
385
- entry.target.repositoryCommonDir,
386
- "worktree",
387
- "list",
388
- "--porcelain",
389
- "-z",
390
- ]);
391
- if (!registrationMatches(records, path, entry, lockExpectation)) {
392
- throw new WorktreeRecoveryError("QUARANTINE_REGISTRATION_CHANGED", "recovery worktree registration could not be repaired", entry);
393
- }
394
- const recoveryHead = await readRecoveryRef(entry, dependencies);
395
- if (recoveryHead !== entry.target.head &&
396
- !(allowMissingRecoveryRef && recoveryHead === undefined)) {
397
- throw new WorktreeRecoveryError("QUARANTINE_RECOVERY_REF_CHANGED", "recovery ref no longer points to the planned HEAD", entry);
398
- }
399
- }
400
- async function recoverInitialQuarantineForUndo(entry, options) {
401
- const dependencies = resolveDependencies(options);
402
- const [originalExists, quarantineExists] = await Promise.all([
403
- pathExists(entry.originalPath, dependencies.inspect),
404
- pathExists(entry.quarantinePath, dependencies.inspect),
405
- ]);
406
- if (originalExists && !quarantineExists) {
407
- const expectedRegistrationPaths = entry.status === "moved" ? [entry.originalPath, entry.quarantinePath] : [entry.originalPath];
408
- await verifyRecoveryPath(entry, options, dependencies, entry.originalPath, entry.target, true, "owned-or-unlocked", expectedRegistrationPaths);
409
- await releaseOwnedRegistrationLock(entry, options, dependencies, entry.originalPath);
410
- await deleteRecoveryRef(entry, dependencies);
411
- return persist({
412
- ...entry,
413
- status: "restored",
414
- restoredAt: dependencies.clock().toISOString(),
415
- }, options);
416
- }
417
- if (quarantineExists && !originalExists) {
418
- await verifyRecoveryPath(entry, options, dependencies, entry.quarantinePath, entry.target, true, "owned-or-unlocked", [entry.originalPath, entry.quarantinePath]);
419
- await ensureRecoveryRef(entry, dependencies);
420
- const records = await dependencies.runGit([
421
- "--git-dir",
422
- entry.target.repositoryCommonDir,
423
- "worktree",
424
- "list",
425
- "--porcelain",
426
- "-z",
427
- ]);
428
- if (!registrationMatches(records, entry.quarantinePath, entry, "owned")) {
429
- await dependencies.runGit([
430
- "--git-dir",
431
- entry.target.repositoryCommonDir,
432
- "worktree",
433
- "lock",
434
- "--reason",
435
- quarantineLockReason(entry),
436
- entry.quarantinePath,
437
- ]);
438
- await verifyLockedRegistration(entry, dependencies);
439
- }
440
- const [stats, measurement] = await Promise.all([
441
- dependencies.inspect(entry.quarantinePath),
442
- dependencies.measure(entry.quarantinePath, {
443
- maxEntries: entry.measurementMaxEntries,
444
- excludeRootEntries: [".git"],
445
- }),
446
- ]);
447
- return persist({
448
- ...entry,
449
- status: "quarantined",
450
- quarantineIdentity: {
451
- ...entry.target,
452
- path: entry.quarantinePath,
453
- device: stats.dev,
454
- inode: stats.ino,
455
- mtimeMs: stats.mtimeMs,
456
- measuredBytes: measurement.bytes,
457
- newestMtimeMs: measurement.newestMtimeMs,
458
- fingerprint: measurement.fingerprint,
459
- },
460
- }, options);
461
- }
462
- throw new WorktreeRecoveryError("QUARANTINE_INITIAL_TRANSITION_AMBIGUOUS", "interrupted quarantine has ambiguous source and destination paths", entry);
463
- }
464
- async function releaseOwnedRegistrationLock(entry, options, dependencies, worktreePath) {
465
- const registrations = await dependencies.runGit([
466
- "--git-dir",
467
- entry.target.repositoryCommonDir,
468
- "worktree",
469
- "list",
470
- "--porcelain",
471
- "-z",
472
- ]);
473
- if (!registrationMatches(registrations, worktreePath, entry, "owned")) {
474
- return;
475
- }
476
- await unlockOwnedWorktree({
477
- worktreePath,
478
- repositoryCommonDir: entry.target.repositoryCommonDir,
479
- expectedReason: quarantineLockReason(entry),
480
- claimId: entry.entryId,
481
- runGit: dependencies.runGit,
482
- platform: options.dependencies?.platform ?? process.platform,
483
- });
484
- await assertTargetRegistrationLock(entry, dependencies, "unlocked", [worktreePath]);
485
- }
486
- async function resumeInterruptedUndo(entry, options) {
487
- const dependencies = resolveDependencies(options);
488
- const [originalExists, quarantineExists] = await Promise.all([
489
- pathExists(entry.originalPath, dependencies.inspect),
490
- pathExists(entry.quarantinePath, dependencies.inspect),
491
- ]);
492
- if (quarantineExists && !originalExists) {
493
- const validated = await validateQuarantinedEntry(entry, options, false, ["restoring"], "owned-or-unlocked");
494
- if (!validated.registrationLocked) {
495
- await dependencies.runGit([
496
- "--git-dir",
497
- entry.target.repositoryCommonDir,
498
- "worktree",
499
- "lock",
500
- "--reason",
501
- quarantineLockReason(entry),
502
- entry.quarantinePath,
503
- ]);
504
- await verifyLockedRegistration(entry, dependencies);
505
- }
506
- return persist({ ...entry, status: "quarantined" }, options);
507
- }
508
- if (originalExists && !quarantineExists) {
509
- const identity = entry.quarantineIdentity ??
510
- (() => {
511
- throw new WorktreeRecoveryError("QUARANTINE_IDENTITY_MISSING", "post-repair quarantine identity is missing", entry);
512
- })();
513
- await verifyRecoveryPath(entry, options, dependencies, entry.originalPath, identity, true, "unlocked", [entry.quarantinePath, entry.originalPath]);
514
- await deleteRecoveryRef(entry, dependencies);
515
- const restored = await persist({
516
- ...entry,
517
- status: "restored",
518
- restoredAt: dependencies.clock().toISOString(),
519
- }, options);
520
- return restored;
521
- }
522
- throw new WorktreeRecoveryError("QUARANTINE_UNDO_TRANSITION_AMBIGUOUS", "interrupted undo has ambiguous source and destination paths", entry);
523
- }
524
188
  export function worktreePurgeIsolationPath(entry) {
525
189
  return `${entry.quarantinePath}.purging`;
526
190
  }
527
- async function recoverPartialForUndo(entry, options) {
528
- const dependencies = resolveDependencies(options);
529
- const isolationPath = worktreePurgeIsolationPath(entry);
530
- const [originalExists, quarantineExists, isolationExists] = await Promise.all([
531
- pathExists(entry.originalPath, dependencies.inspect),
532
- pathExists(entry.quarantinePath, dependencies.inspect),
533
- pathExists(isolationPath, dependencies.inspect),
534
- ]);
535
- if ([originalExists, quarantineExists, isolationExists].filter(Boolean).length !== 1) {
536
- throw new WorktreeRecoveryError("QUARANTINE_PARTIAL_TRANSITION_AMBIGUOUS", "partial quarantine recovery requires exactly one known worktree path", entry);
537
- }
538
- if (originalExists) {
539
- await verifyRecoveryPath(entry, options, dependencies, entry.originalPath, entry.quarantineIdentity ?? entry.target, true, "owned-or-unlocked", [entry.originalPath, entry.quarantinePath, isolationPath]);
540
- await releaseOwnedRegistrationLock(entry, options, dependencies, entry.originalPath);
541
- await deleteRecoveryRef(entry, dependencies);
542
- return persist({
543
- ...entry,
544
- status: "restored",
545
- restoredAt: dependencies.clock().toISOString(),
546
- }, options);
547
- }
548
- if (isolationExists) {
549
- const identity = entry.quarantineIdentity ??
550
- (() => {
551
- throw new WorktreeRecoveryError("QUARANTINE_IDENTITY_MISSING", "partial purge recovery requires post-repair quarantine identity", entry);
552
- })();
553
- await verifyRecoveryPath(entry, options, dependencies, isolationPath, identity, false, "unlocked", [entry.quarantinePath, isolationPath]);
554
- await dependencies.move(isolationPath, entry.quarantinePath);
555
- }
556
- const identity = entry.quarantineIdentity ?? entry.target;
557
- await verifyRecoveryPath(entry, options, dependencies, entry.quarantinePath, identity, true, "owned-or-unlocked", [entry.originalPath, entry.quarantinePath, isolationPath]);
558
- await ensureRecoveryRef(entry, dependencies);
559
- const records = await dependencies.runGit([
560
- "--git-dir",
561
- entry.target.repositoryCommonDir,
562
- "worktree",
563
- "list",
564
- "--porcelain",
565
- "-z",
566
- ]);
567
- if (!registrationMatches(records, entry.quarantinePath, entry, "owned")) {
568
- await dependencies.runGit([
569
- "--git-dir",
570
- entry.target.repositoryCommonDir,
571
- "worktree",
572
- "lock",
573
- "--reason",
574
- quarantineLockReason(entry),
575
- entry.quarantinePath,
576
- ]);
577
- await verifyLockedRegistration(entry, dependencies);
578
- }
579
- const [stats, measurement] = await Promise.all([
580
- dependencies.inspect(entry.quarantinePath),
581
- dependencies.measure(entry.quarantinePath, {
582
- maxEntries: entry.measurementMaxEntries,
583
- excludeRootEntries: [".git"],
584
- }),
585
- ]);
586
- return persist({
587
- ...entry,
588
- status: "quarantined",
589
- quarantineIdentity: {
590
- ...identity,
591
- path: entry.quarantinePath,
592
- device: stats.dev,
593
- inode: stats.ino,
594
- mtimeMs: stats.mtimeMs,
595
- measuredBytes: measurement.bytes,
596
- newestMtimeMs: measurement.newestMtimeMs,
597
- fingerprint: measurement.fingerprint,
598
- },
599
- }, options);
600
- }
601
- async function rollbackPurgeIsolation(entry, isolationPath, options, dependencies, error) {
602
- try {
603
- if ((await pathExists(entry.quarantinePath, dependencies.inspect)) ||
604
- !(await pathExists(isolationPath, dependencies.inspect))) {
605
- throw new Error("worktree paths are not safe for purge isolation rollback");
606
- }
607
- await assertNoGitOperations(entry, isolationPath, dependencies);
608
- await assertTargetRegistrationLock(entry, dependencies, "unlocked", [
609
- entry.quarantinePath,
610
- isolationPath,
611
- ]);
612
- await dependencies.move(isolationPath, entry.quarantinePath);
613
- await assertNoGitOperations(entry, entry.quarantinePath, dependencies);
614
- await dependencies.runGit([
615
- "--git-dir",
616
- entry.target.repositoryCommonDir,
617
- "worktree",
618
- "repair",
619
- entry.quarantinePath,
620
- ]);
621
- await dependencies.runGit([
622
- "--git-dir",
623
- entry.target.repositoryCommonDir,
624
- "worktree",
625
- "lock",
626
- "--reason",
627
- quarantineLockReason(entry),
628
- entry.quarantinePath,
629
- ]);
630
- await verifyLockedRegistration(entry, dependencies);
631
- const recovered = await persist({
632
- ...entry,
633
- status: "quarantined",
634
- diagnostic: {
635
- severity: "error",
636
- code: "QUARANTINE_PURGE_FAILED",
637
- message: error instanceof Error ? error.message : String(error),
638
- adapter: "git",
639
- resourceId: entry.resourceId,
640
- },
641
- }, options);
642
- throw new WorktreeRecoveryError("QUARANTINE_PURGE_FAILED", "purge failed and the isolated worktree was returned to locked quarantine", recovered, { cause: error });
643
- }
644
- catch (recoveryError) {
645
- if (recoveryError instanceof WorktreeRecoveryError && recoveryError.cause === error) {
646
- throw recoveryError;
647
- }
648
- const partial = await persist({
649
- ...entry,
650
- status: "partial",
651
- diagnostic: {
652
- severity: "error",
653
- code: "QUARANTINE_PURGE_PARTIAL",
654
- message: `purge left partial state: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`,
655
- adapter: "git",
656
- resourceId: entry.resourceId,
657
- },
658
- }, options).catch(() => entry);
659
- throw new WorktreeRecoveryError("QUARANTINE_PURGE_PARTIAL", `purge left partial state; inspect ${options.manifestPath}`, partial, { cause: recoveryError });
660
- }
661
- }
662
- async function resumeInterruptedPurge(entry, options) {
663
- const dependencies = resolveDependencies(options);
664
- const isolationPath = worktreePurgeIsolationPath(entry);
665
- const [quarantineExists, isolationExists] = await Promise.all([
666
- pathExists(entry.quarantinePath, dependencies.inspect),
667
- pathExists(isolationPath, dependencies.inspect),
668
- ]);
669
- if (quarantineExists && isolationExists) {
670
- throw new WorktreeRecoveryError("QUARANTINE_PURGE_TRANSITION_AMBIGUOUS", "interrupted purge has both source and isolation paths", entry);
671
- }
672
- if (quarantineExists) {
673
- const validated = await validateQuarantinedEntry(entry, options, false, ["purging"], "owned-or-unlocked");
674
- if (!validated.registrationLocked) {
675
- await dependencies.runGit([
676
- "--git-dir",
677
- entry.target.repositoryCommonDir,
678
- "worktree",
679
- "lock",
680
- "--reason",
681
- quarantineLockReason(entry),
682
- entry.quarantinePath,
683
- ]);
684
- await verifyLockedRegistration(entry, dependencies);
685
- }
686
- return persist({ ...entry, status: "quarantined" }, options);
687
- }
688
- if (isolationExists) {
689
- try {
690
- await assertNoGitOperations(entry, isolationPath, dependencies);
691
- await assertTargetRegistrationLock(entry, dependencies, "unlocked", [
692
- entry.quarantinePath,
693
- isolationPath,
694
- ]);
695
- await dependencies.runGit([
696
- "--git-dir",
697
- entry.target.repositoryCommonDir,
698
- "worktree",
699
- "repair",
700
- isolationPath,
701
- ]);
702
- await validateQuarantinedEntry(entry, options, false, ["purging"], "unlocked", isolationPath);
703
- await options.revalidateProtection?.(entry);
704
- await validateQuarantinedEntry(entry, options, false, ["purging"], "unlocked", isolationPath);
705
- await dependencies.runGit([
706
- "--git-dir",
707
- entry.target.repositoryCommonDir,
708
- "worktree",
709
- "remove",
710
- isolationPath,
711
- ]);
712
- if (await pathExists(isolationPath, dependencies.inspect)) {
713
- throw new WorktreeRecoveryError("QUARANTINE_PURGE_TRANSITION_AMBIGUOUS", "Git reported success but the purge isolation path remains", entry);
714
- }
715
- }
716
- catch (error) {
717
- if (isImmutableRecoveryProtection(error)) {
718
- throw error;
719
- }
720
- return rollbackPurgeIsolation(entry, isolationPath, options, dependencies, error);
721
- }
722
- }
723
- if (!quarantineExists && !isolationExists) {
724
- assertSupportedPlatform(entry, options);
725
- assertManifestPath(entry, options);
726
- const records = await dependencies.runGit([
727
- "--git-dir",
728
- entry.target.repositoryCommonDir,
729
- "worktree",
730
- "list",
731
- "--porcelain",
732
- "-z",
733
- ]);
734
- if (parseWorktreePorcelain(records).some((record) => record.path === entry.quarantinePath ||
735
- record.path === isolationPath ||
736
- (record.head === entry.target.head && record.branch === entry.target.branch))) {
737
- throw new WorktreeRecoveryError("QUARANTINE_REGISTRATION_CHANGED", "interrupted purge left or moved the target worktree registration", entry);
738
- }
739
- const recoveryHead = await readRecoveryRef(entry, dependencies);
740
- if (recoveryHead !== undefined && recoveryHead !== entry.target.head) {
741
- throw new WorktreeRecoveryError("QUARANTINE_RECOVERY_REF_CHANGED", "recovery ref no longer points to the planned HEAD", entry);
742
- }
743
- await deleteRecoveryRef(entry, dependencies);
744
- const purged = await persist({
745
- ...entry,
746
- status: "purged",
747
- purgedAt: dependencies.clock().toISOString(),
748
- }, options);
749
- return { entry: purged, reclaimedBytes: purged.target.measuredBytes };
750
- }
751
- return resumeInterruptedPurge(entry, options);
752
- }
753
- export async function undoWorktreeQuarantine(input, options) {
754
- let entry = quarantineEntrySchema.parse(input);
755
- if (entry.status === "partial") {
756
- entry = await recoverPartialForUndo(entry, options);
757
- if (entry.status === "restored") {
758
- return entry;
759
- }
760
- }
761
- if (["preparing", "recovery-ref-created", "moved"].includes(entry.status)) {
762
- entry = await recoverInitialQuarantineForUndo(entry, options);
763
- if (entry.status === "restored") {
764
- return entry;
765
- }
766
- }
767
- if (entry.status === "restoring") {
768
- entry = await resumeInterruptedUndo(entry, options);
769
- if (entry.status === "restored") {
770
- return entry;
771
- }
772
- }
773
- const { dependencies } = await validateQuarantinedEntry(entry, options, true);
774
- entry = await persist({ ...entry, status: "restoring" }, options);
775
- let unlocked = false;
776
- let moved = false;
777
- let finalizing = false;
778
- try {
779
- await unlockOwnedWorktree({
780
- worktreePath: entry.quarantinePath,
781
- repositoryCommonDir: entry.target.repositoryCommonDir,
782
- expectedReason: quarantineLockReason(entry),
783
- claimId: entry.entryId,
784
- runGit: dependencies.runGit,
785
- platform: options.dependencies?.platform ?? process.platform,
786
- });
787
- unlocked = true;
788
- await assertTargetRegistrationLock(entry, dependencies, "unlocked", [entry.quarantinePath]);
789
- if (await pathExists(entry.originalPath, dependencies.inspect)) {
790
- throw new Error(`original path became occupied before undo: ${entry.originalPath}`);
791
- }
792
- await dependencies.move(entry.quarantinePath, entry.originalPath);
793
- moved = true;
794
- const identity = entry.quarantineIdentity ??
795
- (() => {
796
- throw new WorktreeRecoveryError("QUARANTINE_IDENTITY_MISSING", "post-repair quarantine identity is missing", entry);
797
- })();
798
- await verifyRecoveryPath(entry, options, dependencies, entry.originalPath, identity, false, "unlocked", [entry.quarantinePath, entry.originalPath]);
799
- await deleteRecoveryRef(entry, dependencies);
800
- finalizing = true;
801
- entry = await persist({
802
- ...entry,
803
- status: "restored",
804
- restoredAt: dependencies.clock().toISOString(),
805
- }, options);
806
- return entry;
807
- }
808
- catch (error) {
809
- if (finalizing) {
810
- throw new WorktreeRecoveryError("QUARANTINE_UNDO_FINALIZE_PENDING", "undo restored the worktree but could not persist terminal state; retry undo", entry, { cause: error });
811
- }
812
- if (moved && isImmutableRecoveryProtection(error)) {
813
- throw error;
814
- }
815
- try {
816
- if (moved) {
817
- await assertNoGitOperations(entry, entry.originalPath, dependencies);
818
- await assertTargetRegistrationLock(entry, dependencies, "unlocked", [
819
- entry.quarantinePath,
820
- entry.originalPath,
821
- ]);
822
- if ((await pathExists(entry.quarantinePath, dependencies.inspect)) ||
823
- !(await pathExists(entry.originalPath, dependencies.inspect))) {
824
- throw new Error("worktree paths are not safe for undo rollback");
825
- }
826
- await dependencies.move(entry.originalPath, entry.quarantinePath);
827
- await dependencies.runGit([
828
- "--git-dir",
829
- entry.target.repositoryCommonDir,
830
- "worktree",
831
- "repair",
832
- entry.quarantinePath,
833
- ]);
834
- }
835
- if (unlocked) {
836
- await dependencies.runGit([
837
- "--git-dir",
838
- entry.target.repositoryCommonDir,
839
- "worktree",
840
- "lock",
841
- "--reason",
842
- quarantineLockReason(entry),
843
- entry.quarantinePath,
844
- ]);
845
- }
846
- entry = await persist({
847
- ...entry,
848
- status: "quarantined",
849
- diagnostic: {
850
- severity: "error",
851
- code: "QUARANTINE_UNDO_FAILED",
852
- message: error instanceof Error ? error.message : String(error),
853
- adapter: "git",
854
- resourceId: entry.resourceId,
855
- },
856
- }, options);
857
- throw new WorktreeRecoveryError("QUARANTINE_UNDO_FAILED", "undo failed and the quarantine entry was restored", entry, { cause: error });
858
- }
859
- catch (rollbackError) {
860
- if (rollbackError instanceof WorktreeRecoveryError && rollbackError.cause === error) {
861
- throw rollbackError;
862
- }
863
- entry = await persist({
864
- ...entry,
865
- status: "partial",
866
- diagnostic: {
867
- severity: "error",
868
- code: "QUARANTINE_UNDO_PARTIAL",
869
- message: `undo failed and rollback was incomplete: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`,
870
- adapter: "git",
871
- resourceId: entry.resourceId,
872
- },
873
- }, options).catch(() => entry);
874
- throw new WorktreeRecoveryError("QUARANTINE_UNDO_PARTIAL", `undo left partial state; inspect ${options.manifestPath}`, entry, { cause: rollbackError });
875
- }
876
- }
877
- }
878
- export async function purgeWorktreeQuarantine(input, options) {
879
- let entry = quarantineEntrySchema.parse(input);
880
- if (entry.status === "purging") {
881
- const resumed = await resumeInterruptedPurge(entry, options);
882
- if ("entry" in resumed) {
883
- return resumed;
884
- }
885
- entry = resumed;
886
- }
887
- const { dependencies } = await validateQuarantinedEntry(entry, options, false);
888
- if (options.allowUnexpired !== true &&
889
- dependencies.clock().getTime() < Date.parse(entry.expiresAt)) {
890
- throw new WorktreeRecoveryError("QUARANTINE_NOT_EXPIRED", `quarantine entry does not expire until ${entry.expiresAt}`, entry);
891
- }
892
- entry = await persist({ ...entry, status: "purging" }, options);
893
- const isolationPath = worktreePurgeIsolationPath(entry);
894
- let unlocked = false;
895
- let isolated = false;
896
- let removed = false;
897
- try {
898
- await unlockOwnedWorktree({
899
- worktreePath: entry.quarantinePath,
900
- repositoryCommonDir: entry.target.repositoryCommonDir,
901
- expectedReason: quarantineLockReason(entry),
902
- claimId: entry.entryId,
903
- runGit: dependencies.runGit,
904
- platform: options.dependencies?.platform ?? process.platform,
905
- });
906
- unlocked = true;
907
- await validateQuarantinedEntry(entry, options, false, ["purging"], "unlocked");
908
- if (await pathExists(isolationPath, dependencies.inspect)) {
909
- throw new Error(`purge isolation path already exists: ${isolationPath}`);
910
- }
911
- await dependencies.move(entry.quarantinePath, isolationPath);
912
- isolated = true;
913
- await assertNoGitOperations(entry, isolationPath, dependencies);
914
- await assertTargetRegistrationLock(entry, dependencies, "unlocked", [
915
- entry.quarantinePath,
916
- isolationPath,
917
- ]);
918
- await dependencies.runGit([
919
- "--git-dir",
920
- entry.target.repositoryCommonDir,
921
- "worktree",
922
- "repair",
923
- isolationPath,
924
- ]);
925
- await validateQuarantinedEntry(entry, options, false, ["purging"], "unlocked", isolationPath);
926
- await options.revalidateProtection?.(entry);
927
- await validateQuarantinedEntry(entry, options, false, ["purging"], "unlocked", isolationPath);
928
- await dependencies.runGit([
929
- "--git-dir",
930
- entry.target.repositoryCommonDir,
931
- "worktree",
932
- "remove",
933
- isolationPath,
934
- ]);
935
- if (await pathExists(isolationPath, dependencies.inspect)) {
936
- throw new Error("Git reported success but the purge isolation path still exists");
937
- }
938
- removed = true;
939
- const records = await dependencies.runGit([
940
- "--git-dir",
941
- entry.target.repositoryCommonDir,
942
- "worktree",
943
- "list",
944
- "--porcelain",
945
- "-z",
946
- ]);
947
- if (parseWorktreePorcelain(records).some((record) => record.path === isolationPath ||
948
- (record.head === entry.target.head && record.branch === entry.target.branch))) {
949
- throw new Error("Git reported success but the target worktree registration remains or moved");
950
- }
951
- await deleteRecoveryRef(entry, dependencies);
952
- entry = await persist({
953
- ...entry,
954
- status: "purged",
955
- purgedAt: dependencies.clock().toISOString(),
956
- }, options);
957
- return { entry, reclaimedBytes: entry.target.measuredBytes };
958
- }
959
- catch (error) {
960
- if (removed) {
961
- throw new WorktreeRecoveryError("QUARANTINE_PURGE_FINALIZE_PENDING", "purge removed the worktree but could not persist terminal state; retry purge", entry, { cause: error });
962
- }
963
- if (isolated && isImmutableRecoveryProtection(error)) {
964
- throw error;
965
- }
966
- try {
967
- if (isolated) {
968
- return rollbackPurgeIsolation(entry, isolationPath, options, dependencies, error);
969
- }
970
- if (await pathExists(entry.quarantinePath, dependencies.inspect)) {
971
- if (unlocked) {
972
- await dependencies.runGit([
973
- "--git-dir",
974
- entry.target.repositoryCommonDir,
975
- "worktree",
976
- "lock",
977
- "--reason",
978
- quarantineLockReason(entry),
979
- entry.quarantinePath,
980
- ]);
981
- }
982
- entry = await persist({
983
- ...entry,
984
- status: "quarantined",
985
- diagnostic: {
986
- severity: "error",
987
- code: "QUARANTINE_PURGE_FAILED",
988
- message: error instanceof Error ? error.message : String(error),
989
- adapter: "git",
990
- resourceId: entry.resourceId,
991
- },
992
- }, options);
993
- throw new WorktreeRecoveryError("QUARANTINE_PURGE_FAILED", unlocked
994
- ? "purge failed and the quarantine entry was relocked"
995
- : "purge failed before mutation and the quarantine entry remains retryable", entry, { cause: error });
996
- }
997
- throw error;
998
- }
999
- catch (recoveryError) {
1000
- if (recoveryError instanceof WorktreeRecoveryError && recoveryError.cause === error) {
1001
- throw recoveryError;
1002
- }
1003
- entry = await persist({
1004
- ...entry,
1005
- status: "partial",
1006
- diagnostic: {
1007
- severity: "error",
1008
- code: "QUARANTINE_PURGE_PARTIAL",
1009
- message: `purge left partial state: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`,
1010
- adapter: "git",
1011
- resourceId: entry.resourceId,
1012
- },
1013
- }, options).catch(() => entry);
1014
- throw new WorktreeRecoveryError("QUARANTINE_PURGE_PARTIAL", `purge left partial state; inspect ${options.manifestPath}`, entry, { cause: recoveryError });
1015
- }
1016
- }
1017
- }
1018
191
  //# sourceMappingURL=worktree-recovery.js.map