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