@agimon-ai/doompi-git 0.0.1-alpha.4 → 0.0.1-alpha.6

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 (237) hide show
  1. package/README.md +2 -0
  2. package/dist/api-contracts.cjs +1 -0
  3. package/dist/api-contracts.d.cts +2 -0
  4. package/dist/api-contracts.d.mts +2 -0
  5. package/dist/api-contracts.mjs +1 -0
  6. package/dist/constants/git.cjs +2 -0
  7. package/dist/constants/git.cjs.map +1 -0
  8. package/dist/constants/git.mjs +2 -0
  9. package/dist/constants/git.mjs.map +1 -0
  10. package/dist/controllers/gitCommand.cjs +2 -0
  11. package/dist/controllers/gitCommand.cjs.map +1 -0
  12. package/dist/controllers/gitCommand.mjs +2 -0
  13. package/dist/controllers/gitCommand.mjs.map +1 -0
  14. package/dist/controllers/gitSession.cjs +2 -0
  15. package/dist/controllers/gitSession.cjs.map +1 -0
  16. package/dist/controllers/gitSession.mjs +2 -0
  17. package/dist/controllers/gitSession.mjs.map +1 -0
  18. package/dist/controllers/hubApi.cjs +2 -0
  19. package/dist/controllers/hubApi.cjs.map +1 -0
  20. package/dist/controllers/hubApi.mjs +2 -0
  21. package/dist/controllers/hubApi.mjs.map +1 -0
  22. package/dist/controllers/worktreesChannel.cjs +2 -0
  23. package/dist/controllers/worktreesChannel.cjs.map +1 -0
  24. package/dist/controllers/worktreesChannel.mjs +2 -0
  25. package/dist/controllers/worktreesChannel.mjs.map +1 -0
  26. package/dist/extensions/pi.cjs +2 -1
  27. package/dist/extensions/pi.cjs.map +1 -0
  28. package/dist/extensions/pi.d.cts +6 -2
  29. package/dist/extensions/pi.d.cts.map +1 -0
  30. package/dist/extensions/pi.d.mts +6 -2
  31. package/dist/extensions/pi.d.mts.map +1 -0
  32. package/dist/extensions/pi.mjs +2 -1
  33. package/dist/extensions/pi.mjs.map +1 -0
  34. package/dist/extensions/server.cjs +2 -0
  35. package/dist/extensions/server.cjs.map +1 -0
  36. package/dist/extensions/server.d.cts +5 -0
  37. package/dist/extensions/server.d.cts.map +1 -0
  38. package/dist/extensions/server.d.mts +5 -0
  39. package/dist/extensions/server.d.mts.map +1 -0
  40. package/dist/extensions/server.mjs +2 -0
  41. package/dist/extensions/server.mjs.map +1 -0
  42. package/dist/index.cjs +1 -1
  43. package/dist/index.d.cts +3 -4
  44. package/dist/index.d.mts +3 -4
  45. package/dist/index.mjs +1 -1
  46. package/dist/schemas/apiContracts.cjs +2 -0
  47. package/dist/schemas/apiContracts.cjs.map +1 -0
  48. package/dist/schemas/apiContracts.d.cts +53 -0
  49. package/dist/schemas/apiContracts.d.cts.map +1 -0
  50. package/dist/schemas/apiContracts.d.mts +53 -0
  51. package/dist/schemas/apiContracts.d.mts.map +1 -0
  52. package/dist/schemas/apiContracts.mjs +2 -0
  53. package/dist/schemas/apiContracts.mjs.map +1 -0
  54. package/dist/{adapters/filesystem/atomicJson.cjs → services/atomicJson/index.cjs} +1 -1
  55. package/dist/services/atomicJson/index.cjs.map +1 -0
  56. package/dist/{adapters/filesystem/atomicJson.mjs → services/atomicJson/index.mjs} +1 -1
  57. package/dist/services/atomicJson/index.mjs.map +1 -0
  58. package/dist/services/compositionMirror/index.cjs +2 -0
  59. package/dist/services/compositionMirror/index.cjs.map +1 -0
  60. package/dist/services/compositionMirror/index.mjs +2 -0
  61. package/dist/services/compositionMirror/index.mjs.map +1 -0
  62. package/dist/services/errors/index.cjs +2 -0
  63. package/dist/services/errors/index.cjs.map +1 -0
  64. package/dist/services/errors/index.mjs +2 -0
  65. package/dist/services/errors/index.mjs.map +1 -0
  66. package/dist/services/{extensionService.cjs → extensionService/index.cjs} +1 -1
  67. package/dist/services/extensionService/index.cjs.map +1 -0
  68. package/dist/services/extensionService/index.d.cts +8 -0
  69. package/dist/services/extensionService/index.d.cts.map +1 -0
  70. package/dist/services/extensionService/index.d.mts +8 -0
  71. package/dist/services/extensionService/index.d.mts.map +1 -0
  72. package/dist/services/{extensionService.mjs → extensionService/index.mjs} +1 -1
  73. package/dist/services/extensionService/index.mjs.map +1 -0
  74. package/dist/{adapters/worktree/gitCli.cjs → services/gitCli/index.cjs} +2 -2
  75. package/dist/services/gitCli/index.cjs.map +1 -0
  76. package/dist/{adapters/worktree/gitCli.mjs → services/gitCli/index.mjs} +2 -2
  77. package/dist/services/gitCli/index.mjs.map +1 -0
  78. package/dist/services/gitDependencies/index.cjs +2 -0
  79. package/dist/services/gitDependencies/index.cjs.map +1 -0
  80. package/dist/services/gitDependencies/index.d.cts +6 -0
  81. package/dist/services/gitDependencies/index.d.cts.map +1 -0
  82. package/dist/services/gitDependencies/index.d.mts +6 -0
  83. package/dist/services/gitDependencies/index.d.mts.map +1 -0
  84. package/dist/services/gitDependencies/index.mjs +2 -0
  85. package/dist/services/gitDependencies/index.mjs.map +1 -0
  86. package/dist/services/paths/index.cjs +2 -0
  87. package/dist/services/paths/index.cjs.map +1 -0
  88. package/dist/services/paths/index.mjs +2 -0
  89. package/dist/services/paths/index.mjs.map +1 -0
  90. package/dist/{adapters/worktree/repositoryIdentity.cjs → services/repositoryIdentity/index.cjs} +1 -1
  91. package/dist/services/repositoryIdentity/index.cjs.map +1 -0
  92. package/dist/{adapters/worktree/repositoryIdentity.mjs → services/repositoryIdentity/index.mjs} +1 -1
  93. package/dist/services/repositoryIdentity/index.mjs.map +1 -0
  94. package/dist/services/runWorktree/index.cjs +15 -0
  95. package/dist/services/runWorktree/index.cjs.map +1 -0
  96. package/dist/services/runWorktree/index.mjs +15 -0
  97. package/dist/services/runWorktree/index.mjs.map +1 -0
  98. package/dist/services/worktreeEvents/index.cjs +2 -0
  99. package/dist/services/worktreeEvents/index.cjs.map +1 -0
  100. package/dist/services/worktreeEvents/index.d.cts +15 -0
  101. package/dist/services/worktreeEvents/index.d.cts.map +1 -0
  102. package/dist/services/worktreeEvents/index.d.mts +15 -0
  103. package/dist/services/worktreeEvents/index.d.mts.map +1 -0
  104. package/dist/services/worktreeEvents/index.mjs +2 -0
  105. package/dist/services/worktreeEvents/index.mjs.map +1 -0
  106. package/dist/services/{worktreeNaming.cjs → worktreeNaming/index.cjs} +2 -2
  107. package/dist/services/{worktreeNaming.cjs.map → worktreeNaming/index.cjs.map} +1 -1
  108. package/dist/services/{worktreeNaming.d.mts → worktreeNaming/index.d.cts} +10 -3
  109. package/dist/services/worktreeNaming/index.d.cts.map +1 -0
  110. package/dist/services/{worktreeNaming.d.cts → worktreeNaming/index.d.mts} +10 -3
  111. package/dist/services/worktreeNaming/index.d.mts.map +1 -0
  112. package/dist/services/{worktreeNaming.mjs → worktreeNaming/index.mjs} +2 -2
  113. package/dist/services/{worktreeNaming.mjs.map → worktreeNaming/index.mjs.map} +1 -1
  114. package/dist/services/worktreeOperations/index.cjs +2 -0
  115. package/dist/services/worktreeOperations/index.cjs.map +1 -0
  116. package/dist/{adapters/worktree/worktreeOperations.d.cts → services/worktreeOperations/index.d.cts} +14 -8
  117. package/dist/services/worktreeOperations/index.d.cts.map +1 -0
  118. package/dist/{adapters/worktree/worktreeOperations.d.mts → services/worktreeOperations/index.d.mts} +14 -8
  119. package/dist/services/worktreeOperations/index.d.mts.map +1 -0
  120. package/dist/services/worktreeOperations/index.mjs +2 -0
  121. package/dist/services/worktreeOperations/index.mjs.map +1 -0
  122. package/dist/services/worktreeRegistry/index.cjs +2 -0
  123. package/dist/services/worktreeRegistry/index.cjs.map +1 -0
  124. package/dist/services/worktreeRegistry/index.mjs +2 -0
  125. package/dist/services/worktreeRegistry/index.mjs.map +1 -0
  126. package/dist/tools/runWorktree.cjs +2 -0
  127. package/dist/tools/runWorktree.cjs.map +1 -0
  128. package/dist/tools/runWorktree.mjs +2 -0
  129. package/dist/tools/runWorktree.mjs.map +1 -0
  130. package/dist/types/extension.d.cts +1 -1
  131. package/dist/types/extension.d.mts +1 -1
  132. package/package.json +27 -21
  133. package/src/extensions/web.ts +33 -0
  134. package/src/prompts/doompi-use-git/SKILL.md +5 -2
  135. package/src/types/worktreeRegistry.ts +9 -0
  136. package/src/web/components/RunWorktreeToolMessage.tsx +21 -13
  137. package/src/web/components/WorktreesActivitySection.tsx +29 -13
  138. package/src/web/components/WorktreesPanel.tsx +98 -48
  139. package/src/web/components/toolRenderers.ts +3 -2
  140. package/src/web/stores/worktreesActivityStore.ts +3 -2
  141. package/src/web/tsconfig.json +1 -1
  142. package/dist/adapters/channel/worktreeChannel.cjs +0 -2
  143. package/dist/adapters/channel/worktreeChannel.cjs.map +0 -1
  144. package/dist/adapters/channel/worktreeChannel.d.cts +0 -40
  145. package/dist/adapters/channel/worktreeChannel.d.cts.map +0 -1
  146. package/dist/adapters/channel/worktreeChannel.d.mts +0 -40
  147. package/dist/adapters/channel/worktreeChannel.d.mts.map +0 -1
  148. package/dist/adapters/channel/worktreeChannel.mjs +0 -2
  149. package/dist/adapters/channel/worktreeChannel.mjs.map +0 -1
  150. package/dist/adapters/filesystem/atomicJson.cjs.map +0 -1
  151. package/dist/adapters/filesystem/atomicJson.mjs.map +0 -1
  152. package/dist/adapters/filesystem/paths.cjs +0 -2
  153. package/dist/adapters/filesystem/paths.cjs.map +0 -1
  154. package/dist/adapters/filesystem/paths.mjs +0 -2
  155. package/dist/adapters/filesystem/paths.mjs.map +0 -1
  156. package/dist/adapters/hub/hubClient.cjs +0 -2
  157. package/dist/adapters/hub/hubClient.cjs.map +0 -1
  158. package/dist/adapters/hub/hubClient.d.cts +0 -1
  159. package/dist/adapters/hub/hubClient.d.mts +0 -1
  160. package/dist/adapters/hub/hubClient.mjs +0 -2
  161. package/dist/adapters/hub/hubClient.mjs.map +0 -1
  162. package/dist/adapters/pi/extension.cjs +0 -2
  163. package/dist/adapters/pi/extension.cjs.map +0 -1
  164. package/dist/adapters/pi/extension.d.cts +0 -9
  165. package/dist/adapters/pi/extension.d.cts.map +0 -1
  166. package/dist/adapters/pi/extension.d.mts +0 -9
  167. package/dist/adapters/pi/extension.d.mts.map +0 -1
  168. package/dist/adapters/pi/extension.mjs +0 -2
  169. package/dist/adapters/pi/extension.mjs.map +0 -1
  170. package/dist/adapters/pi/extensions/runWorktreeTool.cjs +0 -15
  171. package/dist/adapters/pi/extensions/runWorktreeTool.cjs.map +0 -1
  172. package/dist/adapters/pi/extensions/runWorktreeTool.mjs +0 -15
  173. package/dist/adapters/pi/extensions/runWorktreeTool.mjs.map +0 -1
  174. package/dist/adapters/web/worktreesChannel.cjs +0 -2
  175. package/dist/adapters/web/worktreesChannel.cjs.map +0 -1
  176. package/dist/adapters/web/worktreesChannel.d.cts +0 -21
  177. package/dist/adapters/web/worktreesChannel.d.cts.map +0 -1
  178. package/dist/adapters/web/worktreesChannel.d.mts +0 -21
  179. package/dist/adapters/web/worktreesChannel.d.mts.map +0 -1
  180. package/dist/adapters/web/worktreesChannel.mjs +0 -2
  181. package/dist/adapters/web/worktreesChannel.mjs.map +0 -1
  182. package/dist/adapters/worktree/dependencyInstall.cjs +0 -2
  183. package/dist/adapters/worktree/dependencyInstall.cjs.map +0 -1
  184. package/dist/adapters/worktree/dependencyInstall.mjs +0 -2
  185. package/dist/adapters/worktree/dependencyInstall.mjs.map +0 -1
  186. package/dist/adapters/worktree/gitCli.cjs.map +0 -1
  187. package/dist/adapters/worktree/gitCli.mjs.map +0 -1
  188. package/dist/adapters/worktree/repositoryIdentity.cjs.map +0 -1
  189. package/dist/adapters/worktree/repositoryIdentity.mjs.map +0 -1
  190. package/dist/adapters/worktree/worktreeOperations.cjs +0 -2
  191. package/dist/adapters/worktree/worktreeOperations.cjs.map +0 -1
  192. package/dist/adapters/worktree/worktreeOperations.d.cts.map +0 -1
  193. package/dist/adapters/worktree/worktreeOperations.d.mts.map +0 -1
  194. package/dist/adapters/worktree/worktreeOperations.mjs +0 -2
  195. package/dist/adapters/worktree/worktreeOperations.mjs.map +0 -1
  196. package/dist/adapters/worktree/worktreeRegistry.cjs +0 -2
  197. package/dist/adapters/worktree/worktreeRegistry.cjs.map +0 -1
  198. package/dist/adapters/worktree/worktreeRegistry.mjs +0 -2
  199. package/dist/adapters/worktree/worktreeRegistry.mjs.map +0 -1
  200. package/dist/commands/doomGitCommand.cjs +0 -2
  201. package/dist/commands/doomGitCommand.cjs.map +0 -1
  202. package/dist/commands/doomGitCommand.mjs +0 -2
  203. package/dist/commands/doomGitCommand.mjs.map +0 -1
  204. package/dist/container/index.cjs +0 -2
  205. package/dist/container/index.cjs.map +0 -1
  206. package/dist/container/index.d.cts +0 -6
  207. package/dist/container/index.d.cts.map +0 -1
  208. package/dist/container/index.d.mts +0 -6
  209. package/dist/container/index.d.mts.map +0 -1
  210. package/dist/container/index.mjs +0 -2
  211. package/dist/container/index.mjs.map +0 -1
  212. package/dist/hubApi.cjs +0 -2
  213. package/dist/hubApi.cjs.map +0 -1
  214. package/dist/hubApi.d.cts +0 -6
  215. package/dist/hubApi.d.cts.map +0 -1
  216. package/dist/hubApi.d.mts +0 -6
  217. package/dist/hubApi.d.mts.map +0 -1
  218. package/dist/hubApi.mjs +0 -2
  219. package/dist/hubApi.mjs.map +0 -1
  220. package/dist/services/extensionService.cjs.map +0 -1
  221. package/dist/services/extensionService.d.cts +0 -8
  222. package/dist/services/extensionService.d.cts.map +0 -1
  223. package/dist/services/extensionService.d.mts +0 -8
  224. package/dist/services/extensionService.d.mts.map +0 -1
  225. package/dist/services/extensionService.mjs.map +0 -1
  226. package/dist/services/support/errors.cjs +0 -2
  227. package/dist/services/support/errors.cjs.map +0 -1
  228. package/dist/services/support/errors.mjs +0 -2
  229. package/dist/services/support/errors.mjs.map +0 -1
  230. package/dist/services/worktreeNaming.d.cts.map +0 -1
  231. package/dist/services/worktreeNaming.d.mts.map +0 -1
  232. package/dist/webHub.cjs +0 -1
  233. package/dist/webHub.d.cts +0 -2
  234. package/dist/webHub.d.mts +0 -2
  235. package/dist/webHub.mjs +0 -1
  236. package/src/exports/webClient.ts +0 -1
  237. package/src/web/index.ts +0 -30
