indusagi-coding-agent 0.1.22 → 0.1.24

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.
Files changed (222) hide show
  1. package/CHANGELOG.md +72 -11
  2. package/README.md +2 -36
  3. package/dist/cli/args.d.ts +117 -1
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +231 -64
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/config-selector.d.ts +58 -2
  8. package/dist/cli/config-selector.d.ts.map +1 -1
  9. package/dist/cli/config-selector.js +130 -12
  10. package/dist/cli/config-selector.js.map +1 -1
  11. package/dist/cli/file-processor.d.ts +70 -2
  12. package/dist/cli/file-processor.d.ts.map +1 -1
  13. package/dist/cli/file-processor.js +240 -15
  14. package/dist/cli/file-processor.js.map +1 -1
  15. package/dist/cli/list-models.d.ts +63 -3
  16. package/dist/cli/list-models.d.ts.map +1 -1
  17. package/dist/cli/list-models.js +202 -27
  18. package/dist/cli/list-models.js.map +1 -1
  19. package/dist/cli/login-handler.d.ts +82 -8
  20. package/dist/cli/login-handler.d.ts.map +1 -1
  21. package/dist/cli/login-handler.js +410 -77
  22. package/dist/cli/login-handler.js.map +1 -1
  23. package/dist/cli/session-picker.d.ts +74 -2
  24. package/dist/cli/session-picker.d.ts.map +1 -1
  25. package/dist/cli/session-picker.js +236 -12
  26. package/dist/cli/session-picker.js.map +1 -1
  27. package/dist/core/agent-session.d.ts +214 -9
  28. package/dist/core/agent-session.d.ts.map +1 -1
  29. package/dist/core/agent-session.js +214 -9
  30. package/dist/core/agent-session.js.map +1 -1
  31. package/dist/core/bash-executor.d.ts +302 -12
  32. package/dist/core/bash-executor.d.ts.map +1 -1
  33. package/dist/core/bash-executor.js +302 -12
  34. package/dist/core/bash-executor.js.map +1 -1
  35. package/dist/core/diagnostics.d.ts +191 -0
  36. package/dist/core/diagnostics.d.ts.map +1 -1
  37. package/dist/core/diagnostics.js +142 -0
  38. package/dist/core/diagnostics.js.map +1 -1
  39. package/dist/core/event-bus.d.ts +146 -0
  40. package/dist/core/event-bus.d.ts.map +1 -1
  41. package/dist/core/event-bus.js +93 -0
  42. package/dist/core/event-bus.js.map +1 -1
  43. package/dist/core/export-html/ansi-to-html.d.ts +4 -0
  44. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  45. package/dist/core/export-html/ansi-to-html.js +4 -0
  46. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  47. package/dist/core/export-html/index.d.ts +128 -0
  48. package/dist/core/export-html/index.d.ts.map +1 -1
  49. package/dist/core/export-html/index.js +128 -0
  50. package/dist/core/export-html/index.js.map +1 -1
  51. package/dist/core/export-html/tool-renderer.d.ts +4 -0
  52. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  53. package/dist/core/export-html/tool-renderer.js +4 -0
  54. package/dist/core/export-html/tool-renderer.js.map +1 -1
  55. package/dist/core/keybindings.d.ts +142 -0
  56. package/dist/core/keybindings.d.ts.map +1 -1
  57. package/dist/core/keybindings.js +142 -0
  58. package/dist/core/keybindings.js.map +1 -1
  59. package/dist/core/model-registry.d.ts +98 -1
  60. package/dist/core/model-registry.d.ts.map +1 -1
  61. package/dist/core/model-registry.js +98 -1
  62. package/dist/core/model-registry.js.map +1 -1
  63. package/dist/core/model-resolver.d.ts +99 -1
  64. package/dist/core/model-resolver.d.ts.map +1 -1
  65. package/dist/core/model-resolver.js +99 -1
  66. package/dist/core/model-resolver.js.map +1 -1
  67. package/dist/core/prompt-templates.js.map +1 -1
  68. package/dist/core/sdk.d.ts +1 -1
  69. package/dist/core/sdk.d.ts.map +1 -1
  70. package/dist/core/sdk.js +0 -2
  71. package/dist/core/sdk.js.map +1 -1
  72. package/dist/core/session-manager.d.ts +127 -0
  73. package/dist/core/session-manager.d.ts.map +1 -1
  74. package/dist/core/session-manager.js +125 -0
  75. package/dist/core/session-manager.js.map +1 -1
  76. package/dist/core/skills.js.map +1 -1
  77. package/dist/core/subagents.js.map +1 -1
  78. package/dist/core/tools/bash.d.ts +391 -11
  79. package/dist/core/tools/bash.d.ts.map +1 -1
  80. package/dist/core/tools/bash.js +269 -2
  81. package/dist/core/tools/bash.js.map +1 -1
  82. package/dist/core/tools/edit.d.ts +284 -6
  83. package/dist/core/tools/edit.d.ts.map +1 -1
  84. package/dist/core/tools/edit.js +238 -0
  85. package/dist/core/tools/edit.js.map +1 -1
  86. package/dist/core/tools/find.d.ts +169 -5
  87. package/dist/core/tools/find.d.ts.map +1 -1
  88. package/dist/core/tools/find.js +136 -0
  89. package/dist/core/tools/find.js.map +1 -1
  90. package/dist/core/tools/grep.d.ts +285 -5
  91. package/dist/core/tools/grep.d.ts.map +1 -1
  92. package/dist/core/tools/grep.js +247 -0
  93. package/dist/core/tools/grep.js.map +1 -1
  94. package/dist/core/tools/index.d.ts +0 -18
  95. package/dist/core/tools/index.d.ts.map +1 -1
  96. package/dist/core/tools/index.js +1 -23
  97. package/dist/core/tools/index.js.map +1 -1
  98. package/dist/core/tools/ls.d.ts +6 -0
  99. package/dist/core/tools/ls.d.ts.map +1 -1
  100. package/dist/core/tools/ls.js +6 -0
  101. package/dist/core/tools/ls.js.map +1 -1
  102. package/dist/core/tools/read.d.ts +308 -7
  103. package/dist/core/tools/read.d.ts.map +1 -1
  104. package/dist/core/tools/read.js +231 -0
  105. package/dist/core/tools/read.js.map +1 -1
  106. package/dist/core/tools/webfetch.d.ts +118 -3
  107. package/dist/core/tools/webfetch.d.ts.map +1 -1
  108. package/dist/core/tools/webfetch.js +118 -3
  109. package/dist/core/tools/webfetch.js.map +1 -1
  110. package/dist/core/tools/websearch.d.ts +130 -3
  111. package/dist/core/tools/websearch.d.ts.map +1 -1
  112. package/dist/core/tools/websearch.js +130 -3
  113. package/dist/core/tools/websearch.js.map +1 -1
  114. package/dist/core/tools/write.d.ts +251 -5
  115. package/dist/core/tools/write.d.ts.map +1 -1
  116. package/dist/core/tools/write.js +210 -0
  117. package/dist/core/tools/write.js.map +1 -1
  118. package/dist/modes/interactive/components/assistant-message.d.ts +164 -1
  119. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  120. package/dist/modes/interactive/components/assistant-message.js +164 -1
  121. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  122. package/dist/modes/interactive/components/bash-execution.d.ts +297 -1
  123. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  124. package/dist/modes/interactive/components/bash-execution.js +297 -1
  125. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  126. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  127. package/dist/modes/interactive/components/tool-execution.js +251 -1
  128. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  129. package/dist/modes/interactive/components/user-message.d.ts +186 -1
  130. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  131. package/dist/modes/interactive/components/user-message.js +186 -1
  132. package/dist/modes/interactive/components/user-message.js.map +1 -1
  133. package/dist/modes/interactive/interactive-mode.d.ts +1567 -13
  134. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  135. package/dist/modes/interactive/interactive-mode.js +1567 -13
  136. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  137. package/dist/modes/interactive/theme/theme.d.ts +422 -0
  138. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  139. package/dist/modes/interactive/theme/theme.js +422 -0
  140. package/dist/modes/interactive/theme/theme.js.map +1 -1
  141. package/dist/modes/print-mode.d.ts +538 -5
  142. package/dist/modes/print-mode.d.ts.map +1 -1
  143. package/dist/modes/print-mode.js +538 -5
  144. package/dist/modes/print-mode.js.map +1 -1
  145. package/dist/modes/rpc/rpc-client.d.ts +921 -8
  146. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  147. package/dist/modes/rpc/rpc-client.js +921 -8
  148. package/dist/modes/rpc/rpc-client.js.map +1 -1
  149. package/dist/modes/rpc/rpc-mode.d.ts +802 -9
  150. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  151. package/dist/modes/rpc/rpc-mode.js +802 -9
  152. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  153. package/dist/modes/rpc/rpc-types.d.ts +356 -3
  154. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  155. package/dist/modes/rpc/rpc-types.js +356 -3
  156. package/dist/modes/rpc/rpc-types.js.map +1 -1
  157. package/dist/modes/shared.d.ts +386 -0
  158. package/dist/modes/shared.d.ts.map +1 -0
  159. package/dist/modes/shared.js +543 -0
  160. package/dist/modes/shared.js.map +1 -0
  161. package/dist/utils/array.d.ts +389 -0
  162. package/dist/utils/array.d.ts.map +1 -0
  163. package/dist/utils/array.js +585 -0
  164. package/dist/utils/array.js.map +1 -0
  165. package/dist/utils/color-formatter.d.ts +318 -0
  166. package/dist/utils/color-formatter.d.ts.map +1 -0
  167. package/dist/utils/color-formatter.js +442 -0
  168. package/dist/utils/color-formatter.js.map +1 -0
  169. package/dist/utils/data-transformer.d.ts +326 -0
  170. package/dist/utils/data-transformer.d.ts.map +1 -0
  171. package/dist/utils/data-transformer.js +512 -0
  172. package/dist/utils/data-transformer.js.map +1 -0
  173. package/dist/utils/date-formatter.d.ts +281 -0
  174. package/dist/utils/date-formatter.d.ts.map +1 -0
  175. package/dist/utils/date-formatter.js +503 -0
  176. package/dist/utils/date-formatter.js.map +1 -0
  177. package/dist/utils/error-handler.d.ts +541 -0
  178. package/dist/utils/error-handler.d.ts.map +1 -0
  179. package/dist/utils/error-handler.js +726 -0
  180. package/dist/utils/error-handler.js.map +1 -0
  181. package/dist/utils/file-operations.d.ts +297 -0
  182. package/dist/utils/file-operations.d.ts.map +1 -0
  183. package/dist/utils/file-operations.js +505 -0
  184. package/dist/utils/file-operations.js.map +1 -0
  185. package/dist/utils/frontmatter.d.ts +268 -6
  186. package/dist/utils/frontmatter.d.ts.map +1 -1
  187. package/dist/utils/frontmatter.js +500 -21
  188. package/dist/utils/frontmatter.js.map +1 -1
  189. package/dist/utils/json-formatter.d.ts +259 -0
  190. package/dist/utils/json-formatter.d.ts.map +1 -0
  191. package/dist/utils/json-formatter.js +517 -0
  192. package/dist/utils/json-formatter.js.map +1 -0
  193. package/dist/utils/logger.d.ts +176 -0
  194. package/dist/utils/logger.d.ts.map +1 -0
  195. package/dist/utils/logger.js +346 -0
  196. package/dist/utils/logger.js.map +1 -0
  197. package/dist/utils/markdown-formatter.d.ts +211 -0
  198. package/dist/utils/markdown-formatter.d.ts.map +1 -0
  199. package/dist/utils/markdown-formatter.js +482 -0
  200. package/dist/utils/markdown-formatter.js.map +1 -0
  201. package/dist/utils/path-validator.d.ts +603 -0
  202. package/dist/utils/path-validator.d.ts.map +1 -0
  203. package/dist/utils/path-validator.js +870 -0
  204. package/dist/utils/path-validator.js.map +1 -0
  205. package/dist/utils/string-formatter.d.ts +609 -0
  206. package/dist/utils/string-formatter.d.ts.map +1 -0
  207. package/dist/utils/string-formatter.js +806 -0
  208. package/dist/utils/string-formatter.js.map +1 -0
  209. package/dist/utils/type-guards.d.ts +629 -0
  210. package/dist/utils/type-guards.d.ts.map +1 -0
  211. package/dist/utils/type-guards.js +662 -0
  212. package/dist/utils/type-guards.js.map +1 -0
  213. package/docs/COMPLETE-GUIDE.md +300 -0
  214. package/docs/MODES-ARCHITECTURE.md +565 -0
  215. package/docs/PRINT-MODE-GUIDE.md +456 -0
  216. package/docs/README.md +1 -2
  217. package/docs/RPC-GUIDE.md +705 -0
  218. package/docs/UTILS-IMPLEMENTATION-SUMMARY.md +647 -0
  219. package/docs/UTILS-MODULE-OVERVIEW.md +1480 -0
  220. package/docs/UTILS-QA-CHECKLIST.md +1061 -0
  221. package/docs/UTILS-USAGE-GUIDE.md +1419 -0
  222. package/package.json +3 -3
