@vite-hub/shell 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -6
- package/dist/analyze-BXwz20IH.js +247 -0
- package/dist/index.d.ts +4 -5
- package/dist/index.js +2 -2
- package/dist/{just-bash-D84udCFy.d.ts → just-bash-DAyZQWLK.d.ts} +2 -2
- package/dist/providers/just-bash.d.ts +1 -1
- package/dist/providers/just-bash.js +132 -59
- package/dist/session-CIy2VLp9.js +245 -0
- package/dist/{types-CNRdehmi.d.ts → types-2uHfTVHi.d.ts} +23 -3
- package/dist/workspace.d.ts +14 -11
- package/dist/workspace.js +237 -209
- package/package.json +29 -14
- package/dist/analyze-Bu5Ueqph.js +0 -126
- package/dist/parse-D9VT4P6N.js +0 -41
- package/dist/providers/cloudflare.d.ts +0 -28
- package/dist/providers/cloudflare.js +0 -44
- package/dist/session-0OrrlmE9.js +0 -178
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/shell",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Unified shell runtimes for ViteHub.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"
|
|
6
|
+
"bash",
|
|
7
|
+
"command-execution",
|
|
7
8
|
"just-bash",
|
|
8
9
|
"shell",
|
|
10
|
+
"typescript",
|
|
9
11
|
"vitehub"
|
|
10
12
|
],
|
|
11
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://vitehub.dev",
|
|
12
14
|
"bugs": "https://github.com/vite-hub/vitehub/issues",
|
|
13
15
|
"license": "Apache-2.0",
|
|
14
16
|
"author": "onmax <maximogarciamtnez@gmail.com>",
|
|
@@ -25,22 +27,35 @@
|
|
|
25
27
|
"sideEffects": false,
|
|
26
28
|
"types": "./dist/index.d.ts",
|
|
27
29
|
"exports": {
|
|
28
|
-
".":
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"default": "./dist/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./providers/just-bash": {
|
|
36
|
+
"types": "./dist/providers/just-bash.d.ts",
|
|
37
|
+
"import": "./dist/providers/just-bash.js",
|
|
38
|
+
"default": "./dist/providers/just-bash.js"
|
|
39
|
+
},
|
|
40
|
+
"./workspace": {
|
|
41
|
+
"types": "./dist/workspace.d.ts",
|
|
42
|
+
"import": "./dist/workspace.js",
|
|
43
|
+
"default": "./dist/workspace.js"
|
|
44
|
+
},
|
|
32
45
|
"./package.json": "./package.json"
|
|
33
46
|
},
|
|
34
47
|
"dependencies": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
48
|
+
"@vite-hub/runtime": "0.1.0",
|
|
49
|
+
"just-bash": "^3.6.0",
|
|
50
|
+
"nostics": "1.3.0",
|
|
51
|
+
"sh-syntax": "0.7.0"
|
|
37
52
|
},
|
|
38
53
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^24.
|
|
40
|
-
"publint": "^0.3.
|
|
54
|
+
"@types/node": "^24.19.1",
|
|
55
|
+
"publint": "^0.3.25",
|
|
41
56
|
"typescript": "^6.0.3",
|
|
42
|
-
"vite-plus": "^0.
|
|
43
|
-
"vitest": "^4.1.
|
|
57
|
+
"vite-plus": "^0.3.3",
|
|
58
|
+
"vitest": "^4.1.11"
|
|
44
59
|
},
|
|
45
60
|
"engines": {
|
|
46
61
|
"node": ">=24.0.0"
|
|
@@ -48,7 +63,7 @@
|
|
|
48
63
|
"scripts": {
|
|
49
64
|
"build": "vp pack",
|
|
50
65
|
"dev": "vp pack --watch",
|
|
51
|
-
"typecheck": "
|
|
66
|
+
"typecheck": "vp run --cache -t @vite-hub/shell#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
|
|
52
67
|
"test": "vp run -t @vite-hub/shell#build && vp test"
|
|
53
68
|
}
|
|
54
69
|
}
|
package/dist/analyze-Bu5Ueqph.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
//#region src/command/analyze.ts
|
|
2
|
-
const defaultMaxInputBytes = 64 * 1024;
|
|
3
|
-
const defaultTimeoutMs = 100;
|
|
4
|
-
async function analyzeShellCommand(command, options = {}) {
|
|
5
|
-
const maxInputBytes = options.maxInputBytes ?? defaultMaxInputBytes;
|
|
6
|
-
if (new TextEncoder().encode(command).byteLength > maxInputBytes) return {
|
|
7
|
-
error: `Shell command exceeds ${maxInputBytes} bytes.`,
|
|
8
|
-
ok: false,
|
|
9
|
-
parser: "sh-syntax"
|
|
10
|
-
};
|
|
11
|
-
try {
|
|
12
|
-
await withTimeout(parseWithShSyntax(command), options.timeoutMs ?? defaultTimeoutMs);
|
|
13
|
-
} catch (error) {
|
|
14
|
-
return {
|
|
15
|
-
commands: detectCommandNames(command),
|
|
16
|
-
error: error instanceof Error ? error.message : String(error),
|
|
17
|
-
ok: false,
|
|
18
|
-
parser: "sh-syntax"
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
commands: detectCommandNames(command),
|
|
23
|
-
hasCommandSubstitution: /(?:\$\(|`)/.test(command),
|
|
24
|
-
hasHeredocs: /<<-?/.test(command),
|
|
25
|
-
hasPipelines: hasUnquoted(command, "|"),
|
|
26
|
-
hasRedirects: /(?:^|[^<])(?:>>?|<)/.test(command),
|
|
27
|
-
ok: true,
|
|
28
|
-
parser: "sh-syntax"
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
async function parseWithShSyntax(command) {
|
|
32
|
-
const { parse, LangVariant } = await import("sh-syntax");
|
|
33
|
-
await parse(command, { variant: LangVariant.LangBash });
|
|
34
|
-
}
|
|
35
|
-
async function withTimeout(promise, timeoutMs) {
|
|
36
|
-
if (timeoutMs <= 0) throw new Error(`Shell analysis timed out after ${timeoutMs}ms.`);
|
|
37
|
-
let timeout;
|
|
38
|
-
try {
|
|
39
|
-
return await Promise.race([promise, new Promise((_, reject) => {
|
|
40
|
-
timeout = setTimeout(() => reject(/* @__PURE__ */ new Error(`Shell analysis timed out after ${timeoutMs}ms.`)), timeoutMs);
|
|
41
|
-
})]);
|
|
42
|
-
} finally {
|
|
43
|
-
if (timeout) clearTimeout(timeout);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function detectCommandNames(command) {
|
|
47
|
-
const names = [];
|
|
48
|
-
for (const segment of splitShellCommandSegments(command)) {
|
|
49
|
-
const name = firstCommandWord(segment);
|
|
50
|
-
if (name && !names.includes(name)) names.push(name);
|
|
51
|
-
}
|
|
52
|
-
return names;
|
|
53
|
-
}
|
|
54
|
-
function splitShellCommandSegments(command) {
|
|
55
|
-
const segments = [];
|
|
56
|
-
let current = "";
|
|
57
|
-
let quote;
|
|
58
|
-
let escaped = false;
|
|
59
|
-
for (let index = 0; index < command.length; index++) {
|
|
60
|
-
const char = command[index];
|
|
61
|
-
const next = command[index + 1];
|
|
62
|
-
if (escaped) {
|
|
63
|
-
current += char;
|
|
64
|
-
escaped = false;
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (char === "\\") {
|
|
68
|
-
current += char;
|
|
69
|
-
escaped = true;
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
if (quote) {
|
|
73
|
-
if (char === quote) quote = void 0;
|
|
74
|
-
current += char;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (char === "'" || char === "\"") {
|
|
78
|
-
quote = char;
|
|
79
|
-
current += char;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (char === "|" || char === ";" || char === "\n" || char === "&" && next === "&" || char === "|" && next === "|") {
|
|
83
|
-
segments.push(current);
|
|
84
|
-
current = "";
|
|
85
|
-
if ((char === "&" || char === "|") && next === char) index += 1;
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
current += char;
|
|
89
|
-
}
|
|
90
|
-
segments.push(current);
|
|
91
|
-
return segments;
|
|
92
|
-
}
|
|
93
|
-
function firstCommandWord(segment) {
|
|
94
|
-
const words = segment.trim().match(/[^\s]+/g) || [];
|
|
95
|
-
for (const word of words) {
|
|
96
|
-
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(word)) continue;
|
|
97
|
-
if (/^\d*(?:>>?|<<?-?|<&|>&)/.test(word)) continue;
|
|
98
|
-
return word.replace(/^command$/, "") || void 0;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function hasUnquoted(command, target) {
|
|
102
|
-
let quote;
|
|
103
|
-
let escaped = false;
|
|
104
|
-
for (const char of command) {
|
|
105
|
-
if (escaped) {
|
|
106
|
-
escaped = false;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
if (char === "\\") {
|
|
110
|
-
escaped = true;
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (quote) {
|
|
114
|
-
if (char === quote) quote = void 0;
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
if (char === "'" || char === "\"") {
|
|
118
|
-
quote = char;
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (char === target) return true;
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
//#endregion
|
|
126
|
-
export { analyzeShellCommand as t };
|
package/dist/parse-D9VT4P6N.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//#region src/command/parse.ts
|
|
2
|
-
function parseShellCommand(command) {
|
|
3
|
-
const words = [];
|
|
4
|
-
let current = "";
|
|
5
|
-
let quote;
|
|
6
|
-
let escaped = false;
|
|
7
|
-
for (const char of command) {
|
|
8
|
-
if (escaped) {
|
|
9
|
-
current += char;
|
|
10
|
-
escaped = false;
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
if (char === "\\") {
|
|
14
|
-
escaped = true;
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
if (quote) {
|
|
18
|
-
if (char === quote) quote = void 0;
|
|
19
|
-
else current += char;
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (char === "'" || char === "\"") {
|
|
23
|
-
quote = char;
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (/\s/.test(char)) {
|
|
27
|
-
if (current) {
|
|
28
|
-
words.push(current);
|
|
29
|
-
current = "";
|
|
30
|
-
}
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
current += char;
|
|
34
|
-
}
|
|
35
|
-
if (escaped) current += "\\";
|
|
36
|
-
if (quote) throw new Error("unterminated quote");
|
|
37
|
-
if (current) words.push(current);
|
|
38
|
-
return words;
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
export { parseShellCommand as t };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { o as ShellExecutionProvider } from "../types-CNRdehmi.js";
|
|
2
|
-
|
|
3
|
-
//#region src/providers/cloudflare.d.ts
|
|
4
|
-
interface CloudflareShellClient {
|
|
5
|
-
exec: (command: string, args?: string[], options?: {
|
|
6
|
-
cwd?: string;
|
|
7
|
-
env?: Record<string, string>;
|
|
8
|
-
onStderr?: (data: string) => void;
|
|
9
|
-
onStdout?: (data: string) => void;
|
|
10
|
-
stdin?: string;
|
|
11
|
-
timeout?: number;
|
|
12
|
-
}) => Promise<{
|
|
13
|
-
code?: number | null;
|
|
14
|
-
exitCode?: number | null;
|
|
15
|
-
stderr: string;
|
|
16
|
-
stdout: string;
|
|
17
|
-
}>;
|
|
18
|
-
supports: {
|
|
19
|
-
execCwd: boolean;
|
|
20
|
-
execEnv: boolean;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
interface CloudflareShellProviderOptions {
|
|
24
|
-
sandbox: CloudflareShellClient;
|
|
25
|
-
}
|
|
26
|
-
declare function createCloudflareShellProvider(options: CloudflareShellProviderOptions): ShellExecutionProvider;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { CloudflareShellClient, CloudflareShellProviderOptions, createCloudflareShellProvider };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { t as analyzeShellCommand } from "../analyze-Bu5Ueqph.js";
|
|
2
|
-
import { t as parseShellCommand } from "../parse-D9VT4P6N.js";
|
|
3
|
-
//#region src/providers/cloudflare.ts
|
|
4
|
-
function createCloudflareShellProvider(options) {
|
|
5
|
-
return {
|
|
6
|
-
analyze: analyzeShellCommand,
|
|
7
|
-
boundary: {
|
|
8
|
-
cwd: options.sandbox.supports.execCwd,
|
|
9
|
-
env: options.sandbox.supports.execEnv,
|
|
10
|
-
filesystem: { writable: true },
|
|
11
|
-
network: "unknown",
|
|
12
|
-
processes: {
|
|
13
|
-
background: false,
|
|
14
|
-
interactive: false
|
|
15
|
-
},
|
|
16
|
-
streaming: true,
|
|
17
|
-
timeout: {
|
|
18
|
-
enforcedBy: "provider",
|
|
19
|
-
supported: true
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
async exec(command, execOptions = {}) {
|
|
23
|
-
const [cmd = "", ...args] = parseShellCommand(command);
|
|
24
|
-
const result = await options.sandbox.exec(cmd, args, {
|
|
25
|
-
cwd: execOptions.cwd,
|
|
26
|
-
env: execOptions.env,
|
|
27
|
-
onStderr: execOptions.onStderr,
|
|
28
|
-
onStdout: execOptions.onStdout,
|
|
29
|
-
stdin: execOptions.stdin,
|
|
30
|
-
timeout: execOptions.timeout
|
|
31
|
-
});
|
|
32
|
-
return {
|
|
33
|
-
command,
|
|
34
|
-
cwd: execOptions.cwd,
|
|
35
|
-
event: "command_finished",
|
|
36
|
-
exitCode: result.exitCode ?? result.code ?? null,
|
|
37
|
-
stderr: result.stderr,
|
|
38
|
-
stdout: result.stdout
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
export { createCloudflareShellProvider };
|
package/dist/session-0OrrlmE9.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { t as analyzeShellCommand } from "./analyze-Bu5Ueqph.js";
|
|
2
|
-
//#region src/runtime/session.ts
|
|
3
|
-
function applyOutputLimit(result, maxLength) {
|
|
4
|
-
if (!maxLength) return result;
|
|
5
|
-
const next = {
|
|
6
|
-
...result,
|
|
7
|
-
maxOutputLength: maxLength
|
|
8
|
-
};
|
|
9
|
-
let truncated = false;
|
|
10
|
-
if (next.stdout.length > maxLength) {
|
|
11
|
-
next.stdout = `${next.stdout.slice(0, maxLength)}\n[output truncated to ${maxLength} characters]\n`;
|
|
12
|
-
truncated = true;
|
|
13
|
-
}
|
|
14
|
-
if (next.stderr.length > maxLength) {
|
|
15
|
-
next.stderr = `${next.stderr.slice(0, maxLength)}\n[output truncated to ${maxLength} characters]\n`;
|
|
16
|
-
truncated = true;
|
|
17
|
-
}
|
|
18
|
-
return truncated ? {
|
|
19
|
-
...next,
|
|
20
|
-
outputTruncated: true
|
|
21
|
-
} : next;
|
|
22
|
-
}
|
|
23
|
-
function createPolicyObservation(command, cwd, message) {
|
|
24
|
-
return {
|
|
25
|
-
command,
|
|
26
|
-
cwd,
|
|
27
|
-
event: "policy_denied",
|
|
28
|
-
exitCode: 126,
|
|
29
|
-
stderr: message.endsWith("\n") ? message : `${message}\n`,
|
|
30
|
-
stdout: ""
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
const shellSessionDisposedMessage = "[vitehub] Shell session is disposed.";
|
|
34
|
-
var RuntimeShellSession = class {
|
|
35
|
-
provider;
|
|
36
|
-
env;
|
|
37
|
-
boundary;
|
|
38
|
-
policy;
|
|
39
|
-
#disposed = false;
|
|
40
|
-
#disposeTask;
|
|
41
|
-
#processes = /* @__PURE__ */ new Set();
|
|
42
|
-
#starts = /* @__PURE__ */ new Set();
|
|
43
|
-
#shellCalls = 0;
|
|
44
|
-
constructor(provider, policy, env) {
|
|
45
|
-
this.provider = provider;
|
|
46
|
-
this.env = env;
|
|
47
|
-
this.boundary = provider.boundary;
|
|
48
|
-
this.policy = policy;
|
|
49
|
-
}
|
|
50
|
-
async analyze(command, options) {
|
|
51
|
-
return await (this.provider.analyze ?? analyzeShellCommand)(command, options);
|
|
52
|
-
}
|
|
53
|
-
async exec(command, options = {}) {
|
|
54
|
-
if (this.#disposed) return createPolicyObservation(command, options.cwd, shellSessionDisposedMessage);
|
|
55
|
-
if (typeof this.policy.maxShellCalls === "number" && this.#shellCalls >= this.policy.maxShellCalls) return createPolicyObservation(command, options.cwd, `[vitehub] Shell session command budget exhausted after ${this.policy.maxShellCalls} calls. The Shell Session policy limits command calls for this run.`);
|
|
56
|
-
this.#shellCalls += 1;
|
|
57
|
-
const started = Date.now();
|
|
58
|
-
const result = await this.provider.exec(command, {
|
|
59
|
-
...options,
|
|
60
|
-
env: {
|
|
61
|
-
...this.env,
|
|
62
|
-
...options.env
|
|
63
|
-
},
|
|
64
|
-
timeout: options.timeout ?? this.policy.timeout
|
|
65
|
-
});
|
|
66
|
-
return applyOutputLimit({
|
|
67
|
-
...result,
|
|
68
|
-
command: result.command ?? command,
|
|
69
|
-
cwd: result.cwd ?? options.cwd,
|
|
70
|
-
durationMs: result.durationMs ?? Date.now() - started,
|
|
71
|
-
event: result.timedOut ? "command_timed_out" : result.event
|
|
72
|
-
}, this.policy.maxOutputLength);
|
|
73
|
-
}
|
|
74
|
-
async startProcess(command, options = {}) {
|
|
75
|
-
if (this.#disposed) throw new Error(shellSessionDisposedMessage);
|
|
76
|
-
if (!this.provider.startProcess || !this.boundary.processes.background) throw new Error("[vitehub] Shell provider does not support long-running processes.");
|
|
77
|
-
if (typeof this.policy.maxProcesses === "number" && this.#processes.size >= this.policy.maxProcesses) throw new Error(`[vitehub] Shell session process budget exhausted after ${this.policy.maxProcesses} processes.`);
|
|
78
|
-
let finishStart;
|
|
79
|
-
const start = new Promise((resolve) => {
|
|
80
|
-
finishStart = resolve;
|
|
81
|
-
});
|
|
82
|
-
this.#starts.add(start);
|
|
83
|
-
start.finally(() => this.#starts.delete(start));
|
|
84
|
-
let process;
|
|
85
|
-
try {
|
|
86
|
-
process = await this.provider.startProcess(command, {
|
|
87
|
-
...options,
|
|
88
|
-
env: {
|
|
89
|
-
...this.env,
|
|
90
|
-
...options.env
|
|
91
|
-
},
|
|
92
|
-
timeout: options.timeout ?? this.policy.timeout
|
|
93
|
-
});
|
|
94
|
-
} catch (error) {
|
|
95
|
-
finishStart();
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
let stopTask;
|
|
99
|
-
let trackedProcess;
|
|
100
|
-
const stop = () => {
|
|
101
|
-
if (stopTask) return stopTask;
|
|
102
|
-
stopTask = Promise.resolve().then(() => process.stop()).then((result) => {
|
|
103
|
-
this.#processes.delete(trackedProcess);
|
|
104
|
-
return result;
|
|
105
|
-
}, (error) => {
|
|
106
|
-
stopTask = void 0;
|
|
107
|
-
throw error;
|
|
108
|
-
});
|
|
109
|
-
return stopTask;
|
|
110
|
-
};
|
|
111
|
-
trackedProcess = {
|
|
112
|
-
...process,
|
|
113
|
-
stop
|
|
114
|
-
};
|
|
115
|
-
this.#processes.add(trackedProcess);
|
|
116
|
-
finishStart();
|
|
117
|
-
if (this.#disposed) {
|
|
118
|
-
try {
|
|
119
|
-
await stop();
|
|
120
|
-
} catch (error) {
|
|
121
|
-
throw new AggregateError([/* @__PURE__ */ new Error(shellSessionDisposedMessage), error], "[vitehub] Shell session was disposed while starting a background process, and stopping it failed.");
|
|
122
|
-
}
|
|
123
|
-
throw new Error(shellSessionDisposedMessage);
|
|
124
|
-
}
|
|
125
|
-
return trackedProcess;
|
|
126
|
-
}
|
|
127
|
-
async listProcesses() {
|
|
128
|
-
return [...this.#processes];
|
|
129
|
-
}
|
|
130
|
-
dispose() {
|
|
131
|
-
this.#disposed = true;
|
|
132
|
-
if (this.#disposeTask) return this.#disposeTask;
|
|
133
|
-
this.#disposeTask = (async () => {
|
|
134
|
-
await Promise.all(this.#starts);
|
|
135
|
-
const failures = [];
|
|
136
|
-
for (const process of [...this.#processes].reverse()) try {
|
|
137
|
-
await process.stop();
|
|
138
|
-
} catch (error) {
|
|
139
|
-
failures.push(error);
|
|
140
|
-
}
|
|
141
|
-
if (failures.length === 1) throw failures[0];
|
|
142
|
-
if (failures.length > 1) throw new AggregateError(failures, "[vitehub] Shell session failed to stop multiple background processes.");
|
|
143
|
-
return {
|
|
144
|
-
event: "session_disposed",
|
|
145
|
-
exitCode: null,
|
|
146
|
-
stderr: "",
|
|
147
|
-
stdout: ""
|
|
148
|
-
};
|
|
149
|
-
})().catch((error) => {
|
|
150
|
-
this.#disposeTask = void 0;
|
|
151
|
-
throw error;
|
|
152
|
-
});
|
|
153
|
-
return this.#disposeTask;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
function createShellRuntime(options) {
|
|
157
|
-
const { provider } = options;
|
|
158
|
-
const policy = options.policy ?? {};
|
|
159
|
-
return {
|
|
160
|
-
boundary: provider.boundary,
|
|
161
|
-
createSession(sessionOptions = {}) {
|
|
162
|
-
return new RuntimeShellSession(provider, {
|
|
163
|
-
...policy,
|
|
164
|
-
...sessionOptions.policy
|
|
165
|
-
}, sessionOptions.env);
|
|
166
|
-
},
|
|
167
|
-
async exec(command, execOptions = {}) {
|
|
168
|
-
const session = new RuntimeShellSession(provider, policy);
|
|
169
|
-
try {
|
|
170
|
-
return await session.exec(command, execOptions);
|
|
171
|
-
} finally {
|
|
172
|
-
await session.dispose();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
//#endregion
|
|
178
|
-
export { createShellRuntime as t };
|