@cerbur/clutch-dsh-worktree 0.1.9 → 0.1.10

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 (501) hide show
  1. package/README.md +99 -23
  2. package/README.zh.md +75 -19
  3. package/lib/client/WorktreeSurface.d.ts +4 -7
  4. package/lib/client/WorktreeSurface.d.ts.map +1 -1
  5. package/lib/client/WorktreeSurface.js +44 -1419
  6. package/lib/client/WorktreeSurface.js.map +1 -1
  7. package/lib/client/{WorktreeContext.d.ts → context/WorktreeContext.d.ts} +1 -1
  8. package/lib/client/context/WorktreeContext.d.ts.map +1 -0
  9. package/lib/client/context/WorktreeContext.js.map +1 -0
  10. package/lib/client/{WorktreeHeroContext.d.ts → context/WorktreeHeroContext.d.ts} +1 -1
  11. package/lib/client/context/WorktreeHeroContext.d.ts.map +1 -0
  12. package/lib/client/context/WorktreeHeroContext.js.map +1 -0
  13. package/lib/client/{worktree-context-store.d.ts → context/worktree-context-store.d.ts} +1 -1
  14. package/lib/client/context/worktree-context-store.d.ts.map +1 -0
  15. package/lib/client/{worktree-context-store.js → context/worktree-context-store.js} +2 -2
  16. package/lib/client/context/worktree-context-store.js.map +1 -0
  17. package/lib/client/{worktree-context.d.ts → context/worktree-context.d.ts} +1 -1
  18. package/lib/client/context/worktree-context.d.ts.map +1 -0
  19. package/lib/client/{worktree-context.js → context/worktree-context.js} +5 -3
  20. package/lib/client/context/worktree-context.js.map +1 -0
  21. package/lib/client/entry.d.ts +1 -1
  22. package/lib/client/entry.d.ts.map +1 -1
  23. package/lib/client/entry.js +25 -13
  24. package/lib/client/entry.js.map +1 -1
  25. package/lib/client/index.d.ts +3 -3
  26. package/lib/client/index.d.ts.map +1 -1
  27. package/lib/client/index.js +2 -2
  28. package/lib/client/index.js.map +1 -1
  29. package/lib/client/locales.d.ts +66 -0
  30. package/lib/client/locales.d.ts.map +1 -1
  31. package/lib/client/locales.js +76 -10
  32. package/lib/client/locales.js.map +1 -1
  33. package/lib/client/{WorktreeOverlay.d.ts → overlay/WorktreeOverlay.d.ts} +2 -2
  34. package/lib/client/overlay/WorktreeOverlay.d.ts.map +1 -0
  35. package/lib/client/{WorktreeOverlay.js → overlay/WorktreeOverlay.js} +2 -2
  36. package/lib/client/overlay/WorktreeOverlay.js.map +1 -0
  37. package/lib/client/overlay/overlay-bounds.d.ts.map +1 -0
  38. package/lib/client/overlay/overlay-bounds.js.map +1 -0
  39. package/lib/client/overlay/sidebar-overlay-geometry.d.ts.map +1 -0
  40. package/lib/client/overlay/sidebar-overlay-geometry.js.map +1 -0
  41. package/lib/client/permission/worktree-permission-icon.d.ts.map +1 -0
  42. package/lib/client/permission/worktree-permission-icon.js.map +1 -0
  43. package/lib/client/permission/worktree-permission.d.ts.map +1 -0
  44. package/lib/client/permission/worktree-permission.js.map +1 -0
  45. package/lib/client/session/session-view.d.ts.map +1 -0
  46. package/lib/client/session/session-view.js.map +1 -0
  47. package/lib/client/{virtual-workspace-membership.d.ts → session/virtual-workspace-membership.d.ts} +1 -1
  48. package/lib/client/session/virtual-workspace-membership.d.ts.map +1 -0
  49. package/lib/client/{virtual-workspace-membership.js → session/virtual-workspace-membership.js} +1 -1
  50. package/lib/client/session/virtual-workspace-membership.js.map +1 -0
  51. package/lib/client/{worktree-session-fork.d.ts → session/worktree-session-fork.d.ts} +7 -1
  52. package/lib/client/session/worktree-session-fork.d.ts.map +1 -0
  53. package/lib/client/{worktree-session-fork.js → session/worktree-session-fork.js} +50 -4
  54. package/lib/client/session/worktree-session-fork.js.map +1 -0
  55. package/lib/client/session/worktree-session-order.d.ts.map +1 -0
  56. package/lib/client/session/worktree-session-order.js.map +1 -0
  57. package/lib/client/session/worktree-session-position.d.ts.map +1 -0
  58. package/lib/client/session/worktree-session-position.js.map +1 -0
  59. package/lib/client/{worktree-session.d.ts → session/worktree-session.d.ts} +3 -3
  60. package/lib/client/session/worktree-session.d.ts.map +1 -0
  61. package/lib/client/{worktree-session.js → session/worktree-session.js} +3 -3
  62. package/lib/client/session/worktree-session.js.map +1 -0
  63. package/lib/client/surface/actions/lifecycle-commands.d.ts +9 -0
  64. package/lib/client/surface/actions/lifecycle-commands.d.ts.map +1 -0
  65. package/lib/client/surface/actions/lifecycle-commands.js +243 -0
  66. package/lib/client/surface/actions/lifecycle-commands.js.map +1 -0
  67. package/lib/client/surface/actions/useDragActions.d.ts +26 -0
  68. package/lib/client/surface/actions/useDragActions.d.ts.map +1 -0
  69. package/lib/client/surface/actions/useDragActions.js +125 -0
  70. package/lib/client/surface/actions/useDragActions.js.map +1 -0
  71. package/lib/client/surface/actions/useLifecycleActions.d.ts +30 -0
  72. package/lib/client/surface/actions/useLifecycleActions.d.ts.map +1 -0
  73. package/lib/client/surface/actions/useLifecycleActions.js +140 -0
  74. package/lib/client/surface/actions/useLifecycleActions.js.map +1 -0
  75. package/lib/client/surface/actions/useNativeActions.d.ts +48 -0
  76. package/lib/client/surface/actions/useNativeActions.d.ts.map +1 -0
  77. package/lib/client/surface/actions/useNativeActions.js +182 -0
  78. package/lib/client/surface/actions/useNativeActions.js.map +1 -0
  79. package/lib/client/surface/actions/useSessionActions.d.ts +24 -0
  80. package/lib/client/surface/actions/useSessionActions.d.ts.map +1 -0
  81. package/lib/client/surface/actions/useSessionActions.js +116 -0
  82. package/lib/client/surface/actions/useSessionActions.js.map +1 -0
  83. package/lib/client/surface/actions/useSurfaceMutation.d.ts +15 -0
  84. package/lib/client/surface/actions/useSurfaceMutation.d.ts.map +1 -0
  85. package/lib/client/surface/actions/useSurfaceMutation.js +24 -0
  86. package/lib/client/surface/actions/useSurfaceMutation.js.map +1 -0
  87. package/lib/client/surface/actions/useWorktreeRegistration.d.ts +31 -0
  88. package/lib/client/surface/actions/useWorktreeRegistration.d.ts.map +1 -0
  89. package/lib/client/surface/actions/useWorktreeRegistration.js +203 -0
  90. package/lib/client/surface/actions/useWorktreeRegistration.js.map +1 -0
  91. package/lib/client/surface/actions/worktree-cleanup-flow.d.ts +10 -0
  92. package/lib/client/surface/actions/worktree-cleanup-flow.d.ts.map +1 -0
  93. package/lib/client/surface/actions/worktree-cleanup-flow.js +19 -0
  94. package/lib/client/surface/actions/worktree-cleanup-flow.js.map +1 -0
  95. package/lib/client/surface/components/AccessConfirmation.d.ts +9 -0
  96. package/lib/client/surface/components/AccessConfirmation.d.ts.map +1 -0
  97. package/lib/client/surface/components/AccessConfirmation.js +18 -0
  98. package/lib/client/surface/components/AccessConfirmation.js.map +1 -0
  99. package/lib/client/surface/components/ActiveWorktree.d.ts +28 -0
  100. package/lib/client/surface/components/ActiveWorktree.d.ts.map +1 -0
  101. package/lib/client/surface/components/ActiveWorktree.js +154 -0
  102. package/lib/client/surface/components/ActiveWorktree.js.map +1 -0
  103. package/lib/client/surface/components/ArchivedWorktree.d.ts +24 -0
  104. package/lib/client/surface/components/ArchivedWorktree.d.ts.map +1 -0
  105. package/lib/client/surface/components/ArchivedWorktree.js +145 -0
  106. package/lib/client/surface/components/ArchivedWorktree.js.map +1 -0
  107. package/lib/client/surface/components/ArchivedWorktrees.d.ts +25 -0
  108. package/lib/client/surface/components/ArchivedWorktrees.d.ts.map +1 -0
  109. package/lib/client/surface/components/ArchivedWorktrees.js +20 -0
  110. package/lib/client/surface/components/ArchivedWorktrees.js.map +1 -0
  111. package/lib/client/surface/components/LifecycleDialogs.d.ts +20 -0
  112. package/lib/client/surface/components/LifecycleDialogs.d.ts.map +1 -0
  113. package/lib/client/surface/components/LifecycleDialogs.js +31 -0
  114. package/lib/client/surface/components/LifecycleDialogs.js.map +1 -0
  115. package/lib/client/surface/components/NativeDialogs.d.ts +9 -0
  116. package/lib/client/surface/components/NativeDialogs.d.ts.map +1 -0
  117. package/lib/client/surface/components/NativeDialogs.js +14 -0
  118. package/lib/client/surface/components/NativeDialogs.js.map +1 -0
  119. package/lib/client/surface/components/NotificationToasts.d.ts +7 -0
  120. package/lib/client/surface/components/NotificationToasts.d.ts.map +1 -0
  121. package/lib/client/surface/components/NotificationToasts.js +24 -0
  122. package/lib/client/surface/components/NotificationToasts.js.map +1 -0
  123. package/lib/client/surface/components/RegistrationDialog.d.ts +15 -0
  124. package/lib/client/surface/components/RegistrationDialog.d.ts.map +1 -0
  125. package/lib/client/surface/components/RegistrationDialog.js +22 -0
  126. package/lib/client/surface/components/RegistrationDialog.js.map +1 -0
  127. package/lib/client/surface/components/SurfaceContent.d.ts +31 -0
  128. package/lib/client/surface/components/SurfaceContent.d.ts.map +1 -0
  129. package/lib/client/surface/components/SurfaceContent.js +65 -0
  130. package/lib/client/surface/components/SurfaceContent.js.map +1 -0
  131. package/lib/client/surface/components/SurfaceHeader.d.ts +15 -0
  132. package/lib/client/surface/components/SurfaceHeader.d.ts.map +1 -0
  133. package/lib/client/surface/components/SurfaceHeader.js +42 -0
  134. package/lib/client/surface/components/SurfaceHeader.js.map +1 -0
  135. package/lib/client/surface/components/WorkspaceTree.d.ts +32 -0
  136. package/lib/client/surface/components/WorkspaceTree.d.ts.map +1 -0
  137. package/lib/client/surface/components/WorkspaceTree.js +145 -0
  138. package/lib/client/surface/components/WorkspaceTree.js.map +1 -0
  139. package/lib/client/{worktree-surface-dialogs.d.ts → surface/components/dialogs.d.ts} +5 -2
  140. package/lib/client/surface/components/dialogs.d.ts.map +1 -0
  141. package/lib/client/{worktree-surface-dialogs.js → surface/components/dialogs.js} +67 -24
  142. package/lib/client/surface/components/dialogs.js.map +1 -0
  143. package/lib/client/{worktree-surface-rows.d.ts → surface/components/rows.d.ts} +3 -3
  144. package/lib/client/surface/components/rows.d.ts.map +1 -0
  145. package/lib/client/{worktree-surface-rows.js → surface/components/rows.js} +79 -17
  146. package/lib/client/surface/components/rows.js.map +1 -0
  147. package/lib/client/surface/notification-queue.d.ts +11 -0
  148. package/lib/client/surface/notification-queue.d.ts.map +1 -0
  149. package/lib/client/surface/notification-queue.js +19 -0
  150. package/lib/client/surface/notification-queue.js.map +1 -0
  151. package/lib/client/{worktree-surface-selectors.d.ts → surface/selectors.d.ts} +10 -5
  152. package/lib/client/surface/selectors.d.ts.map +1 -0
  153. package/lib/client/{worktree-surface-selectors.js → surface/selectors.js} +23 -6
  154. package/lib/client/surface/selectors.js.map +1 -0
  155. package/lib/client/surface/shared.d.ts +40 -0
  156. package/lib/client/surface/shared.d.ts.map +1 -0
  157. package/lib/client/surface/shared.js +53 -0
  158. package/lib/client/surface/shared.js.map +1 -0
  159. package/lib/client/surface/state/useLifecycleState.d.ts +34 -0
  160. package/lib/client/surface/state/useLifecycleState.d.ts.map +1 -0
  161. package/lib/client/surface/state/useLifecycleState.js +39 -0
  162. package/lib/client/surface/state/useLifecycleState.js.map +1 -0
  163. package/lib/client/surface/state/useRegistrationState.d.ts +34 -0
  164. package/lib/client/surface/state/useRegistrationState.d.ts.map +1 -0
  165. package/lib/client/surface/state/useRegistrationState.js +44 -0
  166. package/lib/client/surface/state/useRegistrationState.js.map +1 -0
  167. package/lib/client/surface/state/useSessionExpansion.d.ts +39 -0
  168. package/lib/client/surface/state/useSessionExpansion.d.ts.map +1 -0
  169. package/lib/client/surface/state/useSessionExpansion.js +230 -0
  170. package/lib/client/surface/state/useSessionExpansion.js.map +1 -0
  171. package/lib/client/surface/state/useSessionOrdering.d.ts +15 -0
  172. package/lib/client/surface/state/useSessionOrdering.d.ts.map +1 -0
  173. package/lib/client/surface/state/useSessionOrdering.js +68 -0
  174. package/lib/client/surface/state/useSessionOrdering.js.map +1 -0
  175. package/lib/client/surface/state/useSurfaceMenus.d.ts +9 -0
  176. package/lib/client/surface/state/useSurfaceMenus.d.ts.map +1 -0
  177. package/lib/client/surface/state/useSurfaceMenus.js +15 -0
  178. package/lib/client/surface/state/useSurfaceMenus.js.map +1 -0
  179. package/lib/client/surface/state/useSurfaceRefresh.d.ts +39 -0
  180. package/lib/client/surface/state/useSurfaceRefresh.d.ts.map +1 -0
  181. package/lib/client/surface/state/useSurfaceRefresh.js +274 -0
  182. package/lib/client/surface/state/useSurfaceRefresh.js.map +1 -0
  183. package/lib/client/surface/state/useSurfaceSources.d.ts +31 -0
  184. package/lib/client/surface/state/useSurfaceSources.d.ts.map +1 -0
  185. package/lib/client/surface/state/useSurfaceSources.js +63 -0
  186. package/lib/client/surface/state/useSurfaceSources.js.map +1 -0
  187. package/lib/client/{worktree-surface-types.d.ts → surface/types.d.ts} +50 -13
  188. package/lib/client/surface/types.d.ts.map +1 -0
  189. package/lib/client/surface/types.js +2 -0
  190. package/lib/client/surface/types.js.map +1 -0
  191. package/lib/client/{WorktreeModeAction.d.ts → view/WorktreeModeAction.d.ts} +1 -1
  192. package/lib/client/view/WorktreeModeAction.d.ts.map +1 -0
  193. package/lib/client/{WorktreeModeAction.js → view/WorktreeModeAction.js} +1 -1
  194. package/lib/client/view/WorktreeModeAction.js.map +1 -0
  195. package/lib/client/view/navigation.d.ts.map +1 -0
  196. package/lib/client/view/navigation.js.map +1 -0
  197. package/lib/client/view/view-mode-store.d.ts.map +1 -0
  198. package/lib/client/view/view-mode-store.js.map +1 -0
  199. package/lib/client/view/view-mode.d.ts.map +1 -0
  200. package/lib/client/view/view-mode.js.map +1 -0
  201. package/lib/client/{worktree-error-copy.d.ts → view/worktree-error-copy.d.ts} +2 -2
  202. package/lib/client/view/worktree-error-copy.d.ts.map +1 -0
  203. package/lib/client/view/worktree-error-copy.js.map +1 -0
  204. package/lib/client/{worktree-expand-state.d.ts → view/worktree-expand-state.d.ts} +1 -0
  205. package/lib/client/view/worktree-expand-state.d.ts.map +1 -0
  206. package/lib/client/{worktree-expand-state.js → view/worktree-expand-state.js} +11 -0
  207. package/lib/client/view/worktree-expand-state.js.map +1 -0
  208. package/lib/client/{worktree-view-actions.d.ts → view/worktree-view-actions.d.ts} +11 -5
  209. package/lib/client/view/worktree-view-actions.d.ts.map +1 -0
  210. package/lib/client/{worktree-view-actions.js → view/worktree-view-actions.js} +13 -11
  211. package/lib/client/view/worktree-view-actions.js.map +1 -0
  212. package/lib/client/view/worktree-view-errors.d.ts.map +1 -0
  213. package/lib/client/view/worktree-view-errors.js.map +1 -0
  214. package/lib/client/{worktree-view-read.d.ts → view/worktree-view-read.d.ts} +4 -2
  215. package/lib/client/view/worktree-view-read.d.ts.map +1 -0
  216. package/lib/client/{worktree-view-read.js → view/worktree-view-read.js} +4 -1
  217. package/lib/client/view/worktree-view-read.js.map +1 -0
  218. package/lib/client/view/worktree-view.d.ts.map +1 -0
  219. package/lib/client/view/worktree-view.js.map +1 -0
  220. package/lib/client/worktree-connection.d.ts +5 -0
  221. package/lib/client/worktree-connection.d.ts.map +1 -1
  222. package/lib/client/worktree-connection.js +16 -0
  223. package/lib/client/worktree-connection.js.map +1 -1
  224. package/lib/client.js +4295 -2634
  225. package/lib/client.js.map +1 -1
  226. package/lib/contract/index.contract.js +10 -0
  227. package/lib/contract/index.contract.js.map +1 -1
  228. package/lib/contract/index.d.ts +46 -3
  229. package/lib/contract/index.d.ts.map +1 -1
  230. package/lib/contract/index.js +7 -0
  231. package/lib/contract/index.js.map +1 -1
  232. package/lib/host/dsh-read-adapter.d.ts +10 -1
  233. package/lib/host/dsh-read-adapter.d.ts.map +1 -1
  234. package/lib/host/dsh-read-adapter.js +18 -1
  235. package/lib/host/dsh-read-adapter.js.map +1 -1
  236. package/lib/host/remote.d.ts.map +1 -1
  237. package/lib/host/remote.js +14 -0
  238. package/lib/host/remote.js.map +1 -1
  239. package/lib/host/service.d.ts +24 -0
  240. package/lib/host/service.d.ts.map +1 -1
  241. package/lib/host/service.js +39 -1
  242. package/lib/host/service.js.map +1 -1
  243. package/lib/host/worktree-activity.d.ts +13 -0
  244. package/lib/host/worktree-activity.d.ts.map +1 -0
  245. package/lib/host/worktree-activity.js +23 -0
  246. package/lib/host/worktree-activity.js.map +1 -0
  247. package/lib/host/worktree-permission-manager.js +2 -2
  248. package/lib/host/worktree-permission-manager.js.map +1 -1
  249. package/lib/index.d.ts +3 -3
  250. package/lib/index.d.ts.map +1 -1
  251. package/lib/index.js +2 -2
  252. package/lib/index.js.map +1 -1
  253. package/lib/manage/manager-context.d.ts +2 -1
  254. package/lib/manage/manager-context.d.ts.map +1 -1
  255. package/lib/manage/manager-sessions.js +4 -4
  256. package/lib/manage/manager-sessions.js.map +1 -1
  257. package/lib/manage/manager-worktree-lifecycle.d.ts +23 -0
  258. package/lib/manage/manager-worktree-lifecycle.d.ts.map +1 -0
  259. package/lib/manage/manager-worktree-lifecycle.js +165 -0
  260. package/lib/manage/manager-worktree-lifecycle.js.map +1 -0
  261. package/lib/manage/manager-worktrees.d.ts +1 -6
  262. package/lib/manage/manager-worktrees.d.ts.map +1 -1
  263. package/lib/manage/manager-worktrees.js +78 -112
  264. package/lib/manage/manager-worktrees.js.map +1 -1
  265. package/lib/manage/manager.d.ts +17 -1
  266. package/lib/manage/manager.d.ts.map +1 -1
  267. package/lib/manage/manager.js +23 -6
  268. package/lib/manage/manager.js.map +1 -1
  269. package/lib/provider/generated-name.d.ts +8 -0
  270. package/lib/provider/generated-name.d.ts.map +1 -0
  271. package/lib/provider/generated-name.js +29 -0
  272. package/lib/provider/generated-name.js.map +1 -0
  273. package/lib/provider/{git.d.ts → git/adapter.d.ts} +2 -2
  274. package/lib/provider/git/adapter.d.ts.map +1 -0
  275. package/lib/provider/{git.js → git/adapter.js} +11 -2
  276. package/lib/provider/git/adapter.js.map +1 -0
  277. package/lib/provider/{repository-fingerprint.d.ts → git/repository-fingerprint.d.ts} +1 -1
  278. package/lib/provider/git/repository-fingerprint.d.ts.map +1 -0
  279. package/lib/provider/git/repository-fingerprint.js.map +1 -0
  280. package/lib/provider/{subprocess.d.ts → git/subprocess.d.ts} +1 -1
  281. package/lib/provider/git/subprocess.d.ts.map +1 -0
  282. package/lib/provider/git/subprocess.js.map +1 -0
  283. package/lib/provider/git/worktree-status.d.ts +5 -0
  284. package/lib/provider/git/worktree-status.d.ts.map +1 -0
  285. package/lib/provider/git/worktree-status.js +23 -0
  286. package/lib/provider/git/worktree-status.js.map +1 -0
  287. package/lib/provider/index.d.ts +5 -5
  288. package/lib/provider/index.d.ts.map +1 -1
  289. package/lib/provider/index.js +5 -5
  290. package/lib/provider/index.js.map +1 -1
  291. package/lib/provider/mutation-token.d.ts +1 -1
  292. package/lib/provider/mutation-token.d.ts.map +1 -1
  293. package/lib/provider/mutation-token.js +1 -0
  294. package/lib/provider/mutation-token.js.map +1 -1
  295. package/lib/provider/sidecar/mutation-lock.d.ts.map +1 -0
  296. package/lib/provider/{mutation-lock.js → sidecar/mutation-lock.js} +1 -1
  297. package/lib/provider/sidecar/mutation-lock.js.map +1 -0
  298. package/lib/provider/{sidecar.d.ts → sidecar/repository.d.ts} +3 -3
  299. package/lib/provider/sidecar/repository.d.ts.map +1 -0
  300. package/lib/provider/{sidecar.js → sidecar/repository.js} +12 -5
  301. package/lib/provider/sidecar/repository.js.map +1 -0
  302. package/lib/provider/{sidecar-persistence.d.ts → sidecar/sidecar-persistence.d.ts} +1 -1
  303. package/lib/provider/sidecar/sidecar-persistence.d.ts.map +1 -0
  304. package/lib/provider/{sidecar-persistence.js → sidecar/sidecar-persistence.js} +29 -2
  305. package/lib/provider/sidecar/sidecar-persistence.js.map +1 -0
  306. package/lib/provider/{sidecar-schema.d.ts → sidecar/sidecar-schema.d.ts} +1 -1
  307. package/lib/provider/sidecar/sidecar-schema.d.ts.map +1 -0
  308. package/lib/provider/{sidecar-schema.js → sidecar/sidecar-schema.js} +52 -16
  309. package/lib/provider/sidecar/sidecar-schema.js.map +1 -0
  310. package/lib/provider/transaction/dependencies.d.ts +10 -0
  311. package/lib/provider/transaction/dependencies.d.ts.map +1 -0
  312. package/lib/provider/transaction/dependencies.js +2 -0
  313. package/lib/provider/transaction/dependencies.js.map +1 -0
  314. package/lib/provider/transaction/index.d.ts +17 -0
  315. package/lib/provider/transaction/index.d.ts.map +1 -0
  316. package/lib/provider/transaction/index.js +44 -0
  317. package/lib/provider/transaction/index.js.map +1 -0
  318. package/lib/provider/transaction/operations/adopt-branch.d.ts +6 -0
  319. package/lib/provider/transaction/operations/adopt-branch.d.ts.map +1 -0
  320. package/lib/provider/transaction/operations/adopt-branch.js +59 -0
  321. package/lib/provider/transaction/operations/adopt-branch.js.map +1 -0
  322. package/lib/provider/transaction/operations/clean.d.ts +4 -0
  323. package/lib/provider/transaction/operations/clean.d.ts.map +1 -0
  324. package/lib/provider/transaction/operations/clean.js +168 -0
  325. package/lib/provider/transaction/operations/clean.js.map +1 -0
  326. package/lib/provider/transaction/operations/create.d.ts +5 -0
  327. package/lib/provider/transaction/operations/create.d.ts.map +1 -0
  328. package/lib/provider/transaction/operations/create.js +136 -0
  329. package/lib/provider/transaction/operations/create.js.map +1 -0
  330. package/lib/provider/transaction/operations/import.d.ts +5 -0
  331. package/lib/provider/transaction/operations/import.d.ts.map +1 -0
  332. package/lib/provider/transaction/operations/import.js +92 -0
  333. package/lib/provider/transaction/operations/import.js.map +1 -0
  334. package/lib/provider/transaction/operations/remove.d.ts +4 -0
  335. package/lib/provider/transaction/operations/remove.d.ts.map +1 -0
  336. package/lib/provider/transaction/operations/remove.js +164 -0
  337. package/lib/provider/transaction/operations/remove.js.map +1 -0
  338. package/lib/provider/transaction/recovery/failure-recovery.d.ts +32 -0
  339. package/lib/provider/transaction/recovery/failure-recovery.d.ts.map +1 -0
  340. package/lib/provider/transaction/recovery/failure-recovery.js +147 -0
  341. package/lib/provider/transaction/recovery/failure-recovery.js.map +1 -0
  342. package/lib/provider/transaction/recovery/recover.d.ts +4 -0
  343. package/lib/provider/transaction/recovery/recover.d.ts.map +1 -0
  344. package/lib/provider/transaction/recovery/recover.js +162 -0
  345. package/lib/provider/transaction/recovery/recover.js.map +1 -0
  346. package/lib/provider/transaction/support/admission.d.ts +7 -0
  347. package/lib/provider/transaction/support/admission.d.ts.map +1 -0
  348. package/lib/provider/transaction/support/admission.js +90 -0
  349. package/lib/provider/transaction/support/admission.js.map +1 -0
  350. package/lib/provider/transaction/support/inspection.d.ts +11 -0
  351. package/lib/provider/transaction/support/inspection.d.ts.map +1 -0
  352. package/lib/provider/transaction/support/inspection.js +51 -0
  353. package/lib/provider/transaction/support/inspection.js.map +1 -0
  354. package/lib/provider/transaction/support/journal.d.ts +12 -0
  355. package/lib/provider/transaction/support/journal.d.ts.map +1 -0
  356. package/lib/provider/transaction/support/journal.js +72 -0
  357. package/lib/provider/transaction/support/journal.js.map +1 -0
  358. package/lib/provider/transaction/support/locking.d.ts +4 -0
  359. package/lib/provider/transaction/support/locking.d.ts.map +1 -0
  360. package/lib/provider/transaction/support/locking.js +11 -0
  361. package/lib/provider/transaction/support/locking.js.map +1 -0
  362. package/lib/provider/transaction/support/path-safety.d.ts +11 -0
  363. package/lib/provider/transaction/support/path-safety.d.ts.map +1 -0
  364. package/lib/provider/transaction/support/path-safety.js +82 -0
  365. package/lib/provider/transaction/support/path-safety.js.map +1 -0
  366. package/lib/provider/transaction/support/paths.d.ts +10 -0
  367. package/lib/provider/transaction/support/paths.d.ts.map +1 -0
  368. package/lib/provider/transaction/support/paths.js +68 -0
  369. package/lib/provider/transaction/support/paths.js.map +1 -0
  370. package/lib/provider/transaction/support/publication.d.ts +9 -0
  371. package/lib/provider/transaction/support/publication.d.ts.map +1 -0
  372. package/lib/provider/transaction/support/publication.js +92 -0
  373. package/lib/provider/transaction/support/publication.js.map +1 -0
  374. package/lib/provider/transaction/types.d.ts +38 -0
  375. package/lib/provider/transaction/types.d.ts.map +1 -0
  376. package/lib/provider/transaction/types.js +2 -0
  377. package/lib/provider/transaction/types.js.map +1 -0
  378. package/lib/provider/types.d.ts +22 -3
  379. package/lib/provider/types.d.ts.map +1 -1
  380. package/lib/provider/types.js +1 -1
  381. package/lib/provider/types.js.map +1 -1
  382. package/lib/provider/worktree-lifecycle.d.ts +19 -0
  383. package/lib/provider/worktree-lifecycle.d.ts.map +1 -0
  384. package/lib/provider/worktree-lifecycle.js +44 -0
  385. package/lib/provider/worktree-lifecycle.js.map +1 -0
  386. package/lib/typert.host.js +269 -30
  387. package/lib/typert.remote-client.d.ts +10 -0
  388. package/lib/typert.remote-client.d.ts.map +1 -1
  389. package/lib/typert.remote-client.js +269 -30
  390. package/package.json +1 -1
  391. package/lib/client/WorktreeContext.d.ts.map +0 -1
  392. package/lib/client/WorktreeContext.js.map +0 -1
  393. package/lib/client/WorktreeHeroContext.d.ts.map +0 -1
  394. package/lib/client/WorktreeHeroContext.js.map +0 -1
  395. package/lib/client/WorktreeModeAction.d.ts.map +0 -1
  396. package/lib/client/WorktreeModeAction.js.map +0 -1
  397. package/lib/client/WorktreeOverlay.d.ts.map +0 -1
  398. package/lib/client/WorktreeOverlay.js.map +0 -1
  399. package/lib/client/dsh-rc1-slot-contract.d.ts +0 -43
  400. package/lib/client/dsh-rc1-slot-contract.d.ts.map +0 -1
  401. package/lib/client/dsh-rc1-slot-contract.js +0 -2
  402. package/lib/client/dsh-rc1-slot-contract.js.map +0 -1
  403. package/lib/client/navigation.d.ts.map +0 -1
  404. package/lib/client/navigation.js.map +0 -1
  405. package/lib/client/overlay-bounds.d.ts.map +0 -1
  406. package/lib/client/overlay-bounds.js.map +0 -1
  407. package/lib/client/session-view.d.ts.map +0 -1
  408. package/lib/client/session-view.js.map +0 -1
  409. package/lib/client/sidebar-overlay-geometry.d.ts.map +0 -1
  410. package/lib/client/sidebar-overlay-geometry.js.map +0 -1
  411. package/lib/client/view-mode-store.d.ts.map +0 -1
  412. package/lib/client/view-mode-store.js.map +0 -1
  413. package/lib/client/view-mode.d.ts.map +0 -1
  414. package/lib/client/view-mode.js.map +0 -1
  415. package/lib/client/virtual-workspace-membership.d.ts.map +0 -1
  416. package/lib/client/virtual-workspace-membership.js.map +0 -1
  417. package/lib/client/worktree-context-store.d.ts.map +0 -1
  418. package/lib/client/worktree-context-store.js.map +0 -1
  419. package/lib/client/worktree-context.d.ts.map +0 -1
  420. package/lib/client/worktree-context.js.map +0 -1
  421. package/lib/client/worktree-error-copy.d.ts.map +0 -1
  422. package/lib/client/worktree-error-copy.js.map +0 -1
  423. package/lib/client/worktree-expand-state.d.ts.map +0 -1
  424. package/lib/client/worktree-expand-state.js.map +0 -1
  425. package/lib/client/worktree-permission-icon.d.ts.map +0 -1
  426. package/lib/client/worktree-permission-icon.js.map +0 -1
  427. package/lib/client/worktree-permission.d.ts.map +0 -1
  428. package/lib/client/worktree-permission.js.map +0 -1
  429. package/lib/client/worktree-session-fork.d.ts.map +0 -1
  430. package/lib/client/worktree-session-fork.js.map +0 -1
  431. package/lib/client/worktree-session-order.d.ts.map +0 -1
  432. package/lib/client/worktree-session-order.js.map +0 -1
  433. package/lib/client/worktree-session-position.d.ts.map +0 -1
  434. package/lib/client/worktree-session-position.js.map +0 -1
  435. package/lib/client/worktree-session.d.ts.map +0 -1
  436. package/lib/client/worktree-session.js.map +0 -1
  437. package/lib/client/worktree-surface-dialogs.d.ts.map +0 -1
  438. package/lib/client/worktree-surface-dialogs.js.map +0 -1
  439. package/lib/client/worktree-surface-rows.d.ts.map +0 -1
  440. package/lib/client/worktree-surface-rows.js.map +0 -1
  441. package/lib/client/worktree-surface-selectors.d.ts.map +0 -1
  442. package/lib/client/worktree-surface-selectors.js.map +0 -1
  443. package/lib/client/worktree-surface-types.d.ts.map +0 -1
  444. package/lib/client/worktree-surface-types.js +0 -2
  445. package/lib/client/worktree-surface-types.js.map +0 -1
  446. package/lib/client/worktree-view-actions.d.ts.map +0 -1
  447. package/lib/client/worktree-view-actions.js.map +0 -1
  448. package/lib/client/worktree-view-errors.d.ts.map +0 -1
  449. package/lib/client/worktree-view-errors.js.map +0 -1
  450. package/lib/client/worktree-view-read.d.ts.map +0 -1
  451. package/lib/client/worktree-view-read.js.map +0 -1
  452. package/lib/client/worktree-view.d.ts.map +0 -1
  453. package/lib/client/worktree-view.js.map +0 -1
  454. package/lib/provider/git.d.ts.map +0 -1
  455. package/lib/provider/git.js.map +0 -1
  456. package/lib/provider/mutation-lock.d.ts.map +0 -1
  457. package/lib/provider/mutation-lock.js.map +0 -1
  458. package/lib/provider/repository-fingerprint.d.ts.map +0 -1
  459. package/lib/provider/repository-fingerprint.js.map +0 -1
  460. package/lib/provider/sidecar-persistence.d.ts.map +0 -1
  461. package/lib/provider/sidecar-persistence.js.map +0 -1
  462. package/lib/provider/sidecar-schema.d.ts.map +0 -1
  463. package/lib/provider/sidecar-schema.js.map +0 -1
  464. package/lib/provider/sidecar.d.ts.map +0 -1
  465. package/lib/provider/sidecar.js.map +0 -1
  466. package/lib/provider/subprocess.d.ts.map +0 -1
  467. package/lib/provider/subprocess.js.map +0 -1
  468. package/lib/provider/transaction.d.ts +0 -65
  469. package/lib/provider/transaction.d.ts.map +0 -1
  470. package/lib/provider/transaction.js +0 -1011
  471. package/lib/provider/transaction.js.map +0 -1
  472. /package/lib/client/{WorktreeContext.js → context/WorktreeContext.js} +0 -0
  473. /package/lib/client/{WorktreeHeroContext.js → context/WorktreeHeroContext.js} +0 -0
  474. /package/lib/client/{overlay-bounds.d.ts → overlay/overlay-bounds.d.ts} +0 -0
  475. /package/lib/client/{overlay-bounds.js → overlay/overlay-bounds.js} +0 -0
  476. /package/lib/client/{sidebar-overlay-geometry.d.ts → overlay/sidebar-overlay-geometry.d.ts} +0 -0
  477. /package/lib/client/{sidebar-overlay-geometry.js → overlay/sidebar-overlay-geometry.js} +0 -0
  478. /package/lib/client/{worktree-permission-icon.d.ts → permission/worktree-permission-icon.d.ts} +0 -0
  479. /package/lib/client/{worktree-permission-icon.js → permission/worktree-permission-icon.js} +0 -0
  480. /package/lib/client/{worktree-permission.d.ts → permission/worktree-permission.d.ts} +0 -0
  481. /package/lib/client/{worktree-permission.js → permission/worktree-permission.js} +0 -0
  482. /package/lib/client/{session-view.d.ts → session/session-view.d.ts} +0 -0
  483. /package/lib/client/{session-view.js → session/session-view.js} +0 -0
  484. /package/lib/client/{worktree-session-order.d.ts → session/worktree-session-order.d.ts} +0 -0
  485. /package/lib/client/{worktree-session-order.js → session/worktree-session-order.js} +0 -0
  486. /package/lib/client/{worktree-session-position.d.ts → session/worktree-session-position.d.ts} +0 -0
  487. /package/lib/client/{worktree-session-position.js → session/worktree-session-position.js} +0 -0
  488. /package/lib/client/{navigation.d.ts → view/navigation.d.ts} +0 -0
  489. /package/lib/client/{navigation.js → view/navigation.js} +0 -0
  490. /package/lib/client/{view-mode-store.d.ts → view/view-mode-store.d.ts} +0 -0
  491. /package/lib/client/{view-mode-store.js → view/view-mode-store.js} +0 -0
  492. /package/lib/client/{view-mode.d.ts → view/view-mode.d.ts} +0 -0
  493. /package/lib/client/{view-mode.js → view/view-mode.js} +0 -0
  494. /package/lib/client/{worktree-error-copy.js → view/worktree-error-copy.js} +0 -0
  495. /package/lib/client/{worktree-view-errors.d.ts → view/worktree-view-errors.d.ts} +0 -0
  496. /package/lib/client/{worktree-view-errors.js → view/worktree-view-errors.js} +0 -0
  497. /package/lib/client/{worktree-view.d.ts → view/worktree-view.d.ts} +0 -0
  498. /package/lib/client/{worktree-view.js → view/worktree-view.js} +0 -0
  499. /package/lib/provider/{repository-fingerprint.js → git/repository-fingerprint.js} +0 -0
  500. /package/lib/provider/{subprocess.js → git/subprocess.js} +0 -0
  501. /package/lib/provider/{mutation-lock.d.ts → sidecar/mutation-lock.d.ts} +0 -0
