@vite-hub/workspace 0.0.4 → 0.3.0

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 (137) hide show
  1. package/README.md +339 -115
  2. package/dist/abort-BCwpdrN0.js +32 -0
  3. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  4. package/dist/blob-database.d.ts +474 -0
  5. package/dist/blob-database.js +608 -0
  6. package/dist/checkout.d.ts +128 -0
  7. package/dist/checkout.js +849 -0
  8. package/dist/cloudflare.d.ts +6 -7
  9. package/dist/cloudflare.js +1 -1
  10. package/dist/config-B-863EgC.js +15 -0
  11. package/dist/config-BAgL2dtB.js +1076 -0
  12. package/dist/{config-DE9xlaIw.d.ts → config-BQKcPawI.d.ts} +1 -2
  13. package/dist/discard-CNNtCozM.js +8 -0
  14. package/dist/durability.d.ts +22 -0
  15. package/dist/durability.js +70 -0
  16. package/dist/error-diagnostics-CtKjGtGb.js +188 -0
  17. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  18. package/dist/file-2pFYNtsU.js +22 -0
  19. package/dist/{files-Q6xZjDHA.js → files-BOo4SbwE.js} +3 -3
  20. package/dist/files.d.ts +38 -0
  21. package/dist/files.js +6 -0
  22. package/dist/{github-DHnjxQIX.js → github-CrYp4v8k.js} +44 -24
  23. package/dist/glob-B8YGvTrZ.js +21 -0
  24. package/dist/glob-Cjxms1t7.js +30 -0
  25. package/dist/{host-DJH8cuoU.js → host-BFBpXn0N.js} +144 -77
  26. package/dist/{hosted-RPeJOCFz.js → hosted-KcUR_jPv.js} +303 -97
  27. package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
  28. package/dist/hosted-vercel-blob.d.ts +6 -7
  29. package/dist/hosted-vercel-blob.js +1 -1
  30. package/dist/hosted.d.ts +10 -9
  31. package/dist/hosted.js +2 -2
  32. package/dist/index.d.ts +26 -47
  33. package/dist/index.js +30 -100
  34. package/dist/internal/path.d.ts +2 -0
  35. package/dist/internal/path.js +2 -0
  36. package/dist/lifecycle-B-enk_4A.js +596 -0
  37. package/dist/lineage.d.ts +26 -0
  38. package/dist/lineage.js +76 -0
  39. package/dist/loader.d.ts +5 -6
  40. package/dist/loader.js +3 -2
  41. package/dist/mcp-resources-DF0F5rcL.js +39 -0
  42. package/dist/memory-BOexthyW.js +247 -0
  43. package/dist/metadata-target-CWz6KHKq.js +1589 -0
  44. package/dist/object-Da1zyPCR.js +11 -0
  45. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  46. package/dist/operations-C6FpR8Rr.js +389 -0
  47. package/dist/operations-CE2drFih.js +1234 -0
  48. package/dist/operations.d.ts +90 -0
  49. package/dist/operations.js +3 -0
  50. package/dist/path--wrT_Azm.js +113 -0
  51. package/dist/path-AxMho1wo.d.ts +7 -0
  52. package/dist/path-DrSIenjj.js +59 -0
  53. package/dist/path-zHxQUbqa.d.ts +9 -0
  54. package/dist/plugins-C8C0auoW.d.ts +10 -0
  55. package/dist/provider-9s4Ufkm5.js +1479 -0
  56. package/dist/providers/github/store.d.ts +3 -5
  57. package/dist/providers/github/store.js +1 -1
  58. package/dist/registry-B3BBm4Ts.d.ts +19 -0
  59. package/dist/{registry-D3yzt8HQ.js → registry-CNphafBx.js} +60 -23
  60. package/dist/registry-CYNN623b.d.ts +9 -0
  61. package/dist/request-scope-Dw5n8bMC.js +83 -0
  62. package/dist/results-DgkZUmTL.js +8 -0
  63. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-rQ84J-ij.js} +3 -4
  64. package/dist/runtime/assets.d.ts +3 -5
  65. package/dist/runtime/assets.js +7 -6
  66. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  67. package/dist/runtime/empty-registry.d.ts +2 -2
  68. package/dist/runtime/registry.d.ts +2 -0
  69. package/dist/runtime/registry.js +23 -0
  70. package/dist/runtime/request.d.ts +4 -0
  71. package/dist/runtime/request.js +8 -0
  72. package/dist/runtime/state.d.ts +5 -4
  73. package/dist/runtime/state.js +8 -18
  74. package/dist/runtime/workspace.d.ts +1 -1
  75. package/dist/runtime/workspace.js +1 -1
  76. package/dist/runtime.d.ts +52 -17
  77. package/dist/runtime.js +324 -67
  78. package/dist/{search-BpiCF2Tw.js → search-C_RfoM2j.js} +10 -9
  79. package/dist/server-8tGltlGz.js +303 -0
  80. package/dist/server.d.ts +36 -39
  81. package/dist/server.js +2 -328
  82. package/dist/shared-B3_EUk89.js +848 -0
  83. package/dist/source-metadata.d.ts +10 -7
  84. package/dist/source-metadata.js +12 -12
  85. package/dist/state-BISnUf1s.d.ts +35 -0
  86. package/dist/{ai-BqCC8BpY.js → state-DbrW-njQ.js} +237 -114
  87. package/dist/store-ybhyD38Z.js +1873 -0
  88. package/dist/{sync-DnTQwt8r.js → sync-CCD_VYC8.js} +61 -41
  89. package/dist/target-jWhTdIuF.js +89 -0
  90. package/dist/test.d.ts +1 -1
  91. package/dist/test.js +1 -1
  92. package/dist/{types-CYuwjJ4V.d.ts → types-BbtwmBZ5.d.ts} +321 -35
  93. package/dist/use-C6lV3-wC.d.ts +321 -0
  94. package/dist/{use-BTNDR5Rd.js → use-CSpT5W87.js} +141 -107
  95. package/dist/utils-CgMZCHsX.js +616 -0
  96. package/dist/vite.d.ts +585 -2
  97. package/dist/vite.js +21369 -2
  98. package/dist/workspace-CYB2xZ1T.d.ts +7 -0
  99. package/dist/{workspace-Dq08Yn72.js → workspace-sPWn2Jxj.js} +441 -225
  100. package/package.json +97 -72
  101. package/dist/ai-CjxvGqM0.d.ts +0 -162
  102. package/dist/ai.d.ts +0 -3
  103. package/dist/ai.js +0 -2
  104. package/dist/collections/client.d.ts +0 -39
  105. package/dist/collections/client.js +0 -137
  106. package/dist/collections.d.ts +0 -59
  107. package/dist/collections.js +0 -159
  108. package/dist/config-Bc3c4Su1.js +0 -7904
  109. package/dist/config-CHLLWklZ.js +0 -36
  110. package/dist/file-Bc1X7pco.js +0 -23
  111. package/dist/glob-CEZKeZFC.js +0 -18
  112. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  113. package/dist/lifecycle-LrL3sA4n.js +0 -316
  114. package/dist/metadata-target-B0tOmVW7.js +0 -717
  115. package/dist/mountx.d.ts +0 -10
  116. package/dist/mountx.js +0 -143
  117. package/dist/nitro.d.ts +0 -2
  118. package/dist/nitro.js +0 -2
  119. package/dist/nuxt.d.ts +0 -26
  120. package/dist/nuxt.js +0 -42
  121. package/dist/path-Cp59koVz.js +0 -139
  122. package/dist/provider-B1yLjCJJ.js +0 -746
  123. package/dist/publish.d.ts +0 -35
  124. package/dist/publish.js +0 -112
  125. package/dist/registry-Uj6IVxes.d.ts +0 -11
  126. package/dist/request-execution-B-dSFlGB.js +0 -84
  127. package/dist/runtime-options-BsPSv5O7.js +0 -13
  128. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  129. package/dist/shared-DTR1Hhma.js +0 -331
  130. package/dist/state-tYcRWEh2.d.ts +0 -26
  131. package/dist/store-Dt_Jyys3.js +0 -608
  132. package/dist/target-D4Bqb1eH.js +0 -11
  133. package/dist/token-CVzURBxC.js +0 -61
  134. package/dist/use-BiHzt0xA.d.ts +0 -103
  135. package/dist/vite-BptCrpv2.js +0 -4526
  136. package/dist/vite-CtA9guIM.d.ts +0 -66
  137. package/dist/workspace-Xddf4G1B.d.ts +0 -6
