elizaos-plugin-shell 2.0.0a4__tar.gz
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.
- elizaos_plugin_shell-2.0.0a4/.gitignore +67 -0
- elizaos_plugin_shell-2.0.0a4/LICENSE +28 -0
- elizaos_plugin_shell-2.0.0a4/PKG-INFO +107 -0
- elizaos_plugin_shell-2.0.0a4/README.md +77 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/__init__.py +57 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/_generated_prompts.py +64 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/actions/__init__.py +23 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/actions/clear_history.py +83 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/actions/execute_command.py +225 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/actions/process_action.py +376 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/approvals/__init__.py +121 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/approvals/allowlist.py +595 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/approvals/analysis.py +914 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/approvals/service.py +289 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/approvals/types.py +209 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/generated/specs/__init__.py +1 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/generated/specs/specs.py +153 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/path_utils.py +121 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/process_queue.py +365 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/process_registry.py +463 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/providers/__init__.py +19 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/providers/shell_history.py +134 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/py.typed +0 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/service.py +326 -0
- elizaos_plugin_shell-2.0.0a4/elizaos_plugin_shell/types.py +101 -0
- elizaos_plugin_shell-2.0.0a4/pyproject.toml +106 -0
- elizaos_plugin_shell-2.0.0a4/tests/__init__.py +0 -0
- elizaos_plugin_shell-2.0.0a4/tests/conftest.py +18 -0
- elizaos_plugin_shell-2.0.0a4/tests/test_actions.py +147 -0
- elizaos_plugin_shell-2.0.0a4/tests/test_approvals.py +860 -0
- elizaos_plugin_shell-2.0.0a4/tests/test_integration.py +138 -0
- elizaos_plugin_shell-2.0.0a4/tests/test_path_utils.py +93 -0
- elizaos_plugin_shell-2.0.0a4/tests/test_process_action.py +169 -0
- elizaos_plugin_shell-2.0.0a4/tests/test_process_queue.py +168 -0
- elizaos_plugin_shell-2.0.0a4/tests/test_process_registry.py +180 -0
- elizaos_plugin_shell-2.0.0a4/tests/test_providers.py +130 -0
- elizaos_plugin_shell-2.0.0a4/tests/test_service.py +141 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Build outputs
|
|
2
|
+
dist/
|
|
3
|
+
node_modules/
|
|
4
|
+
|
|
5
|
+
# Environment files
|
|
6
|
+
.env
|
|
7
|
+
.env.local
|
|
8
|
+
.env.production
|
|
9
|
+
.env.staging
|
|
10
|
+
.env.development
|
|
11
|
+
.env.bak
|
|
12
|
+
*.env
|
|
13
|
+
|
|
14
|
+
# OS files
|
|
15
|
+
.DS_Store
|
|
16
|
+
Thumbs.db
|
|
17
|
+
|
|
18
|
+
# IDE files
|
|
19
|
+
.vscode/
|
|
20
|
+
.idea/
|
|
21
|
+
*.swp
|
|
22
|
+
*.swo
|
|
23
|
+
|
|
24
|
+
# Logs
|
|
25
|
+
*.log
|
|
26
|
+
npm-debug.log*
|
|
27
|
+
yarn-debug.log*
|
|
28
|
+
yarn-error.log*
|
|
29
|
+
|
|
30
|
+
# Runtime data
|
|
31
|
+
pids/
|
|
32
|
+
*.pid
|
|
33
|
+
*.seed
|
|
34
|
+
*.pid.lock
|
|
35
|
+
|
|
36
|
+
# Coverage directory used by tools like istanbul
|
|
37
|
+
coverage/
|
|
38
|
+
|
|
39
|
+
# Cache directories
|
|
40
|
+
.cache/
|
|
41
|
+
.npm/
|
|
42
|
+
.eslintcache
|
|
43
|
+
|
|
44
|
+
# Temporary folders
|
|
45
|
+
tmp/
|
|
46
|
+
temp/
|
|
47
|
+
|
|
48
|
+
# Database files
|
|
49
|
+
*.db
|
|
50
|
+
*.pglite
|
|
51
|
+
*.pglite3
|
|
52
|
+
|
|
53
|
+
# ElizaOS specific
|
|
54
|
+
.eliza/
|
|
55
|
+
.elizadb/
|
|
56
|
+
pglite/
|
|
57
|
+
cache/
|
|
58
|
+
dist
|
|
59
|
+
node_modules
|
|
60
|
+
.elizadb
|
|
61
|
+
.turbo
|
|
62
|
+
target/
|
|
63
|
+
__pycache__
|
|
64
|
+
*.pyc
|
|
65
|
+
.venv
|
|
66
|
+
*.egg-info
|
|
67
|
+
package-lock.json
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 elizaOS
|
|
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.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: elizaos-plugin-shell
|
|
3
|
+
Version: 2.0.0a4
|
|
4
|
+
Summary: elizaOS Shell Plugin - Shell command execution with directory restrictions and history tracking
|
|
5
|
+
Project-URL: Homepage, https://github.com/elizaos/eliza
|
|
6
|
+
Project-URL: Documentation, https://elizaos.ai/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/elizaos/eliza
|
|
8
|
+
Author: elizaOS Contributors
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agents,ai,command,elizaos,shell,terminal
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: System :: Shells
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: pydantic>=2.10.0
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: mypy>=1.14.0; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-cov>=6.0.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-xprocess>=1.0.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: ruff>=0.9.0; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# elizaOS Shell Plugin (Python)
|
|
32
|
+
|
|
33
|
+
A secure shell command execution plugin for elizaOS that allows agents to run terminal commands within a restricted directory with command history tracking.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install elizaos-plugin-shell
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- **Cross-platform support**: Works on Linux, macOS, and Windows
|
|
44
|
+
- **Directory restriction**: Commands are restricted to a specified directory for safety
|
|
45
|
+
- **Command filtering**: Configurable list of forbidden commands
|
|
46
|
+
- **Timeout protection**: Automatic termination of long-running commands
|
|
47
|
+
- **Command history**: Tracks command execution history per conversation
|
|
48
|
+
- **File operation tracking**: Monitors file creation, modification, and deletion
|
|
49
|
+
- **Type safe**: Full type annotations with Pydantic models
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
|
|
53
|
+
Set the following environment variables:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Set the allowed directory (commands can only run here)
|
|
57
|
+
SHELL_ALLOWED_DIRECTORY=/path/to/safe/directory
|
|
58
|
+
|
|
59
|
+
# Optional: Set custom timeout in milliseconds (default: 30000)
|
|
60
|
+
SHELL_TIMEOUT=60000
|
|
61
|
+
|
|
62
|
+
# Optional: Add additional forbidden commands (comma-separated)
|
|
63
|
+
SHELL_FORBIDDEN_COMMANDS=rm,mv,cp,chmod,chown,shutdown,reboot
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from elizaos_plugin_shell import ShellService, ShellConfig
|
|
70
|
+
|
|
71
|
+
# Load configuration
|
|
72
|
+
config = ShellConfig.from_env()
|
|
73
|
+
|
|
74
|
+
# Create service
|
|
75
|
+
service = ShellService(config)
|
|
76
|
+
|
|
77
|
+
# Execute a command
|
|
78
|
+
result = await service.execute_command("ls -la", conversation_id="conv-123")
|
|
79
|
+
|
|
80
|
+
if result.success:
|
|
81
|
+
print(f"Output: {result.stdout}")
|
|
82
|
+
else:
|
|
83
|
+
print(f"Error: {result.stderr}")
|
|
84
|
+
|
|
85
|
+
# Get command history
|
|
86
|
+
history = service.get_command_history("conv-123", limit=10)
|
|
87
|
+
|
|
88
|
+
# Clear history
|
|
89
|
+
service.clear_command_history("conv-123")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Security
|
|
93
|
+
|
|
94
|
+
The plugin enforces several security measures:
|
|
95
|
+
|
|
96
|
+
1. **Directory Restriction**: All commands execute within `SHELL_ALLOWED_DIRECTORY`
|
|
97
|
+
2. **Forbidden Commands**: Dangerous commands are blocked by default
|
|
98
|
+
3. **Path Traversal Protection**: Blocks `../` and similar patterns
|
|
99
|
+
4. **No Shell Expansion**: Commands execute without dangerous shell interpretation
|
|
100
|
+
5. **Timeout Protection**: Commands auto-terminate after timeout
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# elizaOS Shell Plugin (Python)
|
|
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
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install elizaos-plugin-shell
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Cross-platform support**: Works on Linux, macOS, and Windows
|
|
14
|
+
- **Directory restriction**: Commands are restricted to a specified directory for safety
|
|
15
|
+
- **Command filtering**: Configurable list of forbidden commands
|
|
16
|
+
- **Timeout protection**: Automatic termination of long-running commands
|
|
17
|
+
- **Command history**: Tracks command execution history per conversation
|
|
18
|
+
- **File operation tracking**: Monitors file creation, modification, and deletion
|
|
19
|
+
- **Type safe**: Full type annotations with Pydantic models
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
Set the following environment variables:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Set the allowed directory (commands can only run here)
|
|
27
|
+
SHELL_ALLOWED_DIRECTORY=/path/to/safe/directory
|
|
28
|
+
|
|
29
|
+
# Optional: Set custom timeout in milliseconds (default: 30000)
|
|
30
|
+
SHELL_TIMEOUT=60000
|
|
31
|
+
|
|
32
|
+
# Optional: Add additional forbidden commands (comma-separated)
|
|
33
|
+
SHELL_FORBIDDEN_COMMANDS=rm,mv,cp,chmod,chown,shutdown,reboot
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from elizaos_plugin_shell import ShellService, ShellConfig
|
|
40
|
+
|
|
41
|
+
# Load configuration
|
|
42
|
+
config = ShellConfig.from_env()
|
|
43
|
+
|
|
44
|
+
# Create service
|
|
45
|
+
service = ShellService(config)
|
|
46
|
+
|
|
47
|
+
# Execute a command
|
|
48
|
+
result = await service.execute_command("ls -la", conversation_id="conv-123")
|
|
49
|
+
|
|
50
|
+
if result.success:
|
|
51
|
+
print(f"Output: {result.stdout}")
|
|
52
|
+
else:
|
|
53
|
+
print(f"Error: {result.stderr}")
|
|
54
|
+
|
|
55
|
+
# Get command history
|
|
56
|
+
history = service.get_command_history("conv-123", limit=10)
|
|
57
|
+
|
|
58
|
+
# Clear history
|
|
59
|
+
service.clear_command_history("conv-123")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Security
|
|
63
|
+
|
|
64
|
+
The plugin enforces several security measures:
|
|
65
|
+
|
|
66
|
+
1. **Directory Restriction**: All commands execute within `SHELL_ALLOWED_DIRECTORY`
|
|
67
|
+
2. **Forbidden Commands**: Dangerous commands are blocked by default
|
|
68
|
+
3. **Path Traversal Protection**: Blocks `../` and similar patterns
|
|
69
|
+
4. **No Shell Expansion**: Commands execute without dangerous shell interpretation
|
|
70
|
+
5. **Timeout Protection**: Commands auto-terminate after timeout
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Actions
|
|
2
|
+
from elizaos_plugin_shell.actions import (
|
|
3
|
+
ClearHistoryAction,
|
|
4
|
+
ExecuteCommandAction,
|
|
5
|
+
get_shell_action_names,
|
|
6
|
+
)
|
|
7
|
+
from elizaos_plugin_shell.path_utils import (
|
|
8
|
+
DEFAULT_FORBIDDEN_COMMANDS,
|
|
9
|
+
extract_base_command,
|
|
10
|
+
is_forbidden_command,
|
|
11
|
+
is_safe_command,
|
|
12
|
+
validate_path,
|
|
13
|
+
)
|
|
14
|
+
from elizaos_plugin_shell.providers import (
|
|
15
|
+
ShellHistoryProvider,
|
|
16
|
+
get_shell_provider_names,
|
|
17
|
+
)
|
|
18
|
+
from elizaos_plugin_shell.service import ShellService
|
|
19
|
+
from elizaos_plugin_shell.types import (
|
|
20
|
+
CommandHistoryEntry,
|
|
21
|
+
CommandResult,
|
|
22
|
+
FileOperation,
|
|
23
|
+
FileOperationType,
|
|
24
|
+
ShellConfig,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
__version__ = "1.2.0"
|
|
28
|
+
|
|
29
|
+
# Plugin metadata
|
|
30
|
+
PLUGIN_NAME = "shell"
|
|
31
|
+
PLUGIN_DESCRIPTION = "Execute shell commands within a restricted directory with history tracking"
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
# Types
|
|
35
|
+
"CommandResult",
|
|
36
|
+
"CommandHistoryEntry",
|
|
37
|
+
"FileOperation",
|
|
38
|
+
"FileOperationType",
|
|
39
|
+
"ShellConfig",
|
|
40
|
+
# Service
|
|
41
|
+
"ShellService",
|
|
42
|
+
# Actions
|
|
43
|
+
"ExecuteCommandAction",
|
|
44
|
+
"ClearHistoryAction",
|
|
45
|
+
"get_shell_action_names",
|
|
46
|
+
# Providers
|
|
47
|
+
"ShellHistoryProvider",
|
|
48
|
+
"get_shell_provider_names",
|
|
49
|
+
# Utils
|
|
50
|
+
"validate_path",
|
|
51
|
+
"is_safe_command",
|
|
52
|
+
"extract_base_command",
|
|
53
|
+
"is_forbidden_command",
|
|
54
|
+
"DEFAULT_FORBIDDEN_COMMANDS",
|
|
55
|
+
"PLUGIN_NAME",
|
|
56
|
+
"PLUGIN_DESCRIPTION",
|
|
57
|
+
]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Auto-generated prompt templates
|
|
3
|
+
DO NOT EDIT - Generated from ../../../../prompts/*.txt
|
|
4
|
+
|
|
5
|
+
These prompts use Handlebars-style template syntax:
|
|
6
|
+
- {{variableName}} for simple substitution
|
|
7
|
+
- {{#each items}}...{{/each}} for iteration
|
|
8
|
+
- {{#if condition}}...{{/if}} for conditionals
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
COMMAND_EXTRACTION_TEMPLATE = """# Extracting shell command from request
|
|
14
|
+
{{recentMessages}}
|
|
15
|
+
|
|
16
|
+
# Instructions: {{senderName}} wants to execute a shell command. Extract the COMPLETE shell command they want to run.
|
|
17
|
+
|
|
18
|
+
IMPORTANT:
|
|
19
|
+
1. Always return the FULL executable shell command, not just the content or partial command.
|
|
20
|
+
2. If the user mentions installing something, create the appropriate brew/npm/apt command.
|
|
21
|
+
3. If the user directly provides a command (like "brew install X"), use it exactly as provided.
|
|
22
|
+
4. ALWAYS extract a command if the user is asking for ANY kind of system operation.
|
|
23
|
+
|
|
24
|
+
Common patterns:
|
|
25
|
+
- "run ls -la" -> command: "ls -la"
|
|
26
|
+
- "execute npm test" -> command: "npm test"
|
|
27
|
+
- "show me the files" or "list files" -> command: "ls -la"
|
|
28
|
+
- "what's in this directory" -> command: "ls -la"
|
|
29
|
+
- "check git status" -> command: "git status"
|
|
30
|
+
- "navigate to src folder" -> command: "cd src"
|
|
31
|
+
- "create a file called test.txt" -> command: "touch test.txt"
|
|
32
|
+
- "write hello world to a file" -> command: "echo 'hello world' > file.txt"
|
|
33
|
+
- "create hello.js with javascript code" -> command: "echo 'console.log(\\"Hello, World!\\");' > hello.js"
|
|
34
|
+
- "create hello_world.py and write a python hello world script inside" -> command: "echo 'print(\\"Hello, World!\\")' > hello_world.py"
|
|
35
|
+
- "make a new directory" -> command: "mkdir newdir"
|
|
36
|
+
- "list files inside your filesystem" -> command: "ls -la"
|
|
37
|
+
- "install orbstack" or "brew install orbstack" -> command: "brew install orbstack"
|
|
38
|
+
- "install mullvad vpn" -> command: "brew install --cask mullvad-vpn"
|
|
39
|
+
- "get system info" -> command: "system_profiler SPHardwareDataType"
|
|
40
|
+
- "check memory usage" -> command: "vm_stat"
|
|
41
|
+
- "install package" -> command: "brew install <package>"
|
|
42
|
+
|
|
43
|
+
Special cases:
|
|
44
|
+
- "Run it in your shell" or "execute it" -> Extract the command from previous context
|
|
45
|
+
- "Install these" -> Look for package names in previous messages
|
|
46
|
+
- Direct commands should be used exactly as provided
|
|
47
|
+
|
|
48
|
+
Key rules:
|
|
49
|
+
1. For file creation with content, use: echo 'content' > filename
|
|
50
|
+
2. For listing files, use: ls -la (not just ls)
|
|
51
|
+
3. Always include the echo command when writing to files
|
|
52
|
+
4. Include all flags and arguments
|
|
53
|
+
5. When user says "run it", "execute it", or similar, they want you to run the command
|
|
54
|
+
|
|
55
|
+
Your response must be formatted as a JSON block:
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"command": "<complete shell command to execute>"
|
|
59
|
+
}
|
|
60
|
+
```"""
|
|
61
|
+
|
|
62
|
+
__all__ = [
|
|
63
|
+
"COMMAND_EXTRACTION_TEMPLATE",
|
|
64
|
+
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from elizaos_plugin_shell.actions.clear_history import ClearHistoryAction
|
|
2
|
+
from elizaos_plugin_shell.actions.execute_command import ExecuteCommandAction
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"ExecuteCommandAction",
|
|
6
|
+
"ClearHistoryAction",
|
|
7
|
+
"get_shell_actions",
|
|
8
|
+
"get_shell_action_names",
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_shell_actions() -> list:
|
|
13
|
+
return [
|
|
14
|
+
ExecuteCommandAction(),
|
|
15
|
+
ClearHistoryAction(),
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_shell_action_names() -> list[str]:
|
|
20
|
+
return [
|
|
21
|
+
"EXECUTE_COMMAND",
|
|
22
|
+
"CLEAR_SHELL_HISTORY",
|
|
23
|
+
]
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
from elizaos_plugin_shell.service import ShellService
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class ActionExample:
|
|
8
|
+
user_message: str
|
|
9
|
+
agent_response: str
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class ActionResult:
|
|
14
|
+
success: bool
|
|
15
|
+
text: str
|
|
16
|
+
data: dict | None = None
|
|
17
|
+
error: str | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ClearHistoryAction:
|
|
21
|
+
CLEAR_KEYWORDS = ["clear", "reset", "delete", "remove", "clean", "wipe", "forget"]
|
|
22
|
+
HISTORY_KEYWORDS = ["history", "terminal", "shell", "command", "commands"]
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def name(self) -> str:
|
|
26
|
+
return "CLEAR_SHELL_HISTORY"
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def similes(self) -> list[str]:
|
|
30
|
+
return ["RESET_SHELL", "CLEAR_TERMINAL", "CLEAR_HISTORY", "RESET_HISTORY"]
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def description(self) -> str:
|
|
34
|
+
return "Clears the recorded history of shell commands for the current conversation"
|
|
35
|
+
|
|
36
|
+
def _has_clear_keyword(self, text: str) -> bool:
|
|
37
|
+
lower = text.lower()
|
|
38
|
+
return any(kw in lower for kw in self.CLEAR_KEYWORDS)
|
|
39
|
+
|
|
40
|
+
def _has_history_keyword(self, text: str) -> bool:
|
|
41
|
+
lower = text.lower()
|
|
42
|
+
return any(kw in lower for kw in self.HISTORY_KEYWORDS)
|
|
43
|
+
|
|
44
|
+
async def validate(self, message: dict, state: dict) -> bool:
|
|
45
|
+
text = message.get("content", {}).get("text", "")
|
|
46
|
+
return self._has_clear_keyword(text) and self._has_history_keyword(text)
|
|
47
|
+
|
|
48
|
+
async def handler(
|
|
49
|
+
self,
|
|
50
|
+
message: dict,
|
|
51
|
+
state: dict,
|
|
52
|
+
service: ShellService | None = None,
|
|
53
|
+
) -> ActionResult:
|
|
54
|
+
if service is None:
|
|
55
|
+
return ActionResult(
|
|
56
|
+
success=False,
|
|
57
|
+
text="Shell service is not available.",
|
|
58
|
+
error="Shell service is not available",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
conversation_id = message.get("room_id") or message.get("agent_id") or "default"
|
|
62
|
+
service.clear_command_history(conversation_id)
|
|
63
|
+
|
|
64
|
+
return ActionResult(
|
|
65
|
+
success=True,
|
|
66
|
+
text="Shell command history has been cleared.",
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def examples(self) -> list[ActionExample]:
|
|
70
|
+
return [
|
|
71
|
+
ActionExample(
|
|
72
|
+
user_message="clear my shell history",
|
|
73
|
+
agent_response="Shell command history has been cleared.",
|
|
74
|
+
),
|
|
75
|
+
ActionExample(
|
|
76
|
+
user_message="reset the terminal history",
|
|
77
|
+
agent_response="Shell command history has been cleared.",
|
|
78
|
+
),
|
|
79
|
+
ActionExample(
|
|
80
|
+
user_message="delete command history",
|
|
81
|
+
agent_response="Shell command history has been cleared.",
|
|
82
|
+
),
|
|
83
|
+
]
|