@framers/agentos-ext-cli-executor 1.1.0 → 1.2.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/LICENSE +23 -0
- package/README.md +80 -28
- package/dist/index.d.ts +68 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +78 -18
- package/dist/index.js.map +1 -1
- package/dist/services/shellService.d.ts +15 -1
- package/dist/services/shellService.d.ts.map +1 -1
- package/dist/services/shellService.js +96 -10
- package/dist/services/shellService.js.map +1 -1
- package/dist/tools/createPdf.d.ts +32 -0
- package/dist/tools/createPdf.d.ts.map +1 -0
- package/dist/tools/createPdf.js +215 -0
- package/dist/tools/createPdf.js.map +1 -0
- package/dist/tools/execute.d.ts +15 -18
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/execute.js +36 -36
- package/dist/tools/execute.js.map +1 -1
- package/dist/tools/fileRead.d.ts +15 -18
- package/dist/tools/fileRead.d.ts.map +1 -1
- package/dist/tools/fileRead.js +63 -39
- package/dist/tools/fileRead.js.map +1 -1
- package/dist/tools/fileWrite.d.ts +15 -18
- package/dist/tools/fileWrite.d.ts.map +1 -1
- package/dist/tools/fileWrite.js +47 -40
- package/dist/tools/fileWrite.js.map +1 -1
- package/dist/tools/listDir.d.ts +15 -18
- package/dist/tools/listDir.d.ts.map +1 -1
- package/dist/tools/listDir.js +45 -45
- package/dist/tools/listDir.js.map +1 -1
- package/dist/tools/readDocument.d.ts +41 -0
- package/dist/tools/readDocument.d.ts.map +1 -0
- package/dist/tools/readDocument.js +252 -0
- package/dist/tools/readDocument.js.map +1 -0
- package/dist/types.d.ts +63 -0
- package/dist/types.d.ts.map +1 -1
- package/manifest.json +20 -14
- package/package.json +15 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Framers
|
|
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
|
+
|
package/README.md
CHANGED
|
@@ -18,30 +18,36 @@ npm install @framers/agentos-ext-cli-executor
|
|
|
18
18
|
## Quick Start
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
-
import { createExtensionPack } from '@framers/agentos-ext-cli-executor';
|
|
22
21
|
import { ExtensionManager } from '@framers/agentos';
|
|
22
|
+
import { createExtensionPack } from '@framers/agentos-ext-cli-executor';
|
|
23
23
|
|
|
24
24
|
const extensionManager = new ExtensionManager();
|
|
25
25
|
|
|
26
|
-
//
|
|
27
|
-
extensionManager.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
26
|
+
// Load the pack into the runtime
|
|
27
|
+
await extensionManager.loadPackFromFactory(
|
|
28
|
+
createExtensionPack({
|
|
29
|
+
options: {
|
|
30
|
+
defaultShell: 'bash',
|
|
31
|
+
timeout: 60000,
|
|
32
|
+
blockedCommands: ['rm -rf /', 'format'],
|
|
33
|
+
// Restrict file_* tools to a per-agent workspace
|
|
34
|
+
filesystem: { allowRead: true, allowWrite: true },
|
|
35
|
+
agentWorkspace: { agentId: 'my-agent' },
|
|
36
|
+
},
|
|
37
|
+
logger: console,
|
|
38
|
+
}),
|
|
39
|
+
'@framers/agentos-ext-cli-executor',
|
|
40
|
+
);
|
|
35
41
|
```
|
|
36
42
|
|
|
37
43
|
## Tools
|
|
38
44
|
|
|
39
|
-
###
|
|
45
|
+
### shell_execute
|
|
40
46
|
|
|
41
47
|
Execute a shell command.
|
|
42
48
|
|
|
43
49
|
```typescript
|
|
44
|
-
const result = await gmi.executeTool('
|
|
50
|
+
const result = await gmi.executeTool('shell_execute', {
|
|
45
51
|
command: 'npm install lodash',
|
|
46
52
|
cwd: '/path/to/project',
|
|
47
53
|
timeout: 30000
|
|
@@ -49,31 +55,31 @@ const result = await gmi.executeTool('shellExecute', {
|
|
|
49
55
|
// Returns: { command, exitCode, stdout, stderr, duration, success }
|
|
50
56
|
```
|
|
51
57
|
|
|
52
|
-
###
|
|
58
|
+
### file_read
|
|
53
59
|
|
|
54
60
|
Read file contents.
|
|
55
61
|
|
|
56
62
|
```typescript
|
|
57
|
-
const result = await gmi.executeTool('
|
|
63
|
+
const result = await gmi.executeTool('file_read', {
|
|
58
64
|
path: './package.json',
|
|
59
65
|
encoding: 'utf-8'
|
|
60
66
|
});
|
|
61
67
|
// Returns: { path, content, size, truncated, encoding }
|
|
62
68
|
|
|
63
69
|
// Read last 50 lines
|
|
64
|
-
const logs = await gmi.executeTool('
|
|
70
|
+
const logs = await gmi.executeTool('file_read', {
|
|
65
71
|
path: './app.log',
|
|
66
72
|
lines: 50,
|
|
67
73
|
fromEnd: true
|
|
68
74
|
});
|
|
69
75
|
```
|
|
70
76
|
|
|
71
|
-
###
|
|
77
|
+
### file_write
|
|
72
78
|
|
|
73
79
|
Write content to a file.
|
|
74
80
|
|
|
75
81
|
```typescript
|
|
76
|
-
const result = await gmi.executeTool('
|
|
82
|
+
const result = await gmi.executeTool('file_write', {
|
|
77
83
|
path: './config.json',
|
|
78
84
|
content: JSON.stringify({ key: 'value' }),
|
|
79
85
|
createDirs: true
|
|
@@ -81,12 +87,12 @@ const result = await gmi.executeTool('fileWrite', {
|
|
|
81
87
|
// Returns: { path, bytesWritten, created, appended }
|
|
82
88
|
```
|
|
83
89
|
|
|
84
|
-
###
|
|
90
|
+
### list_directory
|
|
85
91
|
|
|
86
92
|
List directory contents.
|
|
87
93
|
|
|
88
94
|
```typescript
|
|
89
|
-
const result = await gmi.executeTool('
|
|
95
|
+
const result = await gmi.executeTool('list_directory', {
|
|
90
96
|
path: './src',
|
|
91
97
|
recursive: true,
|
|
92
98
|
pattern: '*.ts',
|
|
@@ -119,6 +125,18 @@ createExtensionPack({
|
|
|
119
125
|
});
|
|
120
126
|
```
|
|
121
127
|
|
|
128
|
+
### Disabling Safety Checks (Dangerous)
|
|
129
|
+
|
|
130
|
+
If you need full control (for example, in a locked-down container or local dev), you can disable all command safety checks:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
createExtensionPack({
|
|
134
|
+
options: {
|
|
135
|
+
dangerouslySkipSecurityChecks: true
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
122
140
|
### Risk Assessment
|
|
123
141
|
|
|
124
142
|
Each command is assessed for risk level:
|
|
@@ -138,24 +156,61 @@ Each command is assessed for risk level:
|
|
|
138
156
|
| `defaultShell` | string | `auto` | Shell to use (bash, powershell, cmd, zsh) |
|
|
139
157
|
| `timeout` | number | `60000` | Default timeout (ms) |
|
|
140
158
|
| `workingDirectory` | string | `process.cwd()` | Default working directory |
|
|
159
|
+
| `filesystem` | object | `undefined` | Optional policy for file_* tools (allowRead/allowWrite + roots) |
|
|
160
|
+
| `agentWorkspace` | object | `undefined` | Optional per-agent workspace directory helper |
|
|
141
161
|
| `allowedCommands` | string[] | `[]` | Command whitelist (empty = all) |
|
|
142
|
-
| `blockedCommands` | string[] | `[
|
|
162
|
+
| `blockedCommands` | string[] | `[]` | Command blacklist (additional to built-in dangerous patterns) |
|
|
163
|
+
| `dangerouslySkipSecurityChecks` | boolean | `false` | Disable all command safety checks (use only in trusted environments) |
|
|
143
164
|
| `env` | object | `{}` | Environment variables |
|
|
144
165
|
|
|
166
|
+
### Filesystem Policy (Recommended)
|
|
167
|
+
|
|
168
|
+
By default, the `file_*` tools can access any path (legacy behavior). To enforce a safe filesystem sandbox, configure `filesystem` + roots:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
createExtensionPack({
|
|
172
|
+
options: {
|
|
173
|
+
filesystem: {
|
|
174
|
+
allowRead: true,
|
|
175
|
+
allowWrite: true,
|
|
176
|
+
readRoots: ['/Users/me/Documents/AgentOS/agents/my-agent'],
|
|
177
|
+
writeRoots: ['/Users/me/Documents/AgentOS/agents/my-agent'],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Per-Agent Workspace Helper
|
|
184
|
+
|
|
185
|
+
To simplify safe defaults, you can configure `agentWorkspace`. When paired with `filesystem.allowRead/allowWrite`, the extension defaults roots to the workspace directory.
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
createExtensionPack({
|
|
189
|
+
options: {
|
|
190
|
+
filesystem: { allowRead: true, allowWrite: true },
|
|
191
|
+
agentWorkspace: {
|
|
192
|
+
agentId: 'my-agent',
|
|
193
|
+
// baseDir defaults to ~/Documents/AgentOS
|
|
194
|
+
subdirs: ['assets', 'exports', 'tmp'],
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
145
200
|
## Use Cases
|
|
146
201
|
|
|
147
202
|
### Code Generation and Execution
|
|
148
203
|
|
|
149
204
|
```typescript
|
|
150
205
|
// Write generated code
|
|
151
|
-
await gmi.executeTool('
|
|
206
|
+
await gmi.executeTool('file_write', {
|
|
152
207
|
path: './generated/app.py',
|
|
153
208
|
content: generatedPythonCode,
|
|
154
209
|
createDirs: true
|
|
155
210
|
});
|
|
156
211
|
|
|
157
212
|
// Execute it
|
|
158
|
-
await gmi.executeTool('
|
|
213
|
+
await gmi.executeTool('shell_execute', {
|
|
159
214
|
command: 'python ./generated/app.py',
|
|
160
215
|
timeout: 30000
|
|
161
216
|
});
|
|
@@ -165,12 +220,12 @@ await gmi.executeTool('shellExecute', {
|
|
|
165
220
|
|
|
166
221
|
```typescript
|
|
167
222
|
// Create project structure
|
|
168
|
-
await gmi.executeTool('
|
|
223
|
+
await gmi.executeTool('shell_execute', {
|
|
169
224
|
command: 'npx create-react-app my-app --template typescript'
|
|
170
225
|
});
|
|
171
226
|
|
|
172
227
|
// Install dependencies
|
|
173
|
-
await gmi.executeTool('
|
|
228
|
+
await gmi.executeTool('shell_execute', {
|
|
174
229
|
command: 'npm install axios lodash',
|
|
175
230
|
cwd: './my-app'
|
|
176
231
|
});
|
|
@@ -180,7 +235,7 @@ await gmi.executeTool('shellExecute', {
|
|
|
180
235
|
|
|
181
236
|
```typescript
|
|
182
237
|
// Read recent logs
|
|
183
|
-
const logs = await gmi.executeTool('
|
|
238
|
+
const logs = await gmi.executeTool('file_read', {
|
|
184
239
|
path: '/var/log/app.log',
|
|
185
240
|
lines: 100,
|
|
186
241
|
fromEnd: true
|
|
@@ -216,6 +271,3 @@ Together, an intelligent agent can:
|
|
|
216
271
|
## License
|
|
217
272
|
|
|
218
273
|
MIT © Frame.dev
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,16 @@
|
|
|
5
5
|
* capabilities for AgentOS agents.
|
|
6
6
|
*
|
|
7
7
|
* @module @framers/agentos-ext-cli-executor
|
|
8
|
-
* @version 1.
|
|
8
|
+
* @version 1.1.0
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import
|
|
12
|
-
import
|
|
11
|
+
import { ExecuteTool } from './tools/execute.js';
|
|
12
|
+
import { FileReadTool } from './tools/fileRead.js';
|
|
13
|
+
import { FileWriteTool } from './tools/fileWrite.js';
|
|
14
|
+
import { ListDirectoryTool } from './tools/listDir.js';
|
|
15
|
+
import { CreatePdfTool } from './tools/createPdf.js';
|
|
16
|
+
import { ReadDocumentTool } from './tools/readDocument.js';
|
|
17
|
+
import type { ShellConfig } from './types.js';
|
|
13
18
|
/**
|
|
14
19
|
* Extension configuration options
|
|
15
20
|
*/
|
|
@@ -37,12 +42,65 @@ export interface CLIExecutorExtensionOptions extends ShellConfig {
|
|
|
37
42
|
* });
|
|
38
43
|
* ```
|
|
39
44
|
*/
|
|
40
|
-
export declare function createExtensionPack(context:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
export declare function createExtensionPack(context: {
|
|
46
|
+
options?: Record<string, unknown>;
|
|
47
|
+
secrets?: Record<string, string>;
|
|
48
|
+
logger?: {
|
|
49
|
+
info: (...args: unknown[]) => void;
|
|
50
|
+
};
|
|
51
|
+
onActivate?: () => Promise<void>;
|
|
52
|
+
onDeactivate?: () => Promise<void>;
|
|
53
|
+
[key: string]: unknown;
|
|
54
|
+
}): {
|
|
55
|
+
name: string;
|
|
56
|
+
version: string;
|
|
57
|
+
descriptors: ({
|
|
58
|
+
id: string;
|
|
59
|
+
kind: string;
|
|
60
|
+
priority: number;
|
|
61
|
+
payload: ExecuteTool;
|
|
62
|
+
} | {
|
|
63
|
+
id: string;
|
|
64
|
+
kind: string;
|
|
65
|
+
priority: number;
|
|
66
|
+
payload: FileReadTool;
|
|
67
|
+
} | {
|
|
68
|
+
id: string;
|
|
69
|
+
kind: string;
|
|
70
|
+
priority: number;
|
|
71
|
+
payload: FileWriteTool;
|
|
72
|
+
} | {
|
|
73
|
+
id: string;
|
|
74
|
+
kind: string;
|
|
75
|
+
priority: number;
|
|
76
|
+
payload: ListDirectoryTool;
|
|
77
|
+
} | {
|
|
78
|
+
id: string;
|
|
79
|
+
kind: string;
|
|
80
|
+
priority: number;
|
|
81
|
+
payload: CreatePdfTool;
|
|
82
|
+
} | {
|
|
83
|
+
id: string;
|
|
84
|
+
kind: string;
|
|
85
|
+
priority: number;
|
|
86
|
+
payload: ReadDocumentTool;
|
|
87
|
+
})[];
|
|
88
|
+
/**
|
|
89
|
+
* Called when extension is activated
|
|
90
|
+
*/
|
|
91
|
+
onActivate: () => Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Called when extension is deactivated
|
|
94
|
+
*/
|
|
95
|
+
onDeactivate: () => Promise<void>;
|
|
96
|
+
};
|
|
97
|
+
export { ShellService } from './services/shellService.js';
|
|
98
|
+
export { ExecuteTool } from './tools/execute.js';
|
|
99
|
+
export { FileReadTool } from './tools/fileRead.js';
|
|
100
|
+
export { FileWriteTool } from './tools/fileWrite.js';
|
|
101
|
+
export { ListDirectoryTool } from './tools/listDir.js';
|
|
102
|
+
export { CreatePdfTool } from './tools/createPdf.js';
|
|
103
|
+
export { ReadDocumentTool } from './tools/readDocument.js';
|
|
104
|
+
export * from './types.js';
|
|
47
105
|
export default createExtensionPack;
|
|
48
106
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;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sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,cAAc,YAAY,CAAC;AAG3B,eAAe,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,14 +5,19 @@
|
|
|
5
5
|
* capabilities for AgentOS agents.
|
|
6
6
|
*
|
|
7
7
|
* @module @framers/agentos-ext-cli-executor
|
|
8
|
-
* @version 1.
|
|
8
|
+
* @version 1.1.0
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
11
|
+
import * as fs from 'node:fs/promises';
|
|
12
|
+
import * as os from 'node:os';
|
|
13
|
+
import * as path from 'node:path';
|
|
14
|
+
import { ShellService } from './services/shellService.js';
|
|
15
|
+
import { ExecuteTool } from './tools/execute.js';
|
|
16
|
+
import { FileReadTool } from './tools/fileRead.js';
|
|
17
|
+
import { FileWriteTool } from './tools/fileWrite.js';
|
|
18
|
+
import { ListDirectoryTool } from './tools/listDir.js';
|
|
19
|
+
import { CreatePdfTool } from './tools/createPdf.js';
|
|
20
|
+
import { ReadDocumentTool } from './tools/readDocument.js';
|
|
16
21
|
/**
|
|
17
22
|
* Creates the CLI executor extension pack
|
|
18
23
|
*
|
|
@@ -35,13 +40,46 @@ import { ListDirectoryTool } from './tools/listDir';
|
|
|
35
40
|
*/
|
|
36
41
|
export function createExtensionPack(context) {
|
|
37
42
|
const options = context.options || {};
|
|
43
|
+
let workspaceDir;
|
|
44
|
+
let workspaceSubdirs = [];
|
|
45
|
+
const workspaceConfig = options.agentWorkspace;
|
|
46
|
+
if (workspaceConfig && workspaceConfig.enabled !== false) {
|
|
47
|
+
const baseDir = (workspaceConfig.baseDir && String(workspaceConfig.baseDir).trim()) ||
|
|
48
|
+
path.join(os.homedir(), 'Documents', 'AgentOS');
|
|
49
|
+
const agentId = String(workspaceConfig.agentId || '').trim();
|
|
50
|
+
if (agentId) {
|
|
51
|
+
workspaceDir = path.resolve(baseDir, agentId);
|
|
52
|
+
workspaceSubdirs = Array.isArray(workspaceConfig.subdirs) && workspaceConfig.subdirs.length > 0
|
|
53
|
+
? workspaceConfig.subdirs.map((d) => String(d)).filter(Boolean)
|
|
54
|
+
: ['assets', 'exports', 'tmp'];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const workingDirectory = options.workingDirectory || workspaceDir;
|
|
58
|
+
const filesystem = options.filesystem
|
|
59
|
+
? {
|
|
60
|
+
...options.filesystem,
|
|
61
|
+
readRoots: options.filesystem.allowRead === true &&
|
|
62
|
+
(!options.filesystem.readRoots || options.filesystem.readRoots.length === 0) &&
|
|
63
|
+
workspaceDir
|
|
64
|
+
? [workspaceDir]
|
|
65
|
+
: options.filesystem.readRoots,
|
|
66
|
+
writeRoots: options.filesystem.allowWrite === true &&
|
|
67
|
+
(!options.filesystem.writeRoots || options.filesystem.writeRoots.length === 0) &&
|
|
68
|
+
workspaceDir
|
|
69
|
+
? [workspaceDir]
|
|
70
|
+
: options.filesystem.writeRoots,
|
|
71
|
+
}
|
|
72
|
+
: undefined;
|
|
38
73
|
// Initialize shell service with configuration
|
|
39
74
|
const shellService = new ShellService({
|
|
40
75
|
defaultShell: options.defaultShell,
|
|
41
76
|
timeout: options.timeout,
|
|
42
|
-
workingDirectory
|
|
77
|
+
workingDirectory,
|
|
78
|
+
filesystem,
|
|
79
|
+
agentWorkspace: options.agentWorkspace,
|
|
43
80
|
allowedCommands: options.allowedCommands,
|
|
44
81
|
blockedCommands: options.blockedCommands,
|
|
82
|
+
dangerouslySkipSecurityChecks: options.dangerouslySkipSecurityChecks,
|
|
45
83
|
env: options.env,
|
|
46
84
|
});
|
|
47
85
|
// Create tool instances
|
|
@@ -49,34 +87,48 @@ export function createExtensionPack(context) {
|
|
|
49
87
|
const fileReadTool = new FileReadTool(shellService);
|
|
50
88
|
const fileWriteTool = new FileWriteTool(shellService);
|
|
51
89
|
const listDirectoryTool = new ListDirectoryTool(shellService);
|
|
90
|
+
const createPdfTool = new CreatePdfTool();
|
|
91
|
+
const readDocumentTool = new ReadDocumentTool(shellService);
|
|
52
92
|
return {
|
|
53
93
|
name: '@framers/agentos-ext-cli-executor',
|
|
54
|
-
version: '1.
|
|
94
|
+
version: '1.2.0',
|
|
55
95
|
descriptors: [
|
|
56
96
|
{
|
|
57
|
-
id:
|
|
97
|
+
id: executeTool.name,
|
|
58
98
|
kind: 'tool',
|
|
59
99
|
priority: options.priority || 50,
|
|
60
100
|
payload: executeTool,
|
|
61
101
|
},
|
|
62
102
|
{
|
|
63
|
-
id:
|
|
103
|
+
id: fileReadTool.name,
|
|
64
104
|
kind: 'tool',
|
|
65
105
|
priority: options.priority || 50,
|
|
66
106
|
payload: fileReadTool,
|
|
67
107
|
},
|
|
68
108
|
{
|
|
69
|
-
id:
|
|
109
|
+
id: fileWriteTool.name,
|
|
70
110
|
kind: 'tool',
|
|
71
111
|
priority: options.priority || 50,
|
|
72
112
|
payload: fileWriteTool,
|
|
73
113
|
},
|
|
74
114
|
{
|
|
75
|
-
id:
|
|
115
|
+
id: listDirectoryTool.name,
|
|
76
116
|
kind: 'tool',
|
|
77
117
|
priority: options.priority || 50,
|
|
78
118
|
payload: listDirectoryTool,
|
|
79
119
|
},
|
|
120
|
+
{
|
|
121
|
+
id: createPdfTool.name,
|
|
122
|
+
kind: 'tool',
|
|
123
|
+
priority: options.priority || 50,
|
|
124
|
+
payload: createPdfTool,
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: readDocumentTool.name,
|
|
128
|
+
kind: 'tool',
|
|
129
|
+
priority: options.priority || 50,
|
|
130
|
+
payload: readDocumentTool,
|
|
131
|
+
},
|
|
80
132
|
],
|
|
81
133
|
/**
|
|
82
134
|
* Called when extension is activated
|
|
@@ -85,6 +137,12 @@ export function createExtensionPack(context) {
|
|
|
85
137
|
if (context.onActivate) {
|
|
86
138
|
await context.onActivate();
|
|
87
139
|
}
|
|
140
|
+
if (workspaceDir && workspaceConfig?.createIfMissing !== false) {
|
|
141
|
+
await fs.mkdir(workspaceDir, { recursive: true });
|
|
142
|
+
for (const sub of workspaceSubdirs) {
|
|
143
|
+
await fs.mkdir(path.join(workspaceDir, sub), { recursive: true });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
88
146
|
context.logger?.info('CLI Executor Extension activated');
|
|
89
147
|
},
|
|
90
148
|
/**
|
|
@@ -99,12 +157,14 @@ export function createExtensionPack(context) {
|
|
|
99
157
|
};
|
|
100
158
|
}
|
|
101
159
|
// 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
|
|
160
|
+
export { ShellService } from './services/shellService.js';
|
|
161
|
+
export { ExecuteTool } from './tools/execute.js';
|
|
162
|
+
export { FileReadTool } from './tools/fileRead.js';
|
|
163
|
+
export { FileWriteTool } from './tools/fileWrite.js';
|
|
164
|
+
export { ListDirectoryTool } from './tools/listDir.js';
|
|
165
|
+
export { CreatePdfTool } from './tools/createPdf.js';
|
|
166
|
+
export { ReadDocumentTool } from './tools/readDocument.js';
|
|
167
|
+
export * from './types.js';
|
|
108
168
|
// Default export for convenience
|
|
109
169
|
export default createExtensionPack;
|
|
110
170
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,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E,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,cAAc,YAAY,CAAC;AAE3B,iCAAiC;AACjC,eAAe,mBAAmB,CAAC"}
|
|
@@ -4,13 +4,18 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module @framers/agentos-ext-cli-executor
|
|
6
6
|
*/
|
|
7
|
-
import type { ShellConfig, ExecutionResult, ScriptOptions, ScriptResult, FileReadOptions, FileReadResult, FileWriteOptions, FileWriteResult, ListDirectoryOptions, ListDirectoryResult, SecurityCheckResult } from '../types';
|
|
7
|
+
import type { ShellConfig, ExecutionResult, ScriptOptions, ScriptResult, FileReadOptions, FileReadResult, FileWriteOptions, FileWriteResult, ListDirectoryOptions, ListDirectoryResult, SecurityCheckResult } from '../types.js';
|
|
8
8
|
/**
|
|
9
9
|
* Shell service for executing commands
|
|
10
10
|
*/
|
|
11
11
|
export declare class ShellService {
|
|
12
12
|
private config;
|
|
13
13
|
constructor(config?: ShellConfig);
|
|
14
|
+
private resolveAbsolutePath;
|
|
15
|
+
private isFilesystemPolicyEnabled;
|
|
16
|
+
private isWithinRoot;
|
|
17
|
+
private resolvePathForAuthorization;
|
|
18
|
+
private assertFilesystemAllowed;
|
|
14
19
|
/**
|
|
15
20
|
* Detect the appropriate shell for the current platform
|
|
16
21
|
*/
|
|
@@ -35,6 +40,15 @@ export declare class ShellService {
|
|
|
35
40
|
* Read a file
|
|
36
41
|
*/
|
|
37
42
|
readFile(filePath: string, options?: FileReadOptions): Promise<FileReadResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Read a file as a raw Buffer (for binary document formats).
|
|
45
|
+
* Enforces the same filesystem security policy as readFile.
|
|
46
|
+
*/
|
|
47
|
+
readFileBuffer(filePath: string): Promise<{
|
|
48
|
+
buffer: Buffer;
|
|
49
|
+
path: string;
|
|
50
|
+
size: number;
|
|
51
|
+
}>;
|
|
38
52
|
/**
|
|
39
53
|
* Write to a file
|
|
40
54
|
*/
|
|
@@ -1 +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,
|
|
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,aAAa,CAAC;AAuBrB;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,GAAE,WAAgB;IAUpC,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,yBAAyB;IAIjC,OAAO,CAAC,YAAY;YAKN,2BAA2B;YAwB3B,uBAAuB;IAoCrC;;OAEG;IACH,OAAO,CAAC,WAAW;IAenB;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB;IAgFnD;;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,C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