bash-hints: grep nudge fires on every Windows path — readShellToken unescapes backslashes, so absolute operands resolve in-project
Summary
On Windows, the grep/rg nudge fires on every rg/grep command whose path operand is written with backslashes — including paths outside the project and single files inside it, which are exactly the cases the suppression logic was written to stay quiet for. The same commands with forward slashes are silent, so it looks like "the hint is random" to anyone on win32.
Environment
@cortexkit/[email protected](reproduced there;shouldSuppressGrepSearchHintandreadShellTokenare byte-identical in0.64.0, and onmainatpackages/aft-bridge/src/bash-hints.ts)- Windows 11, Node 24, OpenCode host (bash tool = PowerShell on this machine)
- project root
C:\Users\dev\proj
Repro
cd C:\Users\dev\proj
rg -n foo C:\Users\dev\elsewhere\CHANGELOG.md
Output is followed by:
DO NOT search code by running grep/rg in bash — it is unindexed, unranked, and serial. Use the `grep` tool instead (indexed and ranked).
Same command with forward slashes is silent:
rg -n foo C:/Users/dev/elsewhere/CHANGELOG.md
Measured suppression
I extracted shouldSuppressGrepSearchHint and its helpers from the shipped @cortexkit/aft-bridge/dist/bash-hints.js and ran them directly with projectRoot = C:\Users\dev\proj:
| command | suppress |
|---|---|
rg -n foo crates/as-run/src (directory) |
false — intended |
rg -n foo crates/as-run/src/zone.rs (file) |
true |
rg -n foo "C:\Users\dev\elsewhere\CHANGELOG.md" |
false — bug |
rg -n foo C:/Users/dev/elsewhere/CHANGELOG.md |
true |
rg -n foo C:\Users\dev\proj\app\Cargo.toml |
false — bug |
rg -n foo C:/Users/dev/proj/app/Cargo.toml |
true |
cd C:/Users/dev/elsewhere && rg -n foo . |
true |
rg -n foo . |
false — intended |
Root cause
readShellToken applies POSIX escape semantics unconditionally, and PowerShell does not use \ as an escape character:
// packages/aft-bridge/src/bash-hints.ts
} else if (ch === "\\") {
index++;
token += command[index] ?? "\\"; // drops the separator
}
So the operand arrives as:
collectPathOperands(...) -> ["C:UsersdevprojappCargo.toml"]
Then the chain runs exactly as written for a relative path:
resolvePathOperand:path.isAbsolute("C:UsersdevprojappCargo.toml")isfalseon win32 (drive-relative, no separator after the colon), so it resolves against the project root.isPathInsideProject→true.sawInProjectOperand = true;shouldSuppressResolvedPathcallsstatSyncon a path that does not exist →catch { return false }.- After the loop:
if (sawInProjectOperand) return false;→ nudge.
The "operand outside the project" branch (if (!isPathInsideProject(...)) continue) is therefore unreachable on Windows for any backslash path.
firstPipelineStage and splitTopLevelStatements do the same index++ after \, so they inherit the same wrong model of the shell.
There is no win32 test coverage: packages/aft-bridge/src/__tests__/bash-hints.test.ts is entirely POSIX-shaped (no path.win32, no C:\).
Suggested fix
Either half alone fixes the reported behaviour; both are cheap.
- Do not unescape
\on win32 inreadShellToken(and the sameindex++infirstPipelineStage/splitTopLevelStatements), or key the quoting model off the host shell. PowerShell escapes with a backtick, not a backslash. - Fail open on
statSync: an in-project operand that does not exist is more likely a mis-resolved token than a real in-project search, so treat it as external instead of settingsawInProjectOperand. That is also correct for a genuinely in-project path that was deleted between the grep and the check.
Tests worth pinning (the last one is the positive control that keeps the nudge working):
readShellToken("C:\\a\\b c", 0)keeps its separators on win32.maybeAppendGrepSearchHint(out, 'rg -n foo C:\\Users\\dev\\elsewhere\\f.md', true, 'C:\\Users\\dev\\proj')===out.… 'rg -n foo C:\\Users\\dev\\proj\\app\\f.md' …===out.… 'rg -n foo C:\\Users\\dev\\proj\\src' …still nudges.
Happy to send a PR for this if you'd like it in that shape.
Thanks for the precise report and the measurements. Confirmed on main: readShellToken, firstPipelineStage and splitTopLevelStatements in packages/aft-bridge/src/bash-hints.ts treat \ as an escape character outside quotes on every platform, and inside double quotes before any character. On Windows a backslash path loses its separators, resolves as a relative path inside the project, fails statSync, and the nudge fires. That matches your table.
We'll fix it here, with Windows path tests that include your positive control (an in-project directory still gets the nudge), and post on this issue when the release that carries it is out.
Fixed in v0.65.0, released today: On Windows, the grep hint no longer misreads backslash paths outside the project. Thanks for the report. If you still see it after updating, reply here and we'll reopen.