@@ -1,3 +1,167 @@
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
+ */
1
165
  import { randomBytes } from "node:crypto";
2
166
  import { createWriteStream, existsSync } from "node:fs";
3
167
  import { tmpdir } from "node:os";
@@ -6,19 +170,31 @@ import { Type } from "@sinclair/typebox";
6
170
  import { spawn } from "child_process";
7
171
  import { getShellConfig, getShellEnv, killProcessTree } from "../../utils/shell.js";
8
172
  import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateTail } from "./truncate.js";
173
+ // ============================================================================
174
+ // Utilities
175
+ // ============================================================================
9
176
  /**
10
177
  * Generate a unique temp file path for bash output
178
+ * @internal
11
179
  */
12
180
  function getTempFilePath() {
13
181
  const id = randomBytes(8).toString("hex");
14
182
  return join(tmpdir(), `indusagi-bash-${id}.log`);
15
183
  }
184
+ // ============================================================================
185
+ // Schema & Types
186
+ // ============================================================================
187
+ /**
188
+ * JSON Schema for bash tool parameters
189
+ * @internal
190
+ */
16
191
  const bashSchema = Type.Object({
17
192
  command: Type.String({ description: "Bash command to execute" }),
18
193
  timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
19
194
  });
20
195
  /**
21
- * Default bash operations using local shell
196
+ * Default bash operations using local system shell
197
+ * @internal
22
198
  */
