Skip to content

fix: grep tool no longer counts "No matches found" as 1 match - #1118

Draft
josemonteiro wants to merge 2 commits into
masterfrom
fix/grep-no-matches-count
Draft

fix: grep tool no longer counts "No matches found" as 1 match#1118
josemonteiro wants to merge 2 commits into
masterfrom
fix/grep-no-matches-count

Conversation

@josemonteiro

Copy link
Copy Markdown
Contributor

Linked issue

N/A — no open tracking issue exists for this bug.

What does this PR do?

When ripgrep finds nothing, pi's grep tool (upstream) returns the literal sentinel "No matches found" as a single text line instead of empty content. Kimchi's grep renderResult in src/extensions/tool-rendering.ts counted every non-empty line as a "match", so the sentinel was miscounted and displayed as 1 matches — contradicting the "No matches found" text underneath.

This PR filters the sentinel out before counting. Real match lines always carry a path:line: prefix, so the exact-string filter cannot swallow genuine results. A zero-match result now correctly renders no matches.

Investigation summary

  • Root cause is in Kimchi's rendering layer, not upstream. No patch needed — the sentinel is a legitimate upstream response.
  • Added regression tests in src/extensions/tool-rendering.test.ts:
    • a no-match sentinel renders no matches, never 1 matches
    • a two-line result still renders 2 matches

Checklist

  • I have read CONTRIBUTING.md and agree to the CLA
  • This PR links to an open issue above (none exists — see above)
  • Tests pass locally (pnpm run test) — tool-rendering.test.ts 74/74 pass
  • Lint passes (pnpm run check) — biome clean
  • Documentation updated if behavior changed (no user-facing docs affected)

When ripgrep finds nothing, pi's grep tool returns the literal sentinel
"No matches found" as a single text line. Kimchi's grep renderResult
counted every non-empty line as a match, so the sentinel was miscounted
and shown as "1 matches".

Filter out the sentinel before counting — real match lines always carry a
path:line: prefix, so genuine results are unaffected. Adds regression
tests covering both the no-match sentinel and real match lines.

Co-Authored-By: Kimchi <noreply@kimchi.dev>
@josemonteiro josemonteiro added the bug Something isn't working label Sep 1, 2026
@kimchi-review

kimchi-review Bot commented Sep 1, 2026

Copy link
Copy Markdown

Kimchi Code Review

Property Value
Commit 65f6c4f
Author @josemonteiro
Files changed 0
Review status Completed
Comments 0
Duration 20s

Summary

📊 Review Score: 90/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 1/5 (1 = trivial, 5 = very complex)

🧪 Tests: yes — Tests are added for both the fix (the 'No matches found' sentinel is not counted as a match) and the regression case (real match lines are still counted correctly). The tests exercise the actual renderResult path registered by the extension.

No significant issues found. LGTM! 🎉

What to expect

Kimchi will analyze the changes in this pull request and post:

  • A summary of the overall changes
  • Inline comments on specific lines with findings categorized by issue type

The review typically completes within a few minutes. This comment will be updated once the review is ready.

Interact with Kimchi
  • @getkimchi review — re-trigger a full review on the latest commit
  • @getkimchi summary — regenerate the PR summary
  • @getkimchi ignore — skip this PR (no review will be posted)
  • Reply to any inline comment to ask follow-up questions or request clarification
Configuration

Reviews are configured by your organization admin.
Review instructions, excluded directories, and severity thresholds can be adjusted per repository in the Kimchi dashboard.


Powered by Kimchi — AI-powered code review by CAST AI

@kimchi-review kimchi-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Review Score: 90/100 (overall code quality — 0 lowest, 100 highest)
⏱️ Estimated effort to review: 1/5 (1 = trivial, 5 = very complex)

🧪 Tests: yes — Tests are added for both the fix (the 'No matches found' sentinel is not counted as a match) and the regression case (real match lines are still counted correctly). The tests exercise the actual renderResult path registered by the extension.

No significant issues found. LGTM! 🎉

- Extract GREP_NO_MATCHES_SENTINEL constant instead of hardcoding the
  string in both the renderer and tests (Primitive Obsession / Shotgun
  Surgery risk flagged by review).
- Detect the sentinel at the content level rather than per-line, so a
  genuine match whose text happens to equal the sentinel is no longer
  at risk of being swallowed.
- Remove the .map(line => line.trim()) scope creep that mutated genuine
  match lines displayed whitespace, restoring the original filter-only
  predicate that preserves line content.
- Add regression test: a real match line containing the sentinel text
  is counted as 1 match, not treated as zero-match.

Co-Authored-By: Kimchi <noreply@kimchi.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant