@vite-hub/workspace 0.0.3 → 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.
Files changed (86) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +13 -2
  3. package/dist/{ai-Ce3PtWFW.js → ai-BqCC8BpY.js} +2 -2
  4. package/dist/{ai-nmHdzjCM.d.ts → ai-CjxvGqM0.d.ts} +1 -1
  5. package/dist/ai.d.ts +2 -2
  6. package/dist/ai.js +1 -1
  7. package/dist/{asset-registry-CaG9b7tf.js → asset-registry-8QI3ML3K.js} +1 -1
  8. package/dist/chunk-2rV9d50f.js +35 -0
  9. package/dist/cloudflare.d.ts +1 -1
  10. package/dist/cloudflare.js +1 -1
  11. package/dist/collections.d.ts +2 -2
  12. package/dist/collections.js +1 -1
  13. package/dist/{config-CZLO0m9h.js → config-Bc3c4Su1.js} +213 -120
  14. package/dist/{config-CDoyls2X.js → config-CHLLWklZ.js} +9 -3
  15. package/dist/{config-3I1BnsdO.d.ts → config-DE9xlaIw.d.ts} +1 -1
  16. package/dist/{file-CHfsZpso.js → file-Bc1X7pco.js} +3 -3
  17. package/dist/{files-QRV55OCx.js → files-Q6xZjDHA.js} +20 -9
  18. package/dist/{github-CfA5vpJ5.js → github-DHnjxQIX.js} +24 -15
  19. package/dist/{glob-D0vD_wRY.js → glob-CEZKeZFC.js} +5 -4
  20. package/dist/host-DJH8cuoU.js +1030 -0
  21. package/dist/{hosted-C1-tTTTf.js → hosted-RPeJOCFz.js} +121 -31
  22. package/dist/hosted-vercel-blob-d6C8ND5j.js +23580 -0
  23. package/dist/hosted-vercel-blob.d.ts +1 -1
  24. package/dist/hosted-vercel-blob.js +1 -1
  25. package/dist/hosted.d.ts +1 -1
  26. package/dist/hosted.js +1 -1
  27. package/dist/index.d.ts +42 -51
  28. package/dist/index.js +124 -419
  29. package/dist/lifecycle-LrL3sA4n.js +316 -0
  30. package/dist/loader.d.ts +1 -1
  31. package/dist/loader.js +1 -1
  32. package/dist/metadata-target-B0tOmVW7.js +717 -0
  33. package/dist/mountx.d.ts +1 -1
  34. package/dist/nitro.d.ts +1 -1
  35. package/dist/nitro.js +1 -1
  36. package/dist/nuxt.d.ts +1 -1
  37. package/dist/nuxt.js +8 -2
  38. package/dist/{path-CNI6wKIU.js → path-Cp59koVz.js} +28 -4
  39. package/dist/{provider-C3_elpEh.js → provider-B1yLjCJJ.js} +194 -47
  40. package/dist/providers/github/store.d.ts +1 -1
  41. package/dist/providers/github/store.js +1 -1
  42. package/dist/publish.d.ts +1 -1
  43. package/dist/publish.js +2 -2
  44. package/dist/registry-D3yzt8HQ.js +127 -0
  45. package/dist/{registry-BIQVCBWI.d.ts → registry-Uj6IVxes.d.ts} +3 -3
  46. package/dist/{request-execution-u9mgUXKX.js → request-execution-B-dSFlGB.js} +8 -4
  47. package/dist/runtime/assets.d.ts +1 -1
  48. package/dist/runtime/assets.js +4 -2
  49. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  50. package/dist/runtime/empty-registry.d.ts +1 -1
  51. package/dist/runtime/state.d.ts +4 -4
  52. package/dist/runtime/state.js +10 -7
  53. package/dist/runtime/workspace.d.ts +1 -1
  54. package/dist/runtime/workspace.js +1 -1
  55. package/dist/runtime-type-iEE6BjQJ.js +34 -0
  56. package/dist/runtime.d.ts +42 -7
  57. package/dist/runtime.js +275 -82
  58. package/dist/{search-C4REyHj9.js → search-BpiCF2Tw.js} +2 -2
  59. package/dist/server.d.ts +2 -2
  60. package/dist/server.js +23 -50
  61. package/dist/{shared-jfogBrd5.js → shared-DTR1Hhma.js} +97 -39
  62. package/dist/source-metadata.d.ts +9 -2
  63. package/dist/source-metadata.js +34 -2
  64. package/dist/{state-TTqa3x3Y.d.ts → state-tYcRWEh2.d.ts} +13 -12
  65. package/dist/store-Dt_Jyys3.js +608 -0
  66. package/dist/{sync-DiuDmSGk.js → sync-DnTQwt8r.js} +6 -5
  67. package/dist/test.d.ts +1 -1
  68. package/dist/test.js +1 -1
  69. package/dist/token-CVzURBxC.js +61 -0
  70. package/dist/{types-60Yn149G.d.ts → types-CYuwjJ4V.d.ts} +94 -27
  71. package/dist/{use-CsV3oIxH.js → use-BTNDR5Rd.js} +145 -31
  72. package/dist/{use-CUFSnFCS.d.ts → use-BiHzt0xA.d.ts} +21 -4
  73. package/dist/vite-BptCrpv2.js +4526 -0
  74. package/dist/vite-CtA9guIM.d.ts +66 -0
  75. package/dist/vite.d.ts +2 -50
  76. package/dist/vite.js +2 -2
  77. package/dist/{workspace-C4k92Ow8.js → workspace-Dq08Yn72.js} +224 -529
  78. package/dist/{workspace-66SKyiec.d.ts → workspace-Xddf4G1B.d.ts} +1 -1
  79. package/package.json +15 -18
  80. package/dist/chunk-8H4AJuhK.js +0 -14
  81. package/dist/host-CAnbugpI.js +0 -370
  82. package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
  83. package/dist/lifecycle-BYoa9hVb.js +0 -176
  84. package/dist/registry-CqyDTW9Y.js +0 -74
  85. package/dist/store-Bs1SLh55.js +0 -414
  86. package/dist/vite-tbfDxtlu.js +0 -2191
