Repository navigation
feat(graph): add limit to codebase_symbol, codebase_impact and codebase_flow - #204
Conversation
|
The exported Please keep the original array-returning function as a compatibility wrapper, and use a separate result helper for the new limit and count metadata. Add a regression for the unchanged three-argument call. Keep the MCP behavior and the agreed graph/index and entry-point-discovery scope unchanged. |
…se_flow codebase_symbol resolves callers and callees for every definition of a name, one file-payload read each, and codebase_impact and codebase_flow list every candidate of an ambiguous name. For a common name such as `main` on a large monorepo the answers run to hundreds of thousands of characters, and the symbol and impact paths take minutes. Add an optional `limit` to all three tools. It applies after the file filter: codebase_symbol resolves only the first `limit` definitions, and codebase_impact and codebase_flow list only the first `limit` ambiguity candidates. For codebase_symbol and codebase_impact, payload reads stop once `limit` matches are resolved. When matches are left out, the answer says so with the shown and total counts, for example: Showing 20 of 1624 definitions of "main". Pass file to narrow to one file, or pass a larger limit to see more. Without `limit`, the tool output is unchanged. Closes giancarloerra#203 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Re: your comment on Thanks. |
23e5063 to
0f48a19
Compare
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
The compatibility requirement is resolved: |
Summary
Adds an optional
limittocodebase_symbol, and to the ambiguity-candidate lists ofcodebase_impactandcodebase_flow, as agreed in #203. Withoutlimit, results and output are unchanged.For a common name such as
main,codebase_symbolresolves callers and callees for every definition, one file-payload read each, in a serial loop. The two sibling tools list every candidate, andcodebase_impactreads a payload for each. The issue measures 1,082,364 characters after 91–139 s for 1,624 definitions on a real monorepo, and 231 s for 5,000 on a synthetic one. Withlimit, the caller gets only the first N matches, and the payload reads stop with them.Changes
index.ts:limit(z.number().int().min(1), optional) in the schemas ofcodebase_symbol,codebase_impactandcodebase_flow.graph-impact.ts:getSymbolContextResult(cache, name, fileHint?, limit?)is new and returns{ contexts, total, fileCount }, wheretotalandfileCountcount the matches after thefilefilter. Withlimit, the loop stops oncelimitdefinitions are resolved, so no payload is read past them. A name-index entry whose payload or symbol does not resolve is skipped as before, and the next match fills its place.getSymbolContext(cache, name, fileHint?)keeps its signature and itsSymbolContext[]return. It callsgetSymbolContextResultwith no limit and returns onlycontexts.getImpactRadiustakeslimitinImpactOptions. In the ambiguous branch it reads payloads only until it haslimitcandidates, and it returnstotalCandidates, the match count after thefilefilter.graph-tools.ts: when an explicitlimitleaves matches out, the answer says so above the list, with the shown and total counts:codebase_symbol's. It namesfileonly when the matches span more than one file, and asks for a longer path when a suffixfilehint still matches several. The second iscodebase_flow's andcodebase_impact's, whose headers already say how to disambiguate. Whenlimitcovers every match, no line is printed.README.md: the three rows of the Impact Analysis table namelimit.Automatic entry-point discovery (
codebase_flowwith noentrypoint) is unchanged.Type of change
Testing
npm run test:unit)npm run test:integration) — not run; no Docker Qdrant available locally. No integration or e2e test reads the changed outputs.npx tsc --noEmit)New tests, covering the four cases from #203:
limit: three definitions ofmain. The test compares the full output of all three tools with the exact text. It also passes against the code onmain.limitmatches and print the shown/total line. Atlimitequal to the match count, none prints it.filehint that keeps two of three matches gives "Showing 1 of 2" in all three tools.getSymbolContextcontract: the two- and three-argument calls return the array of matching definitions, narrowed by the file hint.getFilePayloadshow thatgetSymbolContextResultandgetImpactRadiusstop reading at the limit. A further test shows that a stale name-index entry does not use up the limit.Each new test fails against a mutation of the code it guards, for example a default cap, a limit applied after the reads, or a total counted before the
filefilter.Checklist
Related issues
Closes #203
🤖 Generated with Claude Code
Summary by CodeRabbit