23
199
  const defaultBashOperations = {
24
200
  exec: (command, cwd, { onData, signal, timeout, env }) => {
@@ -93,6 +269,77 @@ const defaultBashOperations = {
93
269
  });
94
270
  },
95
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
+ */
96
343
  export function createBashTool(cwd, options) {
97
344
  const ops = options?.operations ?? defaultBashOperations;
98
345
  const commandPrefix = options?.commandPrefix;
@@ -226,6 +473,26 @@ export function createBashTool(cwd, options) {
226
473
  },
227
474
  };
228
475
  }
229
- /** Default bash tool using process.cwd() - for backwards compatibility */
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
+ */
230
497
  export const bashTool = createBashTool(process.cwd());
231
498
  //# sourceMappingURL=bash.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/core/tools/bash.ts"],"names":[],"mappings":"AAAA,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,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AAC;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,9 +1,165 @@
1
+ /**
2
+ * Edit Tool - Precise text replacement with fuzzy matching and diff output
3
+ *
4
+ * @module core/tools/edit
5
+ * @description
6
+ * Implements the edit tool for the agent. Replaces text in files with:
7
+ * - Fuzzy matching (handles minor whitespace variations)
8
+ * - Unified diff output (shows changes)
9
+ * - Line ending preservation (CRLF, LF)
10
+ * - BOM handling (UTF-8 with BOM)
11
+ *
12
+ * Based on text editing patterns from Anthropic's Claude API (claude-opus model).
13
+ * Fuzzy matching inspired by Ruby's string-similarity algorithms.
14
+ * Refactored for precise agent code modification.
15
+ * - Remote execution support (SSH, containers)
16
+ * - Exact character-level matching
17
+ *
18
+ * ## Tool Interface
19
+ *
20
+ * **Input Parameters:**
21
+ * - `path` (required): File to edit
22
+ * - `oldText` (required): Text to find (must match exactly or fuzzily)
23
+ * - `newText` (required): Replacement text
24
+ *
25
+ * **Output:**
26
+ * - Unified diff showing changes
27
+ * - Line number of first change (for editor navigation)
28
+ * - Error if pattern not found
29
+ *
30
+ * **Error Behavior:**
31
+ * - Pattern not found → Tool error "Pattern not found"
32
+ * - File not found → Tool error "ENOENT: no such file"
33
+ * - Permission denied → Tool error "EACCES: permission denied"
34
+ * - Multiple matches → Tool error "Ambiguous match" (if fuzzy enabled)
35
+ *
36
+ * ## Usage in Agent
37
+ *
38
+ * The agent uses this tool to:
39
+ * - Refactor code (rename functions, update logic)
40
+ * - Fix bugs (change implementations)
41
+ * - Update configuration
42
+ * - Modify test cases
43
+ * - Apply patches
44
+ *
45
+ * ## Matching Algorithm
46
+ *
47
+ * **Exact Matching (default):**
48
+ * - Finds exact string match
49
+ * - Case-sensitive
50
+ * - Whitespace-sensitive
51
+ *
52
+ * **Fuzzy Matching (when enabled):**
53
+ * - Normalizes whitespace
54
+ * - Handles line ending differences
55
+ * - Finds similar strings (for minor variations)
56
+ * - Reports ambiguity if multiple matches
57
+ *
58
+ * ## Features
59
+ *
60
+ * **Line Ending Preservation:**
61
+ * - Detects file's line ending (CRLF or LF)
62
+ * - Preserves in replaced content
63
+ * - Handles mixed line endings gracefully
64
+ *
65
+ * **Normalization:**
66
+ * - Strips BOM if present (UTF-8 with BOM)
67
+ * - Normalizes to LF internally
68
+ * - Restores original format on write
69
+ *
70
+ * **Diff Output:**
71
+ * - Unified diff format
72
+ * - Shows context lines
73
+ * - Indicates changed lines
74
+ * - Line numbers for navigation
75
+ *
76
+ * **Unicode Support:**
77
+ * - Handles UTF-8 correctly
78
+ * - Preserves multibyte characters
79
+ * - BOM aware
80
+ *
81
+ * ## Security
82
+ *
83
+ * **Path validation:**
84
+ * - All paths resolved relative to cwd
85
+ * - No path traversal
86
+ * - Directory traversal prevented
87
+ *
88
+ * **Text matching:**
89
+ * - Pattern matching is literal (not regex)
90
+ * - No code execution via replacement
91
+ * - No template substitution
92
+ *
93
+ * **File safety:**
94
+ * - Read-write permission check
95
+ * - Atomic write (no partial files)
96
+ * - Error on read failures
97
+ *
98
+ * ## Customization
99
+ *
100
+ * **Fuzzy Matching:**
101
+ * ```typescript
102
+ * const tool = createEditTool(cwd, {
103
+ * fuzzyMatch: true, // Enable fuzzy matching
104
+ * });
105
+ * ```
106
+ *
107
+ * **Remote Execution (SSH):**
108
+ * ```typescript
109
+ * const sshTool = createEditTool(cwd, {
110
+ * operations: {
111
+ * readFile: (path) => sshExec(`cat ${path}`),
112
+ * writeFile: (path, content) => sshExec(`cat > ${path}`, content),
113
+ * access: (path) => sshExec(`test -r -w ${path}`),
114
+ * },
115
+ * });
116
+ * ```
117
+ *
118
+ * ## Examples
119
+ *
120
+ * ### Simple replacement
121
+ * ```typescript
122
+ * // Agent calls: edit {
123
+ * // path: "main.ts",
124
+ * // oldText: "const x = 1;",
125
+ * // newText: "const x = 2;"
126
+ * // }
127
+ * ```
128
+ *
129
+ * ### Multi-line replacement
130
+ * ```typescript
131
+ * // Agent calls: edit {
132
+ * // path: "server.ts",
133
+ * // oldText: "app.listen(3000);\nconsole.log('Ready');",
134
+ * // newText: "app.listen(process.env.PORT || 3000);\nconsole.log(`Listening on port ${port}`);"
135
+ * // }
136
+ * ```
137
+ *
138
+ * ## Attribution
139
+ *
140
+ * Based on: indusagi-agent edit tool
141
+ * Modifications:
142
+ * - Added fuzzy matching option
143
+ * - Added unified diff output
144
+ * - Added line ending preservation
145
+ * - Added custom operations interface
146
+ * - Improved error messages
147
+ */
1
148
  import type { AgentTool } from "indusagi/agent";
