Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.
TypeScript ai-agentsanthropicclaude-codeclicode-graphcodexcontext-engineeringcursordeveloper-toolsgeminiknowledge-graphllmmcpmcp-serveropen-sourceopenaitree-sitter
fix(search): grep zero-hit note surfaces unreadable files
Shrish Dwivedi51dd63223006
diff --git a/src/search/grep-cli.ts b/src/search/grep-cli.tsindex 309694d5..09fd92a9 100644--- a/src/search/grep-cli.ts+++ b/src/search/grep-cli.ts@@ -60,9 +60,17 @@ export function formatGrepResult(result: GrepResult): string {/** Loud, actionable zero-hit note (never a bare empty result) — printed to* stderr; the caller still exits 0, since "no hits in the indexed graph" is- * not an error, just a reason to fall back to a real grep. */+ * not an error, just a reason to fall back to a real grep.+ *+ * Truncation is never silent, even on the zero-hit path: if some indexed+ * files couldn't be read (`truncated.files > 0`), that's called out too —+ * otherwise a zero-hit result on a stale graph or wrong root reads as "no+ * matches" when really some files were never searched at all. */export function zeroHitNote(result: GrepResult): string {- return `no hits for "${result.pattern}" in ${result.filesSearched} indexed files — unindexed files (docs, configs, new files) aren't searched; try grep -rn "${result.pattern}" for those`;+ const base = `no hits for "${result.pattern}" in ${result.filesSearched} indexed files — unindexed files (docs, configs, new files) aren't searched; try grep -rn "${result.pattern}" for those`;+ const { files } = result.truncated;+ if (files === 0) return base;+ return `${base} — note: ${files} indexed file${files === 1 ? "" : "s"} could not be read (stale graph? run graft build)`;}/**diff --git a/test/search-grep.test.ts b/test/search-grep.test.tsindex 04a64b42..7799c503 100644--- a/test/search-grep.test.ts+++ b/test/search-grep.test.ts@@ -16,6 +16,7 @@ import { tmpdir } from 'node:os';import { join } from 'node:path';import { execFileSync } from 'node:child_process';import { grepGraph } from '../src/search/grep.js';+import { zeroHitNote } from '../src/search/grep-cli.js';import { WALK_RELATIONS } from '../src/graph/relations.js';import { readGraph, wiringPath } from '../src/graph/write.js';import type { GraphV1, NodeV1 } from '../src/graph/types.js';@@ -222,3 +223,21 @@ test('grepGraph: unreadable file is skipped and counted into truncated.files, noassert.equal(r.truncated.files, 1);assert.equal(r.totalHits, 1);});++test('zeroHitNote (grep-cli.ts): zero hits AND unreadable indexed files mentions the unreadable count, not just the zero-hit note', () => {+ const d = mkdtempSync(join(tmpdir(), 'graft-grep-zero-unreadable-'));+ writeFileSync(join(d, 'real.txt'), 'nothing interesting here\n');+ // 'missing.txt' is indexed in the graph but does not exist on disk — the+ // graph is stale (or the root is wrong) relative to what's on disk.+ const graph = graphOf([fileNode('real.txt', 1), fileNode('missing.txt', 1)]);++ const r = grepGraph(graph, d, 'NOPE_NOT_PRESENT');+ assert.equal(r.totalHits, 0);+ assert.equal(r.truncated.files, 1);++ const note = zeroHitNote(r);+ // The plain zero-hit wording must still be there...+ assert.match(note, /no hits for "NOPE_NOT_PRESENT"/);+ // ...but truncation is never silent: 1 unreadable file must be surfaced too.+ assert.match(note, /1 indexed file.*could not be read/);+});