From 74008a8ceb14e71af08b5134d1361146b614bf64 Mon Sep 17 00:00:00 2001 From: JiHongKim98 Date: Sat, 21 Feb 2026 03:17:48 +0900 Subject: [PATCH] fix(tools): address PR review feedback from cubic - Use tool.schema.enum() for output_mode instead of generic string() - Remove unsafe type assertion for output_mode - Fix files_with_matches mode returning empty results by adding filesOnly flag to parseOutput for --files-with-matches rg output --- src/tools/grep/cli.ts | 14 ++++++++++++-- src/tools/grep/tools.ts | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/tools/grep/cli.ts b/src/tools/grep/cli.ts index 6109139b..c44bda37 100644 --- a/src/tools/grep/cli.ts +++ b/src/tools/grep/cli.ts @@ -95,7 +95,7 @@ function buildArgs(options: GrepOptions, backend: GrepBackend): string[] { return backend === "rg" ? buildRgArgs(options) : buildGrepArgs(options) } -function parseOutput(output: string): GrepMatch[] { +function parseOutput(output: string, filesOnly = false): GrepMatch[] { if (!output.trim()) return [] const matches: GrepMatch[] = [] @@ -104,6 +104,16 @@ function parseOutput(output: string): GrepMatch[] { for (const line of lines) { if (!line.trim()) continue + if (filesOnly) { + // --files-with-matches outputs only file paths, one per line + matches.push({ + file: line.trim(), + line: 0, + text: "", + }) + continue + } + const match = line.match(/^(.+?):(\d+):(.*)$/) if (match) { matches.push({ @@ -191,7 +201,7 @@ async function runRgInternal(options: GrepOptions): Promise { } } - const matches = parseOutput(outputToProcess) + const matches = parseOutput(outputToProcess, options.outputMode === "files_with_matches") const limited = options.headLimit && options.headLimit > 0 ? matches.slice(0, options.headLimit) : matches diff --git a/src/tools/grep/tools.ts b/src/tools/grep/tools.ts index 356eb53a..e4d0e0e4 100644 --- a/src/tools/grep/tools.ts +++ b/src/tools/grep/tools.ts @@ -22,7 +22,7 @@ export function createGrepTools(ctx: PluginInput): Record