@@ -1,5 +1,5 @@
1
- import { WorktreeRecord } from "../types/worktreeRegistry.mjs";
2
- //#region src/services/worktreeNaming.d.ts
1
+ import { WorktreeRecord } from "../../types/worktreeRegistry.cjs";
2
+ //#region src/services/worktreeNaming/index.d.ts
3
3
  interface PrunePlan {
4
4
  /** Orphans whose directory git still lists, safe to remove. */
5
5
  remove: WorktreeRecord[];
@@ -9,6 +9,13 @@ interface PrunePlan {
9
9
  untracked: string[];
10
10
  /** Orphans left alone because they still hold uncommitted work. */
11
11
  keptDirty: WorktreeRecord[];
12
+ /**
13
+ * Branches git refused to delete because they hold commits.
14
+ *
15
+ * Filled by the prune itself, not by the plan: a dry run destroys nothing, so
16
+ * it has nothing to report here and leaves it empty.
17
+ */
18
+ keptBranches: string[];
12
19
  }
13
20
  /**
14
21
  * What a prune would do, decided before anything is destroyed.
@@ -24,4 +31,4 @@ declare function planPrune(input: {
24
31
  }): PrunePlan;
25
32
  //#endregion
26
33
  export { PrunePlan, planPrune };
27
- //# sourceMappingURL=worktreeNaming.d.mts.map
34
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/services/worktreeNaming/index.ts"],"mappings":";;UAoGiB;;EAEf,QAAQ;;EAER,QAAQ;;EAER;;EAEA,WAAW;;;;;;;EAOX;;;;;;;;iBASc,UAAU;EACxB,kBAAkB;EAClB;EACA;EACA,aAAa;IACX"}
@@ -1,5 +1,5 @@
1
- import { WorktreeRecord } from "../types/worktreeRegistry.cjs";
2
- //#region src/services/worktreeNaming.d.ts
1
+ import { WorktreeRecord } from "../../types/worktreeRegistry.mjs";
2
+ //#region src/services/worktreeNaming/index.d.ts
3
3
  interface PrunePlan {
4
4
  /** Orphans whose directory git still lists, safe to remove. */
5
5
  remove: WorktreeRecord[];
@@ -9,6 +9,13 @@ interface PrunePlan {
9
9
  untracked: string[];
10
10
  /** Orphans left alone because they still hold uncommitted work. */
11
11
  keptDirty: WorktreeRecord[];
12
+ /**
13
+ * Branches git refused to delete because they hold commits.
14
+ *
15
+ * Filled by the prune itself, not by the plan: a dry run destroys nothing, so
16
+ * it has nothing to report here and leaves it empty.
17
+ */
18
+ keptBranches: string[];
12
19
  }
13
20
  /**
14
21
  * What a prune would do, decided before anything is destroyed.
@@ -24,4 +31,4 @@ declare function planPrune(input: {
24
31
  }): PrunePlan;
25
32
  //#endregion
26
33
  export { PrunePlan, planPrune };
27
- //# sourceMappingURL=worktreeNaming.d.cts.map
34
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/worktreeNaming/index.ts"],"mappings":";;UAoGiB;;EAEf,QAAQ;;EAER,QAAQ;;EAER;;EAEA,WAAW;;;;;;;EAOX;;;;;;;;iBASc,UAAU;EACxB,kBAAkB;EAClB;EACA;EACA,aAAa;IACX"}
@@ -1,2 +1,2 @@
1
- function e(e){let t=e.toLowerCase().replace(/[^a-z0-9]+/gu,`-`).replace(/^-+|-+$/gu,``).slice(0,64).replace(/-+$/gu,``);return t===``?`worktree`:t}function t(t){let n=`${t.repositoryLabel}--${t.repositoryId}`;return`${t.worktreesRoot}/${n}/${e(t.branch)}--${t.shortId}`}function n(e){if(e.branch.trim()===``)return`A branch name is required.`;let t=e.existing.find(t=>t.branch===e.branch&&t.status!==`orphaned`);if(t)return`Branch ${e.branch} already has a worktree (${t.id}).`}function r(e){if(!e.record)return`No worktree with that id. Call list to see the current ids.`;if(e.dirtyFiles.length===0||e.force)return;let t=e.dirtyFiles.slice(0,10).join(`, `),n=e.dirtyFiles.length>10?`, and ${String(e.dirtyFiles.length-10)} more`:``;return`${String(e.dirtyFiles.length)} uncommitted file(s): ${t}${n}. Pass force: true to discard them.`}function i(e,t){let n=[];return{records:e.map(e=>e.status===`orphaned`||t.exists(e.path)&&t.alive(e)?e:(n.push(e.id),{...e,status:`orphaned`})),changed:n}}function a(e){let t={remove:[],forget:[],untracked:[],keptDirty:[]},n=new Set(e.records.map(e=>e.path)),r=new Set(e.gitPaths);for(let n of e.records)if(n.status===`orphaned`){if(!r.has(n.path)){t.forget.push(n);continue}if((e.dirtyByPath.get(n.path)??[]).length>0){t.keptDirty.push(n);continue}t.remove.push(n)}for(let r of e.gitPaths)r.startsWith(`${e.worktreesRoot}/`)&&!n.has(r)&&t.untracked.push(r);return t}export{e as branchSlug,a as planPrune,i as reconcile,r as refuseClose,n as refuseSpawn,t as worktreeDirectory};
2
- //# sourceMappingURL=worktreeNaming.mjs.map
1
+ function e(e){let t=e.toLowerCase().replace(/[^a-z0-9]+/gu,`-`).replace(/^-+|-+$/gu,``).slice(0,64).replace(/-+$/gu,``);return t===``?`worktree`:t}function t(t){let n=`${t.repositoryLabel}--${t.repositoryId}`;return`${t.worktreesRoot}/${n}/${e(t.branch)}--${t.shortId}`}function n(e){if(e.branch.trim()===``)return`A branch name is required.`;let t=e.existing.find(t=>t.branch===e.branch&&t.status!==`orphaned`);if(t)return`Branch ${e.branch} already has a worktree (${t.id}).`}function r(e){if(!e.record)return`No worktree with that id. Call list to see the current ids.`;if(e.dirtyFiles.length===0||e.force)return;let t=e.dirtyFiles.slice(0,10).join(`, `),n=e.dirtyFiles.length>10?`, and ${String(e.dirtyFiles.length-10)} more`:``;return`${String(e.dirtyFiles.length)} uncommitted file(s): ${t}${n}. Pass force: true to discard them.`}function i(e,t){let n=[];return{records:e.map(e=>e.status===`orphaned`||t.exists(e.path)&&t.alive(e)?e:(n.push(e.id),{...e,status:`orphaned`})),changed:n}}function a(e){let t={remove:[],forget:[],untracked:[],keptDirty:[],keptBranches:[]},n=new Set(e.records.map(e=>e.path)),r=new Set(e.gitPaths);for(let n of e.records)if(n.status===`orphaned`){if(!r.has(n.path)){t.forget.push(n);continue}if((e.dirtyByPath.get(n.path)??[]).length>0){t.keptDirty.push(n);continue}t.remove.push(n)}for(let r of e.gitPaths)r.startsWith(`${e.worktreesRoot}/`)&&!n.has(r)&&t.untracked.push(r);return t}export{e as branchSlug,a as planPrune,i as reconcile,r as refuseClose,n as refuseSpawn,t as worktreeDirectory};
2
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"worktreeNaming.mjs","names":[],"sources":["../../src/services/worktreeNaming.ts"],"sourcesContent":["/**\n * Naming and reconciliation rules for worktrees, as pure functions.\n *\n * Everything here is a function of its arguments so the interesting decisions,\n * which are the ones about destroying work, can be tested without a repository\n * or a filesystem.\n */\n\nimport type { WorktreeRecord } from '../types/worktreeRegistry.ts';\n\nconst MAX_SLUG_LENGTH = 64;\n\n/**\n * A branch name reduced to one safe path segment.\n *\n * Slashes are the point: `wt/fix-auth` is a perfectly good branch and a\n * terrible directory name, because the nested directory it implies is not the\n * one the worktree lives in.\n */\nexport function branchSlug(branch: string): string {\n const slug = branch\n .toLowerCase()\n .replace(/[^a-z0-9]+/gu, '-')\n .replace(/^-+|-+$/gu, '')\n .slice(0, MAX_SLUG_LENGTH)\n .replace(/-+$/gu, '');\n return slug === '' ? 'worktree' : slug;\n}\n\n/**\n * The directory for one worktree.\n *\n * The short id disambiguates two branches whose slugs collide, such as\n * `feature/x` and `feature_x`, which would otherwise want the same directory.\n */\nexport function worktreeDirectory(input: {\n worktreesRoot: string;\n repositoryLabel: string;\n repositoryId: string;\n branch: string;\n shortId: string;\n}): string {\n const repository = `${input.repositoryLabel}--${input.repositoryId}`;\n return `${input.worktreesRoot}/${repository}/${branchSlug(input.branch)}--${input.shortId}`;\n}\n\n/** Why a worktree cannot be created, or undefined when it can. */\nexport function refuseSpawn(input: { branch: string; existing: readonly WorktreeRecord[] }): string | undefined {\n if (input.branch.trim() === '') return 'A branch name is required.';\n // Git refuses a second worktree on one branch, but its message names a path\n // the caller never chose, so this says it in the caller's own terms first.\n const live = input.existing.find((record) => record.branch === input.branch && record.status !== 'orphaned');\n if (live) return `Branch ${input.branch} already has a worktree (${live.id}).`;\n return undefined;\n}\n\n/** Why a worktree cannot be closed, or undefined when it can. */\nexport function refuseClose(input: {\n record: WorktreeRecord | undefined;\n dirtyFiles: readonly string[];\n force: boolean;\n}): string | undefined {\n if (!input.record) return 'No worktree with that id. Call list to see the current ids.';\n if (input.dirtyFiles.length === 0 || input.force) return undefined;\n // Naming the files is the point: \"the tree is dirty\" sends the reader to go\n // look, and the answer is usually a file they forgot rather than one they\n // meant to keep.\n const names = input.dirtyFiles.slice(0, 10).join(', ');\n const more = input.dirtyFiles.length > 10 ? `, and ${String(input.dirtyFiles.length - 10)} more` : '';\n return `${String(input.dirtyFiles.length)} uncommitted file(s): ${names}${more}. Pass force: true to discard them.`;\n}\n\nexport interface Reconciliation {\n records: WorktreeRecord[];\n /** Ids whose status changed, so a caller can report what it noticed. */\n changed: string[];\n}\n\n/**\n * Marks records whose process or directory is gone as orphaned.\n *\n * Nothing is deleted here. A doompi-git orphan owns a directory that may hold\n * uncommitted work, so losing the record would lose the only pointer to it.\n * Deletion is always a separate, named decision.\n */\nexport function reconcile(\n records: readonly WorktreeRecord[],\n probe: { alive: (record: WorktreeRecord) => boolean; exists: (path: string) => boolean },\n): Reconciliation {\n const changed: string[] = [];\n const next = records.map((record) => {\n if (record.status === 'orphaned') return record;\n const gone = !probe.exists(record.path) || !probe.alive(record);\n if (!gone) return record;\n changed.push(record.id);\n return { ...record, status: 'orphaned' as const };\n });\n return { records: next, changed };\n}\n\nexport interface PrunePlan {\n /** Orphans whose directory git still lists, safe to remove. */\n remove: WorktreeRecord[];\n /** Orphans whose directory is already gone; drop the record only. */\n forget: WorktreeRecord[];\n /** Paths git lists under our root that we have no record of; report, never touch. */\n untracked: string[];\n /** Orphans left alone because they still hold uncommitted work. */\n keptDirty: WorktreeRecord[];\n}\n\n/**\n * What a prune would do, decided before anything is destroyed.\n *\n * Separating the plan from the execution is what makes dryRun honest and lets\n * the destructive half be reviewed on its own.\n */\nexport function planPrune(input: {\n records: readonly WorktreeRecord[];\n gitPaths: readonly string[];\n worktreesRoot: string;\n dirtyByPath: ReadonlyMap<string, readonly string[]>;\n}): PrunePlan {\n const plan: PrunePlan = { remove: [], forget: [], untracked: [], keptDirty: [] };\n const known = new Set(input.records.map((record) => record.path));\n const listed = new Set(input.gitPaths);\n for (const record of input.records) {\n if (record.status !== 'orphaned') continue;\n if (!listed.has(record.path)) {\n plan.forget.push(record);\n continue;\n }\n if ((input.dirtyByPath.get(record.path) ?? []).length > 0) {\n plan.keptDirty.push(record);\n continue;\n }\n plan.remove.push(record);\n }\n for (const path of input.gitPaths) {\n // Only ever inside our own root: a worktree the user made by hand is none\n // of this package's business, even when it looks abandoned.\n if (path.startsWith(`${input.worktreesRoot}/`) && !known.has(path)) plan.untracked.push(path);\n }\n return plan;\n}\n"],"mappings":"AAmBA,SAAgB,EAAW,EAAwB,CACjD,IAAM,EAAO,EACV,YAAY,CAAC,CACb,QAAQ,eAAgB,GAAG,CAAC,CAC5B,QAAQ,YAAa,EAAE,CAAC,CACxB,MAAM,EAAG,EAAe,CAAC,CACzB,QAAQ,QAAS,EAAE,EACtB,OAAO,IAAS,GAAK,WAAa,CACpC,CAQA,SAAgB,EAAkB,EAMvB,CACT,IAAM,EAAa,GAAG,EAAM,gBAAgB,IAAI,EAAM,eACtD,MAAO,GAAG,EAAM,cAAc,GAAG,EAAW,GAAG,EAAW,EAAM,MAAM,EAAE,IAAI,EAAM,SACpF,CAGA,SAAgB,EAAY,EAAoF,CAC9G,GAAI,EAAM,OAAO,KAAK,IAAM,GAAI,MAAO,6BAGvC,IAAM,EAAO,EAAM,SAAS,KAAM,GAAW,EAAO,SAAW,EAAM,QAAU,EAAO,SAAW,UAAU,EAC3G,GAAI,EAAM,MAAO,UAAU,EAAM,OAAO,2BAA2B,EAAK,GAAG,GAE7E,CAGA,SAAgB,EAAY,EAIL,CACrB,GAAI,CAAC,EAAM,OAAQ,MAAO,8DAC1B,GAAI,EAAM,WAAW,SAAW,GAAK,EAAM,MAAO,OAIlD,IAAM,EAAQ,EAAM,WAAW,MAAM,EAAG,EAAE,CAAC,CAAC,KAAK,IAAI,EAC/C,EAAO,EAAM,WAAW,OAAS,GAAK,SAAS,OAAO,EAAM,WAAW,OAAS,EAAE,EAAE,OAAS,GACnG,MAAO,GAAG,OAAO,EAAM,WAAW,MAAM,EAAE,wBAAwB,IAAQ,EAAK,oCACjF,CAeA,SAAgB,EACd,EACA,EACgB,CAChB,IAAM,EAAoB,CAAC,EAQ3B,MAAO,CAAE,QAPI,EAAQ,IAAK,GACpB,EAAO,SAAW,YACR,EAAM,OAAO,EAAO,IAAI,GAAM,EAAM,MAAM,CAAM,EAC5C,GAClB,EAAQ,KAAK,EAAO,EAAE,EACf,CAAE,GAAG,EAAQ,OAAQ,UAAoB,EAE7B,EAAG,SAAQ,CAClC,CAmBA,SAAgB,EAAU,EAKZ,CACZ,IAAM,EAAkB,CAAE,OAAQ,CAAC,EAAG,OAAQ,CAAC,EAAG,UAAW,CAAC,EAAG,UAAW,CAAC,CAAE,EACzE,EAAQ,IAAI,IAAI,EAAM,QAAQ,IAAK,GAAW,EAAO,IAAI,CAAC,EAC1D,EAAS,IAAI,IAAI,EAAM,QAAQ,EACrC,IAAK,IAAM,KAAU,EAAM,QACrB,KAAO,SAAW,WACtB,IAAI,CAAC,EAAO,IAAI,EAAO,IAAI,EAAG,CAC5B,EAAK,OAAO,KAAK,CAAM,EACvB,QACF,CACA,IAAK,EAAM,YAAY,IAAI,EAAO,IAAI,GAAK,CAAC,EAAA,CAAG,OAAS,EAAG,CACzD,EAAK,UAAU,KAAK,CAAM,EAC1B,QACF,CACA,EAAK,OAAO,KAAK,CAAM,CALvB,CAOF,IAAK,IAAM,KAAQ,EAAM,SAGnB,EAAK,WAAW,GAAG,EAAM,cAAc,EAAE,GAAK,CAAC,EAAM,IAAI,CAAI,GAAG,EAAK,UAAU,KAAK,CAAI,EAE9F,OAAO,CACT"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/worktreeNaming/index.ts"],"sourcesContent":["/**\n * Naming and reconciliation rules for worktrees, as pure functions.\n *\n * Everything here is a function of its arguments so the interesting decisions,\n * which are the ones about destroying work, can be tested without a repository\n * or a filesystem.\n */\n\nimport type { WorktreeRecord } from '../../types/worktreeRegistry';\n\nconst MAX_SLUG_LENGTH = 64;\n\n/**\n * A branch name reduced to one safe path segment.\n *\n * Slashes are the point: `wt/fix-auth` is a perfectly good branch and a\n * terrible directory name, because the nested directory it implies is not the\n * one the worktree lives in.\n */\nexport function branchSlug(branch: string): string {\n const slug = branch\n .toLowerCase()\n .replace(/[^a-z0-9]+/gu, '-')\n .replace(/^-+|-+$/gu, '')\n .slice(0, MAX_SLUG_LENGTH)\n .replace(/-+$/gu, '');\n return slug === '' ? 'worktree' : slug;\n}\n\n/**\n * The directory for one worktree.\n *\n * The short id disambiguates two branches whose slugs collide, such as\n * `feature/x` and `feature_x`, which would otherwise want the same directory.\n */\nexport function worktreeDirectory(input: {\n worktreesRoot: string;\n repositoryLabel: string;\n repositoryId: string;\n branch: string;\n shortId: string;\n}): string {\n const repository = `${input.repositoryLabel}--${input.repositoryId}`;\n return `${input.worktreesRoot}/${repository}/${branchSlug(input.branch)}--${input.shortId}`;\n}\n\n/** Why a worktree cannot be created, or undefined when it can. */\nexport function refuseSpawn(input: { branch: string; existing: readonly WorktreeRecord[] }): string | undefined {\n if (input.branch.trim() === '') return 'A branch name is required.';\n // Git refuses a second worktree on one branch, but its message names a path\n // the caller never chose, so this says it in the caller's own terms first.\n const live = input.existing.find((record) => record.branch === input.branch && record.status !== 'orphaned');\n if (live) return `Branch ${input.branch} already has a worktree (${live.id}).`;\n return undefined;\n}\n\n/** Why a worktree cannot be closed, or undefined when it can. */\nexport function refuseClose(input: {\n record: WorktreeRecord | undefined;\n dirtyFiles: readonly string[];\n force: boolean;\n}): string | undefined {\n if (!input.record) return 'No worktree with that id. Call list to see the current ids.';\n if (input.dirtyFiles.length === 0 || input.force) return undefined;\n // Naming the files is the point: \"the tree is dirty\" sends the reader to go\n // look, and the answer is usually a file they forgot rather than one they\n // meant to keep.\n const names = input.dirtyFiles.slice(0, 10).join(', ');\n const more = input.dirtyFiles.length > 10 ? `, and ${String(input.dirtyFiles.length - 10)} more` : '';\n return `${String(input.dirtyFiles.length)} uncommitted file(s): ${names}${more}. Pass force: true to discard them.`;\n}\n\nexport interface Reconciliation {\n records: WorktreeRecord[];\n /** Ids whose status changed, so a caller can report what it noticed. */\n changed: string[];\n}\n\n/**\n * Marks records whose process or directory is gone as orphaned.\n *\n * Nothing is deleted here. A doompi-git orphan owns a directory that may hold\n * uncommitted work, so losing the record would lose the only pointer to it.\n * Deletion is always a separate, named decision.\n */\nexport function reconcile(\n records: readonly WorktreeRecord[],\n probe: { alive: (record: WorktreeRecord) => boolean; exists: (path: string) => boolean },\n): Reconciliation {\n const changed: string[] = [];\n const next = records.map((record) => {\n if (record.status === 'orphaned') return record;\n const gone = !probe.exists(record.path) || !probe.alive(record);\n if (!gone) return record;\n changed.push(record.id);\n return { ...record, status: 'orphaned' as const };\n });\n return { records: next, changed };\n}\n\nexport interface PrunePlan {\n /** Orphans whose directory git still lists, safe to remove. */\n remove: WorktreeRecord[];\n /** Orphans whose directory is already gone; drop the record only. */\n forget: WorktreeRecord[];\n /** Paths git lists under our root that we have no record of; report, never touch. */\n untracked: string[];\n /** Orphans left alone because they still hold uncommitted work. */\n keptDirty: WorktreeRecord[];\n /**\n * Branches git refused to delete because they hold commits.\n *\n * Filled by the prune itself, not by the plan: a dry run destroys nothing, so\n * it has nothing to report here and leaves it empty.\n */\n keptBranches: string[];\n}\n\n/**\n * What a prune would do, decided before anything is destroyed.\n *\n * Separating the plan from the execution is what makes dryRun honest and lets\n * the destructive half be reviewed on its own.\n */\nexport function planPrune(input: {\n records: readonly WorktreeRecord[];\n gitPaths: readonly string[];\n worktreesRoot: string;\n dirtyByPath: ReadonlyMap<string, readonly string[]>;\n}): PrunePlan {\n const plan: PrunePlan = { remove: [], forget: [], untracked: [], keptDirty: [], keptBranches: [] };\n const known = new Set(input.records.map((record) => record.path));\n const listed = new Set(input.gitPaths);\n for (const record of input.records) {\n if (record.status !== 'orphaned') continue;\n if (!listed.has(record.path)) {\n plan.forget.push(record);\n continue;\n }\n if ((input.dirtyByPath.get(record.path) ?? []).length > 0) {\n plan.keptDirty.push(record);\n continue;\n }\n plan.remove.push(record);\n }\n for (const path of input.gitPaths) {\n // Only ever inside our own root: a worktree the user made by hand is none\n // of this package's business, even when it looks abandoned.\n if (path.startsWith(`${input.worktreesRoot}/`) && !known.has(path)) plan.untracked.push(path);\n }\n return plan;\n}\n"],"mappings":"AAmBA,SAAgB,EAAW,EAAwB,CACjD,IAAM,EAAO,EACV,YAAY,CAAC,CACb,QAAQ,eAAgB,GAAG,CAAC,CAC5B,QAAQ,YAAa,EAAE,CAAC,CACxB,MAAM,EAAG,EAAe,CAAC,CACzB,QAAQ,QAAS,EAAE,EACtB,OAAO,IAAS,GAAK,WAAa,CACpC,CAQA,SAAgB,EAAkB,EAMvB,CACT,IAAM,EAAa,GAAG,EAAM,gBAAgB,IAAI,EAAM,eACtD,MAAO,GAAG,EAAM,cAAc,GAAG,EAAW,GAAG,EAAW,EAAM,MAAM,EAAE,IAAI,EAAM,SACpF,CAGA,SAAgB,EAAY,EAAoF,CAC9G,GAAI,EAAM,OAAO,KAAK,IAAM,GAAI,MAAO,6BAGvC,IAAM,EAAO,EAAM,SAAS,KAAM,GAAW,EAAO,SAAW,EAAM,QAAU,EAAO,SAAW,UAAU,EAC3G,GAAI,EAAM,MAAO,UAAU,EAAM,OAAO,2BAA2B,EAAK,GAAG,GAE7E,CAGA,SAAgB,EAAY,EAIL,CACrB,GAAI,CAAC,EAAM,OAAQ,MAAO,8DAC1B,GAAI,EAAM,WAAW,SAAW,GAAK,EAAM,MAAO,OAIlD,IAAM,EAAQ,EAAM,WAAW,MAAM,EAAG,EAAE,CAAC,CAAC,KAAK,IAAI,EAC/C,EAAO,EAAM,WAAW,OAAS,GAAK,SAAS,OAAO,EAAM,WAAW,OAAS,EAAE,EAAE,OAAS,GACnG,MAAO,GAAG,OAAO,EAAM,WAAW,MAAM,EAAE,wBAAwB,IAAQ,EAAK,oCACjF,CAeA,SAAgB,EACd,EACA,EACgB,CAChB,IAAM,EAAoB,CAAC,EAQ3B,MAAO,CAAE,QAPI,EAAQ,IAAK,GACpB,EAAO,SAAW,YACR,EAAM,OAAO,EAAO,IAAI,GAAM,EAAM,MAAM,CAAM,EAC5C,GAClB,EAAQ,KAAK,EAAO,EAAE,EACf,CAAE,GAAG,EAAQ,OAAQ,UAAoB,EAE7B,EAAG,SAAQ,CAClC,CA0BA,SAAgB,EAAU,EAKZ,CACZ,IAAM,EAAkB,CAAE,OAAQ,CAAC,EAAG,OAAQ,CAAC,EAAG,UAAW,CAAC,EAAG,UAAW,CAAC,EAAG,aAAc,CAAC,CAAE,EAC3F,EAAQ,IAAI,IAAI,EAAM,QAAQ,IAAK,GAAW,EAAO,IAAI,CAAC,EAC1D,EAAS,IAAI,IAAI,EAAM,QAAQ,EACrC,IAAK,IAAM,KAAU,EAAM,QACrB,KAAO,SAAW,WACtB,IAAI,CAAC,EAAO,IAAI,EAAO,IAAI,EAAG,CAC5B,EAAK,OAAO,KAAK,CAAM,EACvB,QACF,CACA,IAAK,EAAM,YAAY,IAAI,EAAO,IAAI,GAAK,CAAC,EAAA,CAAG,OAAS,EAAG,CACzD,EAAK,UAAU,KAAK,CAAM,EAC1B,QACF,CACA,EAAK,OAAO,KAAK,CAAM,CALvB,CAOF,IAAK,IAAM,KAAQ,EAAM,SAGnB,EAAK,WAAW,GAAG,EAAM,cAAc,EAAE,GAAK,CAAC,EAAM,IAAI,CAAI,GAAG,EAAK,UAAU,KAAK,CAAI,EAE9F,OAAO,CACT"}
@@ -0,0 +1,2 @@
1
+ const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../compositionMirror/index.cjs"),n=require("../errors/index.cjs"),r=require("../repositoryIdentity/index.cjs"),i=require("../paths/index.cjs"),a=require("../worktreeEvents/index.cjs"),o=require("../worktreeNaming/index.cjs"),s=require("../worktreeRegistry/index.cjs");let c=require("node:fs");c=e.__toESM(c,1);let l=require("node:crypto");function u(e){let{git:u}=e,d=e.sessionService,f=e.mirror??t.mirrorComposition,p=e.now??(()=>new Date),m=()=>{if(d===void 0)throw new n.HubUnavailableError(`The cockpit session service is unavailable. Start the cockpit and try again.`);return d},h=()=>{if(e.messageInbox===void 0)throw new n.HubUnavailableError(`The Git message service is unavailable. Start the cockpit and try again.`);return e.messageInbox},g={alive:e=>m().isLive(e.sessionId),exists:e=>c.default.existsSync(e)},_=async t=>{let r=await u.repositoryRoot(t.cwd);if(r===void 0)throw new n.DoomGitExpectedError(`not_a_repository`,`${t.cwd} is not inside a git repository.`,!1,`Run this from a repository checkout.`);let a=s.createWorktreeRegistry(i.registryFile(r,e.homeDir));return{root:r,store:a,records:a.list()}},v=(e,t)=>{let r=e.find(e=>e.id===t);if(r===void 0)throw new n.DoomGitExpectedError(`worktree_not_found`,`No worktree with id ${t}.`,!1,`Call list to see the current ids.`);return r},y=(e,t,r)=>{if(t.parentSessionId!==e.sessionId&&m().isLive(t.parentSessionId))throw new n.DoomGitExpectedError(`worktree_not_owned`,`Worktree ${t.id} belongs to another session.`,!1,`Ask the session that created it to ${r} it, or close that session first.`)},b=(e,t)=>{if(e.sessionId===t.parentSessionId)return{sessionId:t.sessionId,party:`parent`};if(e.sessionId===t.sessionId)return{sessionId:t.parentSessionId,party:`child`};throw new n.DoomGitExpectedError(`worktree_not_owned`,`Worktree ${t.id} belongs to another session.`,!1,`Use a worktree owned by this session.`)},x=e=>{if(!m().isLive(e))throw new n.DoomGitExpectedError(`worktree_peer_unavailable`,`The other worktree session is no longer live.`,!1,`Start a new worktree session before sending a message.`)};return{async spawn(t,a,s){let{root:c,store:d,records:h}=await _(t),g=o.refuseSpawn({branch:a.branch,existing:h});if(g!==void 0)throw new n.DoomGitExpectedError(`worktree_exists`,g,!1,`Pick another branch name, or close it.`);let v=a.baseRef??await u.currentBranch(c)??`HEAD`,y=r.shortId((0,l.randomUUID)()),b=o.worktreeDirectory({worktreesRoot:i.worktreesRoot(e.homeDir),repositoryLabel:r.repositoryLabel(c),repositoryId:r.repositoryId(c),branch:a.branch,shortId:y}),x=()=>s?.signal?.aborted===!0,S=async()=>(await u.removeWorktree({repositoryRoot:c,path:b,force:!0}).catch(()=>void 0),await u.deleteBranch({repositoryRoot:c,branch:a.branch}).catch(()=>!1)?``:` The branch ${a.branch} has work on it and was kept.`);if(s?.onProgress?.(`creating branch ${a.branch}\u2026`),await u.addWorktree({repositoryRoot:c,path:b,branch:a.branch,baseRef:v}),x()){let e=await S();throw new n.DoomGitExpectedError(`spawn_cancelled`,`Cancelled before the session started.${e}`,!1,`The worktree was removed; run it again when you are ready.`)}s?.onProgress?.(`mirroring build output…`),f(c,b),s?.onProgress?.(`starting session…`);let C;try{C=(await m().create({cwd:b,name:a.name??a.branch,parentSessionId:t.sessionId,sessionProvenance:`worktree`,...s?.signal===void 0?{}:{signal:s.signal}})).sessionId}catch(e){let t=await S();throw x()?new n.DoomGitExpectedError(`spawn_cancelled`,`Cancelled while the session was starting.${t}`,!1,`The worktree was removed; run it again when you are ready.`):e instanceof n.HubUnavailableError?new n.DoomGitExpectedError(`hub_unavailable`,`${e.message}${t}`,!0,`Start the cockpit and try again.`):e}let w={version:1,id:y,branch:a.branch,baseRef:v,path:b,repositoryRoot:c,sessionId:C,parentSessionId:t.sessionId,status:`running`,createdAt:p().toISOString()};try{d.replace([...h,w])}catch(e){await m().close(C).catch(()=>void 0);let t=await S();throw new n.DoomGitExpectedError(`registry_write_failed`,`The worktree was created but the registry could not be written (${e.message}).${t}`,!0,`Check the registry file for permissions or free space, then try again.`)}return w},async close(e,t,r){let{root:i,store:a,records:s}=await _(e),l=v(s,t);y(e,l,`close`);let d=c.default.existsSync(l.path)?await u.dirtyFiles(l.path):[],f=o.refuseClose({record:l,dirtyFiles:d,force:r});if(f!==void 0)throw new n.DoomGitExpectedError(`worktree_dirty`,f,!1,`Commit the work, or pass force: true.`);return await m().close(l.sessionId),await u.removeWorktree({repositoryRoot:i,path:l.path,force:r}),a.replace(s.filter(e=>e.id!==t)),l},async list(e){let{store:t,records:n}=await _(e),r=o.reconcile(n,g);return r.changed.length>0&&t.replace(r.records),r.records},async status(e,t){let{records:n}=await _(e),r=v(n,t);return{record:r,dirtyFiles:c.default.existsSync(r.path)?await u.dirtyFiles(r.path):[]}},async merge(e,t,r){let{root:i,records:a}=await _(e),o=v(a,t);y(e,o,`merge`);let s=await u.dirtyFiles(i);if(s.length>0)throw new n.DoomGitExpectedError(`worktree_dirty`,`The parent checkout has ${String(s.length)} uncommitted file(s): ${s.slice(0,10).join(`, `)}.`,!1,`Commit or stash the parent checkout first.`);return await u.mergeBranch({repositoryRoot:i,branch:o.branch,...r===void 0?{}:{message:r}}),o},async send(e,t,r){if(Buffer.byteLength(r,`utf8`)>65536)throw new n.DoomGitExpectedError(`message_too_large`,`A message may not exceed ${String(a.MAX_WORKTREE_MESSAGE_BYTES)} bytes.`,!1,`Send a shorter message.`);let{records:i}=await _(e),o=v(i,t),s=b(e,o);x(s.sessionId),h().send(s.sessionId,{version:1,worktreeId:o.id,fromSessionId:e.sessionId,from:s.party,text:r,sentAt:new Date().toISOString()})},async messages(e,t){let{records:n}=await _(e),r=v(n,t);return b(e,r),h().receive(r.id)},async prune(t,n){let{root:r,store:a,records:s}=await _(t),l=o.reconcile(s,g),d=await u.listWorktreePaths(r),f=new Map;for(let e of l.records)e.status===`orphaned`&&c.default.existsSync(e.path)&&f.set(e.path,await u.dirtyFiles(e.path));let p=o.planPrune({records:l.records,gitPaths:d,worktreesRoot:i.worktreesRoot(e.homeDir),dirtyByPath:f});if(n)return a.replace(l.records),p;for(let e of p.remove)await u.removeWorktree({repositoryRoot:r,path:e.path,force:!1});for(let e of[...p.remove,...p.forget])await u.deleteBranch({repositoryRoot:r,branch:e.branch}).catch(()=>!1)||p.keptBranches.push(e.branch);let m=new Set([...p.remove,...p.forget].map(e=>e.id));return a.replace(l.records.filter(e=>!m.has(e.id))),p}}}exports.createWorktreeOperations=u;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["mirrorComposition","HubUnavailableError","fs","DoomGitExpectedError","createWorktreeRegistry","registryFile","require","refuseSpawn","shortId","randomUUID","worktreeDirectory","worktreesRoot","repositoryLabel","repositoryId","refuseClose","reconcile","MAX_WORKTREE_MESSAGE_BYTES","planPrune"],"sources":["../../../src/services/worktreeOperations/index.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport fs from 'node:fs';\n\nimport type { DoomHubSessionService } from '@agimon-ai/doompi-core/hub-channel';\n\nimport { WORKTREE_RECORD_VERSION } from '../../types/worktreeRegistry';\nimport type { WorktreeGit, WorktreeRecord } from '../../types/worktreeRegistry';\nimport { mirrorComposition } from '../compositionMirror';\nimport { DoomGitExpectedError, HubUnavailableError } from '../errors';\nimport { registryFile, worktreesRoot } from '../paths';\nimport { repositoryId, repositoryLabel, shortId } from '../repositoryIdentity';\nimport { MAX_WORKTREE_MESSAGE_BYTES, type WorktreeMessageInbox, type WorktreeMessageParty } from '../worktreeEvents';\nimport { planPrune, reconcile, refuseClose, refuseSpawn, worktreeDirectory } from '../worktreeNaming';\nimport { createWorktreeRegistry } from '../worktreeRegistry';\n\nexport interface WorktreeContext {\n /** Where the calling session is working, used to find the repository. */\n cwd: string;\n /** The calling session, recorded as the new session's parent. */\n sessionId: string;\n}\n\nexport interface SpawnWorktreeRequest {\n branch: string;\n baseRef?: string;\n name?: string;\n}\n\nexport interface SpawnOptions {\n /** Aborted when the caller gives up, so a spawn nobody is waiting for stops. */\n signal?: AbortSignal;\n /** Phase labels, for a caller that can show them while the work runs. */\n onProgress?: (label: string) => void;\n}\n\nexport interface WorktreeOperations {\n spawn(context: WorktreeContext, request: SpawnWorktreeRequest, options?: SpawnOptions): Promise<WorktreeRecord>;\n close(context: WorktreeContext, id: string, force: boolean): Promise<WorktreeRecord>;\n list(context: WorktreeContext): Promise<WorktreeRecord[]>;\n status(context: WorktreeContext, id: string): Promise<{ record: WorktreeRecord; dirtyFiles: string[] }>;\n merge(context: WorktreeContext, id: string, message?: string): Promise<WorktreeRecord>;\n prune(context: WorktreeContext, dryRun: boolean): Promise<ReturnType<typeof planPrune>>;\n send(context: WorktreeContext, id: string, message: string): Promise<void>;\n messages(context: WorktreeContext, id: string): Promise<import('../worktreeEvents').WorktreeMessage[]>;\n}\n\nexport interface WorktreeOperationsDeps {\n git: WorktreeGit;\n /** The canonical hub-owned session lifecycle. */\n sessionService?: DoomHubSessionService;\n /** Session-local inbox for parent/worktree messages. */\n messageInbox?: WorktreeMessageInbox;\n /** Injected so a test never copies a real dependency tree. */\n mirror?: typeof mirrorComposition;\n homeDir?: string;\n /** Injected so a record's createdAt is reproducible in a test. */\n now?: () => Date;\n}\n\nexport function createWorktreeOperations(deps: WorktreeOperationsDeps): WorktreeOperations {\n const { git } = deps;\n const sessionService = deps.sessionService;\n const mirror = deps.mirror ?? mirrorComposition;\n const now = deps.now ?? (() => new Date());\n const requireSessionService = (): DoomHubSessionService => {\n if (sessionService === undefined)\n throw new HubUnavailableError('The cockpit session service is unavailable. Start the cockpit and try again.');\n return sessionService;\n };\n const requireMessageInbox = (): WorktreeMessageInbox => {\n if (deps.messageInbox === undefined)\n throw new HubUnavailableError('The Git message service is unavailable. Start the cockpit and try again.');\n return deps.messageInbox;\n };\n const probe = {\n alive: (record: WorktreeRecord) => requireSessionService().isLive(record.sessionId),\n exists: (path: string) => fs.existsSync(path),\n };\n\n /**\n * Everything an action needs about the repository it is acting on.\n *\n * Resolved per call rather than cached: a session's cwd is stable, but the\n * worktree registry is shared and another process may have written it since\n * the last call.\n */\n const resolve = async (context: WorktreeContext) => {\n const root = await git.repositoryRoot(context.cwd);\n if (root === undefined) {\n throw new DoomGitExpectedError(\n 'not_a_repository',\n `${context.cwd} is not inside a git repository.`,\n false,\n 'Run this from a repository checkout.',\n );\n }\n const store = createWorktreeRegistry(registryFile(root, deps.homeDir));\n return { root, store, records: store.list() };\n };\n\n const require = (records: readonly WorktreeRecord[], id: string): WorktreeRecord => {\n const record = records.find((entry) => entry.id === id);\n if (record === undefined) {\n throw new DoomGitExpectedError(\n 'worktree_not_found',\n `No worktree with id ${id}.`,\n false,\n 'Call list to see the current ids.',\n );\n }\n return record;\n };\n\n /**\n * Refuses to destroy or merge a worktree another live session is using.\n *\n * `parentSessionId` records who asked for the worktree. Two sessions in one\n * checkout share this registry, so without the check either could close the\n * other's work in progress by id.\n *\n * Once that session is gone there is no owner left to protect, and refusing\n * would strand the worktree: nothing else could ever close it.\n */\n const requireOwner = (context: WorktreeContext, record: WorktreeRecord, action: string): void => {\n if (record.parentSessionId === context.sessionId) return;\n if (!requireSessionService().isLive(record.parentSessionId)) return;\n throw new DoomGitExpectedError(\n 'worktree_not_owned',\n `Worktree ${record.id} belongs to another session.`,\n false,\n `Ask the session that created it to ${action} it, or close that session first.`,\n );\n };\n\n const peerFor = (\n context: WorktreeContext,\n record: WorktreeRecord,\n ): { sessionId: string; party: WorktreeMessageParty } => {\n if (context.sessionId === record.parentSessionId) return { sessionId: record.sessionId, party: 'parent' };\n if (context.sessionId === record.sessionId) return { sessionId: record.parentSessionId, party: 'child' };\n throw new DoomGitExpectedError(\n 'worktree_not_owned',\n `Worktree ${record.id} belongs to another session.`,\n false,\n 'Use a worktree owned by this session.',\n );\n };\n\n const requirePeerLive = (peerSessionId: string): void => {\n if (!requireSessionService().isLive(peerSessionId)) {\n throw new DoomGitExpectedError(\n 'worktree_peer_unavailable',\n 'The other worktree session is no longer live.',\n false,\n 'Start a new worktree session before sending a message.',\n );\n }\n };\n\n return {\n async spawn(context, request, options) {\n const { root, store, records } = await resolve(context);\n const refusal = refuseSpawn({ branch: request.branch, existing: records });\n if (refusal !== undefined) {\n throw new DoomGitExpectedError('worktree_exists', refusal, false, 'Pick another branch name, or close it.');\n }\n const baseRef = request.baseRef ?? (await git.currentBranch(root)) ?? 'HEAD';\n const id = shortId(randomUUID());\n const path = worktreeDirectory({\n worktreesRoot: worktreesRoot(deps.homeDir),\n repositoryLabel: repositoryLabel(root),\n repositoryId: repositoryId(root),\n branch: request.branch,\n shortId: id,\n });\n\n // The worktree and the branch are made by one command, so they are undone\n // by one too. `worktree remove` leaves the branch behind, and a branch\n // nobody asked for is what a failed spawn used to leave on the floor.\n const cancelled = (): boolean => options?.signal?.aborted === true;\n const rollback = async (): Promise<string> => {\n await git.removeWorktree({ repositoryRoot: root, path, force: true }).catch(() => undefined);\n const deleted = await git.deleteBranch({ repositoryRoot: root, branch: request.branch }).catch(() => false);\n return deleted ? '' : ` The branch ${request.branch} has work on it and was kept.`;\n };\n\n options?.onProgress?.(`creating branch ${request.branch}\\u2026`);\n await git.addWorktree({ repositoryRoot: root, path, branch: request.branch, baseRef });\n\n // Checked here rather than only inside the session call: this is the\n // point where a checkout exists that nothing has recorded yet, which is\n // exactly the state an interrupted spawn used to leave behind.\n if (cancelled()) {\n const kept = await rollback();\n throw new DoomGitExpectedError(\n 'spawn_cancelled',\n `Cancelled before the session started.${kept}`,\n false,\n 'The worktree was removed; run it again when you are ready.',\n );\n }\n\n // Before the session, because the session composes the extensions this\n // repository's config names and those live in build output git does not\n // track. A worktree without it starts and dies on the first package it\n // cannot resolve. Nothing here can fail the spawn: a repository with no\n // build output to mirror simply has none.\n options?.onProgress?.('mirroring build output\\u2026');\n mirror(root, path);\n\n // The worktree exists from here on, so every later failure has to leave\n // it removed or recorded. An unrecorded directory on disk is the one\n // outcome with no way back: nothing would ever list it again.\n options?.onProgress?.('starting session\\u2026');\n let sessionId: string;\n try {\n const session = await requireSessionService().create({\n cwd: path,\n name: request.name ?? request.branch,\n parentSessionId: context.sessionId,\n sessionProvenance: 'worktree',\n ...(options?.signal === undefined ? {} : { signal: options.signal }),\n });\n sessionId = session.sessionId;\n } catch (error) {\n const kept = await rollback();\n if (cancelled()) {\n throw new DoomGitExpectedError(\n 'spawn_cancelled',\n `Cancelled while the session was starting.${kept}`,\n false,\n 'The worktree was removed; run it again when you are ready.',\n );\n }\n if (error instanceof HubUnavailableError) {\n throw new DoomGitExpectedError(\n 'hub_unavailable',\n `${error.message}${kept}`,\n true,\n 'Start the cockpit and try again.',\n );\n }\n throw error;\n }\n\n const record: WorktreeRecord = {\n version: WORKTREE_RECORD_VERSION,\n id,\n branch: request.branch,\n baseRef,\n path,\n repositoryRoot: root,\n sessionId,\n parentSessionId: context.sessionId,\n status: 'running',\n createdAt: now().toISOString(),\n };\n try {\n store.replace([...records, record]);\n } catch (error) {\n // A live session with no record is the worst outcome available here:\n // it runs, and no id anything can name points at it. The session goes\n // back too, rather than being left for someone to find by hand.\n await requireSessionService()\n .close(sessionId)\n .catch(() => undefined);\n const kept = await rollback();\n throw new DoomGitExpectedError(\n 'registry_write_failed',\n `The worktree was created but the registry could not be written (${(error as Error).message}).${kept}`,\n true,\n 'Check the registry file for permissions or free space, then try again.',\n );\n }\n return record;\n },\n\n async close(context, id, force) {\n const { root, store, records } = await resolve(context);\n const record = require(records, id);\n requireOwner(context, record, 'close');\n const dirtyFiles = fs.existsSync(record.path) ? await git.dirtyFiles(record.path) : [];\n const refusal = refuseClose({ record, dirtyFiles, force });\n if (refusal !== undefined) {\n throw new DoomGitExpectedError('worktree_dirty', refusal, false, 'Commit the work, or pass force: true.');\n }\n // The session is stopped before the directory goes. Removing a checkout\n // while a process still holds files open in it is how a half-removed\n // worktree and a stale git administrative entry are made.\n await requireSessionService().close(record.sessionId);\n await git.removeWorktree({ repositoryRoot: root, path: record.path, force });\n store.replace(records.filter((entry) => entry.id !== id));\n return record;\n },\n\n async list(context) {\n const { store, records } = await resolve(context);\n const outcome = reconcile(records, probe);\n if (outcome.changed.length > 0) store.replace(outcome.records);\n return outcome.records;\n },\n\n async status(context, id) {\n const { records } = await resolve(context);\n const record = require(records, id);\n const dirtyFiles = fs.existsSync(record.path) ? await git.dirtyFiles(record.path) : [];\n return { record, dirtyFiles };\n },\n\n async merge(context, id, message) {\n const { root, records } = await resolve(context);\n const record = require(records, id);\n requireOwner(context, record, 'merge');\n // The merge lands in the parent, so the parent is what must be clean. A\n // dirty parent would mix the person's in-flight edits into a merge commit\n // they did not intend to make.\n const parentDirty = await git.dirtyFiles(root);\n if (parentDirty.length > 0) {\n throw new DoomGitExpectedError(\n 'worktree_dirty',\n `The parent checkout has ${String(parentDirty.length)} uncommitted file(s): ${parentDirty.slice(0, 10).join(', ')}.`,\n false,\n 'Commit or stash the parent checkout first.',\n );\n }\n await git.mergeBranch({\n repositoryRoot: root,\n branch: record.branch,\n ...(message === undefined ? {} : { message }),\n });\n return record;\n },\n\n /** Sends only between the parent session and its own worktree session. */\n async send(context, id, message) {\n if (Buffer.byteLength(message, 'utf8') > MAX_WORKTREE_MESSAGE_BYTES) {\n throw new DoomGitExpectedError(\n 'message_too_large',\n `A message may not exceed ${String(MAX_WORKTREE_MESSAGE_BYTES)} bytes.`,\n false,\n 'Send a shorter message.',\n );\n }\n const { records } = await resolve(context);\n const record = require(records, id);\n const peer = peerFor(context, record);\n requirePeerLive(peer.sessionId);\n requireMessageInbox().send(peer.sessionId, {\n version: 1,\n worktreeId: record.id,\n fromSessionId: context.sessionId,\n from: peer.party,\n text: message,\n sentAt: new Date().toISOString(),\n });\n },\n\n async messages(context, id) {\n const { records } = await resolve(context);\n const record = require(records, id);\n peerFor(context, record);\n return requireMessageInbox().receive(record.id);\n },\n\n async prune(context, dryRun) {\n const { root, store, records } = await resolve(context);\n const reconciled = reconcile(records, probe);\n const gitPaths = await git.listWorktreePaths(root);\n const dirtyByPath = new Map<string, readonly string[]>();\n for (const record of reconciled.records) {\n if (record.status === 'orphaned' && fs.existsSync(record.path)) {\n dirtyByPath.set(record.path, await git.dirtyFiles(record.path));\n }\n }\n const plan = planPrune({\n records: reconciled.records,\n gitPaths,\n worktreesRoot: worktreesRoot(deps.homeDir),\n dirtyByPath,\n });\n if (dryRun) {\n store.replace(reconciled.records);\n return plan;\n }\n for (const record of plan.remove) {\n await git.removeWorktree({ repositoryRoot: root, path: record.path, force: false });\n }\n // The checkout goes, so the branch it was made for goes with it. Safe\n // delete only: git keeps anything holding commits, and the plan says\n // which ones it kept rather than leaving the reader to notice later.\n for (const record of [...plan.remove, ...plan.forget]) {\n const deleted = await git.deleteBranch({ repositoryRoot: root, branch: record.branch }).catch(() => false);\n if (!deleted) plan.keptBranches.push(record.branch);\n }\n const dropped = new Set([...plan.remove, ...plan.forget].map((record) => record.id));\n store.replace(reconciled.records.filter((record) => !dropped.has(record.id)));\n return plan;\n },\n };\n}\n"],"mappings":"sZA2DA,SAAgB,EAAyB,EAAkD,CACzF,GAAM,CAAE,OAAQ,EACV,EAAiB,EAAK,eACtB,EAAS,EAAK,QAAUA,EAAAA,kBACxB,EAAM,EAAK,UAAc,IAAI,MAC7B,MAAqD,CACzD,GAAI,IAAmB,IAAA,GACrB,MAAM,IAAIC,EAAAA,oBAAoB,8EAA8E,EAC9G,OAAO,CACT,EACM,MAAkD,CACtD,GAAI,EAAK,eAAiB,IAAA,GACxB,MAAM,IAAIA,EAAAA,oBAAoB,0EAA0E,EAC1G,OAAO,EAAK,YACd,EACM,EAAQ,CACZ,MAAQ,GAA2B,EAAsB,CAAC,CAAC,OAAO,EAAO,SAAS,EAClF,OAAS,GAAiBC,EAAAA,QAAG,WAAW,CAAI,CAC9C,EASM,EAAU,KAAO,IAA6B,CAClD,IAAM,EAAO,MAAM,EAAI,eAAe,EAAQ,GAAG,EACjD,GAAI,IAAS,IAAA,GACX,MAAM,IAAIC,EAAAA,qBACR,mBACA,GAAG,EAAQ,IAAI,kCACf,GACA,sCACF,EAEF,IAAM,EAAQC,EAAAA,uBAAuBC,EAAAA,aAAa,EAAM,EAAK,OAAO,CAAC,EACrE,MAAO,CAAE,OAAM,QAAO,QAAS,EAAM,KAAK,CAAE,CAC9C,EAEMC,GAAW,EAAoC,IAA+B,CAClF,IAAM,EAAS,EAAQ,KAAM,GAAU,EAAM,KAAO,CAAE,EACtD,GAAI,IAAW,IAAA,GACb,MAAM,IAAIH,EAAAA,qBACR,qBACA,uBAAuB,EAAG,GAC1B,GACA,mCACF,EAEF,OAAO,CACT,EAYM,GAAgB,EAA0B,EAAwB,IAAyB,CAC3F,KAAO,kBAAoB,E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AQ,CAAO,EAChD,EAAaS,EAAAA,UAAU,EAAS,CAAK,EACrC,EAAW,MAAM,EAAI,kBAAkB,CAAI,EAC3C,EAAc,IAAI,IACxB,IAAK,IAAM,KAAU,EAAW,QAC1B,EAAO,SAAW,YAAcb,EAAAA,QAAG,WAAW,EAAO,IAAI,GAC3D,EAAY,IAAI,EAAO,KAAM,MAAM,EAAI,WAAW,EAAO,IAAI,CAAC,EAGlE,IAAM,EAAOe,EAAAA,UAAU,CACrB,QAAS,EAAW,QACpB,WACA,cAAeN,EAAAA,cAAc,EAAK,OAAO,EACzC,aACF,CAAC,EACD,GAAI,EAEF,OADA,EAAM,QAAQ,EAAW,OAAO,EACzB,EAET,IAAK,IAAM,KAAU,EAAK,OACxB,MAAM,EAAI,eAAe,CAAE,eAAgB,EAAM,KAAM,EAAO,KAAM,MAAO,EAAM,CAAC,EAKpF,IAAK,IAAM,IAAU,CAAC,GAAG,EAAK,OAAQ,GAAG,EAAK,MAAM,EAE7C,MADiB,EAAI,aAAa,CAAE,eAAgB,EAAM,OAAQ,EAAO,MAAO,CAAC,CAAC,CAAC,UAAY,EAAK,GAC3F,EAAK,aAAa,KAAK,EAAO,MAAM,EAEpD,IAAM,EAAU,IAAI,IAAI,CAAC,GAAG,EAAK,OAAQ,GAAG,EAAK,MAAM,CAAC,CAAC,IAAK,GAAW,EAAO,EAAE,CAAC,EAEnF,OADA,EAAM,QAAQ,EAAW,QAAQ,OAAQ,GAAW,CAAC,EAAQ,IAAI,EAAO,EAAE,CAAC,CAAC,EACrE,CACT,CACF,CACF"}
@@ -1,8 +1,8 @@
1
- import "../hub/hubClient.cjs";
2
- import { ChannelMessage } from "../channel/worktreeChannel.cjs";
1
+ import { WorktreeMessage } from "../worktreeEvents/index.cjs";
3
2
  import { WorktreeRecord } from "../../types/worktreeRegistry.cjs";
4
- import { planPrune } from "../../services/worktreeNaming.cjs";
5
- //#region src/adapters/worktree/worktreeOperations.d.ts
3
+ import { planPrune } from "../worktreeNaming/index.cjs";
4
+ import "@agimon-ai/doompi-core/hub-channel";
5
+ //#region src/services/worktreeOperations/index.d.ts
6
6
  interface WorktreeContext {
7
7
  /** Where the calling session is working, used to find the repository. */
8
8
  cwd: string;
@@ -14,8 +14,14 @@ interface SpawnWorktreeRequest {
14
14
  baseRef?: string;
15
15
  name?: string;
16
16
  }
17
+ interface SpawnOptions {
18
+ /** Aborted when the caller gives up, so a spawn nobody is waiting for stops. */
19
+ signal?: AbortSignal;
20
+ /** Phase labels, for a caller that can show them while the work runs. */
21
+ onProgress?: (label: string) => void;
22
+ }
17
23
  interface WorktreeOperations {
18
- spawn(context: WorktreeContext, request: SpawnWorktreeRequest): Promise<WorktreeRecord>;
24
+ spawn(context: WorktreeContext, request: SpawnWorktreeRequest, options?: SpawnOptions): Promise<WorktreeRecord>;
19
25
  close(context: WorktreeContext, id: string, force: boolean): Promise<WorktreeRecord>;
20
26
  list(context: WorktreeContext): Promise<WorktreeRecord[]>;
21
27
  status(context: WorktreeContext, id: string): Promise<{
@@ -25,8 +31,8 @@ interface WorktreeOperations {
25
31
  merge(context: WorktreeContext, id: string, message?: string): Promise<WorktreeRecord>;
26
32
  prune(context: WorktreeContext, dryRun: boolean): Promise<ReturnType<typeof planPrune>>;
27
33
  send(context: WorktreeContext, id: string, message: string): Promise<void>;
28
- messages(context: WorktreeContext, id: string): Promise<ChannelMessage[]>;
34
+ messages(context: WorktreeContext, id: string): Promise<WorktreeMessage[]>;
29
35
  }
30
36
  //#endregion
31
- export { SpawnWorktreeRequest, WorktreeContext, WorktreeOperations };
32
- //# sourceMappingURL=worktreeOperations.d.cts.map
37
+ export { SpawnOptions, SpawnWorktreeRequest, WorktreeContext, WorktreeOperations };
38
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/services/worktreeOperations/index.ts"],"mappings":";;;;;UAeiB;;EAEf;;EAEA;;UAGe;EACf;EACA;EACA;;UAGe;;EAEf,SAAS;;EAET,cAAc;;UAGC;EACf,MAAM,SAAS,iBAAiB,SAAS,sBAAsB,UAAU,eAAe,QAAQ;EAChG,MAAM,SAAS,iBAAiB,YAAY,iBAAiB,QAAQ;EACrE,KAAK,SAAS,kBAAkB,QAAQ;EACxC,OAAO,SAAS,iBAAiB,aAAa;IAAU,QAAQ;IAAgB;;EAChF,MAAM,SAAS,iBAAiB,YAAY,mBAAmB,QAAQ;EACvE,MAAM,SAAS,iBAAiB,kBAAkB,QAAQ,kBAAkB;EAC5E,KAAK,SAAS,iBAAiB,YAAY,kBAAkB;EAC7D,SAAS,SAAS,iBAAiB,aAAa,QAA9B"}
@@ -1,8 +1,8 @@
1
- import "../hub/hubClient.mjs";
2
- import { ChannelMessage } from "../channel/worktreeChannel.mjs";
1
+ import { WorktreeMessage } from "../worktreeEvents/index.mjs";
3
2
  import { WorktreeRecord } from "../../types/worktreeRegistry.mjs";
4
- import { planPrune } from "../../services/worktreeNaming.mjs";
5
- //#region src/adapters/worktree/worktreeOperations.d.ts
3
+ import { planPrune } from "../worktreeNaming/index.mjs";
4
+ import "@agimon-ai/doompi-core/hub-channel";
5
+ //#region src/services/worktreeOperations/index.d.ts
6
6
  interface WorktreeContext {
7
7
  /** Where the calling session is working, used to find the repository. */
8
8
  cwd: string;
@@ -14,8 +14,14 @@ interface SpawnWorktreeRequest {
14
14
  baseRef?: string;
15
15
  name?: string;
16
16
  }
17
+ interface SpawnOptions {
18
+ /** Aborted when the caller gives up, so a spawn nobody is waiting for stops. */
19
+ signal?: AbortSignal;
20
+ /** Phase labels, for a caller that can show them while the work runs. */
21
+ onProgress?: (label: string) => void;
22
+ }
17
23
  interface WorktreeOperations {
18
- spawn(context: WorktreeContext, request: SpawnWorktreeRequest): Promise<WorktreeRecord>;
24
+ spawn(context: WorktreeContext, request: SpawnWorktreeRequest, options?: SpawnOptions): Promise<WorktreeRecord>;
19
25
  close(context: WorktreeContext, id: string, force: boolean): Promise<WorktreeRecord>;
20
26
  list(context: WorktreeContext): Promise<WorktreeRecord[]>;
21
27
  status(context: WorktreeContext, id: string): Promise<{
@@ -25,8 +31,8 @@ interface WorktreeOperations {
25
31
  merge(context: WorktreeContext, id: string, message?: string): Promise<WorktreeRecord>;
26
32
  prune(context: WorktreeContext, dryRun: boolean): Promise<ReturnType<typeof planPrune>>;
27
33
  send(context: WorktreeContext, id: string, message: string): Promise<void>;
28
- messages(context: WorktreeContext, id: string): Promise<ChannelMessage[]>;
34
+ messages(context: WorktreeContext, id: string): Promise<WorktreeMessage[]>;
29
35
  }
30
36
  //#endregion
31
- export { SpawnWorktreeRequest, WorktreeContext, WorktreeOperations };
32
- //# sourceMappingURL=worktreeOperations.d.mts.map
37
+ export { SpawnOptions, SpawnWorktreeRequest, WorktreeContext, WorktreeOperations };
38
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/worktreeOperations/index.ts"],"mappings":";;;;;UAeiB;;EAEf;;EAEA;;UAGe;EACf;EACA;EACA;;UAGe;;EAEf,SAAS;;EAET,cAAc;;UAGC;EACf,MAAM,SAAS,iBAAiB,SAAS,sBAAsB,UAAU,eAAe,QAAQ;EAChG,MAAM,SAAS,iBAAiB,YAAY,iBAAiB,QAAQ;EACrE,KAAK,SAAS,kBAAkB,QAAQ;EACxC,OAAO,SAAS,iBAAiB,aAAa;IAAU,QAAQ;IAAgB;;EAChF,MAAM,SAAS,iBAAiB,YAAY,mBAAmB,QAAQ;EACvE,MAAM,SAAS,iBAAiB,kBAAkB,QAAQ,kBAAkB;EAC5E,KAAK,SAAS,iBAAiB,YAAY,kBAAkB;EAC7D,SAAS,SAAS,iBAAiB,aAAa,QAA9B"}
@@ -0,0 +1,2 @@
1
+ import{mirrorComposition as e}from"../compositionMirror/index.mjs";import{DoomGitExpectedError as t,HubUnavailableError as n}from"../errors/index.mjs";import{repositoryId as r,repositoryLabel as i,shortId as a}from"../repositoryIdentity/index.mjs";import{registryFile as o,worktreesRoot as s}from"../paths/index.mjs";import{MAX_WORKTREE_MESSAGE_BYTES as c}from"../worktreeEvents/index.mjs";import{planPrune as l,reconcile as u,refuseClose as d,refuseSpawn as f,worktreeDirectory as p}from"../worktreeNaming/index.mjs";import{createWorktreeRegistry as m}from"../worktreeRegistry/index.mjs";import h from"node:fs";import{randomUUID as g}from"node:crypto";function _(_){let{git:v}=_,y=_.sessionService,b=_.mirror??e,x=_.now??(()=>new Date),S=()=>{if(y===void 0)throw new n(`The cockpit session service is unavailable. Start the cockpit and try again.`);return y},C=()=>{if(_.messageInbox===void 0)throw new n(`The Git message service is unavailable. Start the cockpit and try again.`);return _.messageInbox},w={alive:e=>S().isLive(e.sessionId),exists:e=>h.existsSync(e)},T=async e=>{let n=await v.repositoryRoot(e.cwd);if(n===void 0)throw new t(`not_a_repository`,`${e.cwd} is not inside a git repository.`,!1,`Run this from a repository checkout.`);let r=m(o(n,_.homeDir));return{root:n,store:r,records:r.list()}},E=(e,n)=>{let r=e.find(e=>e.id===n);if(r===void 0)throw new t(`worktree_not_found`,`No worktree with id ${n}.`,!1,`Call list to see the current ids.`);return r},D=(e,n,r)=>{if(n.parentSessionId!==e.sessionId&&S().isLive(n.parentSessionId))throw new t(`worktree_not_owned`,`Worktree ${n.id} belongs to another session.`,!1,`Ask the session that created it to ${r} it, or close that session first.`)},O=(e,n)=>{if(e.sessionId===n.parentSessionId)return{sessionId:n.sessionId,party:`parent`};if(e.sessionId===n.sessionId)return{sessionId:n.parentSessionId,party:`child`};throw new t(`worktree_not_owned`,`Worktree ${n.id} belongs to another session.`,!1,`Use a worktree owned by this session.`)},k=e=>{if(!S().isLive(e))throw new t(`worktree_peer_unavailable`,`The other worktree session is no longer live.`,!1,`Start a new worktree session before sending a message.`)};return{async spawn(e,o,c){let{root:l,store:u,records:d}=await T(e),m=f({branch:o.branch,existing:d});if(m!==void 0)throw new t(`worktree_exists`,m,!1,`Pick another branch name, or close it.`);let h=o.baseRef??await v.currentBranch(l)??`HEAD`,y=a(g()),C=p({worktreesRoot:s(_.homeDir),repositoryLabel:i(l),repositoryId:r(l),branch:o.branch,shortId:y}),w=()=>c?.signal?.aborted===!0,E=async()=>(await v.removeWorktree({repositoryRoot:l,path:C,force:!0}).catch(()=>void 0),await v.deleteBranch({repositoryRoot:l,branch:o.branch}).catch(()=>!1)?``:` The branch ${o.branch} has work on it and was kept.`);if(c?.onProgress?.(`creating branch ${o.branch}\u2026`),await v.addWorktree({repositoryRoot:l,path:C,branch:o.branch,baseRef:h}),w()){let e=await E();throw new t(`spawn_cancelled`,`Cancelled before the session started.${e}`,!1,`The worktree was removed; run it again when you are ready.`)}c?.onProgress?.(`mirroring build output…`),b(l,C),c?.onProgress?.(`starting session…`);let D;try{D=(await S().create({cwd:C,name:o.name??o.branch,parentSessionId:e.sessionId,sessionProvenance:`worktree`,...c?.signal===void 0?{}:{signal:c.signal}})).sessionId}catch(e){let r=await E();throw w()?new t(`spawn_cancelled`,`Cancelled while the session was starting.${r}`,!1,`The worktree was removed; run it again when you are ready.`):e instanceof n?new t(`hub_unavailable`,`${e.message}${r}`,!0,`Start the cockpit and try again.`):e}let O={version:1,id:y,branch:o.branch,baseRef:h,path:C,repositoryRoot:l,sessionId:D,parentSessionId:e.sessionId,status:`running`,createdAt:x().toISOString()};try{u.replace([...d,O])}catch(e){await S().close(D).catch(()=>void 0);let n=await E();throw new t(`registry_write_failed`,`The worktree was created but the registry could not be written (${e.message}).${n}`,!0,`Check the registry file for permissions or free space, then try again.`)}return O},async close(e,n,r){let{root:i,store:a,records:o}=await T(e),s=E(o,n);D(e,s,`close`);let c=h.existsSync(s.path)?await v.dirtyFiles(s.path):[],l=d({record:s,dirtyFiles:c,force:r});if(l!==void 0)throw new t(`worktree_dirty`,l,!1,`Commit the work, or pass force: true.`);return await S().close(s.sessionId),await v.removeWorktree({repositoryRoot:i,path:s.path,force:r}),a.replace(o.filter(e=>e.id!==n)),s},async list(e){let{store:t,records:n}=await T(e),r=u(n,w);return r.changed.length>0&&t.replace(r.records),r.records},async status(e,t){let{records:n}=await T(e),r=E(n,t);return{record:r,dirtyFiles:h.existsSync(r.path)?await v.dirtyFiles(r.path):[]}},async merge(e,n,r){let{root:i,records:a}=await T(e),o=E(a,n);D(e,o,`merge`);let s=await v.dirtyFiles(i);if(s.length>0)throw new t(`worktree_dirty`,`The parent checkout has ${String(s.length)} uncommitted file(s): ${s.slice(0,10).join(`, `)}.`,!1,`Commit or stash the parent checkout first.`);return await v.mergeBranch({repositoryRoot:i,branch:o.branch,...r===void 0?{}:{message:r}}),o},async send(e,n,r){if(Buffer.byteLength(r,`utf8`)>65536)throw new t(`message_too_large`,`A message may not exceed ${String(c)} bytes.`,!1,`Send a shorter message.`);let{records:i}=await T(e),a=E(i,n),o=O(e,a);k(o.sessionId),C().send(o.sessionId,{version:1,worktreeId:a.id,fromSessionId:e.sessionId,from:o.party,text:r,sentAt:new Date().toISOString()})},async messages(e,t){let{records:n}=await T(e),r=E(n,t);return O(e,r),C().receive(r.id)},async prune(e,t){let{root:n,store:r,records:i}=await T(e),a=u(i,w),o=await v.listWorktreePaths(n),c=new Map;for(let e of a.records)e.status===`orphaned`&&h.existsSync(e.path)&&c.set(e.path,await v.dirtyFiles(e.path));let d=l({records:a.records,gitPaths:o,worktreesRoot:s(_.homeDir),dirtyByPath:c});if(t)return r.replace(a.records),d;for(let e of d.remove)await v.removeWorktree({repositoryRoot:n,path:e.path,force:!1});for(let e of[...d.remove,...d.forget])await v.deleteBranch({repositoryRoot:n,branch:e.branch}).catch(()=>!1)||d.keptBranches.push(e.branch);let f=new Set([...d.remove,...d.forget].map(e=>e.id));return r.replace(a.records.filter(e=>!f.has(e.id))),d}}}export{_ as createWorktreeOperations};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/worktreeOperations/index.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport fs from 'node:fs';\n\nimport type { DoomHubSessionService } from '@agimon-ai/doompi-core/hub-channel';\n\nimport { WORKTREE_RECORD_VERSION } from '../../types/worktreeRegistry';\nimport type { WorktreeGit, WorktreeRecord } from '../../types/worktreeRegistry';\nimport { mirrorComposition } from '../compositionMirror';\nimport { DoomGitExpectedError, HubUnavailableError } from '../errors';\nimport { registryFile, worktreesRoot } from '../paths';\nimport { repositoryId, repositoryLabel, shortId } from '../repositoryIdentity';\nimport { MAX_WORKTREE_MESSAGE_BYTES, type WorktreeMessageInbox, type WorktreeMessageParty } from '../worktreeEvents';\nimport { planPrune, reconcile, refuseClose, refuseSpawn, worktreeDirectory } from '../worktreeNaming';\nimport { createWorktreeRegistry } from '../worktreeRegistry';\n\nexport interface WorktreeContext {\n /** Where the calling session is working, used to find the repository. */\n cwd: string;\n /** The calling session, recorded as the new session's parent. */\n sessionId: string;\n}\n\nexport interface SpawnWorktreeRequest {\n branch: string;\n baseRef?: string;\n name?: string;\n}\n\nexport interface SpawnOptions {\n /** Aborted when the caller gives up, so a spawn nobody is waiting for stops. */\n signal?: AbortSignal;\n /** Phase labels, for a caller that can show them while the work runs. */\n onProgress?: (label: string) => void;\n}\n\nexport interface WorktreeOperations {\n spawn(context: WorktreeContext, request: SpawnWorktreeRequest, options?: SpawnOptions): Promise<WorktreeRecord>;\n close(context: WorktreeContext, id: string, force: boolean): Promise<WorktreeRecord>;\n list(context: WorktreeContext): Promise<WorktreeRecord[]>;\n status(context: WorktreeContext, id: string): Promise<{ record: WorktreeRecord; dirtyFiles: string[] }>;\n merge(context: WorktreeContext, id: string, message?: string): Promise<WorktreeRecord>;\n prune(context: WorktreeContext, dryRun: boolean): Promise<ReturnType<typeof planPrune>>;\n send(context: WorktreeContext, id: string, message: string): Promise<void>;\n messages(context: WorktreeContext, id: string): Promise<import('../worktreeEvents').WorktreeMessage[]>;\n}\n\nexport interface WorktreeOperationsDeps {\n git: WorktreeGit;\n /** The canonical hub-owned session lifecycle. */\n sessionService?: DoomHubSessionService;\n /** Session-local inbox for parent/worktree messages. */\n messageInbox?: WorktreeMessageInbox;\n /** Injected so a test never copies a real dependency tree. */\n mirror?: typeof mirrorComposition;\n homeDir?: string;\n /** Injected so a record's createdAt is reproducible in a test. */\n now?: () => Date;\n}\n\nexport function createWorktreeOperations(deps: WorktreeOperationsDeps): WorktreeOperations {\n const { git } = deps;\n const sessionService = deps.sessionService;\n const mirror = deps.mirror ?? mirrorComposition;\n const now = deps.now ?? (() => new Date());\n const requireSessionService = (): DoomHubSessionService => {\n if (sessionService === undefined)\n throw new HubUnavailableError('The cockpit session service is unavailable. Start the cockpit and try again.');\n return sessionService;\n };\n const requireMessageInbox = (): WorktreeMessageInbox => {\n if (deps.messageInbox === undefined)\n throw new HubUnavailableError('The Git message service is unavailable. Start the cockpit and try again.');\n return deps.messageInbox;\n };\n const probe = {\n alive: (record: WorktreeRecord) => requireSessionService().isLive(record.sessionId),\n exists: (path: string) => fs.existsSync(path),\n };\n\n /**\n * Everything an action needs about the repository it is acting on.\n *\n * Resolved per call rather than cached: a session's cwd is stable, but the\n * worktree registry is shared and another process may have written it since\n * the last call.\n */\n const resolve = async (context: WorktreeContext) => {\n const root = await git.repositoryRoot(context.cwd);\n if (root === undefined) {\n throw new DoomGitExpectedError(\n 'not_a_repository',\n `${context.cwd} is not inside a git repository.`,\n false,\n 'Run this from a repository checkout.',\n );\n }\n const store = createWorktreeRegistry(registryFile(root, deps.homeDir));\n return { root, store, records: store.list() };\n };\n\n const require = (records: readonly WorktreeRecord[], id: string): WorktreeRecord => {\n const record = records.find((entry) => entry.id === id);\n if (record === undefined) {\n throw new DoomGitExpectedError(\n 'worktree_not_found',\n `No worktree with id ${id}.`,\n false,\n 'Call list to see the current ids.',\n );\n }\n return record;\n };\n\n /**\n * Refuses to destroy or merge a worktree another live session is using.\n *\n * `parentSessionId` records who asked for the worktree. Two sessions in one\n * checkout share this registry, so without the check either could close the\n * other's work in progress by id.\n *\n * Once that session is gone there is no owner left to protect, and refusing\n * would strand the worktree: nothing else could ever close it.\n */\n const requireOwner = (context: WorktreeContext, record: WorktreeRecord, action: string): void => {\n if (record.parentSessionId === context.sessionId) return;\n if (!requireSessionService().isLive(record.parentSessionId)) return;\n throw new DoomGitExpectedError(\n 'worktree_not_owned',\n `Worktree ${record.id} belongs to another session.`,\n false,\n `Ask the session that created it to ${action} it, or close that session first.`,\n );\n };\n\n const peerFor = (\n context: WorktreeContext,\n record: WorktreeRecord,\n ): { sessionId: string; party: WorktreeMessageParty } => {\n if (context.sessionId === record.parentSessionId) return { sessionId: record.sessionId, party: 'parent' };\n if (context.sessionId === record.sessionId) return { sessionId: record.parentSessionId, party: 'child' };\n throw new DoomGitExpectedError(\n 'worktree_not_owned',\n `Worktree ${record.id} belongs to another session.`,\n false,\n 'Use a worktree owned by this session.',\n );\n };\n\n const requirePeerLive = (peerSessionId: string): void => {\n if (!requireSessionService().isLive(peerSessionId)) {\n throw new DoomGitExpectedError(\n 'worktree_peer_unavailable',\n 'The other worktree session is no longer live.',\n false,\n 'Start a new worktree session before sending a message.',\n );\n }\n };\n\n return {\n async spawn(context, request, options) {\n const { root, store, records } = await resolve(context);\n const refusal = refuseSpawn({ branch: request.branch, existing: records });\n if (refusal !== undefined) {\n throw new DoomGitExpectedError('worktree_exists', refusal, false, 'Pick another branch name, or close it.');\n }\n const baseRef = request.baseRef ?? (await git.currentBranch(root)) ?? 'HEAD';\n const id = shortId(randomUUID());\n const path = worktreeDirectory({\n worktreesRoot: worktreesRoot(deps.homeDir),\n repositoryLabel: repositoryLabel(root),\n repositoryId: repositoryId(root),\n branch: request.branch,\n shortId: id,\n });\n\n // The worktree and the branch are made by one command, so they are undone\n // by one too. `worktree remove` leaves the branch behind, and a branch\n // nobody asked for is what a failed spawn used to leave on the floor.\n const cancelled = (): boolean => options?.signal?.aborted === true;\n const rollback = async (): Promise<string> => {\n await git.removeWorktree({ repositoryRoot: root, path, force: true }).catch(() => undefined);\n const deleted = await git.deleteBranch({ repositoryRoot: root, branch: request.branch }).catch(() => false);\n return deleted ? '' : ` The branch ${request.branch} has work on it and was kept.`;\n };\n\n options?.onProgress?.(`creating branch ${request.branch}\\u2026`);\n await git.addWorktree({ repositoryRoot: root, path, branch: request.branch, baseRef });\n\n // Checked here rather than only inside the session call: this is the\n // point where a checkout exists that nothing has recorded yet, which is\n // exactly the state an interrupted spawn used to leave behind.\n if (cancelled()) {\n const kept = await rollback();\n throw new DoomGitExpectedError(\n 'spawn_cancelled',\n `Cancelled before the session started.${kept}`,\n false,\n 'The worktree was removed; run it again when you are ready.',\n );\n }\n\n // Before the session, because the session composes the extensions this\n // repository's config names and those live in build output git does not\n // track. A worktree without it starts and dies on the first package it\n // cannot resolve. Nothing here can fail the spawn: a repository with no\n // build output to mirror simply has none.\n options?.onProgress?.('mirroring build output\\u2026');\n mirror(root, path);\n\n // The worktree exists from here on, so every later failure has to leave\n // it removed or recorded. An unrecorded directory on disk is the one\n // outcome with no way back: nothing would ever list it again.\n options?.onProgress?.('starting session\\u2026');\n let sessionId: string;\n try {\n const session = await requireSessionService().create({\n cwd: path,\n name: request.name ?? request.branch,\n parentSessionId: context.sessionId,\n sessionProvenance: 'worktree',\n ...(options?.signal === undefined ? {} : { signal: options.signal }),\n });\n sessionId = session.sessionId;\n } catch (error) {\n const kept = await rollback();\n if (cancelled()) {\n throw new DoomGitExpectedError(\n 'spawn_cancelled',\n `Cancelled while the session was starting.${kept}`,\n false,\n 'The worktree was removed; run it again when you are ready.',\n );\n }\n if (error instanceof HubUnavailableError) {\n throw new DoomGitExpectedError(\n 'hub_unavailable',\n `${error.message}${kept}`,\n true,\n 'Start the cockpit and try again.',\n );\n }\n throw error;\n }\n\n const record: WorktreeRecord = {\n version: WORKTREE_RECORD_VERSION,\n id,\n branch: request.branch,\n baseRef,\n path,\n repositoryRoot: root,\n sessionId,\n parentSessionId: context.sessionId,\n status: 'running',\n createdAt: now().toISOString(),\n };\n try {\n store.replace([...records, record]);\n } catch (error) {\n // A live session with no record is the worst outcome available here:\n // it runs, and no id anything can name points at it. The session goes\n // back too, rather than being left for someone to find by hand.\n await requireSessionService()\n .close(sessionId)\n .catch(() => undefined);\n const kept = await rollback();\n throw new DoomGitExpectedError(\n 'registry_write_failed',\n `The worktree was created but the registry could not be written (${(error as Error).message}).${kept}`,\n true,\n 'Check the registry file for permissions or free space, then try again.',\n );\n }\n return record;\n },\n\n async close(context, id, force) {\n const { root, store, records } = await resolve(context);\n const record = require(records, id);\n requireOwner(context, record, 'close');\n const dirtyFiles = fs.existsSync(record.path) ? await git.dirtyFiles(record.path) : [];\n const refusal = refuseClose({ record, dirtyFiles, force });\n if (refusal !== undefined) {\n throw new DoomGitExpectedError('worktree_dirty', refusal, false, 'Commit the work, or pass force: true.');\n }\n // The session is stopped before the directory goes. Removing a checkout\n // while a process still holds files open in it is how a half-removed\n // worktree and a stale git administrative entry are made.\n await requireSessionService().close(record.sessionId);\n await git.removeWorktree({ repositoryRoot: root, path: record.path, force });\n store.replace(records.filter((entry) => entry.id !== id));\n return record;\n },\n\n async list(context) {\n const { store, records } = await resolve(context);\n const outcome = reconcile(records, probe);\n if (outcome.changed.length > 0) store.replace(outcome.records);\n return outcome.records;\n },\n\n async status(context, id) {\n const { records } = await resolve(context);\n const record = require(records, id);\n const dirtyFiles = fs.existsSync(record.path) ? await git.dirtyFiles(record.path) : [];\n return { record, dirtyFiles };\n },\n\n async merge(context, id, message) {\n const { root, records } = await resolve(context);\n const record = require(records, id);\n requireOwner(context, record, 'merge');\n // The merge lands in the parent, so the parent is what must be clean. A\n // dirty parent would mix the person's in-flight edits into a merge commit\n // they did not intend to make.\n const parentDirty = await git.dirtyFiles(root);\n if (parentDirty.length > 0) {\n throw new DoomGitExpectedError(\n 'worktree_dirty',\n `The parent checkout has ${String(parentDirty.length)} uncommitted file(s): ${parentDirty.slice(0, 10).join(', ')}.`,\n false,\n 'Commit or stash the parent checkout first.',\n );\n }\n await git.mergeBranch({\n repositoryRoot: root,\n branch: record.branch,\n ...(message === undefined ? {} : { message }),\n });\n return record;\n },\n\n /** Sends only between the parent session and its own worktree session. */\n async send(context, id, message) {\n if (Buffer.byteLength(message, 'utf8') > MAX_WORKTREE_MESSAGE_BYTES) {\n throw new DoomGitExpectedError(\n 'message_too_large',\n `A message may not exceed ${String(MAX_WORKTREE_MESSAGE_BYTES)} bytes.`,\n false,\n 'Send a shorter message.',\n );\n }\n const { records } = await resolve(context);\n const record = require(records, id);\n const peer = peerFor(context, record);\n requirePeerLive(peer.sessionId);\n requireMessageInbox().send(peer.sessionId, {\n version: 1,\n worktreeId: record.id,\n fromSessionId: context.sessionId,\n from: peer.party,\n text: message,\n sentAt: new Date().toISOString(),\n });\n },\n\n async messages(context, id) {\n const { records } = await resolve(context);\n const record = require(records, id);\n peerFor(context, record);\n return requireMessageInbox().receive(record.id);\n },\n\n async prune(context, dryRun) {\n const { root, store, records } = await resolve(context);\n const reconciled = reconcile(records, probe);\n const gitPaths = await git.listWorktreePaths(root);\n const dirtyByPath = new Map<string, readonly string[]>();\n for (const record of reconciled.records) {\n if (record.status === 'orphaned' && fs.existsSync(record.path)) {\n dirtyByPath.set(record.path, await git.dirtyFiles(record.path));\n }\n }\n const plan = planPrune({\n records: reconciled.records,\n gitPaths,\n worktreesRoot: worktreesRoot(deps.homeDir),\n dirtyByPath,\n });\n if (dryRun) {\n store.replace(reconciled.records);\n return plan;\n }\n for (const record of plan.remove) {\n await git.removeWorktree({ repositoryRoot: root, path: record.path, force: false });\n }\n // The checkout goes, so the branch it was made for goes with it. Safe\n // delete only: git keeps anything holding commits, and the plan says\n // which ones it kept rather than leaving the reader to notice later.\n for (const record of [...plan.remove, ...plan.forget]) {\n const deleted = await git.deleteBranch({ repositoryRoot: root, branch: record.branch }).catch(() => false);\n if (!deleted) plan.keptBranches.push(record.branch);\n }\n const dropped = new Set([...plan.remove, ...plan.forget].map((record) => record.id));\n store.replace(reconciled.records.filter((record) => !dropped.has(record.id)));\n return plan;\n },\n };\n}\n"],"mappings":"6oBA2DA,SAAgB,EAAyB,EAAkD,CACzF,GAA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AG,EAAK,MAAM,EAE7C,MADiB,EAAI,aAAa,CAAE,eAAgB,EAAM,OAAQ,EAAO,MAAO,CAAC,CAAC,CAAC,UAAY,EAAK,GAC3F,EAAK,aAAa,KAAK,EAAO,MAAM,EAEpD,IAAM,EAAU,IAAI,IAAI,CAAC,GAAG,EAAK,OAAQ,GAAG,EAAK,MAAM,CAAC,CAAC,IAAK,GAAW,EAAO,EAAE,CAAC,EAEnF,OADA,EAAM,QAAQ,EAAW,QAAQ,OAAQ,GAAW,CAAC,EAAQ,IAAI,EAAO,EAAE,CAAC,CAAC,EACrE,CACT,CACF,CACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("../atomicJson/index.cjs");function t(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.version===1&&typeof t.id==`string`&&t.id!==``&&typeof t.path==`string`&&typeof t.branch==`string`&&typeof t.sessionId==`string`}function n(n){return{list(){let r=e.readJson(n);return!r||r.version!==1||!Array.isArray(r.entries)?[]:r.entries.filter(t)},replace(t){e.writeJsonAtomic(n,{version:1,entries:t})}}}exports.createWorktreeRegistry=n;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["readJson"],"sources":["../../../src/services/worktreeRegistry/index.ts"],"sourcesContent":["import {\n WORKTREE_RECORD_VERSION,\n type WorktreeRecord,\n type WorktreeRegistryFile,\n type WorktreeRegistryStore,\n} from '../../types/worktreeRegistry';\nimport { readJson, writeJsonAtomic } from '../atomicJson';\n\nfunction isRecord(value: unknown): value is WorktreeRecord {\n if (typeof value !== 'object' || value === null) return false;\n const record = value as Partial<WorktreeRecord>;\n return (\n record.version === WORKTREE_RECORD_VERSION &&\n typeof record.id === 'string' &&\n record.id !== '' &&\n typeof record.path === 'string' &&\n typeof record.branch === 'string' &&\n typeof record.sessionId === 'string'\n );\n}\n\n/**\n * The worktree registry for one repository, as a single JSON file.\n *\n * One file rather than a file per worktree, and read-modify-write rather than\n * merging: every write comes from a tool call in one session's turn, so there\n * is no concurrent writer to reconcile with. Choosing the simpler shape now\n * means a reader can see the whole registry in one place; if concurrent writers\n * ever appear, that is the point to revisit, not before.\n *\n * A file that does not parse is treated as empty rather than fatal. Losing\n * track of worktrees is recoverable through prune; refusing to run is not.\n */\nexport function createWorktreeRegistry(file: string): WorktreeRegistryStore {\n return {\n list() {\n const parsed = readJson<WorktreeRegistryFile>(file);\n if (!parsed || parsed.version !== WORKTREE_RECORD_VERSION || !Array.isArray(parsed.entries)) return [];\n return parsed.entries.filter(isRecord);\n },\n replace(entries) {\n writeJsonAtomic(file, { version: WORKTREE_RECORD_VERSION, entries } satisfies WorktreeRegistryFile);\n },\n };\n}\n"],"mappings":"2CAQA,SAAS,EAAS,EAAyC,CACzD,GAAI,OAAO,GAAU,WAAY,EAAgB,MAAO,GACxD,IAAM,EAAS,EACf,OACE,EAAO,UAAA,GACP,OAAO,EAAO,IAAO,UACrB,EAAO,KAAO,IACd,OAAO,EAAO,MAAS,UACvB,OAAO,EAAO,QAAW,UACzB,OAAO,EAAO,WAAc,QAEhC,CAcA,SAAgB,EAAuB,EAAqC,CAC1E,MAAO,CACL,MAAO,CACL,IAAM,EAASA,EAAAA,SAA+B,CAAI,EAElD,MADI,CAAC,GAAU,EAAO,UAAA,GAAuC,CAAC,MAAM,QAAQ,EAAO,OAAO,EAAU,CAAC,EAC9F,EAAO,QAAQ,OAAO,CAAQ,CACvC,EACA,QAAQ,EAAS,CACf,EAAA,gBAAgB,EAAM,CAAE,QAAA,EAAkC,SAAQ,CAAgC,CACpG,CACF,CACF"}
@@ -0,0 +1,2 @@
1
+ import{readJson as e,writeJsonAtomic as t}from"../atomicJson/index.mjs";function n(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.version===1&&typeof t.id==`string`&&t.id!==``&&typeof t.path==`string`&&typeof t.branch==`string`&&typeof t.sessionId==`string`}function r(r){return{list(){let t=e(r);return!t||t.version!==1||!Array.isArray(t.entries)?[]:t.entries.filter(n)},replace(e){t(r,{version:1,entries:e})}}}export{r as createWorktreeRegistry};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/worktreeRegistry/index.ts"],"sourcesContent":["import {\n WORKTREE_RECORD_VERSION,\n type WorktreeRecord,\n type WorktreeRegistryFile,\n type WorktreeRegistryStore,\n} from '../../types/worktreeRegistry';\nimport { readJson, writeJsonAtomic } from '../atomicJson';\n\nfunction isRecord(value: unknown): value is WorktreeRecord {\n if (typeof value !== 'object' || value === null) return false;\n const record = value as Partial<WorktreeRecord>;\n return (\n record.version === WORKTREE_RECORD_VERSION &&\n typeof record.id === 'string' &&\n record.id !== '' &&\n typeof record.path === 'string' &&\n typeof record.branch === 'string' &&\n typeof record.sessionId === 'string'\n );\n}\n\n/**\n * The worktree registry for one repository, as a single JSON file.\n *\n * One file rather than a file per worktree, and read-modify-write rather than\n * merging: every write comes from a tool call in one session's turn, so there\n * is no concurrent writer to reconcile with. Choosing the simpler shape now\n * means a reader can see the whole registry in one place; if concurrent writers\n * ever appear, that is the point to revisit, not before.\n *\n * A file that does not parse is treated as empty rather than fatal. Losing\n * track of worktrees is recoverable through prune; refusing to run is not.\n */\nexport function createWorktreeRegistry(file: string): WorktreeRegistryStore {\n return {\n list() {\n const parsed = readJson<WorktreeRegistryFile>(file);\n if (!parsed || parsed.version !== WORKTREE_RECORD_VERSION || !Array.isArray(parsed.entries)) return [];\n return parsed.entries.filter(isRecord);\n },\n replace(entries) {\n writeJsonAtomic(file, { version: WORKTREE_RECORD_VERSION, entries } satisfies WorktreeRegistryFile);\n },\n };\n}\n"],"mappings":"wEAQA,SAAS,EAAS,EAAyC,CACzD,GAAI,OAAO,GAAU,WAAY,EAAgB,MAAO,GACxD,IAAM,EAAS,EACf,OACE,EAAO,UAAA,GACP,OAAO,EAAO,IAAO,UACrB,EAAO,KAAO,IACd,OAAO,EAAO,MAAS,UACvB,OAAO,EAAO,QAAW,UACzB,OAAO,EAAO,WAAc,QAEhC,CAcA,SAAgB,EAAuB,EAAqC,CAC1E,MAAO,CACL,MAAO,CACL,IAAM,EAAS,EAA+B,CAAI,EAElD,MADI,CAAC,GAAU,EAAO,UAAA,GAAuC,CAAC,MAAM,QAAQ,EAAO,OAAO,EAAU,CAAC,EAC9F,EAAO,QAAQ,OAAO,CAAQ,CACvC,EACA,QAAQ,EAAS,CACf,EAAgB,EAAM,CAAE,QAAA,EAAkC,SAAQ,CAAgC,CACpG,CACF,CACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("../schemas/runWorktreeTool.cjs"),t=require("../services/runWorktree/index.cjs");function n(n){return{name:t.RUN_WORKTREE_TOOL_NAME,label:`Worktree`,description:t.RUN_WORKTREE_DESCRIPTION,parameters:e.RunWorktreeParams,prepareArguments:t.validateParams,execute:async(e,r,i,a,o)=>{let s=t.validateParams(r);return await t.executeRunWorktreeTool(s,n,{cwd:o.cwd,sessionId:o.sessionManager.getSessionId()},{...i===void 0?{}:{signal:i},onProgress:e=>a?.({content:[{type:`text`,text:e}],details:{action:s.action}})})}}}exports.RUN_WORKTREE_TOOL_NAME=t.RUN_WORKTREE_TOOL_NAME,exports.createRunWorktreeTool=n,exports.validateParams=t.validateParams;
2
+ //# sourceMappingURL=runWorktree.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runWorktree.cjs","names":["RUN_WORKTREE_TOOL_NAME","RUN_WORKTREE_DESCRIPTION","RunWorktreeParams","validateParams","executeRunWorktreeTool"],"sources":["../../src/tools/runWorktree.ts"],"sourcesContent":["import type { AgentToolResult } from '@earendil-works/pi-agent-core';\nimport type { ToolDefinition } from '@earendil-works/pi-coding-agent';\n\nimport { RunWorktreeParams, type RunWorktreeToolParams } from '../schemas/runWorktreeTool';\nimport {\n executeRunWorktreeTool,\n RUN_WORKTREE_DESCRIPTION,\n RUN_WORKTREE_TOOL_NAME,\n validateParams,\n type RunWorktreeToolDetails,\n} from '../services/runWorktree';\nimport type { WorktreeOperations } from '../services/worktreeOperations';\n\nexport { RUN_WORKTREE_TOOL_NAME, validateParams };\nexport type { RunWorktreeToolDetails };\n\n/** Creates the typed Pi worktree tool declaration. */\nexport function createRunWorktreeTool(\n operations: WorktreeOperations,\n): ToolDefinition<typeof RunWorktreeParams, RunWorktreeToolDetails> {\n const tool: ToolDefinition<typeof RunWorktreeParams, RunWorktreeToolDetails> = {\n name: RUN_WORKTREE_TOOL_NAME,\n label: 'Worktree',\n description: RUN_WORKTREE_DESCRIPTION,\n parameters: RunWorktreeParams,\n prepareArguments: validateParams,\n // The signal and the progress callback are the host's two answers to a\n // call that takes minutes. Dropping them is what let an interrupted spawn\n // run on with nobody waiting for it, and left the caller staring at\n // nothing while it did.\n execute: async (_id, rawParams, signal, onUpdate, ctx) => {\n const params = validateParams(rawParams) as RunWorktreeToolParams;\n return (await executeRunWorktreeTool(\n params,\n operations,\n {\n cwd: ctx.cwd,\n sessionId: ctx.sessionManager.getSessionId(),\n },\n {\n ...(signal === undefined ? {} : { signal }),\n onProgress: (label) =>\n onUpdate?.({ content: [{ type: 'text', text: label }], details: { action: params.action } }),\n },\n )) as AgentToolResult<RunWorktreeToolDetails>;\n },\n };\n return tool;\n}\n"],"mappings":"iGAiBA,SAAgB,EACd,EACkE,CA4BlE,MAAO,CA1BL,KAAMA,EAAAA,uBACN,MAAO,WACP,YAAaC,EAAAA,yBACb,WAAYC,EAAAA,kBACZ,iBAAkBC,EAAAA,eAKlB,QAAS,MAAO,EAAK,EAAW,EAAQ,EAAU,IAAQ,CACxD,IAAM,EAASA,EAAAA,eAAe,CAAS,EACvC,OAAQ,MAAMC,EAAAA,uBACZ,EACA,EACA,CACE,IAAK,EAAI,IACT,UAAW,EAAI,eAAe,aAAa,CAC7C,EACA,CACE,GAAI,IAAW,IAAA,GAAY,CAAC,EAAI,CAAE,QAAO,EACzC,WAAa,GACX,IAAW,CAAE,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAM,CAAM,CAAC,EAAG,QAAS,CAAE,OAAQ,EAAO,MAAO,CAAE,CAAC,CAC/F,CACF,CACF,CAEQ,CACZ"}
@@ -0,0 +1,2 @@
1
+ import{RunWorktreeParams as e}from"../schemas/runWorktreeTool.mjs";import{RUN_WORKTREE_DESCRIPTION as t,RUN_WORKTREE_TOOL_NAME as n,executeRunWorktreeTool as r,validateParams as i}from"../services/runWorktree/index.mjs";function a(a){return{name:n,label:`Worktree`,description:t,parameters:e,prepareArguments:i,execute:async(e,t,n,o,s)=>{let c=i(t);return await r(c,a,{cwd:s.cwd,sessionId:s.sessionManager.getSessionId()},{...n===void 0?{}:{signal:n},onProgress:e=>o?.({content:[{type:`text`,text:e}],details:{action:c.action}})})}}}export{n as RUN_WORKTREE_TOOL_NAME,a as createRunWorktreeTool,i as validateParams};
2
+ //# sourceMappingURL=runWorktree.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runWorktree.mjs","names":[],"sources":["../../src/tools/runWorktree.ts"],"sourcesContent":["import type { AgentToolResult } from '@earendil-works/pi-agent-core';\nimport type { ToolDefinition } from '@earendil-works/pi-coding-agent';\n\nimport { RunWorktreeParams, type RunWorktreeToolParams } from '../schemas/runWorktreeTool';\nimport {\n executeRunWorktreeTool,\n RUN_WORKTREE_DESCRIPTION,\n RUN_WORKTREE_TOOL_NAME,\n validateParams,\n type RunWorktreeToolDetails,\n} from '../services/runWorktree';\nimport type { WorktreeOperations } from '../services/worktreeOperations';\n\nexport { RUN_WORKTREE_TOOL_NAME, validateParams };\nexport type { RunWorktreeToolDetails };\n\n/** Creates the typed Pi worktree tool declaration. */\nexport function createRunWorktreeTool(\n operations: WorktreeOperations,\n): ToolDefinition<typeof RunWorktreeParams, RunWorktreeToolDetails> {\n const tool: ToolDefinition<typeof RunWorktreeParams, RunWorktreeToolDetails> = {\n name: RUN_WORKTREE_TOOL_NAME,\n label: 'Worktree',\n description: RUN_WORKTREE_DESCRIPTION,\n parameters: RunWorktreeParams,\n prepareArguments: validateParams,\n // The signal and the progress callback are the host's two answers to a\n // call that takes minutes. Dropping them is what let an interrupted spawn\n // run on with nobody waiting for it, and left the caller staring at\n // nothing while it did.\n execute: async (_id, rawParams, signal, onUpdate, ctx) => {\n const params = validateParams(rawParams) as RunWorktreeToolParams;\n return (await executeRunWorktreeTool(\n params,\n operations,\n {\n cwd: ctx.cwd,\n sessionId: ctx.sessionManager.getSessionId(),\n },\n {\n ...(signal === undefined ? {} : { signal }),\n onProgress: (label) =>\n onUpdate?.({ content: [{ type: 'text', text: label }], details: { action: params.action } }),\n },\n )) as AgentToolResult<RunWorktreeToolDetails>;\n },\n };\n return tool;\n}\n"],"mappings":"4NAiBA,SAAgB,EACd,EACkE,CA4BlE,MAAO,CA1BL,KAAM,EACN,MAAO,WACP,YAAa,EACb,WAAY,EACZ,iBAAkB,EAKlB,QAAS,MAAO,EAAK,EAAW,EAAQ,EAAU,IAAQ,CACxD,IAAM,EAAS,EAAe,CAAS,EACvC,OAAQ,MAAM,EACZ,EACA,EACA,CACE,IAAK,EAAI,IACT,UAAW,EAAI,eAAe,aAAa,CAC7C,EACA,CACE,GAAI,IAAW,IAAA,GAAY,CAAC,EAAI,CAAE,QAAO,EACzC,WAAa,GACX,IAAW,CAAE,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAM,CAAM,CAAC,EAAG,QAAS,CAAE,OAAQ,EAAO,MAAO,CAAE,CAAC,CAC/F,CACF,CACF,CAEQ,CACZ"}
@@ -1,4 +1,4 @@
1
- import { WorktreeOperations } from "../adapters/worktree/worktreeOperations.cjs";
1
+ import { WorktreeOperations } from "../services/worktreeOperations/index.cjs";
2
2
  //#region src/types/extension.d.ts
3
3
  type GitNotificationLevel = 'info';
4
4
  interface GitExtensionResult {
@@ -1,4 +1,4 @@
1
- import { WorktreeOperations } from "../adapters/worktree/worktreeOperations.mjs";
1
+ import { WorktreeOperations } from "../services/worktreeOperations/index.mjs";
2
2
  //#region src/types/extension.d.ts
3
3
  type GitNotificationLevel = 'info';
4
4
  interface GitExtensionResult {
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@agimon-ai/doompi-git",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.1-alpha.6",
4
4
  "description": "Git worktree sessions for DoomPi: spawn an isolated worktree with its own session and manage it from the parent",
5
5
  "keywords": [
6
+ "ai",
6
7
  "coding-agent",
8
+ "developer-tools",
7
9
  "doompi",
8
10
  "git-worktree",
9
11
  "pi-coding-agent",
@@ -28,7 +30,7 @@
28
30
  "dist",
29
31
  "llms.txt",
30
32
  "package.json",
31
- "src/exports/webClient.ts",
33
+ "src/extensions/web.ts",
32
34
  "src/prompts",
33
35
  "src/types/webWorktrees.ts",
34
36
  "src/types/worktreeRegistry.ts",
@@ -45,16 +47,16 @@
45
47
  "import": "./dist/index.mjs",
46
48
  "require": "./dist/index.cjs"
47
49
  },
48
- "./api/git": {
49
- "types": "./dist/hubApi.d.mts",
50
- "import": "./dist/hubApi.mjs",
51
- "require": "./dist/hubApi.cjs"
52
- },
53
50
  "./extensions/pi": {
54
51
  "types": "./dist/extensions/pi.d.mts",
55
52
  "import": "./dist/extensions/pi.mjs",
56
53
  "require": "./dist/extensions/pi.cjs"
57
54
  },
55
+ "./extensions/server": {
56
+ "types": "./dist/extensions/server.d.mts",
57
+ "import": "./dist/extensions/server.mjs",
58
+ "require": "./dist/extensions/server.cjs"
59
+ },
58
60
  "./package.json": "./package.json"
59
61
  },
60
62
  "publishConfig": {
@@ -65,9 +67,8 @@
65
67
  "@tanstack/react-store": "0.11.1",
66
68
  "@tanstack/store": "0.11.1",
67
69
  "typebox": "1.3.19",
68
- "@agimon-ai/doompi-extension-contracts": "0.0.1-alpha.67",
69
- "@agimon-ai/doompi-web-components": "0.0.1-alpha.27",
70
- "@agimon-ai/doompi-web-contracts": "0.0.1-alpha.30"
70
+ "@agimon-ai/doompi-web-components": "0.0.1-alpha.29",
71
+ "@agimon-ai/doompi-core": "0.0.1-alpha.70"
71
72
  },
72
73
  "devDependencies": {
73
74
  "@earendil-works/pi-agent-core": "0.85.1",
@@ -80,7 +81,7 @@
80
81
  "tsdown": "0.22.14",
81
82
  "typescript": "7.0.2",
82
83
  "vitest": "5.0.0",
83
- "@agimon-ai/vibe-lint-plugin-doom-extension": "0.0.1-alpha.64"
84
+ "@agimon-ai/vibe-lint-plugin-doom-extension": "0.0.1-alpha.66"
84
85
  },
85
86
  "peerDependencies": {
86
87
  "@earendil-works/pi-agent-core": "0.85.1",
@@ -97,11 +98,17 @@
97
98
  "engines": {
98
99
  "node": ">=22.19.0"
99
100
  },
100
- "doompiApi": {
101
- "basePath": "git",
102
- "hub": {
103
- "entry": "./src/exports/hubApi.ts",
104
- "dist": "./dist/hubApi.mjs"
101
+ "doompiServer": {
102
+ "entry": "./src/extensions/server.ts",
103
+ "dist": "./dist/extensions/server.mjs",
104
+ "scopes": [
105
+ "session",
106
+ "global",
107
+ "workspace"
108
+ ],
109
+ "contracts": {
110
+ "entry": "./src/exports/apiContracts.ts",
111
+ "dist": "./dist/api-contracts.mjs"
105
112
  }
106
113
  },
107
114
  "doompiWeb": {
@@ -109,11 +116,10 @@
109
116
  "channels": [
110
117
  "git_worktrees"
111
118
  ],
112
- "client": "./src/exports/webClient.ts",
113
- "hub": {
114
- "entry": "./src/exports/webHub.ts",
115
- "dist": "./dist/webHub.mjs"
116
- }
119
+ "client": "./src/extensions/web.ts",
120
+ "scopes": [
121
+ "session"
122
+ ]
117
123
  },
118
124
  "pi": {
119
125
  "extensions": [
@@ -0,0 +1,33 @@
1
+ import { defineWebPlugin } from '@agimon-ai/doompi-core/web';
2
+
3
+ import { gitToolRenderers } from '../web/components/toolRenderers';
4
+ import { WorktreesActivitySection } from '../web/components/WorktreesActivitySection';
5
+ import { worktreesTab } from '../web/components/WorktreesPanel';
6
+ import { startWorktreeRuntime, worktreeActivitySource, worktreesChannel } from '../web/stores/worktreesActivityStore';
7
+
8
+ /** The named export the generated plugin registry imports. */
9
+ export const webPlugin = defineWebPlugin({
10
+ id: 'git',
11
+ session: {
12
+ channels: [worktreesChannel],
13
+ // The panel commands the hub over its own channel, which needs the page's
14
+ // hub socket rather than the per-session frame sender the slots carry.
15
+ start: startWorktreeRuntime,
16
+ activityGroups: [
17
+ {
18
+ name: 'git',
19
+ keys: 'g w',
20
+ // The source keeps the group present while idle, which is exactly when
21
+ // its launcher matters: a repository with no worktrees is where someone
22
+ // wants to make the first one.
23
+ activeSource: worktreeActivitySource,
24
+ // A standing worktree is not background work in progress; it is state.
25
+ marksBackgroundWork: false,
26
+ transientTab: worktreesTab,
27
+ order: 30,
28
+ },
29
+ ],
30
+ activitySections: [{ id: 'git', component: WorktreesActivitySection }],
31
+ toolRenderers: gitToolRenderers,
32
+ },
33
+ });
@@ -17,12 +17,15 @@ the parent checkout and silently builds the wrong code.
17
17
 
18
18
  Use a worktree when work needs its own branch **and** its own checkout at the
19
19
  same time: a long refactor you want to leave half-finished, a risky migration,
20
- or two features that touch the same files. A worktree costs a full install in
21
- the new directory, so it is the wrong tool for a quick edit; just edit.
20
+ or two features that touch the same files.
22
21
 
23
22
  Do not reach for it to parallelise work that shares a branch. Two sessions on
24
23
  one branch in two checkouts will fight, and git refuses the second worktree.
25
24
 
25
+ The new checkout has no dependencies installed: `spawn_worktree` runs git and
26
+ nothing else, whatever language the repository is in. Install them in the
27
+ worktree before building or testing there.
28
+
26
29
  ## Actions
27
30
 
28
31
  ```
@@ -55,6 +55,15 @@ export interface WorktreeRegistryStore {
55
55
  export interface WorktreeGit {
56
56
  addWorktree(input: { repositoryRoot: string; path: string; branch: string; baseRef: string }): Promise<void>;
57
57
  removeWorktree(input: { repositoryRoot: string; path: string; force: boolean }): Promise<void>;
58
+ /**
59
+ * Safe branch delete, reporting refusal rather than throwing.
60
+ *
61
+ * `worktree remove` leaves the branch behind, so undoing a spawn needs this
62
+ * too. It is always the safe form: git refuses a branch holding unmerged
63
+ * work, and false says the branch is still there rather than pretending it
64
+ * went.
65
+ */
66
+ deleteBranch(input: { repositoryRoot: string; branch: string }): Promise<boolean>;
58
67
  pruneWorktrees(repositoryRoot: string): Promise<void>;
59
68
  /** Paths git currently lists for the repository, used to find orphans. */
60
69
  listWorktreePaths(repositoryRoot: string): Promise<string[]>;