@vite-hub/workspace 0.0.1 → 0.0.2

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 (94) hide show
  1. package/README.md +190 -17
  2. package/dist/{ai-Bk3LLnit.js → ai-Cztw4eLk.js} +149 -29
  3. package/dist/ai-hFdsvDHC.d.ts +162 -0
  4. package/dist/ai.d.ts +2 -85
  5. package/dist/ai.js +1 -1
  6. package/dist/artifacts-store-BAV9jZpd.js +555 -0
  7. package/dist/asset-registry-CaG9b7tf.js +19 -0
  8. package/dist/cli.d.ts +31 -0
  9. package/dist/cli.js +303 -0
  10. package/dist/cloudflare-env-CKxUs2fa.js +20 -0
  11. package/dist/cloudflare.d.ts +16 -0
  12. package/dist/cloudflare.js +3 -0
  13. package/dist/collections/client.d.ts +39 -0
  14. package/dist/collections/client.js +137 -0
  15. package/dist/collections.d.ts +59 -0
  16. package/dist/collections.js +159 -0
  17. package/dist/config--r5unwPc.js +7811 -0
  18. package/dist/config-Ca5DM8fF.d.ts +28 -0
  19. package/dist/config-DCQ6y30R.js +30 -0
  20. package/dist/file-B2q9NE18.js +24 -0
  21. package/dist/{files-DbsIjBya.js → files-xy0le-_U.js} +6 -5
  22. package/dist/github-lIO6-2sH.js +194 -0
  23. package/dist/glob-DeH0dzZX.js +23 -0
  24. package/dist/host-I-_vDs05.js +370 -0
  25. package/dist/hosted-vercel-blob.d.ts +15 -0
  26. package/dist/hosted-vercel-blob.js +26 -0
  27. package/dist/hosted.d.ts +18 -0
  28. package/dist/hosted.js +30 -0
  29. package/dist/index.d.ts +137 -102
  30. package/dist/index.js +479 -594
  31. package/dist/lifecycle-Lhk3dAMt.js +176 -0
  32. package/dist/loader.d.ts +1 -1
  33. package/dist/loader.js +1 -1
  34. package/dist/nitro.d.ts +2 -31
  35. package/dist/nitro.js +2 -2
  36. package/dist/nuxt.d.ts +26 -0
  37. package/dist/nuxt.js +36 -0
  38. package/dist/path-CNI6wKIU.js +115 -0
  39. package/dist/{provider-BZuKAV4e.js → provider-CeQciesl.js} +142 -37
  40. package/dist/providers/cloudflare/artifacts-store.d.ts +1 -1
  41. package/dist/providers/cloudflare/artifacts-store.js +1 -383
  42. package/dist/providers/github/store.d.ts +6 -0
  43. package/dist/providers/github/store.js +362 -0
  44. package/dist/providers/vercel/blob-store.d.ts +1 -1
  45. package/dist/providers/vercel/blob-store.js +77 -18
  46. package/dist/publish.d.ts +3 -2
  47. package/dist/publish.js +48 -142
  48. package/dist/registry-C7DMdBXN.js +74 -0
  49. package/dist/{registry-D4Qzq26I.d.ts → registry-CoC9JxVt.d.ts} +3 -2
  50. package/dist/request-execution-C8qRcReq.js +80 -0
  51. package/dist/runtime/assets.d.ts +2 -1
  52. package/dist/runtime/assets.js +5 -5
  53. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  54. package/dist/runtime/empty-registry.d.ts +1 -1
  55. package/dist/runtime/state.d.ts +4 -21
  56. package/dist/runtime/state.js +7 -4
  57. package/dist/runtime/workspace.d.ts +2 -0
  58. package/dist/runtime/workspace.js +2 -0
  59. package/dist/runtime.d.ts +38 -0
  60. package/dist/runtime.js +643 -0
  61. package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
  62. package/dist/server.d.ts +65 -0
  63. package/dist/server.js +355 -0
  64. package/dist/shared-BRycRSbo.js +255 -0
  65. package/dist/source-metadata.d.ts +2 -0
  66. package/dist/source-metadata.js +2 -0
  67. package/dist/state-DSAHEsq6.d.ts +25 -0
  68. package/dist/sync-DO42ypji.js +269 -0
  69. package/dist/target-D4Bqb1eH.js +11 -0
  70. package/dist/test.d.ts +1 -1
  71. package/dist/test.js +1 -1
  72. package/dist/types-DHkae7Cb.d.ts +628 -0
  73. package/dist/use-D16tf8Ph.d.ts +86 -0
  74. package/dist/use-d_PlAdOu.js +353 -0
  75. package/dist/{utils-BtAm_K5P.js → utils-BPdaCyI6.js} +7 -3
  76. package/dist/vite-NWC9mFjI.js +1882 -0
  77. package/dist/vite.d.ts +33 -5
  78. package/dist/vite.js +2 -131
  79. package/dist/workspace-f2DBLmPZ.d.ts +6 -0
  80. package/dist/workspace-n4wBmdaM.js +1476 -0
  81. package/package.json +158 -62
  82. package/dist/asset-registry-CMuQbyvl.js +0 -14
  83. package/dist/cloudflare-env-DL94Uvpz.js +0 -12
  84. package/dist/config-CvS-7sre.js +0 -49
  85. package/dist/errors-BUL8SoFS.js +0 -21
  86. package/dist/lifecycle-uD82JeGh.js +0 -92
  87. package/dist/module-8LZUMEXC.js +0 -922
  88. package/dist/path-BVv9OXhg.js +0 -63
  89. package/dist/registry-Cnr0NoKv.js +0 -932
  90. package/dist/runtime/nitro-plugin.d.ts +0 -6
  91. package/dist/runtime/nitro-plugin.js +0 -14
  92. package/dist/sandbox-DtGXCWRq.js +0 -198
  93. package/dist/types-CwNcWTdt.d.ts +0 -378
  94. /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
