@neuralnomads/codenomad-dev 0.20.0-dev-20260917-aa51cbb9 → 0.20.0-dev-20260918-a311de98

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 (223) hide show
  1. package/dist/api-types.js.map +1 -1
  2. package/dist/events/bus.js +2 -0
  3. package/dist/events/bus.js.map +1 -1
  4. package/dist/filesystem/__tests__/browser.test.js +10 -10
  5. package/dist/filesystem/__tests__/browser.test.js.map +1 -1
  6. package/dist/filesystem/__tests__/responsiveness.test.js +79 -0
  7. package/dist/filesystem/__tests__/responsiveness.test.js.map +1 -0
  8. package/dist/filesystem/__tests__/search-cache.test.js +48 -9
  9. package/dist/filesystem/__tests__/search-cache.test.js.map +1 -1
  10. package/dist/filesystem/__tests__/search.test.js +8 -8
  11. package/dist/filesystem/__tests__/search.test.js.map +1 -1
  12. package/dist/filesystem/__tests__/write-order.test.js +64 -0
  13. package/dist/filesystem/__tests__/write-order.test.js.map +1 -0
  14. package/dist/filesystem/browser.js +44 -46
  15. package/dist/filesystem/browser.js.map +1 -1
  16. package/dist/filesystem/file-access.js +19 -0
  17. package/dist/filesystem/file-access.js.map +1 -0
  18. package/dist/filesystem/search-cache.js +35 -9
  19. package/dist/filesystem/search-cache.js.map +1 -1
  20. package/dist/filesystem/search.js +9 -8
  21. package/dist/filesystem/search.js.map +1 -1
  22. package/dist/index.js +28 -18
  23. package/dist/index.js.map +1 -1
  24. package/dist/opencode/automation/desktop-plugin.js +69 -0
  25. package/dist/opencode/automation/desktop-plugin.js.map +1 -0
  26. package/dist/opencode/automation/desktop-plugin.test.js +155 -0
  27. package/dist/opencode/automation/desktop-plugin.test.js.map +1 -0
  28. package/dist/opencode/automation-plugin.js +90 -24
  29. package/dist/opencode/automation-plugin.js.map +1 -1
  30. package/dist/opencode/automation-plugin.test.js +14 -1
  31. package/dist/opencode/automation-plugin.test.js.map +1 -1
  32. package/dist/opencode/compatibility/contract-fixture.js +13 -1
  33. package/dist/opencode/compatibility/contract-fixture.js.map +1 -1
  34. package/dist/opencode/compatibility/location.js +13 -0
  35. package/dist/opencode/compatibility/location.js.map +1 -1
  36. package/dist/opencode/compatibility/location.test.js +44 -0
  37. package/dist/opencode/compatibility/location.test.js.map +1 -1
  38. package/dist/opencode/compatibility/runtime.js.map +1 -1
  39. package/dist/opencode/compatibility/transport.js +3 -0
  40. package/dist/opencode/compatibility/transport.js.map +1 -1
  41. package/dist/opencode/compatibility/transport.test.js +40 -0
  42. package/dist/opencode/compatibility/transport.test.js.map +1 -1
  43. package/dist/opencode/desktop-plugin-installation.js +103 -0
  44. package/dist/opencode/desktop-plugin-installation.js.map +1 -0
  45. package/dist/opencode/desktop-plugin-lifecycle.js +117 -0
  46. package/dist/opencode/desktop-plugin-lifecycle.js.map +1 -0
  47. package/dist/opencode/desktop-plugin-lifecycle.test.js +180 -0
  48. package/dist/opencode/desktop-plugin-lifecycle.test.js.map +1 -0
  49. package/dist/opencode/desktop-plugin-paths.js +30 -0
  50. package/dist/opencode/desktop-plugin-paths.js.map +1 -0
  51. package/dist/opencode/desktop-plugin-paths.test.js +46 -0
  52. package/dist/opencode/desktop-plugin-paths.test.js.map +1 -0
  53. package/dist/opencode/desktop-plugin-presence.js +42 -0
  54. package/dist/opencode/desktop-plugin-presence.js.map +1 -0
  55. package/dist/opencode/pruning-installation.js +3 -63
  56. package/dist/opencode/pruning-installation.js.map +1 -1
  57. package/dist/opencode/pruning-lifecycle.js +3 -64
  58. package/dist/opencode/pruning-lifecycle.js.map +1 -1
  59. package/dist/opencode/session-pruning/presence.js +1 -41
  60. package/dist/opencode/session-pruning/presence.js.map +1 -1
  61. package/dist/permissions/opencode-yolo-metadata.js +3 -1
  62. package/dist/permissions/opencode-yolo-metadata.js.map +1 -1
  63. package/dist/permissions/opencode-yolo-metadata.test.js +2 -2
  64. package/dist/permissions/opencode-yolo-metadata.test.js.map +1 -1
  65. package/dist/plugins/automation/plugin.mjs +504 -0
  66. package/dist/plugins/session-pruning/plugin.mjs +1 -1
  67. package/dist/server/routes/automation-plugin.js +31 -4
  68. package/dist/server/routes/automation-plugin.js.map +1 -1
  69. package/dist/server/routes/automation-plugin.test.js +46 -0
  70. package/dist/server/routes/automation-plugin.test.js.map +1 -1
  71. package/dist/server/routes/filesystem.js +3 -3
  72. package/dist/server/routes/filesystem.js.map +1 -1
  73. package/dist/server/routes/workspaces.js +13 -7
  74. package/dist/server/routes/workspaces.js.map +1 -1
  75. package/dist/server/routes/workspaces.test.js +31 -0
  76. package/dist/server/routes/workspaces.test.js.map +1 -1
  77. package/dist/server/routes/worktrees.js +232 -41
  78. package/dist/server/routes/worktrees.js.map +1 -1
  79. package/dist/server/routes/worktrees.test.js +113 -40
  80. package/dist/server/routes/worktrees.test.js.map +1 -1
  81. package/dist/workspaces/__tests__/git-worktrees.test.js +2 -2
  82. package/dist/workspaces/__tests__/git-worktrees.test.js.map +1 -1
  83. package/dist/workspaces/__tests__/native-worktree-fixture.js +22 -0
  84. package/dist/workspaces/__tests__/native-worktree-fixture.js.map +1 -0
  85. package/dist/workspaces/git-status.test.js +24 -1
  86. package/dist/workspaces/git-status.test.js.map +1 -1
  87. package/dist/workspaces/git-worktrees.js +37 -204
  88. package/dist/workspaces/git-worktrees.js.map +1 -1
  89. package/dist/workspaces/host-opencode-service.test.js +58 -1
  90. package/dist/workspaces/host-opencode-service.test.js.map +1 -1
  91. package/dist/workspaces/instance-events.js +5 -0
  92. package/dist/workspaces/instance-events.js.map +1 -1
  93. package/dist/workspaces/instance-events.test.js +36 -1
  94. package/dist/workspaces/instance-events.test.js.map +1 -1
  95. package/dist/workspaces/manager.js +124 -14
  96. package/dist/workspaces/manager.js.map +1 -1
  97. package/dist/workspaces/manager.test.js +25 -0
  98. package/dist/workspaces/manager.test.js.map +1 -1
  99. package/dist/workspaces/native-service-start.js +13 -0
  100. package/dist/workspaces/native-service-start.js.map +1 -0
  101. package/dist/workspaces/native-service-start.test.js +65 -0
  102. package/dist/workspaces/native-service-start.test.js.map +1 -0
  103. package/dist/workspaces/native-worktrees.js +140 -0
  104. package/dist/workspaces/native-worktrees.js.map +1 -0
  105. package/dist/workspaces/opencode-cli-service.js +10 -2
  106. package/dist/workspaces/opencode-cli-service.js.map +1 -1
  107. package/dist/workspaces/opencode-service.js +24 -2
  108. package/dist/workspaces/opencode-service.js.map +1 -1
  109. package/dist/workspaces/opencode-service.test.js +62 -0
  110. package/dist/workspaces/opencode-service.test.js.map +1 -1
  111. package/dist/workspaces/project-session-families.js +376 -0
  112. package/dist/workspaces/project-session-families.js.map +1 -0
  113. package/dist/workspaces/project-session-families.test.js +341 -0
  114. package/dist/workspaces/project-session-families.test.js.map +1 -0
  115. package/dist/workspaces/worktree-directory.js +36 -18
  116. package/dist/workspaces/worktree-directory.js.map +1 -1
  117. package/dist/workspaces/worktree-directory.test.js +123 -5
  118. package/dist/workspaces/worktree-directory.test.js.map +1 -1
  119. package/dist/workspaces/worktree-inventory.js +79 -0
  120. package/dist/workspaces/worktree-inventory.js.map +1 -0
  121. package/dist/workspaces/worktree-inventory.test.js +156 -0
  122. package/dist/workspaces/worktree-inventory.test.js.map +1 -0
  123. package/dist/workspaces/worktree-map.js +2 -5
  124. package/dist/workspaces/worktree-map.js.map +1 -1
  125. package/dist/workspaces/wsl-opencode-service.test.js +16 -2
  126. package/dist/workspaces/wsl-opencode-service.test.js.map +1 -1
  127. package/package.json +4 -3
  128. package/public/assets/App-I9uNKt0K.js +54 -0
  129. package/public/assets/App-I9uNKt0K.js.map +1 -0
  130. package/public/assets/{FilesTab-DY3Vr-3r.js → FilesTab-_xb_Aq0c.js} +3 -3
  131. package/public/assets/{FilesTab-DY3Vr-3r.js.map → FilesTab-_xb_Aq0c.js.map} +1 -1
  132. package/public/assets/{GitChangesTab-BD6CJngE.js → GitChangesTab-Cz0RckYn.js} +3 -3
  133. package/public/assets/{GitChangesTab-BD6CJngE.js.map → GitChangesTab-Cz0RckYn.js.map} +1 -1
  134. package/public/assets/{SplitFilePanel-BdY6d_6m.js → SplitFilePanel-DVkVS5C0.js} +2 -2
  135. package/public/assets/{SplitFilePanel-BdY6d_6m.js.map → SplitFilePanel-DVkVS5C0.js.map} +1 -1
  136. package/public/assets/{StatusTab-C-_2yaPa.js → StatusTab-DU1H4ngp.js} +2 -2
  137. package/public/assets/{StatusTab-C-_2yaPa.js.map → StatusTab-DU1H4ngp.js.map} +1 -1
  138. package/public/assets/{align-justify-DI8VTZ4G.js → align-justify-Czy9hp3K.js} +2 -2
  139. package/public/assets/{align-justify-DI8VTZ4G.js.map → align-justify-Czy9hp3K.js.map} +1 -1
  140. package/public/assets/{bundle-full-D_M65Eb_.js → bundle-full-CMakdq_6.js} +2 -2
  141. package/public/assets/{bundle-full-D_M65Eb_.js.map → bundle-full-CMakdq_6.js.map} +1 -1
  142. package/public/assets/{client-state-CWCzCOz6.js → client-state-DGbupmmR.js} +2 -2
  143. package/public/assets/{client-state-CWCzCOz6.js.map → client-state-DGbupmmR.js.map} +1 -1
  144. package/public/assets/{diff-viewer-CGPsYEr3.js → diff-viewer-CSOlh3i1.js} +2 -2
  145. package/public/assets/{diff-viewer-CGPsYEr3.js.map → diff-viewer-CSOlh3i1.js.map} +1 -1
  146. package/public/assets/index-B0BLbbT3.js +2 -0
  147. package/public/assets/{index-BxRFHpJd.js.map → index-B0BLbbT3.js.map} +1 -1
  148. package/public/assets/index-B52s_Dh2.js +2 -0
  149. package/public/assets/index-B52s_Dh2.js.map +1 -0
  150. package/public/assets/index-B8W9is7z.js +2 -0
  151. package/public/assets/index-B8W9is7z.js.map +1 -0
  152. package/public/assets/index-Bn8a8ymh.js +2 -0
  153. package/public/assets/index-Bn8a8ymh.js.map +1 -0
  154. package/public/assets/index-CWaDoBhJ.js +2 -0
  155. package/public/assets/index-CWaDoBhJ.js.map +1 -0
  156. package/public/assets/{index-MeFffHqb.css → index-CXEtEGDL.css} +1 -1
  157. package/public/assets/index-CbuT2QEY.js +2 -0
  158. package/public/assets/index-CbuT2QEY.js.map +1 -0
  159. package/public/assets/{index-Ddjkirek.js → index-Cq5Hfa6i.js} +2 -2
  160. package/public/assets/{index-Ddjkirek.js.map → index-Cq5Hfa6i.js.map} +1 -1
  161. package/public/assets/index-D03eJbIp.js +2 -0
  162. package/public/assets/index-D03eJbIp.js.map +1 -0
  163. package/public/assets/index-DDK0Fk7j.js +2 -0
  164. package/public/assets/index-DDK0Fk7j.js.map +1 -0
  165. package/public/assets/index-DftCJdT3.js +2 -0
  166. package/public/assets/index-DftCJdT3.js.map +1 -0
  167. package/public/assets/index-_N9V2vB3.js +3 -0
  168. package/public/assets/index-_N9V2vB3.js.map +1 -0
  169. package/public/assets/index-zo6cKyNQ.js +2 -0
  170. package/public/assets/index-zo6cKyNQ.js.map +1 -0
  171. package/public/assets/{loading-Gqh6NPUr.js → loading-B2-6L7aO.js} +2 -2
  172. package/public/assets/{loading-Gqh6NPUr.js.map → loading-B2-6L7aO.js.map} +1 -1
  173. package/public/assets/main-pZWMgVoG.js +42 -0
  174. package/public/assets/main-pZWMgVoG.js.map +1 -0
  175. package/public/assets/{markdown-BWnjyvnX.js → markdown-CH9bocix.js} +4 -4
  176. package/public/assets/{markdown-BWnjyvnX.js.map → markdown-CH9bocix.js.map} +1 -1
  177. package/public/assets/monaco-viewer-Bv1s0h2m.js +27 -0
  178. package/public/assets/monaco-viewer-Bv1s0h2m.js.map +1 -0
  179. package/public/assets/{startup-state-settings-card-C4E2Itop.js → startup-state-settings-card-mmovljyz.js} +2 -2
  180. package/public/assets/{startup-state-settings-card-C4E2Itop.js.map → startup-state-settings-card-mmovljyz.js.map} +1 -1
  181. package/public/assets/{terminal-square-C3wutdV0.js → terminal-square-U8R46SS0.js} +2 -2
  182. package/public/assets/{terminal-square-C3wutdV0.js.map → terminal-square-U8R46SS0.js.map} +1 -1
  183. package/public/assets/tool-call-AnfwOPww.js +60 -0
  184. package/public/assets/tool-call-AnfwOPww.js.map +1 -0
  185. package/public/assets/unified-picker-DtvQUEiv.js +2 -0
  186. package/public/assets/unified-picker-DtvQUEiv.js.map +1 -0
  187. package/public/assets/{wrap-text-CkBxzt04.js → wrap-text-Bh1AU9Re.js} +2 -2
  188. package/public/assets/{wrap-text-CkBxzt04.js.map → wrap-text-Bh1AU9Re.js.map} +1 -1
  189. package/public/index.html +4 -4
  190. package/public/loading.html +4 -4
  191. package/public/sw.js +1 -1
  192. package/public/sw.js.map +1 -1
  193. package/public/assets/App-BROhwPo9.js +0 -54
  194. package/public/assets/App-BROhwPo9.js.map +0 -1
  195. package/public/assets/index-B8-lAqjr.js +0 -2
  196. package/public/assets/index-B8-lAqjr.js.map +0 -1
  197. package/public/assets/index-BeUewQym.js +0 -2
  198. package/public/assets/index-BeUewQym.js.map +0 -1
  199. package/public/assets/index-BxRFHpJd.js +0 -2
  200. package/public/assets/index-Bzv1kU-S.js +0 -2
  201. package/public/assets/index-Bzv1kU-S.js.map +0 -1
  202. package/public/assets/index-C9tI4CRG.js +0 -2
  203. package/public/assets/index-C9tI4CRG.js.map +0 -1
  204. package/public/assets/index-CGYHFZ6F.js +0 -2
  205. package/public/assets/index-CGYHFZ6F.js.map +0 -1
  206. package/public/assets/index-CMEAjBFp.js +0 -2
  207. package/public/assets/index-CMEAjBFp.js.map +0 -1
  208. package/public/assets/index-Cazypvyc.js +0 -2
  209. package/public/assets/index-Cazypvyc.js.map +0 -1
  210. package/public/assets/index-CwqzofWP.js +0 -2
  211. package/public/assets/index-CwqzofWP.js.map +0 -1
  212. package/public/assets/index-Da9yOa6q.js +0 -2
  213. package/public/assets/index-Da9yOa6q.js.map +0 -1
  214. package/public/assets/index-HHgvEOAH.js +0 -3
  215. package/public/assets/index-HHgvEOAH.js.map +0 -1
  216. package/public/assets/main-Cbx7KdTr.js +0 -38
  217. package/public/assets/main-Cbx7KdTr.js.map +0 -1
  218. package/public/assets/monaco-viewer-BEJIiZWL.js +0 -27
  219. package/public/assets/monaco-viewer-BEJIiZWL.js.map +0 -1
  220. package/public/assets/tool-call-DNsAQ_m4.js +0 -60
  221. package/public/assets/tool-call-DNsAQ_m4.js.map +0 -1
  222. package/public/assets/unified-picker-tB7y17Qz.js +0 -2
  223. package/public/assets/unified-picker-tB7y17Qz.js.map +0 -1