@@ -1,4 +1,4 @@
1
- import { P as WorkspaceDefinition, T as Workspace } from "./types-60Yn149G.js";
1
+ import { F as WorkspaceDefinition, T as Workspace } from "./types-CYuwjJ4V.js";
2
2
 
3
3
  //#region src/core/workspace.d.ts
4
4
  declare function createWorkspace(definition: WorkspaceDefinition): Workspace;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/workspace",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Agent-oriented filesystem state and Vite integration for ViteHub.",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -123,25 +123,28 @@
123
123
  }
124
124
  },
125
125
  "dependencies": {
126
+ "@vite-hub/box": "0.0.4",
126
127
  "@vercel/nft": "^1.10.2",
128
+ "@vite-hub/markdown-template": "0.0.4",
129
+ "@vite-hub/runtime": "0.0.4",
130
+ "@vite-hub/source": "0.0.4",
127
131
  "defu": "^6.1.7",
132
+ "esbuild": "^0.27.7",
128
133
  "exsolve": "^1.1.0",
129
134
  "h3": "2.0.1-rc.25",
130
135
  "isomorphic-git": "^1.38.7",
131
136
  "jiti": "^2.7.0",
132
137
  "mountx": "0.0.2",
133
- "minimatch": "^10.2.5",
138
+ "minimatch": "^10.2.6",
134
139
  "mrmime": "^2.0.1",
135
- "ofetch": "^1.5.1",
136
- "@vite-hub/box": "0.0.3",
137
- "@vite-hub/markdown-template": "0.0.3",
138
- "@vite-hub/source": "0.0.3",
139
- "@vite-hub/runtime": "0.0.3"
140
+ "ofetch": "^1.5.1"
140
141
  },
141
142
  "devDependencies": {
142
143
  "@types/node": "^24.13.3",
143
- "@vercel/blob": "^2.6.1",
144
- "ai": "7.0.19",
144
+ "@vercel/blob": "^2.8.0",
145
+ "@vite-hub/env": "0.0.4",
146
+ "@vite-hub/shell": "0.0.4",
147
+ "ai": "7.0.58",
145
148
  "ocache": "^0.1.5",
146
149
  "publint": "^0.3.21",
147
150
  "typescript": "^6.0.3",
@@ -149,21 +152,15 @@
149
152
  "vite-plus": "^0.1.24",
150
153
  "vitest": "^4.1.4",
151
154
  "vue": "^3.5.0",
152
- "@vite-hub/env": "0.0.3",
153
- "@vite-hub/internal": "0.0.1",
154
- "@vite-hub/shell": "0.0.3"
155
+ "@vite-hub/internal": "0.0.1"
155
156
  },