@@ -1,10 +1,13 @@
1
- import { n as __exportAll } from "./chunk-2rV9d50f.js";
2
- import { _ as workspaceError, a as isExcludedWorkspacePath, f as sha256, g as workspaceConflict, i as decodeFile, l as normalizeWorkspacePath, r as contentToBytes, s as normalizeSafeWorkspacePath } from "./path-Cp59koVz.js";
3
- import { a as createSnapshotFromEntries, o as diffSnapshots, r as resolveWorkspaceRevisionMaterializer } from "./store-Dt_Jyys3.js";
4
- import { _ as isMissingWorkspacePathError, g as filterSessionEntries, h as filterSessionDiff, m as assertPathInSessionScope, p as assertDiffInsideSessionPaths, v as scopedSearchQuery } from "./workspace-Dq08Yn72.js";
1
+ import { n as __exportAll } from "./rolldown-runtime-rQ84J-ij.js";
2
+ import { a as workspaceConflict, s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
3
+ import { a as isExcludedWorkspacePath, f as sha256, i as decodeFile, l as normalizeWorkspacePath, r as contentToBytes } from "./path--wrT_Azm.js";
4
+ import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CtKjGtGb.js";
5
+ import { n as createSnapshotFromEntries, r as diffSnapshots } from "./utils-CgMZCHsX.js";
6
+ import { r as resolveWorkspaceRevisionMaterializer } from "./store-ybhyD38Z.js";
7
+ import { C as isMissingWorkspacePathError, S as filterSessionEntries, b as assertPathInSessionScope, w as scopedSearchQuery, x as filterSessionDiff, y as assertDiffInsideSessionPaths } from "./workspace-sPWn2Jxj.js";
8
+ import { normalizeExecutionAuthority } from "@vite-hub/runtime";
5
9
  import { posix } from "node:path";
6
10
  import { randomUUID } from "node:crypto";
7
- import { normalizeExecutionAuthority } from "@vite-hub/runtime";
8
11
  //#region src/session/progress.ts
9
12
  async function withWorkspaceProgress(onProgress, event, fn) {
10
13
  const startedAt = Date.now();
@@ -46,15 +49,61 @@ var host_exports = /* @__PURE__ */ __exportAll({ createHostedWorkspaceSession: (
46
49
  const publicationQueues = /* @__PURE__ */ new WeakMap();
47
50
  const defaultHostInspectionConcurrency = 16;
48
51
  const hostInspectionLimiters = /* @__PURE__ */ new WeakMap();
52
+ const hostMaterializationLimiters = /* @__PURE__ */ new WeakMap();
49
53
  function resolveHostInspectionConcurrency(host) {
50
54
  const concurrency = host.inspectionConcurrency ?? defaultHostInspectionConcurrency;
51
55
  if (!Number.isInteger(concurrency) || concurrency < 1) throw workspaceError("[vitehub] Workspace host inspectionConcurrency must be a positive integer.");
52
56
  return concurrency;
53
57
  }
58
+ function resolveHostMaterializationConcurrency(host) {
59
+ const concurrency = host.materializationConcurrency ?? 1;
60
+ if (!Number.isInteger(concurrency) || concurrency < 1) throw workspaceError("[vitehub] Workspace host materializationConcurrency must be a positive integer.");
61
+ return concurrency;
62
+ }
63
+ async function mapHostMaterialization(host, values, visit, signal) {
64
+ const concurrency = resolveHostMaterializationConcurrency(host);
65
+ let limit = hostMaterializationLimiters.get(host);
66
+ if (!limit) {
67
+ limit = createHostLimiter(concurrency);
68
+ hostMaterializationLimiters.set(host, limit);
69
+ }
70
+ let next = 0;
71
+ let failed = false;
72
+ let failure;
73
+ const workers = Array.from({ length: Math.min(values.length, concurrency) }, async () => {
74
+ while (!failed) {
75
+ signal?.throwIfAborted();
76
+ const index = next++;
77
+ if (index >= values.length) return;
78
+ try {
79
+ await limit(async () => {
80
+ if (failed) return;
81
+ signal?.throwIfAborted();
82
+ try {
83
+ await visit(values[index]);
84
+ } catch (error) {
85
+ if (!failed) failure = error;
86
+ failed = true;
87
+ }
88
+ }, signal);
89
+ } catch (error) {
90
+ if (!failed) failure = error;
91
+ failed = true;
92
+ }
93
+ }
94
+ });
95
+ await Promise.allSettled(workers);
96
+ if (failed) throw failure;
97
+ signal?.throwIfAborted();
98
+ }
54
99
  function resolveHostInspectionLimiter(host) {
55
100
  const existing = hostInspectionLimiters.get(host);
56
101
  if (existing) return existing;
57
- const concurrency = resolveHostInspectionConcurrency(host);
102
+ const limit = createHostLimiter(resolveHostInspectionConcurrency(host));
103
+ hostInspectionLimiters.set(host, limit);
104
+ return limit;
105
+ }
106
+ function createHostLimiter(concurrency) {
58
107
  let active = 0;
59
108
  const queued = [];
60
109
  const run = async (inspect, signal) => {
@@ -83,7 +132,6 @@ function resolveHostInspectionLimiter(host) {
83
132
  queued.shift()?.grant();
84
133
  }
85
134
  };
86
- hostInspectionLimiters.set(host, run);
87
135
  return run;
88
136
  }
89
137
  function inspectHost(host, inspect, signal, batch) {
@@ -183,7 +231,7 @@ function toHostCwd(root, cwd) {
183
231
  if (!posix.isAbsolute(cwd)) return toHostPath(root, cwd);
184
232
  const normalized = posix.normalize(cwd);
185
233
  if (normalized === root || normalized.startsWith(`${root}/`)) return normalized;
186
- if (normalized === "/workspace" || normalized.startsWith("/workspace/")) return toHostPath(root, normalized.slice(10));
234
+ if (normalized === "/workspace" || normalized.startsWith("/workspace/")) return toHostPath(root, normalized === "/workspace" ? "" : normalized.slice(11));
187
235
  throw workspaceError(`[vitehub] Workspace exec cwd must stay inside ${root}: ${cwd}.`);
188
236
  }
189
237
  function fromHostPath(root, path) {
@@ -277,7 +325,7 @@ async function readHostSymlinkTarget(host, root, path, abortSignal, batch) {
277
325
  cwd: root,
278
326
  signal: abortSignal
279
327
  });
280
- if (result.code !== 0) throw workspaceError(`[vitehub] Failed to read workspace symlink: ${path}.`, { cause: new Error(result.stderr || "readlink failed") });
328
+ if (result.code !== 0) throw workspaceError(`[vitehub] Failed to read workspace symlink: ${path}.`, { cause: workspaceErrorDiagnostics.WORKSPACE_R0044({ message: result.stderr || "readlink failed" }) });
281
329
  return result.stdout.replace(/\n$/, "");
282
330
  }, abortSignal, batch);
283
331
  }
@@ -373,23 +421,24 @@ async function captureHostState(host, root, name, abortSignal) {
373
421
  }
374
422
  async function captureHostEntriesState(host, root, entries, name, abortSignal) {
375
423
  const contents = /* @__PURE__ */ new Map();
424
+ const files = await mapHostInspections(host, entries, async (entry, batch) => {
425
+ abortSignal?.throwIfAborted();
426
+ if (entry.type !== "file") return entry;
427
+ const content = isGitSymlinkEntry(entry) ? await readHostSymlinkTarget(host, root, toHostPath(root, entry.path), abortSignal, batch) : await inspectHost(host, async () => {
428
+ const content = await host.files.read(toHostPath(root, entry.path), { signal: abortSignal });
429
+ if (content === null) throw workspaceError(`[vitehub] Workspace host file disappeared while snapshotting: ${entry.path}.`);
430
+ return content;
431
+ }, abortSignal, batch);
432
+ contents.set(entry.path, content);
433
+ return {
434
+ ...entry,
435
+ digest: await sha256(content),
436
+ size: contentToBytes(content).byteLength
437
+ };
438
+ }, abortSignal);
376
439
  return {
377
440
  contents,
378
- snapshot: await createSnapshotFromEntries(await mapHostInspections(host, entries, async (entry, batch) => {
379
- abortSignal?.throwIfAborted();
380
- if (entry.type !== "file") return entry;
381
- const content = isGitSymlinkEntry(entry) ? await readHostSymlinkTarget(host, root, toHostPath(root, entry.path), abortSignal, batch) : await inspectHost(host, async () => {
382
- const content = await host.files.read(toHostPath(root, entry.path), { signal: abortSignal });
383
- if (content === null) throw workspaceError(`[vitehub] Workspace host file disappeared while snapshotting: ${entry.path}.`);
384
- return content;
385
- }, abortSignal, batch);
386
- contents.set(entry.path, content);
387
- return {
388
- ...entry,
389
- digest: await sha256(content),
390
- size: contentToBytes(content).byteLength
391
- };
392
- }, abortSignal), name)
441
+ snapshot: await createSnapshotFromEntries(files, name)
393
442
  };
394
443
  }
395
444
  function isInsideExcludedWriteBackPath(path, excluded) {
@@ -403,11 +452,10 @@ async function captureExcludedHostState(host, root, excluded, abortSignal) {
403
452
  }
404
453
  function mergeExcludedHostState(before, materialized, excluded) {
405
454
  const beforePaths = Object.keys(before.snapshot.entries);
406
- const occupiedRoots = [...new Set([...excluded.filter((root) => beforePaths.some((path) => path === root || path.startsWith(`${root}/`))), ...beforePaths.map(gitMetadataRoot).filter((path) => Boolean(path))])];
407
- const entries = Object.fromEntries(Object.entries(materialized.snapshot.entries).filter(([path]) => !occupiedRoots.some((root) => path === root || path.startsWith(`${root}/`))));
455
+ const occupiedRoots = [.../* @__PURE__ */ new Set([...excluded.filter((root) => beforePaths.some((path) => path === root || path.startsWith(`${root}/`))), ...beforePaths.map(gitMetadataRoot).filter((path) => Boolean(path))])];
456
+ const entries = Object.fromEntries([...Object.entries(materialized.snapshot.entries).filter(([path]) => !occupiedRoots.some((root) => path === root || path.startsWith(`${root}/`))), ...Object.entries(before.snapshot.entries)]);
408
457
  const contents = new Map(materialized.contents);
409
- for (const root of occupiedRoots) for (const path of [...contents.keys()]) if (path === root || path.startsWith(`${root}/`)) contents.delete(path);
410
- for (const [path, entry] of Object.entries(before.snapshot.entries)) entries[path] = entry;
458
+ for (const root of occupiedRoots) for (const path of contents.keys()) if (path === root || path.startsWith(`${root}/`)) contents.delete(path);
411
459
  for (const [path, content] of before.contents) contents.set(path, content);
412
460
  return {
413
461
  contents,
@@ -417,15 +465,7 @@ function mergeExcludedHostState(before, materialized, excluded) {
417
465
  }
418
466
  };
419
467
  }
420
- async function restoreExcludedHostState(host, root, excluded, state, abortSignal) {
421
- const currentGitRoots = (await listHostEntries(host, root, "", true, (entry) => Boolean(gitMetadataRoot(entry.path)), true, [], abortSignal)).map((entry) => gitMetadataRoot(entry.path));
422
- const excludedRoots = [...new Set([...excluded, ...currentGitRoots])];
423
- const roots = excludedRoots.filter((path, index) => !excludedRoots.some((parent, parentIndex) => parentIndex !== index && path.startsWith(`${parent}/`)));
424
- for (const path of roots.sort((left, right) => right.length - left.length)) {
425
- abortSignal?.throwIfAborted();
426
- await removeHostPath(host, root, toHostPath(root, path), true, abortSignal);
427
- }
428
- const entries = Object.entries(state.snapshot.entries).sort(([left], [right]) => left.split("/").length - right.split("/").length);
468
+ async function restoreHostEntries(host, root, entries, contents, abortSignal) {
429
469
  for (const [path, entry] of entries) {
430
470
  abortSignal?.throwIfAborted();
431
471
  const target = toHostPath(root, path);
@@ -437,7 +477,7 @@ async function restoreExcludedHostState(host, root, excluded, state, abortSignal
437
477
  });
438
478
  continue;
439
479
  }
440
- const content = state.contents.get(path);
480
+ const content = contents.get(path);
441
481
  if (content === void 0) continue;
442
482
  await ensureHostParent(host, target, abortSignal);
443
483
  if (entry.metadata?.gitMode === "120000") await writeHostSymlink(host, root, target, String(content), abortSignal);
@@ -447,33 +487,23 @@ async function restoreExcludedHostState(host, root, excluded, state, abortSignal
447
487
  }
448
488
  }
449
489
  }
490
+ async function restoreExcludedHostState(host, root, excluded, state, abortSignal) {
491
+ const currentGitRoots = (await listHostEntries(host, root, "", true, (entry) => Boolean(gitMetadataRoot(entry.path)), true, [], abortSignal)).map((entry) => gitMetadataRoot(entry.path));
492
+ const excludedRoots = [.../* @__PURE__ */ new Set([...excluded, ...currentGitRoots])];
493
+ const roots = excludedRoots.filter((path, index) => !excludedRoots.some((parent, parentIndex) => parentIndex !== index && path.startsWith(`${parent}/`)));
494
+ for (const path of roots.sort((left, right) => right.length - left.length)) {
495
+ abortSignal?.throwIfAborted();
496
+ await removeHostPath(host, root, toHostPath(root, path), true, abortSignal);
497
+ }
498
+ await restoreHostEntries(host, root, Object.entries(state.snapshot.entries).sort(([left], [right]) => left.split("/").length - right.split("/").length), state.contents, abortSignal);
499
+ }
450
500
  async function restoreAttachedHost(host, root, diff, state, abortSignal) {
451
501
  const changed = [...new Set(diff.entries.map((entry) => entry.path))];
452
502
  for (const path of changed.sort((left, right) => right.length - left.length)) {
453
503
  abortSignal?.throwIfAborted();
454
504
  await removeHostPath(host, root, toHostPath(root, path), true, abortSignal);
455
505
  }
456
- const baselineEntries = changed.map((path) => [path, state.snapshot.entries[path]]).filter((entry) => Boolean(entry[1])).sort(([left], [right]) => left.split("/").length - right.split("/").length);
457
- for (const [path, entry] of baselineEntries) {
458
- abortSignal?.throwIfAborted();
459
- const target = toHostPath(root, path);
460
- await removeHostSymlinkAncestors(host, root, target, abortSignal);
461
- if (entry.type === "directory") {
462
- await host.files.mkdir(target, {
463
- recursive: true,
464
- signal: abortSignal
465
- });
466
- continue;
467
- }
468
- const content = state.contents.get(path);
469
- if (content === void 0) continue;
470
- await ensureHostParent(host, target, abortSignal);
471
- if (entry.metadata?.gitMode === "120000") await writeHostSymlink(host, root, target, String(content), abortSignal);
472
- else {
473
- await host.files.write(target, contentToBytes(content), { signal: abortSignal });
474
- if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target, abortSignal);
475
- }
476
- }
506
+ await restoreHostEntries(host, root, changed.map((path) => [path, state.snapshot.entries[path]]).filter((entry) => Boolean(entry[1])).sort(([left], [right]) => left.split("/").length - right.split("/").length), state.contents, abortSignal);
477
507
  }
478
508
  async function resetHostWorkspaceRoot(host, root, abortSignal) {
479
509
  if (await ensureHostWorkspaceRoot(host, root, abortSignal)) return;
@@ -537,6 +567,27 @@ async function sessionEntries(workspace, options) {
537
567
  }
538
568
  return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
539
569
  }
570
+ async function observeRetainedWorkspaceRevision(workspace, options) {
571
+ try {
572
+ const revision = await workspace.history.head();
573
+ if (!revision) return;
574
+ const entries = await sessionEntries(await workspace.history.open(revision.id), options);
575
+ return {
576
+ revision: revision.id,
577
+ files: new Map(entries.filter((entry) => entry.type === "file").map((entry) => [entry.path, entry]))
578
+ };
579
+ } catch {
580
+ return;
581
+ }
582
+ }
583
+ async function matchesRetainedWorkspaceFile(workspace, entry, content, retained) {
584
+ if (!retained?.digest || retained.metadata?.gitMode !== entry.metadata?.gitMode) return false;
585
+ try {
586
+ return retained.digest === await (workspace.history.digest?.(content) ?? sha256(content));
587
+ } catch {
588
+ return false;
589
+ }
590
+ }
540
591
  async function extractRevisionArchive(host, root, materialization, signal) {
541
592
  const stagingRoot = posix.join(root, `.vitehub-workspace-${randomUUID()}`);
542
593
  const archive = posix.join(stagingRoot, "revision.tar.gz");
@@ -637,6 +688,7 @@ async function materializeWorkspace(workspace, host, root, options, useRevisionM
637
688
  abortSignal: options?.abortSignal,
638
689
  paths
639
690
  })) : void 0;
691
+ const retained = !materializer && useRevisionMaterializer ? await observeRetainedWorkspaceRevision(workspace, options) : void 0;
640
692
  await withWorkspaceProgress(options?.onProgress, {
641
693
  id: "workspace.prepare.reset-sandbox",
642
694
  label: "Resetting sandbox workspace"
@@ -676,6 +728,8 @@ async function materializeWorkspace(workspace, host, root, options, useRevisionM
676
728
  id: "workspace.prepare.entries",
677
729
  label: "Resolving workspace entries"
678
730
  }, async () => await sessionEntries(workspace, options));
731
+ const files = entries.filter((entry) => entry.type === "file");
732
+ let matchesRetained = Boolean(retained && files.length === retained.files.size);
679
733
  const symlinks = new Set(entries.filter(isGitSymlinkEntry).map((entry) => entry.path));
680
734
  const nested = entries.find((entry) => hasSymlinkParent(entry.path, symlinks));
681
735
  if (nested) throw workspaceError(`[vitehub] Workspace path crosses a symlink parent: ${nested.path}.`);
@@ -690,32 +744,36 @@ async function materializeWorkspace(workspace, host, root, options, useRevisionM
690
744
  await withWorkspaceProgress(options?.onProgress, {
691
745
  data: {
692
746
  bytes: entries.reduce((total, entry) => total + (entry.size || 0), 0),
693
- files: entries.filter((entry) => entry.type === "file").length
747
+ files: files.length
694
748
  },
695
749
  id: "workspace.prepare.read-files",
696
750
  label: "Reading workspace files"
697
751
  }, async () => {
698
752
  abortSignal?.throwIfAborted();
699
- for (const entry of entries) {
753
+ await mapHostMaterialization(host, files, async (entry) => {
700
754
  abortSignal?.throwIfAborted();
701
- if (entry.type !== "file") continue;
702
755
  const target = toHostPath(root, entry.path);
703
756
  await ensureHostParent(host, target, abortSignal);
757
+ const content = isGitSymlinkEntry(entry) && typeof entry.metadata?.symlinkTarget === "string" ? contentToBytes(entry.metadata.symlinkTarget) : contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" }));
704
758
  if (isGitSymlinkEntry(entry)) {
705
- const symlinkTarget = typeof entry.metadata?.symlinkTarget === "string" ? entry.metadata.symlinkTarget : new TextDecoder().decode(contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })));
759
+ const symlinkTarget = new TextDecoder().decode(content);
706
760
  if (isSafeHostSymlink(root, entry.path, symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget, abortSignal);
707
- else await host.files.write(target, contentToBytes(symlinkTarget), { signal: abortSignal });
761
+ else {
762
+ matchesRetained = false;
763
+ await host.files.write(target, contentToBytes(symlinkTarget), { signal: abortSignal });
764
+ }
708
765
  } else {
709
- await host.files.write(target, contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })), { signal: abortSignal });
766
+ await host.files.write(target, content, { signal: abortSignal });
710
767
  if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target, abortSignal);
711
768
  }
769
+ if (matchesRetained && !await matchesRetainedWorkspaceFile(workspace, entry, content, retained?.files.get(entry.path))) matchesRetained = false;
712
770
  abortSignal?.throwIfAborted();
713
- }
771
+ }, abortSignal);
714
772
  });