@@ -0,0 +1,643 @@
1
+ import { c as normalizeWorkspacePath, p as workspaceError } from "./path-CNI6wKIU.js";
2
+ import { a as copyWorkspacePath, i as appendWorkspaceFile, n as getWorkspaceDependencyRuntimeLoaders, r as setWorkspaceDependencyRuntimeLoaders, t as createWorkspaceTools } from "./ai-Cztw4eLk.js";
3
+ import { a as normalizeWorkspaceSources, f as getWorkspaceSourceRequestDescriptor, g as markLiveWorkspaceSource, h as workspaceSourceRequestDescriptorPath, i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, m as isWorkspaceSourceRequestOnly, o as normalizeWorkspaceSourcesMetadata, r as normalizeWorkspaceSource, t as copyWorkspaceSourceMetadata } from "./config--r5unwPc.js";
4
+ import { n as createWorkspaceSourceRequestExecution, r as getWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-C8qRcReq.js";
5
+ import { c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, l as setWorkspaceHostedStoreLoader, s as createMemoryWorkspaceStore, u as getWorkspaceRuntimeConfig } from "./provider-CeQciesl.js";
6
+ import { t as forwardWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
7
+ import { d as createBasicWorkspaceSession, l as createWorkspaceWritePolicy, n as resetWorkspaceStoreCache, r as createWorkspaceSourceView, s as resolveWorkspacePath } from "./workspace-n4wBmdaM.js";
8
+ import { n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "./registry-C7DMdBXN.js";
9
+ import { t as useWorkspace } from "./use-d_PlAdOu.js";
10
+ import { setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeRegistry } from "./runtime/state.js";
11
+ //#region src/sources/resolution.ts
12
+ function hasWorkspaceSourceResolvers(definition) {
13
+ return normalizeWorkspaceSources(definition?.sources).some((source) => typeof source.source.resolve === "function");
14
+ }
15
+ function isWritableWorkspaceFacade(workspace) {
16
+ return typeof workspace.fs.writeFile === "function";
17
+ }
18
+ function workspaceSessionStarter(workspace) {
19
+ return typeof workspace.startSession === "function" ? workspace : void 0;
20
+ }
21
+ function writeOperations(options) {
22
+ return {
23
+ appendFile: options?.appendFile !== false,
24
+ copyPath: options?.copyPath !== false,
25
+ deletePath: options?.deletePath !== false,
26
+ makeDir: options?.makeDir !== false,
27
+ movePath: options?.movePath !== false,
28
+ writeFile: options?.writeFile !== false
29
+ };
30
+ }
31
+ function createOverlaySourceStore(workspace, fallback) {
32
+ const memory = createMemoryWorkspaceStore();
33
+ async function readBaseFile(path) {
34
+ if (!fallback(path)) return;
35
+ if (!await workspace.fs.exists(path)) return;
36
+ const stat = await workspace.fs.stat(path).catch(() => void 0);
37
+ if (stat?.type === "directory") return;
38
+ return {
39
+ content: await workspace.fs.readFile(path, { encoding: "binary" }),
40
+ mediaType: stat?.mediaType,
41
+ path
42
+ };
43
+ }
44
+ async function baseEntries(path = "", options) {
45
+ try {
46
+ return (await workspace.fs.list(path, options)).filter((entry) => fallback(entry.path));
47
+ } catch {
48
+ return [];
49
+ }
50
+ }
51
+ async function baseGlob(pattern, options) {
52
+ try {
53
+ return (await workspace.fs.glob(pattern, options)).filter((entry) => fallback(entry.path));
54
+ } catch {
55
+ return [];
56
+ }
57
+ }
58
+ async function baseStat(path) {
59
+ if (!fallback(path)) return;
60
+ try {
61
+ return await workspace.fs.stat(path);
62
+ } catch {
63
+ return;
64
+ }
65
+ }
66
+ return {
67
+ async readFile(path) {
68
+ return await memory.readFile(path) || await readBaseFile(path);
69
+ },
70
+ async writeFile(path, file) {
71
+ await memory.writeFile(path, file);
72
+ },
73
+ async list(path, options) {
74
+ return mergeEntries(await baseEntries(path, options), await memory.list(path, options));
75
+ },
76
+ async glob(pattern, options) {
77
+ return mergeEntries(await baseGlob(pattern, options), await memory.glob(pattern, options));
78
+ },
79
+ async stat(path) {
80
+ return await memory.stat(path) || await baseStat(path);
81
+ },
82
+ async mkdir(path, options) {
83
+ await memory.mkdir(path, options);
84
+ },
85
+ async rm(path, options) {
86
+ await memory.rm(path, options);
87
+ },
88
+ async snapshot(options) {
89
+ return await memory.snapshot(options);
90
+ },
91
+ async diff(options) {
92
+ return await memory.diff(options);
93
+ },
94
+ async getMeta(key) {
95
+ return await memory.getMeta?.(key);
96
+ },
97
+ async setMeta(key, value) {
98
+ await memory.setMeta?.(key, value);
99
+ }
100
+ };
101
+ }
102
+ function createWritableFacadeStore(workspace) {
103
+ const meta = /* @__PURE__ */ new Map();
104
+ const metadata = workspace;
105
+ const store = {
106
+ async readFile(path) {
107
+ try {
108
+ const stat = await workspace.fs.stat(path);
109
+ if (stat.type === "directory") return;
110
+ return {
111
+ content: await workspace.fs.readFile(path, { encoding: "binary" }),
112
+ mediaType: stat.mediaType,
113
+ path
114
+ };
115
+ } catch {
116
+ return;
117
+ }
118
+ },
119
+ async writeFile(path, file) {
120
+ await workspace.fs.writeFile(path, file.content, { mediaType: file.mediaType });
121
+ },
122
+ async list(path, options) {
123
+ return await workspace.fs.list(path, options);
124
+ },
125
+ async glob(pattern, options) {
126
+ return await workspace.fs.glob(pattern, options);
127
+ },
128
+ async stat(path) {
129
+ try {
130
+ return await workspace.fs.stat(path);
131
+ } catch {
132
+ return;
133
+ }
134
+ },
135
+ async mkdir(path, options) {
136
+ await workspace.fs.mkdir(path, options);
137
+ },
138
+ async rm(path, options) {
139
+ await workspace.fs.rm(path, options);
140
+ },
141
+ async snapshot(options) {
142
+ return await workspace.snapshot(options);
143
+ },
144
+ async diff(options) {
145
+ return await workspace.diff(options);
146
+ },
147
+ async getMeta(key) {
148
+ if (metadata.getMeta) return await metadata.getMeta(key);
149
+ return meta.get(key);
150
+ },
151
+ async setMeta(key, value) {
152
+ if (metadata.setMeta) {
153
+ await metadata.setMeta(key, value);
154
+ return;
155
+ }
156
+ meta.set(key, value);
157
+ }
158
+ };
159
+ forwardWorkspaceStoreTarget(workspace, store);
160
+ return store;
161
+ }
162
+ async function startOverlayWorkspaceSession(_definition, workspace, options) {
163
+ const host = options?.host;
164
+ if (host) {
165
+ const { createHostedWorkspaceSession } = await import("./host-I-_vDs05.js");
166
+ return await createHostedWorkspaceSession(workspace, {
167
+ ...options,
168
+ host
169
+ });
170
+ }
171
+ return await createBasicWorkspaceSession(workspace, options);
172
+ }
173
+ async function resolveWorkspaceSources(definition, options) {
174
+ if (!hasWorkspaceSourceResolvers(definition) && !options.selectedWorkspaceScope) return definition;
175
+ const sources = {};
176
+ for (const [key, source] of Object.entries(definition.sources || {})) {
177
+ const resolved = await resolveWorkspaceSource(definition, key, source, options);
178
+ if (resolved) sources[key] = resolved;
179
+ }
180
+ return {
181
+ ...definition,
182
+ sources
183
+ };
184
+ }
185
+ async function createWorkspaceSourceResolutionFacade(workspace, definition, options) {
186
+ const resolvedDefinition = await resolveWorkspaceSources(definition, options);
187
+ const sourceRequestExecution = createWorkspaceSourceRequestExecution(resolvedDefinition, { selectedWorkspaceScope: options.selectedWorkspaceScope }) ?? getWorkspaceSourceRequestExecution(workspace.fs);
188
+ if (!options.overlay && resolvedDefinition === definition && !sourceRequestExecution) return {
189
+ definition,
190
+ workspace
191
+ };
192
+ const selectedWorkspaceScope = options.selectedWorkspaceScope;
193
+ const sourceView = createWorkspaceSourceView(createScopedSourceViewDefinition(resolvedDefinition, selectedWorkspaceScope), createOverlaySourceStore(workspace, (path) => !isLazySourcePath(resolvedDefinition, path)));
194
+ const materializeSources = async (options = {}) => await sourceView.materializeSources(options);
195
+ let readWorkspace;
196
+ const fs = attachWorkspaceSourceRequestExecution({
197
+ async readFile(path, options) {
198
+ if (isSourcePath(resolvedDefinition, path)) return await sourceView.readFile(path, options);
199
+ if (selectedScopeCanRead(selectedWorkspaceScope, path) && await sourceViewHasPath(resolvedDefinition, sourceView, path)) return await sourceView.readFile(path, options);
200
+ return await workspace.fs.readFile(path, options);
201
+ },
202
+ async stat(path) {
203
+ if (isSourcePath(resolvedDefinition, path)) return await sourceView.stat(path);
204
+ if (selectedScopeCanSee(selectedWorkspaceScope, path) && await sourceViewHasPath(resolvedDefinition, sourceView, path)) return await sourceView.stat(path);
205
+ return await workspace.fs.stat(path);
206
+ },
207
+ async exists(path) {
208
+ if (isSourcePath(resolvedDefinition, path)) return await sourceView.exists(path);
209
+ return selectedScopeCanSee(selectedWorkspaceScope, path) && await sourceViewHasPath(resolvedDefinition, sourceView, path) || await workspace.fs.exists(path);
210
+ },
211
+ async list(path = "", options = {}) {
212
+ const normalized = normalizeWorkspacePath(path);
213
+ if (normalized && isSourcePath(resolvedDefinition, normalized)) return filterScopedEntries(selectedWorkspaceScope, await sourceView.list(normalized, options));
214
+ const [baseEntries, sourceEntries] = await Promise.all([workspace.fs.list(path, options), selectedScopeCanSee(selectedWorkspaceScope, normalized) && sourcePathIntersects(resolvedDefinition, normalized) ? sourceView.list(normalized, options) : Promise.resolve([])]);
215
+ return mergeEntries(filterBaseEntries(resolvedDefinition, baseEntries), filterScopedEntries(selectedWorkspaceScope, sourceEntries));
216
+ },
217
+ async glob(pattern, options) {
218
+ const [baseEntries, sourceEntries] = await Promise.all([workspace.fs.glob(pattern, options), sourceView.glob(pattern, options)]);
219
+ return mergeEntries(filterBaseEntries(resolvedDefinition, baseEntries), filterScopedEntries(selectedWorkspaceScope, sourceEntries));
220
+ },
221
+ async search(query) {
222
+ const scopedToSource = searchQueryTargetsSource(resolvedDefinition, query);
223
+ const [baseHits, sourceHits] = await Promise.all([scopedToSource ? Promise.resolve([]) : workspace.fs.search(query), sourceView.search(query)]);
224
+ return mergeHits(filterBaseHits(resolvedDefinition, baseHits), filterScopedHits(selectedWorkspaceScope, sourceHits)).slice(0, query.limit ?? 100);
225
+ },
226
+ materializeSources,
227
+ startSession: async (options) => {
228
+ const paths = options?.paths?.length ? options.paths : [""];
229
+ await Promise.all(paths.map((path) => materializeSources({ path })));
230
+ return await startOverlayWorkspaceSession(resolvedDefinition, readWorkspace, options);
231
+ }
232
+ }, sourceRequestExecution);
233
+ readWorkspace = attachWorkspaceSourceRequestExecution({
234
+ name: resolvedDefinition.name,
235
+ exists: fs.exists,
236
+ glob: fs.glob,
237
+ list: fs.list,
238
+ materializeSources,
239
+ readFile: fs.readFile,
240
+ search: fs.search,
241
+ startSession: fs.startSession,
242
+ stat: fs.stat
243
+ }, sourceRequestExecution);
244
+ const createTools = (options) => createWorkspaceTools(fs, {
245
+ broadSearchPaths: options?.broadSearchPaths,
246
+ cwd: options?.cwd,
247
+ maxShellCalls: options?.maxShellCalls,
248
+ maxOutputLength: options?.maxOutputLength,
249
+ operations: {
250
+ list: options?.list,
251
+ materialize: options?.materialize ?? true,
252
+ read: options?.read,
253
+ search: options?.search
254
+ },
255
+ timeout: options?.timeout
256
+ });
257
+ const tools = createTools();
258
+ tools.inspect = createTools;
259
+ tools.none = (() => ({}));
260
+ if (isWritableWorkspaceFacade(workspace)) {
261
+ const writePolicy = createWorkspaceWritePolicy(resolvedDefinition);
262
+ const syncStore = createWritableFacadeStore(workspace);
263
+ let writeWorkspace;
264
+ async function previousStat(path) {
265
+ try {
266
+ return await workspace.fs.stat(path);
267
+ } catch {
268
+ return;
269
+ }
270
+ }
271
+ async function writeWithPolicy(input, write) {
272
+ await sourceView.assertWritable(input.path);
273
+ const next = await writePolicy.before({
274
+ ...input,
275
+ path: normalizeWorkspacePath(input.path),
276
+ previous: await previousStat(input.path),
277
+ workspace: resolvedDefinition.name
278
+ });
279
+ try {
280
+ await sourceView.assertWritable(next.path);
281
+ await write(next);
282
+ await writePolicy.after(next);
283
+ } catch (error) {
284
+ await writePolicy.error(next, error);
285
+ throw error;
286
+ }
287
+ }
288
+ function withSessionSourceGuards(session) {
289
+ return {
290
+ ...session,
291
+ async mkdir(path, options) {
292
+ await sourceView.assertWritable(path);
293
+ await session.mkdir(path, options);
294
+ },
295
+ async rm(path, options) {
296
+ await sourceView.assertWritable(path);
297
+ await session.rm(path, options);
298
+ },
299
+ async writeFile(path, content, options) {
300
+ await sourceView.assertWritable(path);
301
+ await session.writeFile(path, content, options);
302
+ }
303
+ };
304
+ }
305
+ const writeFs = attachWorkspaceSourceRequestExecution({
306
+ appendFile: async (path, content) => await appendWorkspaceFile(writeWorkspace, path, content),
307
+ copyPath: async (from, to, options) => await copyWorkspacePath(writeWorkspace, from, to, options?.overwrite),
308
+ exists: fs.exists,
309
+ glob: fs.glob,
310
+ list: fs.list,
311
+ mkdir: async (path, options) => await writeWithPolicy({
312
+ operation: "mkdir",
313
+ path
314
+ }, async (input) => await workspace.fs.mkdir(input.path, options)),
315
+ movePath: async (from, to, options) => {
316
+ await sourceView.assertWritable(from);
317
+ await sourceView.assertWritable(to);
318
+ await copyWorkspacePath(writeWorkspace, from, to, options?.overwrite);
319
+ await writeWorkspace.rm(from, {
320
+ recursive: true,
321
+ force: true
322
+ });
323
+ },
324
+ readFile: fs.readFile,
325
+ rm: async (path, options) => await writeWithPolicy({
326
+ operation: "rm",
327
+ path
328
+ }, async (input) => await workspace.fs.rm(input.path, options)),
329
+ search: fs.search,
330
+ stat: fs.stat,
331
+ writeFile: async (path, content, options) => await writeWithPolicy({
332
+ content,
333
+ mediaType: options?.mediaType,
334
+ metadata: options?.metadata,
335
+ operation: "writeFile",
336
+ path
337
+ }, async (input) => {
338
+ const writeOptions = options === void 0 && input.mediaType === void 0 && input.metadata === void 0 ? void 0 : {
339
+ ...options,
340
+ mediaType: input.mediaType,
341
+ metadata: input.metadata
342
+ };
343
+ await workspace.fs.writeFile(input.path, input.content ?? content, writeOptions);
344
+ })
345
+ }, sourceRequestExecution);
346
+ writeWorkspace = attachWorkspaceSourceRequestExecution({
347
+ name: resolvedDefinition.name,
348
+ diff: workspace.diff,
349
+ exists: writeFs.exists,
350
+ glob: writeFs.glob,
351
+ list: writeFs.list,
352
+ materializeSources,
353
+ mkdir: writeFs.mkdir,
354
+ publish: async (options) => {
355
+ const { publishWorkspace } = await import("./lifecycle-Lhk3dAMt.js").then((n) => n.t);
356
+ await publishWorkspace(resolvedDefinition, createWritableFacadeStore({
357
+ ...workspace,
358
+ fs: writeFs
359
+ }), options);
360
+ },
361
+ readFile: writeFs.readFile,
362
+ rm: writeFs.rm,
363
+ search: writeFs.search,
364
+ snapshot: workspace.snapshot,
365
+ startSession: async (options) => {
366
+ const paths = options?.paths?.length ? options.paths : [""];
367
+ await Promise.all(paths.map((path) => materializeSources({ path })));
368
+ const startBoxSession = workspace[Symbol.for("vitehub.workspace.start-box-session")];
369
+ return withSessionSourceGuards(options?.host ? await startOverlayWorkspaceSession(resolvedDefinition, writeWorkspace, options) : typeof startBoxSession === "function" ? await startBoxSession(writeWorkspace, options) : await startOverlayWorkspaceSession(resolvedDefinition, writeWorkspace, options));
370
+ },
371
+ stat: writeFs.stat,
372
+ sync: async (options) => {
373
+ const { syncWorkspaceSources } = await import("./sync-DO42ypji.js");
374
+ return await syncWorkspaceSources(resolvedDefinition, syncStore, options);
375
+ },
376
+ writeFile: writeFs.writeFile,
377
+ mount(options) {
378
+ const mode = options?.mode || "read-only";
379
+ return {
380
+ workspace: writeWorkspace,
381
+ mode,
382
+ target: options?.target || "/workspace",
383
+ async diff() {
384
+ return await writeWorkspace.diff();
385
+ },
386
+ async commit() {
387
+ await writeWorkspace.snapshot({ name: "mount-commit" });
388
+ },
389
+ async export() {
390
+ return await writeWorkspace.snapshot({ name: "mount-export" });
391
+ }
392
+ };
393
+ }
394
+ }, sourceRequestExecution);
395
+ const createWriteTools = (options) => createWorkspaceTools(writeWorkspace, {
396
+ broadSearchPaths: options?.broadSearchPaths,
397
+ cwd: options?.cwd,
398
+ maxShellCalls: options?.maxShellCalls,
399
+ maxOutputLength: options?.maxOutputLength,
400
+ operations: {
401
+ list: options?.list,
402
+ materialize: options?.materialize ?? true,
403
+ read: options?.read,
404
+ search: options?.search,
405
+ write: writeOperations(options)
406
+ },
407
+ timeout: options?.timeout
408
+ });
409
+ const writeTools = createWriteTools();
410
+ writeTools.inspect = createTools;
411
+ writeTools.none = (() => ({}));
412
+ writeTools.write = createWriteTools;
413
+ return {
414
+ definition: resolvedDefinition,
415
+ workspace: {
416
+ ...workspace,
417
+ diff: writeWorkspace.diff,
418
+ fs: writeFs,
419
+ materializeSources,
420
+ publish: writeWorkspace.publish,
421
+ snapshot: writeWorkspace.snapshot,
422
+ startSession: writeWorkspace.startSession,
423
+ sync: writeWorkspace.sync,
424
+ tools: writeTools
425
+ }
426
+ };
427
+ }
428
+ const readonlyWorkspace = {
429
+ fs,
430
+ tools
431
+ };
432
+ const starter = workspaceSessionStarter(workspace);
433
+ if (starter) readonlyWorkspace.startSession = async (options) => await starter.startSession(options);
434
+ return {
435
+ definition: resolvedDefinition,
436
+ workspace: readonlyWorkspace
437
+ };
438
+ }
439
+ async function resolveWorkspaceSource(definition, key, input, options) {
440
+ const declared = normalizeWorkspaceSource(key, input);
441
+ const source = declared.source;
442
+ if (!source.resolve) return selectedScopeIntersectsSource(options.selectedWorkspaceScope, declared) ? input : void 0;
443
+ const context = {
444
+ ...Object.fromEntries(options.invocation.context.entries()),
445
+ invocation: options.invocation,
446
+ selectedWorkspaceScope: options.selectedWorkspaceScope,
447
+ source: {
448
+ key,
449
+ mountPath: declared.mountPath
450
+ },
451
+ workspace: {
452
+ name: definition.name,
453
+ rootDir: definition.rootDir,
454
+ sourceRootDir: definition.sourceRootDir
455
+ }
456
+ };
457
+ const resolve = source.resolve;
458
+ const resolved = await resolve(context);
459
+ if (!resolved) return void 0;
460
+ const resolvedSource = withResolvedSourceRuntimeDefaults(applyResolvedWorkspaceSourceBinding(input, resolved));
461
+ const normalized = normalizeWorkspaceSource(key, resolvedSource);
462
+ if (!selectedScopeIntersectsSource(options.selectedWorkspaceScope, normalized)) return void 0;
463
+ return copyWorkspaceSourceMetadata(resolvedSource, {
464
+ ...resolvedSource,
465
+ fingerprint: {
466
+ source: resolvedSource.fingerprint,
467
+ sourceResolution: { selectedWorkspaceScope: options.selectedWorkspaceScope ? {
468
+ all: options.selectedWorkspaceScope.all,
469
+ name: options.selectedWorkspaceScope.name,
470
+ paths: options.selectedWorkspaceScope.paths,
471
+ role: options.selectedWorkspaceScope.role,
472
+ sources: options.selectedWorkspaceScope.sources
473
+ } : void 0 }
474
+ }
475
+ });
476
+ }
477
+ function applyResolvedWorkspaceSourceBinding(input, source) {
478
+ if (!isPlainRecord(input)) return source;
479
+ const next = { ...source };
480
+ copyWorkspaceSourceMetadata(source, next);
481
+ if (!("source" in input)) return next;
482
+ copyDefinedWorkspaceBindingOption(next, input, "cache");
483
+ copyDefinedWorkspaceBindingOption(next, input, "materialize");
484
+ copyDefinedWorkspaceBindingOption(next, input, "mount");
485
+ copyDefinedWorkspaceBindingOption(next, input, "sync");
486
+ copyDefinedWorkspaceBindingOption(next, input, "validate");
487
+ return next;
488
+ }
489
+ function copyDefinedWorkspaceBindingOption(target, input, key) {
490
+ if (input[key] !== void 0) target[key] = input[key];
491
+ }
492
+ function withResolvedSourceRuntimeDefaults(source) {
493
+ if (source.materialize || source.mount && typeof source.mount === "object" && source.mount.materialize) return source;
494
+ if (source.sync) return source;
495
+ return copyWorkspaceSourceMetadata(source, {
496
+ ...source,
497
+ materialize: "lazy"
498
+ });
499
+ }
500
+ function isPlainRecord(input) {
501
+ return !!input && typeof input === "object" && !Array.isArray(input);
502
+ }
503
+ function isSourcePath(definition, path) {
504
+ if (isWorkspaceMetadataPath(path)) return false;
505
+ return resolveWorkspacePath(definition, path).type === "source";
506
+ }
507
+ async function sourceViewHasPath(definition, sourceView, path) {
508
+ if (!sourcePathIntersects(definition, normalizeWorkspacePath(path))) return false;
509
+ try {
510
+ return await sourceView.exists(path);
511
+ } catch {
512
+ return false;
513
+ }
514
+ }
515
+ function sourcePathIntersects(definition, path) {
516
+ if (isWorkspaceMetadataPath(path)) return sourceDescriptorPathIntersects(definition, path);
517
+ return normalizeWorkspaceSources(definition.sources).filter((source) => source.materialize !== "none").some((source) => pathIntersects(source.mountPath, path));
518
+ }
519
+ function isWorkspaceMetadataPath(path) {
520
+ const normalized = normalizeWorkspacePath(path);
521
+ return normalized === ".vitehub" || normalized.startsWith(".vitehub/");
522
+ }
523
+ function sourceDescriptorPathIntersects(definition, path) {
524
+ const normalized = normalizeWorkspacePath(path);
525
+ return normalizeWorkspaceSources(definition.sources).some((source) => source.requestDescriptor && pathIntersects(workspaceSourceRequestDescriptorPath(source.key), normalized));
526
+ }
527
+ function isLazySourcePath(definition, path) {
528
+ const normalized = normalizeWorkspacePath(path);
529
+ return normalizeWorkspaceSources(definition.sources).filter((source) => source.materialize === "lazy").some((source) => pathIntersects(source.mountPath, normalized));
530
+ }
531
+ function searchQueryTargetsSource(definition, query) {
532
+ return (query.paths?.length ? query.paths : [query.cwd || ""]).every((path) => isSourcePath(definition, path));
533
+ }
534
+ function filterBaseEntries(definition, entries) {
535
+ return entries.filter((entry) => !isSourcePath(definition, entry.path));
536
+ }
537
+ function filterBaseHits(definition, hits) {
538
+ return hits.filter((hit) => !isSourcePath(definition, hit.path));
539
+ }
540
+ function createScopedSourceViewDefinition(definition, scope) {
541
+ if (!scope || scope.all) return definition;
542
+ const sources = {};
543
+ for (const source of normalizeWorkspaceSources(definition.sources)) sources[source.key] = scopedWorkspaceSource(source, scope);
544
+ return {
545
+ ...definition,
546
+ sources
547
+ };
548
+ }
549
+ function scopedWorkspaceSource(source, scope) {
550
+ const scopedLivePaths = source.livePaths ? {} : void 0;
551
+ syncScopedLivePaths(scopedLivePaths, source.livePaths, scope);
552
+ const scoped = {
553
+ ...source.source,
554
+ ...scopedLivePaths ? { async prepare(ctx) {
555
+ await source.source.prepare?.(ctx);
556
+ syncScopedLivePaths(scopedLivePaths, source.livePaths, scope);
557
+ } } : {},
558
+ ...source.source.getItems ? { getItems: async (ctx) => (await source.source.getItems(ctx)).filter((item) => selectedScopeCanRead(scope, sourceItemWorkspacePath(source, item.path || item.key))) } : {},
559
+ getKeys: async (ctx) => (await source.source.getKeys(ctx)).filter((key) => selectedScopeCanRead(scope, sourceItemWorkspacePath(source, key))),
560
+ getItem: async (key, ctx) => {
561
+ const path = sourceItemWorkspacePath(source, key);
562
+ if (!selectedScopeCanRead(scope, path)) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
563
+ return await source.source.getItem(key, ctx);
564
+ },
565
+ ...source.source.getMeta ? { getMeta: async (key, ctx) => {
566
+ if (!selectedScopeCanRead(scope, sourceItemWorkspacePath(source, key))) return void 0;
567
+ return await source.source.getMeta(key, ctx);
568
+ } } : {},
569
+ ...source.source.search ? { search: async (query, ctx) => {
570
+ const paths = selectedScopeQueryPaths(scope, query).filter((path) => pathIntersects(source.mountPath, path));
571
+ if (!paths.length) return [];
572
+ return filterScopedHits(scope, await source.source.search({
573
+ ...query,
574
+ paths
575
+ }, ctx));
576
+ } } : {}
577
+ };
578
+ if (!source.requestDescriptor || selectedScopeCanRead(scope, workspaceSourceRequestDescriptorPath(source.key))) copyWorkspaceSourceMetadata(source.source, scoped);
579
+ if (scopedLivePaths) markLiveWorkspaceSource(scoped, scopedLivePaths);
580
+ return scoped;
581
+ }
582
+ function syncScopedLivePaths(target, source, scope) {
583
+ if (!target || !source) return;
584
+ for (const path of Object.keys(target)) delete target[path];
585
+ for (const [path, value] of Object.entries(source)) if (selectedScopeCanRead(scope, path)) target[path] = value;
586
+ }
587
+ function sourceItemWorkspacePath(source, sourcePath) {
588
+ const normalized = normalizeWorkspacePath(sourcePath);
589
+ return normalizeWorkspacePath(source.mountPath ? `${source.mountPath}/${normalized}` : normalized);
590
+ }
591
+ function selectedScopeQueryPaths(scope, query) {
592
+ const requestedPaths = (query.paths?.length ? query.paths : [query.cwd || ""]).map((path) => normalizeWorkspacePath(path));
593
+ const scopedPaths = (scope.paths || []).map((path) => normalizeWorkspacePath(path));
594
+ const paths = /* @__PURE__ */ new Set();
595
+ for (const scopedPath of scopedPaths) for (const requestedPath of requestedPaths) if (pathContains(scopedPath, requestedPath)) paths.add(requestedPath);
596
+ else if (pathContains(requestedPath, scopedPath)) paths.add(scopedPath);
597
+ return [...paths];
598
+ }
599
+ function selectedScopeCanRead(scope, path) {
600
+ if (!scope || scope.all) return true;
601
+ const normalized = normalizeWorkspacePath(path);
602
+ return Boolean(scope.paths?.some((prefix) => pathContains(normalizeWorkspacePath(prefix), normalized)));
603
+ }
604
+ function selectedScopeCanSee(scope, path) {
605
+ if (!scope || scope.all) return true;
606
+ const normalized = normalizeWorkspacePath(path);
607
+ return Boolean(scope.paths?.some((prefix) => pathIntersects(normalizeWorkspacePath(prefix), normalized)));
608
+ }
609
+ function filterScopedEntries(scope, entries) {
610
+ return entries.filter((entry) => selectedScopeCanSee(scope, entry.path));
611
+ }
612
+ function filterScopedHits(scope, hits) {
613
+ return hits.filter((hit) => selectedScopeCanRead(scope, hit.path));
614
+ }
615
+ function mergeEntries(base, source) {
616
+ const entries = /* @__PURE__ */ new Map();
617
+ for (const entry of base) entries.set(entry.path, entry);
618
+ for (const entry of source) entries.set(entry.path, entry);
619
+ return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
620
+ }
621
+ function mergeHits(base, source) {
622
+ const seen = /* @__PURE__ */ new Set();
623
+ return [...base, ...source].filter((hit) => {
624
+ const key = `${hit.path}:${hit.line}:${hit.column}:${hit.text}`;
625
+ if (seen.has(key)) return false;
626
+ seen.add(key);
627
+ return true;
628
+ });
629
+ }
630
+ function selectedScopeIntersectsSource(scope, source) {
631
+ if (!scope || scope.all) return true;
632
+ if (scope.sources?.includes(source.key)) return true;
633
+ const sourcePaths = source.requestOnly ? [workspaceSourceRequestDescriptorPath(source.key)] : source.probeKeys?.length ? source.probeKeys.map((key) => [source.mountPath, key].filter(Boolean).join("/")) : [source.mountPath];
634
+ return Boolean(scope.paths?.some((path) => sourcePaths.some((sourcePath) => pathIntersects(path, sourcePath))));
635
+ }
636
+ function pathContains(container, path) {
637
+ return !container || path === container || path.startsWith(`${container}/`);
638
+ }
639
+ function pathIntersects(left, right) {
640
+ return pathContains(left, right) || pathContains(right, left);
641
+ }
642
+ //#endregion
643
+ export { attachWorkspaceSourceRequestExecution, createWorkspaceSourceResolutionFacade, getWorkspaceDependencyRuntimeLoaders, getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, getWorkspaceSourceRequestDescriptor, getWorkspaceSourceRequestExecution, hasWorkspaceSourceResolvers, isWorkspaceSourceRequestOnly, markLiveWorkspaceSource, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, registerWorkspace, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, resolveWorkspaceSources, setWorkspaceDependencyRuntimeLoaders, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace, workspaceSourceGrantPaths, workspaceSourceRequestDescriptorPath };
@@ -1,5 +1,5 @@
1
- import { t as __exportAll } from "./chunk-DrSxFLj_.js";
2
- import { o as normalizeWorkspacePath } from "./path-BVv9OXhg.js";
1
+ import { t as __exportAll } from "./chunk-8H4AJuhK.js";
2
+ import { c as normalizeWorkspacePath } from "./path-CNI6wKIU.js";
3
3
  //#region src/core/search.ts
4
4
  var search_exports = /* @__PURE__ */ __exportAll({
5
5
  searchText: () => searchText,