@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
package/dist/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as createWorkspaceTools } from "./ai-
|
|
4
|
-
import { d as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { t as
|
|
9
|
-
import { t as
|
|
10
|
-
import { t as
|
|
11
|
-
import {
|
|
1
|
+
import { n as __exportAll } from "./chunk-2rV9d50f.js";
|
|
2
|
+
import { _ as workspaceError, m as isWorkspaceConflict, s as normalizeSafeWorkspacePath } from "./path-Cp59koVz.js";
|
|
3
|
+
import { t as createWorkspaceTools } from "./ai-BqCC8BpY.js";
|
|
4
|
+
import { d as registerMcpResourcesSourceLoader, p as fetch, u as prepareWorkspaceSource, v as markLiveWorkspaceSource } from "./config-Bc3c4Su1.js";
|
|
5
|
+
import { n as resolveWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
6
|
+
import { d as resolveWorkspaceAutoCommit, t as createWorkspace } from "./workspace-Dq08Yn72.js";
|
|
7
|
+
import { r as resolveRegisteredWorkspaceDefinition } from "./registry-D3yzt8HQ.js";
|
|
8
|
+
import { t as useWorkspace } from "./use-BTNDR5Rd.js";
|
|
9
|
+
import { t as withWorkspaceRuntimeOptions } from "./runtime-options-BsPSv5O7.js";
|
|
10
|
+
import { t as file } from "./file-Bc1X7pco.js";
|
|
11
|
+
import { t as github } from "./github-DHnjxQIX.js";
|
|
12
|
+
import { t as glob } from "./glob-CEZKeZFC.js";
|
|
13
|
+
import { invalidateWorkspaceStore } from "./runtime/state.js";
|
|
14
|
+
import { sourceIgnores } from "@vite-hub/source";
|
|
12
15
|
import { lookup } from "mrmime";
|
|
13
|
-
import { markdown as markdown$1 } from "@vite-hub/source/
|
|
14
|
-
import { mcpResources as mcpResources$1 } from "@vite-hub/source/
|
|
15
|
-
import { gzipSync } from "node:zlib";
|
|
16
|
+
import { markdown as markdown$1 } from "@vite-hub/source/markdown";
|
|
17
|
+
import { mcpResources as mcpResources$1 } from "@vite-hub/source/mcp";
|
|
16
18
|
//#region src/core/define.ts
|
|
17
19
|
const workspaceDefinitionKeys = new Set([
|
|
18
20
|
"bindings",
|
|
@@ -70,13 +72,8 @@ function custom(source) {
|
|
|
70
72
|
function markdown(options) {
|
|
71
73
|
const key = normalizeSafeWorkspacePath(options.workspacePath || options.path || "");
|
|
72
74
|
return {
|
|
73
|
-
...markdown$1(options),
|
|
74
|
-
|
|
75
|
-
materialize: options.materialize,
|
|
76
|
-
mount: options.mount,
|
|
77
|
-
probeKeys: options.probeKeys || [key],
|
|
78
|
-
sync: options.sync,
|
|
79
|
-
validate: options.validate
|
|
75
|
+
...withWorkspaceRuntimeOptions(markdown$1(options), options),
|
|
76
|
+
probeKeys: options.probeKeys || [key]
|
|
80
77
|
};
|
|
81
78
|
}
|
|
82
79
|
//#endregion
|
|
@@ -87,18 +84,16 @@ function mcpResources(options) {
|
|
|
87
84
|
...options,
|
|
88
85
|
cache: options.cache
|
|
89
86
|
});
|
|
90
|
-
return markLiveWorkspaceSource({
|
|
87
|
+
return markLiveWorkspaceSource(withWorkspaceRuntimeOptions({
|
|
91
88
|
...baseSource,
|
|
92
|
-
cache: options.cache,
|
|
93
|
-
materialize: options.materialize || (options.sync ? "none" : "lazy"),
|
|
94
|
-
mount: options.mount,
|
|
95
89
|
async prepare(ctx) {
|
|
96
|
-
await baseSource
|
|
90
|
+
await prepareWorkspaceSource(baseSource, ctx);
|
|
97
91
|
resetLivePaths(livePaths, resolveMountPath(options.mount, ctx), await baseSource.getKeys(ctx));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
}
|
|
93
|
+
}, {
|
|
94
|
+
...options,
|
|
95
|
+
materialize: options.materialize || (options.sync ? "none" : "lazy")
|
|
96
|
+
}), livePaths);
|
|
102
97
|
}
|
|
103
98
|
registerMcpResourcesSourceLoader((input) => mcpResources(input));
|
|
104
99
|
function resolveMountPath(mount, ctx) {
|
|
@@ -122,420 +117,123 @@ var sources_exports = /* @__PURE__ */ __exportAll({
|
|
|
122
117
|
markdown: () => markdown,
|
|
123
118
|
mcpResources: () => mcpResources
|
|
124
119
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return path === ".vitehub" || path === ".vitehub/sources" || /^\.vitehub\/sources\/[^/]+\.json$/.test(path);
|
|
146
|
-
}
|
|
147
|
-
function normalizeHarnessWorkspacePath(path = "") {
|
|
148
|
-
const descriptorPath = normalizeSafeWorkspacePath(path, {
|
|
149
|
-
allowEmpty: true,
|
|
150
|
-
allowReserved: true
|
|
151
|
-
});
|
|
152
|
-
if (isGeneratedSourceDescriptorPath(descriptorPath)) return descriptorPath;
|
|
153
|
-
return normalizeSafeWorkspacePath(path, { allowEmpty: true });
|
|
154
|
-
}
|
|
155
|
-
function normalizeSessionPaths(paths) {
|
|
156
|
-
if (paths === void 0) return void 0;
|
|
157
|
-
const normalized = [...new Set((paths || []).map(normalizeHarnessWorkspacePath))];
|
|
158
|
-
if (normalized.includes("")) return void 0;
|
|
159
|
-
return normalized.sort((left, right) => left.length - right.length || left.localeCompare(right));
|
|
160
|
-
}
|
|
161
|
-
function isIgnoredWriteBackPath(path, ignoreWriteBackPaths) {
|
|
162
|
-
for (const ignoredPath of ignoreWriteBackPaths) if (path === ignoredPath || path.startsWith(`${ignoredPath}/`)) return true;
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
function isIgnoredWriteBackParent(path, ignoreWriteBackPaths) {
|
|
166
|
-
for (const ignoredPath of ignoreWriteBackPaths) if (ignoredPath.startsWith(`${path}/`)) return true;
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
async function runSandbox(sandbox, options) {
|
|
170
|
-
const result = await sandbox.run(options);
|
|
171
|
-
if (result.exitCode !== 0) throw new Error(`[vitehub] Failed to prepare Harness Workspace Session: ${result.stderr || "sandbox command failed"}`);
|
|
172
|
-
return result;
|
|
173
|
-
}
|
|
174
|
-
async function withPrepareProgress(onProgress, event, fn) {
|
|
175
|
-
const startedAt = Date.now();
|
|
176
|
-
await onProgress?.({
|
|
177
|
-
data: event.data,
|
|
178
|
-
id: event.id,
|
|
179
|
-
label: event.label,
|
|
180
|
-
status: "started"
|
|
181
|
-
});
|
|
182
|
-
try {
|
|
183
|
-
const result = await fn();
|
|
184
|
-
await onProgress?.({
|
|
185
|
-
data: event.data,
|
|
186
|
-
durationMs: Date.now() - startedAt,
|
|
187
|
-
id: event.id,
|
|
188
|
-
label: event.label,
|
|
189
|
-
status: "completed"
|
|
190
|
-
});
|
|
191
|
-
return result;
|
|
192
|
-
} catch (error) {
|
|
193
|
-
await onProgress?.({
|
|
194
|
-
data: {
|
|
195
|
-
...event.data,
|
|
196
|
-
error: error instanceof Error ? error.message : String(error)
|
|
197
|
-
},
|
|
198
|
-
durationMs: Date.now() - startedAt,
|
|
199
|
-
error: error instanceof Error ? error.message : String(error),
|
|
200
|
-
id: event.id,
|
|
201
|
-
label: event.label,
|
|
202
|
-
status: "failed"
|
|
203
|
-
});
|
|
204
|
-
throw error;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
function workspaceFiles(entries) {
|
|
208
|
-
return entries.filter((entry) => entry.type === "file").sort((left, right) => left.path.localeCompare(right.path));
|
|
209
|
-
}
|
|
210
|
-
function workspaceDirectories(entries) {
|
|
211
|
-
return entries.filter((entry) => entry.type === "directory").map((entry) => entry.path).sort((left, right) => left.localeCompare(right));
|
|
212
|
-
}
|
|
213
|
-
function addParentDirectories(directories, path) {
|
|
214
|
-
let directory = posix.dirname(path);
|
|
215
|
-
while (directory && directory !== ".") {
|
|
216
|
-
directories.add(directory);
|
|
217
|
-
directory = posix.dirname(directory);
|
|
120
|
+
const modelWorkspaceGlobPatternLimits = Object.freeze({
|
|
121
|
+
maxBytes: 2048,
|
|
122
|
+
maxComplexity: 1024,
|
|
123
|
+
maxPatterns: 16
|
|
124
|
+
});
|
|
125
|
+
function boundedAdd(left, right, limit) {
|
|
126
|
+
if (left > limit - right) return limit + 1;
|
|
127
|
+
return left + right;
|
|
128
|
+
}
|
|
129
|
+
function boundedMultiply(left, right, limit) {
|
|
130
|
+
if (left && right > Math.floor(limit / left)) return limit + 1;
|
|
131
|
+
return left * right;
|
|
132
|
+
}
|
|
133
|
+
function boundedUtf8Bytes(value, limit) {
|
|
134
|
+
let bytes = 0;
|
|
135
|
+
for (let index = 0; index < value.length; index++) {
|
|
136
|
+
const codePoint = value.codePointAt(index);
|
|
137
|
+
if (codePoint > 65535) index++;
|
|
138
|
+
bytes += codePoint <= 127 ? 1 : codePoint <= 2047 ? 2 : codePoint <= 65535 ? 3 : 4;
|
|
139
|
+
if (bytes > limit) return limit + 1;
|
|
218
140
|
}
|
|
141
|
+
return bytes;
|
|
219
142
|
}
|
|
220
|
-
|
|
221
|
-
let
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
143
|
+
function findClosingBrace(pattern, opening) {
|
|
144
|
+
let depth = 0;
|
|
145
|
+
for (let index = opening; index < pattern.length; index++) {
|
|
146
|
+
if (pattern[index] === "\\") {
|
|
147
|
+
index++;
|
|
148
|
+
continue;
|
|
226
149
|
}
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
async function workspaceEntries(workspace, paths) {
|
|
230
|
-
if (paths && !paths.length) return [];
|
|
231
|
-
if (!paths) return await workspace.fs.list("", { recursive: true });
|
|
232
|
-
const entries = /* @__PURE__ */ new Map();
|
|
233
|
-
for (const path of paths) {
|
|
234
|
-
const stat = await workspace.fs.stat(path).catch(() => void 0);
|
|
235
|
-
if (!stat) continue;
|
|
236
|
-
entries.set(stat.path, stat);
|
|
237
|
-
if (stat.type === "directory") for (const entry of await workspace.fs.list(path, { recursive: true })) entries.set(entry.path, entry);
|
|
150
|
+
if (pattern[index] === "{") depth++;
|
|
151
|
+
else if (pattern[index] === "}" && --depth === 0) return index;
|
|
238
152
|
}
|
|
239
|
-
return
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
path
|
|
249
|
-
}).catch((error) => {
|
|
250
|
-
if (path && isMissingWorkspacePathError(error)) return;
|
|
251
|
-
throw error;
|
|
252
|
-
});
|
|
253
|
-
}));
|
|
254
|
-
}
|
|
255
|
-
function bytesEqual(left, right) {
|
|
256
|
-
if (!left || left.byteLength !== right.byteLength) return false;
|
|
257
|
-
for (let index = 0; index < left.byteLength; index++) if (left[index] !== right[index]) return false;
|
|
258
|
-
return true;
|
|
259
|
-
}
|
|
260
|
-
function pathsFromFindOutput(stdout) {
|
|
261
|
-
return stdout.split("\n").map((path) => path.trim()).filter(Boolean).map((path) => path.replace(/^\.\//, "")).filter((path) => path && path !== ".").sort((left, right) => left.localeCompare(right));
|
|
262
|
-
}
|
|
263
|
-
async function resetSandboxWorkDir(sandbox, sessionWorkDir, abortSignal) {
|
|
264
|
-
const workDir = posix.normalize(sessionWorkDir);
|
|
265
|
-
const parent = posix.dirname(workDir);
|
|
266
|
-
const name = posix.basename(workDir);
|
|
267
|
-
await sandbox.writeBinaryFile({
|
|
268
|
-
abortSignal,
|
|
269
|
-
content: new Uint8Array(),
|
|
270
|
-
path: sandboxPath(parent, ".vitehub-reset")
|
|
271
|
-
});
|
|
272
|
-
await runSandbox(sandbox, {
|
|
273
|
-
abortSignal,
|
|
274
|
-
command: `rm -rf -- ${shellQuote(name)} && mkdir -p -- ${shellQuote(name)} && rm -f -- ${shellQuote(".vitehub-reset")}`,
|
|
275
|
-
workingDirectory: parent
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
function paddedTarContent(content) {
|
|
279
|
-
const padding = content.byteLength % tarBlockSize ? tarBlockSize - content.byteLength % tarBlockSize : 0;
|
|
280
|
-
if (!padding) return Buffer.from(content);
|
|
281
|
-
return Buffer.concat([Buffer.from(content), Buffer.alloc(padding)]);
|
|
282
|
-
}
|
|
283
|
-
function splitTarPath(path) {
|
|
284
|
-
if (Buffer.byteLength(path) <= 100) return { name: path };
|
|
285
|
-
const parts = path.split("/");
|
|
286
|
-
for (let index = 1; index < parts.length; index++) {
|
|
287
|
-
const prefix = parts.slice(0, index).join("/");
|
|
288
|
-
const name = parts.slice(index).join("/");
|
|
289
|
-
if (Buffer.byteLength(prefix) <= 155 && Buffer.byteLength(name) <= 100) return {
|
|
290
|
-
name,
|
|
291
|
-
prefix
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
throw new Error(`[vitehub] Harness Workspace Session path is too long for tar transfer: ${path}`);
|
|
295
|
-
}
|
|
296
|
-
function writeTarString(header, offset, length, value) {
|
|
297
|
-
const bytes = Buffer.from(value);
|
|
298
|
-
bytes.copy(header, offset, 0, Math.min(bytes.byteLength, length));
|
|
299
|
-
}
|
|
300
|
-
function writeTarOctal(header, offset, length, value) {
|
|
301
|
-
const text = value.toString(8).padStart(length - 1, "0").slice(-(length - 1));
|
|
302
|
-
header.write(text, offset, length - 1, "ascii");
|
|
303
|
-
header[offset + length - 1] = 0;
|
|
304
|
-
}
|
|
305
|
-
function tarHeader(path, options) {
|
|
306
|
-
const header = Buffer.alloc(tarBlockSize);
|
|
307
|
-
const { name, prefix } = splitTarPath(path);
|
|
308
|
-
if (options.linkName && Buffer.byteLength(options.linkName) > 100) throw new Error(`[vitehub] Harness Workspace Session symlink target is too long for tar transfer: ${path}`);
|
|
309
|
-
writeTarString(header, 0, 100, name);
|
|
310
|
-
writeTarOctal(header, 100, 8, options.mode);
|
|
311
|
-
writeTarOctal(header, 108, 8, 0);
|
|
312
|
-
writeTarOctal(header, 116, 8, 0);
|
|
313
|
-
writeTarOctal(header, 124, 12, options.size);
|
|
314
|
-
writeTarOctal(header, 136, 12, 0);
|
|
315
|
-
header.fill(32, 148, 156);
|
|
316
|
-
header[156] = options.type === "directory" ? 53 : options.type === "symlink" ? 50 : 48;
|
|
317
|
-
if (options.linkName) writeTarString(header, 157, 100, options.linkName);
|
|
318
|
-
writeTarString(header, 257, 6, "ustar");
|
|
319
|
-
writeTarString(header, 263, 2, "00");
|
|
320
|
-
if (prefix) writeTarString(header, 345, 155, prefix);
|
|
321
|
-
let checksum = 0;
|
|
322
|
-
for (const byte of header) checksum += byte;
|
|
323
|
-
header.write(checksum.toString(8).padStart(6, "0"), 148, 6, "ascii");
|
|
324
|
-
header[154] = 0;
|
|
325
|
-
header[155] = 32;
|
|
326
|
-
return header;
|
|
327
|
-
}
|
|
328
|
-
function createWorkspaceTarGz(directories, files) {
|
|
329
|
-
const blocks = [];
|
|
330
|
-
for (const directory of [...directories].sort((left, right) => left.localeCompare(right))) {
|
|
331
|
-
const path = directory.endsWith("/") ? directory : `${directory}/`;
|
|
332
|
-
blocks.push(tarHeader(path, {
|
|
333
|
-
mode: 493,
|
|
334
|
-
size: 0,
|
|
335
|
-
type: "directory"
|
|
336
|
-
}));
|
|
337
|
-
}
|
|
338
|
-
for (const [path, file] of [...files.entries()].sort(([left], [right]) => left.localeCompare(right))) {
|
|
339
|
-
if (file.symlinkTarget) {
|
|
340
|
-
blocks.push(tarHeader(path, {
|
|
341
|
-
linkName: file.symlinkTarget,
|
|
342
|
-
mode: 511,
|
|
343
|
-
size: 0,
|
|
344
|
-
type: "symlink"
|
|
345
|
-
}));
|
|
153
|
+
return -1;
|
|
154
|
+
}
|
|
155
|
+
function splitBraceParts(content, separator) {
|
|
156
|
+
const parts = [];
|
|
157
|
+
let depth = 0;
|
|
158
|
+
let start = 0;
|
|
159
|
+
for (let index = 0; index < content.length; index++) {
|
|
160
|
+
if (content[index] === "\\") {
|
|
161
|
+
index++;
|
|
346
162
|
continue;
|
|
347
163
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
blocks.push(Buffer.alloc(tarBlockSize * 2));
|
|
356
|
-
return gzipSync(Buffer.concat(blocks));
|
|
357
|
-
}
|
|
358
|
-
async function extractWorkspaceArchive(sandbox, sessionWorkDir, initialTree, directories, abortSignal) {
|
|
359
|
-
if (!initialTree.files.size && !directories.size) return;
|
|
360
|
-
const path = sandboxPath(sessionWorkDir, archivePath);
|
|
361
|
-
await sandbox.writeBinaryFile({
|
|
362
|
-
abortSignal,
|
|
363
|
-
content: createWorkspaceTarGz(directories, initialTree.files),
|
|
364
|
-
path
|
|
365
|
-
});
|
|
366
|
-
await runSandbox(sandbox, {
|
|
367
|
-
abortSignal,
|
|
368
|
-
command: `tar -xzf ${shellQuote(archivePath)} && rm ${shellQuote(archivePath)}`,
|
|
369
|
-
workingDirectory: sessionWorkDir
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
async function initializeSandboxGitBaseline(sandbox, sessionWorkDir, abortSignal) {
|
|
373
|
-
await runSandbox(sandbox, {
|
|
374
|
-
abortSignal,
|
|
375
|
-
command: "if command -v git >/dev/null 2>&1; then git init -q && git config user.email vitehub@example.invalid && git config user.name ViteHub && git add -A -f && git commit --allow-empty --no-gpg-sign --no-verify -qm workspace-baseline || true; fi",
|
|
376
|
-
workingDirectory: sessionWorkDir
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
async function listSandboxPaths(sandbox, sessionWorkDir, type, abortSignal) {
|
|
380
|
-
const result = await runSandbox(sandbox, {
|
|
381
|
-
abortSignal,
|
|
382
|
-
command: `find . -type ${type} -print`,
|
|
383
|
-
workingDirectory: sessionWorkDir
|
|
384
|
-
});
|
|
385
|
-
return new Set(pathsFromFindOutput(result.stdout));
|
|
386
|
-
}
|
|
387
|
-
async function readSandboxSymlinkTarget(sandbox, sessionWorkDir, path, abortSignal) {
|
|
388
|
-
return (await runSandbox(sandbox, {
|
|
389
|
-
abortSignal,
|
|
390
|
-
command: `readlink -- ${shellQuote(path)}`,
|
|
391
|
-
workingDirectory: sessionWorkDir
|
|
392
|
-
})).stdout.replace(/\n$/, "");
|
|
393
|
-
}
|
|
394
|
-
async function copyWorkspaceToSandbox(workspace, sandbox, sessionWorkDir, abortSignal, paths, onMaterializeProgress, onProgress) {
|
|
395
|
-
await withPrepareProgress(onProgress, {
|
|
396
|
-
data: { paths: paths ?? null },
|
|
397
|
-
id: "workspace.prepare.materialize",
|
|
398
|
-
label: "Materializing workspace sources"
|
|
399
|
-
}, async () => {
|
|
400
|
-
await materializeWorkspaceSourcesForSession(workspace, paths, {
|
|
401
|
-
...abortSignal ? { abortSignal } : {},
|
|
402
|
-
...onMaterializeProgress ? { onProgress: onMaterializeProgress } : {}
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
const entries = await withPrepareProgress(onProgress, {
|
|
406
|
-
data: { paths: paths ?? null },
|
|
407
|
-
id: "workspace.prepare.entries",
|
|
408
|
-
label: "Resolving workspace entries"
|
|
409
|
-
}, async () => await workspaceEntries(workspace, paths));
|
|
410
|
-
const directoriesToCreate = new Set(workspaceDirectories(entries));
|
|
411
|
-
const initialTree = {
|
|
412
|
-
archiveDirectories: directoriesToCreate,
|
|
413
|
-
directories: new Set(workspaceDirectories(entries)),
|
|
414
|
-
files: /* @__PURE__ */ new Map()
|
|
415
|
-
};
|
|
416
|
-
const files = workspaceFiles(entries);
|
|
417
|
-
for (const entry of files) addParentDirectories(directoriesToCreate, entry.path);
|
|
418
|
-
await withPrepareProgress(onProgress, {
|
|
419
|
-
data: { files: files.length },
|
|
420
|
-
id: "workspace.prepare.read-files",
|
|
421
|
-
label: "Reading workspace files"
|
|
422
|
-
}, async () => {
|
|
423
|
-
await forEachConcurrent(files, workspaceReadConcurrency, async (entry) => {
|
|
424
|
-
const bytes = contentToBytes(await workspace.fs.readFile(entry.path, { encoding: "binary" }));
|
|
425
|
-
initialTree.files.set(entry.path, {
|
|
426
|
-
content: bytes,
|
|
427
|
-
mediaType: entry.mediaType,
|
|
428
|
-
symlinkTarget: entry.metadata?.gitMode === "120000" ? typeof entry.metadata.symlinkTarget === "string" ? entry.metadata.symlinkTarget : new TextDecoder().decode(bytes) : void 0
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
|
-
await withPrepareProgress(onProgress, {
|
|
433
|
-
id: "workspace.prepare.reset-sandbox",
|
|
434
|
-
label: "Resetting sandbox workspace"
|
|
435
|
-
}, async () => {
|
|
436
|
-
await resetSandboxWorkDir(sandbox, sessionWorkDir, abortSignal);
|
|
437
|
-
});
|
|
438
|
-
await withPrepareProgress(onProgress, {
|
|
439
|
-
data: {
|
|
440
|
-
directories: directoriesToCreate.size,
|
|
441
|
-
files: initialTree.files.size
|
|
442
|
-
},
|
|
443
|
-
id: "workspace.prepare.extract-archive",
|
|
444
|
-
label: "Extracting workspace archive"
|
|
445
|
-
}, async () => {
|
|
446
|
-
await extractWorkspaceArchive(sandbox, sessionWorkDir, initialTree, directoriesToCreate, abortSignal);
|
|
447
|
-
});
|
|
448
|
-
await withPrepareProgress(onProgress, {
|
|
449
|
-
id: "workspace.prepare.git-status",
|
|
450
|
-
label: "Preparing workspace status"
|
|
451
|
-
}, async () => {
|
|
452
|
-
await initializeSandboxGitBaseline(sandbox, sessionWorkDir, abortSignal);
|
|
453
|
-
});
|
|
454
|
-
return initialTree;
|
|
455
|
-
}
|
|
456
|
-
async function copySandboxChangesToWorkspace(session, definition, sandbox, sessionWorkDir, initialTree, abortSignal, ignoreWriteBackPaths, commit, onWriteBack) {
|
|
457
|
-
if (!sandbox.readBinaryFile) throw new Error("[vitehub] Harness Workspace Session write mode requires sandbox.readBinaryFile.");
|
|
458
|
-
const ignoredWriteBackPaths = new Set([...ignoreWriteBackPaths, ".git"]);
|
|
459
|
-
const sandboxDirectories = await listSandboxPaths(sandbox, sessionWorkDir, "d", abortSignal);
|
|
460
|
-
const sandboxFiles = await listSandboxPaths(sandbox, sessionWorkDir, "f", abortSignal);
|
|
461
|
-
const sandboxSymlinks = await listSandboxPaths(sandbox, sessionWorkDir, "l", abortSignal);
|
|
462
|
-
const sandboxFileEntries = new Set([...sandboxFiles, ...sandboxSymlinks]);
|
|
463
|
-
for (const path of initialTree.files.keys()) {
|
|
464
|
-
if (isIgnoredWriteBackPath(path, ignoredWriteBackPaths)) continue;
|
|
465
|
-
if (!sandboxFileEntries.has(path)) await session.rm(path, { force: true });
|
|
466
|
-
}
|
|
467
|
-
for (const path of [...initialTree.directories].sort((left, right) => right.length - left.length)) {
|
|
468
|
-
if (isIgnoredWriteBackPath(path, ignoredWriteBackPaths)) continue;
|
|
469
|
-
if (isIgnoredWriteBackParent(path, ignoredWriteBackPaths)) continue;
|
|
470
|
-
if (!sandboxDirectories.has(path)) await session.rm(path, {
|
|
471
|
-
force: true,
|
|
472
|
-
recursive: true
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
for (const path of sandboxDirectories) {
|
|
476
|
-
if (isIgnoredWriteBackPath(path, ignoredWriteBackPaths)) continue;
|
|
477
|
-
if (!initialTree.directories.has(path) && isIgnoredWriteBackParent(path, ignoredWriteBackPaths)) continue;
|
|
478
|
-
if (initialTree.archiveDirectories.has(path)) continue;
|
|
479
|
-
await session.mkdir(path, { recursive: true });
|
|
164
|
+
if (content[index] === "{") depth++;
|
|
165
|
+
else if (content[index] === "}") depth--;
|
|
166
|
+
else if (depth === 0 && content.startsWith(separator, index)) {
|
|
167
|
+
parts.push(content.slice(start, index));
|
|
168
|
+
index += separator.length - 1;
|
|
169
|
+
start = index + 1;
|
|
170
|
+
}
|
|
480
171
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
172
|
+
parts.push(content.slice(start));
|
|
173
|
+
return parts;
|
|
174
|
+
}
|
|
175
|
+
function sequenceComplexity(content, limit) {
|
|
176
|
+
const parts = splitBraceParts(content, "..");
|
|
177
|
+
if (parts.length < 2 || parts.length > 3) return void 0;
|
|
178
|
+
const [rawStart, rawEnd, rawStep] = parts;
|
|
179
|
+
const numeric = /^-?\d+$/;
|
|
180
|
+
let start;
|
|
181
|
+
let end;
|
|
182
|
+
if (numeric.test(rawStart) && numeric.test(rawEnd)) {
|
|
183
|
+
start = Number(rawStart);
|
|
184
|
+
end = Number(rawEnd);
|
|
185
|
+
} else if (rawStart?.length === 1 && rawEnd?.length === 1) {
|
|
186
|
+
start = rawStart.codePointAt(0);
|
|
187
|
+
end = rawEnd.codePointAt(0);
|
|
188
|
+
} else return;
|
|
189
|
+
const step = rawStep === void 0 ? 1 : Math.abs(Number(rawStep));
|
|
190
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || !Number.isSafeInteger(step) || step === 0) return limit + 1;
|
|
191
|
+
return Math.floor(Math.abs(end - start) / step) + 1;
|
|
192
|
+
}
|
|
193
|
+
function patternComplexity(pattern, limit) {
|
|
194
|
+
let complexity = 1;
|
|
195
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
196
|
+
if (pattern[index] === "\\") {
|
|
197
|
+
index++;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (pattern[index] === "}") return limit + 1;
|
|
201
|
+
if (pattern[index] !== "{") continue;
|
|
202
|
+
const closing = findClosingBrace(pattern, index);
|
|
203
|
+
if (closing === -1) return limit + 1;
|
|
204
|
+
const content = pattern.slice(index + 1, closing);
|
|
205
|
+
if (!content) return limit + 1;
|
|
206
|
+
if (content.includes("{") || content.includes("}")) return limit + 1;
|
|
207
|
+
const alternatives = splitBraceParts(content, ",");
|
|
208
|
+
let braceComplexity;
|
|
209
|
+
if (alternatives.length > 1) {
|
|
210
|
+
braceComplexity = 0;
|
|
211
|
+
for (const alternative of alternatives) {
|
|
212
|
+
braceComplexity = boundedAdd(braceComplexity, patternComplexity(alternative, limit), limit);
|
|
213
|
+
if (braceComplexity > limit) break;
|
|
214
|
+
}
|
|
215
|
+
} else braceComplexity = sequenceComplexity(content, limit) ?? patternComplexity(content, limit);
|
|
216
|
+
complexity = boundedMultiply(complexity, braceComplexity, limit);
|
|
217
|
+
if (complexity > limit) return complexity;
|
|
218
|
+
index = closing;
|
|
490
219
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
220
|
+
return complexity;
|
|
221
|
+
}
|
|
222
|
+
function assertModelWorkspaceGlobPattern(pattern, limits = modelWorkspaceGlobPatternLimits) {
|
|
223
|
+
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
224
|
+
if (patterns.length > limits.maxPatterns) throw new TypeError(`[vitehub] Workspace glob accepts at most ${limits.maxPatterns} model-facing patterns.`);
|
|
225
|
+
let bytes = 0;
|
|
226
|
+
for (const item of patterns) {
|
|
227
|
+
bytes = boundedAdd(bytes, boundedUtf8Bytes(item, limits.maxBytes), limits.maxBytes);
|
|
228
|
+
if (bytes > limits.maxBytes) break;
|
|
497
229
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
const
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
await onWriteBack?.(diff);
|
|
505
|
-
return;
|
|
230
|
+
if (bytes > limits.maxBytes) throw new TypeError(`[vitehub] Workspace glob pattern input exceeds the model-facing limit of ${limits.maxBytes} bytes.`);
|
|
231
|
+
let complexity = 0;
|
|
232
|
+
for (const item of patterns) {
|
|
233
|
+
const normalized = item.replace(/\\/g, "/");
|
|
234
|
+
complexity = boundedAdd(complexity, patternComplexity(normalized, limits.maxComplexity), limits.maxComplexity);
|
|
235
|
+
if (complexity > limits.maxComplexity) throw new TypeError(`[vitehub] Workspace glob pattern complexity exceeds the model-facing limit of ${limits.maxComplexity} expansions.`);
|
|
506
236
|
}
|
|
507
|
-
const autoCommit = definition ? resolveWorkspaceAutoCommit(definition, diff) : void 0;
|
|
508
|
-
if (definition && !autoCommit) return;
|
|
509
|
-
await session.commit({ message: autoCommit?.message || "harness-workspace-session" });
|
|
510
|
-
await onWriteBack?.(diff);
|
|
511
|
-
}
|
|
512
|
-
async function prepareHarnessWorkspaceSession(workspace, options) {
|
|
513
|
-
const paths = normalizeSessionPaths(options.paths);
|
|
514
|
-
const ignoreWriteBackPaths = new Set((options.ignoreWriteBackPaths || []).map(normalizeHarnessWorkspacePath));
|
|
515
|
-
const initialTree = await copyWorkspaceToSandbox(workspace, options.session, options.sessionWorkDir, options.abortSignal, paths, options.onMaterializeProgress, options.onProgress);
|
|
516
|
-
const sessionOptions = paths ? { paths } : void 0;
|
|
517
|
-
const workspaceSession = isWritableWorkspaceFacade(workspace) && (paths === void 0 || paths.length) ? await withPrepareProgress(options.onProgress, {
|
|
518
|
-
data: { paths: paths ?? null },
|
|
519
|
-
id: "workspace.prepare.start-session",
|
|
520
|
-
label: "Starting workspace write session"
|
|
521
|
-
}, async () => await workspace.startSession(sessionOptions)) : void 0;
|
|
522
|
-
return {
|
|
523
|
-
async close(error) {
|
|
524
|
-
try {
|
|
525
|
-
if (!error && workspaceSession) await copySandboxChangesToWorkspace(workspaceSession, options.definition, options.session, options.sessionWorkDir, initialTree, options.abortSignal, ignoreWriteBackPaths, options.commit, options.onWriteBack);
|
|
526
|
-
} finally {
|
|
527
|
-
await workspaceSession?.close();
|
|
528
|
-
}
|
|
529
|
-
},
|
|
530
|
-
async refreshGitBaseline() {
|
|
531
|
-
await withPrepareProgress(options.onProgress, {
|
|
532
|
-
id: "workspace.prepare.git-status",
|
|
533
|
-
label: "Preparing workspace status"
|
|
534
|
-
}, async () => {
|
|
535
|
-
await initializeSandboxGitBaseline(options.session, options.sessionWorkDir, options.abortSignal);
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
237
|
}
|
|
540
238
|
//#endregion
|
|
541
|
-
export { createWorkspace, createWorkspaceTools, custom, defineWorkspace, fetch, file, github, glob, markdown, mcpResources,
|
|
239
|
+
export { assertModelWorkspaceGlobPattern, createWorkspace, createWorkspaceTools, custom, defineWorkspace, fetch, file, github, glob, invalidateWorkspaceStore, isWorkspaceConflict, markdown, mcpResources, modelWorkspaceGlobPatternLimits, normalizeSafeWorkspacePath, resolveRegisteredWorkspaceDefinition, resolveWorkspaceAutoCommit, resolveWorkspaceStoreTarget, sources_exports as source, sourceIgnores, useWorkspace };
|