@@ -0,0 +1,168 @@
1
+ import path from 'node:path';
2
+ import { createRepositoryFingerprint } from '../../git/repository-fingerprint.js';
3
+ import { completeWorktreeCleanup } from '../../worktree-lifecycle.js';
4
+ import { pathExists, pathEntryMissing, samePhysicalPath } from '../support/paths.js';
5
+ import { recoveryError, pendingClean } from '../support/journal.js';
6
+ import { reconcileCleanFailure } from '../recovery/failure-recovery.js';
7
+ import { withShardLock } from '../support/locking.js';
8
+ import { resolveRepository, findExactWorktree, findWorktreeByPhysicalPath } from '../support/inspection.js';
9
+ import { cleanLegacyObservations, assertMutationAdmitted, assertMutationToken, assertRepositoryCompatible, } from '../support/admission.js';
10
+ import { assertSafeRemovalPath } from '../support/path-safety.js';
11
+ import { publishCleaned, markRecovery } from '../support/publication.js';
12
+ import { providerError } from '../../types.js';
13
+ export async function cleanWorktreeTransaction(dependencies, input) {
14
+ return withShardLock(dependencies, input.workspaceId, async (locked) => {
15
+ await dependencies.git.validateRepository(input.workspaceRoot);
16
+ const repository = await resolveRepository(dependencies, input.workspaceRoot);
17
+ return dependencies.repositoryLock.run(`repository:${createRepositoryFingerprint(repository.identity)}`, async (lock) => {
18
+ lock.assertHeld();
19
+ const gitRoot = repository.identity.topLevel;
20
+ await cleanLegacyObservations(locked);
21
+ const current = await locked.read();
22
+ assertMutationAdmitted(current, input.workspaceId);
23
+ assertRepositoryCompatible(current, repository.identity, input.workspaceId);
24
+ const record = current.worktrees.find((candidate) => candidate.worktreeId === input.worktreeId);
25
+ if (!record) {
26
+ throw providerError('WORKTREE_NOT_FOUND', `Worktree not found: ${input.worktreeId}`, {
27
+ workspaceId: input.workspaceId,
28
+ worktreeId: input.worktreeId,
29
+ });
30
+ }
31
+ if (record.status === 'active') {
32
+ throw providerError('WORKTREE_STATE_CONFLICT', 'Worktree must be archived before cleaning disk', {
33
+ workspaceId: input.workspaceId,
34
+ worktreeId: input.worktreeId,
35
+ });
36
+ }
37
+ assertMutationToken(current, record, input.mutationToken);
38
+ if (record.diskCleanup === 'completed') {
39
+ return;
40
+ }
41
+ if (await samePhysicalPath(record.absolutePath, gitRoot)) {
42
+ throw providerError('WORKTREE_STATE_CONFLICT', 'The main Worktree cannot be cleaned', {
43
+ workspaceId: input.workspaceId,
44
+ worktreeId: input.worktreeId,
45
+ targetPath: record.absolutePath,
46
+ });
47
+ }
48
+ const liveBefore = await dependencies.git.listWorktrees(gitRoot);
49
+ const exactBefore = await findExactWorktree(liveBefore, record.absolutePath, record.branch);
50
+ await assertSafeRemovalPath(dependencies, record, input.workspaceRoot);
51
+ if (await pathEntryMissing(path.join(record.absolutePath, '.git'))) {
52
+ const pathRegistration = await findWorktreeByPhysicalPath(liveBefore, record.absolutePath);
53
+ if (pathRegistration && !exactBefore) {
54
+ throw providerError('WORKTREE_IDENTITY_CHANGED', 'Missing Worktree path has a different Git registration', {
55
+ workspaceId: input.workspaceId,
56
+ worktreeId: input.worktreeId,
57
+ targetPath: record.absolutePath,
58
+ });
59
+ }
60
+ // An absent directory or .git entry is already removed as a Worktree.
61
+ // Preserve residual files and registration; only reconcile the sidecar.
62
+ lock.assertHeld();
63
+ await locked.mutate((snapshot) => {
64
+ const { repository: _repository, ...stableFields } = snapshot;
65
+ void _repository;
66
+ return {
67
+ result: undefined,
68
+ snapshot: completeWorktreeCleanup({
69
+ ...stableFields,
70
+ repositoryFingerprint: createRepositoryFingerprint(repository.identity),
71
+ }, record.worktreeId),
72
+ };
73
+ });
74
+ return;
75
+ }
76
+ if (!exactBefore) {
77
+ throw providerError('WORKTREE_IDENTITY_CHANGED', `Worktree is not registered in Git: ${record.absolutePath}`, {
78
+ workspaceId: input.workspaceId,
79
+ worktreeId: input.worktreeId,
80
+ targetPath: record.absolutePath,
81
+ });
82
+ }
83
+ const pending = pendingClean(input, record, repository.identity);
84
+ await locked.mutate((snapshot) => {
85
+ const { repository: _repository, ...withoutRepository } = snapshot;
86
+ void _repository;
87
+ return {
88
+ result: undefined,
89
+ snapshot: {
90
+ ...withoutRepository,
91
+ repositoryFingerprint: createRepositoryFingerprint(repository.identity),
92
+ pendingOperation: pending,
93
+ },
94
+ };
95
+ });
96
+ try {
97
+ await dependencies.git.removeWorktree(input.workspaceRoot, record.absolutePath);
98
+ }
99
+ catch (error) {
100
+ return reconcileCleanFailure(dependencies, {
101
+ locked,
102
+ input,
103
+ record,
104
+ pending,
105
+ repository: repository.identity,
106
+ gitRoot,
107
+ error,
108
+ });
109
+ }
110
+ lock.assertHeld();
111
+ let liveAfter;
112
+ try {
113
+ liveAfter = await dependencies.git.listWorktrees(gitRoot);
114
+ }
115
+ catch (inspectionError) {
116
+ await markRecovery(locked, pending, 'WORKTREE_RECOVERY_REQUIRED');
117
+ throw recoveryError(`Unable to verify Git after clean: ${record.absolutePath}`, {
118
+ workspaceId: input.workspaceId,
119
+ operationId: pending.id,
120
+ targetPath: record.absolutePath,
121
+ cause: String(inspectionError),
122
+ });
123
+ }
124
+ if (await findExactWorktree(liveAfter, record.absolutePath, record.branch)) {
125
+ await markRecovery(locked, pending, 'WORKTREE_RECOVERY_REQUIRED');
126
+ throw recoveryError(`Git remove did not remove the registered Worktree: ${record.absolutePath}`, {
127
+ workspaceId: input.workspaceId,
128
+ worktreeId: input.worktreeId,
129
+ targetPath: record.absolutePath,
130
+ });
131
+ }
132
+ let targetExists;
133
+ try {
134
+ targetExists = await pathExists(record.absolutePath);
135
+ }
136
+ catch (inspectionError) {
137
+ await markRecovery(locked, pending, 'WORKTREE_RECOVERY_REQUIRED');
138
+ throw recoveryError(`Unable to verify the cleaned Worktree path: ${record.absolutePath}`, {
139
+ workspaceId: input.workspaceId,
140
+ operationId: pending.id,
141
+ targetPath: record.absolutePath,
142
+ cause: String(inspectionError),
143
+ });
144
+ }
145
+ if (targetExists) {
146
+ await markRecovery(locked, pending, 'WORKTREE_IDENTITY_CHANGED');
147
+ throw providerError('WORKTREE_IDENTITY_CHANGED', `Worktree path remains after Git removal: ${record.absolutePath}`, {
148
+ workspaceId: input.workspaceId,
149
+ worktreeId: input.worktreeId,
150
+ targetPath: record.absolutePath,
151
+ });
152
+ }
153
+ try {
154
+ await publishCleaned(locked, pending.id, input.worktreeId, repository.identity);
155
+ }
156
+ catch (error) {
157
+ const sidecarError = error instanceof Error ? error : new Error(String(error));
158
+ throw providerError('SIDECAR_SYNC_REQUIRED', `Git removed Worktree ${input.worktreeId}, but sidecar synchronization failed`, {
159
+ workspaceId: input.workspaceId,
160
+ worktreeId: input.worktreeId,
161
+ workspaceRoot: input.workspaceRoot,
162
+ sidecarError: sidecarError.message,
163
+ });
164
+ }
165
+ });
166
+ });
167
+ }
168
+ //# sourceMappingURL=clean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clean.js","sourceRoot":"","sources":["../../../../src/provider/transaction/operations/clean.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAElF,OAAO,EAAE,uBA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AM,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,2BAA2B,CAAC,CAAC;gBACjE,MAAM,aAAa,CACjB,2BAA2B,EAC3B,4CAA4C,MAAM,CAAC,YAAY,EAAE,EACjE;oBACE,WAAW,EAAE,KAAK,CAAC,WAAW;oBAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,UAAU,EAAE,MAAM,CAAC,YAAY;iBAChC,CACF,CAAC;YACJ,CAAC;YACD,IAAI,CAAC;gBACH,MAAM,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;YAClF,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC/E,MAAM,aAAa,CACjB,uBAAuB,EACvB,wBAAwB,KAAK,CAAC,UAAU,sCAAsC,EAC9E;oBACE,WAAW,EAAE,KAAK,CAAC,WAAW;oBAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,aAAa,EAAE,KAAK,CAAC,aAAa;oBAClC,YAAY,EAAE,YAAY,CAAC,OAAO;iBACnC,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { WorktreeRecord } from '../../../contract/index.js';
2
+ import type { CreateWorktreeTransactionInput } from '../types.js';
3
+ import type { TransactionDependencies } from '../dependencies.js';
4
+ export declare function createWorktreeTransaction(dependencies: Pick<TransactionDependencies, 'dshHome' | 'git' | 'repositoryLock' | 'sidecar'>, input: CreateWorktreeTransactionInput): Promise<WorktreeRecord>;
5
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/provider/transaction/operations/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGjE,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAiBlE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAGlE,wBAAsB,yBAAyB,CAC7C,YAAY,EAAE,IAAI,CAAC,uBAAuB,EAAE,SAAS,GAAG,KAAK,GAAG,gBAAgB,GAAG,SAAS,CAAC,EAC7F,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,cAAc,CAAC,CAoLzB"}
@@ -0,0 +1,136 @@
1
+ import { createRepositoryFingerprint } from '../../git/repository-fingerprint.js';
2
+ import { assertGeneratedNameAvailable } from '../../generated-name.js';
3
+ import { recoveryError, recordForCreate, pendingCreate } from '../support/journal.js';
4
+ import { reconcileCreateFailure } from '../recovery/failure-recovery.js';
5
+ import { withShardLock } from '../support/locking.js';
6
+ import { resolveRepository, findActiveBranchConflict, isExactCreatedWorktree, } from '../support/inspection.js';
7
+ import { cleanLegacyObservations, assertMutationAdmitted, assertRepositoryCompatible, } from '../support/admission.js';
8
+ import { assertGeneratedTarget } from '../support/path-safety.js';
9
+ import { publishCreated, markRecovery } from '../support/publication.js';
10
+ import { providerError } from '../../types.js';
11
+ export async function createWorktreeTransaction(dependencies, input) {
12
+ return withShardLock(dependencies, input.workspaceId, async (locked) => {
13
+ await dependencies.git.validateRepository(input.workspaceRoot);
14
+ const repository = await resolveRepository(dependencies, input.workspaceRoot);
15
+ return dependencies.repositoryLock.run(`repository:${createRepositoryFingerprint(repository.identity)}`, async (lock) => {
16
+ lock.assertHeld();
17
+ const gitRoot = repository.identity.topLevel;
18
+ await cleanLegacyObservations(locked);
19
+ const current = await locked.read();
20
+ assertMutationAdmitted(current, input.workspaceId);
21
+ assertRepositoryCompatible(current, repository.identity, input.workspaceId);
22
+ assertGeneratedTarget(dependencies, input);
23
+ let existingGitWorktrees;
24
+ if (dependencies.git.listBranchesWithWorktreePaths) {
25
+ const branches = await dependencies.git.listBranchesWithWorktreePaths(gitRoot);
26
+ const baseBranch = branches.find((branch) => branch.name === input.baseBranch);
27
+ if (!baseBranch) {
28
+ throw providerError('GIT_OPERATION_FAILED', `Local branch does not exist: ${input.baseBranch}`, {
29
+ workspaceRoot: input.workspaceRoot,
30
+ branch: input.baseBranch,
31
+ });
32
+ }
33
+ if (input.newBranch !== undefined &&
34
+ branches.some((branch) => branch.name === input.newBranch)) {
35
+ throw providerError('WORKTREE_BRANCH_CONFLICT', `New branch already exists: ${input.newBranch}`, {
36
+ workspaceRoot: input.workspaceRoot,
37
+ branch: input.newBranch,
38
+ baseBranch: input.baseBranch,
39
+ });
40
+ }
41
+ if (branches.some((branch) => branch.name === input.targetBranch && branch.worktreePath !== undefined)) {
42
+ throw providerError('WORKTREE_BRANCH_CONFLICT', `Branch is already checked out: ${input.targetBranch}`, {
43
+ workspaceRoot: input.workspaceRoot,
44
+ branch: input.targetBranch,
45
+ baseBranch: input.baseBranch,
46
+ });
47
+ }
48
+ }
49
+ else {
50
+ const branches = await dependencies.git.listBranches(gitRoot);
51
+ if (!branches.includes(input.baseBranch)) {
52
+ throw providerError('GIT_OPERATION_FAILED', `Local branch does not exist: ${input.baseBranch}`, {
53
+ workspaceRoot: input.workspaceRoot,
54
+ branch: input.baseBranch,
55
+ });
56
+ }
57
+ if (input.newBranch !== undefined && branches.includes(input.newBranch)) {
58
+ throw providerError('WORKTREE_BRANCH_CONFLICT', `New branch already exists: ${input.newBranch}`, {
59
+ workspaceRoot: input.workspaceRoot,
60
+ branch: input.newBranch,
61
+ baseBranch: input.baseBranch,
62
+ });
63
+ }
64
+ existingGitWorktrees = await dependencies.git.listWorktrees(gitRoot);
65
+ if (existingGitWorktrees.some((worktree) => worktree.branch === input.targetBranch)) {
66
+ throw providerError('WORKTREE_BRANCH_CONFLICT', `Branch is already checked out: ${input.targetBranch}`, {
67
+ workspaceRoot: input.workspaceRoot,
68
+ branch: input.targetBranch,
69
+ baseBranch: input.baseBranch,
70
+ });
71
+ }
72
+ }
73
+ await assertGeneratedNameAvailable(input.worktreeId, input.targetPath, current, existingGitWorktrees ?? await dependencies.git.listWorktrees(gitRoot));
74
+ const sidecarConflict = await findActiveBranchConflict(dependencies, current, input.targetBranch, gitRoot);
75
+ if (sidecarConflict) {
76
+ throw providerError('WORKTREE_BRANCH_CONFLICT', `Branch is already recorded as active: ${input.targetBranch}`, {
77
+ branch: input.targetBranch,
78
+ worktreeId: sidecarConflict.worktreeId,
79
+ });
80
+ }
81
+ const record = recordForCreate(input);
82
+ const pending = pendingCreate(input, repository.identity);
83
+ await locked.mutate((snapshot) => {
84
+ const { repository: _repository, ...withoutRepository } = snapshot;
85
+ void _repository;
86
+ return {
87
+ result: undefined,
88
+ snapshot: {
89
+ ...withoutRepository,
90
+ repositoryFingerprint: createRepositoryFingerprint(repository.identity),
91
+ pendingOperation: pending,
92
+ },
93
+ };
94
+ });
95
+ try {
96
+ await dependencies.git.createWorktree(input.workspaceRoot, input.targetPath, input.baseBranch, input.newBranch);
97
+ }
98
+ catch (error) {
99
+ return reconcileCreateFailure(dependencies, {
100
+ locked,
101
+ input,
102
+ record,
103
+ pending,
104
+ repository: repository.identity,
105
+ gitRoot,
106
+ error,
107
+ });
108
+ }
109
+ lock.assertHeld();
110
+ let live;
111
+ try {
112
+ live = await dependencies.git.listWorktrees(gitRoot);
113
+ }
114
+ catch (inspectionError) {
115
+ await markRecovery(locked, pending, 'WORKTREE_RECOVERY_REQUIRED');
116
+ throw recoveryError(`Unable to verify Git after create: ${input.targetPath}`, {
117
+ workspaceId: input.workspaceId,
118
+ operationId: pending.id,
119
+ targetPath: input.targetPath,
120
+ cause: String(inspectionError),
121
+ });
122
+ }
123
+ if (!(await isExactCreatedWorktree(live, input))) {
124
+ await markRecovery(locked, pending, 'WORKTREE_RECOVERY_REQUIRED');
125
+ throw recoveryError(`Git create completed without the expected Worktree: ${input.targetPath}`, {
126
+ workspaceId: input.workspaceId,
127
+ worktreeId: input.worktreeId,
128
+ targetPath: input.targetPath,
129
+ });
130
+ }
131
+ await publishCreated(dependencies, locked, pending.id, record, repository.identity);
132
+ return record;
133
+ });
134
+ });
135
+ }
136
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../src/provider/transaction/operations/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAGlF,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,YAA6F,EAC7F,KAAqC;IAErC,OAAO,aAAa,CAAC,YAAY,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QACrE,MAAM,YAAY,CAAC,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC/D,MAAM,UAAU,GAAG,MAAM,iBAAiB,CAAC,YAAY,EAAE,KAAK,CAAC,aAAa,CAAC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D,IAAI,CAAC,CAAC,MAAM,sBAAsB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;gBACjD,MAAM,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,4BAA4B,CAAC,CAAC;gBAClE,MAAM,aAAa,CACjB,uDAAuD,KAAK,CAAC,UAAU,EAAE,EACzE;oBACE,WAAW,EAAE,KAAK,CAAC,WAAW;oBAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,UAAU,EAAE,KAAK,CAAC,UAAU;iBAC7B,CACF,CAAC;YACJ,CAAC;YACD,MAAM,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;YACpF,OAAO,MAAM,CAAC;QAChB,CAAC,CACF,CAAC;IACJ,CAAC,CAA4B,CAAC;AAChC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { WorktreeRecord } from '../../../contract/index.js';
2
+ import type { ImportWorktreeTransactionInput } from '../types.js';
3
+ import type { TransactionDependencies } from '../dependencies.js';
4
+ export declare function importWorktreeTransaction(dependencies: Pick<TransactionDependencies, 'git' | 'repositoryLock' | 'sidecar'>, input: ImportWorktreeTransactionInput): Promise<WorktreeRecord>;
5
+ //# sourceMappingURL=import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../../../src/provider/transaction/operations/import.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEjE,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAalE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAGlE,wBAAsB,yBAAyB,CAC7C,YAAY,EAAE,IAAI,CAAC,uBAAuB,EAAE,KAAK,GAAG,gBAAgB,GAAG,SAAS,CAAC,EACjF,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,cAAc,CAAC,CAoHzB"}
@@ -0,0 +1,92 @@
1
+ import path from 'node:path';
2
+ import { readWorktreeStatus } from '../../git/worktree-status.js';
3
+ import { createRepositoryFingerprint } from '../../git/repository-fingerprint.js';
4
+ import { isDirectory, canonicalPath, samePhysicalPath } from '../support/paths.js';
5
+ import { withShardLock } from '../support/locking.js';
6
+ import { resolveRepository, findWorktreeByPhysicalPath, findSidecarWorktreeByPhysicalPath, } from '../support/inspection.js';
7
+ import { cleanLegacyObservations, assertMutationAdmitted, assertRepositoryCompatible, } from '../support/admission.js';
8
+ import { providerError } from '../../types.js';
9
+ export async function importWorktreeTransaction(dependencies, input) {
10
+ if (!path.isAbsolute(input.absolutePath)) {
11
+ throw providerError('WORKTREE_IMPORT_INVALID', 'An absolute Worktree path is required', {
12
+ workspaceId: input.workspaceId,
13
+ absolutePath: input.absolutePath,
14
+ });
15
+ }
16
+ const requestedPath = path.resolve(input.absolutePath);
17
+ if (!(await isDirectory(requestedPath))) {
18
+ throw providerError('WORKTREE_IMPORT_INVALID', `Worktree path is not a directory: ${requestedPath}`, {
19
+ workspaceId: input.workspaceId,
20
+ absolutePath: requestedPath,
21
+ });
22
+ }
23
+ return withShardLock(dependencies, input.workspaceId, async (locked) => {
24
+ await dependencies.git.validateRepository(input.workspaceRoot);
25
+ const repository = await resolveRepository(dependencies, input.workspaceRoot);
26
+ return dependencies.repositoryLock.run(`repository:${createRepositoryFingerprint(repository.identity)}`, async (lock) => {
27
+ lock.assertHeld();
28
+ const gitRoot = repository.identity.topLevel;
29
+ await cleanLegacyObservations(locked);
30
+ const current = await locked.read();
31
+ assertMutationAdmitted(current, input.workspaceId);
32
+ assertRepositoryCompatible(current, repository.identity, input.workspaceId);
33
+ return locked.mutate(async (snapshot) => {
34
+ const repositoryFingerprint = createRepositoryFingerprint(repository.identity);
35
+ const liveWorktree = await findWorktreeByPhysicalPath(await dependencies.git.listWorktrees(gitRoot), requestedPath);
36
+ if (!liveWorktree ||
37
+ !liveWorktree.branch ||
38
+ (await readWorktreeStatus(liveWorktree)) !== 'ready' ||
39
+ (await samePhysicalPath(liveWorktree.absolutePath, gitRoot))) {
40
+ throw providerError('WORKTREE_IMPORT_INVALID', `Path is not an importable Worktree: ${requestedPath}`, {
41
+ workspaceId: input.workspaceId,
42
+ absolutePath: requestedPath,
43
+ });
44
+ }
45
+ const normalizedPath = await canonicalPath(liveWorktree.absolutePath);
46
+ const existing = await findSidecarWorktreeByPhysicalPath(snapshot.worktrees, normalizedPath);
47
+ if (existing) {
48
+ if (existing.status === 'active' &&
49
+ existing.source === 'external' &&
50
+ existing.workspaceId === input.workspaceId) {
51
+ return {
52
+ result: existing,
53
+ snapshot: snapshot.repositoryFingerprint === repositoryFingerprint
54
+ ? snapshot
55
+ : { ...snapshot, repositoryFingerprint },
56
+ changed: snapshot.repositoryFingerprint === repositoryFingerprint ? false : undefined,
57
+ };
58
+ }
59
+ throw providerError('WORKTREE_ALREADY_MANAGED', `Worktree path is already managed: ${normalizedPath}`, {
60
+ workspaceId: input.workspaceId,
61
+ absolutePath: normalizedPath,
62
+ worktreeId: existing.worktreeId,
63
+ source: existing.source,
64
+ status: existing.status,
65
+ });
66
+ }
67
+ if (snapshot.worktrees.some((candidate) => candidate.worktreeId === input.worktreeId)) {
68
+ throw providerError('SIDECAR_CORRUPT', `Generated Worktree ID is already recorded: ${input.worktreeId}`, {
69
+ worktreeId: input.worktreeId,
70
+ });
71
+ }
72
+ const record = {
73
+ worktreeId: input.worktreeId,
74
+ workspaceId: input.workspaceId,
75
+ absolutePath: normalizedPath,
76
+ branch: liveWorktree.branch,
77
+ source: 'external',
78
+ status: 'active',
79
+ };
80
+ return {
81
+ result: record,
82
+ snapshot: {
83
+ ...snapshot,
84
+ repositoryFingerprint,
85
+ worktrees: [record, ...snapshot.worktrees],
86
+ },
87
+ };
88
+ });
89
+ });
90
+ });
91
+ }
92
+ //# sourceMappingURL=import.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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,KAAK,CAAC,UAAU;qBAC7B,CACF,CAAC;gBACJ,CAAC;gBACD,MAAM,MAAM,GAAmB;oBAC7B,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,WAAW,EAAE,KAAK,CAAC,WAAW;oBAC9B,YAAY,EAAE,cAAc;oBAC5B,MAAM,EAAE,YAAY,CAAC,MAAM;oBAC3B,MAAM,EAAE,UAAU;oBAClB,MAAM,EAAE,QAAQ;iBACjB,CAAC;gBACF,OAAO;oBACL,MAAM,EAAE,MAAM;oBACd,QAAQ,EAAE;wBACR,GAAG,QAAQ;wBACX,qBAAqB;wBACrB,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,QAAQ,CAAC,SAAS,CAAC;qBAC3C;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC,CAA4B,CAAC;AAChC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { RemoveWorktreeTransactionInput } from '../types.js';
2
+ import type { TransactionDependencies } from '../dependencies.js';
3
+ export declare function removeWorktreeTransaction(dependencies: Pick<TransactionDependencies, 'dshHome' | 'git' | 'repositoryLock' | 'sidecar'>, input: RemoveWorktreeTransactionInput): Promise<void>;
4
+ //# sourceMappingURL=remove.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../../../../src/provider/transaction/operations/remove.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAclE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAGlE,wBAAsB,yBAAyB,CAC7C,YAAY,EAAE,IAAI,CAAC,uBAAuB,EAAE,SAAS,GAAG,KAAK,GAAG,gBAAgB,GAAG,SAAS,CAAC,EAC7F,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,IAAI,CAAC,CAyLf"}
@@ -0,0 +1,164 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { createRepositoryFingerprint } from '../../git/repository-fingerprint.js';
3
+ import { pathExists, samePhysicalPath } from '../support/paths.js';
4
+ import { recoveryError, pendingRemove } from '../support/journal.js';
5
+ import { reconcileRemoveFailure } from '../recovery/failure-recovery.js';
6
+ import { withShardLock } from '../support/locking.js';
7
+ import { resolveRepository, findExactWorktree, findWorktreeByPhysicalPath } from '../support/inspection.js';
8
+ import { cleanLegacyObservations, assertMutationAdmitted, assertMutationToken, assertRepositoryCompatible, } from '../support/admission.js';
9
+ import { assertSafeRemovalPath } from '../support/path-safety.js';
10
+ import { publishRemoved, markRecovery } from '../support/publication.js';
11
+ import { providerError } from '../../types.js';
12
+ export async function removeWorktreeTransaction(dependencies, input) {
13
+ return withShardLock(dependencies, input.workspaceId, async (locked) => {
14
+ await dependencies.git.validateRepository(input.workspaceRoot);
15
+ const repository = await resolveRepository(dependencies, input.workspaceRoot);
16
+ return dependencies.repositoryLock.run(`repository:${createRepositoryFingerprint(repository.identity)}`, async (lock) => {
17
+ lock.assertHeld();
18
+ const gitRoot = repository.identity.topLevel;
19
+ await cleanLegacyObservations(locked);
20
+ const current = await locked.read();
21
+ assertMutationAdmitted(current, input.workspaceId);
22
+ assertRepositoryCompatible(current, repository.identity, input.workspaceId);
23
+ const record = current.worktrees.find((candidate) => candidate.worktreeId === input.worktreeId);
24
+ if (!record) {
25
+ throw providerError('WORKTREE_NOT_FOUND', `Worktree not found: ${input.worktreeId}`, {
26
+ workspaceId: input.workspaceId,
27
+ worktreeId: input.worktreeId,
28
+ });
29
+ }
30
+ if (record.status === 'removed') {
31
+ throw providerError('WORKTREE_REMOVED', `Worktree has already been removed: ${input.worktreeId}`, {
32
+ workspaceId: input.workspaceId,
33
+ worktreeId: input.worktreeId,
34
+ });
35
+ }
36
+ assertMutationToken(current, record, input.mutationToken);
37
+ if (await samePhysicalPath(record.absolutePath, gitRoot)) {
38
+ throw providerError('WORKTREE_STATE_CONFLICT', 'The main Worktree cannot be removed', {
39
+ workspaceId: input.workspaceId,
40
+ worktreeId: input.worktreeId,
41
+ targetPath: record.absolutePath,
42
+ });
43
+ }
44
+ const liveBefore = await dependencies.git.listWorktrees(gitRoot);
45
+ const exactBefore = await findExactWorktree(liveBefore, record.absolutePath, record.branch);
46
+ if (!exactBefore) {
47
+ const pathRegistration = await findWorktreeByPhysicalPath(liveBefore, record.absolutePath);
48
+ const branchRegistration = liveBefore.find((worktree) => worktree.branch === record.branch);
49
+ if (!pathRegistration &&
50
+ !branchRegistration &&
51
+ !(await pathExists(record.absolutePath))) {
52
+ // A legacy caller may have completed Git removal before the v3
53
+ // journal was introduced. With no path or matching registration
54
+ // left to delete, finalizing the relation is safe and idempotent.
55
+ const pending = pendingRemove(input, record, repository.identity);
56
+ await locked.mutate((snapshot) => {
57
+ const { repository: _repository, ...withoutRepository } = snapshot;
58
+ void _repository;
59
+ return {
60
+ result: undefined,
61
+ snapshot: {
62
+ ...withoutRepository,
63
+ repositoryFingerprint: createRepositoryFingerprint(repository.identity),
64
+ pendingOperation: pending,
65
+ },
66
+ };
67
+ });
68
+ await publishRemoved(locked, pending.id, input.worktreeId, repository.identity);
69
+ return;
70
+ }
71
+ await markRecovery(locked, {
72
+ id: randomUUID(),
73
+ type: 'remove-worktree',
74
+ phase: 'recovery-needed',
75
+ workspaceId: input.workspaceId,
76
+ worktreeId: input.worktreeId,
77
+ targetPath: record.absolutePath,
78
+ branch: record.branch,
79
+ source: record.source,
80
+ repositoryFingerprint: createRepositoryFingerprint(repository.identity),
81
+ startedAt: new Date().toISOString(),
82
+ }, 'WORKTREE_IDENTITY_CHANGED');
83
+ throw providerError('WORKTREE_IDENTITY_CHANGED', `Worktree identity changed: ${record.absolutePath}`, {
84
+ workspaceId: input.workspaceId,
85
+ worktreeId: input.worktreeId,
86
+ targetPath: record.absolutePath,
87
+ });
88
+ }
89
+ await assertSafeRemovalPath(dependencies, record, input.workspaceRoot);
90
+ const pending = pendingRemove(input, record, repository.identity);
91
+ await locked.mutate((snapshot) => {
92
+ const { repository: _repository, ...withoutRepository } = snapshot;
93
+ void _repository;
94
+ return {
95
+ result: undefined,
96
+ snapshot: {
97
+ ...withoutRepository,
98
+ repositoryFingerprint: createRepositoryFingerprint(repository.identity),
99
+ pendingOperation: pending,
100
+ },
101
+ };
102
+ });
103
+ try {
104
+ await dependencies.git.removeWorktree(input.workspaceRoot, record.absolutePath);
105
+ }
106
+ catch (error) {
107
+ return reconcileRemoveFailure(dependencies, {
108
+ locked,
109
+ input,
110
+ record,
111
+ pending,
112
+ repository: repository.identity,
113
+ gitRoot,
114
+ error,
115
+ });
116
+ }
117
+ lock.assertHeld();
118
+ let liveAfter;
119
+ try {
120
+ liveAfter = await dependencies.git.listWorktrees(gitRoot);
121
+ }
122
+ catch (inspectionError) {
123
+ await markRecovery(locked, pending, 'WORKTREE_RECOVERY_REQUIRED');
124
+ throw recoveryError(`Unable to verify Git after remove: ${record.absolutePath}`, {
125
+ workspaceId: input.workspaceId,
126
+ operationId: pending.id,
127
+ targetPath: record.absolutePath,
128
+ cause: String(inspectionError),
129
+ });
130
+ }
131
+ if (await findExactWorktree(liveAfter, record.absolutePath, record.branch)) {
132
+ await markRecovery(locked, pending, 'WORKTREE_RECOVERY_REQUIRED');
133
+ throw recoveryError(`Git remove did not remove the registered Worktree: ${record.absolutePath}`, {
134
+ workspaceId: input.workspaceId,
135
+ worktreeId: input.worktreeId,
136
+ targetPath: record.absolutePath,
137
+ });
138
+ }
139
+ let targetExists;
140
+ try {
141
+ targetExists = await pathExists(record.absolutePath);
142
+ }
143
+ catch (inspectionError) {
144
+ await markRecovery(locked, pending, 'WORKTREE_RECOVERY_REQUIRED');
145
+ throw recoveryError(`Unable to verify the removed Worktree path: ${record.absolutePath}`, {
146
+ workspaceId: input.workspaceId,
147
+ operationId: pending.id,
148
+ targetPath: record.absolutePath,
149
+ cause: String(inspectionError),
150
+ });
151
+ }
152
+ if (targetExists) {
153
+ await markRecovery(locked, pending, 'WORKTREE_IDENTITY_CHANGED');
154
+ throw providerError('WORKTREE_IDENTITY_CHANGED', `Worktree path remains after Git removal: ${record.absolutePath}`, {
155
+ workspaceId: input.workspaceId,
156
+ worktreeId: input.worktreeId,
157
+ targetPath: record.absolutePath,
158
+ });
159
+ }
160
+ await publishRemoved(locked, pending.id, input.worktreeId, repository.identity);
161
+ });
162
+ });
163
+ }
164
+ //# sourceMappingURL=remove.js.map