@vite-hub/shell 0.5.0 → 0.6.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/dist/{analyze-psY4ydry.js → analyze-CKnpAi1D.js} +15 -17
- package/dist/index.d.ts +1 -5
- package/dist/index.js +2 -2
- package/dist/{just-bash-CHpGR1dZ.d.ts → just-bash-7eQmwBCy.d.ts} +1 -3
- package/dist/providers/just-bash.d.ts +1 -1
- package/dist/providers/just-bash.js +2 -3
- package/dist/{session-DOtQ5C_n.js → session-DI9BVN5c.js} +2 -3
- package/dist/{types-wPMXgnB0.d.ts → types-Ct6o7rwi.d.ts} +1 -2
- package/dist/workspace.d.ts +2 -10
- package/dist/workspace.js +6 -10
- package/package.json +6 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
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",
|
|
@@ -103,24 +103,28 @@ const shellErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
|
-
|
|
107
|
-
//#region src/command/sh-syntax.ts
|
|
106
|
+
// src/command/sh-syntax.ts
|
|
108
107
|
let parser;
|
|
109
108
|
async function parseShell(text, options) {
|
|
109
|
+
return (await shellParser())(text, options);
|
|
110
|
+
}
|
|
111
|
+
function shellParser() {
|
|
110
112
|
parser ??= loadParser().catch((error) => {
|
|
111
113
|
parser = void 0;
|
|
112
114
|
throw error;
|
|
113
115
|
});
|
|
114
|
-
return
|
|
116
|
+
return parser;
|
|
115
117
|
}
|
|
116
118
|
async function loadParser() {
|
|
117
119
|
const shSyntax = await import("sh-syntax");
|
|
118
120
|
const { importError, module: wasm } = await bundledWasmModule();
|
|
119
121
|
if (!wasm) {
|
|
120
|
-
if (!shSyntax.parse) throw shellErrorDiagnostics.SHELL_SH_SYNTAX_WASM_UNAVAILABLE({ cause: importError });
|
|
122
|
+
if (!shSyntax.parse || !shSyntax.init) throw shellErrorDiagnostics.SHELL_SH_SYNTAX_WASM_UNAVAILABLE({ cause: importError });
|
|
123
|
+
await shSyntax.init();
|
|
121
124
|
return shSyntax.parse;
|
|
122
125
|
}
|
|
123
126
|
const processor = shSyntax.getProcessor((imports) => WebAssembly.instantiate(wasm, imports));
|
|
127
|
+
await processor.init();
|
|
124
128
|
return (text, options) => processor(text, options);
|
|
125
129
|
}
|
|
126
130
|
async function bundledWasmModule() {
|
|
@@ -133,8 +137,7 @@ async function bundledWasmModule() {
|
|
|
133
137
|
if (wasm instanceof Uint8Array) return { module: await WebAssembly.compile(wasm) };
|
|
134
138
|
return { module: wasm instanceof WebAssembly.Module ? wasm : void 0 };
|
|
135
139
|
}
|
|
136
|
-
|
|
137
|
-
//#region src/command/parse.ts
|
|
140
|
+
// src/command/parse.ts
|
|
138
141
|
function wordText(word, source, toIndex = createSourceIndex(source)) {
|
|
139
142
|
return word.parts.map((part) => wordPartText(part, source, toIndex, false)).join("");
|
|
140
143
|
}
|
|
@@ -338,8 +341,7 @@ function stripLineContinuations(command) {
|
|
|
338
341
|
}
|
|
339
342
|
return result;
|
|
340
343
|
}
|
|
341
|
-
|
|
342
|
-
//#region src/command/analyze.ts
|
|
344
|
+
// src/command/analyze.ts
|
|
343
345
|
const defaultMaxInputBytes = 65536;
|
|
344
346
|
const defaultTimeoutMs = 100;
|
|
345
347
|
async function analyzeShellCommand(command, options = {}) {
|
|
@@ -351,7 +353,10 @@ async function analyzeShellCommand(command, options = {}) {
|
|
|
351
353
|
};
|
|
352
354
|
try {
|
|
353
355
|
return {
|
|
354
|
-
...analyzeAst(await withTimeout(
|
|
356
|
+
...analyzeAst(await withTimeout((await shellParser())(command, {
|
|
357
|
+
keepComments: true,
|
|
358
|
+
variant: LangVariant.LangBash
|
|
359
|
+
}), options.timeoutMs ?? defaultTimeoutMs), command),
|
|
355
360
|
ok: true,
|
|
356
361
|
parser: "sh-syntax"
|
|
357
362
|
};
|
|
@@ -363,12 +368,6 @@ async function analyzeShellCommand(command, options = {}) {
|
|
|
363
368
|
};
|
|
364
369
|
}
|
|
365
370
|
}
|
|
366
|
-
async function parseWithShSyntax(command) {
|
|
367
|
-
return parseShell(command, {
|
|
368
|
-
keepComments: true,
|
|
369
|
-
variant: LangVariant.LangBash
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
371
|
function analyzeAst(file, command) {
|
|
373
372
|
const commands = [];
|
|
374
373
|
const toIndex = createSourceIndex(command);
|
|
@@ -417,5 +416,4 @@ async function withTimeout(promise, timeoutMs) {
|
|
|
417
416
|
if (timeout) clearTimeout(timeout);
|
|
418
417
|
}
|
|
419
418
|
}
|
|
420
|
-
//#endregion
|
|
421
419
|
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-Ct6o7rwi.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-CKnpAi1D.js";
|
|
2
|
+
import { t as createShellRuntime } from "./session-DI9BVN5c.js";
|
|
3
3
|
export { analyzeShellCommand, createShellRuntime };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { o as ShellDriver } from "./types-
|
|
1
|
+
import { o as ShellDriver } from "./types-Ct6o7rwi.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-7eQmwBCy.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-CKnpAi1D.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-CKnpAi1D.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;
|
|
@@ -303,5 +303,4 @@ function createShellRuntime(options) {
|
|
|
303
303
|
}
|
|
304
304
|
};
|
|
305
305
|
}
|
|
306
|
-
//#endregion
|
|
307
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;
|
|
@@ -35,6 +34,7 @@ interface ShellObservation {
|
|
|
35
34
|
}
|
|
36
35
|
interface ShellAnalyzeOptions {
|
|
37
36
|
maxInputBytes?: number;
|
|
37
|
+
/** Limits the parse. The first call also loads the WebAssembly parser, which this limit does not include. Defaults to 100. */
|
|
38
38
|
timeoutMs?: number;
|
|
39
39
|
}
|
|
40
40
|
interface ShellAnalyzeResult {
|
|
@@ -118,5 +118,4 @@ interface CreateShellSessionOptions {
|
|
|
118
118
|
env?: Record<string, string>;
|
|
119
119
|
policy?: ShellSessionPolicy;
|
|
120
120
|
}
|
|
121
|
-
//#endregion
|
|
122
121
|
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-Ct6o7rwi.js";
|
|
2
|
+
import { a as ShellNetworkGrantExecutor } from "./just-bash-7eQmwBCy.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-DOtQ5C_n.js";
|
|
1
|
+
import { n as splitShellCommandSegments, r as shellErrorDiagnostics } from "./analyze-CKnpAi1D.js";
|
|
3
2
|
import { createJustBashDriver } from "./providers/just-bash.js";
|
|
3
|
+
import { t as createShellRuntime } from "./session-DI9BVN5c.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}".` });
|
|
@@ -269,8 +269,7 @@ function createReadonlyWorkspaceFs(workspace) {
|
|
|
269
269
|
function createWritableWorkspaceFs(workspace) {
|
|
270
270
|
return new WorkspaceFileSystem(workspace, true);
|
|
271
271
|
}
|
|
272
|
-
|
|
273
|
-
//#region src/workspace/command-analysis.ts
|
|
272
|
+
// src/workspace/command-analysis.ts
|
|
274
273
|
async function analyzeWorkspaceInspectionCommand(command) {
|
|
275
274
|
return (await splitShellCommandSegments(command)).map((segment) => ({
|
|
276
275
|
...segment,
|
|
@@ -456,8 +455,7 @@ function hasRecursiveGrepFlag(words) {
|
|
|
456
455
|
}
|
|
457
456
|
return false;
|
|
458
457
|
}
|
|
459
|
-
|
|
460
|
-
//#region src/workspace/path.ts
|
|
458
|
+
// src/workspace/path.ts
|
|
461
459
|
function cleanWorkspaceShellPath(path = ".") {
|
|
462
460
|
const input = path || ".";
|
|
463
461
|
if (input === "." || input === "./" || input === "/" || input === "/workspace") return "";
|
|
@@ -474,8 +472,7 @@ function normalizeSafeShellPath(path) {
|
|
|
474
472
|
if (normalized === ".." || normalized.startsWith("../")) throw shellErrorDiagnostics.SHELL_R0021({ message: `[vitehub] Workspace path escapes the workspace root: "${path}".` });
|
|
475
473
|
return normalized;
|
|
476
474
|
}
|
|
477
|
-
|
|
478
|
-
//#region src/workspace/inspection.ts
|
|
475
|
+
// src/workspace/inspection.ts
|
|
479
476
|
async function runWorkspaceInspectionCommand(_input, command, options) {
|
|
480
477
|
throwIfAborted(options.signal);
|
|
481
478
|
const maxOutputLength = options.maxOutputLength === void 0 ? 3e4 : normalizeOutputLength(options.maxOutputLength);
|
|
@@ -949,5 +946,4 @@ function resolvedWorkspaceCwd(cwd, path) {
|
|
|
949
946
|
const resolvedPath = normalizedCwd ? posix.join(normalizedCwd, path) : path;
|
|
950
947
|
return posix.join(workspaceMountPoint, resolvedPath);
|
|
951
948
|
}
|
|
952
|
-
//#endregion
|
|
953
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.6.0",
|
|
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.6.0",
|
|
49
|
+
"just-bash": "^3.6.1",
|
|
50
50
|
"nostics": "1.4.0",
|
|
51
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"
|