715
773
  if (revision && await materializer?.currentRevision({ abortSignal: options?.abortSignal }) !== revision.revision) throw workspaceConflict(`[vitehub] Workspace revision changed while this Session materialized: ${revision.revision}.`);
716
- const snapshot = options?.writeBack === false ? await createSnapshotFromEntries(entries, "host-open") : await snapshotHost(host, root, "host-open", abortSignal);
774
+ const snapshot = captureSnapshot ? options?.writeBack === false ? await createSnapshotFromEntries(entries, "host-open") : await snapshotHost(host, root, "host-open", abortSignal) : void 0;
717
775
  return {
718
- revision: revision?.revision,
776
+ revision: revision?.revision ?? (matchesRetained ? retained?.revision : void 0),
719
777
  snapshot
720
778
  };
721
779
  }
@@ -753,9 +811,11 @@ async function createHostedWorkspaceSession(workspace, options) {
753
811
  try {
754
812
  executionAuthority = normalizeExecutionAuthority(host.executionAuthority);
755
813
  } catch {
756
- throw new TypeError("[vitehub] Workspace session host must declare executionAuthority.");
814
+ throw workspaceErrorDiagnostics.WORKSPACE_R0045({ message: "[vitehub] Workspace session host must declare executionAuthority." });
757
815
  }
758
816
  resolveHostInspectionConcurrency(host);
817
+ resolveHostMaterializationConcurrency(host);
818
+ if (options.attach && options.disposableTarget) throw workspaceError("[vitehub] Workspace Session attach and disposableTarget cannot be combined.");
759
819
  const root = normalizeTarget(options.target);
760
820
  const sessionPaths = normalizeSessionPaths(options);
761
821
  const excludedWriteBackPaths = [...defaultExcludedSessionPaths, ...(options.writeBack && options.writeBack.exclude || []).map((path) => normalizeSafeWorkspacePath(path, { allowReserved: true }))];
@@ -771,14 +831,14 @@ async function createHostedWorkspaceSession(workspace, options) {
771
831
  });
