indusagi-coding-agent 0.1.25 → 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.
Files changed (83) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/cli/file-processor.js +1 -1
  3. package/dist/cli/file-processor.js.map +1 -1
  4. package/dist/core/agent-session.d.ts +1 -1
  5. package/dist/core/agent-session.d.ts.map +1 -1
  6. package/dist/core/agent-session.js +1 -1
  7. package/dist/core/agent-session.js.map +1 -1
  8. package/dist/core/bash-executor.d.ts +1 -1
  9. package/dist/core/bash-executor.d.ts.map +1 -1
  10. package/dist/core/bash-executor.js +1 -1
  11. package/dist/core/bash-executor.js.map +1 -1
  12. package/dist/core/extensions/types.d.ts +1 -3
  13. package/dist/core/extensions/types.d.ts.map +1 -1
  14. package/dist/core/settings-manager.js +1 -1
  15. package/dist/core/settings-manager.js.map +1 -1
  16. package/dist/core/task-session-manager.d.ts.map +1 -1
  17. package/dist/core/task-session-manager.js +1 -7
  18. package/dist/core/task-session-manager.js.map +1 -1
  19. package/dist/core/tools/bg-process.d.ts +1 -1
  20. package/dist/core/tools/index.d.ts +57 -50
  21. package/dist/core/tools/index.d.ts.map +1 -1
  22. package/dist/core/tools/index.js +89 -21
  23. package/dist/core/tools/index.js.map +1 -1
  24. package/dist/core/tools/todo.d.ts +4 -4
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
  29. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  30. package/dist/modes/interactive/components/bash-execution.js +1 -1
  31. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  32. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  33. package/dist/modes/interactive/components/tool-execution.js +2 -2
  34. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  35. package/package.json +3 -3
  36. package/dist/core/tools/bash.d.ts +0 -428
  37. package/dist/core/tools/bash.d.ts.map +0 -1
  38. package/dist/core/tools/bash.js +0 -498
  39. package/dist/core/tools/bash.js.map +0 -1
  40. package/dist/core/tools/edit-diff.d.ts +0 -63
  41. package/dist/core/tools/edit-diff.d.ts.map +0 -1
  42. package/dist/core/tools/edit-diff.js +0 -243
  43. package/dist/core/tools/edit-diff.js.map +0 -1
  44. package/dist/core/tools/edit.d.ts +0 -315
  45. package/dist/core/tools/edit.d.ts.map +0 -1
  46. package/dist/core/tools/edit.js +0 -384
  47. package/dist/core/tools/edit.js.map +0 -1
  48. package/dist/core/tools/find.d.ts +0 -201
  49. package/dist/core/tools/find.d.ts.map +0 -1
  50. package/dist/core/tools/find.js +0 -342
  51. package/dist/core/tools/find.js.map +0 -1
  52. package/dist/core/tools/grep.d.ts +0 -323
  53. package/dist/core/tools/grep.d.ts.map +0 -1
  54. package/dist/core/tools/grep.js +0 -486
  55. package/dist/core/tools/grep.js.map +0 -1
  56. package/dist/core/tools/ls.d.ts +0 -44
  57. package/dist/core/tools/ls.d.ts.map +0 -1
  58. package/dist/core/tools/ls.js +0 -124
  59. package/dist/core/tools/ls.js.map +0 -1
  60. package/dist/core/tools/path-utils.d.ts +0 -8
  61. package/dist/core/tools/path-utils.d.ts.map +0 -1
  62. package/dist/core/tools/path-utils.js +0 -53
  63. package/dist/core/tools/path-utils.js.map +0 -1
  64. package/dist/core/tools/read.d.ts +0 -338
  65. package/dist/core/tools/read.d.ts.map +0 -1
  66. package/dist/core/tools/read.js +0 -397
  67. package/dist/core/tools/read.js.map +0 -1
  68. package/dist/core/tools/truncate.d.ts +0 -70
  69. package/dist/core/tools/truncate.d.ts.map +0 -1
  70. package/dist/core/tools/truncate.js +0 -205
  71. package/dist/core/tools/truncate.js.map +0 -1
  72. package/dist/core/tools/webfetch.d.ts +0 -174
  73. package/dist/core/tools/webfetch.d.ts.map +0 -1
  74. package/dist/core/tools/webfetch.js +0 -380
  75. package/dist/core/tools/webfetch.js.map +0 -1
  76. package/dist/core/tools/websearch.d.ts +0 -190
  77. package/dist/core/tools/websearch.d.ts.map +0 -1
  78. package/dist/core/tools/websearch.js +0 -267
  79. package/dist/core/tools/websearch.js.map +0 -1
  80. package/dist/core/tools/write.d.ts +0 -273
  81. package/dist/core/tools/write.d.ts.map +0 -1
  82. package/dist/core/tools/write.js +0 -288
  83. package/dist/core/tools/write.js.map +0 -1
