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,18 +1,235 @@
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 } from "@sinclair/typebox";
2
149
  import { constants } from "fs";
3
150
  import { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from "fs/promises";
4
151
  import { detectLineEnding, fuzzyFindText, generateDiffString, normalizeForFuzzyMatch, normalizeToLF, restoreLineEndings, stripBom, } from "./edit-diff.js";
5
152
  import { resolveToCwd } from "./path-utils.js";
153
+ // ============================================================================
154
+ // Schema & Types
155
+ // ============================================================================
156
+ /**
157
+ * JSON Schema for edit tool parameters
158
+ * @internal
159
+ */
6
160
  const editSchema = Type.Object({
7
161
  path: Type.String({ description: "Path to the file to edit (relative or absolute)" }),
8
162
  oldText: Type.String({ description: "Exact text to find and replace (must match exactly)" }),
9
163
  newText: Type.String({ description: "New text to replace the old text with" }),
10
164
  });
165
+ /**
166
+ * Default edit operations using local filesystem
167
+ * @internal
168
+ */
11
169
  const defaultEditOperations = {
12
170
  readFile: (path) => fsReadFile(path),
13
171
  writeFile: (path, content) => fsWriteFile(path, content, "utf-8"),
14
172
  access: (path) => fsAccess(path, constants.R_OK | constants.W_OK),
15
173
  };
174
+ // ============================================================================
175
+ // Tool Factory & Exports
176
+ // ============================================================================
177
+ /**
178
+ * Create an edit tool with custom configuration
179
+ *
180
+ * Creates an AgentTool that can edit files with:
181
+ * - Exact text replacement
182
+ * - Fuzzy matching (optional)
183
+ * - Unified diff output
184
+ * - Line ending preservation
185
+ * - Remote execution support
186
+ *
187
+ * **Tool Behavior:**
188
+ * - Resolves paths relative to working directory
189
+ * - Prevents path traversal
190
+ * - Finds and replaces exact text
191
+ * - Preserves file format (line endings, BOM)
192
+ * - Returns unified diff of changes
193
+ *
194
+ * **Tool Parameters:**
195
+ * - `path` (required): File to edit
196
+ * - `oldText` (required): Text to find
197
+ * - `newText` (required): Replacement text
198
+ *
199
+ * **Tool Output:**
200
+ * - Success message with unified diff
201
+ * - Details: Diff and first changed line number
202
+ * - Errors: Tool error with message
203
+ *
204
+ * **Error Handling:**
205
+ * - Pattern not found: Tool error "Pattern not found"
206
+ * - File not found: Tool error "ENOENT: no such file"
207
+ * - Permission denied: Tool error "EACCES: permission denied"
208
+ * - Other errors: Tool error with message
209
+ *
210
+ * @param cwd - Working directory for relative path resolution
211
+ * - All relative paths resolved from this directory
212
+ * - Prevents directory traversal attacks
213
+ *
214
+ * @param options - Optional configuration
215
+ * - operations: Custom file editing backend (default: filesystem)
216
+ *
217
+ * @returns AgentTool instance ready to use
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * // Basic tool
222
+ * const tool = createEditTool(process.cwd());
223
+ *
224
+ * // With remote backend (SSH)
225
+ * const remoteTool = createEditTool(cwd, {
226
+ * operations: sshOperations,
227
+ * });
228
+ * ```
229
+ *
230
+ * @see EditToolOptions for detailed configuration
231
+ * @see EditOperations for custom backend interface
232
+ */
16
233
  export function createEditTool(cwd, options) {
17
234
  const ops = options?.operations ?? defaultEditOperations;
18
235
  return {
@@ -142,5 +359,26 @@ export function createEditTool(cwd, options) {
142
359
  };
143
360
  }
144
361
  /** Default edit tool using process.cwd() - for backwards compatibility */
362
+ /**
363
+ * Default edit tool instance
364
+ *
365
+ * Pre-created edit tool using current process working directory.
366
+ * Supports exact text replacement with unified diff output.
367
+ *
368
+ * Equivalent to:
369
+ * ```typescript
370
+ * const editTool = createEditTool(process.cwd());
371
+ * ```
372
+ *
373
+ * For custom configuration or remote backends, use createEditTool() directly.
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * import { editTool } from "./tools/edit.js";
378
+ * const agent = new Agent({ tools: [editTool] });
379
+ * ```
380
+ *
381
+ * @see createEditTool for custom configuration
382
+ */
145
383
  export const editTool = createEditTool(process.cwd());
146
384
  //# sourceMappingURL=edit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,I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gB,EAAE;yBACjF,CAAC,CAAC;oBACJ,CAAC;oBAAC,OAAO,KAAU,EAAE,CAAC;wBACrB,yBAAyB;wBACzB,IAAI,MAAM,EAAE,CAAC;4BACZ,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;wBAC9C,CAAC;wBAED,IAAI,CAAC,OAAO,EAAE,CAAC;4BACd,MAAM,CAAC,KAAK,CAAC,CAAC;wBACf,CAAC;oBACF,CAAC;gBACF,CAAC,CAAC,EAAE,CAAC;YACN,CAAC,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC"}
@@ -1,33 +1,197 @@
1
+ /**
2
+ * Find Tool - Search for files using glob patterns
3
+ *
4
+ * Purpose: Implements find tool for agent to search files using glob patterns.
5
+ * Searches with glob patterns (*, **, ?, braces), directory scoping, result limiting.
6
+ *
7
+ * Input Parameters:
8
+ * - pattern (required): Glob pattern (e.g., *.ts, src path to json files)
9
+ * - path (optional): Search directory (default: current directory)
10
+ * - limit (optional): Max results (default: 1000)
11
+ *
12
+ * Output:
13
+ * - List of matching file paths
14
+ * - Truncation info if results exceed limit
15
+ * - Error if pattern invalid
16
+ *
17
+ * Features:
18
+ * - Fast searching using fd if available, falls back to JS glob
19
+ * - Respects .gitignore by default
20
+ * - Result limiting prevents OOM
21
+ * - Path safety: no traversal, validated paths
22
+ * - Pattern validation: literal matching, not code
23
+ *
24
+ * Security:
25
+ * - Patterns validated for safety
26
+ * - All paths resolved relative to cwd
27
+ * - Directory traversal prevented
28
+ * - Invalid paths caught
29
+ * - Max 1000 results by default prevents DOS
30
+ *
31
+ * Examples:
32
+ * - Find all TypeScript files: *.ts
33
+ * - Find JSON recursively: all paths to json files
34
+ * - Find tests in src: src path test ts
35
+ * - Exclude node_modules: src without node_modules
36
+ *
37
+ * Based on Unix find and Node.js glob library.
38
+ * Refactored for agent file discovery with pattern filtering.
39
+ * Modifications: fd support, custom operations, glob patterns, error handling.
40
+ */
1
41
  import type { AgentTool } from "indusagi/agent";
2
42
  import { type TruncationResult } from "./truncate.js";
43
+ /**
44
+ * JSON Schema for find tool parameters
45
+ * @internal
46
+ */
3
47
  declare const findSchema: import("@sinclair/typebox").TObject<{
4
48
  pattern: import("@sinclair/typebox").TString;
5
49
  path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
6
50
  limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
7
51
  }>;
52
+ /**
53
+ * Tool-specific details returned with find results
54
+ */
8
55
  export interface FindToolDetails {
56
+ /** Truncation information if result count exceeded limit */
9
57
  truncation?: TruncationResult;
58
+ /** Number of results if limit was reached */
10
59
  resultLimitReached?: number;
11
60
  }
12
61
  /**
13
- * Pluggable operations for the find tool.
14
- * Override these to delegate file search to remote systems (e.g., SSH).
62
+ * Pluggable interface for file search operations
63
+ *
64
+ * Allows custom implementations for:
65
+ * - Remote file systems (SSH, cloud storage)
66
+ * - Virtual file systems (in-memory, testing)
67
+ * - Custom search backends
68
+ * - Monitoring and logging
15
69
  */
16
70
  export interface FindOperations {
17
- /** Check if path exists */
71
+ /**
72
+ * Check if path exists
73
+ *
74
+ * @param absolutePath - Full path to check
75
+ * @returns true if path exists
76
+ */
18
77
  exists: (absolutePath: string) => Promise<boolean> | boolean;
19
- /** Find files matching glob pattern. Returns relative paths. */
78
+ /**
79
+ * Find files matching glob pattern
80
+ *
81
+ * @param pattern - Glob pattern to match
82
+ * @param cwd - Search root directory
83
+ * @param options - Search options
84
+ * - ignore: Patterns to exclude
85
+ * - limit: Max results to return
86
+ * @returns Array of relative paths matching pattern
87
+ */
20
88
  glob: (pattern: string, cwd: string, options: {
21
89
  ignore: string[];
22
90
  limit: number;
23
91
  }) => Promise<string[]> | string[];
24
92
  }
93
+ /**
94
+ * Configuration options for the find tool
95
+ */
25
96
  export interface FindToolOptions {
26
- /** Custom operations for find. Default: local filesystem + fd */
97
+ /**
98
+ * Custom operations for file searching
99
+ *
100
+ * Default: Local filesystem with fd or glob
101
+ * Custom: SSH, cloud storage, testing mocks
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const tool = createFindTool(cwd, {
106
+ * operations: {
107
+ * exists: (path) => sshExec(`test -e ${path}`),
108
+ * glob: (pattern, cwd, opts) => sshExec(`find ${cwd} -name ${pattern}`),
109
+ * },
110
+ * });
111
+ * ```
112
+ */
27
113
  operations?: FindOperations;
28
114
  }
115
+ /**
116
+ * Create a find tool with custom configuration
117
+ *
118
+ * Creates an AgentTool that can search for files with:
119
+ * - Glob pattern matching
120
+ * - Directory scope limiting
121
+ * - Result limiting
122
+ * - Truncation for large results
123
+ * - Remote execution support
124
+ * - Fast fd-based search
125
+ *
126
+ * **Tool Behavior:**
127
+ * - Resolves paths relative to working directory
128
+ * - Prevents path traversal
129
+ * - Uses fd or glob for searching
130
+ * - Respects .gitignore
131
+ * - Limits results (default: 1000)
132
+ * - Truncates results if too many
133
+ *
134
+ * **Tool Parameters:**
135
+ * - `pattern` (required): Glob pattern (e.g., "*.ts")
136
+ * - `path` (optional): Search directory (default: cwd)
137
+ * - `limit` (optional): Max results (default: 1000)
138
+ *
139
+ * **Tool Output:**
140
+ * - List of matching file paths
141
+ * - Details: Truncation info and limit reached count
142
+ * - Errors: Tool error with message
143
+ *
144
+ * **Error Handling:**
145
+ * - Invalid directory: Tool error "Path outside working directory"
146
+ * - Invalid pattern: Tool error "Invalid glob pattern"
147
+ * - Search errors: Tool error with message
148
+ *
149
+ * @param cwd - Working directory for relative path resolution
150
+ * - All relative paths resolved from this directory
151
+ * - Prevents directory traversal attacks
152
+ *
153
+ * @param options - Optional configuration
154
+ * - operations: Custom search backend (default: local filesystem)
155
+ *
156
+ * @returns AgentTool instance ready to use
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * // Basic tool
161
+ * const tool = createFindTool(process.cwd());
162
+ *
163
+ * // With remote backend (SSH)
164
+ * const remoteTool = createFindTool(cwd, {
165
+ * operations: sshOperations,
166
+ * });
167
+ * ```
168
+ *
169
+ * @see FindToolOptions for detailed configuration
170
+ * @see FindOperations for custom backend interface
171
+ */
29
172
  export declare function createFindTool(cwd: string, options?: FindToolOptions): AgentTool<typeof findSchema>;
30
173
  /** Default find tool using process.cwd() - for backwards compatibility */
174
+ /**
175
+ * Default find tool instance
176
+ *
177
+ * Pre-created find tool using current process working directory.
178
+ * Supports glob pattern matching with result limiting.
179
+ *
180
+ * Equivalent to:
181
+ * ```typescript
182
+ * const findTool = createFindTool(process.cwd());
183
+ * ```
184
+ *
185
+ * For custom configuration or remote backends, use createFindTool() directly.
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * import { findTool } from "./tools/find.js";
190
+ * const agent = new Agent({ tools: [findTool] });
191
+ * ```
192
+ *
193
+ * @see createFindTool for custom configuration
194
+ */
31
195
  export declare const findTool: AgentTool<import("@sinclair/typebox").TObject<{
32
196
  pattern: import("@sinclair/typebox").TString;
33
197
  path: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../src/core/tools/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQhD,OAAO,EAAiC,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAEnG,QAAA,MAAM,UAAU;;;;EAMd,CAAC;AAIH,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,2BAA2B;IAC3B,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAC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AE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC;CACnH;AAcD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CA0NnG;AAED,0EAA0E;AAC1E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,QAAQ;;;;QAAgC,CAAC"}
@@ -1,3 +1,43 @@
1
+ /**
2
+ * Find Tool - Search for files using glob patterns
3
+ *
4
+ * Purpose: Implements find tool for agent to search files using glob patterns.
5
+ * Searches with glob patterns (*, **, ?, braces), directory scoping, result limiting.
6
+ *
7
+ * Input Parameters:
8
+ * - pattern (required): Glob pattern (e.g., *.ts, src path to json files)
9
+ * - path (optional): Search directory (default: current directory)
10
+ * - limit (optional): Max results (default: 1000)
11
+ *
12
+ * Output:
13
+ * - List of matching file paths
14
+ * - Truncation info if results exceed limit
15
+ * - Error if pattern invalid
16
+ *
17
+ * Features:
18
+ * - Fast searching using fd if available, falls back to JS glob
19
+ * - Respects .gitignore by default
20
+ * - Result limiting prevents OOM
21
+ * - Path safety: no traversal, validated paths
22
+ * - Pattern validation: literal matching, not code
23
+ *
24
+ * Security:
25
+ * - Patterns validated for safety
26
+ * - All paths resolved relative to cwd
27
+ * - Directory traversal prevented
28
+ * - Invalid paths caught
29
+ * - Max 1000 results by default prevents DOS
30
+ *
31
+ * Examples:
32
+ * - Find all TypeScript files: *.ts
33
+ * - Find JSON recursively: all paths to json files
34
+ * - Find tests in src: src path test ts
35
+ * - Exclude node_modules: src without node_modules
36
+ *
37
+ * Based on Unix find and Node.js glob library.
38
+ * Refactored for agent file discovery with pattern filtering.
39
+ * Modifications: fd support, custom operations, glob patterns, error handling.
40
+ */
1
41
  import { Type } from "@sinclair/typebox";
2
42
  import { spawnSync } from "child_process";
3
43
  import { existsSync } from "fs";
@@ -6,6 +46,13 @@ import path from "path";
6
46
  import { ensureTool } from "../../utils/tools-manager.js";
7
47
  import { resolveToCwd } from "./path-utils.js";
8
48
  import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
49
+ // ============================================================================
50
+ // Schema & Types
51
+ // ============================================================================
52
+ /**
53
+ * JSON Schema for find tool parameters
54
+ * @internal
55
+ */
9
56
  const findSchema = Type.Object({
10
57
  pattern: Type.String({
11
58
  description: "Glob pattern to match files, e.g. '*.ts', '**/*.json', or 'src/**/*.spec.ts'",
@@ -13,7 +60,15 @@ const findSchema = Type.Object({
13
60
  path: Type.Optional(Type.String({ description: "Directory to search in (default: current directory)" })),
14
61
  limit: Type.Optional(Type.Number({ description: "Maximum number of results (default: 1000)" })),
15
62
  });
63
+ /**
64
+ * Default maximum results for find operations
65
+ * @internal
66
+ */
16
67
  const DEFAULT_LIMIT = 1000;
68
+ /**
69
+ * Default find operations using local filesystem and glob
70
+ * @internal
71
+ */
17
72
  const defaultFindOperations = {
18
73
  exists: existsSync,
19
74
  glob: (_pattern, _searchCwd, _options) => {
@@ -21,6 +76,66 @@ const defaultFindOperations = {
21
76
  return [];
22
77
  },
23
78
  };
79
+ // ============================================================================
80
+ // Tool Factory & Exports
81
+ // ============================================================================
82
+ /**
83
+ * Create a find tool with custom configuration
84
+ *
85
+ * Creates an AgentTool that can search for files with:
86
+ * - Glob pattern matching
87
+ * - Directory scope limiting
88
+ * - Result limiting
89
+ * - Truncation for large results
90
+ * - Remote execution support
91
+ * - Fast fd-based search
92
+ *
93
+ * **Tool Behavior:**
94
+ * - Resolves paths relative to working directory
95
+ * - Prevents path traversal
96
+ * - Uses fd or glob for searching
97
+ * - Respects .gitignore
98
+ * - Limits results (default: 1000)
99
+ * - Truncates results if too many
100
+ *
101
+ * **Tool Parameters:**
102
+ * - `pattern` (required): Glob pattern (e.g., "*.ts")
103
+ * - `path` (optional): Search directory (default: cwd)
104
+ * - `limit` (optional): Max results (default: 1000)
105
+ *
106
+ * **Tool Output:**
107
+ * - List of matching file paths
108
+ * - Details: Truncation info and limit reached count
109
+ * - Errors: Tool error with message
110
+ *
111
+ * **Error Handling:**
112
+ * - Invalid directory: Tool error "Path outside working directory"
113
+ * - Invalid pattern: Tool error "Invalid glob pattern"
114
+ * - Search errors: Tool error with message
115
+ *
116
+ * @param cwd - Working directory for relative path resolution
117
+ * - All relative paths resolved from this directory
118
+ * - Prevents directory traversal attacks
119
+ *
120
+ * @param options - Optional configuration
121
+ * - operations: Custom search backend (default: local filesystem)
122
+ *
123
+ * @returns AgentTool instance ready to use
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // Basic tool
128
+ * const tool = createFindTool(process.cwd());
129
+ *
130
+ * // With remote backend (SSH)
131
+ * const remoteTool = createFindTool(cwd, {
132
+ * operations: sshOperations,
133
+ * });
134
+ * ```
135
+ *
136
+ * @see FindToolOptions for detailed configuration
137
+ * @see FindOperations for custom backend interface
138
+ */
24
139
  export function createFindTool(cwd, options) {
25
140
  const customOps = options?.operations;
26
141
  return {
@@ -202,5 +317,26 @@ export function createFindTool(cwd, options) {
202
317
  };
203
318
  }
204
319
  /** Default find tool using process.cwd() - for backwards compatibility */
320
+ /**
321
+ * Default find tool instance
322
+ *
323
+ * Pre-created find tool using current process working directory.
324
+ * Supports glob pattern matching with result limiting.
325
+ *
326
+ * Equivalent to:
327
+ * ```typescript
328
+ * const findTool = createFindTool(process.cwd());
329
+ * ```
330
+ *
331
+ * For custom configuration or remote backends, use createFindTool() directly.
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * import { findTool } from "./tools/find.js";
336
+ * const agent = new Agent({ tools: [findTool] });
337
+ * ```
338
+ *
339
+ * @see createFindTool for custom configuration
340
+ */
205
341
  export const findTool = createFindTool(process.cwd());
206
342
  //# sourceMappingURL=find.js.map