@vite-hub/workspace 0.0.4 → 0.1.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 (127) hide show
  1. package/README.md +225 -58
  2. package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
  3. package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
  4. package/dist/ai.d.ts +2 -2
  5. package/dist/ai.js +1 -1
  6. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  7. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
  8. package/dist/blob-database.d.ts +521 -0
  9. package/dist/blob-database.js +601 -0
  10. package/dist/cloudflare.d.ts +5 -6
  11. package/dist/cloudflare.js +1 -1
  12. package/dist/config-B7dmzDX3.js +1112 -0
  13. package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
  14. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  15. package/dist/error-diagnostics-DY5GP47p.js +96 -0
  16. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
  17. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
  18. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
  19. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
  20. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
  21. package/dist/file-C0_aPWSS.js +26 -0
  22. package/dist/file-metadata-CxDy-E2H.js +58 -0
  23. package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
  24. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
  25. package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
  26. package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
  27. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
  28. package/dist/glob--XcLlcml.js +22 -0
  29. package/dist/glob--kNYDbfU.js +30 -0
  30. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
  31. package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
  32. package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
  33. package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
  34. package/dist/hosted-vercel-blob.d.ts +5 -6
  35. package/dist/hosted-vercel-blob.js +1 -1
  36. package/dist/hosted.d.ts +6 -7
  37. package/dist/hosted.js +1 -1
  38. package/dist/index.d.ts +57 -36
  39. package/dist/index.js +56 -56
  40. package/dist/inspect-BoObD2cJ.js +167 -0
  41. package/dist/internal/path.d.ts +2 -0
  42. package/dist/internal/path.js +2 -0
  43. package/dist/lifecycle-BwZ7c9hb.js +596 -0
  44. package/dist/loader.d.ts +5 -6
  45. package/dist/loader.js +3 -2
  46. package/dist/mcp-resources-BREFCmtn.js +39 -0
  47. package/dist/memory-BbwOqDXl.js +248 -0
  48. package/dist/metadata-target-DZEZQGHA.js +1588 -0
  49. package/dist/mountx.d.ts +4 -6
  50. package/dist/mountx.js +10 -8
  51. package/dist/nitro.d.ts +1 -1
  52. package/dist/nitro.js +1 -1
  53. package/dist/nuxt.d.ts +13 -12
  54. package/dist/nuxt.js +4 -8
  55. package/dist/operations-BcpWr41m.js +159 -0
  56. package/dist/operations-CGqY1XeG.js +965 -0
  57. package/dist/operations-DnOwKsJT.d.ts +136 -0
  58. package/dist/operations.d.ts +53 -0
  59. package/dist/operations.js +2 -0
  60. package/dist/path-CNAwN7pw.js +114 -0
  61. package/dist/path-DrSIenjj.js +59 -0
  62. package/dist/path-zHxQUbqa.d.ts +9 -0
  63. package/dist/plugins-DqQ8b4T5.d.ts +10 -0
  64. package/dist/provider-kXjfli9u.js +1457 -0
  65. package/dist/providers/github/store.d.ts +3 -5
  66. package/dist/providers/github/store.js +1 -1
  67. package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
  68. package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
  69. package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
  70. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
  71. package/dist/runtime/assets.d.ts +3 -5
  72. package/dist/runtime/assets.js +7 -6
  73. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  74. package/dist/runtime/empty-registry.d.ts +1 -2
  75. package/dist/runtime/state.d.ts +3 -3
  76. package/dist/runtime/state.js +6 -6
  77. package/dist/runtime/workspace.d.ts +1 -1
  78. package/dist/runtime/workspace.js +1 -1
  79. package/dist/runtime.d.ts +51 -17
  80. package/dist/runtime.js +320 -60
  81. package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
  82. package/dist/server-BNQ-Nbjj.js +290 -0
  83. package/dist/server.d.ts +22 -34
  84. package/dist/server.js +2 -328
  85. package/dist/shared-DalXdP0i.js +2158 -0
  86. package/dist/source-metadata.d.ts +6 -7
  87. package/dist/source-metadata.js +7 -7
  88. package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
  89. package/dist/store-CXgmu-uw.js +1729 -0
  90. package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
  91. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
  92. package/dist/test.d.ts +1 -1
  93. package/dist/test.js +1 -1
  94. package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
  95. package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
  96. package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
  97. package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
  98. package/dist/utils-Blrh4N2n.js +545 -0
  99. package/dist/vite-BEvgU2GY.js +20909 -0
  100. package/dist/vite-CcZmMQ7S.d.ts +476 -0
  101. package/dist/vite.d.ts +2 -2
  102. package/dist/vite.js +2 -2
  103. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
  104. package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
  105. package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
  106. package/package.json +89 -55
  107. package/dist/collections/client.d.ts +0 -39
  108. package/dist/collections/client.js +0 -137
  109. package/dist/collections.d.ts +0 -59
  110. package/dist/collections.js +0 -159
  111. package/dist/config-Bc3c4Su1.js +0 -7904
  112. package/dist/config-CHLLWklZ.js +0 -36
  113. package/dist/file-Bc1X7pco.js +0 -23
  114. package/dist/glob-CEZKeZFC.js +0 -18
  115. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  116. package/dist/lifecycle-LrL3sA4n.js +0 -316
  117. package/dist/metadata-target-B0tOmVW7.js +0 -717
  118. package/dist/path-Cp59koVz.js +0 -139
  119. package/dist/provider-B1yLjCJJ.js +0 -746
  120. package/dist/publish.d.ts +0 -35
  121. package/dist/publish.js +0 -112
  122. package/dist/runtime-options-BsPSv5O7.js +0 -13
  123. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  124. package/dist/shared-DTR1Hhma.js +0 -331
  125. package/dist/store-Dt_Jyys3.js +0 -608
  126. package/dist/vite-BptCrpv2.js +0 -4526
  127. package/dist/vite-CtA9guIM.d.ts +0 -66
