fix(mcp): harden code-rationale git-grep for macOS and color configs#825
Open
austintraver wants to merge 1 commit into
Open
fix(mcp): harden code-rationale git-grep for macOS and color configs#825austintraver wants to merge 1 commit into
austintraver wants to merge 1 commit into
Conversation
grep_comment_candidates() shells out to `git grep -E` and parses the output.
The invocation was fragile in two environment-dependent ways, both invisible
on Linux CI:
1. The pattern anchored on `\s`, a GNU regex extension. macOS/BSD git's ERE
engine does not honor it, so `^\s*(#|//|--|\*)...` matched nothing and the
function returned an empty list, silently disabling concept-anchoring on
macOS.
2. The command did not pass `--no-color`, so a user with `color.ui=always`
got ANSI escapes wrapping every path (`\x1b[35m...enrichment.py\x1b[m`),
which the `line.split(":")[0]` path parse then captured verbatim.
Use the POSIX class `[[:space:]]` (portable across BSD/macOS and GNU/Linux)
and pass `--no-color` so parsed output is stable regardless of git config.
The two existing tests already covered this behavior but failed only off
Linux; both now pass on macOS.
|
✅ Health: 7.6 (unchanged) 📋 At a glance
🔎 More signals (2)🔥 Hotspot touched (1)
🔗 Hidden coupling (1 file)
📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-07-14 04:48 UTC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
grep_comment_candidates()inmcp_server/_code_rationale.pyshells out togit grep -Eand parses the result. The invocation was fragile in two environment-dependent ways, both invisible on Linux CI:\sis not portable ingit grep -E.\sis a GNU regex extension; macOS/BSD system git (e.g. Apple Git) does not honor it in ERE mode, so^\s*(#|//|--|\*)...never matches comment-leading lines with leading indentation. The function returns[], silently disabling MCP concept-anchoring / in-code rationale on macOS.git grepoutput was not forced to--no-color. Withcolor.ui=alwaysin a user's git config, git wraps each path in ANSI escapes (\x1b[35m...enrichment.py\x1b[m), which theline.split(":")[0]path parse captures verbatim, corrupting every returned candidate path.Both are invisible in CI (Linux, default git config), so the two tests that cover this pass in CI while the feature is silently broken for macOS users and anyone running
color.ui=always.Fix: use the POSIX class
[[:space:]](portable across BSD/macOS and GNU/Linux git) and pass--no-colorso the parsed output is stable regardless of git config. No behavior change on Linux.Related Issues
None filed.
Test Plan
uv run pytest tests/unit/server/mcp/test_code_rationale.py-> 19 passed on macOS. Before this change,test_grep_comment_candidates_ranks_number_bearing_fileandtest_concept_anchor_injects_winner_as_dominantfail on macOS (they already pass on Linux/CI).ruff checkclean on the changed file.Reproduced on macOS (Apple Git 2.50.1):
Checklist