@framers/agentos-ext-cli-executor 1.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 ADDED
@@ -0,0 +1,221 @@
1
+ # CLI Executor Extension for AgentOS
2
+
3
+ Execute shell commands, run scripts, and manage files for AgentOS agents. This is one of the two fundamental primitives (along with Web Browser) that enables recursive self-building agent capabilities.
4
+
5
+ ## Features
6
+
7
+ - **Shell Execution**: Run any shell command with output capture
8
+ - **File Management**: Read, write, and list files/directories
9
+ - **Security Controls**: Dangerous command detection and blocking
10
+ - **Cross-Platform**: Works on Windows, macOS, and Linux
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install @framers/agentos-ext-cli-executor
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```typescript
21
+ import { createExtensionPack } from '@framers/agentos-ext-cli-executor';
22
+ import { ExtensionManager } from '@framers/agentos';
23
+
24
+ const extensionManager = new ExtensionManager();
25
+
26
+ // Register the CLI extension
27
+ extensionManager.register(createExtensionPack({
28
+ options: {
29
+ defaultShell: 'bash',
30
+ timeout: 60000,
31
+ blockedCommands: ['rm -rf /', 'format']
32
+ },
33
+ logger: console
34
+ }));
35
+ ```
36
+
37
+ ## Tools
38
+
39
+ ### shellExecute
40
+
41
+ Execute a shell command.
42
+
43
+ ```typescript
44
+ const result = await gmi.executeTool('shellExecute', {
45
+ command: 'npm install lodash',
46
+ cwd: '/path/to/project',
47
+ timeout: 30000
48
+ });
49
+ // Returns: { command, exitCode, stdout, stderr, duration, success }
50
+ ```
51
+
52
+ ### fileRead
53
+
54
+ Read file contents.
55
+
56
+ ```typescript
57
+ const result = await gmi.executeTool('fileRead', {
58
+ path: './package.json',
59
+ encoding: 'utf-8'
60
+ });
61
+ // Returns: { path, content, size, truncated, encoding }
62
+
63
+ // Read last 50 lines
64
+ const logs = await gmi.executeTool('fileRead', {
65
+ path: './app.log',
66
+ lines: 50,
67
+ fromEnd: true
68
+ });
69
+ ```
70
+
71
+ ### fileWrite
72
+
73
+ Write content to a file.
74
+
75
+ ```typescript
76
+ const result = await gmi.executeTool('fileWrite', {
77
+ path: './config.json',
78
+ content: JSON.stringify({ key: 'value' }),
79
+ createDirs: true
80
+ });
81
+ // Returns: { path, bytesWritten, created, appended }
82
+ ```
83
+
84
+ ### listDirectory
85
+
86
+ List directory contents.
87
+
88
+ ```typescript
89
+ const result = await gmi.executeTool('listDirectory', {
90
+ path: './src',
91
+ recursive: true,
92
+ pattern: '*.ts',
93
+ includeStats: true
94
+ });
95
+ // Returns: { path, entries: [{ name, path, type, size, ... }], count }
96
+ ```
97
+
98
+ ## Security
99
+
100
+ The extension includes built-in security controls:
101
+
102
+ ### Dangerous Pattern Detection
103
+
104
+ Commands matching these patterns are blocked by default:
105
+ - `rm -rf /` (recursive delete root)
106
+ - `format C:` (format drives)
107
+ - Fork bombs
108
+ - Direct disk writes
109
+ - System shutdown/reboot commands
110
+
111
+ ### Custom Blocklists
112
+
113
+ ```typescript
114
+ createExtensionPack({
115
+ options: {
116
+ blockedCommands: ['sudo', 'su', 'chmod 777'],
117
+ allowedCommands: ['npm', 'node', 'python', 'git'] // Whitelist mode
118
+ }
119
+ });
120
+ ```
121
+
122
+ ### Risk Assessment
123
+
124
+ Each command is assessed for risk level:
125
+
126
+ | Risk Level | Examples |
127
+ |------------|----------|
128
+ | `safe` | `ls`, `cat`, `npm list` |
129
+ | `low` | `echo "text" > file.txt` |
130
+ | `medium` | `rm file.txt`, `eval` |
131
+ | `high` | `sudo`, `curl | sh` |
132
+ | `critical` | `rm -rf /`, blocked patterns |
133
+
134
+ ## Configuration
135
+
136
+ | Option | Type | Default | Description |
137
+ |--------|------|---------|-------------|
138
+ | `defaultShell` | string | `auto` | Shell to use (bash, powershell, cmd, zsh) |
139
+ | `timeout` | number | `60000` | Default timeout (ms) |
140
+ | `workingDirectory` | string | `process.cwd()` | Default working directory |
141
+ | `allowedCommands` | string[] | `[]` | Command whitelist (empty = all) |
142
+ | `blockedCommands` | string[] | `[...]` | Command blacklist |
143
+ | `env` | object | `{}` | Environment variables |
144
+
145
+ ## Use Cases
146
+
147
+ ### Code Generation and Execution
148
+
149
+ ```typescript
150
+ // Write generated code
151
+ await gmi.executeTool('fileWrite', {
152
+ path: './generated/app.py',
153
+ content: generatedPythonCode,
154
+ createDirs: true
155
+ });
156
+
157
+ // Execute it
158
+ await gmi.executeTool('shellExecute', {
159
+ command: 'python ./generated/app.py',
160
+ timeout: 30000
161
+ });
162
+ ```
163
+
164
+ ### Project Setup
165
+
166
+ ```typescript
167
+ // Create project structure
168
+ await gmi.executeTool('shellExecute', {
169
+ command: 'npx create-react-app my-app --template typescript'
170
+ });
171
+
172
+ // Install dependencies
173
+ await gmi.executeTool('shellExecute', {
174
+ command: 'npm install axios lodash',
175
+ cwd: './my-app'
176
+ });
177
+ ```
178
+
179
+ ### Log Analysis
180
+
181
+ ```typescript
182
+ // Read recent logs
183
+ const logs = await gmi.executeTool('fileRead', {
184
+ path: '/var/log/app.log',
185
+ lines: 100,
186
+ fromEnd: true
187
+ });
188
+
189
+ // Parse and analyze
190
+ const errorCount = logs.output.content.match(/ERROR/g)?.length || 0;
191
+ ```
192
+
193
+ ## The Two Primitives Theory
194
+
195
+ This extension, combined with the Web Browser extension, provides the two fundamental capabilities needed for a recursive self-building agent:
196
+
197
+ 1. **CLI Executor** (this extension)
198
+ - Execute arbitrary code
199
+ - Manage files
200
+ - Install dependencies
201
+ - Run tests and builds
202
+
203
+ 2. **Web Browser** (see web-browser extension)
204
+ - Search for information
205
+ - Read documentation
206
+ - Learn new techniques
207
+ - Verify implementations
208
+
209
+ Together, an intelligent agent can:
210
+ 1. Identify what it needs to learn → Web search
211
+ 2. Find documentation/tutorials → Web scraping
212
+ 3. Write code → File write
213
+ 4. Execute and test → Shell execute
214
+ 5. Debug and iterate → Repeat
215
+
216
+ ## License
217
+
218
+ MIT © Frame.dev
219
+
220
+
221
+
@@ -0,0 +1,48 @@
1
+ /**
2
+ * AgentOS CLI Executor Extension
3
+ *
4
+ * Provides shell command execution, script running, and file management
5
+ * capabilities for AgentOS agents.
6
+ *
7
+ * @module @framers/agentos-ext-cli-executor
8
+ * @version 1.0.0
9
+ * @license MIT
10
+ */
11
+ import type { ExtensionContext, ExtensionPack } from '@framers/agentos';
12
+ import type { ShellConfig } from './types';
13
+ /**
14
+ * Extension configuration options
15
+ */
16
+ export interface CLIExecutorExtensionOptions extends ShellConfig {
17
+ /** Extension priority in the stack */
18
+ priority?: number;
19
+ }
20
+ /**
21
+ * Creates the CLI executor extension pack
22
+ *
23
+ * @param context - The extension context
24
+ * @returns The configured extension pack
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * import { createExtensionPack } from '@framers/agentos-ext-cli-executor';
29
+ *
30
+ * const pack = createExtensionPack({
31
+ * options: {
32
+ * defaultShell: 'bash',
33
+ * timeout: 60000,
34
+ * blockedCommands: ['rm -rf /']
35
+ * },
36
+ * logger: console
37
+ * });
38
+ * ```
39
+ */
40
+ export declare function createExtensionPack(context: ExtensionContext): ExtensionPack;
41
+ export { ShellService } from './services/shellService';
42
+ export { ExecuteTool } from './tools/execute';
43
+ export { FileReadTool } from './tools/fileRead';
44
+ export { FileWriteTool } from './tools/fileWrite';
45
+ export { ListDirectoryTool } from './tools/listDir';
46
+ export * from './types';
47
+ export default createExtensionPack;
48
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAMxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,2BAA4B,SAAQ,WAAW;IAC9D,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAqE5E;AAGD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,cAAc,SAAS,CAAC;AAGxB,eAAe,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,110 @@
1
+ /**
2
+ * AgentOS CLI Executor Extension
3
+ *
4
+ * Provides shell command execution, script running, and file management
5
+ * capabilities for AgentOS agents.
6
+ *
7
+ * @module @framers/agentos-ext-cli-executor
8
+ * @version 1.0.0
9
+ * @license MIT
10
+ */
11
+ import { ShellService } from './services/shellService';
12
+ import { ExecuteTool } from './tools/execute';
13
+ import { FileReadTool } from './tools/fileRead';
14
+ import { FileWriteTool } from './tools/fileWrite';
15
+ import { ListDirectoryTool } from './tools/listDir';
16
+ /**
17
+ * Creates the CLI executor extension pack
18
+ *
19
+ * @param context - The extension context
20
+ * @returns The configured extension pack
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { createExtensionPack } from '@framers/agentos-ext-cli-executor';
25
+ *
26
+ * const pack = createExtensionPack({
27
+ * options: {
28
+ * defaultShell: 'bash',
29
+ * timeout: 60000,
30
+ * blockedCommands: ['rm -rf /']
31
+ * },
32
+ * logger: console
33
+ * });
34
+ * ```
35
+ */
36
+ export function createExtensionPack(context) {
37
+ const options = context.options || {};
38
+ // Initialize shell service with configuration
39
+ const shellService = new ShellService({
40
+ defaultShell: options.defaultShell,
41
+ timeout: options.timeout,
42
+ workingDirectory: options.workingDirectory,
43
+ allowedCommands: options.allowedCommands,
44
+ blockedCommands: options.blockedCommands,
45
+ env: options.env,
46
+ });
47
+ // Create tool instances
48
+ const executeTool = new ExecuteTool(shellService);
49
+ const fileReadTool = new FileReadTool(shellService);
50
+ const fileWriteTool = new FileWriteTool(shellService);
51
+ const listDirectoryTool = new ListDirectoryTool(shellService);
52
+ return {
53
+ name: '@framers/agentos-ext-cli-executor',
54
+ version: '1.0.0',
55
+ descriptors: [
56
+ {
57
+ id: 'shellExecute',
58
+ kind: 'tool',
59
+ priority: options.priority || 50,
60
+ payload: executeTool,
61
+ },
62
+ {
63
+ id: 'fileRead',
64
+ kind: 'tool',
65
+ priority: options.priority || 50,
66
+ payload: fileReadTool,
67
+ },
68
+ {
69
+ id: 'fileWrite',
70
+ kind: 'tool',
71
+ priority: options.priority || 50,
72
+ payload: fileWriteTool,
73
+ },
74
+ {
75
+ id: 'listDirectory',
76
+ kind: 'tool',
77
+ priority: options.priority || 50,
78
+ payload: listDirectoryTool,
79
+ },
80
+ ],
81
+ /**
82
+ * Called when extension is activated
83
+ */
84
+ onActivate: async () => {
85
+ if (context.onActivate) {
86
+ await context.onActivate();
87
+ }
88
+ context.logger?.info('CLI Executor Extension activated');
89
+ },
90
+ /**
91
+ * Called when extension is deactivated
92
+ */
93
+ onDeactivate: async () => {
94
+ if (context.onDeactivate) {
95
+ await context.onDeactivate();
96
+ }
97
+ context.logger?.info('CLI Executor Extension deactivated');
98
+ },
99
+ };
100
+ }
101
+ // Export types and classes for consumers
102
+ export { ShellService } from './services/shellService';
103
+ export { ExecuteTool } from './tools/execute';
104
+ export { FileReadTool } from './tools/fileRead';
105
+ export { FileWriteTool } from './tools/fileWrite';
106
+ export { ListDirectoryTool } from './tools/listDir';
107
+ export * from './types';
108
+ // Default export for convenience
109
+ export default createExtensionPack;
110
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD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,EAAE,YAAY;aACtB;YACD;gBACE,EAAE,EAAE,WAAW;gBACf,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE;gBAChC,OAAO,EAAE,aAAa;aACvB;YACD;gBACE,EAAE,EAAE,eAAe;gBACnB,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE;gBAChC,OAAO,EAAE,iBAAiB;aAC3B;SACF;QAED;;WAEG;QACH,UAAU,EAAE,KAAK,IAAI,EAAE;YACrB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gBACvB,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;YAC7B,CAAC;YACD,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,kCAAkC,CAAC,CAAC;QAC3D,CAAC;QAED;;WAEG;QACH,YAAY,EAAE,KAAK,IAAI,EAAE;YACvB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;gBACzB,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC;YAC/B,CAAC;YACD,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,oCAAoC,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC;AACJ,CAAC;AAED,yCAAyC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,cAAc,SAAS,CAAC;AAExB,iCAAiC;AACjC,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Shell Service
3
+ * Manages command execution with security validation.
4
+ *
5
+ * @module @framers/agentos-ext-cli-executor
6
+ */
7
+ import type { ShellConfig, ExecutionResult, ScriptOptions, ScriptResult, FileReadOptions, FileReadResult, FileWriteOptions, FileWriteResult, ListDirectoryOptions, ListDirectoryResult, SecurityCheckResult } from '../types';
8
+ /**
9
+ * Shell service for executing commands
10
+ */
11
+ export declare class ShellService {
12
+ private config;
13
+ constructor(config?: ShellConfig);
14
+ /**
15
+ * Detect the appropriate shell for the current platform
16
+ */
17
+ private detectShell;
18
+ /**
19
+ * Check if a command is safe to execute
20
+ */
21
+ checkSecurity(command: string): SecurityCheckResult;
22
+ /**
23
+ * Execute a shell command
24
+ */
25
+ execute(command: string, options?: {
26
+ cwd?: string;
27
+ env?: Record<string, string>;
28
+ timeout?: number;
29
+ }): Promise<ExecutionResult>;
30
+ /**
31
+ * Run a script file
32
+ */
33
+ runScript(scriptPath: string, options?: ScriptOptions): Promise<ScriptResult>;
34
+ /**
35
+ * Read a file
36
+ */
37
+ readFile(filePath: string, options?: FileReadOptions): Promise<FileReadResult>;
38
+ /**
39
+ * Write to a file
40
+ */
41
+ writeFile(filePath: string, content: string, options?: FileWriteOptions): Promise<FileWriteResult>;
42
+ /**
43
+ * List directory contents
44
+ */
45
+ listDirectory(dirPath: string, options?: ListDirectoryOptions): Promise<ListDirectoryResult>;
46
+ }
47
+ //# sourceMappingURL=shellService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shellService.d.ts","sourceRoot":"","sources":["../../src/services/shellService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,aAAa,EACb,YAAY,EACZ,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EAEnB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAuBlB;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,GAAE,WAAgB;IASpC;;OAEG;IACH,OAAO,CAAC,WAAW;IAenB;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB;IAuEnD;;OAEG;IACG,OAAO,CACX,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GACzE,OAAO,CAAC,eAAe,CAAC;IAwD3B;;OAEG;IACG,SAAS,CACb,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,CAAC;IAiCxB;;OAEG;IACG,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IA4CpF;;OAEG;IACG,SAAS,CACb,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,eAAe,CAAC;IAkC3B;;OAEG;IACG,aAAa,CACjB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,mBAAmB,CAAC;CA6EhC"}