@@ -1,243 +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
- import * as Diff from "diff";
6
- import { constants } from "fs";
7
- import { access, readFile } from "fs/promises";
8
- import { resolveToCwd } from "./path-utils.js";
9
- export function detectLineEnding(content) {
10
- const crlfIdx = content.indexOf("\r\n");
11
- const lfIdx = content.indexOf("\n");
12
- if (lfIdx === -1)
13
- return "\n";
14
- if (crlfIdx === -1)
15
- return "\n";
16
- return crlfIdx < lfIdx ? "\r\n" : "\n";
17
- }
18
- export function normalizeToLF(text) {
19
- return text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
20
- }
21
- export function restoreLineEndings(text, ending) {
22
- return ending === "\r\n" ? text.replace(/\n/g, "\r\n") : text;
23
- }
24
- /**
25
- * Normalize text for fuzzy matching. Applies progressive transformations:
26
- * - Strip trailing whitespace from each line
27
- * - Normalize smart quotes to ASCII equivalents
28
- * - Normalize Unicode dashes/hyphens to ASCII hyphen
29
- * - Normalize special Unicode spaces to regular space
30
- */
31
- export function normalizeForFuzzyMatch(text) {
32
- return (text
33
- // Strip trailing whitespace per line
34
- .split("\n")
35
- .map((line) => line.trimEnd())
36
- .join("\n")
37
- // Smart single quotes → '
38
- .replace(/[\u2018\u2019\u201A\u201B]/g, "'")
39
- // Smart double quotes → "
40
- .replace(/[\u201C\u201D\u201E\u201F]/g, '"')
41
- // Various dashes/hyphens → -
42
- // U+2010 hyphen, U+2011 non-breaking hyphen, U+2012 figure dash,
43
- // U+2013 en-dash, U+2014 em-dash, U+2015 horizontal bar, U+2212 minus
44
- .replace(/[\u2010\u2011\u2012\u2013\u2014\u2015\u2212]/g, "-")
45
- // Special spaces → regular space
46
- // U+00A0 NBSP, U+2002-U+200A various spaces, U+202F narrow NBSP,
47
- // U+205F medium math space, U+3000 ideographic space
48
- .replace(/[\u00A0\u2002-\u200A\u202F\u205F\u3000]/g, " "));
49
- }
50
- /**
51
- * Find oldText in content, trying exact match first, then fuzzy match.
52
- * When fuzzy matching is used, the returned contentForReplacement is the
53
- * fuzzy-normalized version of the content (trailing whitespace stripped,
54
- * Unicode quotes/dashes normalized to ASCII).
55
- */
56
- export function fuzzyFindText(content, oldText) {
57
- // Try exact match first
58
- const exactIndex = content.indexOf(oldText);
59
- if (exactIndex !== -1) {
60
- return {
61
- found: true,
62
- index: exactIndex,
63
- matchLength: oldText.length,
64
- usedFuzzyMatch: false,
65
- contentForReplacement: content,
66
- };
67
- }
68
- // Try fuzzy match - work entirely in normalized space
69
- const fuzzyContent = normalizeForFuzzyMatch(content);
70
- const fuzzyOldText = normalizeForFuzzyMatch(oldText);
71
- const fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);
72
- if (fuzzyIndex === -1) {
73
- return {
74
- found: false,
75
- index: -1,
76
- matchLength: 0,
77
- usedFuzzyMatch: false,
78
- contentForReplacement: content,
79
- };
80
- }
81
- // When fuzzy matching, we work in the normalized space for replacement.
82
- // This means the output will have normalized whitespace/quotes/dashes,
83
- // which is acceptable since we're fixing minor formatting differences anyway.
84
- return {
85
- found: true,
86
- index: fuzzyIndex,
87
- matchLength: fuzzyOldText.length,
88
- usedFuzzyMatch: true,
89
- contentForReplacement: fuzzyContent,
90
- };
91
- }
92
- /** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */
93
- export function stripBom(content) {
94
- return content.startsWith("\uFEFF") ? { bom: "\uFEFF", text: content.slice(1) } : { bom: "", text: content };
95
- }
96
- /**
97
- * Generate a unified diff string with line numbers and context.
98
- * Returns both the diff string and the first changed line number (in the new file).
99
- */
100
- export function generateDiffString(oldContent, newContent, contextLines = 4) {
101
- const parts = Diff.diffLines(oldContent, newContent);
102
- const output = [];
103
- const oldLines = oldContent.split("\n");
104
- const newLines = newContent.split("\n");
105
- const maxLineNum = Math.max(oldLines.length, newLines.length);
106
- const lineNumWidth = String(maxLineNum).length;
107
- let oldLineNum = 1;
108
- let newLineNum = 1;
109
- let lastWasChange = false;
110
- let firstChangedLine;
111
- for (let i = 0; i < parts.length; i++) {
112
- const part = parts[i];
113
- const raw = part.value.split("\n");
114
- if (raw[raw.length - 1] === "") {
115
- raw.pop();
116
- }
117
- if (part.added || part.removed) {
118
- // Capture the first changed line (in the new file)
119
- if (firstChangedLine === undefined) {
120
- firstChangedLine = newLineNum;
121
- }
122
- // Show the change
123
- for (const line of raw) {
124
- if (part.added) {
125
- const lineNum = String(newLineNum).padStart(lineNumWidth, " ");
126
- output.push(`+${lineNum} ${line}`);
127
- newLineNum++;
128
- }
129
- else {
130
- // removed
131
- const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
132
- output.push(`-${lineNum} ${line}`);
133
- oldLineNum++;
134
- }
135
- }
136
- lastWasChange = true;
137
- }
138
- else {
139
- // Context lines - only show a few before/after changes
140
- const nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);
141
- if (lastWasChange || nextPartIsChange) {
142
- // Show context
143
- let linesToShow = raw;
144
- let skipStart = 0;
145
- let skipEnd = 0;
146
- if (!lastWasChange) {
147
- // Show only last N lines as leading context
148
- skipStart = Math.max(0, raw.length - contextLines);
149
- linesToShow = raw.slice(skipStart);
150
- }
151
- if (!nextPartIsChange && linesToShow.length > contextLines) {
152
- // Show only first N lines as trailing context
153
- skipEnd = linesToShow.length - contextLines;
154
- linesToShow = linesToShow.slice(0, contextLines);
155
- }
156
- // Add ellipsis if we skipped lines at start
157
- if (skipStart > 0) {
158
- output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
159
- // Update line numbers for the skipped leading context
160
- oldLineNum += skipStart;
161
- newLineNum += skipStart;
162
- }
163
- for (const line of linesToShow) {
164
- const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
165
- output.push(` ${lineNum} ${line}`);
166
- oldLineNum++;
167
- newLineNum++;
168
- }
169
- // Add ellipsis if we skipped lines at end
170
- if (skipEnd > 0) {
171
- output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
172
- // Update line numbers for the skipped trailing context
173
- oldLineNum += skipEnd;
174
- newLineNum += skipEnd;
175
- }
176
- }
177
- else {
178
- // Skip these context lines entirely
179
- oldLineNum += raw.length;
180
- newLineNum += raw.length;
181
- }
182
- lastWasChange = false;
183
- }
184
- }
185
- return { diff: output.join("\n"), firstChangedLine };
186
- }
187
- /**
188
- * Compute the diff for an edit operation without applying it.
189
- * Used for preview rendering in the TUI before the tool executes.
190
- */
191
- export async function computeEditDiff(path, oldText, newText, cwd) {
192
- const absolutePath = resolveToCwd(path, cwd);
193
- try {
194
- // Check if file exists and is readable
195
- try {
196
- await access(absolutePath, constants.R_OK);
197
- }
198
- catch {
199
- return { error: `File not found: ${path}` };
200
- }
201
- // Read the file
202
- const rawContent = await readFile(absolutePath, "utf-8");
203
- // Strip BOM before matching (LLM won't include invisible BOM in oldText)
204
- const { text: content } = stripBom(rawContent);
205
- const normalizedContent = normalizeToLF(content);
206
- const normalizedOldText = normalizeToLF(oldText);
207
- const normalizedNewText = normalizeToLF(newText);
208
- // Find the old text using fuzzy matching (tries exact match first, then fuzzy)
209
- const matchResult = fuzzyFindText(normalizedContent, normalizedOldText);
210
- if (!matchResult.found) {
211
- return {
212
- error: `Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`,
213
- };
214
- }
215
- // Count occurrences using fuzzy-normalized content for consistency
216
- const fuzzyContent = normalizeForFuzzyMatch(normalizedContent);
217
- const fuzzyOldText = normalizeForFuzzyMatch(normalizedOldText);
218
- const occurrences = fuzzyContent.split(fuzzyOldText).length - 1;
219
- if (occurrences > 1) {
220
- return {
221
- error: `Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,
222
- };
223
- }
224
- // Compute the new content using the matched position
225
- // When fuzzy matching was used, contentForReplacement is the normalized version
226
- const baseContent = matchResult.contentForReplacement;
227
- const newContent = baseContent.substring(0, matchResult.index) +
228
- normalizedNewText +
229
- baseContent.substring(matchResult.index + matchResult.matchLength);
230
- // Check if it would actually change anything
231
- if (baseContent === newContent) {
232
- return {
233
- error: `No changes would be made to ${path}. The replacement produces identical content.`,
234
- };
235
- }
236
- // Generate the diff
237
- return generateDiffString(baseContent, newContent);
238
- }
239
- catch (err) {
240
- return { error: err instanceof Error ? err.message : String(err) };
241
- }
242
- }
243
- //# sourceMappingURL=edit-diff.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"edit-diff.js","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,OAAO,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,OAAO,CAAC,O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AEpE,6CAA6C;QAC7C,IAAI,WAAW,KAAK,UAAU,EAAE,CAAC;YAChC,OAAO;gBACN,KAAK,EAAE,+BAA+B,IAAI,+CAA+C;aACzF,CAAC;QACH,CAAC;QAED,oBAAoB;QACpB,OAAO,kBAAkB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,OAAO,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACpE,CAAC;AACF,CAAC"}
@@ -1,315 +0,0 @@
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
- */
148
- import type { AgentTool } from "indusagi/agent";
149
- /**
150
- * JSON Schema for edit tool parameters
151
- * @internal
152
- */
153
- declare const editSchema: import("@sinclair/typebox").TObject<{
154
- path: import("@sinclair/typebox").TString;
155
- oldText: import("@sinclair/typebox").TString;
156
- newText: import("@sinclair/typebox").TString;
157
- }>;
158
- /**
159
- * Tool-specific details returned with edit results
160
- *
161
- * Provides diff information and navigation hints.
162
- */
163
- export interface EditToolDetails {
164
- /** Unified diff of the changes made */
165
- diff: string;
166
- /** Line number of the first change in the new file (for editor navigation) */
167
- firstChangedLine?: number;
168
- }
169
- /**
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.
179
- */
180
- export interface EditOperations {
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
- */
188
- readFile: (absolutePath: string) => Promise<Buffer>;
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
- */
196
- writeFile: (absolutePath: string, content: string) => Promise<void>;
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
- */
203
- access: (absolutePath: string) => Promise<void>;
204
- }
205
- /**
206
- * Configuration options for the edit tool
207
- *
208
- * Allows customization of file editing backend.
209
- */
210
- export interface EditToolOptions {
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
- */
228
- operations?: EditOperations;
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
- */
286
- export declare function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema>;
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
- */
309
- export declare const editTool: AgentTool<import("@sinclair/typebox").TObject<{
310
- path: import("@sinclair/typebox").TString;
311
- oldText: import("@sinclair/typebox").TString;
312
- newText: import("@sinclair/typebox").TString;
313
- }>, any>;
314
- export {};
315
- //# sourceMappingURL=edit.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkJG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAmBhD;;;GAGG;AACH,QAAA,MAAM,UAAU;;;;EAId,CAAC;AAEH;;;;GAIG;AACH,MAAM,WAA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