From 0455028a3cd25d87f76bc389f89261eee658657a Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Wed, 17 Jun 2026 15:53:58 +0800 Subject: [PATCH] refactor(agents): trim session tool internals --- src/agents/sessions/tools/edit-diff.ts | 36 ++++++------------------- src/agents/sessions/tools/path-utils.ts | 2 +- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/agents/sessions/tools/edit-diff.ts b/src/agents/sessions/tools/edit-diff.ts index 2e1b3e94acb..e7068e88b96 100644 --- a/src/agents/sessions/tools/edit-diff.ts +++ b/src/agents/sessions/tools/edit-diff.ts @@ -35,7 +35,7 @@ export function restoreLineEndings(text: string, ending: "\r\n" | "\n"): string * - Normalize Unicode dashes/hyphens to ASCII hyphen * - Normalize special Unicode spaces to regular space */ -export function normalizeForFuzzyMatch(text: string): string { +function normalizeForFuzzyMatch(text: string): string { return ( text .normalize("NFKC") @@ -58,7 +58,7 @@ export function normalizeForFuzzyMatch(text: string): string { ); } -export interface FuzzyMatchResult { +interface FuzzyMatchResult { /** Whether a match was found */ found: boolean; /** The index where the match starts (in the content that should be used for replacement) */ @@ -86,18 +86,13 @@ interface MatchedEdit { newText: string; } -export interface AppliedEditsResult { - baseContent: string; - newContent: string; -} - /** * Find oldText in content, trying exact match first, then fuzzy match. * When fuzzy matching is used, the returned contentForReplacement is the * fuzzy-normalized version of the content (trailing whitespace stripped, * Unicode quotes/dashes normalized to ASCII). */ -export function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult { +function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult { // Try exact match first const exactIndex = content.indexOf(oldText); if (exactIndex !== -1) { @@ -205,7 +200,7 @@ export function applyEditsToNormalizedContent( normalizedContent: string, edits: Edit[], path: string, -): AppliedEditsResult { +): { baseContent: string; newContent: string } { const normalizedEdits = edits.map((edit) => ({ oldText: normalizeToLF(edit.oldText), newText: normalizeToLF(edit.newText), @@ -423,11 +418,6 @@ export interface EditDiffError { error: string; } -export interface EditDiffOperations { - readFile: (absolutePath: string) => Promise; - access: (absolutePath: string) => Promise; -} - /** * Compute the diff for one or more edit operations without applying them. * Used for preview rendering in the TUI before the tool executes. @@ -436,7 +426,10 @@ export async function computeEditsDiff( path: string, edits: Edit[], cwd: string, - operations?: EditDiffOperations, + operations?: { + readFile: (absolutePath: string) => Promise; + access: (absolutePath: string) => Promise; + }, ): Promise { const absolutePath = resolveToCwd(path, cwd); @@ -478,16 +471,3 @@ export async function computeEditsDiff( return { error: err instanceof Error ? err.message : String(err) }; } } - -/** - * Compute the diff for a single edit operation without applying it. - * Kept as a convenience wrapper for single-edit callers. - */ -export async function computeEditDiff( - path: string, - oldText: string, - newText: string, - cwd: string, -): Promise { - return computeEditsDiff(path, [{ oldText, newText }], cwd); -} diff --git a/src/agents/sessions/tools/path-utils.ts b/src/agents/sessions/tools/path-utils.ts index e233c453684..ac654c5eea6 100644 --- a/src/agents/sessions/tools/path-utils.ts +++ b/src/agents/sessions/tools/path-utils.ts @@ -42,7 +42,7 @@ function normalizeAtPrefix(filePath: string): string { return filePath.startsWith("@") ? filePath.slice(1) : filePath; } -export function expandPath(filePath: string): string { +function expandPath(filePath: string): string { const normalized = normalizeUnicodeSpaces(normalizeAtPrefix(filePath)); if (normalized.startsWith("file://")) { try {