deepagentsdk 0.9.2
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 +21 -0
- package/README.md +159 -0
- package/package.json +95 -0
- package/src/agent.ts +1230 -0
- package/src/backends/composite.ts +273 -0
- package/src/backends/filesystem.ts +692 -0
- package/src/backends/index.ts +22 -0
- package/src/backends/local-sandbox.ts +175 -0
- package/src/backends/persistent.ts +593 -0
- package/src/backends/sandbox.ts +510 -0
- package/src/backends/state.ts +244 -0
- package/src/backends/utils.ts +287 -0
- package/src/checkpointer/file-saver.ts +98 -0
- package/src/checkpointer/index.ts +5 -0
- package/src/checkpointer/kv-saver.ts +82 -0
- package/src/checkpointer/memory-saver.ts +82 -0
- package/src/checkpointer/types.ts +125 -0
- package/src/cli/components/ApiKeyInput.tsx +300 -0
- package/src/cli/components/FilePreview.tsx +237 -0
- package/src/cli/components/Input.tsx +277 -0
- package/src/cli/components/Message.tsx +93 -0
- package/src/cli/components/ModelSelection.tsx +338 -0
- package/src/cli/components/SlashMenu.tsx +101 -0
- package/src/cli/components/StatusBar.tsx +89 -0
- package/src/cli/components/Subagent.tsx +91 -0
- package/src/cli/components/TodoList.tsx +133 -0
- package/src/cli/components/ToolApproval.tsx +70 -0
- package/src/cli/components/ToolCall.tsx +144 -0
- package/src/cli/components/ToolCallSummary.tsx +175 -0
- package/src/cli/components/Welcome.tsx +75 -0
- package/src/cli/components/index.ts +24 -0
- package/src/cli/hooks/index.ts +12 -0
- package/src/cli/hooks/useAgent.ts +933 -0
- package/src/cli/index.tsx +1066 -0
- package/src/cli/theme.ts +205 -0
- package/src/cli/utils/model-list.ts +365 -0
- package/src/constants/errors.ts +29 -0
- package/src/constants/limits.ts +195 -0
- package/src/index.ts +176 -0
- package/src/middleware/agent-memory.ts +330 -0
- package/src/prompts.ts +196 -0
- package/src/skills/index.ts +2 -0
- package/src/skills/load.ts +191 -0
- package/src/skills/types.ts +53 -0
- package/src/tools/execute.ts +167 -0
- package/src/tools/filesystem.ts +418 -0
- package/src/tools/index.ts +39 -0
- package/src/tools/subagent.ts +443 -0
- package/src/tools/todos.ts +101 -0
- package/src/tools/web.ts +567 -0
- package/src/types/backend.ts +177 -0
- package/src/types/core.ts +220 -0
- package/src/types/events.ts +429 -0
- package/src/types/index.ts +94 -0
- package/src/types/structured-output.ts +43 -0
- package/src/types/subagent.ts +96 -0
- package/src/types.ts +22 -0
- package/src/utils/approval.ts +213 -0
- package/src/utils/events.ts +416 -0
- package/src/utils/eviction.ts +181 -0
- package/src/utils/index.ts +34 -0
- package/src/utils/model-parser.ts +38 -0
- package/src/utils/patch-tool-calls.ts +233 -0
- package/src/utils/project-detection.ts +32 -0
- package/src/utils/summarization.ts +254 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocalSandbox: Execute commands locally using child_process.
|
|
3
|
+
*
|
|
4
|
+
* Useful for local development and testing without cloud sandboxes.
|
|
5
|
+
* All file operations are inherited from BaseSandbox and executed
|
|
6
|
+
* via shell commands in the local filesystem.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { spawn } from "child_process";
|
|
10
|
+
import type { ExecuteResponse } from "../types";
|
|
11
|
+
import { BaseSandbox } from "./sandbox";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Options for LocalSandbox.
|
|
15
|
+
*/
|
|
16
|
+
export interface LocalSandboxOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Working directory for command execution.
|
|
19
|
+
* All file paths in sandbox operations are relative to this directory.
|
|
20
|
+
* @default process.cwd()
|
|
21
|
+
*/
|
|
22
|
+
cwd?: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Timeout in milliseconds for command execution.
|
|
26
|
+
* Commands that exceed this timeout will be terminated.
|
|
27
|
+
* @default 30000 (30 seconds)
|
|
28
|
+
*/
|
|
29
|
+
timeout?: number;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Additional environment variables to set for command execution.
|
|
33
|
+
* These are merged with the current process environment.
|
|
34
|
+
*/
|
|
35
|
+
env?: Record<string, string>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Maximum output size in bytes before truncation.
|
|
39
|
+
* @default 1048576 (1MB)
|
|
40
|
+
*/
|
|
41
|
+
maxOutputSize?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Local sandbox that executes commands using Node.js child_process.
|
|
46
|
+
*
|
|
47
|
+
* All commands are executed in a bash shell with the specified working directory.
|
|
48
|
+
* Inherits all file operations (read, write, edit, ls, grep, glob) from BaseSandbox.
|
|
49
|
+
*
|
|
50
|
+
* @example Basic usage
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { LocalSandbox } from 'deepagentsdk';
|
|
53
|
+
*
|
|
54
|
+
* const sandbox = new LocalSandbox({ cwd: './workspace' });
|
|
55
|
+
*
|
|
56
|
+
* // Execute commands
|
|
57
|
+
* const result = await sandbox.execute('ls -la');
|
|
58
|
+
* console.log(result.output);
|
|
59
|
+
*
|
|
60
|
+
* // File operations
|
|
61
|
+
* await sandbox.write('./src/index.ts', 'console.log("hello")');
|
|
62
|
+
* const content = await sandbox.read('./src/index.ts');
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example With timeout and environment
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const sandbox = new LocalSandbox({
|
|
68
|
+
* cwd: './workspace',
|
|
69
|
+
* timeout: 60000, // 60 seconds
|
|
70
|
+
* env: {
|
|
71
|
+
* NODE_ENV: 'development',
|
|
72
|
+
* DEBUG: '*',
|
|
73
|
+
* },
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example Error handling
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const result = await sandbox.execute('npm test');
|
|
80
|
+
* if (result.exitCode !== 0) {
|
|
81
|
+
* console.error('Tests failed:', result.output);
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export class LocalSandbox extends BaseSandbox {
|
|
86
|
+
private readonly cwd: string;
|
|
87
|
+
private readonly timeout: number;
|
|
88
|
+
private readonly env: Record<string, string>;
|
|
89
|
+
private readonly maxOutputSize: number;
|
|
90
|
+
private readonly _id: string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create a new LocalSandbox instance.
|
|
94
|
+
*
|
|
95
|
+
* @param options - Configuration options for the sandbox
|
|
96
|
+
*/
|
|
97
|
+
constructor(options: LocalSandboxOptions = {}) {
|
|
98
|
+
super();
|
|
99
|
+
this.cwd = options.cwd || process.cwd();
|
|
100
|
+
this.timeout = options.timeout || 30000;
|
|
101
|
+
this.env = options.env || {};
|
|
102
|
+
this.maxOutputSize = options.maxOutputSize || 1024 * 1024; // 1MB
|
|
103
|
+
this._id = `local-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Unique identifier for this sandbox instance.
|
|
108
|
+
* Format: `local-{timestamp}-{random}`
|
|
109
|
+
*/
|
|
110
|
+
get id(): string {
|
|
111
|
+
return this._id;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Execute a shell command in the local filesystem.
|
|
116
|
+
*
|
|
117
|
+
* Commands are executed using bash with the configured working directory
|
|
118
|
+
* and environment variables. Output is captured from both stdout and stderr.
|
|
119
|
+
*
|
|
120
|
+
* @param command - Shell command to execute
|
|
121
|
+
* @returns ExecuteResponse with output, exit code, and truncation status
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const result = await sandbox.execute('echo "Hello" && ls -la');
|
|
126
|
+
* console.log(result.output);
|
|
127
|
+
* console.log('Exit code:', result.exitCode);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
async execute(command: string): Promise<ExecuteResponse> {
|
|
131
|
+
return new Promise((resolve) => {
|
|
132
|
+
const child = spawn("bash", ["-c", command], {
|
|
133
|
+
cwd: this.cwd,
|
|
134
|
+
env: { ...process.env, ...this.env },
|
|
135
|
+
timeout: this.timeout,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
let output = "";
|
|
139
|
+
let truncated = false;
|
|
140
|
+
|
|
141
|
+
child.stdout.on("data", (data: Buffer) => {
|
|
142
|
+
if (output.length < this.maxOutputSize) {
|
|
143
|
+
output += data.toString();
|
|
144
|
+
} else {
|
|
145
|
+
truncated = true;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
child.stderr.on("data", (data: Buffer) => {
|
|
150
|
+
if (output.length < this.maxOutputSize) {
|
|
151
|
+
output += data.toString();
|
|
152
|
+
} else {
|
|
153
|
+
truncated = true;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
child.on("close", (code) => {
|
|
158
|
+
resolve({
|
|
159
|
+
output,
|
|
160
|
+
exitCode: code,
|
|
161
|
+
truncated,
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
child.on("error", (err) => {
|
|
166
|
+
resolve({
|
|
167
|
+
output: `Error: ${err.message}`,
|
|
168
|
+
exitCode: 1,
|
|
169
|
+
truncated: false,
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|