@@ -9,7 +9,10 @@ import { buildServiceLaunchSpec, parseWslUncPath, resolveWslHostDirectory, resol
9
9
  import { HostOpenCodeService, hostOpenCodeServiceIdentity, startupEnvironmentHash, } from "./host-opencode-service";
10
10
  import { OpenCodeSharedService, } from "./opencode-service";
11
11
  import { WslOpenCodeService } from "./wsl-opencode-service";
12
- import { isPathOwnedByWorktree, resolveOwnedWorktreePath } from "./worktree-directory";
12
+ import { invalidateWorktreeCache, isPathOwnedByWorktree, resolveOwnedWorktreePath } from "./worktree-directory";
13
+ import { listNativeWorktrees, createNativeWorktree, removeNativeWorktree } from "./native-worktrees";
14
+ import { WorktreeInventory } from "./worktree-inventory";
15
+ import { resolveRepoRoot } from "./git-worktrees";
13
16
  import { locationRequestOptions, readLocationRef, sameLocation } from "../opencode/compatibility/location";
14
17
  const DEFAULT_LAUNCH_TIMEOUT_MS = 30_000;
15
18
  const MAX_ACTIVE_WORKSPACE_CREATIONS = 32;
@@ -69,6 +72,7 @@ export class WorkspaceManager {
69
72
  constructor(options) {
70
73
  this.options = options;
71
74
  this.workspaces = new Map();
75
+ this.deletingWorktreeRoots = new Set();
72
76
  this.cancelledCreationRequests = new Set();
73
77
  this.pendingCreationRequests = new Set();
74
78
  this.activeLocationCreations = new Set();
@@ -77,6 +81,15 @@ export class WorkspaceManager {
77
81
  this.activeWorkspaceCreations = 0;
78
82
  this.shuttingDown = false;
79
83
  this.warnedLegacyServiceEnvironment = false;
84
+ this.worktreeInventory = new WorktreeInventory({
85
+ load: (id) => this.nativeWorktreeContext(id).then(listNativeWorktrees),
86
+ changed: (id) => {
87
+ invalidateWorktreeCache(id);
88
+ this.options.eventBus.publish({ type: "workspace.worktreesChanged", workspaceId: id });
89
+ },
90
+ failed: (id, error) => this.options.logger.warn({ workspaceId: id, err: error }, "Failed to refresh worktree inventory"),
91
+ now: () => this.now(),
92
+ });
80
93
  this.sharedService = options.sharedService ?? new OpenCodeSharedService();
81
94
  }
82
95
  list() {
@@ -94,6 +107,12 @@ export class WorkspaceManager {
94
107
  const record = this.workspaces.get(id);
95
108
  return record?.[WORKSPACE_STATE].published ? record.location?.directory ?? record.path : undefined;
96
109
  }
110
+ getServiceLocation(id) {
111
+ const record = this.workspaces.get(id);
112
+ if (!record?.[WORKSPACE_STATE].published)
113
+ return undefined;
114
+ return record.location ?? { directory: record.path };
115
+ }
97
116
  async getSharedServiceEndpoint(id) {
98
117
  if (!this.workspaces.get(id)?.[WORKSPACE_STATE].published)
99
118
  return undefined;
@@ -110,6 +129,18 @@ export class WorkspaceManager {
110
129
  getSharedServiceClient() {
111
130
  return this.sharedService.client();
112
131
  }
132
+ async reserveWorktreeDeletion(directory) {
133
+ const submitted = path.isAbsolute(directory) ? directory : path.resolve(this.options.rootDir, directory);
134
+ const target = canonicalWorktreeIdentity(await realpath(submitted).catch(() => path.normalize(submitted)), this.options.platform);
135
+ if (Array.from(this.deletingWorktreeRoots).some((root) => pathsOverlap(root, target))) {
136
+ throw new Error("Worktree deletion is already in progress");
137
+ }
138
+ if (Array.from(this.workspaces.values()).some((workspace) => (pathContains(target, canonicalWorktreeIdentity(workspace.path, this.options.platform))))) {
139
+ throw new Error("Worktree is open as another workspace");
140
+ }
141
+ this.deletingWorktreeRoots.add(target);
142
+ return () => this.deletingWorktreeRoots.delete(target);
143
+ }
113
144
  getSharedServiceFetch() {
114
145
  return this.sharedService.fetch ? this.sharedService.fetch() : Promise.resolve(globalThis.fetch);
115
146
  }
@@ -186,11 +217,52 @@ export class WorkspaceManager {
186
217
  return await this.resolveWslServiceDirectory(candidate, record.wslDistro, DEFAULT_LAUNCH_TIMEOUT_MS)
187
218
  ?? (path.posix.isAbsolute(candidate) ? candidate : undefined);
188
219
  }
220
+ async nativeWorktreeContext(id) {
221
+ const record = this.workspaces.get(id);
222
+ const location = this.getServiceLocation(id);
223
+ if (!record || !location)
224
+ throw new Error("Workspace has no native location");
225
+ return {
226
+ client: await this.getSharedServiceClient(), location, workspacePath: record.path,
227
+ toHost: async (directory) => record.wslDistro
228
+ ? this.resolveWslHostDirectory(directory, record.wslDistro, DEFAULT_LAUNCH_TIMEOUT_MS)
229
+ : directory,
230
+ };
231
+ }
232
+ getWorktrees(id, mode = "cached") {
233
+ return this.worktreeInventory.read(id, mode);
234
+ }
235
+ invalidateWorktrees(mode = "lazy") {
236
+ this.worktreeInventory.invalidate(undefined, mode);
237
+ invalidateWorktreeCache();
238
+ }
239
+ async createWorktree(id, branch, fromSlug) {
240
+ try {
241
+ return await createNativeWorktree(await this.nativeWorktreeContext(id), branch, fromSlug);
242
+ }
243
+ finally {
244
+ this.invalidateWorktrees("blocking");
245
+ }
246
+ }
247
+ async removeWorktree(id, serviceDirectory, force) {
248
+ try {
249
+ return await removeNativeWorktree(await this.nativeWorktreeContext(id), serviceDirectory, force);
250
+ }
251
+ finally {
252
+ this.invalidateWorktrees("blocking");
253
+ }
254
+ }
189
255
  async ownsHostDirectory(record, directory) {
256
+ const [target, root] = await Promise.all([
257
+ realpath(directory).catch(() => undefined), realpath(record.path).catch(() => undefined),
258
+ ]);
259
+ if (target && target === root)
260
+ return true;
190
261
  return (await resolveOwnedWorktreePath({
191
262
  workspaceId: record.id,
192
263
  workspacePath: record.path,
193
264
  directory,
265
+ loadWorktrees: async (refresh) => (await this.getWorktrees(record.id, refresh ? "fresh" : "validated")).worktrees,
194
266
  logger: this.options.logger,
195
267
  })) !== null;
196
268
  }
@@ -202,10 +274,20 @@ export class WorkspaceManager {
202
274
  : directory;
203
275
  if (!hostDirectory)
204
276
  return null;
277
+ const [target, root] = await Promise.all([
278
+ realpath(hostDirectory).catch(() => undefined), realpath(record.path).catch(() => undefined),
279
+ ]);
280
+ // The explicitly opened folder is already authority. Do not require native
281
+ // discovery (or a second connection) to authorize that exact local directory.
282
+ if (target && target === root) {
283
+ const { repoRoot } = await resolveRepoRoot(root);
284
+ return { slug: "root", directory: target, worktreeDirectory: await realpath(repoRoot) };
285
+ }
205
286
  return resolveOwnedWorktreePath({
206
287
  workspaceId: record.id,
207
288
  workspacePath: record.path,
208
289
  directory: hostDirectory,
290
+ loadWorktrees: async (refresh) => (await this.getWorktrees(record.id, refresh ? "fresh" : "validated")).worktrees,
209
291
  logger: this.options.logger,
210
292
  });
211
293
  }
@@ -225,6 +307,7 @@ export class WorkspaceManager {
225
307
  workspaceId: record.id,
226
308
  workspacePath: record.path,
227
309
  candidate,
310
+ loadWorktrees: async (refresh) => (await this.getWorktrees(record.id, refresh ? "fresh" : "validated")).worktrees,
228
311
  logger: this.options.logger,
229
312
  });
230
313
  }
@@ -237,20 +320,20 @@ export class WorkspaceManager {
237
320
  return workspace.status === "ready" && binaryPathsEqual(workspace.binaryId, resolvedPath);
238
321
  })?.id;
239
322
  }
240
- listFiles(workspaceId, relativePath = ".") {
323
+ async listFiles(workspaceId, relativePath = ".") {
241
324
  const workspace = this.requireWorkspace(workspaceId);
242
325
  const browser = new FileSystemBrowser({ rootDir: workspace.path });
243
326
  return browser.list(relativePath);
244
327
  }
245
- searchFiles(workspaceId, query, options) {
328
+ async searchFiles(workspaceId, query, options) {
246
329
  const workspace = this.requireWorkspace(workspaceId);
247
330
  return searchWorkspaceFiles(workspace.path, query, options);
248
331
  }
249
- readFile(workspaceId, relativePath, options) {
332
+ async readFile(workspaceId, relativePath, options) {
250
333
  const workspace = this.requireWorkspace(workspaceId);
251
334
  const browser = new FileSystemBrowser({ rootDir: workspace.path });
252
335
  const encoding = options?.encoding ?? "utf-8";
253
- const contents = encoding === "base64" ? browser.readFileBase64(relativePath) : browser.readFile(relativePath);
336
+ const contents = await (encoding === "base64" ? browser.readFileBase64(relativePath) : browser.readFile(relativePath));
254
337
  return {
255
338
  workspaceId,
256
339
  relativePath,
@@ -258,11 +341,11 @@ export class WorkspaceManager {
258
341
  encoding,
259
342
  };
260
343
  }
261
- readFileInDirectory(workspaceId, directory, relativePath, options) {
344
+ async readFileInDirectory(workspaceId, directory, relativePath, options) {
262
345
  this.requireWorkspace(workspaceId);
263
346
  const browser = new FileSystemBrowser({ rootDir: directory });
264
347
  const encoding = options?.encoding ?? "utf-8";
265
- const contents = encoding === "base64" ? browser.readFileBase64(relativePath) : browser.readFile(relativePath);
348
+ const contents = await (encoding === "base64" ? browser.readFileBase64(relativePath) : browser.readFile(relativePath));
266
349
  return {
267
350
  workspaceId,
268
351
  relativePath,
@@ -270,15 +353,15 @@ export class WorkspaceManager {
270
353
  encoding,
271
354
  };
272
355
  }
273
- writeFile(workspaceId, relativePath, contents) {
356
+ async writeFile(workspaceId, relativePath, contents) {
274
357
  const workspace = this.requireWorkspace(workspaceId);
275
358
  const browser = new FileSystemBrowser({ rootDir: workspace.path });
276
- browser.writeFile(relativePath, contents);
359
+ await browser.writeFile(relativePath, contents);
277
360
  }
278
- writeFileInDirectory(workspaceId, directory, relativePath, contents) {
361
+ async writeFileInDirectory(workspaceId, directory, relativePath, contents) {
279
362
  this.requireWorkspace(workspaceId);
280
363
  const browser = new FileSystemBrowser({ rootDir: directory });
281
- browser.writeFile(relativePath, contents);
364
+ await browser.writeFile(relativePath, contents);
282
365
  }
283
366
  async create(folder, name, options = {}) {
284
367
  if (options.requestId)
@@ -290,6 +373,10 @@ export class WorkspaceManager {
290
373
  try {
291
374
  const submittedPath = path.isAbsolute(folder) ? path.normalize(folder) : path.resolve(this.options.rootDir, folder);
292
375
  const workspacePath = await this.withLaunchDeadline(realpath(submittedPath).then((resolved) => path.normalize(resolved), () => submittedPath), undefined, launchDeadlineAt, launchTimeoutMs);
376
+ const workspaceIdentity = canonicalWorktreeIdentity(workspacePath, this.options.platform);
377
+ if (Array.from(this.deletingWorktreeRoots).some((root) => pathContains(root, workspaceIdentity))) {
378
+ throw new Error("Workspace directory is being removed");
379
+ }
293
380
  if (options.requestId && this.cancelledCreationRequests.has(options.requestId)) {
294
381
  throw new Error(`Workspace creation request ${options.requestId} was cancelled`);
295
382
  }
@@ -403,7 +490,6 @@ export class WorkspaceManager {
403
490
  const startupEnvironment = launch.kind === "wsl"
404
491
  ? await this.wslStartupEnvironment(this.serviceStartupEnvironment(), launch.distro, launchDeadlineAt)
405
492
  : this.serviceStartupEnvironment();
406
- await this.options.prepareSessionPruning?.(launch, startupEnvironment);
407
493
  const serviceOptions = {
408
494
  kind: "lifecycle",
409
495
  identity: launch.kind === "host"
@@ -417,6 +503,9 @@ export class WorkspaceManager {
417
503
  lifecycle: launch.kind === "host"
418
504
  ? this.createHostServiceLifecycle(launch, timeoutMs, startupEnvironment)
419
505
  : this.createWslServiceLifecycle(launch, timeoutMs, startupEnvironment),
506
+ prepareDesktopPlugins: this.options.prepareDesktopPlugins
507
+ ? (connection, deadlineAt) => this.options.prepareDesktopPlugins(launch, connection, deadlineAt)
508
+ : undefined,
420
509
  };
421
510
  state.serviceOptions = serviceOptions;
422
511
  this.throwIfCancelled(record);
@@ -728,7 +817,7 @@ export class WorkspaceManager {
728
817
  binary: spec.binary,
729
818
  startupEnvironment,
730
819
  timeoutMs,
731
- });
820
+ }, { startFile: this.options.startServiceCommand });
732
821
  }
733
822
  createHostServiceLifecycle(spec, timeoutMs, startupEnvironment) {
734
823
  return this.options.hostServiceLifecycleFactory?.(spec, timeoutMs, startupEnvironment)
@@ -737,7 +826,7 @@ export class WorkspaceManager {
737
826
  platform: spec.platform,
738
827
  startupEnvironment,
739
828
  timeoutMs,
740
- });
829
+ }, { startFile: this.options.startServiceCommand });
741
830
  }
742
831
  serviceStartupEnvironment() {
743
832
  const configured = this.options.settings.getOwner("config", "server").environmentVariables;
@@ -802,6 +891,8 @@ export class WorkspaceManager {
802
891
  if (this.workspaces.get(id) !== record)
803
892
  return;
804
893
  this.workspaces.delete(id);
894
+ this.worktreeInventory.forget(id);
895
+ invalidateWorktreeCache(id);
805
896
  clearWorkspaceSearchCache(record.path);
806
897
  if (publishStopped)
807
898
  this.publishStopped(record, reason);
@@ -861,4 +952,23 @@ export class WorkspaceManager {
861
952
  return candidates[0] ?? "";
862
953
  }
863
954
  }
955
+ function pathContains(parent, child) {
956
+ const left = parseWorktreeIdentity(parent);
957
+ const right = parseWorktreeIdentity(child);
958
+ if (left || right) {
959
+ if (!left || !right || left.distro !== right.distro)
960
+ return false;
961
+ const relative = path.posix.relative(left.linuxPath, right.linuxPath);
962
+ return relative === "" || (relative !== ".." && !relative.startsWith("../") && !path.posix.isAbsolute(relative));
963
+ }
964
+ const relative = path.relative(parent, child);
965
+ return relative === "" || (relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
966
+ }
967
+ function pathsOverlap(left, right) {
968
+ return pathContains(left, right) || pathContains(right, left);
969
+ }
970
+ function parseWorktreeIdentity(identity) {
971
+ const match = /^wsl:([^:]+):(\/.*)$/.exec(identity);
972
+ return match ? { distro: match[1], linuxPath: match[2] } : undefined;
973
+ }
864
974
  //# sourceMappingURL=manager.js.map