@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
@@ -0,0 +1,2 @@
1
+ const e=require("../../_virtual/_rolldown/runtime.cjs");let t=require("node:fs");t=e.__toESM(t,1);let n=require("node:path");n=e.__toESM(n,1);const r=`node_modules`;function i(e){let i={outputs:[],modules:[]},a=(o,s)=>{let c;try{c=t.default.readdirSync(n.default.join(e,o),{withFileTypes:!0})}catch{return}for(let e of c){if(!e.isDirectory())continue;let t=o===``?e.name:`${o}/${e.name}`;if(e.name!==`.git`){if(e.name===r){i.modules.push(t);continue}if(e.name===`dist`){i.outputs.push(t);continue}s<4&&a(t,s+1)}}};return a(``,1),i}function a(e,a){if(!t.default.existsSync(n.default.join(e,r)))return{kind:`skipped`,reason:`no-modules`};let o=i(e),s=0,c=0;for(let r of o.modules){let i=n.default.join(a,r);if(!t.default.existsSync(i))try{t.default.mkdirSync(n.default.dirname(i),{recursive:!0}),t.default.symlinkSync(n.default.join(e,r),i,`dir`),c+=1}catch{}}for(let r of o.outputs){let i=n.default.join(a,r);if(!t.default.existsSync(i))try{t.default.mkdirSync(n.default.dirname(i),{recursive:!0}),t.default.cpSync(n.default.join(e,r),i,{recursive:!0}),s+=1}catch{}}return{kind:`mirrored`,copied:s,linked:c}}exports.mirrorComposition=a;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["fs","path"],"sources":["../../../src/services/compositionMirror/index.ts"],"sourcesContent":["/**\n * Giving a new worktree the build output its parent checkout already has.\n *\n * DESIGN PATTERNS:\n * - Mirrors, never builds. Everything here is a copy or a symlink of something\n * the parent checkout already produced, so it costs seconds and cannot fail\n * the way a package manager or a compiler can.\n * - `node_modules` is linked, `dist` is copied. The module tree is gigabytes\n * and read-only in practice, so a link is right; build output is small and a\n * link would send a build run inside the worktree straight into the parent's\n * directory.\n * - Absent parent output means nothing to do. A repository with no\n * `node_modules` at its root is either not a JS project or not installed, and\n * either way this has no opinion about it, so a Rust, Go or Python worktree\n * pays nothing.\n *\n * WHY THIS EXISTS:\n * A DoomPi session composes the extensions its repository's config names, and\n * this repository names its own workspace packages by relative path. Those\n * packages declare `pi.extensions` under `dist/`, which git does not track, so\n * a fresh worktree resolves none of them and the session dies on start. The\n * parent checkout has already built exactly what the child needs.\n *\n * AVOID:\n * - Recursing into `node_modules`. The scan is bounded and skips it; without\n * that this walks a gigabyte to find nothing.\n * - Treating a mirror failure as fatal. The worktree is good either way; only\n * the session's composition is poorer for it.\n */\nimport fs from 'node:fs';\nimport path from 'node:path';\n\n/** Directories that are build output worth copying into a new worktree. */\nconst OUTPUT_DIRECTORY = 'dist';\nconst MODULES_DIRECTORY = 'node_modules';\nconst GIT_DIRECTORY = '.git';\n/**\n * How deep the scan goes.\n *\n * Four levels reaches `layers/<group>/<package>/dist` in this repository's\n * layout, and a workspace that buries a package deeper than that gets a\n * partial mirror rather than a slow one.\n */\nconst MAX_DEPTH = 4;\n\nexport type MirrorOutcome =\n | { kind: 'skipped'; reason: 'no-modules' }\n | { kind: 'mirrored'; copied: number; linked: number };\n\ninterface Found {\n /** Paths relative to the source root. */\n outputs: string[];\n modules: string[];\n}\n\nfunction scan(root: string): Found {\n const found: Found = { outputs: [], modules: [] };\n const walk = (relative: string, depth: number): void => {\n let entries: fs.Dirent[];\n try {\n entries = fs.readdirSync(path.join(root, relative), { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n const child = relative === '' ? entry.name : `${relative}/${entry.name}`;\n if (entry.name === GIT_DIRECTORY) continue;\n // Both of these are destinations, not places to look inside.\n if (entry.name === MODULES_DIRECTORY) {\n found.modules.push(child);\n continue;\n }\n if (entry.name === OUTPUT_DIRECTORY) {\n found.outputs.push(child);\n continue;\n }\n if (depth < MAX_DEPTH) walk(child, depth + 1);\n }\n };\n walk('', 1);\n return found;\n}\n\n/**\n * Copies the parent's build output into a worktree and links its modules.\n *\n * Individual failures are counted out rather than thrown: a mirror that lands\n * partly is still better than none, and the caller has a worktree either way.\n */\nexport function mirrorComposition(source: string, target: string): MirrorOutcome {\n if (!fs.existsSync(path.join(source, MODULES_DIRECTORY))) return { kind: 'skipped', reason: 'no-modules' };\n\n const found = scan(source);\n let copied = 0;\n let linked = 0;\n\n for (const relative of found.modules) {\n const destination = path.join(target, relative);\n if (fs.existsSync(destination)) continue;\n try {\n fs.mkdirSync(path.dirname(destination), { recursive: true });\n fs.symlinkSync(path.join(source, relative), destination, 'dir');\n linked += 1;\n } catch {\n // A link the filesystem refuses costs this package one resolution, not\n // the worktree.\n }\n }\n\n for (const relative of found.outputs) {\n const destination = path.join(target, relative);\n if (fs.existsSync(destination)) continue;\n try {\n fs.mkdirSync(path.dirname(destination), { recursive: true });\n fs.cpSync(path.join(source, relative), destination, { recursive: true });\n copied += 1;\n } catch {\n // Same reasoning as a failed link.\n }\n }\n\n return { kind: 'mirrored', copied, linked };\n}\n"],"mappings":"8IAiCA,MACM,EAAoB,eAqB1B,SAAS,EAAK,EAAqB,CACjC,IAAM,EAAe,CAAE,QAAS,CAAC,EAAG,QAAS,CAAC,CAAE,EAC1C,GAAQ,EAAkB,IAAwB,CACtD,IAAI,EACJ,GAAI,CACF,EAAUA,EAAAA,QAAG,YAAYC,EAAAA,QAAK,KAAK,EAAM,CAAQ,EAAG,CAAE,cAAe,EAAK,CAAC,CAC7E,MAAQ,CACN,MACF,CACA,IAAK,IAAM,KAAS,EAAS,CAC3B,GAAI,CAAC,EAAM,YAAY,EAAG,SAC1B,IAAM,EAAQ,IAAa,GAAK,EAAM,KAAO,GAAG,EAAS,GAAG,EAAM,OAC9D,KAAM,OAAS,OAEnB,IAAI,EAAM,OAAS,EAAmB,CACpC,EAAM,QAAQ,KAAK,CAAK,EACxB,QACF,CACA,GAAI,EAAM,OAAS,OAAkB,CACnC,EAAM,QAAQ,KAAK,CAAK,EACxB,QACF,CACI,EAAQ,GAAW,EAAK,EAAO,EAAQ,CAAC,CAL5C,CAMF,CACF,EAEA,OADA,EAAK,GAAI,CAAC,EACH,CACT,CAQA,SAAgB,EAAkB,EAAgB,EAA+B,CAC/E,GAAI,CAACD,EAAAA,QAAG,WAAWC,EAAAA,QAAK,KAAK,EAAQ,CAAiB,CAAC,EAAG,MAAO,CAAE,KAAM,UAAW,OAAQ,YAAa,EAEzG,IAAM,EAAQ,EAAK,CAAM,EACrB,EAAS,EACT,EAAS,EAEb,IAAK,IAAM,KAAY,EAAM,QAAS,CACpC,IAAM,EAAcA,EAAAA,QAAK,KAAK,EAAQ,CAAQ,EAC1CD,MAAAA,QAAG,WAAW,CAAW,EAC7B,GAAI,CACF,EAAA,QAAG,UAAUC,EAAAA,QAAK,QAAQ,CAAW,EAAG,CAAE,UAAW,EAAK,CAAC,EAC3D,EAAA,QAAG,YAAYA,EAAAA,QAAK,KAAK,EAAQ,CAAQ,EAAG,EAAa,KAAK,EAC9D,GAAU,CACZ,MAAQ,CAGR,CACF,CAEA,IAAK,IAAM,KAAY,EAAM,QAAS,CACpC,IAAM,EAAcA,EAAAA,QAAK,KAAK,EAAQ,CAAQ,EAC1CD,MAAAA,QAAG,WAAW,CAAW,EAC7B,GAAI,CACF,EAAA,QAAG,UAAUC,EAAAA,QAAK,QAAQ,CAAW,EAAG,CAAE,UAAW,EAAK,CAAC,EAC3D,EAAA,QAAG,OAAOA,EAAAA,QAAK,KAAK,EAAQ,CAAQ,EAAG,EAAa,CAAE,UAAW,EAAK,CAAC,EACvE,GAAU,CACZ,MAAQ,CAER,CACF,CAEA,MAAO,CAAE,KAAM,WAAY,SAAQ,QAAO,CAC5C"}
@@ -0,0 +1,2 @@
1
+ import e from"node:fs";import t from"node:path";const n=`node_modules`;function r(r){let i={outputs:[],modules:[]},a=(o,s)=>{let c;try{c=e.readdirSync(t.join(r,o),{withFileTypes:!0})}catch{return}for(let e of c){if(!e.isDirectory())continue;let t=o===``?e.name:`${o}/${e.name}`;if(e.name!==`.git`){if(e.name===n){i.modules.push(t);continue}if(e.name===`dist`){i.outputs.push(t);continue}s<4&&a(t,s+1)}}};return a(``,1),i}function i(i,a){if(!e.existsSync(t.join(i,n)))return{kind:`skipped`,reason:`no-modules`};let o=r(i),s=0,c=0;for(let n of o.modules){let r=t.join(a,n);if(!e.existsSync(r))try{e.mkdirSync(t.dirname(r),{recursive:!0}),e.symlinkSync(t.join(i,n),r,`dir`),c+=1}catch{}}for(let n of o.outputs){let r=t.join(a,n);if(!e.existsSync(r))try{e.mkdirSync(t.dirname(r),{recursive:!0}),e.cpSync(t.join(i,n),r,{recursive:!0}),s+=1}catch{}}return{kind:`mirrored`,copied:s,linked:c}}export{i as mirrorComposition};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/compositionMirror/index.ts"],"sourcesContent":["/**\n * Giving a new worktree the build output its parent checkout already has.\n *\n * DESIGN PATTERNS:\n * - Mirrors, never builds. Everything here is a copy or a symlink of something\n * the parent checkout already produced, so it costs seconds and cannot fail\n * the way a package manager or a compiler can.\n * - `node_modules` is linked, `dist` is copied. The module tree is gigabytes\n * and read-only in practice, so a link is right; build output is small and a\n * link would send a build run inside the worktree straight into the parent's\n * directory.\n * - Absent parent output means nothing to do. A repository with no\n * `node_modules` at its root is either not a JS project or not installed, and\n * either way this has no opinion about it, so a Rust, Go or Python worktree\n * pays nothing.\n *\n * WHY THIS EXISTS:\n * A DoomPi session composes the extensions its repository's config names, and\n * this repository names its own workspace packages by relative path. Those\n * packages declare `pi.extensions` under `dist/`, which git does not track, so\n * a fresh worktree resolves none of them and the session dies on start. The\n * parent checkout has already built exactly what the child needs.\n *\n * AVOID:\n * - Recursing into `node_modules`. The scan is bounded and skips it; without\n * that this walks a gigabyte to find nothing.\n * - Treating a mirror failure as fatal. The worktree is good either way; only\n * the session's composition is poorer for it.\n */\nimport fs from 'node:fs';\nimport path from 'node:path';\n\n/** Directories that are build output worth copying into a new worktree. */\nconst OUTPUT_DIRECTORY = 'dist';\nconst MODULES_DIRECTORY = 'node_modules';\nconst GIT_DIRECTORY = '.git';\n/**\n * How deep the scan goes.\n *\n * Four levels reaches `layers/<group>/<package>/dist` in this repository's\n * layout, and a workspace that buries a package deeper than that gets a\n * partial mirror rather than a slow one.\n */\nconst MAX_DEPTH = 4;\n\nexport type MirrorOutcome =\n | { kind: 'skipped'; reason: 'no-modules' }\n | { kind: 'mirrored'; copied: number; linked: number };\n\ninterface Found {\n /** Paths relative to the source root. */\n outputs: string[];\n modules: string[];\n}\n\nfunction scan(root: string): Found {\n const found: Found = { outputs: [], modules: [] };\n const walk = (relative: string, depth: number): void => {\n let entries: fs.Dirent[];\n try {\n entries = fs.readdirSync(path.join(root, relative), { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries) {\n if (!entry.isDirectory()) continue;\n const child = relative === '' ? entry.name : `${relative}/${entry.name}`;\n if (entry.name === GIT_DIRECTORY) continue;\n // Both of these are destinations, not places to look inside.\n if (entry.name === MODULES_DIRECTORY) {\n found.modules.push(child);\n continue;\n }\n if (entry.name === OUTPUT_DIRECTORY) {\n found.outputs.push(child);\n continue;\n }\n if (depth < MAX_DEPTH) walk(child, depth + 1);\n }\n };\n walk('', 1);\n return found;\n}\n\n/**\n * Copies the parent's build output into a worktree and links its modules.\n *\n * Individual failures are counted out rather than thrown: a mirror that lands\n * partly is still better than none, and the caller has a worktree either way.\n */\nexport function mirrorComposition(source: string, target: string): MirrorOutcome {\n if (!fs.existsSync(path.join(source, MODULES_DIRECTORY))) return { kind: 'skipped', reason: 'no-modules' };\n\n const found = scan(source);\n let copied = 0;\n let linked = 0;\n\n for (const relative of found.modules) {\n const destination = path.join(target, relative);\n if (fs.existsSync(destination)) continue;\n try {\n fs.mkdirSync(path.dirname(destination), { recursive: true });\n fs.symlinkSync(path.join(source, relative), destination, 'dir');\n linked += 1;\n } catch {\n // A link the filesystem refuses costs this package one resolution, not\n // the worktree.\n }\n }\n\n for (const relative of found.outputs) {\n const destination = path.join(target, relative);\n if (fs.existsSync(destination)) continue;\n try {\n fs.mkdirSync(path.dirname(destination), { recursive: true });\n fs.cpSync(path.join(source, relative), destination, { recursive: true });\n copied += 1;\n } catch {\n // Same reasoning as a failed link.\n }\n }\n\n return { kind: 'mirrored', copied, linked };\n}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,CAAQ,EAC1C,MAAG,WAAW,CAAW,EAC7B,GAAI,CACF,EAAG,UAAU,EAAK,QAAQ,CAAW,EAAG,CAAE,UAAW,EAAK,CAAC,EAC3D,EAAG,OAAO,EAAK,KAAK,EAAQ,CAAQ,EAAG,EAAa,CAAE,UAAW,EAAK,CAAC,EACvE,GAAU,CACZ,MAAQ,CAER,CACF,CAEA,MAAO,CAAE,KAAM,WAAY,SAAQ,QAAO,CAC5C"}
@@ -0,0 +1,2 @@
1
+ var e=class extends Error{code;retryable;recovery;constructor(e,t,n,r){super(`[${e}] ${t}\nRecovery: ${r}`),this.code=e,this.retryable=n,this.recovery=r,this.name=`DoomGitExpectedError`}},t=class extends Error{constructor(e){super(e),this.name=`HubUnavailableError`}};function n(t,n){return new e(`invalid_request`,t,!1,n)}exports.DoomGitExpectedError=e,exports.HubUnavailableError=t,exports.invalidRequest=n;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../src/services/errors/index.ts"],"sourcesContent":["/**\n * Expected failures, kept private to this package.\n *\n * `@agimon-ai/doompi-core` does not export `invalidRequest` or\n * an expected-error base, so this mirrors doompi-team's shape rather than\n * reaching across a layer boundary for it. The duplication is deliberate and\n * small; a shared helper would be the better answer only once a third package\n * needs one.\n */\n\nexport type DoomGitErrorCode =\n | 'invalid_request'\n | 'not_a_repository'\n | 'worktree_exists'\n | 'worktree_not_found'\n | 'worktree_not_owned'\n | 'worktree_peer_unavailable'\n | 'worktree_dirty'\n | 'hub_unavailable'\n | 'spawn_cancelled'\n | 'registry_write_failed'\n | 'message_too_large'\n | 'git_failed';\n\nexport class DoomGitExpectedError extends Error {\n constructor(\n readonly code: DoomGitErrorCode,\n message: string,\n readonly retryable: boolean,\n readonly recovery: string,\n ) {\n // The recovery line rides in the message because a tool result is read as\n // text: an error the model cannot act on costs a turn to rediscover.\n super(`[${code}] ${message}\\nRecovery: ${recovery}`);\n this.name = 'DoomGitExpectedError';\n }\n}\n\n/** Raised when a worktree action needs the canonical hub but it is not injected. */\nexport class HubUnavailableError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'HubUnavailableError';\n }\n}\n\nexport function invalidRequest(message: string, recovery: string): DoomGitExpectedError {\n return new DoomGitExpectedError('invalid_request', message, false, recovery);\n}\n"],"mappings":"AAwBA,IAAa,EAAb,cAA0C,KAAM,CAEnC,KAEA,UACA,SAJX,YACE,EACA,EACA,EACA,EACA,CAGA,MAAM,IAAI,EAAK,IAAI,EAAQ,cAAc,GAAU,EAP1C,KAAA,KAAA,EAEA,KAAA,UAAA,EACA,KAAA,SAAA,EAKT,KAAK,KAAO,sBACd,CACF,EAGa,EAAb,cAAyC,KAAM,CAC7C,YAAY,EAAiB,CAC3B,MAAM,CAAO,EACb,KAAK,KAAO,qBACd,CACF,EAEA,SAAgB,EAAe,EAAiB,EAAwC,CACtF,OAAO,IAAI,EAAqB,kBAAmB,EAAS,GAAO,CAAQ,CAC7E"}
@@ -0,0 +1,2 @@
1
+ var e=class extends Error{code;retryable;recovery;constructor(e,t,n,r){super(`[${e}] ${t}\nRecovery: ${r}`),this.code=e,this.retryable=n,this.recovery=r,this.name=`DoomGitExpectedError`}},t=class extends Error{constructor(e){super(e),this.name=`HubUnavailableError`}};function n(t,n){return new e(`invalid_request`,t,!1,n)}export{e as DoomGitExpectedError,t as HubUnavailableError,n as invalidRequest};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/errors/index.ts"],"sourcesContent":["/**\n * Expected failures, kept private to this package.\n *\n * `@agimon-ai/doompi-core` does not export `invalidRequest` or\n * an expected-error base, so this mirrors doompi-team's shape rather than\n * reaching across a layer boundary for it. The duplication is deliberate and\n * small; a shared helper would be the better answer only once a third package\n * needs one.\n */\n\nexport type DoomGitErrorCode =\n | 'invalid_request'\n | 'not_a_repository'\n | 'worktree_exists'\n | 'worktree_not_found'\n | 'worktree_not_owned'\n | 'worktree_peer_unavailable'\n | 'worktree_dirty'\n | 'hub_unavailable'\n | 'spawn_cancelled'\n | 'registry_write_failed'\n | 'message_too_large'\n | 'git_failed';\n\nexport class DoomGitExpectedError extends Error {\n constructor(\n readonly code: DoomGitErrorCode,\n message: string,\n readonly retryable: boolean,\n readonly recovery: string,\n ) {\n // The recovery line rides in the message because a tool result is read as\n // text: an error the model cannot act on costs a turn to rediscover.\n super(`[${code}] ${message}\\nRecovery: ${recovery}`);\n this.name = 'DoomGitExpectedError';\n }\n}\n\n/** Raised when a worktree action needs the canonical hub but it is not injected. */\nexport class HubUnavailableError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'HubUnavailableError';\n }\n}\n\nexport function invalidRequest(message: string, recovery: string): DoomGitExpectedError {\n return new DoomGitExpectedError('invalid_request', message, false, recovery);\n}\n"],"mappings":"AAwBA,IAAa,EAAb,cAA0C,KAAM,CAEnC,KAEA,UACA,SAJX,YACE,EACA,EACA,EACA,EACA,CAGA,MAAM,IAAI,EAAK,IAAI,EAAQ,cAAc,GAAU,EAP1C,KAAA,KAAA,EAEA,KAAA,UAAA,EACA,KAAA,SAAA,EAKT,KAAK,KAAO,sBACd,CACF,EAGa,EAAb,cAAyC,KAAM,CAC7C,YAAY,EAAiB,CAC3B,MAAM,CAAO,EACb,KAAK,KAAO,qBACd,CACF,EAEA,SAAgB,EAAe,EAAiB,EAAwC,CACtF,OAAO,IAAI,EAAqB,kBAAmB,EAAS,GAAO,CAAQ,CAC7E"}
@@ -1,2 +1,2 @@
1
1
  var e=class{async execute(){return{message:`Show git worktrees owned by this session`,level:`info`}}};exports.DefaultGitExtensionService=e;
2
- //# sourceMappingURL=extensionService.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../src/services/extensionService/index.ts"],"sourcesContent":["// @scaffold-generated\nimport type { GitExtensionResult, GitExtensionService } from '../../types/extension';\n\nexport class DefaultGitExtensionService implements GitExtensionService {\n async execute(): Promise<GitExtensionResult> {\n return { message: 'Show git worktrees owned by this session', level: 'info' };\n }\n}\n"],"mappings":"AAGA,IAAa,EAAb,KAAuE,CACrE,MAAM,SAAuC,CAC3C,MAAO,CAAE,QAAS,2CAA4C,MAAO,MAAO,CAC9E,CACF"}
@@ -0,0 +1,8 @@
1
+ import { GitExtensionResult, GitExtensionService } from "../../types/extension.cjs";
2
+ //#region src/services/extensionService/index.d.ts
3
+ declare class DefaultGitExtensionService implements GitExtensionService {
4
+ execute(): Promise<GitExtensionResult>;
5
+ }
6
+ //#endregion
7
+ export { DefaultGitExtensionService };
8
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/services/extensionService/index.ts"],"mappings":";;cAGa,sCAAsC;EAC3C,WAAW,QAAQ"}
@@ -0,0 +1,8 @@
1
+ import { GitExtensionResult, GitExtensionService } from "../../types/extension.mjs";
2
+ //#region src/services/extensionService/index.d.ts
3
+ declare class DefaultGitExtensionService implements GitExtensionService {
4
+ execute(): Promise<GitExtensionResult>;
5
+ }
6
+ //#endregion
7
+ export { DefaultGitExtensionService };
8
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/extensionService/index.ts"],"mappings":";;cAGa,sCAAsC;EAC3C,WAAW,QAAQ"}
@@ -1,2 +1,2 @@
1
1
  var e=class{async execute(){return{message:`Show git worktrees owned by this session`,level:`info`}}};export{e as DefaultGitExtensionService};
2
- //# sourceMappingURL=extensionService.mjs.map
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/extensionService/index.ts"],"sourcesContent":["// @scaffold-generated\nimport type { GitExtensionResult, GitExtensionService } from '../../types/extension';\n\nexport class DefaultGitExtensionService implements GitExtensionService {\n async execute(): Promise<GitExtensionResult> {\n return { message: 'Show git worktrees owned by this session', level: 'info' };\n }\n}\n"],"mappings":"AAGA,IAAa,EAAb,KAAuE,CACrE,MAAM,SAAuC,CAC3C,MAAO,CAAE,QAAS,2CAA4C,MAAO,MAAO,CAC9E,CACF"}
@@ -1,4 +1,4 @@
1
- const e=require("../../_virtual/_rolldown/runtime.cjs");let t=require("node:child_process"),n=require("node:fs");n=e.__toESM(n,1);const r=3e4;function i(e,n,r){return new Promise(i=>{(0,t.execFile)(`git`,[...n],{cwd:e,timeout:r,maxBuffer:1e6,env:{...process.env,LC_ALL:`C`}},(e,t,n)=>{i({code:e&&typeof e.code==`number`?e.code:+!!e,stdout:String(t),stderr:String(n)})})})}function a(e,t){return Error(`git ${e} failed (exit ${String(t.code)}, ${String(t.stderr.length)} bytes of stderr)`)}function o(e){let t=e.toLowerCase();return t.includes(`is not a working tree`)||t.includes(`cannot remove working tree`)}function s(){let e=async e=>{await i(e,[`worktree`,`prune`],15e3)};return{async addWorktree({repositoryRoot:e,path:t,branch:n,baseRef:r}){let o=await i(e,[`worktree`,`add`,`-b`,n,t,r],3e5);if(o.code!==0)throw a(`worktree add`,o)},async removeWorktree({repositoryRoot:t,path:r,force:s}){let c=await i(t,[`worktree`,`remove`,...s?[`--force`]:[],r],3e5);if(c.code!==0){if(o(c.stderr)&&!n.default.existsSync(r)){await e(t);return}throw a(`worktree remove`,c)}},pruneWorktrees:e,async listWorktreePaths(e){let t=await i(e,[`worktree`,`list`,`--porcelain`],r);return t.code===0?t.stdout.split(`
1
+ const e=require("../../_virtual/_rolldown/runtime.cjs");let t=require("node:child_process"),n=require("node:fs");n=e.__toESM(n,1);const r=3e4;function i(e,n,r){return new Promise(i=>{(0,t.execFile)(`git`,[...n],{cwd:e,timeout:r,maxBuffer:1e6,env:{...process.env,LC_ALL:`C`}},(e,t,n)=>{i({code:e&&typeof e.code==`number`?e.code:+!!e,stdout:String(t),stderr:String(n)})})})}function a(e,t){return Error(`git ${e} failed (exit ${String(t.code)}, ${String(t.stderr.length)} bytes of stderr)`)}function o(e){let t=e.toLowerCase();return t.includes(`is not a working tree`)||t.includes(`cannot remove working tree`)}function s(){let e=async e=>{await i(e,[`worktree`,`prune`],15e3)};return{async addWorktree({repositoryRoot:e,path:t,branch:n,baseRef:r}){let o=await i(e,[`worktree`,`add`,`-b`,n,t,r],3e5);if(o.code!==0)throw a(`worktree add`,o)},async removeWorktree({repositoryRoot:t,path:r,force:s}){let c=await i(t,[`worktree`,`remove`,...s?[`--force`]:[],r],3e5);if(c.code!==0){if(o(c.stderr)&&!n.default.existsSync(r)){await e(t);return}throw a(`worktree remove`,c)}},async deleteBranch({repositoryRoot:e,branch:t}){return(await i(e,[`branch`,`-d`,t],r)).code===0},pruneWorktrees:e,async listWorktreePaths(e){let t=await i(e,[`worktree`,`list`,`--porcelain`],r);return t.code===0?t.stdout.split(`
2
2
  `).filter(e=>e.startsWith(`worktree `)).map(e=>e.slice(9).trim()).filter(e=>e!==``):[]},async dirtyFiles(e){let t=await i(e,[`status`,`--porcelain`],r);return t.code===0?t.stdout.split(`
3
3
  `).map(e=>e.slice(3).trim()).filter(e=>e!==``):[]},async repositoryRoot(e){let t=await i(e,[`rev-parse`,`--show-toplevel`],r);if(t.code!==0)return;let n=t.stdout.trim();return n===``?void 0:n},async currentBranch(e){let t=await i(e,[`rev-parse`,`--abbrev-ref`,`HEAD`],r);if(t.code!==0)return;let n=t.stdout.trim();return n===``?void 0:n},async mergeBranch({repositoryRoot:e,branch:t,message:n}){let o=await i(e,[`merge`,`--no-ff`,...n===void 0?[]:[`-m`,n],t],r);if(o.code!==0)throw a(`merge`,o)}}}exports.createWorktreeGit=s;
4
- //# sourceMappingURL=gitCli.cjs.map
4
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["fs"],"sources":["../../../src/services/gitCli/index.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport fs from 'node:fs';\n\nimport type { WorktreeGit } from '../../types/worktreeRegistry';\n\n/**\n * Git, as this package needs it.\n *\n * The timeouts are not uniform because the operations are not comparable. A\n * read answers in milliseconds; `worktree add` copies an entire checkout and\n * `worktree remove` deletes one, both bounded by the filesystem rather than by\n * git, and both minutes rather than seconds on a large repository or on\n * Windows. A single timeout would either fail honest work or hang on a wedged\n * one.\n */\nconst READ_TIMEOUT_MS = 30_000;\nconst ADD_TIMEOUT_MS = 300_000;\nconst REMOVE_TIMEOUT_MS = 300_000;\nconst PRUNE_TIMEOUT_MS = 15_000;\nconst MAX_OUTPUT_BYTES = 1_000_000;\n\ninterface GitResult {\n code: number;\n stdout: string;\n stderr: string;\n}\n\n/**\n * Runs git and reports the outcome without ever throwing on a non-zero exit.\n *\n * LC_ALL is pinned because two callers below decide what to do by matching\n * git's own wording, and a translated message would silently turn a recognised\n * condition into an unrecognised failure.\n */\nfunction git(cwd: string, args: readonly string[], timeout: number): Promise<GitResult> {\n return new Promise((resolve) => {\n execFile(\n 'git',\n [...args],\n { cwd, timeout, maxBuffer: MAX_OUTPUT_BYTES, env: { ...process.env, LC_ALL: 'C' } },\n (error, stdout, stderr) => {\n const code = error && typeof error.code === 'number' ? error.code : error ? 1 : 0;\n resolve({ code, stdout: String(stdout), stderr: String(stderr) });\n },\n );\n });\n}\n\n/**\n * The message a failed git call is allowed to surface.\n *\n * Raw stderr never travels: it can carry a remote URL with a token in it, and\n * this text ends up in a tool result the model reads and may repeat.\n */\nfunction failure(operation: string, result: GitResult): Error {\n return new Error(\n `git ${operation} failed (exit ${String(result.code)}, ${String(result.stderr.length)} bytes of stderr)`,\n );\n}\n\n/** Git's own words for \"that worktree is not there any more\". */\nfunction missingWorktree(stderr: string): boolean {\n const normalized = stderr.toLowerCase();\n return normalized.includes('is not a working tree') || normalized.includes('cannot remove working tree');\n}\n\nexport function createWorktreeGit(): WorktreeGit {\n const prune = async (repositoryRoot: string): Promise<void> => {\n await git(repositoryRoot, ['worktree', 'prune'], PRUNE_TIMEOUT_MS);\n };\n\n return {\n async addWorktree({ repositoryRoot, path, branch, baseRef }) {\n const result = await git(repositoryRoot, ['worktree', 'add', '-b', branch, path, baseRef], ADD_TIMEOUT_MS);\n if (result.code !== 0) throw failure('worktree add', result);\n },\n\n async removeWorktree({ repositoryRoot, path, force }) {\n const args = ['worktree', 'remove', ...(force ? ['--force'] : []), path];\n const result = await git(repositoryRoot, args, REMOVE_TIMEOUT_MS);\n if (result.code === 0) return;\n // A directory deleted behind git's back leaves an administrative entry\n // that makes a later `worktree add` at the same path refuse. Treating\n // \"already gone\" as success and pruning is what keeps that path reusable,\n // and it makes remove idempotent for a caller retrying after a crash.\n if (missingWorktree(result.stderr) && !fs.existsSync(path)) {\n await prune(repositoryRoot);\n return;\n }\n throw failure('worktree remove', result);\n },\n\n async deleteBranch({ repositoryRoot, branch }) {\n // -d, never -D: git refuses a branch that still holds unmerged commits,\n // and that refusal is the whole safety property. A rollback that could\n // throw away work someone committed in the worktree is worse than a\n // branch left behind.\n const result = await git(repositoryRoot, ['branch', '-d', branch], READ_TIMEOUT_MS);\n return result.code === 0;\n },\n pruneWorktrees: prune,\n\n async listWorktreePaths(repositoryRoot) {\n const result = await git(repositoryRoot, ['worktree', 'list', '--porcelain'], READ_TIMEOUT_MS);\n if (result.code !== 0) return [];\n return result.stdout\n .split('\\n')\n .filter((line) => line.startsWith('worktree '))\n .map((line) => line.slice('worktree '.length).trim())\n .filter((line) => line !== '');\n },\n\n async dirtyFiles(path) {\n const result = await git(path, ['status', '--porcelain'], READ_TIMEOUT_MS);\n if (result.code !== 0) return [];\n return result.stdout\n .split('\\n')\n .map((line) => line.slice(3).trim())\n .filter((line) => line !== '');\n },\n\n async repositoryRoot(cwd) {\n const result = await git(cwd, ['rev-parse', '--show-toplevel'], READ_TIMEOUT_MS);\n if (result.code !== 0) return undefined;\n const root = result.stdout.trim();\n return root === '' ? undefined : root;\n },\n\n async currentBranch(cwd) {\n const result = await git(cwd, ['rev-parse', '--abbrev-ref', 'HEAD'], READ_TIMEOUT_MS);\n if (result.code !== 0) return undefined;\n const branch = result.stdout.trim();\n return branch === '' ? undefined : branch;\n },\n\n async mergeBranch({ repositoryRoot, branch, message }) {\n // --no-ff so the worktree's work stays identifiable as a unit after the\n // fact. A fast-forward would erase the fact that it was ever separate,\n // which is the one thing worth keeping about a worktree.\n const args = ['merge', '--no-ff', ...(message === undefined ? [] : ['-m', message]), branch];\n const result = await git(repositoryRoot, args, READ_TIMEOUT_MS);\n if (result.code === 0) return;\n // A conflicted merge leaves the parent mid-merge, which is a state the\n // person has to resolve; aborting for them would throw away the conflict\n // markers they need to see.\n throw failure('merge', result);\n },\n };\n}\n"],"mappings":"kIAeA,MAAM,EAAkB,IAmBxB,SAAS,EAAI,EAAa,EAAyB,EAAqC,CACtF,OAAO,IAAI,QAAS,GAAY,EAC9B,EAAA,EAAA,SAAA,CACE,MACA,CAAC,GAAG,CAAI,EACR,CAAE,MAAK,UAAS,UAAW,IAAkB,IAAK,CAAE,GAAG,QAAQ,IAAK,OAAQ,GAAI,CAAE,GACjF,EAAO,EAAQ,IAAW,CAEzB,EAAQ,CAAE,KADG,GAAS,OAAO,EAAM,MAAS,SAAW,EAAM,KAAO,KACpD,OAAQ,OAAO,CAAM,EAAG,OAAQ,OAAO,CAAM,CAAE,CAAC,CAClE,CACF,CACF,CAAC,CACH,CAQA,SAAS,EAAQ,EAAmB,EAA0B,CAC5D,OAAW,MACT,OAAO,EAAU,gBAAgB,OAAO,EAAO,IAAI,EAAE,IAAI,OAAO,EAAO,OAAO,MAAM,EAAE,kBACxF,CACF,CAGA,SAAS,EAAgB,EAAyB,CAChD,IAAM,EAAa,EAAO,YAAY,EACtC,OAAO,EAAW,SAAS,uBAAuB,GAAK,EAAW,SAAS,4BAA4B,CACzG,CAEA,SAAgB,GAAiC,CAC/C,IAAM,EAAQ,KAAO,IAA0C,CAC7D,MAAM,EAAI,EAAgB,CAAC,WAAY,OAAO,EAAG,IAAgB,CACnE,EAEA,MAAO,CACL,MAAM,YAAY,CAAE,iB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EAAE,EAJD,CAAC,CAKjC,EAEA,MAAM,eAAe,EAAK,CACxB,IAAM,EAAS,MAAM,EAAI,EAAK,CAAC,YAAa,iBAAiB,EAAG,CAAe,EAC/E,GAAI,EAAO,OAAS,EAAG,OACvB,IAAM,EAAO,EAAO,OAAO,KAAK,EAChC,OAAO,IAAS,GAAK,IAAA,GAAY,CACnC,EAEA,MAAM,cAAc,EAAK,CACvB,IAAM,EAAS,MAAM,EAAI,EAAK,CAAC,YAAa,eAAgB,MAAM,EAAG,CAAe,EACpF,GAAI,EAAO,OAAS,EAAG,OACvB,IAAM,EAAS,EAAO,OAAO,KAAK,EAClC,OAAO,IAAW,GAAK,IAAA,GAAY,CACrC,EAEA,MAAM,YAAY,CAAE,iBAAgB,SAAQ,WAAW,CAKrD,IAAM,EAAS,MAAM,EAAI,EAAgB,CAD3B,QAAS,UAAW,GAAI,IAAY,IAAA,GAAY,CAAC,EAAI,CAAC,KAAM,CAAO,EAAI,CACzC,EAAG,CAAe,EAC1D,KAAO,OAAS,EAIpB,MAAM,EAAQ,QAAS,CAAM,CAC/B,CACF,CACF"}
@@ -1,4 +1,4 @@
1
- import{execFile as e}from"node:child_process";import t from"node:fs";const n=3e4;function r(t,n,r){return new Promise(i=>{e(`git`,[...n],{cwd:t,timeout:r,maxBuffer:1e6,env:{...process.env,LC_ALL:`C`}},(e,t,n)=>{i({code:e&&typeof e.code==`number`?e.code:+!!e,stdout:String(t),stderr:String(n)})})})}function i(e,t){return Error(`git ${e} failed (exit ${String(t.code)}, ${String(t.stderr.length)} bytes of stderr)`)}function a(e){let t=e.toLowerCase();return t.includes(`is not a working tree`)||t.includes(`cannot remove working tree`)}function o(){let e=async e=>{await r(e,[`worktree`,`prune`],15e3)};return{async addWorktree({repositoryRoot:e,path:t,branch:n,baseRef:a}){let o=await r(e,[`worktree`,`add`,`-b`,n,t,a],3e5);if(o.code!==0)throw i(`worktree add`,o)},async removeWorktree({repositoryRoot:n,path:o,force:s}){let c=await r(n,[`worktree`,`remove`,...s?[`--force`]:[],o],3e5);if(c.code!==0){if(a(c.stderr)&&!t.existsSync(o)){await e(n);return}throw i(`worktree remove`,c)}},pruneWorktrees:e,async listWorktreePaths(e){let t=await r(e,[`worktree`,`list`,`--porcelain`],n);return t.code===0?t.stdout.split(`
1
+ import{execFile as e}from"node:child_process";import t from"node:fs";const n=3e4;function r(t,n,r){return new Promise(i=>{e(`git`,[...n],{cwd:t,timeout:r,maxBuffer:1e6,env:{...process.env,LC_ALL:`C`}},(e,t,n)=>{i({code:e&&typeof e.code==`number`?e.code:+!!e,stdout:String(t),stderr:String(n)})})})}function i(e,t){return Error(`git ${e} failed (exit ${String(t.code)}, ${String(t.stderr.length)} bytes of stderr)`)}function a(e){let t=e.toLowerCase();return t.includes(`is not a working tree`)||t.includes(`cannot remove working tree`)}function o(){let e=async e=>{await r(e,[`worktree`,`prune`],15e3)};return{async addWorktree({repositoryRoot:e,path:t,branch:n,baseRef:a}){let o=await r(e,[`worktree`,`add`,`-b`,n,t,a],3e5);if(o.code!==0)throw i(`worktree add`,o)},async removeWorktree({repositoryRoot:n,path:o,force:s}){let c=await r(n,[`worktree`,`remove`,...s?[`--force`]:[],o],3e5);if(c.code!==0){if(a(c.stderr)&&!t.existsSync(o)){await e(n);return}throw i(`worktree remove`,c)}},async deleteBranch({repositoryRoot:e,branch:t}){return(await r(e,[`branch`,`-d`,t],n)).code===0},pruneWorktrees:e,async listWorktreePaths(e){let t=await r(e,[`worktree`,`list`,`--porcelain`],n);return t.code===0?t.stdout.split(`
2
2
  `).filter(e=>e.startsWith(`worktree `)).map(e=>e.slice(9).trim()).filter(e=>e!==``):[]},async dirtyFiles(e){let t=await r(e,[`status`,`--porcelain`],n);return t.code===0?t.stdout.split(`
3
3
  `).map(e=>e.slice(3).trim()).filter(e=>e!==``):[]},async repositoryRoot(e){let t=await r(e,[`rev-parse`,`--show-toplevel`],n);if(t.code!==0)return;let i=t.stdout.trim();return i===``?void 0:i},async currentBranch(e){let t=await r(e,[`rev-parse`,`--abbrev-ref`,`HEAD`],n);if(t.code!==0)return;let i=t.stdout.trim();return i===``?void 0:i},async mergeBranch({repositoryRoot:e,branch:t,message:a}){let o=await r(e,[`merge`,`--no-ff`,...a===void 0?[]:[`-m`,a],t],n);if(o.code!==0)throw i(`merge`,o)}}}export{o as createWorktreeGit};
4
- //# sourceMappingURL=gitCli.mjs.map
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/gitCli/index.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\nimport fs from 'node:fs';\n\nimport type { WorktreeGit } from '../../types/worktreeRegistry';\n\n/**\n * Git, as this package needs it.\n *\n * The timeouts are not uniform because the operations are not comparable. A\n * read answers in milliseconds; `worktree add` copies an entire checkout and\n * `worktree remove` deletes one, both bounded by the filesystem rather than by\n * git, and both minutes rather than seconds on a large repository or on\n * Windows. A single timeout would either fail honest work or hang on a wedged\n * one.\n */\nconst READ_TIMEOUT_MS = 30_000;\nconst ADD_TIMEOUT_MS = 300_000;\nconst REMOVE_TIMEOUT_MS = 300_000;\nconst PRUNE_TIMEOUT_MS = 15_000;\nconst MAX_OUTPUT_BYTES = 1_000_000;\n\ninterface GitResult {\n code: number;\n stdout: string;\n stderr: string;\n}\n\n/**\n * Runs git and reports the outcome without ever throwing on a non-zero exit.\n *\n * LC_ALL is pinned because two callers below decide what to do by matching\n * git's own wording, and a translated message would silently turn a recognised\n * condition into an unrecognised failure.\n */\nfunction git(cwd: string, args: readonly string[], timeout: number): Promise<GitResult> {\n return new Promise((resolve) => {\n execFile(\n 'git',\n [...args],\n { cwd, timeout, maxBuffer: MAX_OUTPUT_BYTES, env: { ...process.env, LC_ALL: 'C' } },\n (error, stdout, stderr) => {\n const code = error && typeof error.code === 'number' ? error.code : error ? 1 : 0;\n resolve({ code, stdout: String(stdout), stderr: String(stderr) });\n },\n );\n });\n}\n\n/**\n * The message a failed git call is allowed to surface.\n *\n * Raw stderr never travels: it can carry a remote URL with a token in it, and\n * this text ends up in a tool result the model reads and may repeat.\n */\nfunction failure(operation: string, result: GitResult): Error {\n return new Error(\n `git ${operation} failed (exit ${String(result.code)}, ${String(result.stderr.length)} bytes of stderr)`,\n );\n}\n\n/** Git's own words for \"that worktree is not there any more\". */\nfunction missingWorktree(stderr: string): boolean {\n const normalized = stderr.toLowerCase();\n return normalized.includes('is not a working tree') || normalized.includes('cannot remove working tree');\n}\n\nexport function createWorktreeGit(): WorktreeGit {\n const prune = async (repositoryRoot: string): Promise<void> => {\n await git(repositoryRoot, ['worktree', 'prune'], PRUNE_TIMEOUT_MS);\n };\n\n return {\n async addWorktree({ repositoryRoot, path, branch, baseRef }) {\n const result = await git(repositoryRoot, ['worktree', 'add', '-b', branch, path, baseRef], ADD_TIMEOUT_MS);\n if (result.code !== 0) throw failure('worktree add', result);\n },\n\n async removeWorktree({ repositoryRoot, path, force }) {\n const args = ['worktree', 'remove', ...(force ? ['--force'] : []), path];\n const result = await git(repositoryRoot, args, REMOVE_TIMEOUT_MS);\n if (result.code === 0) return;\n // A directory deleted behind git's back leaves an administrative entry\n // that makes a later `worktree add` at the same path refuse. Treating\n // \"already gone\" as success and pruning is what keeps that path reusable,\n // and it makes remove idempotent for a caller retrying after a crash.\n if (missingWorktree(result.stderr) && !fs.existsSync(path)) {\n await prune(repositoryRoot);\n return;\n }\n throw failure('worktree remove', result);\n },\n\n async deleteBranch({ repositoryRoot, branch }) {\n // -d, never -D: git refuses a branch that still holds unmerged commits,\n // and that refusal is the whole safety property. A rollback that could\n // throw away work someone committed in the worktree is worse than a\n // branch left behind.\n const result = await git(repositoryRoot, ['branch', '-d', branch], READ_TIMEOUT_MS);\n return result.code === 0;\n },\n pruneWorktrees: prune,\n\n async listWorktreePaths(repositoryRoot) {\n const result = await git(repositoryRoot, ['worktree', 'list', '--porcelain'], READ_TIMEOUT_MS);\n if (result.code !== 0) return [];\n return result.stdout\n .split('\\n')\n .filter((line) => line.startsWith('worktree '))\n .map((line) => line.slice('worktree '.length).trim())\n .filter((line) => line !== '');\n },\n\n async dirtyFiles(path) {\n const result = await git(path, ['status', '--porcelain'], READ_TIMEOUT_MS);\n if (result.code !== 0) return [];\n return result.stdout\n .split('\\n')\n .map((line) => line.slice(3).trim())\n .filter((line) => line !== '');\n },\n\n async repositoryRoot(cwd) {\n const result = await git(cwd, ['rev-parse', '--show-toplevel'], READ_TIMEOUT_MS);\n if (result.code !== 0) return undefined;\n const root = result.stdout.trim();\n return root === '' ? undefined : root;\n },\n\n async currentBranch(cwd) {\n const result = await git(cwd, ['rev-parse', '--abbrev-ref', 'HEAD'], READ_TIMEOUT_MS);\n if (result.code !== 0) return undefined;\n const branch = result.stdout.trim();\n return branch === '' ? undefined : branch;\n },\n\n async mergeBranch({ repositoryRoot, branch, message }) {\n // --no-ff so the worktree's work stays identifiable as a unit after the\n // fact. A fast-forward would erase the fact that it was ever separate,\n // which is the one thing worth keeping about a worktree.\n const args = ['merge', '--no-ff', ...(message === undefined ? [] : ['-m', message]), branch];\n const result = await git(repositoryRoot, args, READ_TIMEOUT_MS);\n if (result.code === 0) return;\n // A conflicted merge leaves the parent mid-merge, which is a state the\n // person has to resolve; aborting for them would throw away the conflict\n // markers they need to see.\n throw failure('merge', result);\n },\n };\n}\n"],"mappings":"qEAeA,MAAM,EAAkB,IAmBxB,SAAS,EAAI,EAAa,EAAyB,EAAqC,CACtF,OAAO,IAAI,QAAS,GAAY,CAC9B,EACE,MACA,CAAC,GAAG,CAAI,EACR,CAAE,MAAK,UAAS,UAAW,IAAkB,IAAK,CAAE,GAAG,QAAQ,IAAK,OAAQ,GAAI,CAAE,GACjF,EAAO,EAAQ,IAAW,CAEzB,EAAQ,CAAE,KADG,GAAS,OAAO,EAAM,MAAS,SAAW,EAAM,KAAO,KACpD,OAAQ,OAAO,CAAM,EAAG,OAAQ,OAAO,CAAM,CAAE,CAAC,CAClE,CACF,CACF,CAAC,CACH,CAQA,SAAS,EAAQ,EAAmB,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,EAAK,WAAW,WAAW,CAAC,CAAC,CAC9C,IAAK,GAAS,EAAK,MAAM,CAAkB,CAAC,CAAC,KAAK,CAAC,CAAC,CACpD,OAAQ,GAAS,IAAS,EAAE,EALD,CAAC,CAMjC,EAEA,MAAM,WAAW,EAAM,CACrB,IAAM,EAAS,MAAM,EAAI,EAAM,CAAC,SAAU,aAAa,EAAG,CAAe,EAEzE,OADI,EAAO,OAAS,EACb,EAAO,OACX,MAAM;CAAI,CAAC,CACX,IAAK,GAAS,EAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CACnC,OAAQ,GAAS,IAAS,EAAE,EAJD,CAAC,CAKjC,EAEA,MAAM,eAAe,EAAK,CACxB,IAAM,EAAS,MAAM,EAAI,EAAK,CAAC,YAAa,iBAAiB,EAAG,CAAe,EAC/E,GAAI,EAAO,OAAS,EAAG,OACvB,IAAM,EAAO,EAAO,OAAO,KAAK,EAChC,OAAO,IAAS,GAAK,IAAA,GAAY,CACnC,EAEA,MAAM,cAAc,EAAK,CACvB,IAAM,EAAS,MAAM,EAAI,EAAK,CAAC,YAAa,eAAgB,MAAM,EAAG,CAAe,EACpF,GAAI,EAAO,OAAS,EAAG,OACvB,IAAM,EAAS,EAAO,OAAO,KAAK,EAClC,OAAO,IAAW,GAAK,IAAA,GAAY,CACrC,EAEA,MAAM,YAAY,CAAE,iBAAgB,SAAQ,WAAW,CAKrD,IAAM,EAAS,MAAM,EAAI,EAAgB,CAD3B,QAAS,UAAW,GAAI,IAAY,IAAA,GAAY,CAAC,EAAI,CAAC,KAAM,CAAO,EAAI,CACzC,EAAG,CAAe,EAC1D,KAAO,OAAS,EAIpB,MAAM,EAAQ,QAAS,CAAM,CAC/B,CACF,CACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("../extensionService/index.cjs"),t=require("../gitCli/index.cjs"),n=require("../worktreeOperations/index.cjs");function r(r={}){return{service:r.service??new e.DefaultGitExtensionService,operations:r.operations??n.createWorktreeOperations({git:t.createWorktreeGit()})}}exports.createGitDependencies=r;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["DefaultGitExtensionService","createWorktreeOperations","createWorktreeGit"],"sources":["../../../src/services/gitDependencies/index.ts"],"sourcesContent":["import type { GitExtensionDependencies } from '../../types/extension';\nimport { DefaultGitExtensionService } from '../extensionService';\n// @scaffold-generated\nimport { createWorktreeGit } from '../gitCli';\nimport { createWorktreeOperations } from '../worktreeOperations';\n\nexport function createGitDependencies(overrides: Partial<GitExtensionDependencies> = {}): GitExtensionDependencies {\n return {\n service: overrides.service ?? new DefaultGitExtensionService(),\n operations: overrides.operations ?? createWorktreeOperations({ git: createWorktreeGit() }),\n };\n}\n"],"mappings":"+HAMA,SAAgB,EAAsB,EAA+C,CAAC,EAA6B,CACjH,MAAO,CACL,QAAS,EAAU,SAAW,IAAIA,EAAAA,2BAClC,WAAY,EAAU,YAAcC,EAAAA,yBAAyB,CAAE,IAAKC,EAAAA,kBAAkB,CAAE,CAAC,CAC3F,CACF"}
@@ -0,0 +1,6 @@
1
+ import { GitExtensionDependencies } from "../../types/extension.cjs";
2
+ //#region src/services/gitDependencies/index.d.ts
3
+ declare function createGitDependencies(overrides?: Partial<GitExtensionDependencies>): GitExtensionDependencies;
4
+ //#endregion
5
+ export { createGitDependencies };
6
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/services/gitDependencies/index.ts"],"mappings":";;iBAMgB,sBAAsB,YAAW,QAAQ,4BAAiC"}
@@ -0,0 +1,6 @@
1
+ import { GitExtensionDependencies } from "../../types/extension.mjs";
2
+ //#region src/services/gitDependencies/index.d.ts
3
+ declare function createGitDependencies(overrides?: Partial<GitExtensionDependencies>): GitExtensionDependencies;
4
+ //#endregion
5
+ export { createGitDependencies };
6
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/gitDependencies/index.ts"],"mappings":";;iBAMgB,sBAAsB,YAAW,QAAQ,4BAAiC"}
@@ -0,0 +1,2 @@
1
+ import{DefaultGitExtensionService as e}from"../extensionService/index.mjs";import{createWorktreeGit as t}from"../gitCli/index.mjs";import{createWorktreeOperations as n}from"../worktreeOperations/index.mjs";function r(r={}){return{service:r.service??new e,operations:r.operations??n({git:t()})}}export{r as createGitDependencies};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/gitDependencies/index.ts"],"sourcesContent":["import type { GitExtensionDependencies } from '../../types/extension';\nimport { DefaultGitExtensionService } from '../extensionService';\n// @scaffold-generated\nimport { createWorktreeGit } from '../gitCli';\nimport { createWorktreeOperations } from '../worktreeOperations';\n\nexport function createGitDependencies(overrides: Partial<GitExtensionDependencies> = {}): GitExtensionDependencies {\n return {\n service: overrides.service ?? new DefaultGitExtensionService(),\n operations: overrides.operations ?? createWorktreeOperations({ git: createWorktreeGit() }),\n };\n}\n"],"mappings":"8MAMA,SAAgB,EAAsB,EAA+C,CAAC,EAA6B,CACjH,MAAO,CACL,QAAS,EAAU,SAAW,IAAI,EAClC,WAAY,EAAU,YAAc,EAAyB,CAAE,IAAK,EAAkB,CAAE,CAAC,CAC3F,CACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../repositoryIdentity/index.cjs");let n=require("node:path");n=e.__toESM(n,1);let r=require("node:os");r=e.__toESM(r,1),require("@agimon-ai/doompi-core/web");function i(e=r.default.homedir()){return n.default.join(e,`.pi`,`.doom`,`git`)}function a(e=r.default.homedir()){return n.default.join(i(e),`worktrees`)}function o(e,a=r.default.homedir()){let o=`${t.repositoryLabel(e)}--${t.repositoryId(e)}`;return n.default.join(i(a),`registry`,o,`worktrees.json`)}exports.doomGitRoot=i,exports.registryFile=o,exports.worktreesRoot=a;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["os","path","repositoryLabel","repositoryId"],"sources":["../../../src/services/paths/index.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\n\nimport { REGISTRY_DIR_ENV, resolveRegistryDir } from '@agimon-ai/doompi-core/web';\n\nimport { repositoryId, repositoryLabel } from '../repositoryIdentity';\n\nconst REGISTRY_DIR_FLAG = '--registry-dir';\n\n/**\n * Where this package keeps its own state.\n *\n * Outside the repository on purpose. A worktree directory inside the checkout\n * would be found by every glob the repository's own tooling runs, and would\n * resolve workspace imports against the parent checkout rather than the\n * worktree, so a session there would build the wrong source while appearing to\n * work.\n */\nexport function doomGitRoot(homeDir: string = os.homedir()): string {\n return path.join(homeDir, '.pi', '.doom', 'git');\n}\n\n/** The directory every worktree for every repository is created under. */\nexport function worktreesRoot(homeDir: string = os.homedir()): string {\n return path.join(doomGitRoot(homeDir), 'worktrees');\n}\n\n/** One registry file per repository, keyed by the shared git directory. */\n\nexport function registryFile(repositoryRoot: string, homeDir: string = os.homedir()): string {\n const key = `${repositoryLabel(repositoryRoot)}--${repositoryId(repositoryRoot)}`;\n return path.join(doomGitRoot(homeDir), 'registry', key, 'worktrees.json');\n}\n\n/**\n * The session registry directory this process's hub is watching.\n *\n * A spawned session only appears in the rail if it registers in the same\n * directory the hub watches, and the hub passes that directory to its children\n * as `--registry-dir` while also inheriting the env var. Recovering it from\n * this process's own argv and env, in the same precedence the hub and the\n * session server use, is what makes a worktree session visible rather than\n * silently invisible.\n */\nexport function hubRegistryDir(\n argv: readonly string[] = process.argv,\n env: NodeJS.ProcessEnv = process.env,\n homeDir: string = os.homedir(),\n): string {\n const index = argv.indexOf(REGISTRY_DIR_FLAG);\n const flagValue = index >= 0 ? argv[index + 1] : undefined;\n return resolveRegistryDir({\n ...(flagValue === undefined ? {} : { flagValue }),\n ...(env[REGISTRY_DIR_ENV] === undefined ? {} : { envValue: env[REGISTRY_DIR_ENV] }),\n homeDir,\n });\n}\n"],"mappings":"iOAkBA,SAAgB,EAAY,EAAkBA,EAAAA,QAAG,QAAQ,EAAW,CAClE,OAAOC,EAAAA,QAAK,KAAK,EAAS,MAAO,QAAS,KAAK,CACjD,CAGA,SAAgB,EAAc,EAAkBD,EAAAA,QAAG,QAAQ,EAAW,CACpE,OAAOC,EAAAA,QAAK,KAAK,EAAY,CAAO,EAAG,WAAW,CACpD,CAIA,SAAgB,EAAa,EAAwB,EAAkBD,EAAAA,QAAG,QAAQ,EAAW,CAC3F,IAAM,EAAM,GAAGE,EAAAA,gBAAgB,CAAc,EAAE,IAAIC,EAAAA,aAAa,CAAc,IAC9E,OAAOF,EAAAA,QAAK,KAAK,EAAY,CAAO,EAAG,WAAY,EAAK,gBAAgB,CAC1E"}
@@ -0,0 +1,2 @@
1
+ import{repositoryId as e,repositoryLabel as t}from"../repositoryIdentity/index.mjs";import n from"node:path";import r from"node:os";import"@agimon-ai/doompi-core/web";function i(e=r.homedir()){return n.join(e,`.pi`,`.doom`,`git`)}function a(e=r.homedir()){return n.join(i(e),`worktrees`)}function o(a,o=r.homedir()){let s=`${t(a)}--${e(a)}`;return n.join(i(o),`registry`,s,`worktrees.json`)}export{i as doomGitRoot,o as registryFile,a as worktreesRoot};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/paths/index.ts"],"sourcesContent":["import os from 'node:os';\nimport path from 'node:path';\n\nimport { REGISTRY_DIR_ENV, resolveRegistryDir } from '@agimon-ai/doompi-core/web';\n\nimport { repositoryId, repositoryLabel } from '../repositoryIdentity';\n\nconst REGISTRY_DIR_FLAG = '--registry-dir';\n\n/**\n * Where this package keeps its own state.\n *\n * Outside the repository on purpose. A worktree directory inside the checkout\n * would be found by every glob the repository's own tooling runs, and would\n * resolve workspace imports against the parent checkout rather than the\n * worktree, so a session there would build the wrong source while appearing to\n * work.\n */\nexport function doomGitRoot(homeDir: string = os.homedir()): string {\n return path.join(homeDir, '.pi', '.doom', 'git');\n}\n\n/** The directory every worktree for every repository is created under. */\nexport function worktreesRoot(homeDir: string = os.homedir()): string {\n return path.join(doomGitRoot(homeDir), 'worktrees');\n}\n\n/** One registry file per repository, keyed by the shared git directory. */\n\nexport function registryFile(repositoryRoot: string, homeDir: string = os.homedir()): string {\n const key = `${repositoryLabel(repositoryRoot)}--${repositoryId(repositoryRoot)}`;\n return path.join(doomGitRoot(homeDir), 'registry', key, 'worktrees.json');\n}\n\n/**\n * The session registry directory this process's hub is watching.\n *\n * A spawned session only appears in the rail if it registers in the same\n * directory the hub watches, and the hub passes that directory to its children\n * as `--registry-dir` while also inheriting the env var. Recovering it from\n * this process's own argv and env, in the same precedence the hub and the\n * session server use, is what makes a worktree session visible rather than\n * silently invisible.\n */\nexport function hubRegistryDir(\n argv: readonly string[] = process.argv,\n env: NodeJS.ProcessEnv = process.env,\n homeDir: string = os.homedir(),\n): string {\n const index = argv.indexOf(REGISTRY_DIR_FLAG);\n const flagValue = index >= 0 ? argv[index + 1] : undefined;\n return resolveRegistryDir({\n ...(flagValue === undefined ? {} : { flagValue }),\n ...(env[REGISTRY_DIR_ENV] === undefined ? {} : { envValue: env[REGISTRY_DIR_ENV] }),\n homeDir,\n });\n}\n"],"mappings":"uKAkBA,SAAgB,EAAY,EAAkB,EAAG,QAAQ,EAAW,CAClE,OAAO,EAAK,KAAK,EAAS,MAAO,QAAS,KAAK,CACjD,CAGA,SAAgB,EAAc,EAAkB,EAAG,QAAQ,EAAW,CACpE,OAAO,EAAK,KAAK,EAAY,CAAO,EAAG,WAAW,CACpD,CAIA,SAAgB,EAAa,EAAwB,EAAkB,EAAG,QAAQ,EAAW,CAC3F,IAAM,EAAM,GAAG,EAAgB,CAAc,EAAE,IAAI,EAAa,CAAc,IAC9E,OAAO,EAAK,KAAK,EAAY,CAAO,EAAG,WAAY,EAAK,gBAAgB,CAC1E"}
@@ -1,2 +1,2 @@
1
1
  const e=require("../../_virtual/_rolldown/runtime.cjs");let t=require("node:fs");t=e.__toESM(t,1);let n=require("node:crypto"),r=require("node:path");r=e.__toESM(r,1);function i(e){let n=r.default.join(e,`.git`),i;try{i=t.default.statSync(n)}catch{return}if(i.isDirectory())return n;let a;try{a=t.default.readFileSync(n,`utf8`).trim()}catch{return}if(!a.startsWith(`gitdir:`))return;let o=r.default.resolve(e,a.slice(7).trim());try{let e=t.default.readFileSync(r.default.join(o,`commondir`),`utf8`).trim();return r.default.resolve(o,e)}catch{return o}}function a(e){let t=r.default.basename(e).toLowerCase().replace(/[^a-z0-9]+/gu,`-`).replace(/^-+|-+$/gu,``).slice(0,32);return t===``?`repository`:t}function o(e){let t=i(e),a=t===void 0?`root:${r.default.resolve(e)}`:`git:${t}`;return(0,n.createHash)(`sha256`).update(a).digest(`hex`).slice(0,12)}function s(e){return(0,n.createHash)(`sha256`).update(e).digest(`hex`).slice(0,8)}exports.gitCommonDirectory=i,exports.repositoryId=o,exports.repositoryLabel=a,exports.shortId=s;
2
- //# sourceMappingURL=repositoryIdentity.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["path","fs","createHash"],"sources":["../../../src/services/repositoryIdentity/index.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nconst ID_LENGTH = 12;\nconst MAX_LABEL_LENGTH = 32;\n\n/**\n * The git directory shared by a repository and all of its worktrees.\n *\n * A normal checkout has a `.git` directory. A linked worktree has a `.git`\n * FILE pointing at `<common>/worktrees/<name>`, whose `commondir` points back\n * at the shared directory. Following that chain is what makes every worktree of\n * one repository agree on the repository's identity, which matters here because\n * the registry is per repository and must be found from inside a worktree too.\n */\nexport function gitCommonDirectory(root: string): string | undefined {\n const marker = path.join(root, '.git');\n let stat: fs.Stats;\n try {\n stat = fs.statSync(marker);\n } catch {\n return undefined;\n }\n if (stat.isDirectory()) return marker;\n let pointer: string;\n try {\n pointer = fs.readFileSync(marker, 'utf8').trim();\n } catch {\n return undefined;\n }\n if (!pointer.startsWith('gitdir:')) return undefined;\n const gitDir = path.resolve(root, pointer.slice('gitdir:'.length).trim());\n try {\n const common = fs.readFileSync(path.join(gitDir, 'commondir'), 'utf8').trim();\n return path.resolve(gitDir, common);\n } catch {\n // A submodule's .git file has no commondir; its gitdir is already common.\n return gitDir;\n }\n}\n\n/** A directory name that is recognisable to a person and safe on a filesystem. */\nexport function repositoryLabel(root: string): string {\n const label = path\n .basename(root)\n .toLowerCase()\n .replace(/[^a-z0-9]+/gu, '-')\n .replace(/^-+|-+$/gu, '')\n .slice(0, MAX_LABEL_LENGTH);\n return label === '' ? 'repository' : label;\n}\n\n/**\n * A stable id for the repository a directory belongs to.\n *\n * Keyed on the common git directory rather than the given path, so the main\n * checkout and every worktree of it resolve to one id and therefore to one\n * registry. Falling back to the path keeps a non-repository directory usable\n * instead of failing, though nothing here should reach that case.\n */\nexport function repositoryId(root: string): string {\n const common = gitCommonDirectory(root);\n const token = common === undefined ? `root:${path.resolve(root)}` : `git:${common}`;\n return createHash('sha256').update(token).digest('hex').slice(0, ID_LENGTH);\n}\n\n/** A short, collision-resistant suffix for one worktree directory. */\nexport function shortId(seed: string): string {\n return createHash('sha256').update(seed).digest('hex').slice(0, 8);\n}\n"],"mappings":"uKAgBA,SAAgB,EAAmB,EAAkC,CACnE,IAAM,EAASA,EAAAA,QAAK,KAAK,EAAM,MAAM,EACjC,EACJ,GAAI,CACF,EAAOC,EAAAA,QAAG,SAAS,CAAM,CAC3B,MAAQ,CACN,MACF,CACA,GAAI,EAAK,YAAY,EAAG,OAAO,EAC/B,IAAI,EACJ,GAAI,CACF,EAAUA,EAAAA,QAAG,aAAa,EAAQ,MAAM,CAAC,CAAC,KAAK,CACjD,MAAQ,CACN,MACF,CACA,GAAI,CAAC,EAAQ,WAAW,SAAS,EAAG,OACpC,IAAM,EAASD,EAAAA,QAAK,QAAQ,EAAM,EAAQ,MAAM,CAAgB,CAAC,CAAC,KAAK,CAAC,EACxE,GAAI,CACF,IAAM,EAASC,EAAAA,QAAG,aAAaD,EAAAA,QAAK,KAAK,EAAQ,WAAW,EAAG,MAAM,CAAC,CAAC,KAAK,EAC5E,OAAOA,EAAAA,QAAK,QAAQ,EAAQ,CAAM,CACpC,MAAQ,CAEN,OAAO,CACT,CACF,CAGA,SAAgB,EAAgB,EAAsB,CACpD,IAAM,EAAQA,EAAAA,QACX,SAAS,CAAI,CAAC,CACd,YAAY,CAAC,CACb,QAAQ,eAAgB,GAAG,CAAC,CAC5B,QAAQ,YAAa,EAAE,CAAC,CACxB,MAAM,EAAG,EAAgB,EAC5B,OAAO,IAAU,GAAK,aAAe,CACvC,CAUA,SAAgB,EAAa,EAAsB,CACjD,IAAM,EAAS,EAAmB,CAAI,EAChC,EAAQ,IAAW,IAAA,GAAY,QAAQA,EAAAA,QAAK,QAAQ,CAAI,IAAM,OAAO,IAC3E,OAAA,EAAOE,EAAAA,WAAAA,CAAW,QAAQ,CAAC,CAAC,OAAO,CAAK,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,EAAG,EAAS,CAC5E,CAGA,SAAgB,EAAQ,EAAsB,CAC5C,OAAA,EAAOA,EAAAA,WAAAA,CAAW,QAAQ,CAAC,CAAC,OAAO,CAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,EAAG,CAAC,CACnE"}
@@ -1,2 +1,2 @@
1
1
  import e from"node:fs";import{createHash as t}from"node:crypto";import n from"node:path";function r(t){let r=n.join(t,`.git`),i;try{i=e.statSync(r)}catch{return}if(i.isDirectory())return r;let a;try{a=e.readFileSync(r,`utf8`).trim()}catch{return}if(!a.startsWith(`gitdir:`))return;let o=n.resolve(t,a.slice(7).trim());try{let t=e.readFileSync(n.join(o,`commondir`),`utf8`).trim();return n.resolve(o,t)}catch{return o}}function i(e){let t=n.basename(e).toLowerCase().replace(/[^a-z0-9]+/gu,`-`).replace(/^-+|-+$/gu,``).slice(0,32);return t===``?`repository`:t}function a(e){let i=r(e),a=i===void 0?`root:${n.resolve(e)}`:`git:${i}`;return t(`sha256`).update(a).digest(`hex`).slice(0,12)}function o(e){return t(`sha256`).update(e).digest(`hex`).slice(0,8)}export{r as gitCommonDirectory,a as repositoryId,i as repositoryLabel,o as shortId};
2
- //# sourceMappingURL=repositoryIdentity.mjs.map
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/repositoryIdentity/index.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nconst ID_LENGTH = 12;\nconst MAX_LABEL_LENGTH = 32;\n\n/**\n * The git directory shared by a repository and all of its worktrees.\n *\n * A normal checkout has a `.git` directory. A linked worktree has a `.git`\n * FILE pointing at `<common>/worktrees/<name>`, whose `commondir` points back\n * at the shared directory. Following that chain is what makes every worktree of\n * one repository agree on the repository's identity, which matters here because\n * the registry is per repository and must be found from inside a worktree too.\n */\nexport function gitCommonDirectory(root: string): string | undefined {\n const marker = path.join(root, '.git');\n let stat: fs.Stats;\n try {\n stat = fs.statSync(marker);\n } catch {\n return undefined;\n }\n if (stat.isDirectory()) return marker;\n let pointer: string;\n try {\n pointer = fs.readFileSync(marker, 'utf8').trim();\n } catch {\n return undefined;\n }\n if (!pointer.startsWith('gitdir:')) return undefined;\n const gitDir = path.resolve(root, pointer.slice('gitdir:'.length).trim());\n try {\n const common = fs.readFileSync(path.join(gitDir, 'commondir'), 'utf8').trim();\n return path.resolve(gitDir, common);\n } catch {\n // A submodule's .git file has no commondir; its gitdir is already common.\n return gitDir;\n }\n}\n\n/** A directory name that is recognisable to a person and safe on a filesystem. */\nexport function repositoryLabel(root: string): string {\n const label = path\n .basename(root)\n .toLowerCase()\n .replace(/[^a-z0-9]+/gu, '-')\n .replace(/^-+|-+$/gu, '')\n .slice(0, MAX_LABEL_LENGTH);\n return label === '' ? 'repository' : label;\n}\n\n/**\n * A stable id for the repository a directory belongs to.\n *\n * Keyed on the common git directory rather than the given path, so the main\n * checkout and every worktree of it resolve to one id and therefore to one\n * registry. Falling back to the path keeps a non-repository directory usable\n * instead of failing, though nothing here should reach that case.\n */\nexport function repositoryId(root: string): string {\n const common = gitCommonDirectory(root);\n const token = common === undefined ? `root:${path.resolve(root)}` : `git:${common}`;\n return createHash('sha256').update(token).digest('hex').slice(0, ID_LENGTH);\n}\n\n/** A short, collision-resistant suffix for one worktree directory. */\nexport function shortId(seed: string): string {\n return createHash('sha256').update(seed).digest('hex').slice(0, 8);\n}\n"],"mappings":"yFAgBA,SAAgB,EAAmB,EAAkC,CACnE,IAAM,EAAS,EAAK,KAAK,EAAM,MAAM,EACjC,EACJ,GAAI,CACF,EAAO,EAAG,SAAS,CAAM,CAC3B,MAAQ,CACN,MACF,CACA,GAAI,EAAK,YAAY,EAAG,OAAO,EAC/B,IAAI,EACJ,GAAI,CACF,EAAU,EAAG,aAAa,EAAQ,MAAM,CAAC,CAAC,KAAK,CACjD,MAAQ,CACN,MACF,CACA,GAAI,CAAC,EAAQ,WAAW,SAAS,EAAG,OACpC,IAAM,EAAS,EAAK,QAAQ,EAAM,EAAQ,MAAM,CAAgB,CAAC,CAAC,KAAK,CAAC,EACxE,GAAI,CACF,IAAM,EAAS,EAAG,aAAa,EAAK,KAAK,EAAQ,WAAW,EAAG,MAAM,CAAC,CAAC,KAAK,EAC5E,OAAO,EAAK,QAAQ,EAAQ,CAAM,CACpC,MAAQ,CAEN,OAAO,CACT,CACF,CAGA,SAAgB,EAAgB,EAAsB,CACpD,IAAM,EAAQ,EACX,SAAS,CAAI,CAAC,CACd,YAAY,CAAC,CACb,QAAQ,eAAgB,GAAG,CAAC,CAC5B,QAAQ,YAAa,EAAE,CAAC,CACxB,MAAM,EAAG,EAAgB,EAC5B,OAAO,IAAU,GAAK,aAAe,CACvC,CAUA,SAAgB,EAAa,EAAsB,CACjD,IAAM,EAAS,EAAmB,CAAI,EAChC,EAAQ,IAAW,IAAA,GAAY,QAAQ,EAAK,QAAQ,CAAI,IAAM,OAAO,IAC3E,OAAO,EAAW,QAAQ,CAAC,CAAC,OAAO,CAAK,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,EAAG,EAAS,CAC5E,CAGA,SAAgB,EAAQ,EAAsB,CAC5C,OAAO,EAAW,QAAQ,CAAC,CAAC,OAAO,CAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,EAAG,CAAC,CACnE"}
@@ -0,0 +1,15 @@
1
+ const e=require("../errors/index.cjs"),t=require("../../schemas/runWorktreeTool.cjs"),n=new Set(Object.values(t.WORKTREE_ACTIONS));function r(r){if(typeof r!=`object`||!r||Array.isArray(r))throw e.invalidRequest(`run_worktree parameters must be an object.`,`Call it with one documented action shape.`);let i=r,a=i.action;if(typeof a!=`string`||!n.has(a))throw e.invalidRequest(`Unknown action ${typeof a==`string`?`'${a}'`:`value`}.`,`Use one of: ${[...n].join(`, `)}.`);let o=t.WORKTREE_ACTION_FIELDS[a],s=Object.keys(i).filter(e=>!o.includes(e));if(s.length>0)throw e.invalidRequest(`action='${a}' does not accept: ${s.join(`, `)}.`,`Fields for '${a}': ${o.join(`, `)}.`);for(let t of[`branch`,`id`])if(o.includes(t)&&t in i){let n=i[t];if(typeof n!=`string`||n.trim()===``)throw e.invalidRequest(`action='${a}' requires a nonblank '${t}'.`,`Pass a ${t}.`)}for(let t of[`baseRef`,`name`,`task`,`message`])if(t in i&&(typeof i[t]!=`string`||i[t].trim()===``))throw e.invalidRequest(`action='${a}' requires a nonblank '${t}'.`,`Pass a ${t}.`);for(let t of[`force`,`dryRun`])if(t in i&&typeof i[t]!=`boolean`)throw e.invalidRequest(`action='${a}' requires boolean '${t}'.`,`Pass true or false for ${t}.`);if(a===t.WORKTREE_ACTIONS.send&&typeof i.message!=`string`)throw e.invalidRequest(`action='send' requires 'message'.`,`Pass the message to send.`);if(a===t.WORKTREE_ACTIONS.spawn_worktree&&typeof i.branch!=`string`)throw e.invalidRequest(`action='spawn_worktree' requires 'branch'.`,`Name the branch to create.`);if((a===t.WORKTREE_ACTIONS.close_worktree||a===t.WORKTREE_ACTIONS.status||a===t.WORKTREE_ACTIONS.merge||a===t.WORKTREE_ACTIONS.send||a===t.WORKTREE_ACTIONS.messages)&&typeof i.id!=`string`)throw e.invalidRequest(`action='${a}' requires 'id'.`,`Call list to see the current ids.`);return i}function i(e){return`${e.id} ${e.branch} ${e.status} ${e.path}`}function a(...e){return[{type:`text`,text:e.join(`
2
+ `)}]}async function o(e,n,r,o={}){switch(e.action){case t.WORKTREE_ACTIONS.spawn_worktree:{let t=await n.spawn(r,{branch:e.branch,...e.baseRef===void 0?{}:{baseRef:e.baseRef},...e.name===void 0?{}:{name:e.name}},o);return{content:a(`Worktree ${t.id} created on ${t.branch} from ${t.baseRef}.`,`Path: ${t.path}`,`Session ${t.sessionId} is starting; it appears nested under this one in the rail.`),details:{action:e.action,records:[t]}}}case t.WORKTREE_ACTIONS.close_worktree:{let t=await n.close(r,e.id,e.force??!1);return{content:a(`Worktree ${t.id} (${t.branch}) closed and removed.`),details:{action:e.action,records:[t]}}}case t.WORKTREE_ACTIONS.list:{let t=await n.list(r);return{content:t.length===0?a(`No worktrees for this repository.`):a(`${String(t.length)} worktree(s):`,...t.map(i)),details:{action:e.action,records:t}}}case t.WORKTREE_ACTIONS.status:{let{record:t,dirtyFiles:o}=await n.status(r,e.id);return{content:a(i(t),`Session: ${t.sessionId}`,o.length===0?`Clean.`:`${String(o.length)} uncommitted file(s): ${o.slice(0,20).join(`, `)}`),details:{action:e.action,records:[t]}}}case t.WORKTREE_ACTIONS.merge:{let t=await n.merge(r,e.id,...e.message===void 0?[]:[e.message]);return{content:a(`Merged ${t.branch} into this checkout.`),details:{action:e.action,records:[t]}}}case t.WORKTREE_ACTIONS.send:return await n.send(r,e.id,e.message),{content:a(`Message sent to worktree ${e.id}.`),details:{action:e.action}};case t.WORKTREE_ACTIONS.messages:{let t=await n.messages(r,e.id);return{content:t.length===0?a(`No messages.`):a(`${String(t.length)} message(s):`,...t.map(e=>`[${e.sentAt}] ${e.from}: ${e.text}`)),details:{action:e.action}}}case t.WORKTREE_ACTIONS.prune:{let t=e.dryRun??!1,i=await n.prune(r,t);return{content:a(t?`Prune plan (nothing was changed):`:`Pruned:`,`Remove: ${i.remove.length===0?`none`:i.remove.map(e=>e.id).join(`, `)}`,`Forget: ${i.forget.length===0?`none`:i.forget.map(e=>e.id).join(`, `)}`,`Kept, uncommitted work: ${i.keptDirty.length===0?`none`:i.keptDirty.map(e=>e.id).join(`, `)}`,`Untracked directories, left alone: ${i.untracked.length===0?`none`:i.untracked.join(`, `)}`,...i.keptBranches.length===0?[]:[`Branches kept, they hold commits: ${i.keptBranches.join(`, `)}`]),details:{action:e.action}}}}}exports.RUN_WORKTREE_DESCRIPTION=`Create and manage git worktrees, each with its own DoomPi session nested under this one.
3
+
4
+ Actions:
5
+ - spawn_worktree: create a worktree on a new branch and start a session in it. Requires 'branch'. Optional 'baseRef' (defaults to the current branch), 'name' for the rail, 'task' as the first message.
6
+ - close_worktree: stop a worktree's session and delete its directory. Requires 'id'. Refuses a dirty tree unless 'force' is true.
7
+ - list: every worktree for this repository, with status.
8
+ - status: one worktree and its uncommitted files. Requires 'id'.
9
+ - merge: merge a worktree's branch into this checkout. Requires 'id'. Refuses when this checkout is dirty.
10
+ - prune: remove orphaned worktrees. Pass 'dryRun' to see the plan without destroying anything.
11
+ - send: send a message to the other side of a worktree. Requires 'id' and 'message'.
12
+ - messages: read messages waiting for you from a worktree. Requires 'id'.
13
+
14
+ Worktrees live outside the repository, under ~/.pi/.doom/git/worktrees.`,exports.RUN_WORKTREE_TOOL_NAME=`run_worktree`,exports.executeRunWorktreeTool=o,exports.validateParams=r;
15
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["WORKTREE_ACTIONS","invalidRequest","WORKTREE_ACTION_FIELDS"],"sources":["../../../src/services/runWorktree/index.ts"],"sourcesContent":["import {\n RunWorktreeParams,\n WORKTREE_ACTION_FIELDS,\n WORKTREE_ACTIONS,\n type WorktreeAction,\n type RunWorktreeToolParams,\n} from '../../schemas/runWorktreeTool';\nimport type { WorktreeRecord } from '../../types/worktreeRegistry';\nimport { invalidRequest } from '../errors';\nimport type { WorktreeOperations } from '../worktreeOperations';\n\nexport { RunWorktreeParams };\nexport type { RunWorktreeToolParams, WorktreeAction };\n\nexport const RUN_WORKTREE_TOOL_NAME = 'run_worktree';\n\nconst IMPLEMENTED_ACTIONS: ReadonlySet<string> = new Set(Object.values(WORKTREE_ACTIONS));\n\nexport const RUN_WORKTREE_DESCRIPTION = `Create and manage git worktrees, each with its own DoomPi session nested under this one.\n\nActions:\n- spawn_worktree: create a worktree on a new branch and start a session in it. Requires 'branch'. Optional 'baseRef' (defaults to the current branch), 'name' for the rail, 'task' as the first message.\n- close_worktree: stop a worktree's session and delete its directory. Requires 'id'. Refuses a dirty tree unless 'force' is true.\n- list: every worktree for this repository, with status.\n- status: one worktree and its uncommitted files. Requires 'id'.\n- merge: merge a worktree's branch into this checkout. Requires 'id'. Refuses when this checkout is dirty.\n- prune: remove orphaned worktrees. Pass 'dryRun' to see the plan without destroying anything.\n- send: send a message to the other side of a worktree. Requires 'id' and 'message'.\n- messages: read messages waiting for you from a worktree. Requires 'id'.\n\nWorktrees live outside the repository, under ~/.pi/.doom/git/worktrees.`;\n\nexport interface RunWorktreeToolDetails {\n action: WorktreeAction;\n records?: WorktreeRecord[];\n}\n\nexport interface RunWorktreeToolResult {\n content: [{ type: 'text'; text: string }];\n details: RunWorktreeToolDetails;\n}\n\nexport interface RunWorktreeExecutionContext {\n readonly cwd: string;\n readonly sessionId: string;\n}\n\nexport interface RunWorktreeExecutionOptions {\n readonly signal?: AbortSignal;\n readonly onProgress?: (label: string) => void;\n}\n\n/** Rejects calls that do not match one documented action shape. */\nexport function validateParams(input: unknown): RunWorktreeToolParams {\n if (typeof input !== 'object' || input === null || Array.isArray(input)) {\n throw invalidRequest('run_worktree parameters must be an object.', 'Call it with one documented action shape.');\n }\n const record = input as Record<string, unknown>;\n const action = record.action;\n if (typeof action !== 'string' || !IMPLEMENTED_ACTIONS.has(action)) {\n throw invalidRequest(\n `Unknown action ${typeof action === 'string' ? `'${action}'` : 'value'}.`,\n `Use one of: ${[...IMPLEMENTED_ACTIONS].join(', ')}.`,\n );\n }\n const allowed = WORKTREE_ACTION_FIELDS[action as WorktreeAction];\n const unexpected = Object.keys(record).filter((key) => !allowed.includes(key));\n if (unexpected.length > 0) {\n throw invalidRequest(\n `action='${action}' does not accept: ${unexpected.join(', ')}.`,\n `Fields for '${action}': ${allowed.join(', ')}.`,\n );\n }\n for (const field of ['branch', 'id'] as const) {\n if (allowed.includes(field) && field in record) {\n const value = record[field];\n if (typeof value !== 'string' || value.trim() === '') {\n throw invalidRequest(`action='${action}' requires a nonblank '${field}'.`, `Pass a ${field}.`);\n }\n }\n }\n const stringFields = ['baseRef', 'name', 'task', 'message'] as const;\n for (const field of stringFields) {\n if (field in record && (typeof record[field] !== 'string' || record[field].trim() === '')) {\n throw invalidRequest(`action='${action}' requires a nonblank '${field}'.`, `Pass a ${field}.`);\n }\n }\n for (const field of ['force', 'dryRun'] as const) {\n if (field in record && typeof record[field] !== 'boolean') {\n throw invalidRequest(`action='${action}' requires boolean '${field}'.`, `Pass true or false for ${field}.`);\n }\n }\n if (action === WORKTREE_ACTIONS.send && typeof record.message !== 'string') {\n throw invalidRequest(\"action='send' requires 'message'.\", 'Pass the message to send.');\n }\n if (action === WORKTREE_ACTIONS.spawn_worktree && typeof record.branch !== 'string') {\n throw invalidRequest(\"action='spawn_worktree' requires 'branch'.\", 'Name the branch to create.');\n }\n if (\n (action === WORKTREE_ACTIONS.close_worktree ||\n action === WORKTREE_ACTIONS.status ||\n action === WORKTREE_ACTIONS.merge ||\n action === WORKTREE_ACTIONS.send ||\n action === WORKTREE_ACTIONS.messages) &&\n typeof record.id !== 'string'\n ) {\n throw invalidRequest(`action='${action}' requires 'id'.`, 'Call list to see the current ids.');\n }\n return record as RunWorktreeToolParams;\n}\n\nfunction describe(record: WorktreeRecord): string {\n return `${record.id} ${record.branch} ${record.status} ${record.path}`;\n}\n\nfunction text(...lines: readonly string[]): [{ type: 'text'; text: string }] {\n return [{ type: 'text', text: lines.join('\\n') }];\n}\n\nexport async function executeRunWorktreeTool(\n params: RunWorktreeToolParams,\n operations: WorktreeOperations,\n context: RunWorktreeExecutionContext,\n options: RunWorktreeExecutionOptions = {},\n): Promise<RunWorktreeToolResult> {\n switch (params.action) {\n case WORKTREE_ACTIONS.spawn_worktree: {\n const record = await operations.spawn(\n context,\n {\n branch: params.branch,\n ...(params.baseRef === undefined ? {} : { baseRef: params.baseRef }),\n ...(params.name === undefined ? {} : { name: params.name }),\n },\n options,\n );\n return {\n content: text(\n `Worktree ${record.id} created on ${record.branch} from ${record.baseRef}.`,\n `Path: ${record.path}`,\n `Session ${record.sessionId} is starting; it appears nested under this one in the rail.`,\n ),\n details: { action: params.action, records: [record] },\n };\n }\n case WORKTREE_ACTIONS.close_worktree: {\n const record = await operations.close(context, params.id, params.force ?? false);\n return {\n content: text(`Worktree ${record.id} (${record.branch}) closed and removed.`),\n details: { action: params.action, records: [record] },\n };\n }\n case WORKTREE_ACTIONS.list: {\n const records = await operations.list(context);\n return {\n content:\n records.length === 0\n ? text('No worktrees for this repository.')\n : text(`${String(records.length)} worktree(s):`, ...records.map(describe)),\n details: { action: params.action, records },\n };\n }\n case WORKTREE_ACTIONS.status: {\n const { record, dirtyFiles } = await operations.status(context, params.id);\n return {\n content: text(\n describe(record),\n `Session: ${record.sessionId}`,\n dirtyFiles.length === 0\n ? 'Clean.'\n : `${String(dirtyFiles.length)} uncommitted file(s): ${dirtyFiles.slice(0, 20).join(', ')}`,\n ),\n details: { action: params.action, records: [record] },\n };\n }\n case WORKTREE_ACTIONS.merge: {\n const record = await operations.merge(\n context,\n params.id,\n ...(params.message === undefined ? [] : ([params.message] as const)),\n );\n return {\n content: text(`Merged ${record.branch} into this checkout.`),\n details: { action: params.action, records: [record] },\n };\n }\n case WORKTREE_ACTIONS.send: {\n await operations.send(context, params.id, params.message);\n return { content: text(`Message sent to worktree ${params.id}.`), details: { action: params.action } };\n }\n case WORKTREE_ACTIONS.messages: {\n const waiting = await operations.messages(context, params.id);\n return {\n content:\n waiting.length === 0\n ? text('No messages.')\n : text(\n `${String(waiting.length)} message(s):`,\n ...waiting.map((entry) => `[${entry.sentAt}] ${entry.from}: ${entry.text}`),\n ),\n details: { action: params.action },\n };\n }\n case WORKTREE_ACTIONS.prune: {\n const dryRun = params.dryRun ?? false;\n const plan = await operations.prune(context, dryRun);\n const lines = [\n dryRun ? 'Prune plan (nothing was changed):' : 'Pruned:',\n `Remove: ${plan.remove.length === 0 ? 'none' : plan.remove.map((record) => record.id).join(', ')}`,\n `Forget: ${plan.forget.length === 0 ? 'none' : plan.forget.map((record) => record.id).join(', ')}`,\n `Kept, uncommitted work: ${plan.keptDirty.length === 0 ? 'none' : plan.keptDirty.map((record) => record.id).join(', ')}`,\n `Untracked directories, left alone: ${plan.untracked.length === 0 ? 'none' : plan.untracked.join(', ')}`,\n ...(plan.keptBranches.length === 0\n ? []\n : [`Branches kept, they hold commits: ${plan.keptBranches.join(', ')}`]),\n ];\n return { content: text(...lines), details: { action: params.action } };\n }\n }\n}\n"],"mappings":"sFAgBM,EAA2C,IAAI,IAAI,OAAO,OAAOA,EAAAA,gBAAgB,CAAC,EAqCxF,SAAgB,EAAe,EAAuC,CACpE,GAAI,OAAO,GAAU,WAAY,GAAkB,MAAM,QAAQ,CAAK,EACpE,MAAMC,EAAAA,eAAe,6CAA8C,2CAA2C,EAEhH,IAAM,EAAS,EACT,EAAS,EAAO,OACtB,GAAI,OAAO,GAAW,UAAY,CAAC,EAAoB,IAAI,CAAM,EAC/D,MAAMA,EAAAA,eACJ,kBAAkB,OAAO,GAAW,SAAW,IAAI,EAAO,GAAK,QAAQ,GACvE,eAAe,CAAC,GAA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EAAQ,MAAM,EAAE,cAC1B,GAAG,EAAQ,IAAK,GAAU,IAAI,EAAM,OAAO,IAAI,EAAM,KAAK,IAAI,EAAM,MAAM,CAC5E,EACN,QAAS,CAAE,OAAQ,EAAO,MAAO,CACnC,CACF,CACA,KAAKA,EAAAA,iBAAiB,MAAO,CAC3B,IAAM,EAAS,EAAO,QAAU,GAC1B,EAAO,MAAM,EAAW,MAAM,EAAS,CAAM,EAWnD,MAAO,CAAE,QAAS,EAThB,EAAS,oCAAsC,UAC/C,WAAW,EAAK,OAAO,SAAW,EAAI,OAAS,EAAK,OAAO,IAAK,GAAW,EAAO,EAAE,CAAC,CAAC,KAAK,IAAI,IAC/F,WAAW,EAAK,OAAO,SAAW,EAAI,OAAS,EAAK,OAAO,IAAK,GAAW,EAAO,EAAE,CAAC,CAAC,KAAK,IAAI,IAC/F,2BAA2B,EAAK,UAAU,SAAW,EAAI,OAAS,EAAK,UAAU,IAAK,GAAW,EAAO,EAAE,CAAC,CAAC,KAAK,IAAI,IACrH,sCAAsC,EAAK,UAAU,SAAW,EAAI,OAAS,EAAK,UAAU,KAAK,IAAI,IACrG,GAAI,EAAK,aAAa,SAAW,EAC7B,CAAC,EACD,CAAC,qCAAqC,EAAK,aAAa,KAAK,IAAI,GAAG,CAE3C,EAAG,QAAS,CAAE,OAAQ,EAAO,MAAO,CAAE,CACvE,CACF,CACF"}
@@ -0,0 +1,15 @@
1
+ import{invalidRequest as e}from"../errors/index.mjs";import{WORKTREE_ACTIONS as t,WORKTREE_ACTION_FIELDS as n}from"../../schemas/runWorktreeTool.mjs";const r=`run_worktree`,i=new Set(Object.values(t)),a=`Create and manage git worktrees, each with its own DoomPi session nested under this one.
2
+
3
+ Actions:
4
+ - spawn_worktree: create a worktree on a new branch and start a session in it. Requires 'branch'. Optional 'baseRef' (defaults to the current branch), 'name' for the rail, 'task' as the first message.
5
+ - close_worktree: stop a worktree's session and delete its directory. Requires 'id'. Refuses a dirty tree unless 'force' is true.
6
+ - list: every worktree for this repository, with status.
7
+ - status: one worktree and its uncommitted files. Requires 'id'.
8
+ - merge: merge a worktree's branch into this checkout. Requires 'id'. Refuses when this checkout is dirty.
9
+ - prune: remove orphaned worktrees. Pass 'dryRun' to see the plan without destroying anything.
10
+ - send: send a message to the other side of a worktree. Requires 'id' and 'message'.
11
+ - messages: read messages waiting for you from a worktree. Requires 'id'.
12
+
13
+ Worktrees live outside the repository, under ~/.pi/.doom/git/worktrees.`;function o(r){if(typeof r!=`object`||!r||Array.isArray(r))throw e(`run_worktree parameters must be an object.`,`Call it with one documented action shape.`);let a=r,o=a.action;if(typeof o!=`string`||!i.has(o))throw e(`Unknown action ${typeof o==`string`?`'${o}'`:`value`}.`,`Use one of: ${[...i].join(`, `)}.`);let s=n[o],c=Object.keys(a).filter(e=>!s.includes(e));if(c.length>0)throw e(`action='${o}' does not accept: ${c.join(`, `)}.`,`Fields for '${o}': ${s.join(`, `)}.`);for(let t of[`branch`,`id`])if(s.includes(t)&&t in a){let n=a[t];if(typeof n!=`string`||n.trim()===``)throw e(`action='${o}' requires a nonblank '${t}'.`,`Pass a ${t}.`)}for(let t of[`baseRef`,`name`,`task`,`message`])if(t in a&&(typeof a[t]!=`string`||a[t].trim()===``))throw e(`action='${o}' requires a nonblank '${t}'.`,`Pass a ${t}.`);for(let t of[`force`,`dryRun`])if(t in a&&typeof a[t]!=`boolean`)throw e(`action='${o}' requires boolean '${t}'.`,`Pass true or false for ${t}.`);if(o===t.send&&typeof a.message!=`string`)throw e(`action='send' requires 'message'.`,`Pass the message to send.`);if(o===t.spawn_worktree&&typeof a.branch!=`string`)throw e(`action='spawn_worktree' requires 'branch'.`,`Name the branch to create.`);if((o===t.close_worktree||o===t.status||o===t.merge||o===t.send||o===t.messages)&&typeof a.id!=`string`)throw e(`action='${o}' requires 'id'.`,`Call list to see the current ids.`);return a}function s(e){return`${e.id} ${e.branch} ${e.status} ${e.path}`}function c(...e){return[{type:`text`,text:e.join(`
14
+ `)}]}async function l(e,n,r,i={}){switch(e.action){case t.spawn_worktree:{let t=await n.spawn(r,{branch:e.branch,...e.baseRef===void 0?{}:{baseRef:e.baseRef},...e.name===void 0?{}:{name:e.name}},i);return{content:c(`Worktree ${t.id} created on ${t.branch} from ${t.baseRef}.`,`Path: ${t.path}`,`Session ${t.sessionId} is starting; it appears nested under this one in the rail.`),details:{action:e.action,records:[t]}}}case t.close_worktree:{let t=await n.close(r,e.id,e.force??!1);return{content:c(`Worktree ${t.id} (${t.branch}) closed and removed.`),details:{action:e.action,records:[t]}}}case t.list:{let t=await n.list(r);return{content:t.length===0?c(`No worktrees for this repository.`):c(`${String(t.length)} worktree(s):`,...t.map(s)),details:{action:e.action,records:t}}}case t.status:{let{record:t,dirtyFiles:i}=await n.status(r,e.id);return{content:c(s(t),`Session: ${t.sessionId}`,i.length===0?`Clean.`:`${String(i.length)} uncommitted file(s): ${i.slice(0,20).join(`, `)}`),details:{action:e.action,records:[t]}}}case t.merge:{let t=await n.merge(r,e.id,...e.message===void 0?[]:[e.message]);return{content:c(`Merged ${t.branch} into this checkout.`),details:{action:e.action,records:[t]}}}case t.send:return await n.send(r,e.id,e.message),{content:c(`Message sent to worktree ${e.id}.`),details:{action:e.action}};case t.messages:{let t=await n.messages(r,e.id);return{content:t.length===0?c(`No messages.`):c(`${String(t.length)} message(s):`,...t.map(e=>`[${e.sentAt}] ${e.from}: ${e.text}`)),details:{action:e.action}}}case t.prune:{let t=e.dryRun??!1,i=await n.prune(r,t);return{content:c(t?`Prune plan (nothing was changed):`:`Pruned:`,`Remove: ${i.remove.length===0?`none`:i.remove.map(e=>e.id).join(`, `)}`,`Forget: ${i.forget.length===0?`none`:i.forget.map(e=>e.id).join(`, `)}`,`Kept, uncommitted work: ${i.keptDirty.length===0?`none`:i.keptDirty.map(e=>e.id).join(`, `)}`,`Untracked directories, left alone: ${i.untracked.length===0?`none`:i.untracked.join(`, `)}`,...i.keptBranches.length===0?[]:[`Branches kept, they hold commits: ${i.keptBranches.join(`, `)}`]),details:{action:e.action}}}}}export{a as RUN_WORKTREE_DESCRIPTION,r as RUN_WORKTREE_TOOL_NAME,l as executeRunWorktreeTool,o as validateParams};
15
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/runWorktree/index.ts"],"sourcesContent":["import {\n RunWorktreeParams,\n WORKTREE_ACTION_FIELDS,\n WORKTREE_ACTIONS,\n type WorktreeAction,\n type RunWorktreeToolParams,\n} from '../../schemas/runWorktreeTool';\nimport type { WorktreeRecord } from '../../types/worktreeRegistry';\nimport { invalidRequest } from '../errors';\nimport type { WorktreeOperations } from '../worktreeOperations';\n\nexport { RunWorktreeParams };\nexport type { RunWorktreeToolParams, WorktreeAction };\n\nexport const RUN_WORKTREE_TOOL_NAME = 'run_worktree';\n\nconst IMPLEMENTED_ACTIONS: ReadonlySet<string> = new Set(Object.values(WORKTREE_ACTIONS));\n\nexport const RUN_WORKTREE_DESCRIPTION = `Create and manage git worktrees, each with its own DoomPi session nested under this one.\n\nActions:\n- spawn_worktree: create a worktree on a new branch and start a session in it. Requires 'branch'. Optional 'baseRef' (defaults to the current branch), 'name' for the rail, 'task' as the first message.\n- close_worktree: stop a worktree's session and delete its directory. Requires 'id'. Refuses a dirty tree unless 'force' is true.\n- list: every worktree for this repository, with status.\n- status: one worktree and its uncommitted files. Requires 'id'.\n- merge: merge a worktree's branch into this checkout. Requires 'id'. Refuses when this checkout is dirty.\n- prune: remove orphaned worktrees. Pass 'dryRun' to see the plan without destroying anything.\n- send: send a message to the other side of a worktree. Requires 'id' and 'message'.\n- messages: read messages waiting for you from a worktree. Requires 'id'.\n\nWorktrees live outside the repository, under ~/.pi/.doom/git/worktrees.`;\n\nexport interface RunWorktreeToolDetails {\n action: WorktreeAction;\n records?: WorktreeRecord[];\n}\n\nexport interface RunWorktreeToolResult {\n content: [{ type: 'text'; text: string }];\n details: RunWorktreeToolDetails;\n}\n\nexport interface RunWorktreeExecutionContext {\n readonly cwd: string;\n readonly sessionId: string;\n}\n\nexport interface RunWorktreeExecutionOptions {\n readonly signal?: AbortSignal;\n readonly onProgress?: (label: string) => void;\n}\n\n/** Rejects calls that do not match one documented action shape. */\nexport function validateParams(input: unknown): RunWorktreeToolParams {\n if (typeof input !== 'object' || input === null || Array.isArray(input)) {\n throw invalidRequest('run_worktree parameters must be an object.', 'Call it with one documented action shape.');\n }\n const record = input as Record<string, unknown>;\n const action = record.action;\n if (typeof action !== 'string' || !IMPLEMENTED_ACTIONS.has(action)) {\n throw invalidRequest(\n `Unknown action ${typeof action === 'string' ? `'${action}'` : 'value'}.`,\n `Use one of: ${[...IMPLEMENTED_ACTIONS].join(', ')}.`,\n );\n }\n const allowed = WORKTREE_ACTION_FIELDS[action as WorktreeAction];\n const unexpected = Object.keys(record).filter((key) => !allowed.includes(key));\n if (unexpected.length > 0) {\n throw invalidRequest(\n `action='${action}' does not accept: ${unexpected.join(', ')}.`,\n `Fields for '${action}': ${allowed.join(', ')}.`,\n );\n }\n for (const field of ['branch', 'id'] as const) {\n if (allowed.includes(field) && field in record) {\n const value = record[field];\n if (typeof value !== 'string' || value.trim() === '') {\n throw invalidRequest(`action='${action}' requires a nonblank '${field}'.`, `Pass a ${field}.`);\n }\n }\n }\n const stringFields = ['baseRef', 'name', 'task', 'message'] as const;\n for (const field of stringFields) {\n if (field in record && (typeof record[field] !== 'string' || record[field].trim() === '')) {\n throw invalidRequest(`action='${action}' requires a nonblank '${field}'.`, `Pass a ${field}.`);\n }\n }\n for (const field of ['force', 'dryRun'] as const) {\n if (field in record && typeof record[field] !== 'boolean') {\n throw invalidRequest(`action='${action}' requires boolean '${field}'.`, `Pass true or false for ${field}.`);\n }\n }\n if (action === WORKTREE_ACTIONS.send && typeof record.message !== 'string') {\n throw invalidRequest(\"action='send' requires 'message'.\", 'Pass the message to send.');\n }\n if (action === WORKTREE_ACTIONS.spawn_worktree && typeof record.branch !== 'string') {\n throw invalidRequest(\"action='spawn_worktree' requires 'branch'.\", 'Name the branch to create.');\n }\n if (\n (action === WORKTREE_ACTIONS.close_worktree ||\n action === WORKTREE_ACTIONS.status ||\n action === WORKTREE_ACTIONS.merge ||\n action === WORKTREE_ACTIONS.send ||\n action === WORKTREE_ACTIONS.messages) &&\n typeof record.id !== 'string'\n ) {\n throw invalidRequest(`action='${action}' requires 'id'.`, 'Call list to see the current ids.');\n }\n return record as RunWorktreeToolParams;\n}\n\nfunction describe(record: WorktreeRecord): string {\n return `${record.id} ${record.branch} ${record.status} ${record.path}`;\n}\n\nfunction text(...lines: readonly string[]): [{ type: 'text'; text: string }] {\n return [{ type: 'text', text: lines.join('\\n') }];\n}\n\nexport async function executeRunWorktreeTool(\n params: RunWorktreeToolParams,\n operations: WorktreeOperations,\n context: RunWorktreeExecutionContext,\n options: RunWorktreeExecutionOptions = {},\n): Promise<RunWorktreeToolResult> {\n switch (params.action) {\n case WORKTREE_ACTIONS.spawn_worktree: {\n const record = await operations.spawn(\n context,\n {\n branch: params.branch,\n ...(params.baseRef === undefined ? {} : { baseRef: params.baseRef }),\n ...(params.name === undefined ? {} : { name: params.name }),\n },\n options,\n );\n return {\n content: text(\n `Worktree ${record.id} created on ${record.branch} from ${record.baseRef}.`,\n `Path: ${record.path}`,\n `Session ${record.sessionId} is starting; it appears nested under this one in the rail.`,\n ),\n details: { action: params.action, records: [record] },\n };\n }\n case WORKTREE_ACTIONS.close_worktree: {\n const record = await operations.close(context, params.id, params.force ?? false);\n return {\n content: text(`Worktree ${record.id} (${record.branch}) closed and removed.`),\n details: { action: params.action, records: [record] },\n };\n }\n case WORKTREE_ACTIONS.list: {\n const records = await operations.list(context);\n return {\n content:\n records.length === 0\n ? text('No worktrees for this repository.')\n : text(`${String(records.length)} worktree(s):`, ...records.map(describe)),\n details: { action: params.action, records },\n };\n }\n case WORKTREE_ACTIONS.status: {\n const { record, dirtyFiles } = await operations.status(context, params.id);\n return {\n content: text(\n describe(record),\n `Session: ${record.sessionId}`,\n dirtyFiles.length === 0\n ? 'Clean.'\n : `${String(dirtyFiles.length)} uncommitted file(s): ${dirtyFiles.slice(0, 20).join(', ')}`,\n ),\n details: { action: params.action, records: [record] },\n };\n }\n case WORKTREE_ACTIONS.merge: {\n const record = await operations.merge(\n context,\n params.id,\n ...(params.message === undefined ? [] : ([params.message] as const)),\n );\n return {\n content: text(`Merged ${record.branch} into this checkout.`),\n details: { action: params.action, records: [record] },\n };\n }\n case WORKTREE_ACTIONS.send: {\n await operations.send(context, params.id, params.message);\n return { content: text(`Message sent to worktree ${params.id}.`), details: { action: params.action } };\n }\n case WORKTREE_ACTIONS.messages: {\n const waiting = await operations.messages(context, params.id);\n return {\n content:\n waiting.length === 0\n ? text('No messages.')\n : text(\n `${String(waiting.length)} message(s):`,\n ...waiting.map((entry) => `[${entry.sentAt}] ${entry.from}: ${entry.text}`),\n ),\n details: { action: params.action },\n };\n }\n case WORKTREE_ACTIONS.prune: {\n const dryRun = params.dryRun ?? false;\n const plan = await operations.prune(context, dryRun);\n const lines = [\n dryRun ? 'Prune plan (nothing was changed):' : 'Pruned:',\n `Remove: ${plan.remove.length === 0 ? 'none' : plan.remove.map((record) => record.id).join(', ')}`,\n `Forget: ${plan.forget.length === 0 ? 'none' : plan.forget.map((record) => record.id).join(', ')}`,\n `Kept, uncommitted work: ${plan.keptDirty.length === 0 ? 'none' : plan.keptDirty.map((record) => record.id).join(', ')}`,\n `Untracked directories, left alone: ${plan.untracked.length === 0 ? 'none' : plan.untracked.join(', ')}`,\n ...(plan.keptBranches.length === 0\n ? []\n : [`Branches kept, they hold commits: ${plan.keptBranches.join(', ')}`]),\n ];\n return { content: text(...lines), details: { action: params.action } };\n }\n }\n}\n"],"mappings":"sJAcA,MAAa,EAAyB,eAEhC,EAA2C,IAAI,IAAI,OAAO,OAAO,CAAgB,CAAC,EAE3E,EAA2B;;;;;;;;;;;;yEAmCxC,SAAgB,EAAe,EAAuC,CACpE,GAAI,OAAO,GAAU,WAAY,GAAkB,MAAM,QAAQ,CAAK,EACpE,M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G,OAAO,EAAQ,MAAM,EAAE,cAC1B,GAAG,EAAQ,IAAK,GAAU,IAAI,EAAM,OAAO,IAAI,EAAM,KAAK,IAAI,EAAM,MAAM,CAC5E,EACN,QAAS,CAAE,OAAQ,EAAO,MAAO,CACnC,CACF,CACA,KAAK,EAAiB,MAAO,CAC3B,IAAM,EAAS,EAAO,QAAU,GAC1B,EAAO,MAAM,EAAW,MAAM,EAAS,CAAM,EAWnD,MAAO,CAAE,QAAS,EAThB,EAAS,oCAAsC,UAC/C,WAAW,EAAK,OAAO,SAAW,EAAI,OAAS,EAAK,OAAO,IAAK,GAAW,EAAO,EAAE,CAAC,CAAC,KAAK,IAAI,IAC/F,WAAW,EAAK,OAAO,SAAW,EAAI,OAAS,EAAK,OAAO,IAAK,GAAW,EAAO,EAAE,CAAC,CAAC,KAAK,IAAI,IAC/F,2BAA2B,EAAK,UAAU,SAAW,EAAI,OAAS,EAAK,UAAU,IAAK,GAAW,EAAO,EAAE,CAAC,CAAC,KAAK,IAAI,IACrH,sCAAsC,EAAK,UAAU,SAAW,EAAI,OAAS,EAAK,UAAU,KAAK,IAAI,IACrG,GAAI,EAAK,aAAa,SAAW,EAC7B,CAAC,EACD,CAAC,qCAAqC,EAAK,aAAa,KAAK,IAAI,GAAG,CAE3C,EAAG,QAAS,CAAE,OAAQ,EAAO,MAAO,CAAE,CACvE,CACF,CACF"}
@@ -0,0 +1,2 @@
1
+ const e=`git_worktree_message`;function t(e){return e===`parent`||e===`child`}function n(e){if(typeof e!=`object`||!e)return;let n=e;if(n.version===1&&typeof n.worktreeId==`string`&&n.worktreeId!==``&&typeof n.fromSessionId==`string`&&n.fromSessionId!==``&&t(n.from)&&typeof n.text==`string`&&n.text!==``&&!(Buffer.byteLength(n.text,`utf8`)>65536)&&typeof n.sentAt==`string`&&n.sentAt!==``)return n}function r(t,r){if(r===``)throw Error(`The Git message service requires a session identity.`);let i=new Map,a=t.subscribe(e,r,e=>{let t=n(e);if(t===void 0)return;let r=i.get(t.worktreeId)??[];r.length>=100&&r.shift(),r.push(t),i.set(t.worktreeId,r)}),o=!1;return{send(n,r){if(o)throw Error(`The Git message service is closed.`);t.publish(e,n,r)},receive(e){if(o)return[];let t=i.get(e);return t===void 0?[]:(i.delete(e),t)},close(){o||(o=!0,a(),i.clear())}}}function i(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.version===1&&typeof t.repositoryRoot==`string`&&t.repositoryRoot!==``}exports.GIT_WORKTREE_LIFECYCLE_EVENT=`git_worktree_lifecycle`,exports.GIT_WORKTREE_MESSAGE_EVENT=e,exports.MAX_WORKTREE_MESSAGE_BYTES=65536,exports.createWorktreeMessageInbox=r,exports.isWorktreeLifecycleEvent=i;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../src/services/worktreeEvents/index.ts"],"sourcesContent":["import type { DoomDirectEventBus } from '@agimon-ai/doompi-core/hub-channel';\n\nexport const GIT_WORKTREE_LIFECYCLE_EVENT = 'git_worktree_lifecycle';\nexport const GIT_WORKTREE_MESSAGE_EVENT = 'git_worktree_message';\nexport const WORKTREE_MESSAGE_VERSION = 1 as const;\nexport const MAX_WORKTREE_MESSAGE_BYTES = 64 * 1024;\nexport const MAX_WORKTREE_INBOX_MESSAGES = 100;\n\nexport interface WorktreeLifecycleEvent {\n readonly version: typeof WORKTREE_MESSAGE_VERSION;\n readonly repositoryRoot: string;\n}\n\nexport type WorktreeMessageParty = 'parent' | 'child';\n\nexport interface WorktreeMessage {\n readonly version: typeof WORKTREE_MESSAGE_VERSION;\n readonly worktreeId: string;\n readonly fromSessionId: string;\n readonly from: WorktreeMessageParty;\n readonly text: string;\n readonly sentAt: string;\n}\n\nexport interface WorktreeMessageInbox {\n send(targetSessionId: string, message: WorktreeMessage): void;\n receive(worktreeId: string): WorktreeMessage[];\n close(): void;\n}\n\nfunction isMessageParty(value: unknown): value is WorktreeMessageParty {\n return value === 'parent' || value === 'child';\n}\n\nfunction parseMessage(value: unknown): WorktreeMessage | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const record = value as Partial<WorktreeMessage>;\n if (record.version !== WORKTREE_MESSAGE_VERSION) return undefined;\n if (typeof record.worktreeId !== 'string' || record.worktreeId === '') return undefined;\n if (typeof record.fromSessionId !== 'string' || record.fromSessionId === '') return undefined;\n if (!isMessageParty(record.from)) return undefined;\n if (typeof record.text !== 'string' || record.text === '') return undefined;\n if (Buffer.byteLength(record.text, 'utf8') > MAX_WORKTREE_MESSAGE_BYTES) return undefined;\n if (typeof record.sentAt !== 'string' || record.sentAt === '') return undefined;\n return record as WorktreeMessage;\n}\n\nexport function createWorktreeMessageInbox(directEvents: DoomDirectEventBus, sessionId: string): WorktreeMessageInbox {\n if (sessionId === '') throw new Error('The Git message service requires a session identity.');\n const messages = new Map<string, WorktreeMessage[]>();\n const unsubscribe = directEvents.subscribe(GIT_WORKTREE_MESSAGE_EVENT, sessionId, (payload) => {\n const message = parseMessage(payload);\n if (message === undefined) return;\n const inbox = messages.get(message.worktreeId) ?? [];\n if (inbox.length >= MAX_WORKTREE_INBOX_MESSAGES) inbox.shift();\n inbox.push(message);\n messages.set(message.worktreeId, inbox);\n });\n let closed = false;\n return {\n send(targetSessionId, message) {\n if (closed) throw new Error('The Git message service is closed.');\n directEvents.publish(GIT_WORKTREE_MESSAGE_EVENT, targetSessionId, message);\n },\n receive(worktreeId) {\n if (closed) return [];\n const inbox = messages.get(worktreeId);\n if (inbox === undefined) return [];\n messages.delete(worktreeId);\n return inbox;\n },\n close() {\n if (closed) return;\n closed = true;\n unsubscribe();\n messages.clear();\n },\n };\n}\n\nexport function isWorktreeLifecycleEvent(value: unknown): value is WorktreeLifecycleEvent {\n if (typeof value !== 'object' || value === null) return false;\n const record = value as Partial<WorktreeLifecycleEvent>;\n return (\n record.version === WORKTREE_MESSAGE_VERSION &&\n typeof record.repositoryRoot === 'string' &&\n record.repositoryRoot !== ''\n );\n}\n"],"mappings":"AAEA,MACa,EA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gB,MAAO,GACxD,IAAM,EAAS,EACf,OACE,EAAO,UAAA,GACP,OAAO,EAAO,gBAAmB,UACjC,EAAO,iBAAmB,EAE9B"}
@@ -0,0 +1,15 @@
1
+ import "@agimon-ai/doompi-core/hub-channel";
2
+ //#region src/services/worktreeEvents/index.d.ts
3
+ declare const WORKTREE_MESSAGE_VERSION: 1;
4
+ type WorktreeMessageParty = 'parent' | 'child';
5
+ interface WorktreeMessage {
6
+ readonly version: typeof WORKTREE_MESSAGE_VERSION;
7
+ readonly worktreeId: string;
8
+ readonly fromSessionId: string;
9
+ readonly from: WorktreeMessageParty;
10
+ readonly text: string;
11
+ readonly sentAt: string;
12
+ }
13
+ //#endregion
14
+ export { WORKTREE_MESSAGE_VERSION, WorktreeMessage, WorktreeMessageParty };
15
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../../src/services/worktreeEvents/index.ts"],"mappings":";;cAIa;KASD;UAEK;WACN,gBAAgB;WAChB;WACA;WACA,MAAM;WACN;WACA"}
@@ -0,0 +1,15 @@
1
+ import "@agimon-ai/doompi-core/hub-channel";
2
+ //#region src/services/worktreeEvents/index.d.ts
3
+ declare const WORKTREE_MESSAGE_VERSION: 1;
4
+ type WorktreeMessageParty = 'parent' | 'child';
5
+ interface WorktreeMessage {
6
+ readonly version: typeof WORKTREE_MESSAGE_VERSION;
7
+ readonly worktreeId: string;
8
+ readonly fromSessionId: string;
9
+ readonly from: WorktreeMessageParty;
10
+ readonly text: string;
11
+ readonly sentAt: string;
12
+ }
13
+ //#endregion
14
+ export { WORKTREE_MESSAGE_VERSION, WorktreeMessage, WorktreeMessageParty };
15
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/worktreeEvents/index.ts"],"mappings":";;cAIa;KASD;UAEK;WACN,gBAAgB;WAChB;WACA;WACA,MAAM;WACN;WACA"}
@@ -0,0 +1,2 @@
1
+ const e=`git_worktree_lifecycle`,t=`git_worktree_message`,n=65536;function r(e){return e===`parent`||e===`child`}function i(e){if(typeof e!=`object`||!e)return;let t=e;if(t.version===1&&typeof t.worktreeId==`string`&&t.worktreeId!==``&&typeof t.fromSessionId==`string`&&t.fromSessionId!==``&&r(t.from)&&typeof t.text==`string`&&t.text!==``&&!(Buffer.byteLength(t.text,`utf8`)>65536)&&typeof t.sentAt==`string`&&t.sentAt!==``)return t}function a(e,n){if(n===``)throw Error(`The Git message service requires a session identity.`);let r=new Map,a=e.subscribe(t,n,e=>{let t=i(e);if(t===void 0)return;let n=r.get(t.worktreeId)??[];n.length>=100&&n.shift(),n.push(t),r.set(t.worktreeId,n)}),o=!1;return{send(n,r){if(o)throw Error(`The Git message service is closed.`);e.publish(t,n,r)},receive(e){if(o)return[];let t=r.get(e);return t===void 0?[]:(r.delete(e),t)},close(){o||(o=!0,a(),r.clear())}}}function o(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.version===1&&typeof t.repositoryRoot==`string`&&t.repositoryRoot!==``}export{e as GIT_WORKTREE_LIFECYCLE_EVENT,t as GIT_WORKTREE_MESSAGE_EVENT,n as MAX_WORKTREE_MESSAGE_BYTES,a as createWorktreeMessageInbox,o as isWorktreeLifecycleEvent};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/worktreeEvents/index.ts"],"sourcesContent":["import type { DoomDirectEventBus } from '@agimon-ai/doompi-core/hub-channel';\n\nexport const GIT_WORKTREE_LIFECYCLE_EVENT = 'git_worktree_lifecycle';\nexport const GIT_WORKTREE_MESSAGE_EVENT = 'git_worktree_message';\nexport const WORKTREE_MESSAGE_VERSION = 1 as const;\nexport const MAX_WORKTREE_MESSAGE_BYTES = 64 * 1024;\nexport const MAX_WORKTREE_INBOX_MESSAGES = 100;\n\nexport interface WorktreeLifecycleEvent {\n readonly version: typeof WORKTREE_MESSAGE_VERSION;\n readonly repositoryRoot: string;\n}\n\nexport type WorktreeMessageParty = 'parent' | 'child';\n\nexport interface WorktreeMessage {\n readonly version: typeof WORKTREE_MESSAGE_VERSION;\n readonly worktreeId: string;\n readonly fromSessionId: string;\n readonly from: WorktreeMessageParty;\n readonly text: string;\n readonly sentAt: string;\n}\n\nexport interface WorktreeMessageInbox {\n send(targetSessionId: string, message: WorktreeMessage): void;\n receive(worktreeId: string): WorktreeMessage[];\n close(): void;\n}\n\nfunction isMessageParty(value: unknown): value is WorktreeMessageParty {\n return value === 'parent' || value === 'child';\n}\n\nfunction parseMessage(value: unknown): WorktreeMessage | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const record = value as Partial<WorktreeMessage>;\n if (record.version !== WORKTREE_MESSAGE_VERSION) return undefined;\n if (typeof record.worktreeId !== 'string' || record.worktreeId === '') return undefined;\n if (typeof record.fromSessionId !== 'string' || record.fromSessionId === '') return undefined;\n if (!isMessageParty(record.from)) return undefined;\n if (typeof record.text !== 'string' || record.text === '') return undefined;\n if (Buffer.byteLength(record.text, 'utf8') > MAX_WORKTREE_MESSAGE_BYTES) return undefined;\n if (typeof record.sentAt !== 'string' || record.sentAt === '') return undefined;\n return record as WorktreeMessage;\n}\n\nexport function createWorktreeMessageInbox(directEvents: DoomDirectEventBus, sessionId: string): WorktreeMessageInbox {\n if (sessionId === '') throw new Error('The Git message service requires a session identity.');\n const messages = new Map<string, WorktreeMessage[]>();\n const unsubscribe = directEvents.subscribe(GIT_WORKTREE_MESSAGE_EVENT, sessionId, (payload) => {\n const message = parseMessage(payload);\n if (message === undefined) return;\n const inbox = messages.get(message.worktreeId) ?? [];\n if (inbox.length >= MAX_WORKTREE_INBOX_MESSAGES) inbox.shift();\n inbox.push(message);\n messages.set(message.worktreeId, inbox);\n });\n let closed = false;\n return {\n send(targetSessionId, message) {\n if (closed) throw new Error('The Git message service is closed.');\n directEvents.publish(GIT_WORKTREE_MESSAGE_EVENT, targetSessionId, message);\n },\n receive(worktreeId) {\n if (closed) return [];\n const inbox = messages.get(worktreeId);\n if (inbox === undefined) return [];\n messages.delete(worktreeId);\n return inbox;\n },\n close() {\n if (closed) return;\n closed = true;\n unsubscribe();\n messages.clear();\n },\n };\n}\n\nexport function isWorktreeLifecycleEvent(value: unknown): value is WorktreeLifecycleEvent {\n if (typeof value !== 'object' || value === null) return false;\n const record = value as Partial<WorktreeLifecycleEvent>;\n return (\n record.version === WORKTREE_MESSAGE_VERSION &&\n typeof record.repositoryRoot === 'string' &&\n record.repositoryRoot !== ''\n );\n}\n"],"mappings":"AAEA,MAAa,EAA+B,yBAC/B,EAA6B,uBAE7B,EAA6B,MAyB1C,SAAS,EAAe,EAA+C,CACrE,OAAO,IAAU,UAAY,IAAU,OACzC,CAEA,SAAS,EAAa,EAA6C,CACjE,GAAI,OAAO,GAAU,WAAY,EAAgB,OACjD,IAAM,EAAS,EACX,KAAO,UAAA,GACP,OAAO,EAAO,YAAe,UAAY,EAAO,aAAe,IAC/D,OAAO,EAAO,eAAkB,UAAY,EAAO,gBAAkB,IACpE,EAAe,EAAO,IAAI,GAC3B,OAAO,EAAO,MAAS,UAAY,EAAO,OAAS,IACnD,SAAO,WAAW,EAAO,KAAM,MAAM,EAAA,QACrC,OAAO,EAAO,QAAW,UAAY,EAAO,SAAW,GAC3D,OAAO,CACT,CAEA,SAAgB,EAA2B,EAAkC,EAAyC,CACpH,GAAI,IAAc,GAAI,MAAU,MAAM,sDAAsD,EAC5F,IAAM,EAAW,IAAI,IACf,EAAc,EAAa,UAAU,EAA4B,EAAY,GAAY,CAC7F,IAAM,EAAU,EAAa,CAAO,EACpC,GAAI,IAAY,IAAA,GAAW,OAC3B,IAAM,EAAQ,EAAS,IAAI,EAAQ,UAAU,GAAK,CAAC,EAC/C,EAAM,QAAA,KAAuC,EAAM,MAAM,EAC7D,EAAM,KAAK,CAAO,EAClB,EAAS,IAAI,EAAQ,WAAY,CAAK,CACxC,CAAC,EACG,EAAS,GACb,MAAO,CACL,KAAK,EAAiB,EAAS,CAC7B,GAAI,EAAQ,MAAU,MAAM,oCAAoC,EAChE,EAAa,QAAQ,EAA4B,EAAiB,CAAO,CAC3E,EACA,QAAQ,EAAY,CAClB,GAAI,EAAQ,MAAO,CAAC,EACpB,IAAM,EAAQ,EAAS,IAAI,CAAU,EAGrC,OAFI,IAAU,IAAA,GAAkB,CAAC,GACjC,EAAS,OAAO,CAAU,EACnB,EACT,EACA,OAAQ,CACF,IACJ,EAAS,GACT,EAAY,EACZ,EAAS,MAAM,EACjB,CACF,CACF,CAEA,SAAgB,EAAyB,EAAiD,CACxF,GAAI,OAAO,GAAU,WAAY,EAAgB,MAAO,GACxD,IAAM,EAAS,EACf,OACE,EAAO,UAAA,GACP,OAAO,EAAO,gBAAmB,UACjC,EAAO,iBAAmB,EAE9B"}
@@ -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}exports.branchSlug=e,exports.planPrune=a,exports.reconcile=i,exports.refuseClose=r,exports.refuseSpawn=n,exports.worktreeDirectory=t;
2
- //# sourceMappingURL=worktreeNaming.cjs.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}exports.branchSlug=e,exports.planPrune=a,exports.reconcile=i,exports.refuseClose=r,exports.refuseSpawn=n,exports.worktreeDirectory=t;
2
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"worktreeNaming.cjs","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.cjs","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,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