havensdk-plugin-shell 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/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +120 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HavenPlugin } from "havensdk";
|
|
2
|
+
export interface ShellPluginOptions {
|
|
3
|
+
allowedCommands?: string[];
|
|
4
|
+
blockedCommands?: string[];
|
|
5
|
+
timeout?: number;
|
|
6
|
+
maxOutput?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function pluginShell(options?: ShellPluginOptions): HavenPlugin;
|
|
9
|
+
export default pluginShell;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,UAAU,CAAC;AAG9D,MAAM,WAAW,kBAAkB;IACjC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAgBD,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW,CAqHrE;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pluginShell = pluginShell;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const DEFAULT_BLOCKED_PATTERNS = [
|
|
6
|
+
/\brm\s+(-\w*r\w*f\s+|.*--no-preserve-root)/i, // rm -rf, rm --no-preserve-root
|
|
7
|
+
/\bdel\s+\/s\b/i, // Windows del /s
|
|
8
|
+
/\bformat\s+[a-zA-Z]:/i, // Windows format drive
|
|
9
|
+
/\bmkfs\b/i,
|
|
10
|
+
/\bdd\s+if=/i,
|
|
11
|
+
/:\(\)\{.*:\|.*&\}/, // fork bomb
|
|
12
|
+
/\bshutdown\b/i,
|
|
13
|
+
/\breboot\b/i,
|
|
14
|
+
/\bhalt\b/i,
|
|
15
|
+
/\bpoweroff\b/i,
|
|
16
|
+
/>\s*\/dev\/(sda|nvme|hda)/i, // write to block device
|
|
17
|
+
];
|
|
18
|
+
function pluginShell(options) {
|
|
19
|
+
const defaultTimeout = options?.timeout ?? 30000;
|
|
20
|
+
const maxOutput = options?.maxOutput ?? 100000;
|
|
21
|
+
const blockedPatterns = [...DEFAULT_BLOCKED_PATTERNS, ...(options?.blockedCommands ?? [])];
|
|
22
|
+
return {
|
|
23
|
+
name: "havensdk-plugin-shell",
|
|
24
|
+
version: "0.0.1",
|
|
25
|
+
tools: [
|
|
26
|
+
{
|
|
27
|
+
name: "shell_run",
|
|
28
|
+
description: "Execute a shell command and return output",
|
|
29
|
+
parameters: {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
command: { type: "string", description: "Command to execute" },
|
|
33
|
+
cwd: { type: "string", description: "Working directory (defaults to agent cwd)" },
|
|
34
|
+
timeout: { type: "number", description: "Timeout in ms" },
|
|
35
|
+
env: { type: "object", description: "Environment variables" },
|
|
36
|
+
},
|
|
37
|
+
required: ["command"],
|
|
38
|
+
},
|
|
39
|
+
execute: async (input, ctx) => {
|
|
40
|
+
const { command, cwd, timeout: cmdTimeout, env } = input;
|
|
41
|
+
const tokens = command.trim().split(/\s+/);
|
|
42
|
+
let binary = "";
|
|
43
|
+
for (const token of tokens) {
|
|
44
|
+
if (token.includes("=") && !token.includes("/"))
|
|
45
|
+
continue;
|
|
46
|
+
binary = token.split("/").pop() ?? token;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
if (options?.allowedCommands && options.allowedCommands.length > 0) {
|
|
50
|
+
if (!options.allowedCommands.includes(binary)) {
|
|
51
|
+
return { error: `Command not in allowed list: ${binary}`, exitCode: -1 };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
if (/[|;&$`(){}><\n]/.test(command)) {
|
|
56
|
+
return { error: `Blocked: command contains shell metacharacters. Use allowlist mode for advanced commands.`, exitCode: -1 };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const pattern of blockedPatterns) {
|
|
60
|
+
const isRegex = pattern instanceof RegExp;
|
|
61
|
+
const blocked = isRegex ? pattern.test(command) : command.includes(String(pattern));
|
|
62
|
+
if (blocked) {
|
|
63
|
+
return { error: `Blocked command pattern: ${isRegex ? pattern.source : String(pattern)}`, exitCode: -1 };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const effectiveTimeout = cmdTimeout ?? defaultTimeout;
|
|
67
|
+
const workingDir = cwd ?? ctx.cwd;
|
|
68
|
+
return new Promise((resolve) => {
|
|
69
|
+
const isWindows = process.platform === "win32";
|
|
70
|
+
const shell = isWindows ? "cmd.exe" : "/bin/bash";
|
|
71
|
+
const shellArgs = isWindows ? ["/c", command] : ["-c", command];
|
|
72
|
+
const proc = (0, child_process_1.spawn)(shell, shellArgs, {
|
|
73
|
+
cwd: workingDir,
|
|
74
|
+
env: { ...process.env, ...env },
|
|
75
|
+
});
|
|
76
|
+
let stdout = "";
|
|
77
|
+
let stderr = "";
|
|
78
|
+
let killed = false;
|
|
79
|
+
proc.stdout.on("data", (data) => {
|
|
80
|
+
if (stdout.length < maxOutput) {
|
|
81
|
+
stdout += data.toString();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
proc.stderr.on("data", (data) => {
|
|
85
|
+
if (stderr.length < maxOutput) {
|
|
86
|
+
stderr += data.toString();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const timer = setTimeout(() => {
|
|
90
|
+
killed = true;
|
|
91
|
+
proc.kill("SIGTERM");
|
|
92
|
+
}, effectiveTimeout);
|
|
93
|
+
proc.on("close", (code) => {
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
resolve({
|
|
96
|
+
command,
|
|
97
|
+
exitCode: killed ? -1 : (code ?? 0),
|
|
98
|
+
stdout: stdout.trim(),
|
|
99
|
+
stderr: stderr.trim(),
|
|
100
|
+
timedOut: killed,
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
proc.on("error", (err) => {
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
resolve({
|
|
106
|
+
command,
|
|
107
|
+
exitCode: -1,
|
|
108
|
+
stdout: "",
|
|
109
|
+
stderr: err.message,
|
|
110
|
+
timedOut: false,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
exports.default = pluginShell;
|
|
120
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAwBA,kCAqHC;AA5ID,iDAAsC;AAStC,MAAM,wBAAwB,GAAG;IAC/B,6CAA6C,EAAG,gCAAgC;IAChF,gBAAgB,EAAiC,iBAAiB;IAClE,uBAAuB,EAA0B,uBAAuB;IACxE,WAAW;IACX,aAAa;IACb,mBAAmB,EAA8B,YAAY;IAC7D,eAAe;IACf,aAAa;IACb,WAAW;IACX,eAAe;IACf,4BAA4B,EAAqB,wBAAwB;CAC1E,CAAC;AAEF,SAAgB,WAAW,CAAC,OAA4B;IACtD,MAAM,cAAc,GAAG,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC;IACjD,MAAM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AE;4BACxB,YAAY,CAAC,KAAK,CAAC,CAAC;4BACpB,OAAO,CAAC;gCACN,OAAO;gCACP,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;gCACnC,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE;gCACrB,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE;gCACrB,QAAQ,EAAE,MAAM;6BACjB,CAAC,CAAC;wBACL,CAAC,CAAC,CAAC;wBAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;4BACvB,YAAY,CAAC,KAAK,CAAC,CAAC;4BACpB,OAAO,CAAC;gCACN,OAAO;gCACP,QAAQ,EAAE,CAAC,CAAC;gCACZ,MAAM,EAAE,EAAE;gCACV,MAAM,EAAE,GAAG,CAAC,OAAO;gCACnB,QAAQ,EAAE,KAAK;6BAChB,CAAC,CAAC;wBACL,CAAC,CAAC,CAAC;oBACL,CAAC,CAAC,CAAC;gBACL,CAAC;aACF;SACF;KACF,CAAC;AACJ,CAAC;AAED,kBAAe,WAAW,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HavenPlugin } from "havensdk";
|
|
2
|
+
export interface ShellPluginOptions {
|
|
3
|
+
allowedCommands?: string[];
|
|
4
|
+
blockedCommands?: string[];
|
|
5
|
+
timeout?: number;
|
|
6
|
+
maxOutput?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function pluginShell(options?: ShellPluginOptions): HavenPlugin;
|
|
9
|
+
export default pluginShell;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,UAAU,CAAC;AAG9D,MAAM,WAAW,kBAAkB;IACjC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAgBD,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,WAAW,CAqHrE;AAED,eAAe,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
const DEFAULT_BLOCKED_PATTERNS = [
|
|
3
|
+
/\brm\s+(-\w*r\w*f\s+|.*--no-preserve-root)/i, // rm -rf, rm --no-preserve-root
|
|
4
|
+
/\bdel\s+\/s\b/i, // Windows del /s
|
|
5
|
+
/\bformat\s+[a-zA-Z]:/i, // Windows format drive
|
|
6
|
+
/\bmkfs\b/i,
|
|
7
|
+
/\bdd\s+if=/i,
|
|
8
|
+
/:\(\)\{.*:\|.*&\}/, // fork bomb
|
|
9
|
+
/\bshutdown\b/i,
|
|
10
|
+
/\breboot\b/i,
|
|
11
|
+
/\bhalt\b/i,
|
|
12
|
+
/\bpoweroff\b/i,
|
|
13
|
+
/>\s*\/dev\/(sda|nvme|hda)/i, // write to block device
|
|
14
|
+
];
|
|
15
|
+
export function pluginShell(options) {
|
|
16
|
+
const defaultTimeout = options?.timeout ?? 30000;
|
|
17
|
+
const maxOutput = options?.maxOutput ?? 100000;
|
|
18
|
+
const blockedPatterns = [...DEFAULT_BLOCKED_PATTERNS, ...(options?.blockedCommands ?? [])];
|
|
19
|
+
return {
|
|
20
|
+
name: "havensdk-plugin-shell",
|
|
21
|
+
version: "0.0.1",
|
|
22
|
+
tools: [
|
|
23
|
+
{
|
|
24
|
+
name: "shell_run",
|
|
25
|
+
description: "Execute a shell command and return output",
|
|
26
|
+
parameters: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
command: { type: "string", description: "Command to execute" },
|
|
30
|
+
cwd: { type: "string", description: "Working directory (defaults to agent cwd)" },
|
|
31
|
+
timeout: { type: "number", description: "Timeout in ms" },
|
|
32
|
+
env: { type: "object", description: "Environment variables" },
|
|
33
|
+
},
|
|
34
|
+
required: ["command"],
|
|
35
|
+
},
|
|
36
|
+
execute: async (input, ctx) => {
|
|
37
|
+
const { command, cwd, timeout: cmdTimeout, env } = input;
|
|
38
|
+
const tokens = command.trim().split(/\s+/);
|
|
39
|
+
let binary = "";
|
|
40
|
+
for (const token of tokens) {
|
|
41
|
+
if (token.includes("=") && !token.includes("/"))
|
|
42
|
+
continue;
|
|
43
|
+
binary = token.split("/").pop() ?? token;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
if (options?.allowedCommands && options.allowedCommands.length > 0) {
|
|
47
|
+
if (!options.allowedCommands.includes(binary)) {
|
|
48
|
+
return { error: `Command not in allowed list: ${binary}`, exitCode: -1 };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (/[|;&$`(){}><\n]/.test(command)) {
|
|
53
|
+
return { error: `Blocked: command contains shell metacharacters. Use allowlist mode for advanced commands.`, exitCode: -1 };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const pattern of blockedPatterns) {
|
|
57
|
+
const isRegex = pattern instanceof RegExp;
|
|
58
|
+
const blocked = isRegex ? pattern.test(command) : command.includes(String(pattern));
|
|
59
|
+
if (blocked) {
|
|
60
|
+
return { error: `Blocked command pattern: ${isRegex ? pattern.source : String(pattern)}`, exitCode: -1 };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const effectiveTimeout = cmdTimeout ?? defaultTimeout;
|
|
64
|
+
const workingDir = cwd ?? ctx.cwd;
|
|
65
|
+
return new Promise((resolve) => {
|
|
66
|
+
const isWindows = process.platform === "win32";
|
|
67
|
+
const shell = isWindows ? "cmd.exe" : "/bin/bash";
|
|
68
|
+
const shellArgs = isWindows ? ["/c", command] : ["-c", command];
|
|
69
|
+
const proc = spawn(shell, shellArgs, {
|
|
70
|
+
cwd: workingDir,
|
|
71
|
+
env: { ...process.env, ...env },
|
|
72
|
+
});
|
|
73
|
+
let stdout = "";
|
|
74
|
+
let stderr = "";
|
|
75
|
+
let killed = false;
|
|
76
|
+
proc.stdout.on("data", (data) => {
|
|
77
|
+
if (stdout.length < maxOutput) {
|
|
78
|
+
stdout += data.toString();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
proc.stderr.on("data", (data) => {
|
|
82
|
+
if (stderr.length < maxOutput) {
|
|
83
|
+
stderr += data.toString();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
const timer = setTimeout(() => {
|
|
87
|
+
killed = true;
|
|
88
|
+
proc.kill("SIGTERM");
|
|
89
|
+
}, effectiveTimeout);
|
|
90
|
+
proc.on("close", (code) => {
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
resolve({
|
|
93
|
+
command,
|
|
94
|
+
exitCode: killed ? -1 : (code ?? 0),
|
|
95
|
+
stdout: stdout.trim(),
|
|
96
|
+
stderr: stderr.trim(),
|
|
97
|
+
timedOut: killed,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
proc.on("error", (err) => {
|
|
101
|
+
clearTimeout(timer);
|
|
102
|
+
resolve({
|
|
103
|
+
command,
|
|
104
|
+
exitCode: -1,
|
|
105
|
+
stdout: "",
|
|
106
|
+
stderr: err.message,
|
|
107
|
+
timedOut: false,
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export default pluginShell;
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,C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|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/cjs/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/cjs/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/doanbactam/haven.git"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/doanbactam/haven/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/doanbactam/haven#readme",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"keywords": [
|
|
29
|
+
"plugin",
|
|
30
|
+
"shell",
|
|
31
|
+
"terminal",
|
|
32
|
+
"agents",
|
|
33
|
+
"typescript"
|
|
34
|
+
],
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"engines": {
|
|
37
|
+
"bun": ">=1.3.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc",
|
|
41
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
42
|
+
"test": "bun test",
|
|
43
|
+
"types": "tsc --noEmit",
|
|
44
|
+
"lint": "eslint src/",
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"prepublishOnly": "bun run build && bun run build:cjs && bun run types && bun test"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"havensdk": "workspace:*"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"typescript": "^5.8.2"
|
|
56
|
+
}
|
|
57
|
+
}
|