@vite-hub/shell 0.4.1 → 0.5.1
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/dist/{analyze-kSc2pmy2.js → analyze-3W0Rnm5v.js} +26 -68
- package/dist/index.d.ts +1 -5
- package/dist/index.js +2 -2
- package/dist/{just-bash-CHpGR1dZ.d.ts → just-bash-3Rfl6Fim.d.ts} +1 -3
- package/dist/providers/just-bash.d.ts +1 -1
- package/dist/providers/just-bash.js +2 -3
- package/dist/{session-DjjZUIPE.js → session-ChhAKsnl.js} +2 -6
- package/dist/{types-wPMXgnB0.d.ts → types-0p6rVKwI.d.ts} +0 -2
- package/dist/workspace.d.ts +2 -10
- package/dist/workspace.js +24 -14
- package/package.json +7 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BinCmdOperator, LangVariant, RedirOperator, walk } from "sh-syntax";
|
|
1
|
+
import { BinCmdOperator, LangVariant, RedirOperator, createSourceIndex, walk } from "sh-syntax";
|
|
2
2
|
import { defineDiagnostics } from "nostics";
|
|
3
|
-
|
|
3
|
+
// src/error-diagnostics.ts
|
|
4
4
|
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
5
5
|
const shellErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
6
6
|
docsBase: "https://vitehub.dev/docs/shell/diagnostics",
|
|
@@ -93,14 +93,17 @@ const shellErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
93
93
|
...dynamicError,
|
|
94
94
|
fix: "Make the driver return its process handle within the Shell timeout, or raise the Shell policy timeout if longer startup is expected."
|
|
95
95
|
},
|
|
96
|
+
SHELL_PATH_NOT_FOUND: {
|
|
97
|
+
...dynamicError,
|
|
98
|
+
fix: "Create the path first, or correct the path. The command found no file or directory there."
|
|
99
|
+
},
|
|
96
100
|
SHELL_SH_SYNTAX_WASM_UNAVAILABLE: {
|
|
97
101
|
why: "[vitehub] sh-syntax cannot load its WebAssembly parser on this host.",
|
|
98
102
|
fix: "Build the server with `vitehub()`, which bundles the sh-syntax WebAssembly parser, or run it on Node, where sh-syntax reads `main.wasm` from its own package."
|
|
99
103
|
}
|
|
100
104
|
}
|
|
101
105
|
});
|
|
102
|
-
|
|
103
|
-
//#region src/command/sh-syntax.ts
|
|
106
|
+
// src/command/sh-syntax.ts
|
|
104
107
|
let parser;
|
|
105
108
|
async function parseShell(text, options) {
|
|
106
109
|
parser ??= loadParser().catch((error) => {
|
|
@@ -111,25 +114,25 @@ async function parseShell(text, options) {
|
|
|
111
114
|
}
|
|
112
115
|
async function loadParser() {
|
|
113
116
|
const shSyntax = await import("sh-syntax");
|
|
114
|
-
const wasm = await bundledWasmModule();
|
|
117
|
+
const { importError, module: wasm } = await bundledWasmModule();
|
|
115
118
|
if (!wasm) {
|
|
116
|
-
if (!shSyntax.parse) throw shellErrorDiagnostics.SHELL_SH_SYNTAX_WASM_UNAVAILABLE();
|
|
119
|
+
if (!shSyntax.parse) throw shellErrorDiagnostics.SHELL_SH_SYNTAX_WASM_UNAVAILABLE({ cause: importError });
|
|
117
120
|
return shSyntax.parse;
|
|
118
121
|
}
|
|
119
122
|
const processor = shSyntax.getProcessor((imports) => WebAssembly.instantiate(wasm, imports));
|
|
120
123
|
return (text, options) => processor(text, options);
|
|
121
124
|
}
|
|
122
125
|
async function bundledWasmModule() {
|
|
126
|
+
let wasm;
|
|
123
127
|
try {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return
|
|
127
|
-
} catch {
|
|
128
|
-
return;
|
|
128
|
+
wasm = await (await import("sh-syntax/main.wasm?module")).default;
|
|
129
|
+
} catch (importError) {
|
|
130
|
+
return { importError };
|
|
129
131
|
}
|
|
132
|
+
if (wasm instanceof Uint8Array) return { module: await WebAssembly.compile(wasm) };
|
|
133
|
+
return { module: wasm instanceof WebAssembly.Module ? wasm : void 0 };
|
|
130
134
|
}
|
|
131
|
-
|
|
132
|
-
//#region src/command/parse.ts
|
|
135
|
+
// src/command/parse.ts
|
|
133
136
|
function wordText(word, source, toIndex = createSourceIndex(source)) {
|
|
134
137
|
return word.parts.map((part) => wordPartText(part, source, toIndex, false)).join("");
|
|
135
138
|
}
|
|
@@ -191,8 +194,7 @@ async function splitShellCommandSegments(command) {
|
|
|
191
194
|
}];
|
|
192
195
|
}
|
|
193
196
|
const toIndex = createSourceIndex(command);
|
|
194
|
-
|
|
195
|
-
if (scanned === void 0 || stripLineContinuations(scanned).commentContinuation) return [{
|
|
197
|
+
if (hasUnterminatedHeredoc(file)) return [{
|
|
196
198
|
command,
|
|
197
199
|
followsPipe: false,
|
|
198
200
|
invalid: true,
|
|
@@ -208,7 +210,7 @@ async function splitShellCommandSegments(command) {
|
|
|
208
210
|
for (const { negated, stmt, separator } of leaves) {
|
|
209
211
|
const trailingComment = stmt.comments.find((comment) => comment.start >= stmt.end);
|
|
210
212
|
const rawEnd = separator?.offset ?? (trailingComment ? toIndex(trailingComment.start) : toIndex(stmt.end));
|
|
211
|
-
const raw = stripLineContinuations(command.slice(cursor, Math.max(cursor, rawEnd)))
|
|
213
|
+
const raw = stripLineContinuations(command.slice(cursor, Math.max(cursor, rawEnd)));
|
|
212
214
|
segments.push({
|
|
213
215
|
command: raw,
|
|
214
216
|
followsPipe,
|
|
@@ -220,31 +222,13 @@ async function splitShellCommandSegments(command) {
|
|
|
220
222
|
}
|
|
221
223
|
return segments;
|
|
222
224
|
}
|
|
223
|
-
function
|
|
224
|
-
let
|
|
225
|
+
function hasUnterminatedHeredoc(file) {
|
|
226
|
+
let unterminated = false;
|
|
225
227
|
walk(file, (node) => {
|
|
226
|
-
if (
|
|
227
|
-
|
|
228
|
-
result = withoutTerminatorLine(result, node.word ? wordText(node.word, command, toIndex) : "", toIndex(node.end), node.op === RedirOperator.DashHdoc);
|
|
229
|
-
return result !== void 0;
|
|
230
|
-
}
|
|
231
|
-
if (node.type === "Redirect" && node.hdoc) {
|
|
232
|
-
const start = toIndex(node.hdoc.start);
|
|
233
|
-
const end = toIndex(node.hdoc.end);
|
|
234
|
-
result = result.slice(0, start) + " ".repeat(end - start) + result.slice(end);
|
|
235
|
-
}
|
|
236
|
-
return true;
|
|
228
|
+
if (node.type === "Redirect" && (node.op === RedirOperator.Hdoc || node.op === RedirOperator.DashHdoc) && node.closePos.offset === 0) unterminated = true;
|
|
229
|
+
return !unterminated;
|
|
237
230
|
});
|
|
238
|
-
return
|
|
239
|
-
}
|
|
240
|
-
function withoutTerminatorLine(source, delimiter, from, stripTabs) {
|
|
241
|
-
let start = source.indexOf("\n", from) + 1;
|
|
242
|
-
while (start > 0 && start < source.length) {
|
|
243
|
-
const end = source.indexOf("\n", start) === -1 ? source.length : source.indexOf("\n", start);
|
|
244
|
-
const line = source.slice(start, end);
|
|
245
|
-
if ((stripTabs ? line.replace(/^\t+/, "") : line) === delimiter) return source.slice(0, start) + " ".repeat(end - start) + source.slice(end);
|
|
246
|
-
start = end + 1;
|
|
247
|
-
}
|
|
231
|
+
return unterminated;
|
|
248
232
|
}
|
|
249
233
|
function flattenStatement(stmt, outer, toIndex, leaves, negated = false) {
|
|
250
234
|
if (stmt.cmd?.type === "BinaryCmd") {
|
|
@@ -299,26 +283,8 @@ function binaryOperator(op, offset) {
|
|
|
299
283
|
default: return;
|
|
300
284
|
}
|
|
301
285
|
}
|
|
302
|
-
function createSourceIndex(source) {
|
|
303
|
-
const indexes = [0];
|
|
304
|
-
let byteOffset = 0;
|
|
305
|
-
for (let index = 0; index < source.length;) {
|
|
306
|
-
const codePoint = source.codePointAt(index);
|
|
307
|
-
byteOffset += utf8Length(codePoint);
|
|
308
|
-
index += codePoint > 65535 ? 2 : 1;
|
|
309
|
-
indexes[byteOffset] = index;
|
|
310
|
-
}
|
|
311
|
-
return (offset) => indexes[offset] ?? source.length;
|
|
312
|
-
}
|
|
313
|
-
function utf8Length(codePoint) {
|
|
314
|
-
if (codePoint <= 127) return 1;
|
|
315
|
-
if (codePoint <= 2047) return 2;
|
|
316
|
-
if (codePoint <= 65535) return 3;
|
|
317
|
-
return 4;
|
|
318
|
-
}
|
|
319
286
|
function stripLineContinuations(command) {
|
|
320
287
|
let result = "";
|
|
321
|
-
let commentContinuation = false;
|
|
322
288
|
let quote;
|
|
323
289
|
let ansiCQuoted = false;
|
|
324
290
|
let escaped = false;
|
|
@@ -327,10 +293,7 @@ function stripLineContinuations(command) {
|
|
|
327
293
|
const char = command[index];
|
|
328
294
|
if (comment) {
|
|
329
295
|
result += char;
|
|
330
|
-
if (char === "\n")
|
|
331
|
-
comment = false;
|
|
332
|
-
if (command[index - 1] === "\\") commentContinuation = true;
|
|
333
|
-
}
|
|
296
|
+
if (char === "\n") comment = false;
|
|
334
297
|
continue;
|
|
335
298
|
}
|
|
336
299
|
if (escaped) {
|
|
@@ -371,13 +334,9 @@ function stripLineContinuations(command) {
|
|
|
371
334
|
if (char === "'" || char === "\"") quote = char;
|
|
372
335
|
result += char;
|
|
373
336
|
}
|
|
374
|
-
return
|
|
375
|
-
commentContinuation,
|
|
376
|
-
text: result
|
|
377
|
-
};
|
|
337
|
+
return result;
|
|
378
338
|
}
|
|
379
|
-
|
|
380
|
-
//#region src/command/analyze.ts
|
|
339
|
+
// src/command/analyze.ts
|
|
381
340
|
const defaultMaxInputBytes = 65536;
|
|
382
341
|
const defaultTimeoutMs = 100;
|
|
383
342
|
async function analyzeShellCommand(command, options = {}) {
|
|
@@ -455,5 +414,4 @@ async function withTimeout(promise, timeoutMs) {
|
|
|
455
414
|
if (timeout) clearTimeout(timeout);
|
|
456
415
|
}
|
|
457
416
|
}
|
|
458
|
-
//#endregion
|
|
459
417
|
export { splitShellCommandSegments as n, shellErrorDiagnostics as r, analyzeShellCommand as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { a as ShellBoundary, c as ShellObservationEvent, d as ShellRuntimeExecOptions, f as ShellSession, i as ShellAnalyzeResult, l as ShellProcess, n as CreateShellSessionOptions, o as ShellDriver, p as ShellSessionPolicy, r as ShellAnalyzeOptions, s as ShellObservation, t as CreateShellRuntimeOptions, u as ShellRuntime } from "./types-
|
|
2
|
-
//#region src/command/analyze.d.ts
|
|
1
|
+
import { a as ShellBoundary, c as ShellObservationEvent, d as ShellRuntimeExecOptions, f as ShellSession, i as ShellAnalyzeResult, l as ShellProcess, n as CreateShellSessionOptions, o as ShellDriver, p as ShellSessionPolicy, r as ShellAnalyzeOptions, s as ShellObservation, t as CreateShellRuntimeOptions, u as ShellRuntime } from "./types-0p6rVKwI.js";
|
|
3
2
|
export declare function analyzeShellCommand(command: string, options?: ShellAnalyzeOptions): Promise<ShellAnalyzeResult>;
|
|
4
|
-
//#endregion
|
|
5
|
-
//#region src/runtime/session.d.ts
|
|
6
3
|
export declare function createShellRuntime(options: CreateShellRuntimeOptions): ShellRuntime;
|
|
7
|
-
//#endregion
|
|
8
4
|
export type { CreateShellRuntimeOptions, CreateShellSessionOptions, ShellAnalyzeOptions, ShellAnalyzeResult, ShellBoundary, ShellDriver, ShellObservation, ShellObservationEvent, ShellProcess, ShellRuntime, ShellRuntimeExecOptions, ShellSession, ShellSessionPolicy };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as analyzeShellCommand } from "./analyze-
|
|
2
|
-
import { t as createShellRuntime } from "./session-
|
|
1
|
+
import { t as analyzeShellCommand } from "./analyze-3W0Rnm5v.js";
|
|
2
|
+
import { t as createShellRuntime } from "./session-ChhAKsnl.js";
|
|
3
3
|
export { analyzeShellCommand, createShellRuntime };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { o as ShellDriver } from "./types-
|
|
1
|
+
import { o as ShellDriver } from "./types-0p6rVKwI.js";
|
|
2
2
|
import { BashOptions } from "just-bash/browser";
|
|
3
3
|
import { IFileSystem } from "just-bash";
|
|
4
|
-
//#region src/providers/just-bash.d.ts
|
|
5
4
|
interface JustBashFileSystem extends IFileSystem {
|
|
6
5
|
readonly writeFs: boolean;
|
|
7
6
|
}
|
|
@@ -33,5 +32,4 @@ interface ShellNetworkRequestResult {
|
|
|
33
32
|
content: string | Uint8Array;
|
|
34
33
|
}
|
|
35
34
|
declare function createJustBashDriver(options: JustBashDriverOptions): ShellDriver;
|
|
36
|
-
//#endregion
|
|
37
35
|
export { ShellNetworkGrantExecutor as a, createJustBashDriver as c, JustBashFileSystem as i, JustBashExecutionLimitProfile as n, ShellNetworkRequest as o, JustBashExecutionLimits as r, ShellNetworkRequestResult as s, JustBashDriverOptions as t };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ShellNetworkGrantExecutor, c as createJustBashDriver, i as JustBashFileSystem, n as JustBashExecutionLimitProfile, o as ShellNetworkRequest, r as JustBashExecutionLimits, s as ShellNetworkRequestResult, t as JustBashDriverOptions } from "../just-bash-
|
|
1
|
+
import { a as ShellNetworkGrantExecutor, c as createJustBashDriver, i as JustBashFileSystem, n as JustBashExecutionLimitProfile, o as ShellNetworkRequest, r as JustBashExecutionLimits, s as ShellNetworkRequestResult, t as JustBashDriverOptions } from "../just-bash-3Rfl6Fim.js";
|
|
2
2
|
export { JustBashDriverOptions, JustBashExecutionLimitProfile, JustBashExecutionLimits, JustBashFileSystem, ShellNetworkGrantExecutor, ShellNetworkRequest, ShellNetworkRequestResult, createJustBashDriver };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as shellErrorDiagnostics, t as analyzeShellCommand } from "../analyze-
|
|
2
|
-
|
|
1
|
+
import { r as shellErrorDiagnostics, t as analyzeShellCommand } from "../analyze-3W0Rnm5v.js";
|
|
2
|
+
// src/providers/just-bash.ts
|
|
3
3
|
function createJustBashDriver(options) {
|
|
4
4
|
const commands = options.commands?.slice();
|
|
5
5
|
const networkGrants = options.networkGrants;
|
|
@@ -297,5 +297,4 @@ function boundOutput(content, maxLength) {
|
|
|
297
297
|
truncated: true
|
|
298
298
|
};
|
|
299
299
|
}
|
|
300
|
-
//#endregion
|
|
301
300
|
export { createJustBashDriver };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as shellErrorDiagnostics, t as analyzeShellCommand } from "./analyze-
|
|
2
|
-
|
|
1
|
+
import { r as shellErrorDiagnostics, t as analyzeShellCommand } from "./analyze-3W0Rnm5v.js";
|
|
2
|
+
// src/runtime/session.ts
|
|
3
3
|
function applyOutputLimit(result, maxLength) {
|
|
4
4
|
const limit = normalizeLimit(maxLength);
|
|
5
5
|
if (limit === void 0) return result;
|
|
@@ -35,7 +35,6 @@ function normalizeLimit(value) {
|
|
|
35
35
|
if (value === Number.POSITIVE_INFINITY) return void 0;
|
|
36
36
|
return Number.isFinite(value) ? Math.max(0, Math.floor(value)) : 0;
|
|
37
37
|
}
|
|
38
|
-
/** A per-call limit can only lower the policy limit. */
|
|
39
38
|
function lowerLimit(requested, policy) {
|
|
40
39
|
const call = normalizeLimit(requested);
|
|
41
40
|
const bound = normalizeLimit(policy);
|
|
@@ -78,14 +77,12 @@ function createTimeoutObservation(command, cwd, timeout) {
|
|
|
78
77
|
timedOut: true
|
|
79
78
|
};
|
|
80
79
|
}
|
|
81
|
-
/** Race the driver against the timeout, then abort the driver work. */
|
|
82
80
|
async function execWithRuntimeTimeout(driver, command, options, timeout) {
|
|
83
81
|
const controller = new AbortController();
|
|
84
82
|
const running = driver.exec(command, {
|
|
85
83
|
...options,
|
|
86
84
|
signal: options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal
|
|
87
85
|
});
|
|
88
|
-
running.catch(() => {});
|
|
89
86
|
let timer;
|
|
90
87
|
const timedOut = new Promise((resolve) => {
|
|
91
88
|
timer = setTimeout(() => {
|
|
@@ -306,5 +303,4 @@ function createShellRuntime(options) {
|
|
|
306
303
|
}
|
|
307
304
|
};
|
|
308
305
|
}
|
|
309
|
-
//#endregion
|
|
310
306
|
export { createShellRuntime as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ExecutionBudget } from "@vite-hub/runtime";
|
|
2
|
-
//#region src/runtime/types.d.ts
|
|
3
2
|
type ShellObservationEvent = "command_finished" | "command_timed_out" | "policy_denied" | "session_disposed";
|
|
4
3
|
interface ShellRuntimeExecOptions {
|
|
5
4
|
budget?: ExecutionBudget;
|
|
@@ -118,5 +117,4 @@ interface CreateShellSessionOptions {
|
|
|
118
117
|
env?: Record<string, string>;
|
|
119
118
|
policy?: ShellSessionPolicy;
|
|
120
119
|
}
|
|
121
|
-
//#endregion
|
|
122
120
|
export { ShellBoundary as a, ShellObservationEvent as c, ShellRuntimeExecOptions as d, ShellSession as f, ShellAnalyzeResult as i, ShellProcess as l, CreateShellSessionOptions as n, ShellDriver as o, ShellSessionPolicy as p, ShellAnalyzeOptions as r, ShellObservation as s, CreateShellRuntimeOptions as t, ShellRuntime as u };
|
package/dist/workspace.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { o as ShellDriver, s as ShellObservation } from "./types-
|
|
2
|
-
import { a as ShellNetworkGrantExecutor } from "./just-bash-
|
|
1
|
+
import { o as ShellDriver, s as ShellObservation } from "./types-0p6rVKwI.js";
|
|
2
|
+
import { a as ShellNetworkGrantExecutor } from "./just-bash-3Rfl6Fim.js";
|
|
3
3
|
import { ExecutionBudget } from "@vite-hub/runtime";
|
|
4
4
|
import { IFileSystem } from "just-bash";
|
|
5
|
-
//#region src/workspace/types.d.ts
|
|
6
5
|
type ShellContent = string | Uint8Array;
|
|
7
6
|
interface ShellReadFileOptions {
|
|
8
7
|
encoding?: "utf8" | "binary";
|
|
@@ -51,16 +50,12 @@ interface WritableShellWorkspace extends ReadonlyShellWorkspace {
|
|
|
51
50
|
mkdir(path: string, options?: ShellMkdirOptions): Promise<void>;
|
|
52
51
|
rm(path: string, options?: ShellRmOptions): Promise<void>;
|
|
53
52
|
}
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/workspace/filesystem.d.ts
|
|
56
53
|
interface WorkspaceShellFileSystem extends IFileSystem {
|
|
57
54
|
readonly writeFs: boolean;
|
|
58
55
|
}
|
|
59
56
|
export declare const workspaceMountPoint = "/workspace";
|
|
60
57
|
export declare function createReadonlyWorkspaceFs(workspace: ReadonlyShellWorkspace): WorkspaceShellFileSystem;
|
|
61
58
|
export declare function createWritableWorkspaceFs(workspace: WritableShellWorkspace): WorkspaceShellFileSystem;
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/workspace/inspection.d.ts
|
|
64
59
|
interface WorkspaceInspectionCommandOptions {
|
|
65
60
|
budget?: ExecutionBudget;
|
|
66
61
|
budgetCharged?: boolean;
|
|
@@ -75,9 +70,6 @@ interface WorkspaceInspectionCommandOptions {
|
|
|
75
70
|
timeout?: number;
|
|
76
71
|
}
|
|
77
72
|
export declare function runWorkspaceInspectionCommand(_input: SearchableShellWorkspace, command: string, options: WorkspaceInspectionCommandOptions): Promise<ShellObservation>;
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/workspace/path.d.ts
|
|
80
73
|
export declare function cleanWorkspaceShellPath(path?: string): string;
|
|
81
74
|
export declare function cleanWorkspaceMutationPath(path: string): string;
|
|
82
|
-
//#endregion
|
|
83
75
|
export type { ReadonlyShellWorkspace, SearchableShellWorkspace, ShellContent, ShellEntry, ShellListOptions, ShellMkdirOptions, ShellReadFileOptions, ShellRmOptions, ShellSearchHit, ShellSearchQuery, ShellStat, WorkspaceShellFileSystem, WritableShellWorkspace };
|
package/dist/workspace.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { n as splitShellCommandSegments, r as shellErrorDiagnostics } from "./analyze-
|
|
2
|
-
import { t as createShellRuntime } from "./session-DjjZUIPE.js";
|
|
1
|
+
import { n as splitShellCommandSegments, r as shellErrorDiagnostics } from "./analyze-3W0Rnm5v.js";
|
|
3
2
|
import { createJustBashDriver } from "./providers/just-bash.js";
|
|
3
|
+
import { t as createShellRuntime } from "./session-ChhAKsnl.js";
|
|
4
4
|
import { Buffer } from "node:buffer";
|
|
5
5
|
import { posix } from "node:path";
|
|
6
|
-
|
|
6
|
+
// src/workspace/filesystem.ts
|
|
7
7
|
const workspaceMountPoint = "/workspace";
|
|
8
8
|
function createEscapeError(path) {
|
|
9
9
|
return shellErrorDiagnostics.SHELL_R0013({ message: `[vitehub] Workspace path escapes the workspace root: "${path}".` });
|
|
@@ -55,8 +55,12 @@ function statFromEntry(entry) {
|
|
|
55
55
|
size: entry.type === "file" ? entry.size || 0 : 0
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
function isMissingWorkspacePath(error) {
|
|
59
|
+
return error instanceof Error && /Workspace (?:path|file) does not exist:/.test(error.message);
|
|
60
|
+
}
|
|
61
|
+
async function copyWorkspacePath(workspace, from, to, missingDirectory) {
|
|
59
62
|
if ((await workspace.stat(from)).type === "file") {
|
|
63
|
+
if (missingDirectory) throw missingDirectory();
|
|
60
64
|
await workspace.writeFile(to, await workspace.readFile(from, { encoding: "binary" }));
|
|
61
65
|
return;
|
|
62
66
|
}
|
|
@@ -125,7 +129,13 @@ var WorkspaceFileSystem = class {
|
|
|
125
129
|
path: "",
|
|
126
130
|
type: "directory"
|
|
127
131
|
});
|
|
128
|
-
return statFromEntry(await this.workspace.stat(relativePath))
|
|
132
|
+
return statFromEntry(await this.workspace.stat(relativePath).catch((error) => {
|
|
133
|
+
if (!isMissingWorkspacePath(error)) throw error;
|
|
134
|
+
throw shellErrorDiagnostics.SHELL_PATH_NOT_FOUND({
|
|
135
|
+
cause: error,
|
|
136
|
+
message: `[vitehub] ENOENT: no such file or directory, stat '${this.#resolveFromRoot(path)}'`
|
|
137
|
+
});
|
|
138
|
+
}));
|
|
129
139
|
}
|
|
130
140
|
async mkdir(path, options) {
|
|
131
141
|
const workspace = this.#requireWritable();
|
|
@@ -161,7 +171,7 @@ var WorkspaceFileSystem = class {
|
|
|
161
171
|
await this.#refreshPaths();
|
|
162
172
|
}
|
|
163
173
|
async cp(src, dest, _options) {
|
|
164
|
-
await copyWorkspacePath(this.#requireWritable(), this.#toRelativePath(src), this.#toRelativePath(dest));
|
|
174
|
+
await copyWorkspacePath(this.#requireWritable(), this.#toRelativePath(src), this.#toRelativePath(dest), this.#missingDirectory(dest));
|
|
165
175
|
await this.#refreshPaths();
|
|
166
176
|
}
|
|
167
177
|
async mv(src, dest) {
|
|
@@ -173,7 +183,7 @@ var WorkspaceFileSystem = class {
|
|
|
173
183
|
return;
|
|
174
184
|
}
|
|
175
185
|
if (!from || to.startsWith(`${from}/`)) throw shellErrorDiagnostics.SHELL_R0022({ message: `[vitehub] Cannot move Workspace path "${src}" into itself, "${dest}".` });
|
|
176
|
-
await copyWorkspacePath(workspace, from, to);
|
|
186
|
+
await copyWorkspacePath(workspace, from, to, this.#missingDirectory(dest));
|
|
177
187
|
await workspace.rm(from, {
|
|
178
188
|
recursive: true,
|
|
179
189
|
force: true
|
|
@@ -228,6 +238,10 @@ var WorkspaceFileSystem = class {
|
|
|
228
238
|
#resolveFromRoot(path) {
|
|
229
239
|
return this.resolvePath(workspaceMountPoint, path);
|
|
230
240
|
}
|
|
241
|
+
#missingDirectory(path) {
|
|
242
|
+
if (!path.endsWith("/")) return void 0;
|
|
243
|
+
return () => shellErrorDiagnostics.SHELL_PATH_NOT_FOUND({ message: `[vitehub] ENOTDIR: not a directory, '${this.#resolveFromRoot(path)}'` });
|
|
244
|
+
}
|
|
231
245
|
#toRelativePath(path) {
|
|
232
246
|
const absolutePath = this.#resolveFromRoot(path);
|
|
233
247
|
if (absolutePath === "/workspace") return "";
|
|
@@ -255,8 +269,7 @@ function createReadonlyWorkspaceFs(workspace) {
|
|
|
255
269
|
function createWritableWorkspaceFs(workspace) {
|
|
256
270
|
return new WorkspaceFileSystem(workspace, true);
|
|
257
271
|
}
|
|
258
|
-
|
|
259
|
-
//#region src/workspace/command-analysis.ts
|
|
272
|
+
// src/workspace/command-analysis.ts
|
|
260
273
|
async function analyzeWorkspaceInspectionCommand(command) {
|
|
261
274
|
return (await splitShellCommandSegments(command)).map((segment) => ({
|
|
262
275
|
...segment,
|
|
@@ -442,8 +455,7 @@ function hasRecursiveGrepFlag(words) {
|
|
|
442
455
|
}
|
|
443
456
|
return false;
|
|
444
457
|
}
|
|
445
|
-
|
|
446
|
-
//#region src/workspace/path.ts
|
|
458
|
+
// src/workspace/path.ts
|
|
447
459
|
function cleanWorkspaceShellPath(path = ".") {
|
|
448
460
|
const input = path || ".";
|
|
449
461
|
if (input === "." || input === "./" || input === "/" || input === "/workspace") return "";
|
|
@@ -460,8 +472,7 @@ function normalizeSafeShellPath(path) {
|
|
|
460
472
|
if (normalized === ".." || normalized.startsWith("../")) throw shellErrorDiagnostics.SHELL_R0021({ message: `[vitehub] Workspace path escapes the workspace root: "${path}".` });
|
|
461
473
|
return normalized;
|
|
462
474
|
}
|
|
463
|
-
|
|
464
|
-
//#region src/workspace/inspection.ts
|
|
475
|
+
// src/workspace/inspection.ts
|
|
465
476
|
async function runWorkspaceInspectionCommand(_input, command, options) {
|
|
466
477
|
throwIfAborted(options.signal);
|
|
467
478
|
const maxOutputLength = options.maxOutputLength === void 0 ? 3e4 : normalizeOutputLength(options.maxOutputLength);
|
|
@@ -935,5 +946,4 @@ function resolvedWorkspaceCwd(cwd, path) {
|
|
|
935
946
|
const resolvedPath = normalizedCwd ? posix.join(normalizedCwd, path) : path;
|
|
936
947
|
return posix.join(workspaceMountPoint, resolvedPath);
|
|
937
948
|
}
|
|
938
|
-
//#endregion
|
|
939
949
|
export { cleanWorkspaceMutationPath, cleanWorkspaceShellPath, createReadonlyWorkspaceFs, createWritableWorkspaceFs, runWorkspaceInspectionCommand, workspaceMountPoint };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Unified shell runtimes for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bash",
|
|
@@ -45,17 +45,17 @@
|
|
|
45
45
|
"./package.json": "./package.json"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@vite-hub/runtime": "0.
|
|
49
|
-
"just-bash": "^3.6.
|
|
48
|
+
"@vite-hub/runtime": "0.5.1",
|
|
49
|
+
"just-bash": "^3.6.1",
|
|
50
50
|
"nostics": "1.4.0",
|
|
51
|
-
"sh-syntax": "0.8.
|
|
51
|
+
"sh-syntax": "0.8.7"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@types/node": "^24.19.
|
|
54
|
+
"@types/node": "^24.19.2",
|
|
55
55
|
"publint": "^0.3.25",
|
|
56
56
|
"typescript": "^6.0.3",
|
|
57
|
-
"vite-plus": "^
|
|
58
|
-
"vitest": "
|
|
57
|
+
"vite-plus": "^1.7.0",
|
|
58
|
+
"vitest": "5.1.0"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=24.15.0"
|