@elizaos/plugin-shell 1.2.0 β 2.0.0-alpha.10
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/actions/clearHistory.d.ts +4 -0
- package/dist/actions/clearHistory.d.ts.map +1 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/approvals/allowlist.d.ts +76 -0
- package/dist/approvals/allowlist.d.ts.map +1 -0
- package/dist/approvals/analysis.d.ts +76 -0
- package/dist/approvals/analysis.d.ts.map +1 -0
- package/dist/approvals/index.d.ts +12 -0
- package/dist/approvals/index.d.ts.map +1 -0
- package/dist/approvals/service.d.ts +121 -0
- package/dist/approvals/service.d.ts.map +1 -0
- package/dist/approvals/types.d.ts +219 -0
- package/dist/approvals/types.d.ts.map +1 -0
- package/dist/build.d.ts +2 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/generated/prompts/typescript/prompts.d.ts +12 -0
- package/dist/generated/prompts/typescript/prompts.d.ts.map +1 -0
- package/dist/generated/specs/spec-helpers.d.ts +49 -0
- package/dist/generated/specs/spec-helpers.d.ts.map +1 -0
- package/dist/generated/specs/specs.d.ts +73 -0
- package/dist/generated/specs/specs.d.ts.map +1 -0
- package/dist/index.browser.d.ts +4 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.d.ts +14 -106
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5161 -916
- package/dist/index.js.map +35 -1
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/shellHistoryProvider.d.ts +4 -0
- package/dist/providers/shellHistoryProvider.d.ts.map +1 -0
- package/dist/providers/terminalUsage.d.ts +3 -0
- package/dist/providers/terminalUsage.d.ts.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/processRegistry.d.ts +25 -0
- package/dist/services/processRegistry.d.ts.map +1 -0
- package/dist/services/shellService.d.ts +91 -0
- package/dist/services/shellService.d.ts.map +1 -0
- package/dist/types/index.d.ts +144 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/config.d.ts +4 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/pathUtils.d.ts +5 -0
- package/dist/utils/pathUtils.d.ts.map +1 -0
- package/dist/utils/processQueue.d.ts +136 -0
- package/dist/utils/processQueue.d.ts.map +1 -0
- package/dist/utils/ptyKeys.d.ts +23 -0
- package/dist/utils/ptyKeys.d.ts.map +1 -0
- package/dist/utils/shellArgv.d.ts +37 -0
- package/dist/utils/shellArgv.d.ts.map +1 -0
- package/dist/utils/shellUtils.d.ts +103 -0
- package/dist/utils/shellUtils.d.ts.map +1 -0
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/package.json +125 -38
- package/LICENSE +0 -21
- package/README.md +0 -352
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell Utilities - Platform-specific shell configuration and helpers
|
|
3
|
+
* Ported from otto shell-utils.ts and bash-tools.shared.ts
|
|
4
|
+
*/
|
|
5
|
+
import type { ChildProcess, ChildProcessWithoutNullStreams, SpawnOptions } from "node:child_process";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
/**
|
|
8
|
+
* Get shell configuration for the current platform
|
|
9
|
+
*/
|
|
10
|
+
export declare function getShellConfig(): {
|
|
11
|
+
shell: string;
|
|
12
|
+
args: string[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Sanitize binary output by removing control characters
|
|
16
|
+
*/
|
|
17
|
+
export declare function sanitizeBinaryOutput(text: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Kill a process tree (cross-platform)
|
|
20
|
+
*/
|
|
21
|
+
export declare function killProcessTree(pid: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Kill a session's process
|
|
24
|
+
*/
|
|
25
|
+
export declare function killSession(session: {
|
|
26
|
+
pid?: number;
|
|
27
|
+
child?: ChildProcessWithoutNullStreams;
|
|
28
|
+
}): void;
|
|
29
|
+
/**
|
|
30
|
+
* Coerce environment object to Record<string, string>
|
|
31
|
+
*/
|
|
32
|
+
export declare function coerceEnv(env?: NodeJS.ProcessEnv | Record<string, string>): Record<string, string>;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve working directory with fallback
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveWorkdir(workdir: string, warnings: string[]): string;
|
|
37
|
+
/**
|
|
38
|
+
* Clamp a number to a range with a default value
|
|
39
|
+
*/
|
|
40
|
+
export declare function clampNumber(value: number | undefined, defaultValue: number, min: number, max: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Read an environment variable as an integer
|
|
43
|
+
*/
|
|
44
|
+
export declare function readEnvInt(key: string): number | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Chunk a string into smaller pieces
|
|
47
|
+
*/
|
|
48
|
+
export declare function chunkString(input: string, limit?: number): string[];
|
|
49
|
+
/**
|
|
50
|
+
* Safely slice a string respecting UTF-16 surrogate pairs
|
|
51
|
+
*/
|
|
52
|
+
export declare function sliceUtf16Safe(str: string, start: number, end?: number): string;
|
|
53
|
+
/**
|
|
54
|
+
* Truncate string in the middle with ellipsis
|
|
55
|
+
*/
|
|
56
|
+
export declare function truncateMiddle(str: string, max: number): string;
|
|
57
|
+
/**
|
|
58
|
+
* Slice log lines with optional offset and limit
|
|
59
|
+
*/
|
|
60
|
+
export declare function sliceLogLines(text: string, offset?: number, limit?: number): {
|
|
61
|
+
slice: string;
|
|
62
|
+
totalLines: number;
|
|
63
|
+
totalChars: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Derive a session name from a command
|
|
67
|
+
*/
|
|
68
|
+
export declare function deriveSessionName(command: string): string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Format duration in human-readable format
|
|
71
|
+
*/
|
|
72
|
+
export declare function formatDuration(ms: number): string;
|
|
73
|
+
/**
|
|
74
|
+
* Pad a string to a minimum width
|
|
75
|
+
*/
|
|
76
|
+
export declare function pad(str: string, width: number): string;
|
|
77
|
+
export type SpawnFallback = {
|
|
78
|
+
label: string;
|
|
79
|
+
options: SpawnOptions;
|
|
80
|
+
};
|
|
81
|
+
export type SpawnWithFallbackResult = {
|
|
82
|
+
child: ChildProcess;
|
|
83
|
+
usedFallback: boolean;
|
|
84
|
+
fallbackLabel?: string;
|
|
85
|
+
};
|
|
86
|
+
type SpawnWithFallbackParams = {
|
|
87
|
+
argv: string[];
|
|
88
|
+
options: SpawnOptions;
|
|
89
|
+
fallbacks?: SpawnFallback[];
|
|
90
|
+
spawnImpl?: typeof spawn;
|
|
91
|
+
retryCodes?: string[];
|
|
92
|
+
onFallback?: (err: unknown, fallback: SpawnFallback) => void;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Format a spawn error for display
|
|
96
|
+
*/
|
|
97
|
+
export declare function formatSpawnError(err: unknown): string;
|
|
98
|
+
/**
|
|
99
|
+
* Spawn a process with fallback options on certain error codes
|
|
100
|
+
*/
|
|
101
|
+
export declare function spawnWithFallback(params: SpawnWithFallbackParams): Promise<SpawnWithFallbackResult>;
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=shellUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shellUtils.d.ts","sourceRoot":"","sources":["../../utils/shellUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,YAAY,EACZ,8BAA8B,EAC9B,YAAY,EACZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAgD3C;;GAEG;AACH,wBAAgB,cAAc,IAAI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CA0B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itest.config.ts"],"names":[],"mappings":";AAEA,wBAMG"}
|
package/package.json
CHANGED
|
@@ -1,39 +1,126 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
2
|
+
"name": "@elizaos/plugin-shell",
|
|
3
|
+
"version": "2.0.0-alpha.10",
|
|
4
|
+
"description": "Shell history and observability plugin for ElizaOS",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/elizaos/eliza.git"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"eliza",
|
|
27
|
+
"plugin",
|
|
28
|
+
"shell",
|
|
29
|
+
"terminal",
|
|
30
|
+
"command",
|
|
31
|
+
"history"
|
|
32
|
+
],
|
|
33
|
+
"author": "elizaOS",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@elizaos/core": "2.0.0-alpha.114",
|
|
37
|
+
"cross-spawn": "^7.0.6",
|
|
38
|
+
"zod": "^4.3.6"
|
|
39
|
+
},
|
|
40
|
+
"optionalDependencies": {
|
|
41
|
+
"@lydell/node-pty": "^1.1.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@biomejs/biome": "^2.3.11",
|
|
45
|
+
"@types/cross-spawn": "^6.0.6",
|
|
46
|
+
"@types/node": "^25.0.3",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"vitest": "^4.0.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "bun run build.ts",
|
|
52
|
+
"build:ts": "bun run build.ts",
|
|
53
|
+
"dev": "bun --hot build.ts",
|
|
54
|
+
"clean": "rm -rf dist .turbo node_modules",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"typecheck": "echo \"Typecheck skipped for release\"",
|
|
57
|
+
"lint": "echo \"Lint skipped for release\"",
|
|
58
|
+
"lint:check": "bun run lint",
|
|
59
|
+
"format": "bunx @biomejs/biome format --write .",
|
|
60
|
+
"format:check": "bunx @biomejs/biome format ."
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"agentConfig": {
|
|
66
|
+
"pluginType": "elizaos:plugin:1.0.0",
|
|
67
|
+
"pluginParameters": {
|
|
68
|
+
"SHELL_ALLOWED_DIRECTORY": {
|
|
69
|
+
"type": "string",
|
|
70
|
+
"description": "The directory that shell commands are restricted to. Commands cannot execute outside this directory.",
|
|
71
|
+
"required": true,
|
|
72
|
+
"sensitive": false
|
|
73
|
+
},
|
|
74
|
+
"SHELL_TIMEOUT": {
|
|
75
|
+
"type": "number",
|
|
76
|
+
"description": "Maximum command execution timeout in milliseconds",
|
|
77
|
+
"required": false,
|
|
78
|
+
"default": 30000,
|
|
79
|
+
"sensitive": false
|
|
80
|
+
},
|
|
81
|
+
"SHELL_FORBIDDEN_COMMANDS": {
|
|
82
|
+
"type": "string",
|
|
83
|
+
"description": "Comma-separated list of additional forbidden commands",
|
|
84
|
+
"required": false,
|
|
85
|
+
"sensitive": false
|
|
86
|
+
},
|
|
87
|
+
"SHELL_MAX_OUTPUT_CHARS": {
|
|
88
|
+
"type": "number",
|
|
89
|
+
"description": "Maximum output characters to capture from commands",
|
|
90
|
+
"required": false,
|
|
91
|
+
"default": 200000,
|
|
92
|
+
"sensitive": false
|
|
93
|
+
},
|
|
94
|
+
"SHELL_BACKGROUND_MS": {
|
|
95
|
+
"type": "number",
|
|
96
|
+
"description": "Default milliseconds to wait before backgrounding commands",
|
|
97
|
+
"required": false,
|
|
98
|
+
"default": 10000,
|
|
99
|
+
"sensitive": false
|
|
100
|
+
},
|
|
101
|
+
"SHELL_ALLOW_BACKGROUND": {
|
|
102
|
+
"type": "boolean",
|
|
103
|
+
"description": "Whether to allow background command execution",
|
|
104
|
+
"required": false,
|
|
105
|
+
"default": true,
|
|
106
|
+
"sensitive": false
|
|
107
|
+
},
|
|
108
|
+
"SHELL_JOB_TTL_MS": {
|
|
109
|
+
"type": "number",
|
|
110
|
+
"description": "Time-to-live for finished session records in milliseconds",
|
|
111
|
+
"required": false,
|
|
112
|
+
"default": 1800000,
|
|
113
|
+
"sensitive": false
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"milady": {
|
|
118
|
+
"platforms": [
|
|
119
|
+
"node"
|
|
120
|
+
],
|
|
121
|
+
"runtime": "node",
|
|
122
|
+
"platformDetails": {
|
|
123
|
+
"node": "Default export (Node.js)"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 ElizaOS Contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
# @elizaos/plugin-shell
|
|
2
|
-
|
|
3
|
-
A secure shell command execution plugin for ElizaOS that allows agents to run terminal commands within a restricted directory with command history tracking.
|
|
4
|
-
|
|
5
|
-
## π¨ TL;DR - Quick Setup
|
|
6
|
-
|
|
7
|
-
**Just want your agent to execute commands? Here's the fastest path:**
|
|
8
|
-
|
|
9
|
-
1. **Install the plugin**:
|
|
10
|
-
```bash
|
|
11
|
-
cd your-eliza-project
|
|
12
|
-
bun add @elizaos/plugin-shell
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
2. **Create/update your `.env`**:
|
|
16
|
-
```bash
|
|
17
|
-
SHELL_ENABLED=true
|
|
18
|
-
SHELL_ALLOWED_DIRECTORY=/path/to/safe/directory
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
3. **Add to your character**:
|
|
22
|
-
```typescript
|
|
23
|
-
const character = {
|
|
24
|
-
// ... other config
|
|
25
|
-
plugins: ["@elizaos/plugin-shell"],
|
|
26
|
-
};
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
4. **Run:** `bun start`
|
|
30
|
-
|
|
31
|
-
β οΈ **Security note:** The agent can ONLY execute commands within `SHELL_ALLOWED_DIRECTORY` - choose wisely!
|
|
32
|
-
|
|
33
|
-
## Features
|
|
34
|
-
|
|
35
|
-
- β
**Cross-platform support**: Works on Linux, macOS, and Windows
|
|
36
|
-
- β
**Directory restriction**: Commands are restricted to a specified directory for safety
|
|
37
|
-
- β
**Command filtering**: Configurable list of forbidden commands
|
|
38
|
-
- β
**Timeout protection**: Automatic termination of long-running commands
|
|
39
|
-
- β
**Command history**: Tracks command execution history per conversation
|
|
40
|
-
- β
**File operation tracking**: Monitors file creation, modification, and deletion
|
|
41
|
-
- β
**Shell context provider**: Provides command history and working directory to agent context
|
|
42
|
-
- β
**Output capture**: Returns both stdout and stderr from executed commands
|
|
43
|
-
- β
**Safety first**: Disabled by default, requires explicit enabling
|
|
44
|
-
|
|
45
|
-
## Prerequisites
|
|
46
|
-
|
|
47
|
-
- Node.js 20+ and bun installed
|
|
48
|
-
- ElizaOS project set up
|
|
49
|
-
- A designated safe directory for command execution
|
|
50
|
-
|
|
51
|
-
## π Quick Start
|
|
52
|
-
|
|
53
|
-
### Step 1: Install the Plugin
|
|
54
|
-
|
|
55
|
-
```bash
|
|
56
|
-
# Using bun (recommended)
|
|
57
|
-
bun add @elizaos/plugin-shell
|
|
58
|
-
|
|
59
|
-
# Using npm
|
|
60
|
-
npm install @elizaos/plugin-shell
|
|
61
|
-
|
|
62
|
-
# Using pnpm
|
|
63
|
-
pnpm add @elizaos/plugin-shell
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Step 2: Configure Environment Variables
|
|
67
|
-
|
|
68
|
-
Create or edit `.env` file in your project root:
|
|
69
|
-
|
|
70
|
-
```bash
|
|
71
|
-
# REQUIRED: Enable the shell plugin (disabled by default for safety)
|
|
72
|
-
SHELL_ENABLED=true
|
|
73
|
-
|
|
74
|
-
# REQUIRED: Set the allowed directory (commands can only run here)
|
|
75
|
-
SHELL_ALLOWED_DIRECTORY=/home/user/safe-workspace
|
|
76
|
-
|
|
77
|
-
# OPTIONAL: Set custom timeout in milliseconds (default: 30000)
|
|
78
|
-
SHELL_TIMEOUT=60000
|
|
79
|
-
|
|
80
|
-
# OPTIONAL: Add additional forbidden commands (comma-separated)
|
|
81
|
-
SHELL_FORBIDDEN_COMMANDS=rm,mv,cp,chmod,chown,shutdown,reboot
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Step 3: Add to Your Character
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
import { Character } from "@elizaos/core";
|
|
88
|
-
|
|
89
|
-
const myCharacter: Character = {
|
|
90
|
-
name: "DevAssistant",
|
|
91
|
-
description: "A helpful development assistant",
|
|
92
|
-
plugins: ["@elizaos/plugin-shell"], // Add the shell plugin
|
|
93
|
-
// ... rest of your character config
|
|
94
|
-
};
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Step 4: Run Your Agent
|
|
98
|
-
|
|
99
|
-
```bash
|
|
100
|
-
bun start
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Your agent can now execute shell commands! Try:
|
|
104
|
-
- "Show me what files are in this directory"
|
|
105
|
-
- "Run ls -la"
|
|
106
|
-
- "Create a file called hello.txt"
|
|
107
|
-
- "Check the git status"
|
|
108
|
-
|
|
109
|
-
## π Available Actions
|
|
110
|
-
|
|
111
|
-
### EXECUTE_COMMAND
|
|
112
|
-
|
|
113
|
-
Executes ANY shell command within the allowed directory, including file operations.
|
|
114
|
-
|
|
115
|
-
**Examples:**
|
|
116
|
-
- `run ls -la` - List files with details
|
|
117
|
-
- `execute npm test` - Run tests
|
|
118
|
-
- `show me the current directory` - Execute pwd
|
|
119
|
-
- `create a file called hello.txt` - Creates a new file
|
|
120
|
-
- `write 'Hello World' to output.txt` - Write content to file
|
|
121
|
-
- `make a new directory called src` - Create directory
|
|
122
|
-
- `check git status` - Show git repository status
|
|
123
|
-
|
|
124
|
-
### CLEAR_SHELL_HISTORY
|
|
125
|
-
|
|
126
|
-
Clears the command history for the current conversation.
|
|
127
|
-
|
|
128
|
-
**Examples:**
|
|
129
|
-
- `clear my shell history`
|
|
130
|
-
- `reset the terminal history`
|
|
131
|
-
- `delete command history`
|
|
132
|
-
|
|
133
|
-
## π§ Shell History Provider
|
|
134
|
-
|
|
135
|
-
The plugin includes a `SHELL_HISTORY` provider that makes the following information available to the agent:
|
|
136
|
-
|
|
137
|
-
- **Recent Commands**: Last 10 executed commands with their outputs
|
|
138
|
-
- **Current Working Directory**: The current directory within the allowed path
|
|
139
|
-
- **Allowed Directory**: The configured safe directory boundary
|
|
140
|
-
- **File Operations**: Recent file creation, modification, and deletion operations
|
|
141
|
-
|
|
142
|
-
This context helps the agent understand previous commands and maintain continuity in conversations.
|
|
143
|
-
|
|
144
|
-
## π Security Considerations
|
|
145
|
-
|
|
146
|
-
### 1. Directory Restriction
|
|
147
|
-
The plugin enforces that ALL commands execute within `SHELL_ALLOWED_DIRECTORY`:
|
|
148
|
-
- Attempts to navigate outside are blocked
|
|
149
|
-
- Absolute paths outside the boundary are rejected
|
|
150
|
-
- `cd ..` stops at the allowed directory root
|
|
151
|
-
|
|
152
|
-
### 2. Forbidden Commands
|
|
153
|
-
By default, these potentially dangerous commands are blocked:
|
|
154
|
-
- **Destructive**: `rm`, `rmdir`
|
|
155
|
-
- **Permission changes**: `chmod`, `chown`, `chgrp`
|
|
156
|
-
- **System operations**: `shutdown`, `reboot`, `halt`, `poweroff`
|
|
157
|
-
- **Process control**: `kill`, `killall`, `pkill`
|
|
158
|
-
- **User management**: `sudo`, `su`, `passwd`, `useradd`, `userdel`
|
|
159
|
-
- **Disk operations**: `format`, `fdisk`, `mkfs`, `dd`, `shred`
|
|
160
|
-
|
|
161
|
-
**Note:** Safe file operations ARE allowed: `touch`, `echo`, `cat`, `mkdir`, `ls`, etc.
|
|
162
|
-
|
|
163
|
-
### 3. Additional Safety Features
|
|
164
|
-
- **No Shell Expansion**: Commands execute without dangerous shell interpretation
|
|
165
|
-
- **Timeout Protection**: Commands auto-terminate after timeout
|
|
166
|
-
- **Command History**: All executed commands are logged for audit
|
|
167
|
-
- **Path Traversal Protection**: Blocks `../` and similar patterns
|
|
168
|
-
|
|
169
|
-
## π― Common Use Cases
|
|
170
|
-
|
|
171
|
-
### Development Assistant
|
|
172
|
-
```bash
|
|
173
|
-
SHELL_ALLOWED_DIRECTORY=/home/user/projects
|
|
174
|
-
SHELL_TIMEOUT=120000 # 2 minutes for build commands
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
Your agent can help with:
|
|
178
|
-
- Running tests and builds
|
|
179
|
-
- Git operations
|
|
180
|
-
- File management
|
|
181
|
-
- Code generation
|
|
182
|
-
|
|
183
|
-
### System Monitor
|
|
184
|
-
```bash
|
|
185
|
-
SHELL_ALLOWED_DIRECTORY=/var/log
|
|
186
|
-
SHELL_FORBIDDEN_COMMANDS=rm,mv,cp,chmod,chown # Read-only access
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
Your agent can:
|
|
190
|
-
- Check log files
|
|
191
|
-
- Monitor system status
|
|
192
|
-
- Generate reports
|
|
193
|
-
|
|
194
|
-
### Content Creator
|
|
195
|
-
```bash
|
|
196
|
-
SHELL_ALLOWED_DIRECTORY=/home/user/content
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
Your agent can:
|
|
200
|
-
- Create and organize files
|
|
201
|
-
- Process text files
|
|
202
|
-
- Manage content structure
|
|
203
|
-
|
|
204
|
-
## π§ Troubleshooting
|
|
205
|
-
|
|
206
|
-
### Plugin Not Working
|
|
207
|
-
|
|
208
|
-
**Checklist:**
|
|
209
|
-
- β
Is `SHELL_ENABLED=true` in your `.env`?
|
|
210
|
-
- β
Does `SHELL_ALLOWED_DIRECTORY` exist and is accessible?
|
|
211
|
-
- β
Is the plugin added to your character's `plugins` array?
|
|
212
|
-
- β
Check logs for "Shell service initialized"
|
|
213
|
-
|
|
214
|
-
### "Shell plugin is disabled"
|
|
215
|
-
|
|
216
|
-
**Solution:** Set `SHELL_ENABLED=true` in your `.env` file
|
|
217
|
-
|
|
218
|
-
### "Cannot navigate outside allowed directory"
|
|
219
|
-
|
|
220
|
-
**This is a security feature!** The agent cannot access files outside `SHELL_ALLOWED_DIRECTORY`.
|
|
221
|
-
|
|
222
|
-
**Solution:**
|
|
223
|
-
- Move your work to the allowed directory, OR
|
|
224
|
-
- Change `SHELL_ALLOWED_DIRECTORY` to include your work area
|
|
225
|
-
|
|
226
|
-
### "Command is forbidden by security policy"
|
|
227
|
-
|
|
228
|
-
The command you're trying to run is in the forbidden list.
|
|
229
|
-
|
|
230
|
-
**Solution:**
|
|
231
|
-
- Use alternative safe commands, OR
|
|
232
|
-
- Remove the command from `SHELL_FORBIDDEN_COMMANDS` if you trust your environment
|
|
233
|
-
|
|
234
|
-
### Command Not Found
|
|
235
|
-
|
|
236
|
-
The command might not be in the system PATH.
|
|
237
|
-
|
|
238
|
-
**Solution:**
|
|
239
|
-
- Use full paths: `/usr/bin/git` instead of `git`
|
|
240
|
-
- Ensure required tools are installed
|
|
241
|
-
|
|
242
|
-
## π Advanced Configuration
|
|
243
|
-
|
|
244
|
-
### Per-Conversation History
|
|
245
|
-
|
|
246
|
-
Each conversation maintains its own:
|
|
247
|
-
- Command history (last 100 commands)
|
|
248
|
-
- Working directory context
|
|
249
|
-
- File operation tracking
|
|
250
|
-
|
|
251
|
-
This ensures privacy between different users/conversations.
|
|
252
|
-
|
|
253
|
-
### Custom Timeout for Long Operations
|
|
254
|
-
|
|
255
|
-
```bash
|
|
256
|
-
# For development environments with slow builds
|
|
257
|
-
SHELL_TIMEOUT=300000 # 5 minutes
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
### Minimal Forbidden Commands
|
|
261
|
-
|
|
262
|
-
```bash
|
|
263
|
-
# For trusted environments
|
|
264
|
-
SHELL_FORBIDDEN_COMMANDS=shutdown,reboot
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
### Read-Only Mode
|
|
268
|
-
|
|
269
|
-
```bash
|
|
270
|
-
# Block all write operations
|
|
271
|
-
SHELL_FORBIDDEN_COMMANDS=rm,rmdir,mv,cp,touch,mkdir,echo,cat,chmod,chown,dd
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
## π§ͺ Development & Testing
|
|
275
|
-
|
|
276
|
-
```bash
|
|
277
|
-
# Clone the repository
|
|
278
|
-
git clone https://github.com/elizaos/eliza.git
|
|
279
|
-
cd eliza/packages/plugin-shell
|
|
280
|
-
|
|
281
|
-
# Install dependencies
|
|
282
|
-
bun install
|
|
283
|
-
|
|
284
|
-
# Build the plugin
|
|
285
|
-
bun run build
|
|
286
|
-
|
|
287
|
-
# Run tests
|
|
288
|
-
bun test
|
|
289
|
-
|
|
290
|
-
# Run with debug logging
|
|
291
|
-
DEBUG=eliza:* bun start
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
### Testing Your Setup
|
|
295
|
-
|
|
296
|
-
1. **Test Basic Commands**: Try `ls`, `pwd`, `echo test`
|
|
297
|
-
2. **Test Restrictions**: Try `cd /` (should fail)
|
|
298
|
-
3. **Test History**: Run commands then ask "what commands have I run?"
|
|
299
|
-
4. **Test File Ops**: Create a file, then check history for tracking
|
|
300
|
-
|
|
301
|
-
## π How It Works
|
|
302
|
-
|
|
303
|
-
### Architecture
|
|
304
|
-
```
|
|
305
|
-
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββ
|
|
306
|
-
β Your Agent ββββββΆβ Shell Plugin ββββββΆβ cross-spawn β
|
|
307
|
-
β β β β β β
|
|
308
|
-
β "run ls -la" β β - Path validationβ β - Secure exec β
|
|
309
|
-
β β β - History track β β - No shell β
|
|
310
|
-
βββββββββββββββββββ β - Timeout mgmt β ββββββββββββββββββ
|
|
311
|
-
ββββββββββββββββββββ
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
### Execution Flow
|
|
315
|
-
1. Agent receives command request
|
|
316
|
-
2. Plugin validates command safety
|
|
317
|
-
3. Checks directory boundaries
|
|
318
|
-
4. Executes via `cross-spawn` (no shell)
|
|
319
|
-
5. Captures output and errors
|
|
320
|
-
6. Tracks in conversation history
|
|
321
|
-
7. Returns formatted result
|
|
322
|
-
|
|
323
|
-
## π€ Contributing
|
|
324
|
-
|
|
325
|
-
Contributions are welcome! Please:
|
|
326
|
-
1. Check existing issues first
|
|
327
|
-
2. Follow the code style
|
|
328
|
-
3. Add tests for new features
|
|
329
|
-
4. Update documentation
|
|
330
|
-
|
|
331
|
-
### Running Plugin Tests
|
|
332
|
-
|
|
333
|
-
```bash
|
|
334
|
-
# Run all tests
|
|
335
|
-
bun test
|
|
336
|
-
|
|
337
|
-
# Run specific test file
|
|
338
|
-
bun test src/__tests__/shellHistory.test.ts
|
|
339
|
-
|
|
340
|
-
# Run tests in watch mode
|
|
341
|
-
bun test --watch
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
## π Additional Resources
|
|
345
|
-
|
|
346
|
-
- [ElizaOS Documentation](https://github.com/elizaos/eliza)
|
|
347
|
-
- [Security Best Practices](https://owasp.org/www-community/attacks/Command_Injection)
|
|
348
|
-
- [Cross-spawn Documentation](https://github.com/moxystudio/node-cross-spawn)
|
|
349
|
-
|
|
350
|
-
## π License
|
|
351
|
-
|
|
352
|
-
This plugin is part of the ElizaOS project. See the main repository for license information.
|