package/dist/runtime.js CHANGED
@@ -1,15 +1,22 @@
1
- import { _ as workspaceError, l as normalizeWorkspacePath } from "./path-Cp59koVz.js";
2
- import { a as copyWorkspacePath, i as appendWorkspaceFile, n as getWorkspaceDependencyRuntimeLoaders, r as setWorkspaceDependencyRuntimeLoaders, t as createWorkspaceTools } from "./ai-BqCC8BpY.js";
3
- import { _ as workspaceSourceRequestDescriptorPath, a as normalizeWorkspaceSources, g as isWorkspaceSourceRequestOnly, i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, m as getWorkspaceSourceRequestDescriptor, o as normalizeWorkspaceSourcesMetadata, r as normalizeWorkspaceSource, t as copyWorkspaceSourceMetadata, u as prepareWorkspaceSource, v as markLiveWorkspaceSource } from "./config-Bc3c4Su1.js";
4
- import { n as createWorkspaceSourceRequestExecution, r as getWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-B-dSFlGB.js";
5
- import { c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, l as setWorkspaceHostedStoreLoader, s as createMemoryWorkspaceStore, u as getWorkspaceRuntimeConfig } from "./provider-B1yLjCJJ.js";
6
- import { t as forwardWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
7
- import { t as hasRuntimeType } from "./runtime-type-iEE6BjQJ.js";
8
- import { f as createBasicWorkspaceSession, i as createWorkspaceSourceView, l as resolveWorkspacePath, r as resetWorkspaceStoreCache, u as createWorkspaceWritePolicy } from "./workspace-Dq08Yn72.js";
9
- import { n as resolveWorkspaceMetadataTarget, r as workspaceMetadataTarget, t as forwardWorkspaceMetadataTarget } from "./metadata-target-B0tOmVW7.js";
10
- import { n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "./registry-D3yzt8HQ.js";
11
- import { t as useWorkspace } from "./use-BTNDR5Rd.js";
1
+ import { s as workspaceError } from "./path-DrSIenjj.js";
2
+ import { l as normalizeWorkspacePath } from "./path-CNAwN7pw.js";
3
+ import { n as resolveWorkspaceStoreTarget, r as workspaceStoreTarget, t as forwardWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
4
+ import { a as copyWorkspacePath, i as appendWorkspaceFile, n as getWorkspaceDependencyRuntimeLoaders, r as setWorkspaceDependencyRuntimeLoaders, t as createWorkspaceTools } from "./ai-BZyLwULx.js";
5
+ import { _ as isWorkspaceSourceRequestOnly, a as normalizeWorkspaceSources, b as markLiveWorkspaceSource, f as prepareWorkspaceSource, h as getWorkspaceSourceRequestDescriptor, i as normalizeWorkspaceSourceMetadata, l as workspaceSourceGrantPaths, o as normalizeWorkspaceSourcesMetadata, r as normalizeWorkspaceSource, t as copyWorkspaceSourceMetadata, u as ownSourceOption, v as workspaceSourceRequestDescriptorPath } from "./config-B7dmzDX3.js";
6
+ import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
7
+ import { i as workspaceSourceRequestMatches, n as createWorkspaceSourceRequestExecution, r as getWorkspaceSourceRequestExecution, t as attachWorkspaceSourceRequestExecution } from "./request-execution-Dk9rY-Yh.js";
8
+ import { t as createMemoryWorkspaceStore } from "./memory-BbwOqDXl.js";
9
+ import { a as createWorkspaceHistoryReader, c as forwardWorkspaceHistoryMerge, g as registerWorkspacePlugin, i as createWorkspaceHistory, m as createWorkspaceWritePolicy, s as forwardWorkspaceHistoryFiles } from "./utils-Blrh4N2n.js";
10
+ import { d as getWorkspaceRuntimeConfig, f as setWorkspaceRuntimeConfig, l as getWorkspaceHostedStoreLoader, u as setWorkspaceHostedStoreLoader } from "./provider-kXjfli9u.js";
11
+ import { a as isInternalWorkspaceMetaKey, c as isWorkspaceSourceSyncMetaKey, m as createBasicWorkspaceSession, o as createWorkspaceSourceView, p as resolveWorkspacePath, r as resetWorkspaceStoreCache } from "./workspace-6pxkOuxr.js";
12
+ import { M as registerWorkspaceStoreAlias, a as resolveWorkspaceMetadataMutationTarget, i as forwardWorkspaceMetadataView, n as createWorkspaceMetadataTarget, o as resolveWorkspaceMetadataTarget, r as forwardWorkspaceMetadataTarget, s as setWorkspaceMetadata, t as attachWorkspaceMetadataTarget } from "./metadata-target-DZEZQGHA.js";
13
+ import { n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "./registry-Bp-8UUfG.js";
14
+ import { t as useWorkspace } from "./use-BQj7nSz6.js";
12
15
  import { invalidateWorkspaceStore, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeRegistry } from "./runtime/state.js";
16
+ import { join, resolve } from "node:path";
17
+ import { randomUUID } from "node:crypto";
18
+ import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
19
+ import { lstat, readdir, rename, rm } from "node:fs/promises";
13
20
  //#region src/sources/resolution.ts
14
21
  function hasWorkspaceSourceResolvers(definition) {
15
22
  return normalizeWorkspaceSources(definition?.sources).some((source) => typeof source.source.resolve === "function");
@@ -17,6 +24,71 @@ function hasWorkspaceSourceResolvers(definition) {
17
24
  function isWritableWorkspaceFacade(workspace) {
18
25
  return typeof workspace.fs.writeFile === "function";
19
26
  }
27
+ const sourceBindingLineage = /* @__PURE__ */ new WeakMap();
28
+ function sameWorkspaceSourceBinding(key, left, right) {
29
+ if (left === right) return true;
30
+ if (!left || !right) return false;
31
+ if (typeof left !== "object" || typeof right !== "object") return false;
32
+ if ((sourceBindingLineage.get(left) ?? left) !== (sourceBindingLineage.get(right) ?? right)) return false;
33
+ const leftBinding = normalizeWorkspaceSource(key, left);
34
+ const rightBinding = normalizeWorkspaceSource(key, right);
35
+ if (leftBinding.source.fingerprint === void 0 || rightBinding.source.fingerprint === void 0) return false;
36
+ return sameWorkspaceSourceValue({
37
+ cache: leftBinding.cache,
38
+ materialize: leftBinding.materialize,
39
+ mountPath: leftBinding.mountPath,
40
+ source: leftBinding.source.fingerprint,
41
+ sync: leftBinding.sync
42
+ }, {
43
+ cache: rightBinding.cache,
44
+ materialize: rightBinding.materialize,
45
+ mountPath: rightBinding.mountPath,
46
+ source: rightBinding.source.fingerprint,
47
+ sync: rightBinding.sync
48
+ });
49
+ }
50
+ function sameWorkspaceSourceValue(left, right, ancestors = /* @__PURE__ */ new Set()) {
51
+ try {
52
+ if (typeof left !== "object" || left === null || typeof right !== "object" || right === null) return Object.is(left, right);
53
+ const leftProxy = isWorkspaceSourceProxy(left);
54
+ const rightProxy = isWorkspaceSourceProxy(right);
55
+ if (leftProxy !== false || rightProxy !== false) return false;
56
+ const prototype = Object.getPrototypeOf(left);
57
+ if (Array.isArray(left) !== Array.isArray(right) || prototype !== Object.getPrototypeOf(right) || prototype !== Object.prototype && prototype !== Array.prototype && prototype !== null || "toJSON" in left || "toJSON" in right || ancestors.has(left) || ancestors.has(right)) return false;
58
+ const leftKeys = Reflect.ownKeys(left);
59
+ const rightKeys = Reflect.ownKeys(right);
60
+ if (leftKeys.length !== rightKeys.length) return false;
61
+ const leftProperties = leftKeys.map((key) => Object.getOwnPropertyDescriptor(left, key));
62
+ const rightProperties = rightKeys.map((key) => Object.getOwnPropertyDescriptor(right, key));
63
+ if (leftProperties.some((property) => !property || !("value" in property)) || rightProperties.some((property) => !property || !("value" in property))) return false;
64
+ ancestors.add(left);
65
+ ancestors.add(right);
66
+ try {
67
+ return leftKeys.every((key, index) => {
68
+ if (key !== rightKeys[index]) return false;
69
+ const leftProperty = leftProperties[index];
70
+ const rightProperty = rightProperties[index];
71
+ return !!leftProperty && !!rightProperty && "value" in leftProperty && "value" in rightProperty && leftProperty.enumerable === rightProperty.enumerable && sameWorkspaceSourceValue(leftProperty.value, rightProperty.value, ancestors);
72
+ });
73
+ } finally {
74
+ ancestors.delete(left);
75
+ ancestors.delete(right);
76
+ }
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+ const isWorkspaceSourceProxy = (() => {
82
+ try {
83
+ const process = globalThis.process;
84
+ const getBuiltinModule = process?.getBuiltinModule;
85
+ if (typeof getBuiltinModule !== "function") return (_value) => void 0;
86
+ const util = getBuiltinModule.call(process, "util");
87
+ return typeof util?.types?.isProxy === "function" ? util.types.isProxy : (_value) => void 0;
88
+ } catch {
89
+ return (_value) => void 0;
90
+ }
91
+ })();
20
92
  function workspaceSessionStarter(workspace) {
21
93
  return typeof workspace.startSession === "function" ? workspace : void 0;
22
94
  }
@@ -30,7 +102,7 @@ function writeOperations(options) {
30
102
  writeFile: options?.writeFile !== false
31
103
  };
32
104
  }
33
- function createOverlaySourceStore(workspace, fallback) {
105
+ function createOverlaySourceStore(workspace, fallback, backingMetadataTarget) {
34
106
  const memory = createMemoryWorkspaceStore();
35
107
  const tombstones = /* @__PURE__ */ new Set();
36
108
  function isTombstoned(path) {
@@ -74,6 +146,7 @@ function createOverlaySourceStore(workspace, fallback) {
74
146
  }
75
147
  }
76
148
  return {
149
+ [workspaceStoreTarget]: async () => await resolveWorkspaceStoreTarget(workspace) ?? { provider: "memory" },
77
150
  isTombstoned,
78
151
  async readFile(path) {
79
152
  return await memory.readFile(path) || await readBaseFile(path);
@@ -112,21 +185,37 @@ function createOverlaySourceStore(workspace, fallback) {
112
185
  return await memory.getMeta?.(key) ?? await internalMetadata?.getMeta?.(key) ?? await workspace.getMeta?.(key);
113
186
  },
114
187
  async setMeta(key, value) {
188
+ if (isInternalWorkspaceMetaKey(key) && isWorkspaceSourceSyncMetaKey(key)) {
189
+ const mutationTarget = backingMetadataTarget ? resolveWorkspaceMetadataMutationTarget(backingMetadataTarget) : void 0;
190
+ if (mutationTarget && await setWorkspaceMetadata(mutationTarget, key, value)) return;
191
+ }
115
192
  await memory.setMeta?.(key, value);
116
193
  }
117
194
  };
118
195
  }
119
- function createWritableFacadeStore(workspace) {
196
+ const sourceSyncStores = /* @__PURE__ */ new WeakMap();
197
+ /** Preserve internal Source Sync routing when wrapping a writable facade. */
198
+ function forwardWorkspaceFacade(source, target) {
199
+ forwardWorkspaceMetadataTarget(source, target);
200
+ const syncStore = sourceSyncStores.get(source.fs);
201
+ if (syncStore) sourceSyncStores.set(target.fs, syncStore);
202
+ }
203
+ function createWritableFacadeStore(workspace, sourceSync) {
204
+ const backingSyncStore = sourceSync ? sourceSyncStores.get(workspace.fs)?.(sourceSync) : void 0;
205
+ if (backingSyncStore) return backingSyncStore;
120
206
  const meta = /* @__PURE__ */ new Map();
121
207
  const metadata = workspace;
122
208
  const store = {
123
209
  async readFile(path) {
210
+ const target = sourceSync ? resolveWorkspaceMetadataMutationTarget(await resolveWorkspaceMetadataTarget(workspace) ?? {}) : void 0;
211
+ if (target?.readFile) return await target.readFile(path);
124
212
  try {
125
213
  const stat = await workspace.fs.stat(path);
126
214
  if (stat.type === "directory") return;
127
215
  return {
128
216
  content: await workspace.fs.readFile(path, { encoding: "binary" }),
129
217
  mediaType: stat.mediaType,
218
+ metadata: stat.metadata,
130
219
  path
131
220
  };
132
221
  } catch {
@@ -134,7 +223,12 @@ function createWritableFacadeStore(workspace) {
134
223
  }
135
224
  },
136
225
  async writeFile(path, file) {
137
- await workspace.fs.writeFile(path, file.content, { mediaType: file.mediaType });
226
+ const target = sourceSync ? resolveWorkspaceMetadataMutationTarget(await resolveWorkspaceMetadataTarget(workspace) ?? {}) : void 0;
227
+ if (target?.writeFile) return await target.writeFile(path, file);
228
+ await workspace.fs.writeFile(path, file.content, {
229
+ mediaType: file.mediaType,
230
+ metadata: file.metadata
231
+ });
138
232
  },
139
233
  async list(path, options) {
140
234
  return await workspace.fs.list(path, options);
@@ -150,9 +244,13 @@ function createWritableFacadeStore(workspace) {
150
244
  }
151
245
  },
152
246
  async mkdir(path, options) {
247
+ const target = sourceSync ? resolveWorkspaceMetadataMutationTarget(await resolveWorkspaceMetadataTarget(workspace) ?? {}) : void 0;
248
+ if (target?.mkdir) return await target.mkdir(path, options);
153
249
  await workspace.fs.mkdir(path, options);
154
250
  },
155
251
  async rm(path, options) {
252
+ const target = sourceSync ? resolveWorkspaceMetadataMutationTarget(await resolveWorkspaceMetadataTarget(workspace) ?? {}) : void 0;
253
+ if (target?.rm) return await target.rm(path, options);
156
254
  await workspace.fs.rm(path, options);
157
255
  },
158
256
  async snapshot(options) {
@@ -169,7 +267,12 @@ function createWritableFacadeStore(workspace) {
169
267
  return meta.get(key);
170
268
  },
171
269
  async setMeta(key, value) {
270
+ const target = sourceSync ? resolveWorkspaceMetadataMutationTarget(await resolveWorkspaceMetadataTarget(workspace) ?? {}) : void 0;
271
+ if (target) {
272
+ if (await setWorkspaceMetadata(target, key, value)) return;
273
+ }
172
274
  if (metadata.setMeta) {
275
+ if (isInternalWorkspaceMetaKey(key)) throw workspaceError("[vitehub] Source Sync cannot write internal metadata without a private metadata target.");
173
276
  await metadata.setMeta(key, value);
174
277
  return;
175
278
  }
@@ -182,7 +285,7 @@ function createWritableFacadeStore(workspace) {
182
285
  async function startOverlayWorkspaceSession(_definition, workspace, options) {
183
286
  const host = options?.host;
184
287
  if (host) {
185
- const { createHostedWorkspaceSession } = await import("./host-DJH8cuoU.js").then((n) => n.n);
288
+ const { createHostedWorkspaceSession } = await import("./host-CFnrTXTK.js").then((n) => n.n);
186
289
  return await createHostedWorkspaceSession(workspace, {
187
290
  ...options,
188
291
  host
@@ -192,7 +295,7 @@ async function startOverlayWorkspaceSession(_definition, workspace, options) {
192
295
  }
193
296
  async function resolveWorkspaceSources(definition, options) {
194
297
  if (!hasWorkspaceSourceResolvers(definition) && !options.selectedWorkspaceScope) return definition;
195
- const sources = {};
298
+ const sources = Object.create(null);
196
299
  for (const [key, source] of Object.entries(definition.sources || {})) {
197
300
  const resolved = await resolveWorkspaceSource(definition, key, source, options);
198
301
  if (resolved) sources[key] = resolved;
@@ -205,14 +308,19 @@ async function resolveWorkspaceSources(definition, options) {
205
308
  async function createWorkspaceSourceResolutionFacade(workspace, definition, options) {
206
309
  const resolvedDefinition = await resolveWorkspaceSources(definition, options);
207
310
  const sourceRequestExecution = createWorkspaceSourceRequestExecution(resolvedDefinition, { selectedWorkspaceScope: options.selectedWorkspaceScope }) ?? getWorkspaceSourceRequestExecution(workspace.fs);
208
- if (!options.overlay && resolvedDefinition === definition && !sourceRequestExecution) return {
311
+ if (!options.overlay && resolvedDefinition === definition && !sourceRequestExecution && (!options.selectedWorkspaceScope || options.selectedWorkspaceScope.all)) return {
209
312
  definition,
210
313
  workspace
211
314
  };
212
315
  const selectedWorkspaceScope = options.selectedWorkspaceScope;
213
316
  const sourceViewDefinition = createScopedSourceViewDefinition(resolvedDefinition, selectedWorkspaceScope);
214
- const overlayStore = createOverlaySourceStore(workspace, (path) => !isLazySourcePath(resolvedDefinition, path) || selectedScopeCanSee(selectedWorkspaceScope, path) && isUnchangedStartupSourcePath(definition, resolvedDefinition, path));
317
+ const overlayStore = createOverlaySourceStore(workspace, (path) => !isLazySourcePath(resolvedDefinition, path) || selectedScopeCanSee(selectedWorkspaceScope, path) && isUnchangedStartupSourcePath(definition, resolvedDefinition, path), await resolveWorkspaceMetadataTarget(workspace));
215
318
  const sourceView = createWorkspaceSourceView(sourceViewDefinition, overlayStore, { reuseStartupSnapshots: true });
319
+ function requireCompleteHistory() {
320
+ if (selectedWorkspaceScope && !selectedWorkspaceScope.all) throw workspaceErrorDiagnostics.WORKSPACE_R0069({ message: "[vitehub] Retained folder history requires access to the complete Workspace. A selected path or Source scope cannot inspect or replace its full history." });
321
+ return workspace.history;
322
+ }
323
+ const history = createWorkspaceHistoryReader(workspace.history, !selectedWorkspaceScope || selectedWorkspaceScope.all);
216
324
  const materializeSources = async (options = {}) => await sourceView.materializeSources(options);
217
325
  const canUseBase = (path) => !overlayStore.isTombstoned(normalizeWorkspacePath(path));
218
326
  let readWorkspace;
@@ -277,6 +385,7 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
277
385
  read: options?.read,
278
386
  search: options?.search
279
387
  },
388
+ sourceRequests: options?.sourceRequests,
280
389
  timeout: options?.timeout
281
390
  });
282
391
  const tools = createTools();
@@ -284,7 +393,8 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
284
393
  tools.none = (() => ({}));
285
394
  if (isWritableWorkspaceFacade(workspace)) {
286
395
  const writePolicy = createWorkspaceWritePolicy(resolvedDefinition);
287
- const syncStore = createWritableFacadeStore(workspace);
396
+ const syncStore = createWritableFacadeStore(workspace, resolvedDefinition);
397
+ if (!sourceSyncStores.has(workspace.fs)) registerWorkspaceStoreAlias(syncStore, overlayStore);
288
398
  let writeWorkspace;
289
399
  async function previousStat(path) {
290
400
  try {
@@ -293,6 +403,33 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
293
403
  return;
294
404
  }
295
405
  }
406
+ const writes = {
407
+ writeFile: async (path, content, options) => await workspace.fs.writeFile(path, content, options),
408
+ mkdir: async (path, options) => await workspace.fs.mkdir(path, options),
409
+ rm: async (path, options) => await workspace.fs.rm(path, options)
410
+ };
411
+ const baseWrites = {
412
+ mkdir: sourceView.requireWriteGrant(async (path, options) => await writes.mkdir(path, options)),
413
+ rm: sourceView.requireWriteGrant(async (path, options) => await writes.rm(path, options)),
414
+ writeFile: sourceView.requireWriteGrant(async (path, content, options) => await writes.writeFile(path, content, options))
415
+ };
416
+ const baseRebase = sourceView.requireRebaseGrants(async (options) => await workspace.history.rebase(options));
417
+ const resolvedHistory = createWorkspaceHistory(resolvedDefinition, {
418
+ ...overlayStore,
419
+ history: {
420
+ ...createWorkspaceHistoryReader(workspace.history, true),
421
+ commit: async (options) => await workspace.history.commit(forwardWorkspaceHistoryFiles(options))
422
+ }
423
+ }, sourceView);
424
+ async function commitHistory(options) {
425
+ requireCompleteHistory();
426
+ return await resolvedHistory.commit(options);
427
+ }
428
+ async function rebase(options) {
429
+ const grants = [];
430
+ for (const path of options?.takeRemote ?? []) grants.push(await sourceView.assertWritable(path));
431
+ await baseRebase(grants, options);
432
+ }
296
433
  async function writeWithPolicy(input, write, preservePath = false) {
297
434
  await sourceView.assertWritable(input.path);
298
435
  const next = await writePolicy.before({
@@ -303,8 +440,7 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
303
440
  });
304
441
  try {
305
442
  if (preservePath && next.path !== normalizeWorkspacePath(input.path)) throw workspaceError(`[vitehub] Workspace validator cannot rewrite preserved path: ${normalizeWorkspacePath(input.path)} -> ${next.path}.`);
306
- await sourceView.assertWritable(next.path);
307
- const result = await write(next);
443
+ const result = await write(next, await sourceView.assertWritable(next.path));
308
444
  await writePolicy.after(next);
309
445
  return {
310
446
  input: next,
@@ -316,24 +452,29 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
316
452
  }
317
453
  }
318
454
  function withSessionSourceGuards(session) {
455
+ const sessionWrites = {
456
+ mkdir: sourceView.requireWriteGrant(async (path, options) => await session.mkdir(path, options)),
457
+ rm: sourceView.requireWriteGrant(async (path, options) => await session.rm(path, options)),
458
+ writeFile: sourceView.requireWriteGrant(async (path, content, options) => await session.writeFile(path, content, options))
459
+ };
319
460
  return {
320
461
  ...session,
321
462
  async mkdir(path, options) {
322
- await sourceView.assertWritable(path);
323
- await session.mkdir(path, options);
463
+ await sessionWrites.mkdir(await sourceView.assertWritable(path), path, options);
324
464
  },
325
465
  async rm(path, options) {
326
- await sourceView.assertWritable(path);
327
- await session.rm(path, options);
466
+ await sessionWrites.rm(await sourceView.assertWritable(path), path, options);
328
467
  },
329
468
  async writeFile(path, content, options) {
330
- await sourceView.assertWritable(path);
331
- await session.writeFile(path, content, options);
469
+ await sessionWrites.writeFile(await sourceView.assertWritable(path), path, content, options);
332
470
  }
333
471
  };
334
472
  }
335
473
  const writeFs = attachWorkspaceSourceRequestExecution({
336
- appendFile: async (path, content) => await appendWorkspaceFile(writeWorkspace, path, content),
474
+ appendFile: async (path, content) => {
475
+ await sourceView.assertWritable(path);
476
+ await appendWorkspaceFile(writeWorkspace, path, content);
477
+ },
337
478
  copyPath: async (from, to, options) => {
338
479
  await sourceView.assertWritable(to);
339
480
  await copyWorkspacePath(writeWorkspace, from, to, options?.overwrite);
@@ -345,7 +486,7 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
345
486
  await writeWithPolicy({
346
487
  operation: "mkdir",
347
488
  path
348
- }, async (input) => await workspace.fs.mkdir(input.path, options));
489
+ }, async (input, grant) => await baseWrites.mkdir(grant, input.path, options));
349
490
  },
350
491
  movePath: async (from, to, options) => {
351
492
  await sourceView.assertWritable(from);
@@ -361,7 +502,7 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
361
502
  await writeWithPolicy({
362
503
  operation: "rm",
363
504
  path
364
- }, async (input) => await workspace.fs.rm(input.path, options));
505
+ }, async (input, grant) => await baseWrites.rm(grant, input.path, options));
365
506
  },
366
507
  search: fs.search,
367
508
  stat: fs.stat,
@@ -372,33 +513,31 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
372
513
  metadata: options?.metadata,
373
514
  operation: "writeFile",
374
515
  path
375
- }, async (next) => {
516
+ }, async (next, grant) => {
376
517
  const writeOptions = options === void 0 && next.mediaType === void 0 && next.metadata === void 0 ? void 0 : {
377
518
  ...options,
378
519
  mediaType: next.mediaType,
379
520
  metadata: next.metadata
380
521
  };
381
- return await workspace.fs.writeFile(next.path, next.content ?? content, writeOptions);
522
+ return await baseWrites.writeFile(grant, next.path, next.content ?? content, writeOptions);
382
523
  }, options?.preservePath);
383
524
  return result || input.path;
384
525
  }
385
526
  }, sourceRequestExecution);
386
527
  writeWorkspace = attachWorkspaceSourceRequestExecution({
387
528
  name: resolvedDefinition.name,
529
+ history: {
530
+ ...workspace.history,
531
+ ...history,
532
+ commit: commitHistory
533
+ },
388
534
  diff: workspace.diff,
389
535
  exists: writeFs.exists,
390
536
  glob: writeFs.glob,
391
537
  list: writeFs.list,
392
538
  materializeSources,
393
539
  mkdir: writeFs.mkdir,
394
- publish: async (options) => {
395
- const { publishWorkspace } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
396
- await publishWorkspace(resolvedDefinition, createWritableFacadeStore({
397
- ...workspace,
398
- fs: writeFs
399
- }), options);
400
- },
401
- rebase: workspace.history.rebase,
540
+ rebase,
402
541
  readFile: writeFs.readFile,
403
542
  rm: writeFs.rm,
404
543
  search: writeFs.search,
@@ -406,12 +545,12 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
406
545
  startSession: async (options) => {
407
546
  const paths = options?.paths?.length ? options.paths : [""];
408
547
  if (options?.materializeSources !== false) await Promise.all(paths.map((path) => materializeSources({ path })));
409
- const startBoxSession = Reflect.get(workspace, Symbol.for("vitehub.workspace.start-box-session"));
410
- return withSessionSourceGuards(options?.host ? await startOverlayWorkspaceSession(resolvedDefinition, writeWorkspace, options) : typeof startBoxSession === "function" ? await startBoxSession(writeWorkspace, options) : await startOverlayWorkspaceSession(resolvedDefinition, writeWorkspace, options));
548
+ const startSandboxSession = Reflect.get(workspace, Symbol.for("vitehub.workspace.start-sandbox-session"));
549
+ return withSessionSourceGuards(options?.host ? await startOverlayWorkspaceSession(resolvedDefinition, writeWorkspace, options) : typeof startSandboxSession === "function" ? await startSandboxSession(writeWorkspace, options) : await startOverlayWorkspaceSession(resolvedDefinition, writeWorkspace, options));
411
550
  },
412
551
  stat: writeFs.stat,
413
552
  sync: async (options) => {
414
- const { syncWorkspaceSources } = await import("./sync-DnTQwt8r.js");
553
+ const { syncWorkspaceSources } = await import("./sync-CN6ec-5M.js");
415
554
  return await syncWorkspaceSources(resolvedDefinition, syncStore, options);
416
555
  },
417
556
  writeFile: writeFs.writeFile
@@ -428,24 +567,88 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
428
567
  search: options?.search,
429
568
  write: writeOperations(options)
430
569
  },
570
+ sourceRequests: options?.sourceRequests,
431
571
  timeout: options?.timeout
432
572
  });
433
573
  const writeTools = createWriteTools();
434
574
  writeTools.inspect = createTools;
435
575
  writeTools.none = (() => ({}));
436
576
  writeTools.write = createWriteTools;
577
+ const baseHistory = workspace.history;
578
+ const writableHistory = {
579
+ ...history,
580
+ ...baseHistory.merge ? { merge: async (options) => {
581
+ requireCompleteHistory();
582
+ return await baseHistory.merge(forwardWorkspaceHistoryMerge(options, async (commitOptions, apply) => {
583
+ return await createWorkspaceHistory(resolvedDefinition, {
584
+ ...overlayStore,
585
+ history: {
586
+ ...createWorkspaceHistoryReader(workspace.history, true),
587
+ commit: apply
588
+ }
589
+ }, sourceView).commit(commitOptions);
590
+ }));
591
+ } } : {},
592
+ ...baseHistory.openPullRequest ? { openPullRequest: async (options) => {
593
+ requireCompleteHistory();
594
+ return await baseHistory.openPullRequest(options);
595
+ } } : {},
596
+ commit: commitHistory,
597
+ checkpoint: baseHistory.checkpoint.bind(baseHistory),
598
+ rebase
599
+ };
437
600
  const writableWorkspace = {
438
601
  ...workspace,
602
+ async capabilities() {
603
+ const capabilities = await workspace.capabilities();
604
+ return {
605
+ ...capabilities,
606
+ retainedHistory: capabilities.retainedHistory === true && (!selectedWorkspaceScope || selectedWorkspaceScope.all)
607
+ };
608
+ },
439
609
  diff: writeWorkspace.diff,
440
610
  fs: writeFs,
611
+ history: writableHistory,
441
612
  materializeSources,
442
- publish: writeWorkspace.publish,
443
613
  snapshot: writeWorkspace.snapshot,
444
614
  startSession: writeWorkspace.startSession,
445
615
  sync: writeWorkspace.sync,
446
616
  tools: writeTools
447
617
  };
448
- forwardWorkspaceMetadataTarget({ [workspaceMetadataTarget]: () => overlayStore }, writableWorkspace);
618
+ sourceSyncStores.set(writableWorkspace.fs, (childDefinition) => {
619
+ const guardDefinition = {
620
+ ...sourceViewDefinition,
621
+ sources: Object.fromEntries(Object.entries(sourceViewDefinition.sources ?? {}).filter(([key, source]) => {
622
+ const resolvedSource = resolvedDefinition.sources?.[key];
623
+ return childDefinition.name !== resolvedDefinition.name || !sameWorkspaceSourceBinding(key, resolvedSource, childDefinition.sources?.[key]) || !normalizeWorkspaceSource(key, resolvedSource ?? source).sync;
624
+ }))
625
+ };
626
+ const guard = createWorkspaceSourceView(guardDefinition, overlayStore, { reuseStartupSnapshots: true });
627
+ const backing = createWritableFacadeStore(workspace, childDefinition);
628
+ const guarded = {
629
+ ...backing,
630
+ async readFile(path) {
631
+ await guard.assertWritableCurrentPath(normalizeWorkspacePath(path));
632
+ return await backing.readFile(path);
633
+ },
634
+ async writeFile(path, file) {
635
+ await guard.assertWritableCurrentPath(normalizeWorkspacePath(path));
636
+ await backing.writeFile(path, file);
637
+ },
638
+ async mkdir(path, options) {
639
+ await guard.assertWritableCurrentPath(normalizeWorkspacePath(path));
640
+ await backing.mkdir(path, options);
641
+ },
642
+ async rm(path, options) {
643
+ await guard.assertWritableCurrentPath(normalizeWorkspacePath(path));
644
+ await backing.rm(path, options);
645
+ }
646
+ };
647
+ registerWorkspaceStoreAlias(guarded, syncStore);
648
+ return guarded;
649
+ });
650
+ attachWorkspaceMetadataTarget(writableWorkspace, () => createWorkspaceMetadataTarget(overlayStore, resolvedDefinition.name));
651
+ forwardWorkspaceStoreTarget(workspace, writableWorkspace);
449
652
  return {
450
653
  definition: resolvedDefinition,
451
654
  workspace: writableWorkspace
@@ -453,9 +656,11 @@ async function createWorkspaceSourceResolutionFacade(workspace, definition, opti
453
656
  }
454
657
  const readonlyWorkspace = {
455
658
  fs,
659
+ history,
456
660
  tools
457
661
  };
458
- forwardWorkspaceMetadataTarget({ [workspaceMetadataTarget]: () => overlayStore }, readonlyWorkspace);
662
+ attachWorkspaceMetadataTarget(readonlyWorkspace, () => createWorkspaceMetadataTarget(overlayStore, resolvedDefinition.name));
663
+ forwardWorkspaceStoreTarget(workspace, readonlyWorkspace);
459
664
  const starter = workspaceSessionStarter(workspace);
460
665
  if (starter) readonlyWorkspace.startSession = async (options) => await starter.startSession(options);
461
666
  return {
@@ -487,7 +692,7 @@ async function resolveWorkspaceSource(definition, key, input, options) {
487
692
  const resolvedSource = withResolvedSourceRuntimeDefaults(applyResolvedWorkspaceSourceBinding(input, resolved));
488
693
  const normalized = normalizeWorkspaceSource(key, resolvedSource);
489
694
  if (!selectedScopeIntersectsSource(options.selectedWorkspaceScope, normalized)) return void 0;
490
- return copyWorkspaceSourceMetadata(resolvedSource, {
695
+ const result = copyWorkspaceSourceMetadata(resolvedSource, {
491
696
  ...resolvedSource,
492
697
  fingerprint: {
493
698
  source: resolvedSource.fingerprint,
@@ -500,6 +705,8 @@ async function resolveWorkspaceSource(definition, key, input, options) {
500
705
  } : void 0 }
501
706
  }
502
707
  });
708
+ sourceBindingLineage.set(result, typeof input === "object" ? sourceBindingLineage.get(input) ?? input : input);
709
+ return result;
503
710
  }
504
711
  function applyResolvedWorkspaceSourceBinding(input, source) {
505
712
  if (!isPlainRecord(input)) return source;
@@ -514,11 +721,12 @@ function applyResolvedWorkspaceSourceBinding(input, source) {
514
721
  return next;
515
722
  }
516
723
  function copyDefinedWorkspaceBindingOption(target, input, key) {
517
- if (input[key] !== void 0) target[key] = input[key];
724
+ if (Object.hasOwn(input, key) && input[key] !== void 0) target[key] = input[key];
518
725
  }
519
726
  function withResolvedSourceRuntimeDefaults(source) {
520
- if (source.materialize || source.mount && typeof source.mount === "object" && source.mount.materialize) return source;
521
- if (source.sync) return source;
727
+ const mount = ownSourceOption(source, "mount");
728
+ if (ownSourceOption(source, "materialize") || mount && typeof mount === "object" && ownSourceOption(mount, "materialize")) return source;
729
+ if (ownSourceOption(source, "sync")) return source;
522
730
  return copyWorkspaceSourceMetadata(source, {
523
731
  ...source,
524
732
  materialize: "lazy"
@@ -673,10 +881,10 @@ async function waitForAbortable(operation, signal) {
673
881
  }
674
882
  }
675
883
  function createWorkspacePreparation(options) {
676
- if (!options || !hasRuntimeType(options.workspace, "string") || !options.workspace.trim()) throw new TypeError("[vitehub] Workspace preparation requires a Workspace name.");
677
- if (options.sources !== void 0 && (!Array.isArray(options.sources) || options.sources.some((source) => !hasRuntimeType(source, "string") || !source.trim()))) throw new TypeError("[vitehub] Workspace preparation sources must be non-empty strings.");
884
+ if (!options || !hasRuntimeType(options.workspace, "string") || !options.workspace.trim()) throw workspaceErrorDiagnostics.WORKSPACE_R0034({ message: "[vitehub] Workspace preparation requires a Workspace name." });
885
+ if (options.sources !== void 0 && (!Array.isArray(options.sources) || options.sources.some((source) => !hasRuntimeType(source, "string") || !source.trim()))) throw workspaceErrorDiagnostics.WORKSPACE_R0035({ message: "[vitehub] Workspace preparation sources must be non-empty strings." });
678
886
  const retryDelayMs = options.retryDelayMs ?? 1e4;
679
- if (!Number.isFinite(retryDelayMs) || retryDelayMs < 0 || retryDelayMs > MAX_TIMER_DELAY_MS) throw new TypeError(`[vitehub] Workspace preparation retryDelayMs must be between 0 and ${MAX_TIMER_DELAY_MS}.`);
887
+ if (!Number.isFinite(retryDelayMs) || retryDelayMs < 0 || retryDelayMs > MAX_TIMER_DELAY_MS) throw workspaceErrorDiagnostics.WORKSPACE_R0036({ message: `[vitehub] Workspace preparation retryDelayMs must be between 0 and ${MAX_TIMER_DELAY_MS}.` });
680
888
  const workspaceName = options.workspace.trim();
681
889
  const sources = options.sources === void 0 ? void 0 : [...new Set(options.sources.map((source) => source.trim()))];
682
890
  let workspace = useWorkspace(workspaceName, { mode: "write" });
@@ -721,14 +929,18 @@ function createWorkspacePreparation(options) {
721
929
  try {
722
930
  const definition = await resolveRegisteredWorkspaceDefinition(workspaceName, controller.signal);
723
931
  const selectedSources = sources ?? normalizeWorkspaceSources(definition.sources).filter((source) => source.materialize === "startup").map((source) => source.key);
724
- if (!selectedSources.length) throw new Error(`[vitehub] Workspace "${workspaceName}" has no startup sources to prepare.`);
725
932
  const result = await workspace.materializeSources({
726
933
  abortSignal: controller.signal,
727
934
  sources: selectedSources
728
935
  });
936
+ if (!selectedSources.length) throw workspaceErrorDiagnostics.WORKSPACE_R0037({ message: `[vitehub] Workspace "${workspaceName}" has no startup sources to prepare.` });
729
937
  const sourceResults = new Map(result.sources.map((source) => [source.source, source]));
730
938
  const failures = selectedSources.filter((source) => sourceResults.get(source)?.status !== "ready");
731
- if (failures.length) throw new Error(`[vitehub] Workspace "${workspaceName}" sources failed to prepare: ${failures.join(", ")}.`);
939
+ if (failures.length) throw workspaceErrorDiagnostics.WORKSPACE_R0038({ message: `[vitehub] Workspace "${workspaceName}" sources failed to prepare: ${failures.join(", ")}.` });
940
+ if (options.requireNonEmpty) {
941
+ const empty = selectedSources.filter((source) => !sourceResults.get(source)?.files);
942
+ if (empty.length) throw workspaceErrorDiagnostics.WORKSPACE_R0038({ message: `[vitehub] Workspace "${workspaceName}" sources are empty: ${empty.join(", ")}.` });
943
+ }
732
944
  await waitForAbortable(options.validate?.(result), controller.signal);
733
945
  if (stopped || attemptLifecycle !== lifecycle) return state;
734
946
  const finishedAtMs = Date.now();
@@ -769,12 +981,19 @@ function createWorkspacePreparation(options) {
769
981
  getState() {
770
982
  return state;
771
983
  },
772
- response() {
984
+ response(method = "GET") {
985
+ if (method !== "GET" && method !== "HEAD") return new Response(null, {
986
+ status: 405,
987
+ headers: {
988
+ allow: "GET, HEAD",
989
+ "cache-control": "no-store"
990
+ }
991
+ });
773
992
  const ready = state.status === "ready";
774
- return Response.json({
993
+ return new Response(method === "HEAD" ? null : JSON.stringify({
775
994
  ready,
776
995
  status: state.status
777
- }, {
996
+ }), {
778
997
  headers: {
779
998
  "cache-control": "no-store",
780
999
  "content-type": "application/json; charset=utf-8"
@@ -810,10 +1029,51 @@ function createWorkspacePreparation(options) {
810
1029
  if (retryTimer) clearTimeout(retryTimer);
811
1030
  retryTimer = void 0;
812
1031
  const current = active;
813
- abortController?.abort(/* @__PURE__ */ new Error(`[vitehub] Workspace "${workspaceName}" preparation stopped.`));
1032
+ abortController?.abort(workspaceErrorDiagnostics.WORKSPACE_R0039({ message: `[vitehub] Workspace "${workspaceName}" preparation stopped.` }));
814
1033
  await current;
815
1034
  }
816
1035
  });
817
1036
  }
818
1037
  //#endregion
819
- export { attachWorkspaceSourceRequestExecution, createWorkspacePreparation, createWorkspaceSourceResolutionFacade, getWorkspaceDependencyRuntimeLoaders, getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, getWorkspaceSourceRequestDescriptor, getWorkspaceSourceRequestExecution, hasWorkspaceSourceResolvers, invalidateWorkspaceStore, isWorkspaceSourceRequestOnly, markLiveWorkspaceSource, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, registerWorkspace, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, resolveWorkspaceSources, setWorkspaceDependencyRuntimeLoaders, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace, workspaceSourceGrantPaths, workspaceSourceRequestDescriptorPath };
1038
+ //#region src/storage/recover-local-locks.ts
1039
+ /**
1040
+ * Remove abandoned markers from a trusted, exclusively owned local store.
1041
+ * Stop all store users and prevent changes to the store and its ancestor directories
1042
+ * for the entire call. Path checks catch existing symlinks; they do not provide
1043
+ * protection against concurrent filesystem mutation.
1044
+ */
1045
+ async function recoverLocalWorkspaceLocks(options) {
1046
+ if (options.offline !== true) throw workspaceError("[vitehub] Workspace lock recovery requires exclusive offline access.");
1047
+ const root = resolve(options.root);
1048
+ const directory = join(root, ".vitehub", "locks");
1049
+ for (const path of [
1050
+ root,
1051
+ join(root, ".vitehub"),
1052
+ directory
1053
+ ]) {
1054
+ const info = await lstat(path).catch((error) => {
1055
+ if (error.code === "ENOENT") return void 0;
1056
+ throw error;
1057
+ });
1058
+ if (!info) return { removed: 0 };
1059
+ if (!info.isDirectory() || info.isSymbolicLink()) throw workspaceError(`[vitehub] Expected a real Workspace lock recovery directory: ${path}.`);
1060
+ }
1061
+ let removed = 0;
1062
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
1063
+ const markerName = /^[a-f0-9]{64}\.(gate|readers|writers)$/.test(entry.name);
1064
+ const quarantineName = /^\.recovery-[a-f0-9]{64}\.(gate|readers|writers)-[0-9a-f-]+$/.test(entry.name);
1065
+ if (!markerName && !quarantineName) continue;
1066
+ if (markerName && (!entry.isDirectory() || entry.isSymbolicLink())) throw workspaceError(`[vitehub] Expected a real Workspace lock marker directory: ${entry.name}.`);
1067
+ const source = join(directory, entry.name);
1068
+ if (quarantineName) await rm(source, { recursive: true });
1069
+ else {
1070
+ const quarantine = join(directory, `.recovery-${entry.name}-${randomUUID()}`);
1071
+ await rename(source, quarantine);
1072
+ await rm(quarantine, { recursive: true });
1073
+ }
1074
+ removed++;
1075
+ }
1076
+ return { removed };
1077
+ }
1078
+ //#endregion
1079
+ export { attachWorkspaceSourceRequestExecution, createWorkspaceHistoryReader, createWorkspacePreparation, createWorkspaceSourceResolutionFacade, forwardWorkspaceFacade, forwardWorkspaceMetadataView, getWorkspaceDependencyRuntimeLoaders, getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, getWorkspaceSourceRequestDescriptor, getWorkspaceSourceRequestExecution, hasWorkspaceSourceResolvers, invalidateWorkspaceStore, isWorkspaceSourceRequestOnly, markLiveWorkspaceSource, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, recoverLocalWorkspaceLocks, registerWorkspace, registerWorkspacePlugin, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, resolveWorkspaceSources, setWorkspaceDependencyRuntimeLoaders, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace, workspaceSourceGrantPaths, workspaceSourceRequestDescriptorPath, workspaceSourceRequestMatches };