indusagi-coding-agent 0.1.24 → 0.1.26
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/CHANGELOG.md +96 -0
- package/dist/cli/file-processor.js +1 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/discover-packages.d.ts +6 -0
- package/dist/core/discover-packages.d.ts.map +1 -0
- package/dist/core/discover-packages.js +62 -0
- package/dist/core/discover-packages.js.map +1 -0
- package/dist/core/extensions/types.d.ts +1 -3
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +2 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/task-session-manager.d.ts.map +1 -1
- package/dist/core/task-session-manager.js +1 -7
- package/dist/core/task-session-manager.js.map +1 -1
- package/dist/core/tools/bg-process.d.ts +49 -0
- package/dist/core/tools/bg-process.d.ts.map +1 -0
- package/dist/core/tools/bg-process.js +69 -0
- package/dist/core/tools/bg-process.js.map +1 -0
- package/dist/core/tools/index.d.ts +68 -16
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +100 -17
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/registry.d.ts +17 -0
- package/dist/core/tools/registry.d.ts.map +1 -0
- package/dist/core/tools/registry.js +108 -0
- package/dist/core/tools/registry.js.map +1 -0
- package/dist/core/tools/todo.d.ts +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +12 -1
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +1 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +2 -2
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/docs/COMPREHENSIVE-CLI-SUMMARY.md +900 -0
- package/package.json +7 -3
- package/dist/core/tools/bash.d.ts +0 -428
- package/dist/core/tools/bash.d.ts.map +0 -1
- package/dist/core/tools/bash.js +0 -498
- package/dist/core/tools/bash.js.map +0 -1
- package/dist/core/tools/edit-diff.d.ts +0 -63
- package/dist/core/tools/edit-diff.d.ts.map +0 -1
- package/dist/core/tools/edit-diff.js +0 -243
- package/dist/core/tools/edit-diff.js.map +0 -1
- package/dist/core/tools/edit.d.ts +0 -315
- package/dist/core/tools/edit.d.ts.map +0 -1
- package/dist/core/tools/edit.js +0 -384
- package/dist/core/tools/edit.js.map +0 -1
- package/dist/core/tools/find.d.ts +0 -201
- package/dist/core/tools/find.d.ts.map +0 -1
- package/dist/core/tools/find.js +0 -342
- package/dist/core/tools/find.js.map +0 -1
- package/dist/core/tools/grep.d.ts +0 -323
- package/dist/core/tools/grep.d.ts.map +0 -1
- package/dist/core/tools/grep.js +0 -486
- package/dist/core/tools/grep.js.map +0 -1
- package/dist/core/tools/ls.d.ts +0 -44
- package/dist/core/tools/ls.d.ts.map +0 -1
- package/dist/core/tools/ls.js +0 -124
- package/dist/core/tools/ls.js.map +0 -1
- package/dist/core/tools/path-utils.d.ts +0 -8
- package/dist/core/tools/path-utils.d.ts.map +0 -1
- package/dist/core/tools/path-utils.js +0 -53
- package/dist/core/tools/path-utils.js.map +0 -1
- package/dist/core/tools/read.d.ts +0 -338
- package/dist/core/tools/read.d.ts.map +0 -1
- package/dist/core/tools/read.js +0 -397
- package/dist/core/tools/read.js.map +0 -1
- package/dist/core/tools/truncate.d.ts +0 -70
- package/dist/core/tools/truncate.d.ts.map +0 -1
- package/dist/core/tools/truncate.js +0 -205
- package/dist/core/tools/truncate.js.map +0 -1
- package/dist/core/tools/webfetch.d.ts +0 -174
- package/dist/core/tools/webfetch.d.ts.map +0 -1
- package/dist/core/tools/webfetch.js +0 -380
- package/dist/core/tools/webfetch.js.map +0 -1
- package/dist/core/tools/websearch.d.ts +0 -190
- package/dist/core/tools/websearch.d.ts.map +0 -1
- package/dist/core/tools/websearch.js +0 -267
- package/dist/core/tools/websearch.js.map +0 -1
- package/dist/core/tools/write.d.ts +0 -273
- package/dist/core/tools/write.d.ts.map +0 -1
- package/dist/core/tools/write.js +0 -288
- package/dist/core/tools/write.js.map +0 -1
package/dist/core/tools/bash.js
DELETED
|
@@ -1,498 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bash Tool - Execute shell commands with streaming and timeout support
|
|
3
|
-
*
|
|
4
|
-
* @module core/tools/bash
|
|
5
|
-
* @description
|
|
6
|
-
* Implements the bash tool for the agent. Executes arbitrary bash commands
|
|
7
|
-
* in the specified working directory with support for:
|
|
8
|
-
* - Real-time output streaming via onUpdate callbacks
|
|
9
|
-
* - Timeout enforcement
|
|
10
|
-
* - Custom execution backends (SSH, containers)
|
|
11
|
-
*
|
|
12
|
-
* Based on Anthropic's Claude API tool definitions and bash execution patterns.
|
|
13
|
-
* Refactored for agent streaming and multi-backend execution.
|
|
14
|
-
* - Large output handling with temp files
|
|
15
|
-
* - Error exit code detection
|
|
16
|
-
*
|
|
17
|
-
* ## Tool Interface
|
|
18
|
-
*
|
|
19
|
-
* **Input Parameters:**
|
|
20
|
-
* - `command` (required): Bash command to execute
|
|
21
|
-
* - `timeout` (optional): Timeout in seconds (no default)
|
|
22
|
-
*
|
|
23
|
-
* **Output:**
|
|
24
|
-
* - Text content with command output
|
|
25
|
-
* - Tool details with truncation info and full output path
|
|
26
|
-
*
|
|
27
|
-
* **Error Behavior:**
|
|
28
|
-
* - Exit code !== 0 → Tool error (rejected)
|
|
29
|
-
* - Timeout → Tool error "Command timed out after N seconds"
|
|
30
|
-
* - Aborted → Tool error "Command aborted"
|
|
31
|
-
* - Other errors → Tool error with message
|
|
32
|
-
*
|
|
33
|
-
* ## Usage in Agent Loops
|
|
34
|
-
*
|
|
35
|
-
* The agent can use this tool to:
|
|
36
|
-
* - Run tests, builds, and deployments
|
|
37
|
-
* - Query system state (ls, git status, npm list, etc.)
|
|
38
|
-
* - Execute scripts and utilities
|
|
39
|
-
* - Validate changes
|
|
40
|
-
*
|
|
41
|
-
* Tool results are included in LLM context for further analysis.
|
|
42
|
-
*
|
|
43
|
-
* ## Security & Safety
|
|
44
|
-
*
|
|
45
|
-
* **No input validation:**
|
|
46
|
-
* - Commands are executed as-is (caller/LLM responsible for safety)
|
|
47
|
-
* - No command whitelisting or blocking
|
|
48
|
-
* - Caller can restrict via BashOperations interface
|
|
49
|
-
*
|
|
50
|
-
* **Execution isolation:**
|
|
51
|
-
* - Runs in separate process (shell process)
|
|
52
|
-
* - No access to parent's memory or file descriptors
|
|
53
|
-
* - Process killed on abort/timeout (kills children too)
|
|
54
|
-
*
|
|
55
|
-
* **Output safety:**
|
|
56
|
-
* - Large output written to temp files (not memory)
|
|
57
|
-
* - Output truncated tail (keeps last 100KB)
|
|
58
|
-
* - Temp files cleaned up by filesystem (caller responsibility)
|
|
59
|
-
*
|
|
60
|
-
* **Environment handling:**
|
|
61
|
-
* - Merges provided env vars with shell defaults
|
|
62
|
-
* - Caller responsible for filtering sensitive vars
|
|
63
|
-
* - Shell config resolved from system defaults
|
|
64
|
-
*
|
|
65
|
-
* ## Customization
|
|
66
|
-
*
|
|
67
|
-
* **Custom Execution Backend:**
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const sshTool = createBashTool(cwd, {
|
|
70
|
-
* operations: {
|
|
71
|
-
* exec: async (cmd, cwd, opts) => {
|
|
72
|
-
* // SSH execution: ssh user@host "cd cwd && cmd"
|
|
73
|
-
* const { execSync } = require('child_process');
|
|
74
|
-
* // Stream output via opts.onData(buffer)
|
|
75
|
-
* return { exitCode: 0 };
|
|
76
|
-
* },
|
|
77
|
-
* },
|
|
78
|
-
* });
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* **Command Prefix:**
|
|
82
|
-
* ```typescript
|
|
83
|
-
* const aliasedTool = createBashTool(cwd, {
|
|
84
|
-
* commandPrefix: "shopt -s expand_aliases\n. ~/.bashrc",
|
|
85
|
-
* });
|
|
86
|
-
* // Now bash aliases will work
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* **Hook Integration:**
|
|
90
|
-
* ```typescript
|
|
91
|
-
* const toolWithHooks = createBashTool(cwd, {
|
|
92
|
-
* hookRunner: hooksRunner,
|
|
93
|
-
* });
|
|
94
|
-
* // Hooks can inject environment via shell.env hook
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* ## Output Handling
|
|
98
|
-
*
|
|
99
|
-
* **Small output (<50KB):**
|
|
100
|
-
* - Returned directly in tool response
|
|
101
|
-
* - Sent to LLM context immediately
|
|
102
|
-
*
|
|
103
|
-
* **Large output (>50KB):**
|
|
104
|
-
* - Written to temp file: `/tmp/indusagi-bash-<random>.log`
|
|
105
|
-
* - Tool response shows last 100KB with notice
|
|
106
|
-
* - Truncated: true in details
|
|
107
|
-
* - Agent can read full output from fullOutputPath
|
|
108
|
-
*
|
|
109
|
-
* **Very long lines (single line >30KB):**
|
|
110
|
-
* - Edge case: line longer than entire max output
|
|
111
|
-
* - Tool shows truncation notice
|
|
112
|
-
* - Full output still in temp file
|
|
113
|
-
*
|
|
114
|
-
* ## Performance
|
|
115
|
-
*
|
|
116
|
-
* - Output streamed via onUpdate callbacks (no buffering)
|
|
117
|
-
* - Large output written to disk (not memory)
|
|
118
|
-
* - Process stdout/stderr captured separately
|
|
119
|
-
* - Timeout checked per second (or per data chunk)
|
|
120
|
-
*
|
|
121
|
-
* ## Error Handling
|
|
122
|
-
*
|
|
123
|
-
* **Rejected with error message:**
|
|
124
|
-
* - Non-zero exit codes: "Command exited with code X"
|
|
125
|
-
* - Timeout: "Command timed out after X seconds"
|
|
126
|
-
* - Abort: "Command aborted"
|
|
127
|
-
* - Spawn errors: "ENOENT: command not found" etc.
|
|
128
|
-
*
|
|
129
|
-
* **Error recovery:**
|
|
130
|
-
* - Extensions can handle via tool.error hooks
|
|
131
|
-
* - Agent can suggest alternatives or retry
|
|
132
|
-
* - Partial output included in error message
|
|
133
|
-
*
|
|
134
|
-
* ## Examples
|
|
135
|
-
*
|
|
136
|
-
* ### Simple command
|
|
137
|
-
* ```typescript
|
|
138
|
-
* // Agent calls: bash {command: "echo hello"}
|
|
139
|
-
* // Output: "hello"
|
|
140
|
-
* ```
|
|
141
|
-
*
|
|
142
|
-
* ### With streaming
|
|
143
|
-
* ```typescript
|
|
144
|
-
* // Agent calls: bash {command: "npm test"}
|
|
145
|
-
* // onUpdate called repeatedly with partial output
|
|
146
|
-
* // Final result includes full output or temp file path
|
|
147
|
-
* ```
|
|
148
|
-
*
|
|
149
|
-
* ### With timeout
|
|
150
|
-
* ```typescript
|
|
151
|
-
* // Agent calls: bash {command: "sleep 100", timeout: 5}
|
|
152
|
-
* // After 5 seconds: rejected with "Command timed out after 5 seconds"
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
|
-
* ## Attribution
|
|
156
|
-
*
|
|
157
|
-
* Based on: indusagi-agent bash tool
|
|
158
|
-
* Modifications:
|
|
159
|
-
* - Added streaming via onUpdate callbacks
|
|
160
|
-
* - Added temporary file handling for large output
|
|
161
|
-
* - Added hook runner integration
|
|
162
|
-
* - Improved error messages with context
|
|
163
|
-
* - Added custom operations interface for pluggability
|
|
164
|
-
*/
|
|
165
|
-
import { randomBytes } from "node:crypto";
|
|
166
|
-
import { createWriteStream, existsSync } from "node:fs";
|
|
167
|
-
import { tmpdir } from "node:os";
|
|
168
|
-
import { join } from "node:path";
|
|
169
|
-
import { Type } from "@sinclair/typebox";
|
|
170
|
-
import { spawn } from "child_process";
|
|
171
|
-
import { getShellConfig, getShellEnv, killProcessTree } from "../../utils/shell.js";
|
|
172
|
-
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateTail } from "./truncate.js";
|
|
173
|
-
// ============================================================================
|
|
174
|
-
// Utilities
|
|
175
|
-
// ============================================================================
|
|
176
|
-
/**
|
|
177
|
-
* Generate a unique temp file path for bash output
|
|
178
|
-
* @internal
|
|
179
|
-
*/
|
|
180
|
-
function getTempFilePath() {
|
|
181
|
-
const id = randomBytes(8).toString("hex");
|
|
182
|
-
return join(tmpdir(), `indusagi-bash-${id}.log`);
|
|
183
|
-
}
|
|
184
|
-
// ============================================================================
|
|
185
|
-
// Schema & Types
|
|
186
|
-
// ============================================================================
|
|
187
|
-
/**
|
|
188
|
-
* JSON Schema for bash tool parameters
|
|
189
|
-
* @internal
|
|
190
|
-
*/
|
|
191
|
-
const bashSchema = Type.Object({
|
|
192
|
-
command: Type.String({ description: "Bash command to execute" }),
|
|
193
|
-
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
|
|
194
|
-
});
|
|
195
|
-
/**
|
|
196
|
-
* Default bash operations using local system shell
|
|
197
|
-
* @internal
|
|
198
|
-
*/
|
|
199
|
-
const defaultBashOperations = {
|
|
200
|
-
exec: (command, cwd, { onData, signal, timeout, env }) => {
|
|
201
|
-
return new Promise((resolve, reject) => {
|
|
202
|
-
const { shell, args } = getShellConfig();
|
|
203
|
-
if (!existsSync(cwd)) {
|
|
204
|
-
reject(new Error(`Working directory does not exist: ${cwd}\nCannot execute bash commands.`));
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
const child = spawn(shell, [...args, command], {
|
|
208
|
-
cwd,
|
|
209
|
-
detached: true,
|
|
210
|
-
env: { ...getShellEnv(), ...(env ?? {}) },
|
|
211
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
212
|
-
});
|
|
213
|
-
let timedOut = false;
|
|
214
|
-
// Set timeout if provided
|
|
215
|
-
let timeoutHandle;
|
|
216
|
-
if (timeout !== undefined && timeout > 0) {
|
|
217
|
-
timeoutHandle = setTimeout(() => {
|
|
218
|
-
timedOut = true;
|
|
219
|
-
if (child.pid) {
|
|
220
|
-
killProcessTree(child.pid);
|
|
221
|
-
}
|
|
222
|
-
}, timeout * 1000);
|
|
223
|
-
}
|
|
224
|
-
// Stream stdout and stderr
|
|
225
|
-
if (child.stdout) {
|
|
226
|
-
child.stdout.on("data", onData);
|
|
227
|
-
}
|
|
228
|
-
if (child.stderr) {
|
|
229
|
-
child.stderr.on("data", onData);
|
|
230
|
-
}
|
|
231
|
-
// Handle shell spawn errors
|
|
232
|
-
child.on("error", (err) => {
|
|
233
|
-
if (timeoutHandle)
|
|
234
|
-
clearTimeout(timeoutHandle);
|
|
235
|
-
if (signal)
|
|
236
|
-
signal.removeEventListener("abort", onAbort);
|
|
237
|
-
reject(err);
|
|
238
|
-
});
|
|
239
|
-
// Handle abort signal - kill entire process tree
|
|
240
|
-
const onAbort = () => {
|
|
241
|
-
if (child.pid) {
|
|
242
|
-
killProcessTree(child.pid);
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
if (signal) {
|
|
246
|
-
if (signal.aborted) {
|
|
247
|
-
onAbort();
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
// Handle process exit
|
|
254
|
-
child.on("close", (code) => {
|
|
255
|
-
if (timeoutHandle)
|
|
256
|
-
clearTimeout(timeoutHandle);
|
|
257
|
-
if (signal)
|
|
258
|
-
signal.removeEventListener("abort", onAbort);
|
|
259
|
-
if (signal?.aborted) {
|
|
260
|
-
reject(new Error("aborted"));
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
if (timedOut) {
|
|
264
|
-
reject(new Error(`timeout:${timeout}`));
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
resolve({ exitCode: code });
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
},
|
|
271
|
-
};
|
|
272
|
-
// ============================================================================
|
|
273
|
-
// Tool Factory & Exports
|
|
274
|
-
// ============================================================================
|
|
275
|
-
/**
|
|
276
|
-
* Create a bash tool with custom configuration
|
|
277
|
-
*
|
|
278
|
-
* Creates an AgentTool that can execute bash commands. Supports:
|
|
279
|
-
* - Custom execution backends (local, SSH, containers)
|
|
280
|
-
* - Command preprocessing (aliases, initialization)
|
|
281
|
-
* - Hook integration (environment variable injection)
|
|
282
|
-
* - Streaming output and timeout enforcement
|
|
283
|
-
* - Large output handling with temp files
|
|
284
|
-
*
|
|
285
|
-
* **Tool Behavior:**
|
|
286
|
-
* - Commands execute in specified working directory
|
|
287
|
-
* - Output streamed via onUpdate callbacks
|
|
288
|
-
* - Large outputs written to temp files
|
|
289
|
-
* - Non-zero exit codes → Tool error
|
|
290
|
-
* - Timeout errors rejected with message
|
|
291
|
-
* - Abort signal triggers clean cancellation
|
|
292
|
-
*
|
|
293
|
-
* **Tool Parameters:**
|
|
294
|
-
* - `command` (required, string): Bash command to execute
|
|
295
|
-
* - `timeout` (optional, number): Timeout in seconds
|
|
296
|
-
*
|
|
297
|
-
* **Tool Output:**
|
|
298
|
-
* - Text: Command output (last 100KB if truncated)
|
|
299
|
-
* - Details: Truncation info and temp file path
|
|
300
|
-
*
|
|
301
|
-
* @param cwd - Working directory for command execution
|
|
302
|
-
* - Must exist and be readable
|
|
303
|
-
* - Commands execute with this as working directory
|
|
304
|
-
* - Can be overridden per execution
|
|
305
|
-
*
|
|
306
|
-
* @param options - Optional configuration
|
|
307
|
-
* - operations: Custom execution backend (default: local shell)
|
|
308
|
-
* - commandPrefix: Prefix injected into every command
|
|
309
|
-
* - hookRunner: Hooks for environment customization
|
|
310
|
-
*
|
|
311
|
-
* @returns AgentTool instance ready to use
|
|
312
|
-
*
|
|
313
|
-
* **Error Handling:**
|
|
314
|
-
* - Non-zero exit codes: `Tool error: "Command exited with code X"`
|
|
315
|
-
* - Timeout: `Tool error: "Command timed out after X seconds"`
|
|
316
|
-
* - Abort: `Tool error: "Command aborted"`
|
|
317
|
-
* - Spawn errors: `Tool error: "ENOENT: command not found"`
|
|
318
|
-
*
|
|
319
|
-
* @example
|
|
320
|
-
* ```typescript
|
|
321
|
-
* // Basic tool
|
|
322
|
-
* const tool = createBashTool(process.cwd());
|
|
323
|
-
*
|
|
324
|
-
* // With custom backend (SSH)
|
|
325
|
-
* const sshTool = createBashTool("/workspace", {
|
|
326
|
-
* operations: sshOperations,
|
|
327
|
-
* });
|
|
328
|
-
*
|
|
329
|
-
* // With alias support
|
|
330
|
-
* const aliasTool = createBashTool(cwd, {
|
|
331
|
-
* commandPrefix: "shopt -s expand_aliases\n. ~/.bashrc",
|
|
332
|
-
* });
|
|
333
|
-
*
|
|
334
|
-
* // With hooks
|
|
335
|
-
* const hookTool = createBashTool(cwd, {
|
|
336
|
-
* hookRunner: hooksRunner,
|
|
337
|
-
* });
|
|
338
|
-
* ```
|
|
339
|
-
*
|
|
340
|
-
* @see BashToolOptions for detailed configuration options
|
|
341
|
-
* @see BashOperations for custom execution backend interface
|
|
342
|
-
*/
|
|
343
|
-
export function createBashTool(cwd, options) {
|
|
344
|
-
const ops = options?.operations ?? defaultBashOperations;
|
|
345
|
-
const commandPrefix = options?.commandPrefix;
|
|
346
|
-
const hookRunner = options?.hookRunner;
|
|
347
|
-
return {
|
|
348
|
-
name: "bash",
|
|
349
|
-
label: "bash",
|
|
350
|
-
description: `Execute a bash command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,
|
|
351
|
-
parameters: bashSchema,
|
|
352
|
-
execute: async (_toolCallId, { command, timeout }, signal, onUpdate) => {
|
|
353
|
-
// Apply command prefix if configured (e.g., "shopt -s expand_aliases" for alias support)
|
|
354
|
-
const resolvedCommand = commandPrefix ? `${commandPrefix}\n${command}` : command;
|
|
355
|
-
const hookEnv = hookRunner?.hasHandlers("shell.env")
|
|
356
|
-
? (await hookRunner.trigger("shell.env", { cwd }, { env: {} })).env
|
|
357
|
-
: undefined;
|
|
358
|
-
return new Promise((resolve, reject) => {
|
|
359
|
-
// We'll stream to a temp file if output gets large
|
|
360
|
-
let tempFilePath;
|
|
361
|
-
let tempFileStream;
|
|
362
|
-
let totalBytes = 0;
|
|
363
|
-
// Keep a rolling buffer of the last chunk for tail truncation
|
|
364
|
-
const chunks = [];
|
|
365
|
-
let chunksBytes = 0;
|
|
366
|
-
// Keep more than we need so we have enough for truncation
|
|
367
|
-
const maxChunksBytes = DEFAULT_MAX_BYTES * 2;
|
|
368
|
-
const handleData = (data) => {
|
|
369
|
-
totalBytes += data.length;
|
|
370
|
-
// Start writing to temp file once we exceed the threshold
|
|
371
|
-
if (totalBytes > DEFAULT_MAX_BYTES && !tempFilePath) {
|
|
372
|
-
tempFilePath = getTempFilePath();
|
|
373
|
-
tempFileStream = createWriteStream(tempFilePath);
|
|
374
|
-
// Write all buffered chunks to the file
|
|
375
|
-
for (const chunk of chunks) {
|
|
376
|
-
tempFileStream.write(chunk);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
// Write to temp file if we have one
|
|
380
|
-
if (tempFileStream) {
|
|
381
|
-
tempFileStream.write(data);
|
|
382
|
-
}
|
|
383
|
-
// Keep rolling buffer of recent data
|
|
384
|
-
chunks.push(data);
|
|
385
|
-
chunksBytes += data.length;
|
|
386
|
-
// Trim old chunks if buffer is too large
|
|
387
|
-
while (chunksBytes > maxChunksBytes && chunks.length > 1) {
|
|
388
|
-
const removed = chunks.shift();
|
|
389
|
-
chunksBytes -= removed.length;
|
|
390
|
-
}
|
|
391
|
-
// Stream partial output to callback (truncated rolling buffer)
|
|
392
|
-
if (onUpdate) {
|
|
393
|
-
const fullBuffer = Buffer.concat(chunks);
|
|
394
|
-
const fullText = fullBuffer.toString("utf-8");
|
|
395
|
-
const truncation = truncateTail(fullText);
|
|
396
|
-
onUpdate({
|
|
397
|
-
content: [{ type: "text", text: truncation.content || "" }],
|
|
398
|
-
details: {
|
|
399
|
-
truncation: truncation.truncated ? truncation : undefined,
|
|
400
|
-
fullOutputPath: tempFilePath,
|
|
401
|
-
},
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
ops.exec(resolvedCommand, cwd, { onData: handleData, signal, timeout, env: hookEnv })
|
|
406
|
-
.then(({ exitCode }) => {
|
|
407
|
-
// Close temp file stream
|
|
408
|
-
if (tempFileStream) {
|
|
409
|
-
tempFileStream.end();
|
|
410
|
-
}
|
|
411
|
-
// Combine all buffered chunks
|
|
412
|
-
const fullBuffer = Buffer.concat(chunks);
|
|
413
|
-
const fullOutput = fullBuffer.toString("utf-8");
|
|
414
|
-
// Apply tail truncation
|
|
415
|
-
const truncation = truncateTail(fullOutput);
|
|
416
|
-
let outputText = truncation.content || "(no output)";
|
|
417
|
-
// Build details with truncation info
|
|
418
|
-
let details;
|
|
419
|
-
if (truncation.truncated) {
|
|
420
|
-
details = {
|
|
421
|
-
truncation,
|
|
422
|
-
fullOutputPath: tempFilePath,
|
|
423
|
-
};
|
|
424
|
-
// Build actionable notice
|
|
425
|
-
const startLine = truncation.totalLines - truncation.outputLines + 1;
|
|
426
|
-
const endLine = truncation.totalLines;
|
|
427
|
-
if (truncation.lastLinePartial) {
|
|
428
|
-
// Edge case: last line alone > 30KB
|
|
429
|
-
const lastLineSize = formatSize(Buffer.byteLength(fullOutput.split("\n").pop() || "", "utf-8"));
|
|
430
|
-
outputText += `\n\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${tempFilePath}]`;
|
|
431
|
-
}
|
|
432
|
-
else if (truncation.truncatedBy === "lines") {
|
|
433
|
-
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${tempFilePath}]`;
|
|
434
|
-
}
|
|
435
|
-
else {
|
|
436
|
-
outputText += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${tempFilePath}]`;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
if (exitCode !== 0 && exitCode !== null) {
|
|
440
|
-
outputText += `\n\nCommand exited with code ${exitCode}`;
|
|
441
|
-
reject(new Error(outputText));
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
resolve({ content: [{ type: "text", text: outputText }], details });
|
|
445
|
-
}
|
|
446
|
-
})
|
|
447
|
-
.catch((err) => {
|
|
448
|
-
// Close temp file stream
|
|
449
|
-
if (tempFileStream) {
|
|
450
|
-
tempFileStream.end();
|
|
451
|
-
}
|
|
452
|
-
// Combine all buffered chunks for error output
|
|
453
|
-
const fullBuffer = Buffer.concat(chunks);
|
|
454
|
-
let output = fullBuffer.toString("utf-8");
|
|
455
|
-
if (err.message === "aborted") {
|
|
456
|
-
if (output)
|
|
457
|
-
output += "\n\n";
|
|
458
|
-
output += "Command aborted";
|
|
459
|
-
reject(new Error(output));
|
|
460
|
-
}
|
|
461
|
-
else if (err.message.startsWith("timeout:")) {
|
|
462
|
-
const timeoutSecs = err.message.split(":")[1];
|
|
463
|
-
if (output)
|
|
464
|
-
output += "\n\n";
|
|
465
|
-
output += `Command timed out after ${timeoutSecs} seconds`;
|
|
466
|
-
reject(new Error(output));
|
|
467
|
-
}
|
|
468
|
-
else {
|
|
469
|
-
reject(err);
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
});
|
|
473
|
-
},
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Default bash tool instance
|
|
478
|
-
*
|
|
479
|
-
* Pre-created bash tool using current process working directory.
|
|
480
|
-
* Useful for simple cases where customization isn't needed.
|
|
481
|
-
*
|
|
482
|
-
* Equivalent to:
|
|
483
|
-
* ```typescript
|
|
484
|
-
* const bashTool = createBashTool(process.cwd());
|
|
485
|
-
* ```
|
|
486
|
-
*
|
|
487
|
-
* For custom configuration, use createBashTool() directly.
|
|
488
|
-
*
|
|
489
|
-
* @example
|
|
490
|
-
* ```typescript
|
|
491
|
-
* import { bashTool } from "./tools/bash.js";
|
|
492
|
-
* const agent = new Agent({ tools: [bashTool] });
|
|
493
|
-
* ```
|
|
494
|
-
*
|
|
495
|
-
* @see createBashTool for custom configuration
|
|
496
|
-
*/
|
|
497
|
-
export const bashTool = createBashTool(process.cwd());
|
|
498
|
-
//# sourceMappingURL=bash.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEpF,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAyB,YAAY,EAAE,MAAM,eAAe,C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AI,MAAM;4BAAE,MAAM,IAAI,MAAM,CAAC;wBAC7B,MAAM,IAAI,2BAA2B,WAAW,UAAU,CAAC;wBAC3D,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;oBAC3B,CAAC;yBAAM,CAAC;wBACP,MAAM,CAAC,GAAG,CAAC,CAAC;oBACb,CAAC;gBACF,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared diff computation utilities for the edit tool.
|
|
3
|
-
* Used by both edit.ts (for execution) and tool-execution.ts (for preview rendering).
|
|
4
|
-
*/
|
|
5
|
-
export declare function detectLineEnding(content: string): "\r\n" | "\n";
|
|
6
|
-
export declare function normalizeToLF(text: string): string;
|
|
7
|
-
export declare function restoreLineEndings(text: string, ending: "\r\n" | "\n"): string;
|
|
8
|
-
/**
|
|
9
|
-
* Normalize text for fuzzy matching. Applies progressive transformations:
|
|
10
|
-
* - Strip trailing whitespace from each line
|
|
11
|
-
* - Normalize smart quotes to ASCII equivalents
|
|
12
|
-
* - Normalize Unicode dashes/hyphens to ASCII hyphen
|
|
13
|
-
* - Normalize special Unicode spaces to regular space
|
|
14
|
-
*/
|
|
15
|
-
export declare function normalizeForFuzzyMatch(text: string): string;
|
|
16
|
-
export interface FuzzyMatchResult {
|
|
17
|
-
/** Whether a match was found */
|
|
18
|
-
found: boolean;
|
|
19
|
-
/** The index where the match starts (in the content that should be used for replacement) */
|
|
20
|
-
index: number;
|
|
21
|
-
/** Length of the matched text */
|
|
22
|
-
matchLength: number;
|
|
23
|
-
/** Whether fuzzy matching was used (false = exact match) */
|
|
24
|
-
usedFuzzyMatch: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* The content to use for replacement operations.
|
|
27
|
-
* When exact match: original content. When fuzzy match: normalized content.
|
|
28
|
-
*/
|
|
29
|
-
contentForReplacement: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Find oldText in content, trying exact match first, then fuzzy match.
|
|
33
|
-
* When fuzzy matching is used, the returned contentForReplacement is the
|
|
34
|
-
* fuzzy-normalized version of the content (trailing whitespace stripped,
|
|
35
|
-
* Unicode quotes/dashes normalized to ASCII).
|
|
36
|
-
*/
|
|
37
|
-
export declare function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult;
|
|
38
|
-
/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */
|
|
39
|
-
export declare function stripBom(content: string): {
|
|
40
|
-
bom: string;
|
|
41
|
-
text: string;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Generate a unified diff string with line numbers and context.
|
|
45
|
-
* Returns both the diff string and the first changed line number (in the new file).
|
|
46
|
-
*/
|
|
47
|
-
export declare function generateDiffString(oldContent: string, newContent: string, contextLines?: number): {
|
|
48
|
-
diff: string;
|
|
49
|
-
firstChangedLine: number | undefined;
|
|
50
|
-
};
|
|
51
|
-
export interface EditDiffResult {
|
|
52
|
-
diff: string;
|
|
53
|
-
firstChangedLine: number | undefined;
|
|
54
|
-
}
|
|
55
|
-
export interface EditDiffError {
|
|
56
|
-
error: string;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Compute the diff for an edit operation without applying it.
|
|
60
|
-
* Used for preview rendering in the TUI before the tool executes.
|
|
61
|
-
*/
|
|
62
|
-
export declare function computeEditDiff(path: string, oldText: string, newText: string, cwd: string): Promise<EditDiffResult | EditDiffError>;
|
|
63
|
-
//# sourceMappingURL=edit-diff.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"edit-diff.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA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