Skip to content

feat(mcp): line numbers in explore output + per-file cluster fixes#188

Merged
colbymchenry merged 4 commits into
mainfrom
feat/explore-line-numbers
May 19, 2026
Merged

feat(mcp): line numbers in explore output + per-file cluster fixes#188
colbymchenry merged 4 commits into
mainfrom
feat/explore-line-numbers

Conversation

@colbymchenry
Copy link
Copy Markdown
Owner

Follow-up to #185 / #187. Came out of testing the question "what if codegraph_explore returned line numbers too?"

Changes

  1. Line numbers in explore source sections (<num>\t<code>, cat -n style, matching the Read tool). Lets the agent cite file:line straight from the payload instead of re-opening a file just to recover a line number — the dominant residual cost on precise-tracing questions. Toggle off with CODEGRAPH_EXPLORE_LINENUMS=0.

  2. Cluster ranking now prioritizes entry points. The I'm missing something?  #185 per-file cap ranked clusters purely by density, which buried the relevant methods (perform/didCreateURLRequest/task in Alamofire's Session.swift) under the dense top-of-file class header + property list. Clusters containing a query entry point now rank first; density is a tiebreaker.

  3. Whole-file "envelope" nodes excluded from clustering. A class/struct/etc. spanning >50% of the file (the Session class is ~1,400 lines) was collapsing every method into one giant cluster that tail-trimmed down to just the class header. Now dropped from the ranges so the granular methods survive.

Fixes 2 and 3 are corrections to the #185 per-file cap (unreleased), surfaced while validating line numbers: the relevant code wasn't making it into the payload, which is why an agent still had to re-read.

Evidence

Isolated A/B (answer "on which exact line is the URLSession task created in didCreateURLRequest?", relevant code already in payload, two identical Explore subagents):

Arm Reads Extra Bash Answer
no line numbers 2 reads of Session.swift + 1 grep yes 1298 ✓
line numbers 0 0 1298 ✓

The no-line-numbers arm burned ~4-5k tokens (a Read of lines 1-500) recovering a line number the line-numbered arm cited for the ~130-token payload cost.

Payload size, net vs the 0.7.10 baseline (line numbers on): Alamofire -60%, Excalidraw -32%, VS Code -12% per explore call. (Line numbers add ~3-5%; the cap fixes shifted which lines are shown, not the totals materially.)

Test plan

  • 16 tests in __tests__/explore-output-budget.test.ts (3 new: line numbers present by default, absent when toggled off, envelope filter keeps method bodies)
  • Full suite 612/612
  • Reviewer: end-to-end token check in a fresh session vs the prior 0.7.11 run (the offline harness measures payload, not full-session tokens)

colbymchenry and others added 4 commits May 19, 2026 16:43
Follow-up to #185. Three changes to codegraph_explore:

1. Source sections now carry cat -n style line-number prefixes
   (<num>\t<code>), so the agent can cite file:line straight from the
   payload instead of re-Reading the file just to recover a line number.
   Isolated A/B: the no-line-numbers arm spent 2 Reads + a grep to find a
   line number the line-numbered arm cited with zero follow-up calls.
   Payload cost ~3-5%. Toggle off with CODEGRAPH_EXPLORE_LINENUMS=0.

2. Per-file cluster selection now ranks clusters containing a query entry
   point ahead of dense declaration blocks. Density-only ranking buried
   the relevant methods (perform/didCreateURLRequest/task in Alamofire's
   Session.swift) under the top-of-file class header + property list.

3. Whole-file "envelope" nodes (a class/struct/etc. spanning >50% of the
   file) are excluded from clustering. The Session class spans ~1,400
   lines; keeping it collapsed every method into one giant cluster that
   tail-trimmed down to just the class header, hiding the methods.

Net vs the 0.7.10 baseline, line numbers on: Alamofire -60%, Excalidraw
-32%, VS Code -12% per explore call.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The gap separator and the two tail-trim markers used C-style `//`
comments, which aren't comments in Python, Ruby, etc. Switch to plain
`... (gap) ...` / `... (trimmed) ...` so they read correctly inside any
language's fenced source block. With line numbers on, the line-number
jump already corroborates a gap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sibling to the explore marker fix: codegraph_context's code-block
truncation used a C-style `// ... truncated ...`. Switch to
`... (truncated) ...` so it reads correctly in any language's fenced
source block.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@colbymchenry colbymchenry merged commit 2c1a314 into main May 19, 2026
colbymchenry added a commit that referenced this pull request May 20, 2026
Folds all changes since 0.7.10 into 0.7.12 (0.7.11 was unpublished from
npm): size-adaptive codegraph_explore output budget (#185/#187), line
numbers in explore source sections (#188), explore-first tool guidance
(#191), language-neutral source-omission markers, and Kotlin/Swift
test-file detection (#191).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant