@vite-hub/workspace 0.0.3 → 0.0.4

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 (86) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +13 -2
  3. package/dist/{ai-Ce3PtWFW.js → ai-BqCC8BpY.js} +2 -2
  4. package/dist/{ai-nmHdzjCM.d.ts → ai-CjxvGqM0.d.ts} +1 -1
  5. package/dist/ai.d.ts +2 -2
  6. package/dist/ai.js +1 -1
  7. package/dist/{asset-registry-CaG9b7tf.js → asset-registry-8QI3ML3K.js} +1 -1
  8. package/dist/chunk-2rV9d50f.js +35 -0
  9. package/dist/cloudflare.d.ts +1 -1
  10. package/dist/cloudflare.js +1 -1
  11. package/dist/collections.d.ts +2 -2
  12. package/dist/collections.js +1 -1
  13. package/dist/{config-CZLO0m9h.js → config-Bc3c4Su1.js} +213 -120
  14. package/dist/{config-CDoyls2X.js → config-CHLLWklZ.js} +9 -3
  15. package/dist/{config-3I1BnsdO.d.ts → config-DE9xlaIw.d.ts} +1 -1
  16. package/dist/{file-CHfsZpso.js → file-Bc1X7pco.js} +3 -3
  17. package/dist/{files-QRV55OCx.js → files-Q6xZjDHA.js} +20 -9
  18. package/dist/{github-CfA5vpJ5.js → github-DHnjxQIX.js} +24 -15
  19. package/dist/{glob-D0vD_wRY.js → glob-CEZKeZFC.js} +5 -4
  20. package/dist/host-DJH8cuoU.js +1030 -0
  21. package/dist/{hosted-C1-tTTTf.js → hosted-RPeJOCFz.js} +121 -31
  22. package/dist/hosted-vercel-blob-d6C8ND5j.js +23580 -0
  23. package/dist/hosted-vercel-blob.d.ts +1 -1
  24. package/dist/hosted-vercel-blob.js +1 -1
  25. package/dist/hosted.d.ts +1 -1
  26. package/dist/hosted.js +1 -1
  27. package/dist/index.d.ts +42 -51
  28. package/dist/index.js +124 -419
  29. package/dist/lifecycle-LrL3sA4n.js +316 -0
  30. package/dist/loader.d.ts +1 -1
  31. package/dist/loader.js +1 -1
  32. package/dist/metadata-target-B0tOmVW7.js +717 -0
  33. package/dist/mountx.d.ts +1 -1
  34. package/dist/nitro.d.ts +1 -1
  35. package/dist/nitro.js +1 -1
  36. package/dist/nuxt.d.ts +1 -1
  37. package/dist/nuxt.js +8 -2
  38. package/dist/{path-CNI6wKIU.js → path-Cp59koVz.js} +28 -4
  39. package/dist/{provider-C3_elpEh.js → provider-B1yLjCJJ.js} +194 -47
  40. package/dist/providers/github/store.d.ts +1 -1
  41. package/dist/providers/github/store.js +1 -1
  42. package/dist/publish.d.ts +1 -1
  43. package/dist/publish.js +2 -2
  44. package/dist/registry-D3yzt8HQ.js +127 -0
  45. package/dist/{registry-BIQVCBWI.d.ts → registry-Uj6IVxes.d.ts} +3 -3
  46. package/dist/{request-execution-u9mgUXKX.js → request-execution-B-dSFlGB.js} +8 -4
  47. package/dist/runtime/assets.d.ts +1 -1
  48. package/dist/runtime/assets.js +4 -2
  49. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  50. package/dist/runtime/empty-registry.d.ts +1 -1
  51. package/dist/runtime/state.d.ts +4 -4
  52. package/dist/runtime/state.js +10 -7
  53. package/dist/runtime/workspace.d.ts +1 -1
  54. package/dist/runtime/workspace.js +1 -1
  55. package/dist/runtime-type-iEE6BjQJ.js +34 -0
  56. package/dist/runtime.d.ts +42 -7
  57. package/dist/runtime.js +275 -82
  58. package/dist/{search-C4REyHj9.js → search-BpiCF2Tw.js} +2 -2
  59. package/dist/server.d.ts +2 -2
  60. package/dist/server.js +23 -50
  61. package/dist/{shared-jfogBrd5.js → shared-DTR1Hhma.js} +97 -39
  62. package/dist/source-metadata.d.ts +9 -2
  63. package/dist/source-metadata.js +34 -2
  64. package/dist/{state-TTqa3x3Y.d.ts → state-tYcRWEh2.d.ts} +13 -12
  65. package/dist/store-Dt_Jyys3.js +608 -0
  66. package/dist/{sync-DiuDmSGk.js → sync-DnTQwt8r.js} +6 -5
  67. package/dist/test.d.ts +1 -1
  68. package/dist/test.js +1 -1
  69. package/dist/token-CVzURBxC.js +61 -0
  70. package/dist/{types-60Yn149G.d.ts → types-CYuwjJ4V.d.ts} +94 -27
  71. package/dist/{use-CsV3oIxH.js → use-BTNDR5Rd.js} +145 -31
  72. package/dist/{use-CUFSnFCS.d.ts → use-BiHzt0xA.d.ts} +21 -4
  73. package/dist/vite-BptCrpv2.js +4526 -0
  74. package/dist/vite-CtA9guIM.d.ts +66 -0
  75. package/dist/vite.d.ts +2 -50
  76. package/dist/vite.js +2 -2
  77. package/dist/{workspace-C4k92Ow8.js → workspace-Dq08Yn72.js} +224 -529
  78. package/dist/{workspace-66SKyiec.d.ts → workspace-Xddf4G1B.d.ts} +1 -1
  79. package/package.json +15 -18
  80. package/dist/chunk-8H4AJuhK.js +0 -14
  81. package/dist/host-CAnbugpI.js +0 -370
  82. package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
  83. package/dist/lifecycle-BYoa9hVb.js +0 -176
  84. package/dist/registry-CqyDTW9Y.js +0 -74
  85. package/dist/store-Bs1SLh55.js +0 -414
  86. package/dist/vite-tbfDxtlu.js +0 -2191
@@ -1,10 +1,12 @@
1
- import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, i as decodeFile, n as contentStreamToBytes, o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes } from "./path-CNI6wKIU.js";
2
- import { a as normalizeWorkspaceSources, c as sourceMountIntersectsPath, h as workspaceSourceRequestDescriptorPath, n as createSourceContext, s as sourceMountContainsPath } from "./config-CZLO0m9h.js";
3
- import { n as createWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-u9mgUXKX.js";
4
- import { s as createMemoryWorkspaceStore, t as createWorkspaceStoreFromProvider } from "./provider-C3_elpEh.js";
1
+ import { _ as workspaceError, a as isExcludedWorkspacePath, i as decodeFile, l as normalizeWorkspacePath, n as contentStreamToBytes, o as matchesAny, r as contentToBytes, s as normalizeSafeWorkspacePath } from "./path-Cp59koVz.js";
2
+ import { _ as workspaceSourceRequestDescriptorPath, a as normalizeWorkspaceSources, c as sourceMountIntersectsPath, n as createSourceContext, s as sourceMountContainsPath, u as prepareWorkspaceSource } from "./config-Bc3c4Su1.js";
3
+ import { n as createWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-B-dSFlGB.js";
4
+ import { s as createMemoryWorkspaceStore, t as createWorkspaceStoreFromProvider } from "./provider-B1yLjCJJ.js";
5
+ import { n as forwardWorkspaceRevisionMaterializer } from "./store-Dt_Jyys3.js";
5
6
  import { t as forwardWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
6
- import { t as searchText } from "./search-C4REyHj9.js";
7
- import { posix } from "node:path";
7
+ import { t as hasRuntimeType } from "./runtime-type-iEE6BjQJ.js";
8
+ import { t as searchText } from "./search-BpiCF2Tw.js";
9
+ import { a as hasFreshSourceSnapshot, c as readCurrentSourceSnapshot, i as hasCurrentSourceSnapshot, l as readResolvedSourceFile, o as materializeWorkspaceSources, p as statVirtualSourcePath, r as workspaceMetadataTarget, s as materializesCompleteSource, u as searchMaterializedStore } from "./metadata-target-B0tOmVW7.js";
8
10
  import { minimatch } from "minimatch";
9
11
  import { noExecutionAuthority } from "@vite-hub/runtime";
10
12
  //#region src/session/scope.ts
@@ -319,497 +321,6 @@ function resolveWorkspaceAutoCommit(definition, diff) {
319
321
  };
320
322
  }
321
323
  //#endregion
322
- //#region src/sources/source-items.ts
323
- function normalizeWorkspaceSourceItemPath(source, rawSourcePath, options = {}) {
324
- const sourcePath = normalizeSafeWorkspacePath(rawSourcePath, {
325
- allowEmpty: false,
326
- allowReserved: true
327
- });
328
- const label = options.operation ? `${options.operation} item path` : "source item path";
329
- if (sourcePath.split("/").some((part) => part === ".git" || part === ".vitehub")) throw workspaceError(`[vitehub] Workspace ${label} is reserved: ${rawSourcePath}.`);
330
- const path = normalizeSafeWorkspacePath(source.mountPath ? `${source.mountPath}/${sourcePath}` : sourcePath, { allowEmpty: false });
331
- if (source.mountPath && !sourceMountContainsPath(source, path)) throw workspaceError(`[vitehub] Workspace ${label} escapes source mount: ${rawSourcePath}.`);
332
- return {
333
- path,
334
- sourcePath
335
- };
336
- }
337
- function normalizeSourceItemPath(source, item, options = {}) {
338
- return normalizeWorkspaceSourceItemPath(source, item.path || item.key, options);
339
- }
340
- //#endregion
341
- //#region src/sources/materialization.ts
342
- function sourceSnapshotMetaKey(sourceKey) {
343
- return `source:${sourceKey}:snapshot`;
344
- }
345
- function sourceConfigFingerprint(source) {
346
- return {
347
- cache: source.cache,
348
- key: source.key,
349
- materialize: source.materialize,
350
- mountPath: source.mountPath,
351
- source: source.source.fingerprint
352
- };
353
- }
354
- async function sourceConfigHash(source) {
355
- return await sha256(sourceConfigFingerprint(source));
356
- }
357
- function isSnapshotFresh(meta, source, configHash) {
358
- if (!meta || meta.status !== "ready" || meta.configHash !== configHash) return false;
359
- if (!source.cache || typeof source.cache.maxAge !== "number") return false;
360
- if (!meta.materializedAt) return false;
361
- return Date.now() - Date.parse(meta.materializedAt) <= source.cache.maxAge * 1e3;
362
- }
363
- async function readSourceSnapshotMetadata(store, sourceKey) {
364
- return await store.getMeta?.(sourceSnapshotMetaKey(sourceKey));
365
- }
366
- async function hasCurrentSourceSnapshot(store, source) {
367
- const configHash = await sourceConfigHash(source);
368
- const meta = await readSourceSnapshotMetadata(store, source.key);
369
- return meta?.status === "ready" && meta.configHash === configHash;
370
- }
371
- async function writeSourceSnapshotMetadata(store, metadata) {
372
- await store.setMeta?.(sourceSnapshotMetaKey(metadata.source), metadata);
373
- }
374
- function materializedItemMeta(snapshot, configHash, path) {
375
- if (!snapshot || snapshot.configHash !== configHash) return void 0;
376
- if (snapshot.status !== "ready" && snapshot.status !== "updating" && snapshot.status !== "error") return void 0;
377
- return snapshot.items?.[path];
378
- }
379
- function checkpointItems(items) {
380
- return Object.keys(items).length ? items : void 0;
381
- }
382
- function contentSize(content) {
383
- return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
384
- }
385
- function sourcePathMatches(path, source, options) {
386
- if (options?.sources?.length && !options.sources.includes(source.key)) return false;
387
- const requested = normalizeWorkspacePath(options?.path || "");
388
- if (!requested) return true;
389
- return sourceMountIntersectsPath(source, requested);
390
- }
391
- function pathContains(container, path) {
392
- return !container || path === container || path.startsWith(`${container}/`);
393
- }
394
- function materializationPathMatches(path, options) {
395
- return pathContains(normalizeWorkspacePath(options?.path || ""), path);
396
- }
397
- function materializesCompleteSource(source, options) {
398
- const requested = normalizeWorkspacePath(options?.path || "");
399
- return !requested || Boolean(source.mountPath && pathContains(requested, source.mountPath));
400
- }
401
- function shouldMaterializeSource(source, options) {
402
- if (source.requestOnly || !sourcePathMatches("", source, options)) return false;
403
- if (source.materialize === "lazy") return true;
404
- return source.materialize === "build" && Boolean(options?.path);
405
- }
406
- function throwIfAborted(signal) {
407
- if (!signal?.aborted) return;
408
- throw signal.reason instanceof Error ? signal.reason : workspaceError("[vitehub] Workspace source materialization aborted.");
409
- }
410
- async function reportMaterializationProgress(options, source, event) {
411
- await options?.onProgress?.({
412
- ...event,
413
- mountPath: source.mountPath,
414
- path: normalizeWorkspacePath(options?.path || ""),
415
- source: source.key
416
- });
417
- }
418
- function shouldReportMaterializationUpdate(lastReportedAt, files) {
419
- return files === 1 || files % 25 === 0 || Date.now() - lastReportedAt >= 1e3;
420
- }
421
- function looksLikeConcreteFilePath(path) {
422
- const name = posix.basename(path);
423
- return name.includes(".") || [
424
- "Dockerfile",
425
- "LICENSE",
426
- "Makefile",
427
- "Procfile",
428
- "README"
429
- ].includes(name);
430
- }
431
- function directMaterializationSourceKey(source, options) {
432
- const requested = normalizeWorkspacePath(options?.path || "");
433
- if (!requested || !sourceMountContainsPath(source, requested) || requested === source.mountPath) return;
434
- const sourcePath = source.mountPath ? requested.slice(source.mountPath.length + 1) : requested;
435
- return sourcePath && looksLikeConcreteFilePath(sourcePath) ? sourcePath : void 0;
436
- }
437
- function parentDirectoryPaths(path) {
438
- const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
439
- const paths = [];
440
- for (let index = 1; index < parts.length; index++) paths.push(parts.slice(0, index).join("/"));
441
- return paths;
442
- }
443
- async function removeStaleMaterializedSourceFiles(store, source, nextPaths, scope, options = {}) {
444
- const entries = await store.list(source.mountPath, { recursive: true });
445
- const nextDirectories = new Set([...nextPaths].flatMap((path) => parentDirectoryPaths(path)));
446
- const staleDirectories = /* @__PURE__ */ new Set();
447
- for (const entry of entries) {
448
- if (!materializationPathMatches(entry.path, scope)) continue;
449
- if (nextPaths.has(entry.path) || entry.type !== "file") continue;
450
- const file = await store.readFile(entry.path);
451
- if (options.removeUntracked || file?.metadata?.source === source.key) {
452
- for (const directory of parentDirectoryPaths(entry.path)) staleDirectories.add(directory);
453
- await store.rm(entry.path, { force: true });
454
- }
455
- }
456
- for (const entry of entries.filter((entry) => entry.type === "directory" && staleDirectories.has(entry.path) && !nextDirectories.has(entry.path)).sort((a, b) => b.path.length - a.path.length)) try {
457
- await store.rm(entry.path, { force: true });
458
- } catch {}
459
- }
460
- async function* iterateSourceItems(source, ctx) {
461
- if (source.source.getItems) {
462
- yield* await source.source.getItems(ctx);
463
- return;
464
- }
465
- for (const key of await source.source.getKeys(ctx)) yield await source.source.getItem(key, ctx);
466
- }
467
- function createMaterializationEntry(source, item, upstreamMeta) {
468
- const { path, sourcePath } = normalizeSourceItemPath(source, item, { operation: "source materialization" });
469
- return {
470
- item,
471
- metadata: createLazyMaterializedMetadata({
472
- sourceKey: source.key,
473
- sourcePath,
474
- validate: source.validate
475
- }, item, upstreamMeta),
476
- path,
477
- ...sourceItemContent$1(item)
478
- };
479
- }
480
- function sourceItemContent$1(item) {
481
- if (item.contentStream) {
482
- if (typeof item.content !== "undefined" || typeof item.data !== "undefined") throw workspaceError("[vitehub] Workspace source items cannot define contentStream with content or data.");
483
- return { contentStream: item.contentStream };
484
- }
485
- return { content: item.content ?? (typeof item.data === "undefined" ? "" : JSON.stringify(item.data, null, 2)) };
486
- }
487
- async function* iterateMaterializationEntries(source, ctx, store, snapshot, configHash, options) {
488
- const directKey = directMaterializationSourceKey(source, options);
489
- if (directKey) {
490
- const entry = createMaterializationEntry(source, await source.source.getItem(directKey, ctx), void 0);
491
- if (materializationPathMatches(entry.path, options)) yield entry;
492
- return;
493
- }
494
- if (source.source.getItems) {
495
- for await (const item of iterateSourceItems(source, ctx)) {
496
- const entry = createMaterializationEntry(source, item, await source.source.getMeta?.(item.key, ctx));
497
- if (materializationPathMatches(entry.path, options)) yield entry;
498
- }
499
- return;
500
- }
501
- for (const key of await source.source.getKeys(ctx)) {
502
- const upstreamMeta = await source.source.getMeta?.(key, ctx);
503
- const { path, sourcePath } = normalizeWorkspaceSourceItemPath(source, key, { operation: "source materialization" });
504
- if (!materializationPathMatches(path, options)) continue;
505
- const previous = materializedItemMeta(snapshot, configHash, path);
506
- if (upstreamMeta && previous?.source === source.key && previous.sourcePath === sourcePath && !hasSourceMetaChanged(previous, upstreamMeta)) {
507
- const stat = await store.stat(path);
508
- if (stat?.type === "file") {
509
- yield {
510
- metadata: previous,
511
- path,
512
- reused: stat
513
- };
514
- continue;
515
- }
516
- }
517
- yield createMaterializationEntry(source, await source.source.getItem(key, ctx), upstreamMeta);
518
- }
519
- }
520
- async function materializeWorkspaceSources(definition, store, options = {}) {
521
- const started = Date.now();
522
- const sources = normalizeWorkspaceSources(definition.sources).filter((source) => shouldMaterializeSource(source, options));
523
- const resultSources = [];
524
- let files = 0;
525
- let directories = 0;
526
- let bytes = 0;
527
- for (const source of sources) {
528
- throwIfAborted(options.abortSignal);
529
- const sourceStarted = Date.now();
530
- await reportMaterializationProgress(options, source, { status: "started" });
531
- const configHash = await sourceConfigHash(source);
532
- const existing = await readSourceSnapshotMetadata(store, source.key);
533
- const completeSource = materializesCompleteSource(source, options);
534
- if (completeSource && isSnapshotFresh(existing, source, configHash)) {
535
- resultSources.push({
536
- source: source.key,
537
- mountPath: source.mountPath,
538
- status: "ready",
539
- commit: existing?.commit,
540
- materializedAt: existing?.materializedAt,
541
- files: existing?.files,
542
- bytes: existing?.bytes
543
- });
544
- files += existing?.files || 0;
545
- bytes += existing?.bytes || 0;
546
- await reportMaterializationProgress(options, source, {
547
- bytes: existing?.bytes || 0,
548
- durationMs: Date.now() - sourceStarted,
549
- files: existing?.files || 0,
550
- status: "completed"
551
- });
552
- continue;
553
- }
554
- const itemMetadata = existing?.configHash === configHash ? { ...existing.items || {} } : {};
555
- if (completeSource) await writeSourceSnapshotMetadata(store, {
556
- configHash,
557
- source: source.key,
558
- mountPath: source.mountPath,
559
- status: "updating",
560
- items: checkpointItems(itemMetadata),
561
- cacheMaxAge: source.cache ? source.cache.maxAge : void 0
562
- });
563
- let sourceFiles = 0;
564
- let sourceBytes = 0;
565
- let lastProgressAt = 0;
566
- try {
567
- const ctx = createSourceContext(definition, source, store, { abortSignal: options.abortSignal });
568
- throwIfAborted(options.abortSignal);
569
- await source.source.prepare?.(ctx);
570
- throwIfAborted(options.abortSignal);
571
- if (source.mountPath) await store.mkdir(source.mountPath, { recursive: true });
572
- let commit;
573
- const directorySet = new Set(source.mountPath ? [source.mountPath] : []);
574
- const nextPaths = /* @__PURE__ */ new Set();
575
- for await (const entry of iterateMaterializationEntries(source, ctx, store, existing, configHash, options)) {
576
- throwIfAborted(options.abortSignal);
577
- const path = entry.path;
578
- nextPaths.add(path);
579
- const parts = path.split("/");
580
- for (let index = 1; index < parts.length; index++) directorySet.add(parts.slice(0, index).join("/"));
581
- itemMetadata[path] = entry.metadata;
582
- if (entry.reused) {
583
- commit ||= entry.metadata.ref || entry.metadata.sha;
584
- sourceFiles++;
585
- sourceBytes += entry.reused.size || 0;
586
- if (completeSource) await writeSourceSnapshotMetadata(store, {
587
- configHash,
588
- source: source.key,
589
- mountPath: source.mountPath,
590
- status: "updating",
591
- commit,
592
- files: sourceFiles,
593
- bytes: sourceBytes,
594
- items: checkpointItems(itemMetadata),
595
- cacheMaxAge: source.cache ? source.cache.maxAge : void 0
596
- });
597
- if (shouldReportMaterializationUpdate(lastProgressAt, sourceFiles)) {
598
- lastProgressAt = Date.now();
599
- await reportMaterializationProgress(options, source, {
600
- bytes: sourceBytes,
601
- files: sourceFiles,
602
- status: "updating"
603
- });
604
- }
605
- continue;
606
- }
607
- const item = entry.item;
608
- const metadata = item.metadata || {};
609
- commit ||= readStringMeta(metadata, "ref") || readStringMeta(metadata, "sha") || entry.metadata.ref || entry.metadata.sha;
610
- const written = await writeMaterializedFile(store, path, {
611
- path,
612
- content: entry.content,
613
- contentStream: entry.contentStream,
614
- mediaType: item.mediaType,
615
- metadata: {
616
- ...metadata,
617
- ...entry.metadata,
618
- source: source.key
619
- }
620
- });
621
- sourceFiles++;
622
- sourceBytes += written.size || 0;
623
- if (completeSource) await writeSourceSnapshotMetadata(store, {
624
- configHash,
625
- source: source.key,
626
- mountPath: source.mountPath,
627
- status: "updating",
628
- commit,
629
- files: sourceFiles,
630
- bytes: sourceBytes,
631
- items: checkpointItems(itemMetadata),
632
- cacheMaxAge: source.cache ? source.cache.maxAge : void 0
633
- });
634
- if (shouldReportMaterializationUpdate(lastProgressAt, sourceFiles)) {
635
- lastProgressAt = Date.now();
636
- await reportMaterializationProgress(options, source, {
637
- bytes: sourceBytes,
638
- files: sourceFiles,
639
- status: "updating"
640
- });
641
- }
642
- }
643
- throwIfAborted(options.abortSignal);
644
- await removeStaleMaterializedSourceFiles(store, source, nextPaths, options, { removeUntracked: Boolean(source.mountPath) });
645
- const readyItems = Object.fromEntries([...nextPaths].flatMap((path) => {
646
- const metadata = itemMetadata[path];
647
- return metadata ? [[path, metadata]] : [];
648
- }));
649
- const ready = {
650
- configHash,
651
- source: source.key,
652
- mountPath: source.mountPath,
653
- status: "ready",
654
- commit,
655
- materializedAt: (/* @__PURE__ */ new Date()).toISOString(),
656
- files: sourceFiles,
657
- bytes: sourceBytes,
658
- items: readyItems,
659
- cacheMaxAge: source.cache ? source.cache.maxAge : void 0
660
- };
661
- if (completeSource) await writeSourceSnapshotMetadata(store, ready);
662
- else if (existing?.configHash === configHash) await writeSourceSnapshotMetadata(store, {
663
- ...existing,
664
- items: checkpointItems(itemMetadata)
665
- });
666
- resultSources.push(ready);
667
- files += sourceFiles;
668
- bytes += sourceBytes;
669
- directories += directorySet.size;
670
- await reportMaterializationProgress(options, source, {
671
- bytes: sourceBytes,
672
- directories: directorySet.size,
673
- durationMs: Date.now() - sourceStarted,
674
- files: sourceFiles,
675
- status: "completed"
676
- });
677
- } catch (error) {
678
- const failed = {
679
- configHash,
680
- source: source.key,
681
- mountPath: source.mountPath,
682
- status: "error",
683
- error: error instanceof Error ? error.message : String(error),
684
- files: sourceFiles,
685
- bytes: sourceBytes,
686
- items: checkpointItems(itemMetadata),
687
- cacheMaxAge: source.cache ? source.cache.maxAge : void 0
688
- };
689
- if (!options.abortSignal?.aborted) await writeSourceSnapshotMetadata(store, failed);
690
- resultSources.push(failed);
691
- await reportMaterializationProgress(options, source, {
692
- bytes: sourceBytes,
693
- durationMs: Date.now() - sourceStarted,
694
- error: failed.error,
695
- files: sourceFiles,
696
- status: "failed"
697
- });
698
- if (options.abortSignal?.aborted) throw error;
699
- }
700
- }
701
- return {
702
- bytes,
703
- directories,
704
- durationMs: Date.now() - started,
705
- files,
706
- path: normalizeWorkspacePath(options.path || ""),
707
- sources: resultSources
708
- };
709
- }
710
- async function readResolvedSourceFile(resolution, store, ctx, options) {
711
- const file = await store.readFile(resolution.workspacePath);
712
- if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${resolution.workspacePath}.`);
713
- return decodeFile(file.content, options);
714
- }
715
- async function writeMaterializedFile(store, path, file) {
716
- if (file.contentStream) {
717
- if (store.writeFileStream) return await store.writeFileStream(path, {
718
- path: file.path,
719
- content: file.contentStream,
720
- mediaType: file.mediaType,
721
- metadata: file.metadata
722
- });
723
- const content = await contentStreamToBytes(file.contentStream);
724
- await store.writeFile(path, {
725
- path: file.path,
726
- content,
727
- mediaType: file.mediaType,
728
- metadata: file.metadata
729
- });
730
- return { size: content.byteLength };
731
- }
732
- const content = file.content ?? "";
733
- await store.writeFile(path, {
734
- path: file.path,
735
- content,
736
- mediaType: file.mediaType,
737
- metadata: file.metadata
738
- });
739
- return { size: contentSize(content) };
740
- }
741
- async function statVirtualSourcePath(source, workspacePath, store, ctx) {
742
- const stored = await store.stat(workspacePath);
743
- if (stored) return stored;
744
- const keys = await source.source.getKeys(ctx);
745
- const sourcePath = normalizeSourcePath(source, workspacePath);
746
- if (!sourcePath && keys.length > 0) return {
747
- path: source.mountPath,
748
- type: "directory"
749
- };
750
- if (keys.includes(sourcePath)) return {
751
- path: workspacePath,
752
- type: "file",
753
- digest: readDigest(await source.source.getMeta?.(sourcePath, ctx))
754
- };
755
- if (keys.some((key) => key.startsWith(`${sourcePath}/`))) return {
756
- path: workspacePath,
757
- type: "directory"
758
- };
759
- }
760
- async function searchMaterializedStore(store, query) {
761
- const limit = query.limit ?? 100;
762
- const result = [];
763
- const entries = query.paths?.length ? (await Promise.all(query.paths.map(async (path) => {
764
- const [stat, nested] = await Promise.all([store.stat(path), store.glob(`${path}/**/*`)]);
765
- return [...stat?.type === "file" ? [stat] : [], ...nested];
766
- }))).flat() : await store.glob("**/*");
767
- for (const entry of entries) {
768
- if (entry.type !== "file") continue;
769
- const file = await store.readFile(entry.path);
770
- if (!file) continue;
771
- const text = typeof file.content === "string" ? file.content : new TextDecoder().decode(file.content);
772
- result.push(...searchText(entry.path, text, {
773
- ...query,
774
- limit: limit - result.length
775
- }));
776
- if (result.length >= limit) break;
777
- }
778
- return result.slice(0, limit);
779
- }
780
- function createLazyMaterializedMetadata(resolution, item, upstreamMeta) {
781
- const now = (/* @__PURE__ */ new Date()).toISOString();
782
- return {
783
- source: resolution.sourceKey,
784
- sourcePath: resolution.sourcePath,
785
- materializedAt: now,
786
- validatedAt: resolution.validate === "request" ? now : void 0,
787
- etag: readStringMeta(upstreamMeta, "etag"),
788
- sha: readStringMeta(upstreamMeta, "sha"),
789
- digest: readStringMeta(upstreamMeta, "digest") || readStringMeta(item.metadata, "digest"),
790
- ref: readStringMeta(upstreamMeta, "ref")
791
- };
792
- }
793
- function hasSourceMetaChanged(current, upstreamMeta) {
794
- const next = {
795
- etag: readStringMeta(upstreamMeta, "etag"),
796
- sha: readStringMeta(upstreamMeta, "sha"),
797
- digest: readStringMeta(upstreamMeta, "digest"),
798
- ref: readStringMeta(upstreamMeta, "ref")
799
- };
800
- return current.etag !== next.etag || current.sha !== next.sha || current.digest !== next.digest || current.ref !== next.ref;
801
- }
802
- function normalizeSourcePath(source, workspacePath) {
803
- if (workspacePath === source.mountPath) return "";
804
- return source.mountPath && workspacePath.startsWith(`${source.mountPath}/`) ? normalizeWorkspacePath(workspacePath.slice(source.mountPath.length + 1)) : normalizeWorkspacePath(workspacePath);
805
- }
806
- function readStringMeta(meta, key) {
807
- return typeof meta?.[key] === "string" ? meta[key] : void 0;
808
- }
809
- function readDigest(meta) {
810
- return readStringMeta(meta, "digest") || readStringMeta(meta, "sha");
811
- }
812
- //#endregion
813
324
  //#region src/sources/resolver.ts
814
325
  function resolveWorkspacePath(definition, path) {
815
326
  const workspacePath = normalizeSafeWorkspacePath(path, { allowEmpty: true });
@@ -872,17 +383,67 @@ function canonicalSourceSyncState(state) {
872
383
  }
873
384
  //#endregion
874
385
  //#region src/sources/view.ts
875
- function createWorkspaceSourceView(definition, store) {
386
+ const materializationByStore = /* @__PURE__ */ new WeakMap();
387
+ async function invalidateWorkspaceSourceMaterialization(definition, store, sourceKeys) {
388
+ const state = materializationByStore.get(store)?.get(definition);
389
+ if (!state) return;
390
+ const pending = /* @__PURE__ */ new Set();
391
+ for (const sourceKey of sourceKeys) {
392
+ state.completedSources.delete(sourceKey);
393
+ state.materializedSources.delete(sourceKey);
394
+ state.generationBySource.set(sourceKey, (state.generationBySource.get(sourceKey) ?? 0) + 1);
395
+ const operation = state.pendingBySource.get(sourceKey);
396
+ if (operation) pending.add(operation.tail);
397
+ }
398
+ await Promise.all(pending);
399
+ }
400
+ async function waitForMaterialization(pending, signal) {
401
+ if (!signal) return await pending;
402
+ signal.throwIfAborted();
403
+ let removeAbortListener = () => {};
404
+ const aborted = new Promise((_resolve, reject) => {
405
+ const onAbort = () => reject(signal.reason);
406
+ signal.addEventListener("abort", onAbort, { once: true });
407
+ removeAbortListener = () => signal.removeEventListener("abort", onAbort);
408
+ if (signal.aborted) onAbort();
409
+ });
410
+ try {
411
+ return await Promise.race([pending, aborted]);
412
+ } finally {
413
+ removeAbortListener();
414
+ }
415
+ }
416
+ function createWorkspaceSourceView(definition, store, options = {}) {
876
417
  const sourceContext = createSourceContext(definition, void 0, store);
877
418
  const allSources = normalizeWorkspaceSources(definition.sources);
878
- const sources = allSources.filter((source) => !source.requestOnly && source.materialize === "lazy");
419
+ const sources = allSources.filter((source) => !source.requestOnly && (source.materialize === "lazy" || source.materialize === "startup"));
879
420
  const syncSources = allSources.filter((source) => source.sync);
880
421
  const descriptorSources = allSources.filter((source) => source.requestDescriptor);
881
422
  const writePolicy = createWorkspaceWritePolicy(definition);
882
423
  const prepareBySource = /* @__PURE__ */ new Map();
883
- const materializeBySource = /* @__PURE__ */ new Map();
424
+ const sourceContexts = /* @__PURE__ */ new Map();
425
+ let materializationByDefinition = materializationByStore.get(store);
426
+ if (!materializationByDefinition) {
427
+ materializationByDefinition = /* @__PURE__ */ new WeakMap();
428
+ materializationByStore.set(store, materializationByDefinition);
429
+ }
430
+ const materializationState = materializationByDefinition.get(definition) ?? {
431
+ completedSources: /* @__PURE__ */ new Set(),
432
+ generationBySource: /* @__PURE__ */ new Map(),
433
+ materializedSources: /* @__PURE__ */ new Set(),
434
+ pendingBySource: /* @__PURE__ */ new Map()
435
+ };
436
+ if (!materializationByDefinition.has(definition)) materializationByDefinition.set(definition, materializationState);
437
+ const { completedSources, generationBySource, materializedSources, pendingBySource } = materializationState;
438
+ const uncachedMaterializedSources = /* @__PURE__ */ new Set();
439
+ const persistsSourceSnapshots = Boolean(store.getMeta && store.setMeta);
884
440
  function getSourceContext(source) {
885
- return createSourceContext(definition, source, store);
441
+ let context = sourceContexts.get(source.key);
442
+ if (!context) {
443
+ context = createSourceContext(definition, source, store);
444
+ sourceContexts.set(source.key, context);
445
+ }
446
+ return context;
886
447
  }
887
448
  function isLazySourcePath(path) {
888
449
  return sources.some((source) => sourceMountContainsPath(source, path));
@@ -954,17 +515,29 @@ function createWorkspaceSourceView(definition, store) {
954
515
  }, null, 2);
955
516
  }
956
517
  function isLiveSource(sourceKey) {
957
- return Boolean(sources.find((item) => item.key === sourceKey)?.livePaths);
518
+ const source = sources.find((item) => item.key === sourceKey);
519
+ return Boolean(source?.livePaths && source.materialize !== "startup");
520
+ }
521
+ function usesLiveProvider(source) {
522
+ return Boolean(source.livePaths && source.materialize !== "startup");
958
523
  }
959
524
  function getLazySourcesForPath(path) {
960
525
  return sources.filter((source) => sourceMountIntersectsPath(source, path));
961
526
  }
962
527
  async function ensurePrepared(sourceKey) {
963
528
  const source = sources.find((item) => item.key === sourceKey);
964
- if (!source?.source.prepare) return;
529
+ if (!source) return;
530
+ if (source.materialize === "startup" && completedSources.has(sourceKey)) {
531
+ if (!persistsSourceSnapshots || await hasCurrentSourceSnapshot(store, source)) return;
532
+ completedSources.delete(sourceKey);
533
+ }
534
+ if (source.materialize === "startup" && options.reuseStartupSnapshots && await hasCurrentSourceSnapshot(store, source)) {
535
+ completedSources.add(sourceKey);
536
+ return;
537
+ }
965
538
  let pending = prepareBySource.get(sourceKey);
966
539
  if (!pending) {
967
- pending = source.source.prepare(getSourceContext(source));
540
+ pending = prepareWorkspaceSource(source.source, getSourceContext(source)).then(() => void 0);
968
541
  prepareBySource.set(sourceKey, pending);
969
542
  }
970
543
  await pending;
@@ -972,24 +545,116 @@ function createWorkspaceSourceView(definition, store) {
972
545
  async function ensurePreparedSources(items = sources) {
973
546
  await Promise.all(items.map(async (source) => await ensurePrepared(source.key)));
974
547
  }
548
+ async function materializeSerialized(options = {}) {
549
+ const requestedPath = normalizeWorkspacePath(options.path || "");
550
+ const selectedSources = allSources.filter((source) => source.materialize === "lazy" || source.materialize === "startup" || source.materialize === "build" && Boolean(requestedPath)).filter((source) => (!options.sources?.length || options.sources.includes(source.key)) && sourceMountIntersectsPath(source, requestedPath));
551
+ const predecessors = selectedSources.flatMap((source) => {
552
+ const pending = pendingBySource.get(source.key);
553
+ return pending ? [pending.tail] : [];
554
+ });
555
+ const previous = waitForMaterialization(Promise.all(predecessors), options.abortSignal);
556
+ const current = (async () => {
557
+ await previous;
558
+ const generations = new Map(selectedSources.map((source) => {
559
+ const generation = (generationBySource.get(source.key) ?? 0) + 1;
560
+ generationBySource.set(source.key, generation);
561
+ return [source.key, generation];
562
+ }));
563
+ const mutations = /* @__PURE__ */ new Set();
564
+ const isCurrent = () => selectedSources.every((source) => generationBySource.get(source.key) === generations.get(source.key));
565
+ async function trackMutation(operation) {
566
+ if (!isCurrent()) throw options.abortSignal?.reason ?? workspaceError("[vitehub] Workspace source materialization was superseded.");
567
+ const mutation = operation();
568
+ mutations.add(mutation);
569
+ try {
570
+ return await mutation;
571
+ } finally {
572
+ mutations.delete(mutation);
573
+ }
574
+ }
575
+ for (const source of selectedSources) {
576
+ if (!materializesCompleteSource(source, options)) continue;
577
+ materializedSources.delete(source.key);
578
+ if (source.materialize === "startup") completedSources.delete(source.key);
579
+ }
580
+ let result;
581
+ try {
582
+ result = await waitForMaterialization(materializeWorkspaceSources(definition, store, options, {
583
+ isCurrent,
584
+ async mutate(operation) {
585
+ options.abortSignal?.throwIfAborted();
586
+ return await trackMutation(operation);
587
+ },
588
+ async checkpoint(operation) {
589
+ return await trackMutation(operation);
590
+ }
591
+ }), options.abortSignal);
592
+ } catch (error) {
593
+ if (options.abortSignal?.aborted && mutations.size) await Promise.allSettled(mutations);
594
+ throw error;
595
+ }
596
+ for (const sourceResult of result.sources) {
597
+ const source = sources.find((item) => item.key === sourceResult.source);
598
+ if (sourceResult.status === "ready" && source && materializesCompleteSource(source, options)) {
599
+ materializedSources.add(source.key);
600
+ if (source.materialize === "lazy" && source.cache === false) uncachedMaterializedSources.add(source.key);
601
+ if (source.materialize === "startup") completedSources.add(source.key);
602
+ }
603
+ }
604
+ return result;
605
+ })();
606
+ const tail = current.then(() => void 0, async () => {
607
+ await Promise.allSettled(predecessors);
608
+ });
609
+ const entries = new Map(selectedSources.map((source) => [source.key, {
610
+ fullSource: materializesCompleteSource(source, options),
611
+ promise: current,
612
+ tail
613
+ }]));
614
+ for (const [sourceKey, entry] of entries) pendingBySource.set(sourceKey, entry);
615
+ tail.then(() => {
616
+ for (const [sourceKey, entry] of entries) if (pendingBySource.get(sourceKey) === entry) pendingBySource.delete(sourceKey);
617
+ });
618
+ return await current;
619
+ }
975
620
  async function ensureMaterialized(sourceKey) {
976
- let pending = materializeBySource.get(sourceKey);
977
- if (!pending) {
978
- pending = materializeWorkspaceSources(definition, store, { sources: [sourceKey] }).then(() => void 0);
979
- materializeBySource.set(sourceKey, pending);
621
+ const source = sources.find((item) => item.key === sourceKey);
622
+ if (!source) return;
623
+ const isUncachedLazySource = source.materialize === "lazy" && source.cache === false;
624
+ const pending = pendingBySource.get(sourceKey);
625
+ if (pending?.fullSource) {
626
+ try {
627
+ await pending.promise;
628
+ } catch {}
629
+ if (materializedSources.has(sourceKey) || completedSources.has(sourceKey)) {
630
+ if (isUncachedLazySource) uncachedMaterializedSources.add(sourceKey);
631
+ return;
632
+ }
980
633
  }
981
- await pending;
634
+ if (isUncachedLazySource ? uncachedMaterializedSources.has(sourceKey) : materializedSources.has(sourceKey)) {
635
+ const maxAge = source.cache && source.cache.maxAge;
636
+ if (source.materialize !== "lazy" || !Number.isFinite(maxAge) || await hasFreshSourceSnapshot(store, source)) return;
637
+ materializedSources.delete(sourceKey);
638
+ }
639
+ if (completedSources.has(sourceKey)) {
640
+ if (!persistsSourceSnapshots || await hasCurrentSourceSnapshot(store, source)) return;
641
+ completedSources.delete(sourceKey);
642
+ }
643
+ await materializeSerialized({ sources: [sourceKey] });
982
644
  }
983
645
  async function ensureMaterializedSources(items = sources) {
984
646
  await Promise.all(items.map(async (source) => await ensureMaterialized(source.key)));
985
647
  }
986
648
  async function listSourceAware(path = "", options = {}) {
987
- const storeEntries = await store.list(path, options);
649
+ const normalized = normalizeWorkspacePath(path);
650
+ const storeEntries = isDescriptorPath(normalized) ? [] : await store.list(path, options);
988
651
  const result = new Map(storeEntries.map((entry) => [entry.path, entry]));
989
- for (const entry of descriptorPathEntries(path, options)) result.set(entry.path, entry);
652
+ for (const entry of descriptorPathEntries(path, options)) if (!isExcludedWorkspacePath(entry.path, options.exclude)) result.set(entry.path, entry);
653
+ if (isDescriptorPath(normalized)) return [...result.values()].sort((left, right) => left.path.localeCompare(right.path));
990
654
  for (const source of getLazySourcesForPath(path)) {
655
+ if (isExcludedWorkspacePath(source.mountPath, options.exclude)) continue;
991
656
  await ensurePrepared(source.key);
992
- if (source.livePaths) {
657
+ if (usesLiveProvider(source)) {
993
658
  await pruneLiveSourceStoreEntries(result, source);
994
659
  continue;
995
660
  }
@@ -1054,7 +719,7 @@ function createWorkspaceSourceView(definition, store) {
1054
719
  for (const source of sources) {
1055
720
  const paths = sourcePaths.get(source.key);
1056
721
  if (query.paths?.length && !paths?.length && !query.paths.some((path) => !normalizeWorkspacePath(path))) continue;
1057
- if (source.livePaths) {
722
+ if (usesLiveProvider(source)) {
1058
723
  await ensurePrepared(source.key);
1059
724
  const liveEntries = liveSourceEntries(source).filter((entry) => entry.type === "file").filter((entry) => !paths?.length || paths.some((path) => !path || entry.path === path || entry.path.startsWith(`${path}/`)));
1060
725
  for (const entry of liveEntries) {
@@ -1139,6 +804,11 @@ function createWorkspaceSourceView(definition, store) {
1139
804
  if (resolution.type === "source") {
1140
805
  await ensurePrepared(resolution.sourceKey);
1141
806
  if (isLiveSource(resolution.sourceKey)) return decodeFile(await sourceItemContent(await resolution.source.source.getItem(resolution.sourcePath, getSourceContext(resolution.source))), options);
807
+ if (resolution.source.materialize === "startup" && !completedSources.has(resolution.sourceKey) && !materializedSources.has(resolution.sourceKey)) await ensureMaterialized(resolution.sourceKey);
808
+ const cacheMaxAge = resolution.source.cache && resolution.source.cache.maxAge;
809
+ let shouldRefreshCachedLazy = false;
810
+ if (resolution.source.materialize === "lazy" && Number.isFinite(cacheMaxAge)) shouldRefreshCachedLazy = materializedSources.has(resolution.sourceKey) || Boolean(await readCurrentSourceSnapshot(store, resolution.source));
811
+ if (shouldRefreshCachedLazy) await ensureMaterialized(resolution.sourceKey);
1142
812
  const file = await store.readFile(resolution.workspacePath);
1143
813
  if (file) return decodeFile(file.content, options);
1144
814
  await ensureMaterialized(resolution.sourceKey);
@@ -1161,13 +831,19 @@ function createWorkspaceSourceView(definition, store) {
1161
831
  workspace: definition.name
1162
832
  });
1163
833
  try {
1164
- await store.writeFile(input.path, {
834
+ if (options?.preservePath && input.path !== resolution.workspacePath) throw workspaceError(`[vitehub] Workspace validator cannot rewrite preserved path: ${resolution.workspacePath} -> ${input.path}.`);
835
+ const file = {
1165
836
  path: input.path,
1166
837
  content: input.content ?? content,
1167
838
  mediaType: input.mediaType,
1168
839
  metadata: input.metadata
1169
- });
840
+ };
841
+ if (options?.ifDigest !== void 0) {
842
+ if (!store.writeFileConditional) throw workspaceError("[vitehub] This Workspace Store does not support conditional writes.");
843
+ await store.writeFileConditional(input.path, file, options.ifDigest);
844
+ } else await store.writeFile(input.path, file);
1170
845
  await writePolicy.after(input);
846
+ return input.path;
1171
847
  } catch (error) {
1172
848
  await writePolicy.error(input, error);
1173
849
  throw error;
@@ -1179,11 +855,11 @@ function createWorkspaceSourceView(definition, store) {
1179
855
  async glob(pattern, options) {
1180
856
  const patterns = Array.isArray(pattern) ? pattern : [pattern];
1181
857
  await ensurePreparedSources();
1182
- await ensureMaterializedSources(sources.filter((source) => !source.livePaths));
858
+ await ensureMaterializedSources(sources.filter((source) => !usesLiveProvider(source)));
1183
859
  const result = /* @__PURE__ */ new Map();
1184
860
  for (const entry of await store.glob(patterns, options)) result.set(entry.path, entry);
1185
861
  for (const entry of descriptorPathEntries("", { recursive: true })) if (entry.type === "file" && patterns.some((pattern) => matchesAny(entry.path, pattern))) result.set(entry.path, entry);
1186
- for (const source of sources.filter((source) => source.livePaths)) {
862
+ for (const source of sources.filter(usesLiveProvider)) {
1187
863
  await pruneLiveSourceStoreEntries(result, source);
1188
864
  for (const entry of liveSourceEntries(source)) if (entry.type === "file" && patterns.some((pattern) => matchesAny(entry.path, pattern))) result.set(entry.path, entry);
1189
865
  }
@@ -1207,8 +883,10 @@ function createWorkspaceSourceView(definition, store) {
1207
883
  if (!result) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
1208
884
  return result;
1209
885
  }
886
+ if (resolution.source.materialize === "startup") await ensureMaterialized(resolution.sourceKey);
1210
887
  const stored = await store.stat(resolution.workspacePath);
1211
888
  if (stored) return stored;
889
+ if (resolution.source.materialize === "startup" && completedSources.has(resolution.sourceKey)) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
1212
890
  await ensureMaterialized(resolution.sourceKey);
1213
891
  const result = await statVirtualSourcePath(resolution.source, resolution.workspacePath, store, getSourceContext(resolution.source));
1214
892
  if (!result) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
@@ -1216,7 +894,7 @@ function createWorkspaceSourceView(definition, store) {
1216
894
  }
1217
895
  let result = await store.stat(resolution.workspacePath);
1218
896
  if (!result) {
1219
- if (!resolution.workspacePath && sources.some((source) => !source.mountPath && source.livePaths)) return {
897
+ if (!resolution.workspacePath && sources.some((source) => !source.mountPath && usesLiveProvider(source))) return {
1220
898
  path: "",
1221
899
  type: "directory"
1222
900
  };
@@ -1227,7 +905,7 @@ function createWorkspaceSourceView(definition, store) {
1227
905
  return result;
1228
906
  },
1229
907
  async materializeSources(options) {
1230
- return await materializeWorkspaceSources(definition, store, options);
908
+ return await materializeSerialized(options);
1231
909
  },
1232
910
  async exists(path) {
1233
911
  if (descriptorStat(normalizeWorkspacePath(path))) return true;
@@ -1238,12 +916,14 @@ function createWorkspaceSourceView(definition, store) {
1238
916
  if (!resolution.workspacePath) return true;
1239
917
  return Boolean(liveSourceStat(resolution.source, resolution.workspacePath));
1240
918
  }
919
+ if (resolution.source.materialize === "startup") await ensureMaterialized(resolution.sourceKey);
1241
920
  if (await store.stat(resolution.workspacePath)) return true;
921
+ if (resolution.source.materialize === "startup" && completedSources.has(resolution.sourceKey)) return false;
1242
922
  await ensureMaterialized(resolution.sourceKey);
1243
923
  return Boolean(await statVirtualSourcePath(resolution.source, resolution.workspacePath, store, getSourceContext(resolution.source)));
1244
924
  }
1245
925
  if (await store.stat(resolution.workspacePath)) return true;
1246
- if (!resolution.workspacePath && sources.some((source) => !source.mountPath && source.livePaths)) return true;
926
+ if (!resolution.workspacePath && sources.some((source) => !source.mountPath && usesLiveProvider(source))) return true;
1247
927
  await materializeRootSourceForPath(resolution.workspacePath);
1248
928
  return Boolean(await store.stat(resolution.workspacePath));
1249
929
  },
@@ -1326,6 +1006,7 @@ function addLiveSourceEntries(result, path, options, sources) {
1326
1006
  const normalized = normalizeWorkspacePath(path);
1327
1007
  for (const source of sources.filter((source) => source.livePaths)) for (const entry of liveSourceEntries(source)) {
1328
1008
  if (!isListedLiveEntry(entry, normalized, options)) continue;
1009
+ if (isExcludedWorkspacePath(entry.path, options.exclude)) continue;
1329
1010
  result.set(entry.path, entry);
1330
1011
  }
1331
1012
  }
@@ -1371,6 +1052,9 @@ function getCachedWorkspaceStore(definition, create) {
1371
1052
  }
1372
1053
  return store;
1373
1054
  }
1055
+ function invalidateCachedWorkspaceStore(definition) {
1056
+ storeByDefinition.delete(definition);
1057
+ }
1374
1058
  function resetWorkspaceStoreCache() {
1375
1059
  storeByDefinition = /* @__PURE__ */ new WeakMap();
1376
1060
  }
@@ -1383,9 +1067,13 @@ function createWorkspace(definition) {
1383
1067
  const store = getStore(definition);
1384
1068
  const files = createWorkspaceSourceView(definition, store);
1385
1069
  const workspace = {
1070
+ [workspaceMetadataTarget]: () => store,
1386
1071
  name: definition.name,
1072
+ async capabilities() {
1073
+ return { conditionalWrites: hasRuntimeType(store.writeFileConditional, "function") };
1074
+ },
1387
1075
  async sync(options) {
1388
- const { syncWorkspaceSources } = await import("./sync-DiuDmSGk.js");
1076
+ const { syncWorkspaceSources } = await import("./sync-DnTQwt8r.js");
1389
1077
  return await syncWorkspaceSources(definition, store, options);
1390
1078
  },
1391
1079
  async materializeSources(options) {
@@ -1401,7 +1089,7 @@ function createWorkspace(definition) {
1401
1089
  return await files.readFile(path, options);
1402
1090
  },
1403
1091
  async writeFile(path, content, options) {
1404
- await files.writeFile(path, content, options);
1092
+ return await files.writeFile(path, content, options);
1405
1093
  },
1406
1094
  async list(path, options) {
1407
1095
  return await files.list(path, options);
@@ -1425,22 +1113,26 @@ function createWorkspace(definition) {
1425
1113
  await files.rm(path, options);
1426
1114
  },
1427
1115
  async publish(options) {
1428
- const { publishWorkspace } = await import("./lifecycle-BYoa9hVb.js").then((n) => n.t);
1116
+ const { publishWorkspace } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
1429
1117
  await publishWorkspace(definition, store, options);
1430
1118
  },
1431
1119
  async snapshot(options) {
1432
1120
  const snapshot = await store.snapshot(options);
1433
- const { publishWorkspaceSnapshot } = await import("./lifecycle-BYoa9hVb.js").then((n) => n.t);
1121
+ const { publishWorkspaceSnapshot } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
1434
1122
  await publishWorkspaceSnapshot(definition, store, snapshot);
1435
1123
  return snapshot;
1436
1124
  },
1125
+ async rebase(options) {
1126
+ if (!store.rebase) throw new Error("[vitehub] Workspace Store does not support rebasing.");
1127
+ await store.rebase(options);
1128
+ },
1437
1129
  async diff(options) {
1438
1130
  return await store.diff(options);
1439
1131
  },
1440
1132
  async startSession(options) {
1441
1133
  const host = options?.host;
1442
1134
  if (host) {
1443
- const { createHostedWorkspaceSession } = await import("./host-CAnbugpI.js");
1135
+ const { createHostedWorkspaceSession } = await import("./host-DJH8cuoU.js").then((n) => n.n);
1444
1136
  return await createHostedWorkspaceSession(workspace, {
1445
1137
  ...options,
1446
1138
  host
@@ -1450,11 +1142,14 @@ function createWorkspace(definition) {
1450
1142
  }
1451
1143
  };
1452
1144
  forwardWorkspaceStoreTarget(store, workspace);
1453
- workspace.__syncWorkspaceDefinition = async () => {
1454
- const { syncWorkspaceDefinition } = await import("./lifecycle-BYoa9hVb.js").then((n) => n.t);
1455
- await syncWorkspaceDefinition(definition, store);
1145
+ if (!normalizeWorkspaceSources(definition.sources).some((source) => source.requestDescriptor || source.livePaths)) forwardWorkspaceRevisionMaterializer(store, workspace);
1146
+ const synchronizedWorkspace = workspace;
1147
+ synchronizedWorkspace.__workspaceDefinitionSyncKey = definition;
1148
+ synchronizedWorkspace.__syncWorkspaceDefinition = async (abortSignal) => {
1149
+ const { syncWorkspaceDefinition } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
1150
+ await syncWorkspaceDefinition(definition, store, abortSignal);
1456
1151
  };
1457
1152
  return attachWorkspaceSourceRequestExecution(workspace, createWorkspaceSourceRequestExecution(definition));
1458
1153
  }
1459
1154
  //#endregion
1460
- export { scopedSearchQuery as _, sourceSyncMetaKey as a, normalizeSourceItemPath as c, createBasicWorkspaceSession as d, assertDiffInsideSessionPaths as f, isMissingWorkspacePathError as g, filterSessionEntries as h, readWorkspaceSourceSyncState as i, createWorkspaceWritePolicy as l, filterSessionDiff as m, resetWorkspaceStoreCache as n, workspaceSourceSyncStateEquals as o, assertPathInSessionScope as p, createWorkspaceSourceView as r, resolveWorkspacePath as s, createWorkspace as t, resolveWorkspaceAutoCommit as u };
1155
+ export { isMissingWorkspacePathError as _, invalidateWorkspaceSourceMaterialization as a, workspaceSourceSyncStateEquals as c, resolveWorkspaceAutoCommit as d, createBasicWorkspaceSession as f, filterSessionEntries as g, filterSessionDiff as h, createWorkspaceSourceView as i, resolveWorkspacePath as l, assertPathInSessionScope as m, invalidateCachedWorkspaceStore as n, readWorkspaceSourceSyncState as o, assertDiffInsideSessionPaths as p, resetWorkspaceStoreCache as r, sourceSyncMetaKey as s, createWorkspace as t, createWorkspaceWritePolicy as u, scopedSearchQuery as v };