@vite-hub/workspace 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +48 -2
- package/dist/{ai-Cztw4eLk.js → ai-BqCC8BpY.js} +15 -4
- package/dist/{ai-hFdsvDHC.d.ts → ai-CjxvGqM0.d.ts} +1 -1
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-CaG9b7tf.js → asset-registry-8QI3ML3K.js} +1 -1
- package/dist/chunk-2rV9d50f.js +35 -0
- package/dist/cloudflare.d.ts +4 -2
- package/dist/cloudflare.js +1 -2
- package/dist/collections.d.ts +2 -2
- package/dist/collections.js +1 -1
- package/dist/{config--r5unwPc.js → config-Bc3c4Su1.js} +213 -120
- package/dist/{config-DCQ6y30R.js → config-CHLLWklZ.js} +9 -3
- package/dist/{config-Ca5DM8fF.d.ts → config-DE9xlaIw.d.ts} +1 -1
- package/dist/{file-B2q9NE18.js → file-Bc1X7pco.js} +9 -10
- package/dist/{files-xy0le-_U.js → files-Q6xZjDHA.js} +20 -9
- package/dist/{github-lIO6-2sH.js → github-DHnjxQIX.js} +27 -23
- package/dist/glob-CEZKeZFC.js +18 -0
- package/dist/host-DJH8cuoU.js +1030 -0
- package/dist/{artifacts-store-BAV9jZpd.js → hosted-RPeJOCFz.js} +146 -30
- package/dist/hosted-vercel-blob-d6C8ND5j.js +23580 -0
- package/dist/hosted-vercel-blob.d.ts +1 -1
- package/dist/hosted-vercel-blob.js +1 -25
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +1 -29
- package/dist/index.d.ts +61 -78
- package/dist/index.js +133 -435
- package/dist/lifecycle-LrL3sA4n.js +316 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- package/dist/metadata-target-B0tOmVW7.js +717 -0
- package/dist/mountx.d.ts +10 -0
- package/dist/mountx.js +143 -0
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +8 -2
- package/dist/{path-CNI6wKIU.js → path-Cp59koVz.js} +28 -4
- package/dist/{provider-CeQciesl.js → provider-B1yLjCJJ.js} +194 -47
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1 -361
- package/dist/publish.d.ts +1 -1
- package/dist/publish.js +2 -2
- package/dist/registry-D3yzt8HQ.js +127 -0
- package/dist/{registry-CoC9JxVt.d.ts → registry-Uj6IVxes.d.ts} +3 -3
- package/dist/{request-execution-C8qRcReq.js → request-execution-B-dSFlGB.js} +8 -4
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/assets.js +4 -2
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +1 -1
- package/dist/runtime/state.d.ts +4 -4
- package/dist/runtime/state.js +10 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime-options-BsPSv5O7.js +13 -0
- package/dist/runtime-type-iEE6BjQJ.js +34 -0
- package/dist/runtime.d.ts +42 -7
- package/dist/runtime.js +276 -100
- package/dist/{search-C4REyHj9.js → search-BpiCF2Tw.js} +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +24 -51
- package/dist/{shared-BRycRSbo.js → shared-DTR1Hhma.js} +115 -39
- package/dist/source-metadata.d.ts +9 -2
- package/dist/source-metadata.js +34 -2
- package/dist/{state-DSAHEsq6.d.ts → state-tYcRWEh2.d.ts} +13 -12
- package/dist/store-Dt_Jyys3.js +608 -0
- package/dist/{sync-DO42ypji.js → sync-DnTQwt8r.js} +6 -5
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/token-CVzURBxC.js +61 -0
- package/dist/{types-DHkae7Cb.d.ts → types-CYuwjJ4V.d.ts} +94 -43
- package/dist/{use-d_PlAdOu.js → use-BTNDR5Rd.js} +147 -50
- package/dist/{use-D16tf8Ph.d.ts → use-BiHzt0xA.d.ts} +21 -4
- package/dist/vite-BptCrpv2.js +4526 -0
- package/dist/vite-CtA9guIM.d.ts +66 -0
- package/dist/vite.d.ts +2 -50
- package/dist/vite.js +2 -2
- package/dist/{workspace-n4wBmdaM.js → workspace-Dq08Yn72.js} +224 -545
- package/dist/{workspace-f2DBLmPZ.d.ts → workspace-Xddf4G1B.d.ts} +1 -1
- package/package.json +20 -38
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/cli.d.ts +0 -31
- package/dist/cli.js +0 -303
- package/dist/cloudflare-env-CKxUs2fa.js +0 -20
- package/dist/glob-DeH0dzZX.js +0 -23
- package/dist/host-I-_vDs05.js +0 -370
- package/dist/lifecycle-Lhk3dAMt.js +0 -176
- package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
- package/dist/providers/cloudflare/artifacts-store.js +0 -2
- package/dist/providers/vercel/blob-store.d.ts +0 -6
- package/dist/providers/vercel/blob-store.js +0 -235
- package/dist/registry-C7DMdBXN.js +0 -74
- package/dist/utils-BPdaCyI6.js +0 -55
- package/dist/vite-NWC9mFjI.js +0 -1882
|
@@ -0,0 +1,1030 @@
|
|
|
1
|
+
import { n as __exportAll } from "./chunk-2rV9d50f.js";
|
|
2
|
+
import { _ as workspaceError, a as isExcludedWorkspacePath, f as sha256, g as workspaceConflict, i as decodeFile, l as normalizeWorkspacePath, r as contentToBytes, s as normalizeSafeWorkspacePath } from "./path-Cp59koVz.js";
|
|
3
|
+
import { a as createSnapshotFromEntries, o as diffSnapshots, r as resolveWorkspaceRevisionMaterializer } from "./store-Dt_Jyys3.js";
|
|
4
|
+
import { _ as isMissingWorkspacePathError, g as filterSessionEntries, h as filterSessionDiff, m as assertPathInSessionScope, p as assertDiffInsideSessionPaths, v as scopedSearchQuery } from "./workspace-Dq08Yn72.js";
|
|
5
|
+
import { posix } from "node:path";
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { normalizeExecutionAuthority } from "@vite-hub/runtime";
|
|
8
|
+
//#region src/session/progress.ts
|
|
9
|
+
async function withWorkspaceProgress(onProgress, event, fn) {
|
|
10
|
+
const startedAt = Date.now();
|
|
11
|
+
await onProgress?.({
|
|
12
|
+
data: event.data,
|
|
13
|
+
id: event.id,
|
|
14
|
+
label: event.label,
|
|
15
|
+
status: "started"
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
const result = await fn();
|
|
19
|
+
await onProgress?.({
|
|
20
|
+
data: event.data,
|
|
21
|
+
durationMs: Date.now() - startedAt,
|
|
22
|
+
id: event.id,
|
|
23
|
+
label: event.label,
|
|
24
|
+
status: "completed"
|
|
25
|
+
});
|
|
26
|
+
return result;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
29
|
+
await onProgress?.({
|
|
30
|
+
data: {
|
|
31
|
+
...event.data,
|
|
32
|
+
error: message
|
|
33
|
+
},
|
|
34
|
+
durationMs: Date.now() - startedAt,
|
|
35
|
+
error: message,
|
|
36
|
+
id: event.id,
|
|
37
|
+
label: event.label,
|
|
38
|
+
status: "failed"
|
|
39
|
+
});
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/session/host.ts
|
|
45
|
+
var host_exports = /* @__PURE__ */ __exportAll({ createHostedWorkspaceSession: () => createHostedWorkspaceSession });
|
|
46
|
+
const publicationQueues = /* @__PURE__ */ new WeakMap();
|
|
47
|
+
const defaultHostInspectionConcurrency = 16;
|
|
48
|
+
const hostInspectionLimiters = /* @__PURE__ */ new WeakMap();
|
|
49
|
+
function resolveHostInspectionConcurrency(host) {
|
|
50
|
+
const concurrency = host.inspectionConcurrency ?? defaultHostInspectionConcurrency;
|
|
51
|
+
if (!Number.isInteger(concurrency) || concurrency < 1) throw workspaceError("[vitehub] Workspace host inspectionConcurrency must be a positive integer.");
|
|
52
|
+
return concurrency;
|
|
53
|
+
}
|
|
54
|
+
function resolveHostInspectionLimiter(host) {
|
|
55
|
+
const existing = hostInspectionLimiters.get(host);
|
|
56
|
+
if (existing) return existing;
|
|
57
|
+
const concurrency = resolveHostInspectionConcurrency(host);
|
|
58
|
+
let active = 0;
|
|
59
|
+
const queued = [];
|
|
60
|
+
const run = async (inspect, signal) => {
|
|
61
|
+
signal?.throwIfAborted();
|
|
62
|
+
if (active < concurrency) active++;
|
|
63
|
+
else await new Promise((resolve, reject) => {
|
|
64
|
+
const entry = { grant: () => {
|
|
65
|
+
signal?.removeEventListener("abort", abort);
|
|
66
|
+
active++;
|
|
67
|
+
resolve();
|
|
68
|
+
} };
|
|
69
|
+
const abort = () => {
|
|
70
|
+
const index = queued.indexOf(entry);
|
|
71
|
+
if (index < 0) return;
|
|
72
|
+
queued.splice(index, 1);
|
|
73
|
+
reject(signal?.reason);
|
|
74
|
+
};
|
|
75
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
76
|
+
queued.push(entry);
|
|
77
|
+
if (signal?.aborted) abort();
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
return await inspect();
|
|
81
|
+
} finally {
|
|
82
|
+
active--;
|
|
83
|
+
queued.shift()?.grant();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
hostInspectionLimiters.set(host, run);
|
|
87
|
+
return run;
|
|
88
|
+
}
|
|
89
|
+
function inspectHost(host, inspect, signal, batch) {
|
|
90
|
+
return resolveHostInspectionLimiter(host)(async () => {
|
|
91
|
+
batch?.assertActive();
|
|
92
|
+
try {
|
|
93
|
+
return await inspect();
|
|
94
|
+
} catch (error) {
|
|
95
|
+
batch?.fail(error);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}, signal);
|
|
99
|
+
}
|
|
100
|
+
async function mapHostInspections(host, values, visit, _signal) {
|
|
101
|
+
const results = [];
|
|
102
|
+
let next = 0;
|
|
103
|
+
let failed = false;
|
|
104
|
+
let failure;
|
|
105
|
+
const assertActive = () => {
|
|
106
|
+
if (failed) throw failure;
|
|
107
|
+
};
|
|
108
|
+
const fail = (error) => {
|
|
109
|
+
if (!failed) failure = error;
|
|
110
|
+
failed = true;
|
|
111
|
+
};
|
|
112
|
+
const batch = {
|
|
113
|
+
assertActive,
|
|
114
|
+
fail
|
|
115
|
+
};
|
|
116
|
+
const workers = Array.from({ length: Math.min(values.length, resolveHostInspectionConcurrency(host)) }, async () => {
|
|
117
|
+
while (!failed) {
|
|
118
|
+
const index = next++;
|
|
119
|
+
if (index >= values.length) return;
|
|
120
|
+
try {
|
|
121
|
+
results[index] = await visit(values[index], batch);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
fail(error);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
await Promise.all(workers);
|
|
128
|
+
if (failed) throw failure;
|
|
129
|
+
return results;
|
|
130
|
+
}
|
|
131
|
+
async function waitForOperation(operation, signal) {
|
|
132
|
+
signal?.throwIfAborted();
|
|
133
|
+
if (!signal) return await operation;
|
|
134
|
+
return await new Promise((resolve, reject) => {
|
|
135
|
+
const abort = () => reject(signal.reason);
|
|
136
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
137
|
+
operation.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
async function withWorkspacePublication(key, signal, publish) {
|
|
141
|
+
const previous = publicationQueues.get(key) || Promise.resolve();
|
|
142
|
+
let release;
|
|
143
|
+
const current = new Promise((resolve) => {
|
|
144
|
+
release = resolve;
|
|
145
|
+
});
|
|
146
|
+
publicationQueues.set(key, current);
|
|
147
|
+
try {
|
|
148
|
+
await waitForOperation(previous, signal);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
previous.finally(release);
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
return await publish();
|
|
155
|
+
} finally {
|
|
156
|
+
release();
|
|
157
|
+
if (publicationQueues.get(key) === current) publicationQueues.delete(key);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function normalizeTarget(target = "/workspace") {
|
|
161
|
+
const normalized = posix.resolve("/", target.replace(/\\/g, "/"));
|
|
162
|
+
if (normalized === "/") throw workspaceError("[vitehub] Workspace session target cannot be the host root.");
|
|
163
|
+
return normalized;
|
|
164
|
+
}
|
|
165
|
+
function normalizeSearchRoot(path) {
|
|
166
|
+
const normalized = posix.normalize(path.replace(/\\/g, "/"));
|
|
167
|
+
return normalized === "." ? "" : normalizeSafeWorkspacePath(normalized, { allowEmpty: true });
|
|
168
|
+
}
|
|
169
|
+
function normalizeReadableSessionPath(path) {
|
|
170
|
+
const normalized = normalizeSafeWorkspacePath(path, { allowReserved: true });
|
|
171
|
+
if (/^\.vitehub\/sources\/[^/]+\.json$/.test(normalized)) return normalized;
|
|
172
|
+
return normalizeSafeWorkspacePath(path);
|
|
173
|
+
}
|
|
174
|
+
function toHostPath(root, path = "") {
|
|
175
|
+
const normalized = normalizeSafeWorkspacePath(path, {
|
|
176
|
+
allowEmpty: true,
|
|
177
|
+
allowReserved: true
|
|
178
|
+
});
|
|
179
|
+
return normalized ? posix.join(root, normalized) : root;
|
|
180
|
+
}
|
|
181
|
+
function toHostCwd(root, cwd) {
|
|
182
|
+
if (cwd === void 0) return root;
|
|
183
|
+
if (!posix.isAbsolute(cwd)) return toHostPath(root, cwd);
|
|
184
|
+
const normalized = posix.normalize(cwd);
|
|
185
|
+
if (normalized === root || normalized.startsWith(`${root}/`)) return normalized;
|
|
186
|
+
if (normalized === "/workspace" || normalized.startsWith("/workspace/")) return toHostPath(root, normalized.slice(10));
|
|
187
|
+
throw workspaceError(`[vitehub] Workspace exec cwd must stay inside ${root}: ${cwd}.`);
|
|
188
|
+
}
|
|
189
|
+
function fromHostPath(root, path) {
|
|
190
|
+
const normalizedRoot = root.replace(/\/+$/, "");
|
|
191
|
+
const normalizedPath = posix.resolve(root, path).replace(/\/+$/, "");
|
|
192
|
+
if (normalizedPath === normalizedRoot) return "";
|
|
193
|
+
if (!normalizedPath.startsWith(`${normalizedRoot}/`)) throw workspaceError(`[vitehub] Workspace host returned a path outside ${root}: ${path}.`);
|
|
194
|
+
return normalizeSafeWorkspacePath(normalizedPath.slice(normalizedRoot.length + 1), { allowReserved: true });
|
|
195
|
+
}
|
|
196
|
+
function isGitSymlinkEntry(entry) {
|
|
197
|
+
return entry.metadata?.gitMode === "120000";
|
|
198
|
+
}
|
|
199
|
+
function hasSymlinkParent(path, symlinks) {
|
|
200
|
+
let parent = posix.dirname(path);
|
|
201
|
+
while (parent && parent !== "." && parent !== "/") {
|
|
202
|
+
if (symlinks.has(parent)) return true;
|
|
203
|
+
parent = posix.dirname(parent);
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
function isSafeHostSymlink(root, path, target) {
|
|
208
|
+
if (posix.isAbsolute(target)) return false;
|
|
209
|
+
const resolved = posix.resolve(posix.dirname(toHostPath(root, path)), target);
|
|
210
|
+
return resolved === root || resolved.startsWith(`${root}/`);
|
|
211
|
+
}
|
|
212
|
+
async function isHostPath(host, path, flag, abortSignal) {
|
|
213
|
+
abortSignal?.throwIfAborted();
|
|
214
|
+
return (await inspectHost(host, async () => await host.exec("test", [flag, path], { signal: abortSignal }), abortSignal)).code === 0;
|
|
215
|
+
}
|
|
216
|
+
async function assertHostWorkspaceRoot(host, root, abortSignal) {
|
|
217
|
+
if (await isHostPath(host, root, "-L", abortSignal) || !await isHostPath(host, root, "-d", abortSignal)) throw workspaceError(`[vitehub] Workspace host root must be a directory: ${root}.`);
|
|
218
|
+
}
|
|
219
|
+
async function ensureHostWorkspaceRoot(host, root, abortSignal) {
|
|
220
|
+
const symlink = await isHostPath(host, root, "-L", abortSignal);
|
|
221
|
+
if (!symlink && await isHostPath(host, root, "-d", abortSignal)) return false;
|
|
222
|
+
if (symlink || await inspectHost(host, async () => await host.files.exists(root, { signal: abortSignal }), abortSignal)) await host.files.remove(root, {
|
|
223
|
+
recursive: false,
|
|
224
|
+
signal: abortSignal
|
|
225
|
+
});
|
|
226
|
+
await host.files.mkdir(root, {
|
|
227
|
+
recursive: true,
|
|
228
|
+
signal: abortSignal
|
|
229
|
+
});
|
|
230
|
+
await assertHostWorkspaceRoot(host, root, abortSignal);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
async function removeHostSymlinkAncestors(host, root, path, abortSignal) {
|
|
234
|
+
let ancestor = root;
|
|
235
|
+
for (const component of fromHostPath(root, path).split("/").slice(0, -1)) {
|
|
236
|
+
ancestor = posix.join(ancestor, component);
|
|
237
|
+
abortSignal?.throwIfAborted();
|
|
238
|
+
if (!await isHostPath(host, ancestor, "-L", abortSignal)) continue;
|
|
239
|
+
await host.files.remove(ancestor, {
|
|
240
|
+
recursive: false,
|
|
241
|
+
signal: abortSignal
|
|
242
|
+
});
|
|
243
|
+
if (await isHostPath(host, ancestor, "-L", abortSignal)) throw workspaceError(`[vitehub] Failed to remove Workspace symlink ancestor: ${ancestor}.`);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async function removeHostPath(host, root, path, recursive, abortSignal) {
|
|
248
|
+
abortSignal?.throwIfAborted();
|
|
249
|
+
await removeHostSymlinkAncestors(host, root, path, abortSignal);
|
|
250
|
+
await host.files.remove(path, {
|
|
251
|
+
recursive: await isHostPath(host, path, "-L", abortSignal) ? false : recursive,
|
|
252
|
+
signal: abortSignal
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
async function assertNoHostSymlinkParent(host, root, target, abortSignal) {
|
|
256
|
+
const path = fromHostPath(root, target);
|
|
257
|
+
if (hasSymlinkParent(path, new Set((await listHostEntries(host, root, "", true, void 0, false, [], abortSignal)).filter(isGitSymlinkEntry).map((entry) => entry.path)))) throw workspaceError(`[vitehub] Workspace host path crosses a symlink parent: ${path}.`);
|
|
258
|
+
}
|
|
259
|
+
function toWorkspaceEntry(root, entry) {
|
|
260
|
+
return {
|
|
261
|
+
metadata: entry.type === "symlink" ? { gitMode: "120000" } : entry.type === "file" && entry.executable ? { gitMode: "100755" } : void 0,
|
|
262
|
+
path: fromHostPath(root, entry.path),
|
|
263
|
+
size: entry.size,
|
|
264
|
+
type: entry.type === "directory" ? "directory" : "file"
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
async function ensureHostParent(host, path, abortSignal) {
|
|
268
|
+
const parent = posix.dirname(path);
|
|
269
|
+
if (parent && parent !== "." && parent !== "/") await host.files.mkdir(parent, {
|
|
270
|
+
recursive: true,
|
|
271
|
+
signal: abortSignal
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
async function readHostSymlinkTarget(host, root, path, abortSignal, batch) {
|
|
275
|
+
return await inspectHost(host, async () => {
|
|
276
|
+
const result = await host.exec("readlink", [fromHostPath(root, path)], {
|
|
277
|
+
cwd: root,
|
|
278
|
+
signal: abortSignal
|
|
279
|
+
});
|
|
280
|
+
if (result.code !== 0) throw workspaceError(`[vitehub] Failed to read workspace symlink: ${path}.`, { cause: new Error(result.stderr || "readlink failed") });
|
|
281
|
+
return result.stdout.replace(/\n$/, "");
|
|
282
|
+
}, abortSignal, batch);
|
|
283
|
+
}
|
|
284
|
+
async function writeHostSymlink(host, root, path, target, abortSignal) {
|
|
285
|
+
await removeHostPath(host, root, path, false, abortSignal);
|
|
286
|
+
const result = await host.exec("ln", [
|
|
287
|
+
"-s",
|
|
288
|
+
target,
|
|
289
|
+
fromHostPath(root, path)
|
|
290
|
+
], {
|
|
291
|
+
cwd: root,
|
|
292
|
+
signal: abortSignal
|
|
293
|
+
});
|
|
294
|
+
if (result.code !== 0) throw workspaceError(`[vitehub] Failed to create workspace symlink: ${path}. ${result.stderr || "ln failed"}`);
|
|
295
|
+
}
|
|
296
|
+
async function readHostFile(host, root, path, abortSignal) {
|
|
297
|
+
await assertHostWorkspaceRoot(host, root, abortSignal);
|
|
298
|
+
if (!await inspectHost(host, async () => await host.files.exists(path, { signal: abortSignal }), abortSignal)) return void 0;
|
|
299
|
+
const content = await inspectHost(host, async () => await host.files.read(path, { signal: abortSignal }), abortSignal);
|
|
300
|
+
return content ? {
|
|
301
|
+
content,
|
|
302
|
+
path: fromHostPath(root, path)
|
|
303
|
+
} : void 0;
|
|
304
|
+
}
|
|
305
|
+
function gitMetadataRoot(path) {
|
|
306
|
+
const parts = path.split("/");
|
|
307
|
+
const index = parts.findIndex((part) => part.toLowerCase() === ".git");
|
|
308
|
+
return index === -1 ? void 0 : parts.slice(0, index + 1).join("/");
|
|
309
|
+
}
|
|
310
|
+
async function removeHostGitMetadata(host, root, signal) {
|
|
311
|
+
const directories = [""];
|
|
312
|
+
for (let index = 0; index < directories.length; index++) {
|
|
313
|
+
signal?.throwIfAborted();
|
|
314
|
+
const directory = directories[index];
|
|
315
|
+
for (const entry of await inspectHost(host, async () => await host.files.list(toHostPath(root, directory), { signal }), signal)) {
|
|
316
|
+
const path = fromHostPath(root, entry.path);
|
|
317
|
+
const gitRoot = gitMetadataRoot(path);
|
|
318
|
+
if (gitRoot) await removeHostPath(host, root, toHostPath(root, gitRoot), true, signal);
|
|
319
|
+
else if (entry.type === "directory") directories.push(path);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async function listHostEntries(host, root, path = "", recursive = false, include, includeGit = false, excluded = [], abortSignal) {
|
|
324
|
+
abortSignal?.throwIfAborted();
|
|
325
|
+
await assertHostWorkspaceRoot(host, root, abortSignal);
|
|
326
|
+
const workspacePath = normalizeSafeWorkspacePath(path, {
|
|
327
|
+
allowEmpty: true,
|
|
328
|
+
allowReserved: true
|
|
329
|
+
});
|
|
330
|
+
if (isExcludedWorkspacePath(workspacePath, excluded)) return [];
|
|
331
|
+
const hostExcluded = excluded.map((item) => toHostPath(root, normalizeWorkspacePath(item)));
|
|
332
|
+
return (await mapHostInspections(host, (await inspectHost(host, async () => await host.files.list(toHostPath(root, workspacePath), {
|
|
333
|
+
exclude: hostExcluded,
|
|
334
|
+
recursive,
|
|
335
|
+
signal: abortSignal
|
|
336
|
+
}), abortSignal)).map((entry) => ({
|
|
337
|
+
executable: entry.executable,
|
|
338
|
+
workspaceEntry: toWorkspaceEntry(root, entry)
|
|
339
|
+
})).filter(({ workspaceEntry }) => !isExcludedWorkspacePath(workspaceEntry.path, excluded) && (!include || include(workspaceEntry))), async ({ executable, workspaceEntry }, batch) => {
|
|
340
|
+
abortSignal?.throwIfAborted();
|
|
341
|
+
if (workspaceEntry.type !== "file" || isGitSymlinkEntry(workspaceEntry)) return workspaceEntry;
|
|
342
|
+
if (executable !== void 0) return workspaceEntry;
|
|
343
|
+
return (await inspectHost(host, async () => await host.exec("test", ["-x", workspaceEntry.path], {
|
|
344
|
+
cwd: root,
|
|
345
|
+
signal: abortSignal
|
|
346
|
+
}), abortSignal, batch)).code === 0 ? {
|
|
347
|
+
...workspaceEntry,
|
|
348
|
+
metadata: {
|
|
349
|
+
...workspaceEntry.metadata,
|
|
350
|
+
gitMode: "100755"
|
|
351
|
+
}
|
|
352
|
+
} : workspaceEntry;
|
|
353
|
+
}, abortSignal)).filter((entry) => entry.path && (includeGit || !gitMetadataRoot(entry.path))).sort((left, right) => left.path.localeCompare(right.path));
|
|
354
|
+
}
|
|
355
|
+
async function makeHostFileExecutable(host, root, path, abortSignal) {
|
|
356
|
+
const result = await host.exec("chmod", ["+x", fromHostPath(root, path)], {
|
|
357
|
+
cwd: root,
|
|
358
|
+
signal: abortSignal
|
|
359
|
+
});
|
|
360
|
+
if (result.code !== 0) throw workspaceError(`[vitehub] Failed to preserve executable Workspace file: ${path}. ${result.stderr || "chmod failed"}`);
|
|
361
|
+
}
|
|
362
|
+
async function snapshotHost(host, root, name, abortSignal) {
|
|
363
|
+
return (await captureHostState(host, root, name, abortSignal)).snapshot;
|
|
364
|
+
}
|
|
365
|
+
async function captureHostState(host, root, name, abortSignal) {
|
|
366
|
+
abortSignal?.throwIfAborted();
|
|
367
|
+
if (await isHostPath(host, root, "-L", abortSignal)) throw workspaceError(`[vitehub] Workspace host root must be a directory: ${root}.`);
|
|
368
|
+
if (!await inspectHost(host, async () => await host.files.exists(root, { signal: abortSignal }), abortSignal)) return {
|
|
369
|
+
contents: /* @__PURE__ */ new Map(),
|
|
370
|
+
snapshot: await createSnapshotFromEntries([], name)
|
|
371
|
+
};
|
|
372
|
+
return await captureHostEntriesState(host, root, await listHostEntries(host, root, "", true, void 0, false, [], abortSignal), name, abortSignal);
|
|
373
|
+
}
|
|
374
|
+
async function captureHostEntriesState(host, root, entries, name, abortSignal) {
|
|
375
|
+
const contents = /* @__PURE__ */ new Map();
|
|
376
|
+
return {
|
|
377
|
+
contents,
|
|
378
|
+
snapshot: await createSnapshotFromEntries(await mapHostInspections(host, entries, async (entry, batch) => {
|
|
379
|
+
abortSignal?.throwIfAborted();
|
|
380
|
+
if (entry.type !== "file") return entry;
|
|
381
|
+
const content = isGitSymlinkEntry(entry) ? await readHostSymlinkTarget(host, root, toHostPath(root, entry.path), abortSignal, batch) : await inspectHost(host, async () => {
|
|
382
|
+
const content = await host.files.read(toHostPath(root, entry.path), { signal: abortSignal });
|
|
383
|
+
if (content === null) throw workspaceError(`[vitehub] Workspace host file disappeared while snapshotting: ${entry.path}.`);
|
|
384
|
+
return content;
|
|
385
|
+
}, abortSignal, batch);
|
|
386
|
+
contents.set(entry.path, content);
|
|
387
|
+
return {
|
|
388
|
+
...entry,
|
|
389
|
+
digest: await sha256(content),
|
|
390
|
+
size: contentToBytes(content).byteLength
|
|
391
|
+
};
|
|
392
|
+
}, abortSignal), name)
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function isInsideExcludedWriteBackPath(path, excluded) {
|
|
396
|
+
return Boolean(gitMetadataRoot(path)) || excluded.some((item) => path === item || path.startsWith(`${item}/`));
|
|
397
|
+
}
|
|
398
|
+
async function captureExcludedHostState(host, root, excluded, abortSignal) {
|
|
399
|
+
abortSignal?.throwIfAborted();
|
|
400
|
+
if (await isHostPath(host, root, "-L", abortSignal)) throw workspaceError(`[vitehub] Workspace host root must be a directory: ${root}.`);
|
|
401
|
+
if (!await inspectHost(host, async () => await host.files.exists(root, { signal: abortSignal }), abortSignal)) return await captureHostEntriesState(host, root, [], "host-excluded", abortSignal);
|
|
402
|
+
return await captureHostEntriesState(host, root, await listHostEntries(host, root, "", true, (entry) => isInsideExcludedWriteBackPath(entry.path, excluded), true, [], abortSignal), "host-excluded", abortSignal);
|
|
403
|
+
}
|
|
404
|
+
function mergeExcludedHostState(before, materialized, excluded) {
|
|
405
|
+
const beforePaths = Object.keys(before.snapshot.entries);
|
|
406
|
+
const occupiedRoots = [...new Set([...excluded.filter((root) => beforePaths.some((path) => path === root || path.startsWith(`${root}/`))), ...beforePaths.map(gitMetadataRoot).filter((path) => Boolean(path))])];
|
|
407
|
+
const entries = Object.fromEntries(Object.entries(materialized.snapshot.entries).filter(([path]) => !occupiedRoots.some((root) => path === root || path.startsWith(`${root}/`))));
|
|
408
|
+
const contents = new Map(materialized.contents);
|
|
409
|
+
for (const root of occupiedRoots) for (const path of [...contents.keys()]) if (path === root || path.startsWith(`${root}/`)) contents.delete(path);
|
|
410
|
+
for (const [path, entry] of Object.entries(before.snapshot.entries)) entries[path] = entry;
|
|
411
|
+
for (const [path, content] of before.contents) contents.set(path, content);
|
|
412
|
+
return {
|
|
413
|
+
contents,
|
|
414
|
+
snapshot: {
|
|
415
|
+
...materialized.snapshot,
|
|
416
|
+
entries
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
async function restoreExcludedHostState(host, root, excluded, state, abortSignal) {
|
|
421
|
+
const currentGitRoots = (await listHostEntries(host, root, "", true, (entry) => Boolean(gitMetadataRoot(entry.path)), true, [], abortSignal)).map((entry) => gitMetadataRoot(entry.path));
|
|
422
|
+
const excludedRoots = [...new Set([...excluded, ...currentGitRoots])];
|
|
423
|
+
const roots = excludedRoots.filter((path, index) => !excludedRoots.some((parent, parentIndex) => parentIndex !== index && path.startsWith(`${parent}/`)));
|
|
424
|
+
for (const path of roots.sort((left, right) => right.length - left.length)) {
|
|
425
|
+
abortSignal?.throwIfAborted();
|
|
426
|
+
await removeHostPath(host, root, toHostPath(root, path), true, abortSignal);
|
|
427
|
+
}
|
|
428
|
+
const entries = Object.entries(state.snapshot.entries).sort(([left], [right]) => left.split("/").length - right.split("/").length);
|
|
429
|
+
for (const [path, entry] of entries) {
|
|
430
|
+
abortSignal?.throwIfAborted();
|
|
431
|
+
const target = toHostPath(root, path);
|
|
432
|
+
await removeHostSymlinkAncestors(host, root, target, abortSignal);
|
|
433
|
+
if (entry.type === "directory") {
|
|
434
|
+
await host.files.mkdir(target, {
|
|
435
|
+
recursive: true,
|
|
436
|
+
signal: abortSignal
|
|
437
|
+
});
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
const content = state.contents.get(path);
|
|
441
|
+
if (content === void 0) continue;
|
|
442
|
+
await ensureHostParent(host, target, abortSignal);
|
|
443
|
+
if (entry.metadata?.gitMode === "120000") await writeHostSymlink(host, root, target, String(content), abortSignal);
|
|
444
|
+
else {
|
|
445
|
+
await host.files.write(target, contentToBytes(content), { signal: abortSignal });
|
|
446
|
+
if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target, abortSignal);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
async function restoreAttachedHost(host, root, diff, state, abortSignal) {
|
|
451
|
+
const changed = [...new Set(diff.entries.map((entry) => entry.path))];
|
|
452
|
+
for (const path of changed.sort((left, right) => right.length - left.length)) {
|
|
453
|
+
abortSignal?.throwIfAborted();
|
|
454
|
+
await removeHostPath(host, root, toHostPath(root, path), true, abortSignal);
|
|
455
|
+
}
|
|
456
|
+
const baselineEntries = changed.map((path) => [path, state.snapshot.entries[path]]).filter((entry) => Boolean(entry[1])).sort(([left], [right]) => left.split("/").length - right.split("/").length);
|
|
457
|
+
for (const [path, entry] of baselineEntries) {
|
|
458
|
+
abortSignal?.throwIfAborted();
|
|
459
|
+
const target = toHostPath(root, path);
|
|
460
|
+
await removeHostSymlinkAncestors(host, root, target, abortSignal);
|
|
461
|
+
if (entry.type === "directory") {
|
|
462
|
+
await host.files.mkdir(target, {
|
|
463
|
+
recursive: true,
|
|
464
|
+
signal: abortSignal
|
|
465
|
+
});
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
const content = state.contents.get(path);
|
|
469
|
+
if (content === void 0) continue;
|
|
470
|
+
await ensureHostParent(host, target, abortSignal);
|
|
471
|
+
if (entry.metadata?.gitMode === "120000") await writeHostSymlink(host, root, target, String(content), abortSignal);
|
|
472
|
+
else {
|
|
473
|
+
await host.files.write(target, contentToBytes(content), { signal: abortSignal });
|
|
474
|
+
if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target, abortSignal);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
async function resetHostWorkspaceRoot(host, root, abortSignal) {
|
|
479
|
+
if (await ensureHostWorkspaceRoot(host, root, abortSignal)) return;
|
|
480
|
+
for (const entry of await inspectHost(host, async () => await host.files.list(root, { signal: abortSignal }), abortSignal)) {
|
|
481
|
+
abortSignal?.throwIfAborted();
|
|
482
|
+
await removeHostPath(host, root, entry.path, true, abortSignal);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function isExcludedWriteBackPath(path, excluded) {
|
|
486
|
+
return Boolean(gitMetadataRoot(path)) || excluded.some((item) => path === item || path.startsWith(`${item}/`) || item.startsWith(`${path}/`));
|
|
487
|
+
}
|
|
488
|
+
const defaultExcludedSessionPaths = [
|
|
489
|
+
".agent-runs",
|
|
490
|
+
".git",
|
|
491
|
+
".vitehub"
|
|
492
|
+
];
|
|
493
|
+
function isExcludedSessionSourcePath(path) {
|
|
494
|
+
if (path === ".vitehub/sources" || path.startsWith(".vitehub/sources/")) return false;
|
|
495
|
+
return isExcludedWriteBackPath(path, defaultExcludedSessionPaths);
|
|
496
|
+
}
|
|
497
|
+
function filterWriteBackDiff(diff, excluded) {
|
|
498
|
+
return {
|
|
499
|
+
...diff,
|
|
500
|
+
entries: diff.entries.filter((entry) => !isExcludedWriteBackPath(entry.path, excluded))
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function normalizeSessionPaths(options) {
|
|
504
|
+
if (options?.paths === void 0) return void 0;
|
|
505
|
+
const paths = [...new Set(options.paths.map((path) => normalizeSafeWorkspacePath(path, {
|
|
506
|
+
allowEmpty: true,
|
|
507
|
+
allowReserved: true
|
|
508
|
+
})))];
|
|
509
|
+
if (paths.includes("")) return void 0;
|
|
510
|
+
return paths.sort((left, right) => left.length - right.length || left.localeCompare(right));
|
|
511
|
+
}
|
|
512
|
+
async function sessionEntries(workspace, options) {
|
|
513
|
+
const paths = normalizeSessionPaths(options);
|
|
514
|
+
const entries = /* @__PURE__ */ new Map();
|
|
515
|
+
const directories = paths ? [] : [""];
|
|
516
|
+
if (paths) for (const path of paths) {
|
|
517
|
+
const excluded = isExcludedSessionSourcePath(path);
|
|
518
|
+
if (excluded && path !== ".vitehub") continue;
|
|
519
|
+
const stat = await workspace.stat(path).catch((error) => {
|
|
520
|
+
if (isMissingWorkspacePathError(error)) return void 0;
|
|
521
|
+
throw error;
|
|
522
|
+
});
|
|
523
|
+
if (!stat) continue;
|
|
524
|
+
if (!excluded) entries.set(stat.path, stat);
|
|
525
|
+
if (stat.type === "directory") directories.push(stat.path);
|
|
526
|
+
}
|
|
527
|
+
const visited = /* @__PURE__ */ new Set();
|
|
528
|
+
for (let index = 0; index < directories.length; index++) {
|
|
529
|
+
const directory = directories[index];
|
|
530
|
+
if (visited.has(directory)) continue;
|
|
531
|
+
visited.add(directory);
|
|
532
|
+
for (const entry of await workspace.list(directory)) {
|
|
533
|
+
const excluded = isExcludedSessionSourcePath(entry.path);
|
|
534
|
+
if (!excluded) entries.set(entry.path, entry);
|
|
535
|
+
if (entry.type === "directory" && (!excluded || entry.path === ".vitehub")) directories.push(entry.path);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
539
|
+
}
|
|
540
|
+
async function extractRevisionArchive(host, root, materialization, signal) {
|
|
541
|
+
const stagingRoot = posix.join(root, `.vitehub-workspace-${randomUUID()}`);
|
|
542
|
+
const archive = posix.join(stagingRoot, "revision.tar.gz");
|
|
543
|
+
const staging = posix.join(stagingRoot, "extracted");
|
|
544
|
+
await host.files.mkdir(stagingRoot, {
|
|
545
|
+
recursive: true,
|
|
546
|
+
signal
|
|
547
|
+
});
|
|
548
|
+
await host.files.write(archive, materialization.archive, { signal });
|
|
549
|
+
await host.files.mkdir(staging, {
|
|
550
|
+
recursive: true,
|
|
551
|
+
signal
|
|
552
|
+
});
|
|
553
|
+
try {
|
|
554
|
+
const listed = await inspectHost(host, async () => await host.exec("tar", ["-tzf", archive], { signal }), signal);
|
|
555
|
+
if (listed.code !== 0) throw workspaceError(`[vitehub] Failed to inspect Workspace revision ${materialization.revision}: ${listed.stderr || "tar failed"}`);
|
|
556
|
+
const unsafeMember = listed.stdout.split("\n").filter(Boolean).find((member) => {
|
|
557
|
+
if (member.startsWith("/") || member.includes("\0")) return true;
|
|
558
|
+
return member.replace(/\/+$/, "").split("/").includes("..");
|
|
559
|
+
});
|
|
560
|
+
if (unsafeMember) throw workspaceError(`[vitehub] Workspace revision archive contains an unsafe path: ${unsafeMember}.`);
|
|
561
|
+
const extracted = await host.exec("tar", [
|
|
562
|
+
"-xzf",
|
|
563
|
+
archive,
|
|
564
|
+
"-C",
|
|
565
|
+
staging
|
|
566
|
+
], { signal });
|
|
567
|
+
if (extracted.code !== 0) throw workspaceError(`[vitehub] Failed to extract Workspace revision ${materialization.revision}: ${extracted.stderr || "tar failed"}`);
|
|
568
|
+
const roots = (await inspectHost(host, async () => await host.files.list(staging, { signal }), signal)).filter((entry) => entry.type === "directory");
|
|
569
|
+
if (roots.length !== 1) throw workspaceError(`[vitehub] Workspace revision archive must contain one repository root.`);
|
|
570
|
+
const archiveRoot = normalizeSafeWorkspacePath(materialization.root, {
|
|
571
|
+
allowEmpty: true,
|
|
572
|
+
allowReserved: true
|
|
573
|
+
});
|
|
574
|
+
let source = roots[0].path;
|
|
575
|
+
let validSource = true;
|
|
576
|
+
for (const component of archiveRoot.split("/").filter(Boolean)) {
|
|
577
|
+
source = posix.join(source, component);
|
|
578
|
+
if ((await inspectHost(host, async () => await host.exec("test", ["-L", source], { signal }), signal)).code === 0) throw workspaceError(`[vitehub] Workspace revision archive root must not contain symlinks: ${materialization.root}.`);
|
|
579
|
+
if ((await inspectHost(host, async () => await host.exec("test", ["-d", source], { signal }), signal)).code !== 0) {
|
|
580
|
+
validSource = false;
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (!validSource && materialization.files > 0) throw workspaceError(`[vitehub] Workspace revision archive is missing ${materialization.root || "its repository root"}.`);
|
|
585
|
+
if (!validSource) return;
|
|
586
|
+
const paths = materialization.paths;
|
|
587
|
+
if (!paths) {
|
|
588
|
+
const copied = await host.exec("cp", [
|
|
589
|
+
"-a",
|
|
590
|
+
`${source}/.`,
|
|
591
|
+
root
|
|
592
|
+
], { signal });
|
|
593
|
+
if (copied.code !== 0) throw workspaceError(`[vitehub] Failed to materialize Workspace revision ${materialization.revision}: ${copied.stderr || "copy failed"}`);
|
|
594
|
+
} else for (const path of paths) {
|
|
595
|
+
const selected = posix.join(source, path);
|
|
596
|
+
if (!await inspectHost(host, async () => await host.files.exists(selected, { signal }), signal)) continue;
|
|
597
|
+
const destination = toHostPath(root, posix.dirname(path) === "." ? "" : posix.dirname(path));
|
|
598
|
+
await host.files.mkdir(destination, {
|
|
599
|
+
recursive: true,
|
|
600
|
+
signal
|
|
601
|
+
});
|
|
602
|
+
const copied = await host.exec("cp", [
|
|
603
|
+
"-a",
|
|
604
|
+
selected,
|
|
605
|
+
destination
|
|
606
|
+
], { signal });
|
|
607
|
+
if (copied.code !== 0) throw workspaceError(`[vitehub] Failed to materialize Workspace revision ${materialization.revision}: ${copied.stderr || "copy failed"}`);
|
|
608
|
+
}
|
|
609
|
+
} finally {
|
|
610
|
+
await removeHostPath(host, root, stagingRoot, true, signal);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
async function sanitizeHostSymlinks(host, root, abortSignal) {
|
|
614
|
+
const symlinks = (await listHostEntries(host, root, "", true, void 0, false, [], abortSignal)).filter(isGitSymlinkEntry);
|
|
615
|
+
for (const entry of symlinks) {
|
|
616
|
+
abortSignal?.throwIfAborted();
|
|
617
|
+
const path = toHostPath(root, entry.path);
|
|
618
|
+
const target = await readHostSymlinkTarget(host, root, path, abortSignal);
|
|
619
|
+
if (isSafeHostSymlink(root, entry.path, target)) continue;
|
|
620
|
+
await host.files.remove(path, {
|
|
621
|
+
recursive: false,
|
|
622
|
+
signal: abortSignal
|
|
623
|
+
});
|
|
624
|
+
await host.files.write(path, contentToBytes(target), { signal: abortSignal });
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
async function materializeWorkspace(workspace, host, root, options, useRevisionMaterializer = true, onHostMutation, captureSnapshot = true) {
|
|
628
|
+
const abortSignal = options?.abortSignal;
|
|
629
|
+
abortSignal?.throwIfAborted();
|
|
630
|
+
const paths = normalizeSessionPaths(options);
|
|
631
|
+
const materializer = useRevisionMaterializer ? resolveWorkspaceRevisionMaterializer(workspace) : void 0;
|
|
632
|
+
const revision = materializer ? await withWorkspaceProgress(options?.onProgress, {
|
|
633
|
+
data: { paths: paths ?? null },
|
|
634
|
+
id: "workspace.prepare.revision",
|
|
635
|
+
label: "Resolving workspace revision"
|
|
636
|
+
}, async () => await materializer.materializeRevision({
|
|
637
|
+
abortSignal: options?.abortSignal,
|
|
638
|
+
paths
|
|
639
|
+
})) : void 0;
|
|
640
|
+
await withWorkspaceProgress(options?.onProgress, {
|
|
641
|
+
id: "workspace.prepare.reset-sandbox",
|
|
642
|
+
label: "Resetting sandbox workspace"
|
|
643
|
+
}, async () => {
|
|
644
|
+
onHostMutation?.();
|
|
645
|
+
await resetHostWorkspaceRoot(host, root, abortSignal);
|
|
646
|
+
});
|
|
647
|
+
abortSignal?.throwIfAborted();
|
|
648
|
+
if (revision?.archive) {
|
|
649
|
+
await withWorkspaceProgress(options?.onProgress, {
|
|
650
|
+
data: {
|
|
651
|
+
bytes: revision.archive.byteLength,
|
|
652
|
+
files: revision.files,
|
|
653
|
+
revision: revision.revision
|
|
654
|
+
},
|
|
655
|
+
id: "workspace.prepare.extract-archive",
|
|
656
|
+
label: "Extracting workspace revision"
|
|
657
|
+
}, async () => await extractRevisionArchive(host, root, {
|
|
658
|
+
...revision,
|
|
659
|
+
archive: revision.archive
|
|
660
|
+
}, options?.abortSignal));
|
|
661
|
+
abortSignal?.throwIfAborted();
|
|
662
|
+
await Promise.all(defaultExcludedSessionPaths.map((path) => removeHostPath(host, root, toHostPath(root, path), true, abortSignal)));
|
|
663
|
+
await removeHostGitMetadata(host, root, abortSignal);
|
|
664
|
+
abortSignal?.throwIfAborted();
|
|
665
|
+
await sanitizeHostSymlinks(host, root, abortSignal);
|
|
666
|
+
abortSignal?.throwIfAborted();
|
|
667
|
+
const snapshot = captureSnapshot ? options?.writeBack === false ? await createSnapshotFromEntries(await listHostEntries(host, root, "", true, void 0, false, [], abortSignal), "host-open") : await snapshotHost(host, root, "host-open", abortSignal) : void 0;
|
|
668
|
+
abortSignal?.throwIfAborted();
|
|
669
|
+
return {
|
|
670
|
+
revision: revision.revision,
|
|
671
|
+
snapshot
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
const entries = await withWorkspaceProgress(options?.onProgress, {
|
|
675
|
+
data: { paths: paths ?? null },
|
|
676
|
+
id: "workspace.prepare.entries",
|
|
677
|
+
label: "Resolving workspace entries"
|
|
678
|
+
}, async () => await sessionEntries(workspace, options));
|
|
679
|
+
const symlinks = new Set(entries.filter(isGitSymlinkEntry).map((entry) => entry.path));
|
|
680
|
+
const nested = entries.find((entry) => hasSymlinkParent(entry.path, symlinks));
|
|
681
|
+
if (nested) throw workspaceError(`[vitehub] Workspace path crosses a symlink parent: ${nested.path}.`);
|
|
682
|
+
for (const entry of entries.filter((entry) => entry.type === "directory")) {
|
|
683
|
+
abortSignal?.throwIfAborted();
|
|
684
|
+
await host.files.mkdir(toHostPath(root, entry.path), {
|
|
685
|
+
recursive: true,
|
|
686
|
+
signal: abortSignal
|
|
687
|
+
});
|
|
688
|
+
abortSignal?.throwIfAborted();
|
|
689
|
+
}
|
|
690
|
+
await withWorkspaceProgress(options?.onProgress, {
|
|
691
|
+
data: {
|
|
692
|
+
bytes: entries.reduce((total, entry) => total + (entry.size || 0), 0),
|
|
693
|
+
files: entries.filter((entry) => entry.type === "file").length
|
|
694
|
+
},
|
|
695
|
+
id: "workspace.prepare.read-files",
|
|
696
|
+
label: "Reading workspace files"
|
|
697
|
+
}, async () => {
|
|
698
|
+
abortSignal?.throwIfAborted();
|
|
699
|
+
for (const entry of entries) {
|
|
700
|
+
abortSignal?.throwIfAborted();
|
|
701
|
+
if (entry.type !== "file") continue;
|
|
702
|
+
const target = toHostPath(root, entry.path);
|
|
703
|
+
await ensureHostParent(host, target, abortSignal);
|
|
704
|
+
if (isGitSymlinkEntry(entry)) {
|
|
705
|
+
const symlinkTarget = typeof entry.metadata?.symlinkTarget === "string" ? entry.metadata.symlinkTarget : new TextDecoder().decode(contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })));
|
|
706
|
+
if (isSafeHostSymlink(root, entry.path, symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget, abortSignal);
|
|
707
|
+
else await host.files.write(target, contentToBytes(symlinkTarget), { signal: abortSignal });
|
|
708
|
+
} else {
|
|
709
|
+
await host.files.write(target, contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })), { signal: abortSignal });
|
|
710
|
+
if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target, abortSignal);
|
|
711
|
+
}
|
|
712
|
+
abortSignal?.throwIfAborted();
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
if (revision && await materializer?.currentRevision({ abortSignal: options?.abortSignal }) !== revision.revision) throw workspaceConflict(`[vitehub] Workspace revision changed while this Session materialized: ${revision.revision}.`);
|
|
716
|
+
const snapshot = options?.writeBack === false ? await createSnapshotFromEntries(entries, "host-open") : await snapshotHost(host, root, "host-open", abortSignal);
|
|
717
|
+
return {
|
|
718
|
+
revision: revision?.revision,
|
|
719
|
+
snapshot
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
async function commitHostChanges(workspace, diff, contents, mediaTypes, message) {
|
|
723
|
+
for (const entry of diff.entries) {
|
|
724
|
+
if (entry.after?.type === "directory") {
|
|
725
|
+
if (entry.before?.type === "file") await workspace.rm(entry.path, { force: true });
|
|
726
|
+
await workspace.mkdir(entry.path, { recursive: true });
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
if (entry.type === "removed") {
|
|
730
|
+
await workspace.rm(entry.path, {
|
|
731
|
+
force: true,
|
|
732
|
+
recursive: true
|
|
733
|
+
});
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
if (entry.after?.type !== "file") continue;
|
|
737
|
+
if (entry.before?.type === "directory") await workspace.rm(entry.path, {
|
|
738
|
+
force: true,
|
|
739
|
+
recursive: true
|
|
740
|
+
});
|
|
741
|
+
const before = entry.before?.type === "file" ? await workspace.stat(entry.path).catch(() => void 0) : void 0;
|
|
742
|
+
const content = contents.get(entry.path);
|
|
743
|
+
if (content !== void 0) await workspace.writeFile(entry.path, content, {
|
|
744
|
+
mediaType: mediaTypes.get(entry.path) || before?.mediaType,
|
|
745
|
+
metadata: entry.after.metadata
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
return await workspace.snapshot({ name: message || "host-commit" });
|
|
749
|
+
}
|
|
750
|
+
async function createHostedWorkspaceSession(workspace, options) {
|
|
751
|
+
const host = options.host;
|
|
752
|
+
let executionAuthority;
|
|
753
|
+
try {
|
|
754
|
+
executionAuthority = normalizeExecutionAuthority(host.executionAuthority);
|
|
755
|
+
} catch {
|
|
756
|
+
throw new TypeError("[vitehub] Workspace session host must declare executionAuthority.");
|
|
757
|
+
}
|
|
758
|
+
resolveHostInspectionConcurrency(host);
|
|
759
|
+
const root = normalizeTarget(options.target);
|
|
760
|
+
const sessionPaths = normalizeSessionPaths(options);
|
|
761
|
+
const excludedWriteBackPaths = [...defaultExcludedSessionPaths, ...(options.writeBack && options.writeBack.exclude || []).map((path) => normalizeSafeWorkspacePath(path, { allowReserved: true }))];
|
|
762
|
+
let closed = false;
|
|
763
|
+
const existingExcludedState = await captureExcludedHostState(host, root, excludedWriteBackPaths, options.abortSignal);
|
|
764
|
+
let attachedState = options.attach ? await captureHostState(host, root, "host-attach", options.abortSignal) : void 0;
|
|
765
|
+
let materialization;
|
|
766
|
+
let materializedExcludedState;
|
|
767
|
+
let setupMutatedHost = false;
|
|
768
|
+
try {
|
|
769
|
+
materialization = attachedState ? { snapshot: attachedState.snapshot } : await materializeWorkspace(workspace, host, root, options, true, () => {
|
|
770
|
+
setupMutatedHost = true;
|
|
771
|
+
});
|
|
772
|
+
if (!attachedState) materializedExcludedState = await captureExcludedHostState(host, root, excludedWriteBackPaths, options.abortSignal);
|
|
773
|
+
} catch (error) {
|
|
774
|
+
if (attachedState || !setupMutatedHost) throw error;
|
|
775
|
+
try {
|
|
776
|
+
host.detachAbortSignal?.();
|
|
777
|
+
await materializeWorkspace(workspace, host, root, {
|
|
778
|
+
...options,
|
|
779
|
+
abortSignal: void 0,
|
|
780
|
+
onProgress: void 0
|
|
781
|
+
}, false);
|
|
782
|
+
await restoreExcludedHostState(host, root, excludedWriteBackPaths, existingExcludedState);
|
|
783
|
+
} catch (restoreError) {
|
|
784
|
+
throw new AggregateError([error, restoreError], "[vitehub] Workspace Session setup and excluded-state restoration failed.");
|
|
785
|
+
}
|
|
786
|
+
throw error;
|
|
787
|
+
}
|
|
788
|
+
let baseline = materialization.snapshot;
|
|
789
|
+
let baseRevision = materialization.revision;
|
|
790
|
+
const excludedState = attachedState ? existingExcludedState : mergeExcludedHostState(existingExcludedState, materializedExcludedState, excludedWriteBackPaths);
|
|
791
|
+
const mediaTypes = /* @__PURE__ */ new Map();
|
|
792
|
+
function assertOpen() {
|
|
793
|
+
if (closed) throw workspaceError("[vitehub] Workspace host session is already closed.");
|
|
794
|
+
}
|
|
795
|
+
async function currentDiff(abortSignal) {
|
|
796
|
+
assertOpen();
|
|
797
|
+
return filterWriteBackDiff(diffSnapshots(baseline, await snapshotHost(host, root, "host-diff", abortSignal)), excludedWriteBackPaths);
|
|
798
|
+
}
|
|
799
|
+
return {
|
|
800
|
+
executionAuthority,
|
|
801
|
+
async readFile(path, readOptions) {
|
|
802
|
+
assertOpen();
|
|
803
|
+
const file = await readHostFile(host, root, toHostPath(root, assertPathInSessionScope(normalizeReadableSessionPath(path), sessionPaths, { masked: true })));
|
|
804
|
+
if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
805
|
+
return decodeFile(file.content, readOptions);
|
|
806
|
+
},
|
|
807
|
+
async writeFile(path, content, writeOptions) {
|
|
808
|
+
assertOpen();
|
|
809
|
+
const target = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths));
|
|
810
|
+
await assertNoHostSymlinkParent(host, root, target);
|
|
811
|
+
await ensureHostParent(host, target);
|
|
812
|
+
await removeHostPath(host, root, target, true);
|
|
813
|
+
const symlinkTarget = writeOptions?.metadata?.gitMode === "120000" ? new TextDecoder().decode(contentToBytes(content)) : void 0;
|
|
814
|
+
if (symlinkTarget !== void 0 && isSafeHostSymlink(root, fromHostPath(root, target), symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget);
|
|
815
|
+
else {
|
|
816
|
+
await host.files.write(target, contentToBytes(content));
|
|
817
|
+
const workspacePath = fromHostPath(root, target);
|
|
818
|
+
if (writeOptions?.metadata?.gitMode === "100755" || baseline.entries[workspacePath]?.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
|
|
819
|
+
}
|
|
820
|
+
const workspacePath = fromHostPath(root, target);
|
|
821
|
+
if (writeOptions?.mediaType) mediaTypes.set(workspacePath, writeOptions.mediaType);
|
|
822
|
+
else mediaTypes.delete(workspacePath);
|
|
823
|
+
},
|
|
824
|
+
async mkdir(path, mkdirOptions = {}) {
|
|
825
|
+
assertOpen();
|
|
826
|
+
const hostTarget = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path, { allowEmpty: true }), sessionPaths, { mkdir: true }));
|
|
827
|
+
await assertNoHostSymlinkParent(host, root, hostTarget);
|
|
828
|
+
await host.files.mkdir(hostTarget, { recursive: mkdirOptions.recursive });
|
|
829
|
+
},
|
|
830
|
+
async rm(path, rmOptions) {
|
|
831
|
+
assertOpen();
|
|
832
|
+
const workspacePath = assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths);
|
|
833
|
+
const target = toHostPath(root, workspacePath);
|
|
834
|
+
await assertNoHostSymlinkParent(host, root, target);
|
|
835
|
+
await removeHostPath(host, root, target, Boolean(rmOptions?.recursive));
|
|
836
|
+
mediaTypes.delete(normalizeWorkspacePath(workspacePath));
|
|
837
|
+
},
|
|
838
|
+
async list(path = "", listOptions = {}) {
|
|
839
|
+
assertOpen();
|
|
840
|
+
return filterSessionEntries(await listHostEntries(host, root, path, listOptions.recursive, void 0, false, listOptions.exclude), sessionPaths);
|
|
841
|
+
},
|
|
842
|
+
async glob(pattern, globOptions) {
|
|
843
|
+
assertOpen();
|
|
844
|
+
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
845
|
+
const cwd = normalizeSearchRoot(globOptions?.cwd || "");
|
|
846
|
+
const { matchesAny } = await import("./path-Cp59koVz.js").then((n) => n.u);
|
|
847
|
+
return filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((entry) => {
|
|
848
|
+
if (entry.type !== "file") return false;
|
|
849
|
+
if (!cwd) return patterns.some((item) => matchesAny(entry.path, item));
|
|
850
|
+
if (!entry.path.startsWith(`${cwd}/`)) return false;
|
|
851
|
+
const relative = entry.path.slice(cwd.length + 1);
|
|
852
|
+
return patterns.some((item) => matchesAny(relative, item));
|
|
853
|
+
});
|
|
854
|
+
},
|
|
855
|
+
async search(query) {
|
|
856
|
+
assertOpen();
|
|
857
|
+
const { searchText } = await import("./search-BpiCF2Tw.js").then((n) => n.n);
|
|
858
|
+
const scoped = scopedSearchQuery(query, sessionPaths, normalizeSearchRoot);
|
|
859
|
+
if (!scoped) return [];
|
|
860
|
+
const scopedSearchRoots = [...new Set((scoped.paths?.length ? scoped.paths : [scoped.cwd || ""]).map(normalizeSearchRoot))].filter(Boolean);
|
|
861
|
+
const limit = scoped.limit ?? 100;
|
|
862
|
+
const hits = [];
|
|
863
|
+
for (const entry of filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((item) => item.type === "file")) {
|
|
864
|
+
if (scopedSearchRoots.length && !scopedSearchRoots.some((path) => entry.path === path || entry.path.startsWith(`${path}/`))) continue;
|
|
865
|
+
const content = await inspectHost(host, async () => await host.files.read(toHostPath(root, entry.path)));
|
|
866
|
+
if (content === null) continue;
|
|
867
|
+
const text = new TextDecoder().decode(content);
|
|
868
|
+
hits.push(...searchText(entry.path, text, {
|
|
869
|
+
...scoped,
|
|
870
|
+
limit: limit - hits.length
|
|
871
|
+
}));
|
|
872
|
+
if (hits.length >= limit) break;
|
|
873
|
+
}
|
|
874
|
+
return hits;
|
|
875
|
+
},
|
|
876
|
+
async diff(diffOptions) {
|
|
877
|
+
if (options.writeBack === false) throw workspaceError("[vitehub] Workspace Session diff is unavailable when writeBack is false.");
|
|
878
|
+
return filterSessionDiff(await currentDiff(diffOptions?.abortSignal), sessionPaths);
|
|
879
|
+
},
|
|
880
|
+
async commit(commitOptions) {
|
|
881
|
+
assertOpen();
|
|
882
|
+
if (options.writeBack === false) throw workspaceError("[vitehub] Workspace Session commit is unavailable when writeBack is false.");
|
|
883
|
+
const abortSignal = commitOptions?.abortSignal ?? options.abortSignal;
|
|
884
|
+
abortSignal?.throwIfAborted();
|
|
885
|
+
const capturedState = await captureHostState(host, root, commitOptions?.message || "host-commit", abortSignal);
|
|
886
|
+
const diff = filterWriteBackDiff(diffSnapshots(baseline, capturedState.snapshot), excludedWriteBackPaths);
|
|
887
|
+
if (!diff.entries.length) return;
|
|
888
|
+
assertDiffInsideSessionPaths(diff, sessionPaths);
|
|
889
|
+
const publicationDiff = {
|
|
890
|
+
...diff,
|
|
891
|
+
entries: diff.entries.map((entry) => {
|
|
892
|
+
const content = capturedState.contents.get(entry.path);
|
|
893
|
+
if (entry.after?.metadata?.gitMode !== "120000" || content === void 0 || isSafeHostSymlink(root, entry.path, String(content))) return entry;
|
|
894
|
+
return {
|
|
895
|
+
...entry,
|
|
896
|
+
after: {
|
|
897
|
+
...entry.after,
|
|
898
|
+
metadata: void 0
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
})
|
|
902
|
+
};
|
|
903
|
+
const sanitizedPaths = publicationDiff.entries.filter((entry, index) => entry.after?.metadata?.gitMode !== diff.entries[index]?.after?.metadata?.gitMode);
|
|
904
|
+
const sanitizedPathNames = new Set(sanitizedPaths.map((entry) => entry.path));
|
|
905
|
+
const sanitizedCapturedSnapshot = sanitizedPaths.length ? await createSnapshotFromEntries(Object.entries(capturedState.snapshot.entries).map(([path, entry]) => ({
|
|
906
|
+
path,
|
|
907
|
+
...entry,
|
|
908
|
+
...sanitizedPathNames.has(path) ? { metadata: void 0 } : {}
|
|
909
|
+
})), commitOptions?.message || "host-commit") : capturedState.snapshot;
|
|
910
|
+
const revisionMaterializer = resolveWorkspaceRevisionMaterializer(workspace);
|
|
911
|
+
await withWorkspacePublication(revisionMaterializer || workspace, abortSignal, async () => {
|
|
912
|
+
abortSignal?.throwIfAborted();
|
|
913
|
+
if (baseRevision && await revisionMaterializer?.currentRevision({ abortSignal }) !== baseRevision) throw workspaceConflict(`[vitehub] Workspace revision changed after this Session materialized: ${baseRevision}.`);
|
|
914
|
+
const nextAttachedState = options.attach ? {
|
|
915
|
+
...capturedState,
|
|
916
|
+
snapshot: sanitizedCapturedSnapshot
|
|
917
|
+
} : void 0;
|
|
918
|
+
const nextBaseline = nextAttachedState?.snapshot || await createSnapshotFromEntries(Object.entries(baseline.entries).filter(([path]) => !publicationDiff.entries.some((entry) => entry.path === path && !entry.after)).map(([path, entry]) => {
|
|
919
|
+
return {
|
|
920
|
+
path,
|
|
921
|
+
...publicationDiff.entries.find((item) => item.path === path)?.after || entry
|
|
922
|
+
};
|
|
923
|
+
}).concat(publicationDiff.entries.filter((entry) => entry.after && !baseline.entries[entry.path]).map((entry) => ({
|
|
924
|
+
path: entry.path,
|
|
925
|
+
...entry.after
|
|
926
|
+
}))), commitOptions?.message || "host-commit");
|
|
927
|
+
for (const entry of sanitizedPaths) {
|
|
928
|
+
abortSignal?.throwIfAborted();
|
|
929
|
+
const content = capturedState.contents.get(entry.path);
|
|
930
|
+
if (content === void 0) continue;
|
|
931
|
+
const target = toHostPath(root, entry.path);
|
|
932
|
+
await removeHostPath(host, root, target, false);
|
|
933
|
+
await host.files.write(target, contentToBytes(content));
|
|
934
|
+
}
|
|
935
|
+
try {
|
|
936
|
+
await commitHostChanges(workspace, publicationDiff, capturedState.contents, mediaTypes, commitOptions?.message);
|
|
937
|
+
} catch (error) {
|
|
938
|
+
if (baseRevision) try {
|
|
939
|
+
await workspace.rebase({ takeRemote: diff.entries.map((entry) => entry.path) });
|
|
940
|
+
} catch (rollbackError) {
|
|
941
|
+
throw new AggregateError([error, rollbackError], "[vitehub] Workspace publication and rollback failed.");
|
|
942
|
+
}
|
|
943
|
+
throw error;
|
|
944
|
+
}
|
|
945
|
+
if (baseRevision) baseRevision = await revisionMaterializer.currentRevision({ refresh: false });
|
|
946
|
+
if (nextAttachedState) attachedState = nextAttachedState;
|
|
947
|
+
baseline = nextBaseline;
|
|
948
|
+
});
|
|
949
|
+
},
|
|
950
|
+
async exec(command, args = [], execOptions = {}) {
|
|
951
|
+
assertOpen();
|
|
952
|
+
const result = await host.exec(command, args, {
|
|
953
|
+
cwd: toHostCwd(root, execOptions.cwd),
|
|
954
|
+
env: execOptions.env,
|
|
955
|
+
signal: execOptions.abortSignal,
|
|
956
|
+
timeout: execOptions.timeout
|
|
957
|
+
});
|
|
958
|
+
return {
|
|
959
|
+
args,
|
|
960
|
+
command,
|
|
961
|
+
exitCode: result.code,
|
|
962
|
+
stderr: result.stderr,
|
|
963
|
+
stdout: result.stdout
|
|
964
|
+
};
|
|
965
|
+
},
|
|
966
|
+
async close(closeOptions) {
|
|
967
|
+
if (closed) return;
|
|
968
|
+
const abortSignal = closeOptions?.abortSignal;
|
|
969
|
+
abortSignal?.throwIfAborted();
|
|
970
|
+
host.detachAbortSignal?.();
|
|
971
|
+
await ensureHostWorkspaceRoot(host, root, abortSignal);
|
|
972
|
+
if (options.writeBack === false && !options.attach) {
|
|
973
|
+
await materializeWorkspace(workspace, host, root, {
|
|
974
|
+
...options,
|
|
975
|
+
abortSignal,
|
|
976
|
+
onProgress: void 0
|
|
977
|
+
}, true, void 0, false);
|
|
978
|
+
await restoreExcludedHostState(host, root, excludedWriteBackPaths, excludedState, abortSignal);
|
|
979
|
+
closed = true;
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
let diff;
|
|
983
|
+
let restoreError;
|
|
984
|
+
let revisionChanged = false;
|
|
985
|
+
if (options.attach && attachedState) {
|
|
986
|
+
const attachedDiff = filterSessionDiff(diffSnapshots(baseline, await snapshotHost(host, root, "host-close", abortSignal)), sessionPaths);
|
|
987
|
+
let attachedRestoreError;
|
|
988
|
+
try {
|
|
989
|
+
await restoreAttachedHost(host, root, attachedDiff, attachedState, abortSignal);
|
|
990
|
+
} catch (error) {
|
|
991
|
+
attachedRestoreError = error;
|
|
992
|
+
}
|
|
993
|
+
try {
|
|
994
|
+
await restoreExcludedHostState(host, root, excludedWriteBackPaths, excludedState, abortSignal);
|
|
995
|
+
} catch (excludedError) {
|
|
996
|
+
if (attachedRestoreError) throw new AggregateError([attachedRestoreError, excludedError], "[vitehub] Attached Workspace Session restoration and excluded-state restoration failed.");
|
|
997
|
+
throw excludedError;
|
|
998
|
+
}
|
|
999
|
+
if (attachedRestoreError) throw attachedRestoreError;
|
|
1000
|
+
} else try {
|
|
1001
|
+
diff = await currentDiff(abortSignal);
|
|
1002
|
+
const revisionMaterializer = resolveWorkspaceRevisionMaterializer(workspace);
|
|
1003
|
+
revisionChanged = Boolean(baseRevision && await revisionMaterializer?.currentRevision({ abortSignal }) !== baseRevision);
|
|
1004
|
+
} catch (error) {
|
|
1005
|
+
restoreError = error;
|
|
1006
|
+
}
|
|
1007
|
+
abortSignal?.throwIfAborted();
|
|
1008
|
+
try {
|
|
1009
|
+
if (!restoreError && (diff?.entries.length || revisionChanged)) await materializeWorkspace(workspace, host, root, {
|
|
1010
|
+
...options,
|
|
1011
|
+
abortSignal,
|
|
1012
|
+
onProgress: void 0
|
|
1013
|
+
});
|
|
1014
|
+
} catch (error) {
|
|
1015
|
+
restoreError = error;
|
|
1016
|
+
}
|
|
1017
|
+
abortSignal?.throwIfAborted();
|
|
1018
|
+
try {
|
|
1019
|
+
if (!options.attach) await restoreExcludedHostState(host, root, excludedWriteBackPaths, excludedState, abortSignal);
|
|
1020
|
+
} catch (excludedError) {
|
|
1021
|
+
if (restoreError) throw new AggregateError([restoreError, excludedError], "[vitehub] Workspace Session restoration and excluded-state restoration failed.");
|
|
1022
|
+
throw excludedError;
|
|
1023
|
+
}
|
|
1024
|
+
if (restoreError) throw restoreError;
|
|
1025
|
+
closed = true;
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
//#endregion
|
|
1030
|
+
export { host_exports as n, withWorkspaceProgress as r, createHostedWorkspaceSession as t };
|