772
832
  if (!attachedState) materializedExcludedState = await captureExcludedHostState(host, root, excludedWriteBackPaths, options.abortSignal);
773
833
  } catch (error) {
774
- if (attachedState || !setupMutatedHost) throw error;
834
+ if (attachedState || !setupMutatedHost || options.disposableTarget) throw error;
775
835
  try {
776
836
  host.detachAbortSignal?.();
777
837
  await materializeWorkspace(workspace, host, root, {
778
838
  ...options,
779
839
  abortSignal: void 0,
780
840
  onProgress: void 0
781
- }, false);
841
+ }, false, void 0, false);
782
842
  await restoreExcludedHostState(host, root, excludedWriteBackPaths, existingExcludedState);
783
843
  } catch (restoreError) {
784
844
  throw new AggregateError([error, restoreError], "[vitehub] Workspace Session setup and excluded-state restoration failed.");
@@ -786,7 +846,7 @@ async function createHostedWorkspaceSession(workspace, options) {
786
846
  throw error;
787
847
  }
788
848
  let baseline = materialization.snapshot;
789
- let baseRevision = materialization.revision;
849
+ let baseRevision = resolveWorkspaceRevisionMaterializer(workspace) ? materialization.revision : void 0;
790
850
  const excludedState = attachedState ? existingExcludedState : mergeExcludedHostState(existingExcludedState, materializedExcludedState, excludedWriteBackPaths);
791
851
  const mediaTypes = /* @__PURE__ */ new Map();
792
852
  function assertOpen() {
@@ -798,9 +858,11 @@ async function createHostedWorkspaceSession(workspace, options) {
798
858
  }
799
859
  return {
800
860
  executionAuthority,
861
+ revision: materialization.revision,
801
862
  async readFile(path, readOptions) {
802
863
  assertOpen();
803
- const file = await readHostFile(host, root, toHostPath(root, assertPathInSessionScope(normalizeReadableSessionPath(path), sessionPaths, { masked: true })));
864
+ const target = toHostPath(root, assertPathInSessionScope(normalizeReadableSessionPath(path), sessionPaths, { masked: true }));
865
+ const file = await readHostFile(host, root, target);
804
866
  if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
805
867
  return decodeFile(file.content, readOptions);
806
868
  },
@@ -823,7 +885,8 @@ async function createHostedWorkspaceSession(workspace, options) {
823
885
  },
824
886
  async mkdir(path, mkdirOptions = {}) {
825
887
  assertOpen();
826
- const hostTarget = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path, { allowEmpty: true }), sessionPaths, { mkdir: true }));
888
+ const target = assertPathInSessionScope(normalizeSafeWorkspacePath(path, { allowEmpty: true }), sessionPaths, { mkdir: true });
889
+ const hostTarget = toHostPath(root, target);
827
890
  await assertNoHostSymlinkParent(host, root, hostTarget);
828
891
  await host.files.mkdir(hostTarget, { recursive: mkdirOptions.recursive });
829
892
  },