149
+ /**
150
+ * JSON Schema for edit tool parameters
151
+ * @internal
152
+ */
2
153
  declare const editSchema: import("@sinclair/typebox").TObject<{
3
154
  path: import("@sinclair/typebox").TString;
4
155
  oldText: import("@sinclair/typebox").TString;
5
156
  newText: import("@sinclair/typebox").TString;
6
157
  }>;
158
+ /**
159
+ * Tool-specific details returned with edit results
160
+ *
161
+ * Provides diff information and navigation hints.
162
+ */
7
163
  export interface EditToolDetails {
8
164
  /** Unified diff of the changes made */
9
165
  diff: string;
@@ -11,23 +167,145 @@ export interface EditToolDetails {
11
167
  firstChangedLine?: number;
12
168
  }
13
169
  /**
14
- * Pluggable operations for the edit tool.
15
- * Override these to delegate file editing to remote systems (e.g., SSH).
170
+ * Pluggable interface for file editing operations
171
+ *
172
+ * Allows custom implementations for:
173
+ * - Remote file systems (SSH, cloud storage)
174
+ * - Virtual file systems (in-memory, testing)
175
+ * - Custom permission models
176
+ * - Monitoring and auditing
177
+ *
178
+ * Implementations must respect working directory boundaries.
16
179
  */
17
180
  export interface EditOperations {
18
- /** Read file contents as a Buffer */
181
+ /**
182
+ * Read file contents as a Buffer
183
+ *
184
+ * @param absolutePath - Full path to file (already validated)
185
+ * @returns Buffer with file contents
186
+ * @throws Error on read failures
187
+ */
19
188
  readFile: (absolutePath: string) => Promise<Buffer>;
20
- /** Write content to a file */
189
+ /**
190
+ * Write content to a file (overwrite completely)
191
+ *
192
+ * @param absolutePath - Full path to file (already validated)
193
+ * @param content - File content as string
194
+ * @throws Error on write failures
195
+ */
21
196
  writeFile: (absolutePath: string, content: string) => Promise<void>;
22
- /** Check if file is readable and writable (throw if not) */
197
+ /**
198
+ * Check if file is readable and writable
199
+ *
200
+ * @param absolutePath - Full path to file (already validated)
201
+ * @throws Error if not readable/writable
202
+ */
23
203
  access: (absolutePath: string) => Promise<void>;
24
204
  }
205
+ /**
206
+ * Configuration options for the edit tool
207
+ *
208
+ * Allows customization of file editing backend.
209
+ */
25
210
  export interface EditToolOptions {
26
- /** Custom operations for file editing. Default: local filesystem */
211
+ /**
212
+ * Custom operations for file editing
213
+ *
214
+ * Default: Local filesystem operations
215
+ * Custom: SSH, cloud storage, testing mocks
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * const tool = createEditTool(cwd, {
220
+ * operations: {
221
+ * readFile: (path) => sshExec(`cat ${path}`),
222
+ * writeFile: (path, content) => sshExec(`cat > ${path}`, content),
223
+ * access: (path) => sshExec(`test -r -w ${path}`),
224
+ * },
225
+ * });
226
+ * ```
227
+ */
27
228
  operations?: EditOperations;
28
229
  }
230
+ /**
231
+ * Create an edit tool with custom configuration
232
+ *
233
+ * Creates an AgentTool that can edit files with:
234
+ * - Exact text replacement
235
+ * - Fuzzy matching (optional)
236
+ * - Unified diff output
237
+ * - Line ending preservation
238
+ * - Remote execution support
239
+ *
240
+ * **Tool Behavior:**
241
+ * - Resolves paths relative to working directory
242
+ * - Prevents path traversal
243
+ * - Finds and replaces exact text
244
+ * - Preserves file format (line endings, BOM)
245
+ * - Returns unified diff of changes
246
+ *
247
+ * **Tool Parameters:**
248
+ * - `path` (required): File to edit
249
+ * - `oldText` (required): Text to find
250
+ * - `newText` (required): Replacement text
251
+ *
252
+ * **Tool Output:**
253
+ * - Success message with unified diff
254
+ * - Details: Diff and first changed line number
255
+ * - Errors: Tool error with message
256
+ *
257
+ * **Error Handling:**
258
+ * - Pattern not found: Tool error "Pattern not found"
259
+ * - File not found: Tool error "ENOENT: no such file"
260
+ * - Permission denied: Tool error "EACCES: permission denied"
261
+ * - Other errors: Tool error with message
262
+ *
263
+ * @param cwd - Working directory for relative path resolution
264
+ * - All relative paths resolved from this directory
265
+ * - Prevents directory traversal attacks
266
+ *
267
+ * @param options - Optional configuration
268
+ * - operations: Custom file editing backend (default: filesystem)
269
+ *
270
+ * @returns AgentTool instance ready to use
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * // Basic tool
275
+ * const tool = createEditTool(process.cwd());
276
+ *
277
+ * // With remote backend (SSH)
278
+ * const remoteTool = createEditTool(cwd, {
279
+ * operations: sshOperations,
280
+ * });
281
+ * ```
282
+ *
283
+ * @see EditToolOptions for detailed configuration
284
+ * @see EditOperations for custom backend interface
285
+ */
29
286
  export declare function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema>;
30
287
  /** Default edit tool using process.cwd() - for backwards compatibility */
288
+ /**
289
+ * Default edit tool instance
290
+ *
291
+ * Pre-created edit tool using current process working directory.
292
+ * Supports exact text replacement with unified diff output.
293
+ *
294
+ * Equivalent to:
295
+ * ```typescript
296
+ * const editTool = createEditTool(process.cwd());
297
+ * ```
298
+ *
299
+ * For custom configuration or remote backends, use createEditTool() directly.
300
+ *
301
+ * @example
302
+ * ```typescript
303
+ * import { editTool } from "./tools/edit.js";
304
+ * const agent = new Agent({ tools: [editTool] });
305
+ * ```
306
+ *
307
+ * @see createEditTool for custom configuration
308
+ */
31
309
  export declare const editTool: AgentTool<import("@sinclair/typebox").TObject<{
32
310
  path: import("@sinclair/typebox").TString;
33
311
  oldText: import("@sinclair/typebox").TString;
@@ -1 +1 @@
1
- {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,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