156
157
  "peerDependencies": {
157
- "@vercel/blob": "^2.6.1",
158
+ "@vite-hub/shell": "0.0.4",
158
159
  "ai": "^6.0.0 || ^7.0.0-0",
159
160
  "vite": ">=8.0.0",
160
- "vue": "^3.5.0",
161
- "@vite-hub/shell": "0.0.3"
161
+ "vue": "^3.5.0"
162
162
  },
163
163
  "peerDependenciesMeta": {
164
- "@vercel/blob": {
165
- "optional": true
166
- },
167
164
  "@vite-hub/shell": {
168
165
  "optional": true
169
166
  },
@@ -1,14 +0,0 @@
1
- import "node:module";
2
- //#region \0rolldown/runtime.js
3
- var __defProp = Object.defineProperty;
4
- var __exportAll = (all, no_symbols) => {
5
- let target = {};
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
11
- return target;
12
- };
13
- //#endregion
14
- export { __exportAll as t };
@@ -1,370 +0,0 @@
1
- import { c as normalizeWorkspacePath, d as sha256, i as decodeFile, o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes } from "./path-CNI6wKIU.js";
2
- import { i as diffSnapshots, r as createSnapshotFromEntries } from "./store-Bs1SLh55.js";
3
- import { _ as scopedSearchQuery, f as assertDiffInsideSessionPaths, g as isMissingWorkspacePathError, h as filterSessionEntries, m as filterSessionDiff, p as assertPathInSessionScope } from "./workspace-C4k92Ow8.js";
4
- import { posix } from "node:path";
5
- import { normalizeExecutionAuthority } from "@vite-hub/runtime";
6
- //#region src/session/host.ts
7
- function normalizeTarget(target = "/workspace") {
8
- const normalized = posix.resolve("/", target.replace(/\\/g, "/"));
9
- if (normalized === "/") throw workspaceError("[vitehub] Workspace session target cannot be the host root.");
10
- return normalized;
11
- }
12
- function normalizeSearchRoot(path) {
13
- const normalized = posix.normalize(path.replace(/\\/g, "/"));
14
- return normalized === "." ? "" : normalizeSafeWorkspacePath(normalized, { allowEmpty: true });
15
- }
16
- function toHostPath(root, path = "") {
17
- const normalized = normalizeSafeWorkspacePath(path, { allowEmpty: true });
18
- return normalized ? posix.join(root, normalized) : root;
19
- }
20
- function toHostCwd(root, cwd) {
21
- if (cwd === void 0) return root;
22
- if (!posix.isAbsolute(cwd)) return toHostPath(root, cwd);
23
- const normalized = posix.normalize(cwd);
24
- if (normalized === root || normalized.startsWith(`${root}/`)) return normalized;
25
- if (normalized === "/workspace" || normalized.startsWith("/workspace/")) return toHostPath(root, normalized.slice(10));
26
- throw workspaceError(`[vitehub] Workspace exec cwd must stay inside ${root}: ${cwd}.`);
27
- }
28
- function fromHostPath(root, path) {
29
- const normalizedRoot = root.replace(/\/+$/, "");
30
- const normalizedPath = posix.resolve(root, path).replace(/\/+$/, "");
31
- if (normalizedPath === normalizedRoot) return "";
32
- if (!normalizedPath.startsWith(`${normalizedRoot}/`)) throw workspaceError(`[vitehub] Workspace host returned a path outside ${root}: ${path}.`);
33
- return normalizeWorkspacePath(normalizedPath.slice(normalizedRoot.length + 1));
34
- }
35
- function isGitSymlinkEntry(entry) {
36
- return entry.metadata?.gitMode === "120000";
37
- }
38
- function hasSymlinkParent(path, symlinks) {
39
- let parent = posix.dirname(path);
40
- while (parent && parent !== "." && parent !== "/") {
41
- if (symlinks.has(parent)) return true;
42
- parent = posix.dirname(parent);
43
- }
44
- return false;
45
- }
46
- function isSafeHostSymlink(root, path, target) {
47
- if (posix.isAbsolute(target)) return false;
48
- const resolved = posix.resolve(posix.dirname(toHostPath(root, path)), target);
49
- return resolved === root || resolved.startsWith(`${root}/`);
50
- }
51
- async function assertNoHostSymlinkParent(host, root, target) {
52
- const path = fromHostPath(root, target);
53
- if (hasSymlinkParent(path, new Set((await listHostEntries(host, root, "", true)).filter(isGitSymlinkEntry).map((entry) => entry.path)))) throw workspaceError(`[vitehub] Workspace host path crosses a symlink parent: ${path}.`);
54
- }
55
- function toWorkspaceEntry(root, entry) {
56
- return {
57
- metadata: entry.type === "symlink" ? { gitMode: "120000" } : void 0,
58
- path: fromHostPath(root, entry.path),
59
- size: entry.size,
60
- type: entry.type === "directory" ? "directory" : "file"
61
- };
62
- }
63
- async function ensureHostParent(host, path) {
64
- const parent = posix.dirname(path);
65
- if (parent && parent !== "." && parent !== "/") await host.files.mkdir(parent, { recursive: true });
66
- }
67
- async function readHostSymlinkTarget(host, root, path) {
68
- const result = await host.exec("readlink", [fromHostPath(root, path)], { cwd: root });
69
- if (result.code !== 0) throw workspaceError(`[vitehub] Failed to read workspace symlink: ${path}.`, { cause: new Error(result.stderr || "readlink failed") });
70
- return result.stdout.replace(/\n$/, "");
71
- }
72
- async function writeHostSymlink(host, root, path, target) {
73
- await host.files.remove(path).catch(() => void 0);
74
- const result = await host.exec("ln", [
75
- "-s",
76
- target,
77
- fromHostPath(root, path)
78
- ], { cwd: root });
79
- if (result.code !== 0) throw workspaceError(`[vitehub] Failed to create workspace symlink: ${path}. ${result.stderr || "ln failed"}`);
80
- }
81
- async function readHostFile(host, root, path) {
82
- if (!await host.files.exists(path)) return void 0;
83
- const content = await host.files.read(path);
84
- return content ? {
85
- content,
86
- path: fromHostPath(root, path)
87
- } : void 0;
88
- }
89
- async function listHostEntries(host, root, path = "", recursive = false) {
90
- const entries = await host.files.list(toHostPath(root, path), { recursive });
91
- return (await Promise.all(entries.map(async (entry) => {
92
- const workspaceEntry = toWorkspaceEntry(root, entry);
93
- if (workspaceEntry.type !== "file" || isGitSymlinkEntry(workspaceEntry)) return workspaceEntry;
94
- return (await host.exec("test", ["-x", fromHostPath(root, entry.path)], { cwd: root })).code === 0 ? {
95
- ...workspaceEntry,
96
- metadata: {
97
- ...workspaceEntry.metadata,
98
- gitMode: "100755"
99
- }
100
- } : workspaceEntry;
101
- }))).filter((entry) => entry.path && entry.path !== ".git" && !entry.path.startsWith(".git/")).sort((left, right) => left.path.localeCompare(right.path));
102
- }
103
- async function makeHostFileExecutable(host, root, path) {
104
- const result = await host.exec("chmod", ["+x", fromHostPath(root, path)], { cwd: root });
105
- if (result.code !== 0) throw workspaceError(`[vitehub] Failed to preserve executable Workspace file: ${path}. ${result.stderr || "chmod failed"}`);
106
- }
107
- async function snapshotHost(host, root, name) {
108
- return (await captureHostState(host, root, name)).snapshot;
109
- }
110
- async function captureHostState(host, root, name) {
111
- const entries = await listHostEntries(host, root, "", true);
112
- const contents = /* @__PURE__ */ new Map();
113
- return {
114
- contents,
115
- snapshot: await createSnapshotFromEntries(await Promise.all(entries.map(async (entry) => {
116
- if (entry.type !== "file") return entry;
117
- const content = isGitSymlinkEntry(entry) ? await readHostSymlinkTarget(host, root, toHostPath(root, entry.path)) : await host.files.read(toHostPath(root, entry.path));
118
- if (content === null) throw workspaceError(`[vitehub] Workspace host file disappeared while snapshotting: ${entry.path}.`);
119
- contents.set(entry.path, content);
120
- return {
121
- ...entry,
122
- digest: await sha256(content),
123
- size: contentToBytes(content).byteLength
124
- };
125
- })), name)
126
- };
127
- }
128
- async function restoreAttachedHost(host, root, diff, state) {
129
- const changed = [...new Set(diff.entries.map((entry) => entry.path))];
130
- for (const path of changed.sort((left, right) => right.length - left.length)) await host.files.remove(toHostPath(root, path), { recursive: true }).catch(() => void 0);
131
- const baselineEntries = changed.map((path) => [path, state.snapshot.entries[path]]).filter((entry) => Boolean(entry[1])).sort(([left], [right]) => left.split("/").length - right.split("/").length);
132
- for (const [path, entry] of baselineEntries) {
133
- const target = toHostPath(root, path);
134
- if (entry.type === "directory") {
135
- await host.files.mkdir(target, { recursive: true });
136
- continue;
137
- }
138
- const content = state.contents.get(path);
139
- if (content === void 0) continue;
140
- await ensureHostParent(host, target);
141
- if (entry.metadata?.gitMode === "120000") await writeHostSymlink(host, root, target, String(content));
142
- else {
143
- await host.files.write(target, contentToBytes(content));
144
- if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
145
- }
146
- }
147
- }
148
- async function resetHostWorkspaceRoot(host, root) {
149
- await host.files.remove(root, { recursive: true }).catch(() => void 0);
150
- await host.files.mkdir(root, { recursive: true });
151
- }
152
- function normalizeSessionPaths(options) {
153
- const paths = [...new Set((options?.paths || []).map((path) => normalizeSafeWorkspacePath(path, {
154
- allowEmpty: true,
155
- allowReserved: true
156
- })))];
157
- if (!paths.length || paths.includes("")) return void 0;
158
- return paths.sort((left, right) => left.length - right.length || left.localeCompare(right));
159
- }
160
- async function sessionEntries(workspace, options) {
161
- const paths = normalizeSessionPaths(options);
162
- if (!paths) return await workspace.list("", { recursive: true });
163
- const entries = /* @__PURE__ */ new Map();
164
- for (const path of paths) {
165
- const stat = await workspace.stat(path).catch((error) => {
166
- if (isMissingWorkspacePathError(error)) return void 0;
167
- throw error;
168
- });
169
- if (!stat) continue;
170
- entries.set(stat.path, stat);
171
- if (stat.type === "directory") for (const entry of await workspace.list(path, { recursive: true })) entries.set(entry.path, entry);
172
- }
173
- return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
174
- }
175
- async function materializeWorkspace(workspace, host, root, options) {
176
- await resetHostWorkspaceRoot(host, root);
177
- const entries = await sessionEntries(workspace, options);
178
- const symlinks = new Set(entries.filter(isGitSymlinkEntry).map((entry) => entry.path));
179
- const nested = entries.find((entry) => hasSymlinkParent(entry.path, symlinks));
180
- if (nested) throw workspaceError(`[vitehub] Workspace path crosses a symlink parent: ${nested.path}.`);
181
- for (const entry of entries.filter((entry) => entry.type === "directory")) await host.files.mkdir(toHostPath(root, entry.path), { recursive: true });
182
- for (const entry of entries) {
183
- if (entry.type !== "file") continue;
184
- const target = toHostPath(root, entry.path);
185
- await ensureHostParent(host, target);
186
- if (isGitSymlinkEntry(entry)) {
187
- const symlinkTarget = typeof entry.metadata?.symlinkTarget === "string" ? entry.metadata.symlinkTarget : new TextDecoder().decode(contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })));
188
- if (isSafeHostSymlink(root, entry.path, symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget);
189
- else await host.files.write(target, contentToBytes(symlinkTarget));
190
- } else {
191
- await host.files.write(target, contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })));
192
- if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
193
- }
194
- }
195
- return await snapshotHost(host, root, "host-open");
196
- }
197
- async function commitHostChanges(host, root, workspace, diff, mediaTypes, message) {
198
- for (const entry of diff.entries) {
199
- if (entry.after?.type === "directory") {
200
- if (entry.before?.type === "file") await workspace.rm(entry.path, { force: true });
201
- await workspace.mkdir(entry.path, { recursive: true });
202
- continue;
203
- }
204
- if (entry.type === "removed") {
205
- await workspace.rm(entry.path, {
206
- force: true,
207
- recursive: true
208
- });
209
- continue;
210
- }
211
- if (entry.after?.type !== "file") continue;
212
- if (entry.before?.type === "directory") await workspace.rm(entry.path, {
213
- force: true,
214
- recursive: true
215
- });
216
- const before = entry.before?.type === "file" ? await workspace.stat(entry.path).catch(() => void 0) : void 0;
217
- const target = toHostPath(root, entry.path);
218
- const symlinkTarget = entry.after.metadata?.gitMode === "120000" ? await readHostSymlinkTarget(host, root, target) : void 0;
219
- const file = symlinkTarget === void 0 ? await readHostFile(host, root, target) : isSafeHostSymlink(root, entry.path, symlinkTarget) ? {
220
- content: symlinkTarget,
221
- metadata: entry.after.metadata,
222
- path: entry.path
223
- } : {
224
- content: symlinkTarget,
225
- path: entry.path
226
- };
227
- if (file) await workspace.writeFile(entry.path, file.content, {
228
- mediaType: file.mediaType || mediaTypes.get(entry.path) || before?.mediaType,
229
- metadata: symlinkTarget === void 0 ? entry.after.metadata : file.metadata
230
- });
231
- }
232
- await workspace.snapshot({ name: message || "host-commit" });
233
- }
234
- async function createHostedWorkspaceSession(workspace, options) {
235
- const host = options.host;
236
- let executionAuthority;
237
- try {
238
- executionAuthority = normalizeExecutionAuthority(host.executionAuthority);
239
- } catch {
240
- throw new TypeError("[vitehub] Workspace session host must declare executionAuthority.");
241
- }
242
- const root = normalizeTarget(options.target);
243
- const sessionPaths = normalizeSessionPaths(options);
244
- let closed = false;
245
- let attachedState = options.attach ? await captureHostState(host, root, "host-attach") : void 0;
246
- let baseline = attachedState?.snapshot || await materializeWorkspace(workspace, host, root, options);
247
- const mediaTypes = /* @__PURE__ */ new Map();
248
- function assertOpen() {
249
- if (closed) throw workspaceError("[vitehub] Workspace host session is already closed.");
250
- }
251
- async function currentDiff() {
252
- assertOpen();
253
- return diffSnapshots(baseline, await snapshotHost(host, root));
254
- }
255
- return {
256
- executionAuthority,
257
- async readFile(path, readOptions) {
258
- assertOpen();
259
- const file = await readHostFile(host, root, toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths, { masked: true })));
260
- if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
261
- return decodeFile(file.content, readOptions);
262
- },
263
- async writeFile(path, content, writeOptions) {
264
- assertOpen();
265
- const target = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths));
266
- await assertNoHostSymlinkParent(host, root, target);
267
- await ensureHostParent(host, target);
268
- await host.files.remove(target, { recursive: true }).catch(() => void 0);
269
- const symlinkTarget = writeOptions?.metadata?.gitMode === "120000" ? new TextDecoder().decode(contentToBytes(content)) : void 0;
270
- if (symlinkTarget !== void 0 && isSafeHostSymlink(root, fromHostPath(root, target), symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget);
271
- else {
272
- await host.files.write(target, contentToBytes(content));
273
- const workspacePath = fromHostPath(root, target);
274
- if (writeOptions?.metadata?.gitMode === "100755" || baseline.entries[workspacePath]?.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
275
- }
276
- const workspacePath = fromHostPath(root, target);
277
- if (writeOptions?.mediaType) mediaTypes.set(workspacePath, writeOptions.mediaType);
278
- else mediaTypes.delete(workspacePath);
279
- },
280
- async mkdir(path, mkdirOptions = {}) {
281
- assertOpen();
282
- const hostTarget = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path, { allowEmpty: true }), sessionPaths, { mkdir: true }));
283
- await assertNoHostSymlinkParent(host, root, hostTarget);
284
- await host.files.mkdir(hostTarget, { recursive: mkdirOptions.recursive });
285
- },
286
- async rm(path, rmOptions) {
287
- assertOpen();
288
- const workspacePath = assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths);
289
- const target = toHostPath(root, workspacePath);
290
- await assertNoHostSymlinkParent(host, root, target);
291
- await host.files.remove(target, { recursive: rmOptions?.recursive });
292
- mediaTypes.delete(normalizeWorkspacePath(workspacePath));
293
- },
294
- async list(path = "", listOptions = {}) {
295
- assertOpen();
296
- return filterSessionEntries(await listHostEntries(host, root, path, listOptions.recursive), sessionPaths);
297
- },
298
- async glob(pattern, globOptions) {
299
- assertOpen();
300
- const patterns = Array.isArray(pattern) ? pattern : [pattern];
301
- const cwd = normalizeSearchRoot(globOptions?.cwd || "");
302
- const { matchesAny } = await import("./path-CNI6wKIU.js").then((n) => n.l);
303
- return filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((entry) => {
304
- if (entry.type !== "file") return false;
305
- if (!cwd) return patterns.some((item) => matchesAny(entry.path, item));
306
- if (!entry.path.startsWith(`${cwd}/`)) return false;
307
- const relative = entry.path.slice(cwd.length + 1);
308
- return patterns.some((item) => matchesAny(relative, item));
309
- });
310
- },
311
- async search(query) {
312
- assertOpen();
313
- const { searchText } = await import("./search-C4REyHj9.js").then((n) => n.n);
314
- const scoped = scopedSearchQuery(query, sessionPaths, normalizeSearchRoot);
315
- if (!scoped) return [];
316
- const scopedSearchRoots = [...new Set((scoped.paths?.length ? scoped.paths : [scoped.cwd || ""]).map(normalizeSearchRoot))].filter(Boolean);
317
- const limit = scoped.limit ?? 100;
318
- const hits = [];
319
- for (const entry of filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((item) => item.type === "file")) {
320
- if (scopedSearchRoots.length && !scopedSearchRoots.some((path) => entry.path === path || entry.path.startsWith(`${path}/`))) continue;
321
- const content = await host.files.read(toHostPath(root, entry.path));
322
- if (content === null) continue;
323
- const text = new TextDecoder().decode(content);
324
- hits.push(...searchText(entry.path, text, {
325
- ...scoped,
326
- limit: limit - hits.length
327
- }));
328
- if (hits.length >= limit) break;
329
- }
330
- return hits;
331
- },
332
- async diff() {
333
- return filterSessionDiff(await currentDiff(), sessionPaths);
334
- },
335
- async commit(commitOptions) {
336
- const diff = await currentDiff();
337
- if (!diff.entries.length) return;
338
- assertDiffInsideSessionPaths(diff, sessionPaths);
339
- await commitHostChanges(host, root, workspace, diff, mediaTypes, commitOptions?.message);
340
- if (options.attach) {
341
- attachedState = await captureHostState(host, root, commitOptions?.message || "host-commit");
342
- baseline = attachedState.snapshot;
343
- } else baseline = await snapshotHost(host, root, commitOptions?.message || "host-commit");
344
- },
345
- async exec(command, args = [], execOptions = {}) {
346
- assertOpen();
347
- const result = await host.exec(command, args, {
348
- cwd: toHostCwd(root, execOptions.cwd),
349
- env: execOptions.env,
350
- signal: execOptions.abortSignal,
351
- timeout: execOptions.timeout
352
- });
353
- return {
354
- args,
355
- command,
356
- exitCode: result.code,
357
- stderr: result.stderr,
358
- stdout: result.stdout
359
- };
360
- },
361
- async close() {
362
- if (closed) return;
363
- if (options.attach && attachedState) await restoreAttachedHost(host, root, filterSessionDiff(diffSnapshots(baseline, await snapshotHost(host, root)), sessionPaths), attachedState);
364
- closed = true;
365
- if (!options.attach) await materializeWorkspace(workspace, host, root, options);
366
- }
367
- };
368
- }
369
- //#endregion
370
- export { createHostedWorkspaceSession };