@vite-hub/workspace 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +225 -58
- package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
- package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +57 -36
- package/dist/index.js +56 -56
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +4 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/path-CNAwN7pw.js +114 -0
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
- package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
- package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
- 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 +1 -2
- package/dist/runtime/state.d.ts +3 -3
- package/dist/runtime/state.js +6 -6
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +51 -17
- package/dist/runtime.js +320 -60
- package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -328
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +6 -7
- package/dist/source-metadata.js +7 -7
- package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
- package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
- package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
- package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
- package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
- package/package.json +89 -55
- 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/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/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { n as __exportAll } from "./
|
|
2
|
-
import {
|
|
3
|
-
import { a as
|
|
4
|
-
import {
|
|
1
|
+
import { n as __exportAll } from "./rolldown-runtime-B4iAMlE-.js";
|
|
2
|
+
import { a as workspaceConflict, s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
3
|
+
import { a as isExcludedWorkspacePath, f as sha256, i as decodeFile, l as normalizeWorkspacePath, r as contentToBytes } from "./path-CNAwN7pw.js";
|
|
4
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
|
|
5
|
+
import { n as createSnapshotFromEntries, r as diffSnapshots } from "./utils-Blrh4N2n.js";
|
|
6
|
+
import { r as resolveWorkspaceRevisionMaterializer } from "./store-CXgmu-uw.js";
|
|
7
|
+
import { _ as filterSessionDiff, b as scopedSearchQuery, g as assertPathInSessionScope, h as assertDiffInsideSessionPaths, v as filterSessionEntries, y as isMissingWorkspacePathError } from "./workspace-6pxkOuxr.js";
|
|
5
8
|
import { posix } from "node:path";
|
|
6
9
|
import { randomUUID } from "node:crypto";
|
|
7
10
|
import { normalizeExecutionAuthority } from "@vite-hub/runtime";
|
|
@@ -46,15 +49,61 @@ var host_exports = /* @__PURE__ */ __exportAll({ createHostedWorkspaceSession: (
|
|
|
46
49
|
const publicationQueues = /* @__PURE__ */ new WeakMap();
|
|
47
50
|
const defaultHostInspectionConcurrency = 16;
|
|
48
51
|
const hostInspectionLimiters = /* @__PURE__ */ new WeakMap();
|
|
52
|
+
const hostMaterializationLimiters = /* @__PURE__ */ new WeakMap();
|
|
49
53
|
function resolveHostInspectionConcurrency(host) {
|
|
50
54
|
const concurrency = host.inspectionConcurrency ?? defaultHostInspectionConcurrency;
|
|
51
55
|
if (!Number.isInteger(concurrency) || concurrency < 1) throw workspaceError("[vitehub] Workspace host inspectionConcurrency must be a positive integer.");
|
|
52
56
|
return concurrency;
|
|
53
57
|
}
|
|
58
|
+
function resolveHostMaterializationConcurrency(host) {
|
|
59
|
+
const concurrency = host.materializationConcurrency ?? 1;
|
|
60
|
+
if (!Number.isInteger(concurrency) || concurrency < 1) throw workspaceError("[vitehub] Workspace host materializationConcurrency must be a positive integer.");
|
|
61
|
+
return concurrency;
|
|
62
|
+
}
|
|
63
|
+
async function mapHostMaterialization(host, values, visit, signal) {
|
|
64
|
+
const concurrency = resolveHostMaterializationConcurrency(host);
|
|
65
|
+
let limit = hostMaterializationLimiters.get(host);
|
|
66
|
+
if (!limit) {
|
|
67
|
+
limit = createHostLimiter(concurrency);
|
|
68
|
+
hostMaterializationLimiters.set(host, limit);
|
|
69
|
+
}
|
|
70
|
+
let next = 0;
|
|
71
|
+
let failed = false;
|
|
72
|
+
let failure;
|
|
73
|
+
const workers = Array.from({ length: Math.min(values.length, concurrency) }, async () => {
|
|
74
|
+
while (!failed) {
|
|
75
|
+
signal?.throwIfAborted();
|
|
76
|
+
const index = next++;
|
|
77
|
+
if (index >= values.length) return;
|
|
78
|
+
try {
|
|
79
|
+
await limit(async () => {
|
|
80
|
+
if (failed) return;
|
|
81
|
+
signal?.throwIfAborted();
|
|
82
|
+
try {
|
|
83
|
+
await visit(values[index]);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (!failed) failure = error;
|
|
86
|
+
failed = true;
|
|
87
|
+
}
|
|
88
|
+
}, signal);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (!failed) failure = error;
|
|
91
|
+
failed = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
await Promise.allSettled(workers);
|
|
96
|
+
if (failed) throw failure;
|
|
97
|
+
signal?.throwIfAborted();
|
|
98
|
+
}
|
|
54
99
|
function resolveHostInspectionLimiter(host) {
|
|
55
100
|
const existing = hostInspectionLimiters.get(host);
|
|
56
101
|
if (existing) return existing;
|
|
57
|
-
const
|
|
102
|
+
const limit = createHostLimiter(resolveHostInspectionConcurrency(host));
|
|
103
|
+
hostInspectionLimiters.set(host, limit);
|
|
104
|
+
return limit;
|
|
105
|
+
}
|
|
106
|
+
function createHostLimiter(concurrency) {
|
|
58
107
|
let active = 0;
|
|
59
108
|
const queued = [];
|
|
60
109
|
const run = async (inspect, signal) => {
|
|
@@ -83,7 +132,6 @@ function resolveHostInspectionLimiter(host) {
|
|
|
83
132
|
queued.shift()?.grant();
|
|
84
133
|
}
|
|
85
134
|
};
|
|
86
|
-
hostInspectionLimiters.set(host, run);
|
|
87
135
|
return run;
|
|
88
136
|
}
|
|
89
137
|
function inspectHost(host, inspect, signal, batch) {
|
|
@@ -183,7 +231,7 @@ function toHostCwd(root, cwd) {
|
|
|
183
231
|
if (!posix.isAbsolute(cwd)) return toHostPath(root, cwd);
|
|
184
232
|
const normalized = posix.normalize(cwd);
|
|
185
233
|
if (normalized === root || normalized.startsWith(`${root}/`)) return normalized;
|
|
186
|
-
if (normalized === "/workspace" || normalized.startsWith("/workspace/")) return toHostPath(root, normalized.slice(
|
|
234
|
+
if (normalized === "/workspace" || normalized.startsWith("/workspace/")) return toHostPath(root, normalized === "/workspace" ? "" : normalized.slice(11));
|
|
187
235
|
throw workspaceError(`[vitehub] Workspace exec cwd must stay inside ${root}: ${cwd}.`);
|
|
188
236
|
}
|
|
189
237
|
function fromHostPath(root, path) {
|
|
@@ -277,7 +325,7 @@ async function readHostSymlinkTarget(host, root, path, abortSignal, batch) {
|
|
|
277
325
|
cwd: root,
|
|
278
326
|
signal: abortSignal
|
|
279
327
|
});
|
|
280
|
-
if (result.code !== 0) throw workspaceError(`[vitehub] Failed to read workspace symlink: ${path}.`, { cause:
|
|
328
|
+
if (result.code !== 0) throw workspaceError(`[vitehub] Failed to read workspace symlink: ${path}.`, { cause: workspaceErrorDiagnostics.WORKSPACE_R0044({ message: result.stderr || "readlink failed" }) });
|
|
281
329
|
return result.stdout.replace(/\n$/, "");
|
|
282
330
|
}, abortSignal, batch);
|
|
283
331
|
}
|
|
@@ -373,23 +421,24 @@ async function captureHostState(host, root, name, abortSignal) {
|
|
|
373
421
|
}
|
|
374
422
|
async function captureHostEntriesState(host, root, entries, name, abortSignal) {
|
|
375
423
|
const contents = /* @__PURE__ */ new Map();
|
|
424
|
+
const files = await mapHostInspections(host, entries, async (entry, batch) => {
|
|
425
|
+
abortSignal?.throwIfAborted();
|
|
426
|
+
if (entry.type !== "file") return entry;
|
|
427
|
+
const content = isGitSymlinkEntry(entry) ? await readHostSymlinkTarget(host, root, toHostPath(root, entry.path), abortSignal, batch) : await inspectHost(host, async () => {
|
|
428
|
+
const content = await host.files.read(toHostPath(root, entry.path), { signal: abortSignal });
|
|
429
|
+
if (content === null) throw workspaceError(`[vitehub] Workspace host file disappeared while snapshotting: ${entry.path}.`);
|
|
430
|
+
return content;
|
|
431
|
+
}, abortSignal, batch);
|
|
432
|
+
contents.set(entry.path, content);
|
|
433
|
+
return {
|
|
434
|
+
...entry,
|
|
435
|
+
digest: await sha256(content),
|
|
436
|
+
size: contentToBytes(content).byteLength
|
|
437
|
+
};
|
|
438
|
+
}, abortSignal);
|
|
376
439
|
return {
|
|
377
440
|
contents,
|
|
378
|
-
snapshot: await createSnapshotFromEntries(
|
|
379
|
-
abortSignal?.throwIfAborted();
|
|
380
|
-
if (entry.type !== "file") return entry;
|
|
381
|
-
const content = isGitSymlinkEntry(entry) ? await readHostSymlinkTarget(host, root, toHostPath(root, entry.path), abortSignal, batch) : await inspectHost(host, async () => {
|
|
382
|
-
const content = await host.files.read(toHostPath(root, entry.path), { signal: abortSignal });
|
|
383
|
-
if (content === null) throw workspaceError(`[vitehub] Workspace host file disappeared while snapshotting: ${entry.path}.`);
|
|
384
|
-
return content;
|
|
385
|
-
}, abortSignal, batch);
|
|
386
|
-
contents.set(entry.path, content);
|
|
387
|
-
return {
|
|
388
|
-
...entry,
|
|
389
|
-
digest: await sha256(content),
|
|
390
|
-
size: contentToBytes(content).byteLength
|
|
391
|
-
};
|
|
392
|
-
}, abortSignal), name)
|
|
441
|
+
snapshot: await createSnapshotFromEntries(files, name)
|
|
393
442
|
};
|
|
394
443
|
}
|
|
395
444
|
function isInsideExcludedWriteBackPath(path, excluded) {
|
|
@@ -403,11 +452,10 @@ async function captureExcludedHostState(host, root, excluded, abortSignal) {
|
|
|
403
452
|
}
|
|
404
453
|
function mergeExcludedHostState(before, materialized, excluded) {
|
|
405
454
|
const beforePaths = Object.keys(before.snapshot.entries);
|
|
406
|
-
const occupiedRoots = [
|
|
407
|
-
const entries = Object.fromEntries(Object.entries(materialized.snapshot.entries).filter(([path]) => !occupiedRoots.some((root) => path === root || path.startsWith(`${root}/`))));
|
|
455
|
+
const occupiedRoots = [.../* @__PURE__ */ new Set([...excluded.filter((root) => beforePaths.some((path) => path === root || path.startsWith(`${root}/`))), ...beforePaths.map(gitMetadataRoot).filter((path) => Boolean(path))])];
|
|
456
|
+
const entries = Object.fromEntries([...Object.entries(materialized.snapshot.entries).filter(([path]) => !occupiedRoots.some((root) => path === root || path.startsWith(`${root}/`))), ...Object.entries(before.snapshot.entries)]);
|
|
408
457
|
const contents = new Map(materialized.contents);
|
|
409
|
-
for (const root of occupiedRoots) for (const path of
|
|
410
|
-
for (const [path, entry] of Object.entries(before.snapshot.entries)) entries[path] = entry;
|
|
458
|
+
for (const root of occupiedRoots) for (const path of contents.keys()) if (path === root || path.startsWith(`${root}/`)) contents.delete(path);
|
|
411
459
|
for (const [path, content] of before.contents) contents.set(path, content);
|
|
412
460
|
return {
|
|
413
461
|
contents,
|
|
@@ -419,7 +467,7 @@ function mergeExcludedHostState(before, materialized, excluded) {
|
|
|
419
467
|
}
|
|
420
468
|
async function restoreExcludedHostState(host, root, excluded, state, abortSignal) {
|
|
421
469
|
const currentGitRoots = (await listHostEntries(host, root, "", true, (entry) => Boolean(gitMetadataRoot(entry.path)), true, [], abortSignal)).map((entry) => gitMetadataRoot(entry.path));
|
|
422
|
-
const excludedRoots = [
|
|
470
|
+
const excludedRoots = [.../* @__PURE__ */ new Set([...excluded, ...currentGitRoots])];
|
|
423
471
|
const roots = excludedRoots.filter((path, index) => !excludedRoots.some((parent, parentIndex) => parentIndex !== index && path.startsWith(`${parent}/`)));
|
|
424
472
|
for (const path of roots.sort((left, right) => right.length - left.length)) {
|
|
425
473
|
abortSignal?.throwIfAborted();
|
|
@@ -696,9 +744,8 @@ async function materializeWorkspace(workspace, host, root, options, useRevisionM
|
|
|
696
744
|
label: "Reading workspace files"
|
|
697
745
|
}, async () => {
|
|
698
746
|
abortSignal?.throwIfAborted();
|
|
699
|
-
|
|
747
|
+
await mapHostMaterialization(host, entries.filter((entry) => entry.type === "file"), async (entry) => {
|
|
700
748
|
abortSignal?.throwIfAborted();
|
|
701
|
-
if (entry.type !== "file") continue;
|
|
702
749
|
const target = toHostPath(root, entry.path);
|
|
703
750
|
await ensureHostParent(host, target, abortSignal);
|
|
704
751
|
if (isGitSymlinkEntry(entry)) {
|
|
@@ -706,14 +753,15 @@ async function materializeWorkspace(workspace, host, root, options, useRevisionM
|
|
|
706
753
|
if (isSafeHostSymlink(root, entry.path, symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget, abortSignal);
|
|
707
754
|
else await host.files.write(target, contentToBytes(symlinkTarget), { signal: abortSignal });
|
|
708
755
|
} else {
|
|
709
|
-
|
|
756
|
+
const content = contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" }));
|
|
757
|
+
await host.files.write(target, content, { signal: abortSignal });
|
|
710
758
|
if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target, abortSignal);
|
|
711
759
|
}
|
|
712
760
|
abortSignal?.throwIfAborted();
|
|
713
|
-
}
|
|
761
|
+
}, abortSignal);
|
|
714
762
|
});
|
|
715
763
|
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);
|
|
764
|
+
const snapshot = captureSnapshot ? options?.writeBack === false ? await createSnapshotFromEntries(entries, "host-open") : await snapshotHost(host, root, "host-open", abortSignal) : void 0;
|
|
717
765
|
return {
|
|
718
766
|
revision: revision?.revision,
|
|
719
767
|
snapshot
|
|
@@ -753,9 +801,11 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
753
801
|
try {
|
|
754
802
|
executionAuthority = normalizeExecutionAuthority(host.executionAuthority);
|
|
755
803
|
} catch {
|
|
756
|
-
throw
|
|
804
|
+
throw workspaceErrorDiagnostics.WORKSPACE_R0045({ message: "[vitehub] Workspace session host must declare executionAuthority." });
|
|
757
805
|
}
|
|
758
806
|
resolveHostInspectionConcurrency(host);
|
|
807
|
+
resolveHostMaterializationConcurrency(host);
|
|
808
|
+
if (options.attach && options.disposableTarget) throw workspaceError("[vitehub] Workspace Session attach and disposableTarget cannot be combined.");
|
|
759
809
|
const root = normalizeTarget(options.target);
|
|
760
810
|
const sessionPaths = normalizeSessionPaths(options);
|
|
761
811
|
const excludedWriteBackPaths = [...defaultExcludedSessionPaths, ...(options.writeBack && options.writeBack.exclude || []).map((path) => normalizeSafeWorkspacePath(path, { allowReserved: true }))];
|
|
@@ -771,14 +821,14 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
771
821
|
});
|
|
772
822
|
if (!attachedState) materializedExcludedState = await captureExcludedHostState(host, root, excludedWriteBackPaths, options.abortSignal);
|
|
773
823
|
} catch (error) {
|
|
774
|
-
if (attachedState || !setupMutatedHost) throw error;
|
|
824
|
+
if (attachedState || !setupMutatedHost || options.disposableTarget) throw error;
|
|
775
825
|
try {
|
|
776
826
|
host.detachAbortSignal?.();
|
|
777
827
|
await materializeWorkspace(workspace, host, root, {
|
|
778
828
|
...options,
|
|
779
829
|
abortSignal: void 0,
|
|
780
830
|
onProgress: void 0
|
|
781
|
-
}, false);
|
|
831
|
+
}, false, void 0, false);
|
|
782
832
|
await restoreExcludedHostState(host, root, excludedWriteBackPaths, existingExcludedState);
|
|
783
833
|
} catch (restoreError) {
|
|
784
834
|
throw new AggregateError([error, restoreError], "[vitehub] Workspace Session setup and excluded-state restoration failed.");
|
|
@@ -800,7 +850,8 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
800
850
|
executionAuthority,
|
|
801
851
|
async readFile(path, readOptions) {
|
|
802
852
|
assertOpen();
|
|
803
|
-
const
|
|
853
|
+
const target = toHostPath(root, assertPathInSessionScope(normalizeReadableSessionPath(path), sessionPaths, { masked: true }));
|
|
854
|
+
const file = await readHostFile(host, root, target);
|
|
804
855
|
if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
805
856
|
return decodeFile(file.content, readOptions);
|
|
806
857
|
},
|
|
@@ -823,7 +874,8 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
823
874
|
},
|
|
824
875
|
async mkdir(path, mkdirOptions = {}) {
|
|
825
876
|
assertOpen();
|
|
826
|
-
const
|
|
877
|
+
const target = assertPathInSessionScope(normalizeSafeWorkspacePath(path, { allowEmpty: true }), sessionPaths, { mkdir: true });
|
|
878
|
+
const hostTarget = toHostPath(root, target);
|
|
827
879
|
await assertNoHostSymlinkParent(host, root, hostTarget);
|
|
828
880
|
await host.files.mkdir(hostTarget, { recursive: mkdirOptions.recursive });
|
|
829
881
|
},
|
|
@@ -843,7 +895,7 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
843
895
|
assertOpen();
|
|
844
896
|
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
845
897
|
const cwd = normalizeSearchRoot(globOptions?.cwd || "");
|
|
846
|
-
const { matchesAny } = await import("./path-
|
|
898
|
+
const { matchesAny } = await import("./path-CNAwN7pw.js").then((n) => n.u);
|
|
847
899
|
return filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((entry) => {
|
|
848
900
|
if (entry.type !== "file") return false;
|
|
849
901
|
if (!cwd) return patterns.some((item) => matchesAny(entry.path, item));
|
|
@@ -854,7 +906,7 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
854
906
|
},
|
|
855
907
|
async search(query) {
|
|
856
908
|
assertOpen();
|
|
857
|
-
const { searchText } = await import("./search-
|
|
909
|
+
const { searchText } = await import("./search-CrTmXj5h.js").then((n) => n.n);
|
|
858
910
|
const scoped = scopedSearchQuery(query, sessionPaths, normalizeSearchRoot);
|
|
859
911
|
if (!scoped) return [];
|
|
860
912
|
const scopedSearchRoots = [...new Set((scoped.paths?.length ? scoped.paths : [scoped.cwd || ""]).map(normalizeSearchRoot))].filter(Boolean);
|
|
@@ -968,6 +1020,10 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
968
1020
|
const abortSignal = closeOptions?.abortSignal;
|
|
969
1021
|
abortSignal?.throwIfAborted();
|
|
970
1022
|
host.detachAbortSignal?.();
|
|
1023
|
+
if (options.disposableTarget) {
|
|
1024
|
+
closed = true;
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
971
1027
|
await ensureHostWorkspaceRoot(host, root, abortSignal);
|
|
972
1028
|
if (options.writeBack === false && !options.attach) {
|
|
973
1029
|
await materializeWorkspace(workspace, host, root, {
|
|
@@ -1010,7 +1066,7 @@ async function createHostedWorkspaceSession(workspace, options) {
|
|
|
1010
1066
|
...options,
|
|
1011
1067
|
abortSignal,
|
|
1012
1068
|
onProgress: void 0
|
|
1013
|
-
});
|
|
1069
|
+
}, true, void 0, false);
|
|
1014
1070
|
} catch (error) {
|
|
1015
1071
|
restoreError = error;
|
|
1016
1072
|
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { a as workspaceConflict, n as assertWorkspaceDigest, s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
2
|
+
import { a as isExcludedWorkspacePath, c as normalizeSafeWorkspacePattern, f as sha256, l as normalizeWorkspacePath, r as contentToBytes } from "./path-CNAwN7pw.js";
|
|
3
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
|
|
4
|
+
import { t as copyJsonFileMetadata } from "./file-metadata-CxDy-E2H.js";
|
|
5
|
+
import { n as createSnapshotFromEntries, r as diffSnapshots } from "./utils-Blrh4N2n.js";
|
|
6
|
+
import { t as createWorkspaceGlobMatcher } from "./glob--kNYDbfU.js";
|
|
7
|
+
import { b as getActiveCloudflareBinding } from "./shared-DalXdP0i.js";
|
|
8
|
+
import { a as resolveGitHubWorkspaceStore, f as setWorkspaceRuntimeConfig, i as resolveCloudflareArtifactsStore, l as getWorkspaceHostedStoreLoader, u as setWorkspaceHostedStoreLoader } from "./provider-kXjfli9u.js";
|
|
9
|
+
import { t as createGitHubWorkspaceStore } from "./store-CXgmu-uw.js";
|
|
6
10
|
import { resolve } from "node:path";
|
|
11
|
+
import { boolean, check, object, optional, parse as parse$1, pipe, record, string, unknown } from "valibot";
|
|
12
|
+
//#region ../internal/src/object.ts
|
|
13
|
+
function isPlainObject(value) {
|
|
14
|
+
if (value === null || Object(value) !== value || Array.isArray(value)) return false;
|
|
15
|
+
return typeof value === "object";
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
7
18
|
//#region src/storage/memory-fs.ts
|
|
8
19
|
function copyBinaryData(data) {
|
|
9
20
|
if (ArrayBuffer.isView(data)) return Uint8Array.from(new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
|
|
@@ -39,7 +50,7 @@ var MemoryStats = class {
|
|
|
39
50
|
var MemoryFS = class {
|
|
40
51
|
#decoder = new TextDecoder();
|
|
41
52
|
#encoder = new TextEncoder();
|
|
42
|
-
entries = new Map([["/", {
|
|
53
|
+
entries = /* @__PURE__ */ new Map([["/", {
|
|
43
54
|
kind: "dir",
|
|
44
55
|
children: /* @__PURE__ */ new Set(),
|
|
45
56
|
mtimeMs: Date.now()
|
|
@@ -172,13 +183,28 @@ var MemoryFS = class {
|
|
|
172
183
|
}
|
|
173
184
|
};
|
|
174
185
|
function memoryFsError(code, path) {
|
|
175
|
-
return Object.assign(
|
|
186
|
+
return Object.assign(workspaceErrorDiagnostics.WORKSPACE_R0065({ message: `${code}: ${path}` }), { code });
|
|
176
187
|
}
|
|
177
188
|
//#endregion
|
|
178
189
|
//#region src/providers/cloudflare/artifacts-store.ts
|
|
179
190
|
const dir = "/workspace";
|
|
180
191
|
const fileMetadataPath = ".vitehub/files.json";
|
|
192
|
+
const fileMetadataJournalPath = ".vitehub/files.pending.json";
|
|
181
193
|
const tokenRefreshWindow = 6e4;
|
|
194
|
+
const fileMetadataSchema = object({
|
|
195
|
+
mediaType: optional(string()),
|
|
196
|
+
metadata: optional(pipe(record(string(), unknown()), check((value) => value.source === void 0 || typeof value.source === "string", "metadata.source must be a string when provided")))
|
|
197
|
+
});
|
|
198
|
+
const fileMetadataFilesSchema = record(string(), fileMetadataSchema);
|
|
199
|
+
const fileMetadataJournalSchema = object({
|
|
200
|
+
path: string(),
|
|
201
|
+
existed: boolean(),
|
|
202
|
+
digest: string(),
|
|
203
|
+
metadata: fileMetadataSchema
|
|
204
|
+
});
|
|
205
|
+
function parseJson(content) {
|
|
206
|
+
return JSON.parse(new TextDecoder().decode(content));
|
|
207
|
+
}
|
|
182
208
|
function sameSnapshotEntry(left, right) {
|
|
183
209
|
return left?.digest === right?.digest && left?.type === right?.type && left?.size === right?.size && JSON.stringify(left?.metadata) === JSON.stringify(right?.metadata);
|
|
184
210
|
}
|
|
@@ -252,7 +278,7 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
252
278
|
path: normalized,
|
|
253
279
|
content,
|
|
254
280
|
mediaType: fileMetadata?.mediaType,
|
|
255
|
-
metadata: fileMetadata?.metadata
|
|
281
|
+
metadata: structuredClone(fileMetadata?.metadata)
|
|
256
282
|
};
|
|
257
283
|
}
|
|
258
284
|
async writeFile(path, file) {
|
|
@@ -279,7 +305,8 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
279
305
|
for (const [absolute, entry] of this.#fs.entries) {
|
|
280
306
|
if (absolute === dir || !absolute.startsWith(`${dir}/`)) continue;
|
|
281
307
|
const path = normalizeWorkspacePath(absolute.slice(`${dir}/`.length));
|
|
282
|
-
|
|
308
|
+
const root = path.split("/")[0]?.toLowerCase();
|
|
309
|
+
if (!path || root === ".git" || root === ".vitehub") continue;
|
|
283
310
|
if (isExcludedWorkspacePath(path, options.exclude)) continue;
|
|
284
311
|
if (normalizedPrefix) {
|
|
285
312
|
if (path === normalizedPrefix) continue;
|
|
@@ -291,7 +318,7 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
291
318
|
entries.push({
|
|
292
319
|
digest: await sha256(entry.data),
|
|
293
320
|
mediaType: fileMetadata?.mediaType,
|
|
294
|
-
metadata: fileMetadata?.metadata,
|
|
321
|
+
metadata: structuredClone(fileMetadata?.metadata),
|
|
295
322
|
mtime: entry.mtimeMs,
|
|
296
323
|
path,
|
|
297
324
|
size: entry.data.byteLength,
|
|
@@ -305,9 +332,10 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
305
332
|
}
|
|
306
333
|
return entries.sort((a, b) => a.path.localeCompare(b.path));
|
|
307
334
|
}
|
|
308
|
-
async glob(pattern,
|
|
335
|
+
async glob(pattern, options = {}) {
|
|
309
336
|
const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
|
|
310
|
-
|
|
337
|
+
const { cwd, matches } = createWorkspaceGlobMatcher(patterns, options);
|
|
338
|
+
return (await this.list(cwd, { recursive: true })).filter((entry) => entry.type === "file" && matches(entry.path));
|
|
311
339
|
}
|
|
312
340
|
async stat(path) {
|
|
313
341
|
const normalized = normalizeSafeWorkspacePath(path);
|
|
@@ -322,7 +350,7 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
322
350
|
return {
|
|
323
351
|
digest: bytes ? await sha256(bytes) : void 0,
|
|
324
352
|
mediaType: fileMetadata?.mediaType,
|
|
325
|
-
metadata: fileMetadata?.metadata,
|
|
353
|
+
metadata: structuredClone(fileMetadata?.metadata),
|
|
326
354
|
mtime: stat.mtimeMs,
|
|
327
355
|
path: normalized,
|
|
328
356
|
size: stat.isFile() ? stat.size : void 0,
|
|
@@ -334,10 +362,21 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
334
362
|
await this.#ensure();
|
|
335
363
|
await this.#mutate(() => this.#fs.promises.mkdir(this.#absolute(normalized), { recursive: options.recursive ?? true }));
|
|
336
364
|
}
|
|
365
|
+
async removeEmptyDirectory(path) {
|
|
366
|
+
const normalized = normalizeSafeWorkspacePath(path, { allowEmpty: true });
|
|
367
|
+
if (!normalized) return;
|
|
368
|
+
await this.#ensure();
|
|
369
|
+
await this.#mutate(async () => {
|
|
370
|
+
await this.#fs.promises.rmdir(this.#absolute(normalized)).catch((error) => {
|
|
371
|
+
if (error.code !== "ENOENT" && error.code !== "ENOTDIR") throw error;
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
}
|
|
337
375
|
async rm(path, options = {}) {
|
|
338
376
|
const normalized = normalizeSafeWorkspacePath(path);
|
|
339
377
|
await this.#ensure();
|
|
340
378
|
await this.#mutate(async () => {
|
|
379
|
+
if (options.ifDigest !== void 0) assertWorkspaceDigest(path, options.ifDigest, (await this.#stat(normalized))?.digest);
|
|
341
380
|
const absolute = this.#absolute(normalized);
|
|
342
381
|
const stat = await this.#fs.promises.stat(absolute).catch(() => void 0);
|
|
343
382
|
if (!stat) {
|
|
@@ -474,7 +513,9 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
474
513
|
async diff(options = {}) {
|
|
475
514
|
await this.#ensure();
|
|
476
515
|
return await this.#mutate(async () => {
|
|
477
|
-
|
|
516
|
+
const from = options.from || this.#baseline;
|
|
517
|
+
const to = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }));
|
|
518
|
+
return diffSnapshots(from, to);
|
|
478
519
|
});
|
|
479
520
|
}
|
|
480
521
|
async getMeta(key) {
|
|
@@ -492,13 +533,30 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
492
533
|
await this.#mutate(() => this.#fs.promises.writeFile(path, contentToBytes(JSON.stringify(value))));
|
|
493
534
|
}
|
|
494
535
|
async #writeFile(path, file) {
|
|
495
|
-
|
|
536
|
+
file = {
|
|
537
|
+
...file,
|
|
538
|
+
metadata: copyJsonFileMetadata(path, file.metadata)
|
|
539
|
+
};
|
|
540
|
+
const existed = await this.#fs.promises.stat(this.#absolute(path)).then((stat) => stat.isFile()).catch(() => false);
|
|
541
|
+
const content = contentToBytes(file.content);
|
|
542
|
+
const digest = await sha256(content);
|
|
543
|
+
await this.#fs.promises.writeFile(this.#internalAbsolute(fileMetadataJournalPath), JSON.stringify({
|
|
544
|
+
path,
|
|
545
|
+
existed,
|
|
546
|
+
digest,
|
|
547
|
+
metadata: {
|
|
548
|
+
mediaType: file.mediaType,
|
|
549
|
+
metadata: file.metadata
|
|
550
|
+
}
|
|
551
|
+
}));
|
|
552
|
+
await this.#fs.promises.writeFile(this.#absolute(path), content);
|
|
496
553
|
if (file.mediaType !== void 0 || file.metadata !== void 0) this.#files.set(path, {
|
|
497
554
|
mediaType: file.mediaType,
|
|
498
555
|
metadata: file.metadata
|
|
499
556
|
});
|
|
500
557
|
else this.#files.delete(path);
|
|
501
558
|
await this.#writeFileMetadata();
|
|
559
|
+
this.#fs.deleteTree(this.#internalAbsolute(fileMetadataJournalPath));
|
|
502
560
|
}
|
|
503
561
|
#absolute(path) {
|
|
504
562
|
return `${dir}/${path}`;
|
|
@@ -512,9 +570,34 @@ var CloudflareArtifactsWorkspaceStore = class {
|
|
|
512
570
|
}
|
|
513
571
|
async #loadFileMetadata() {
|
|
514
572
|
const content = await this.#fs.promises.readFile(this.#internalAbsolute(fileMetadataPath)).catch(() => void 0);
|
|
515
|
-
if (
|
|
516
|
-
|
|
517
|
-
|
|
573
|
+
if (content) {
|
|
574
|
+
const files = parse$1(fileMetadataFilesSchema, parseJson(contentToBytes(content)));
|
|
575
|
+
this.#files = new Map(Object.entries(files).map(([path, file]) => [path, {
|
|
576
|
+
...file,
|
|
577
|
+
metadata: copyJsonFileMetadata(path, file.metadata)
|
|
578
|
+
}]));
|
|
579
|
+
}
|
|
580
|
+
const pending = await this.#fs.promises.readFile(this.#internalAbsolute(fileMetadataJournalPath)).catch(() => void 0);
|
|
581
|
+
if (!pending) return;
|
|
582
|
+
let journal;
|
|
583
|
+
try {
|
|
584
|
+
journal = parse$1(fileMetadataJournalSchema, parseJson(contentToBytes(pending)));
|
|
585
|
+
journal.metadata.metadata = copyJsonFileMetadata(journal.path, journal.metadata.metadata);
|
|
586
|
+
} catch {
|
|
587
|
+
this.#fs.deleteTree(this.#internalAbsolute(fileMetadataJournalPath));
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
try {
|
|
591
|
+
if (journal.path && await this.#fs.promises.stat(this.#absolute(journal.path)).then((stat) => stat.isFile()).catch(() => false)) {
|
|
592
|
+
const content = await this.#fs.promises.readFile(this.#absolute(journal.path));
|
|
593
|
+
if (await sha256(contentToBytes(content)) !== journal.digest) return;
|
|
594
|
+
if (journal.metadata && (journal.metadata.mediaType !== void 0 || journal.metadata.metadata !== void 0)) this.#files.set(journal.path, journal.metadata);
|
|
595
|
+
else this.#files.delete(journal.path);
|
|
596
|
+
await this.#writeFileMetadata();
|
|
597
|
+
}
|
|
598
|
+
} finally {
|
|
599
|
+
this.#fs.deleteTree(this.#internalAbsolute(fileMetadataJournalPath));
|
|
600
|
+
}
|
|
518
601
|
}
|
|
519
602
|
async #writeFileMetadata() {
|
|
520
603
|
const path = this.#internalAbsolute(fileMetadataPath);
|
|
@@ -668,4 +751,4 @@ function configureHostedWorkspaceRuntime(options = {}) {
|
|
|
668
751
|
return config;
|
|
669
752
|
}
|
|
670
753
|
//#endregion
|
|
671
|
-
export { installHostedWorkspaceRuntime as n, createCloudflareArtifactsWorkspaceStore as r, configureHostedWorkspaceRuntime as t };
|
|
754
|
+
export { isPlainObject as i, installHostedWorkspaceRuntime as n, createCloudflareArtifactsWorkspaceStore as r, configureHostedWorkspaceRuntime as t };
|