@@ -843,7 +906,7 @@ async function createHostedWorkspaceSession(workspace, options) {
843
906
  assertOpen();
844
907
  const patterns = Array.isArray(pattern) ? pattern : [pattern];
845
908
  const cwd = normalizeSearchRoot(globOptions?.cwd || "");
846
- const { matchesAny } = await import("./path-Cp59koVz.js").then((n) => n.u);
909
+ const { matchesAny } = await import("./path--wrT_Azm.js").then((n) => n.u);
847
910
  return filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((entry) => {
848
911
  if (entry.type !== "file") return false;
849
912
  if (!cwd) return patterns.some((item) => matchesAny(entry.path, item));
@@ -854,7 +917,7 @@ async function createHostedWorkspaceSession(workspace, options) {
854
917
  },
855
918
  async search(query) {
856
919
  assertOpen();
857
- const { searchText } = await import("./search-BpiCF2Tw.js").then((n) => n.n);
920
+ const { searchText } = await import("./search-C_RfoM2j.js").then((n) => n.n);
858
921
  const scoped = scopedSearchQuery(query, sessionPaths, normalizeSearchRoot);
859
922
  if (!scoped) return [];
860
923
  const scopedSearchRoots = [...new Set((scoped.paths?.length ? scoped.paths : [scoped.cwd || ""]).map(normalizeSearchRoot))].filter(Boolean);
@@ -968,6 +1031,10 @@ async function createHostedWorkspaceSession(workspace, options) {
968
1031
  const abortSignal = closeOptions?.abortSignal;
969
1032
  abortSignal?.throwIfAborted();
970
1033
  host.detachAbortSignal?.();
1034
+ if (options.disposableTarget) {
1035
+ closed = true;
1036
+ return;
1037
+ }
971
1038
  await ensureHostWorkspaceRoot(host, root, abortSignal);
972
1039
  if (options.writeBack === false && !options.attach) {
973
1040
  await materializeWorkspace(workspace, host, root, {
@@ -1010,7 +1077,7 @@ async function createHostedWorkspaceSession(workspace, options) {
1010
1077
  ...options,
1011
1078
  abortSignal,
1012
1079
  onProgress: void 0
1013
- });
1080
+ }, true, void 0, false);
1014
1081
  } catch (error) {
1015
1082
  restoreError = error;
1016
1083
  }