Skip to content

feat(tree): compact tree with line counts, hub addresses and symbols - #296

Merged
JordanCoin merged 4 commits into
mainfrom
feat/tree-compact-addresses
Nov 11, 2026
Merged

JordanCoin merged 4 commits into
mainfrom
feat/tree-compact-addresses

Conversation

@JordanCoin

@JordanCoin JordanCoin commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Follows #295 (hub stars and legend), now merged.

What

Everything here applies to the plain codemap . tree. The goal is a tree an agent can act on directly: less repeated structure, and addresses it can hand straight to rg or a file read.

Less noise

  • Tests fold into their source: filegraph.go (+3 tests). Unmatched tests show as +N other tests, except inside a tests tree, which still lists its files.
  • Runs of 4+ siblings that differ only in digits collapse: page-*.yml ×9.
  • A wholly untracked directory is one line with its file count and size.
  • A single-file directory prints as dir/FILE.
  • An overlong name gets its own row instead of forcing the whole directory into one column.

Addresses

  • Line counts at 100+ lines: hooks.go 2535L.
  • Trailer: Hubs (top 10 of N, by importers), one hub per line with its importer count, full repo-relative path and line count.
  • Symbol addresses (path:line Name) were built and then removed: the first exported functions in file order are arbitrary, and Go package hubs got none.
  • Next: line with the follow-up commands.

Hook

  • Session-start states hubs once and sheds extras before cutting depth (first the hub list down to top 3, then line counts). On this repo the hook goes from depth 1 at 3,369 chars to full depth at 8,559; werkzeug stays full depth at 8,071.

Evidence

  • Blind ranking by six model judges (3 Haiku, 3 Sonnet) across codemap, CodeMachine-CLI and docling: all six ranked this output first and the 4.7.1 output last.
  • Agent task benchmark (two hidden-test tasks, two models, three repeats per cell): every run passed in every arm, and turn and token differences were within run-to-run noise. No measured task-level effect in either direction.

Cost

codemap . origin/main this PR
codemap, warm daemon 0.04s 0.13s
docling, no daemon 0.40s 1.97s

About 1.4s of the docling increase is the hub graph scan that #295 already adds. The timings were measured before the symbol lines were removed, so they are an upper bound.

Output size: codemap 307 to 163 lines (16.1KB to 10.3KB), docling 492 to 456 lines, CodeMachine-CLI 313 to 324 lines (22.4KB, up from 20.0KB).

Safety

Line counts read file contents. Reads go through one function that skips anything Lstat does not report as a regular file (symlinks, FIFOs, devices) and reads through a 2MB+1 limit. Known remaining gap: a path swapped for a FIFO between the Lstat and the open could block; closing it needs a non-blocking open.

Unchanged

  • --json, --deps, --skyline are byte-identical to origin/main on codemap and docling.
  • MCP get_structure gets the folding and layout changes but no stars, line counts, legend or trailer, since MCP passes no hub or line data. Its HUB FILES block is unchanged.

Test

gofmt -l . clean, go vet ./..., go test ./... pass locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FWQw8DzwM4bQnL7mvk6Fsq

JordanCoin and others added 2 commits November 11, 2026 13:49
The tree starred the five largest source files with no legend, so a reader
could not tell what the star meant, and on this repo it landed on
main_more_test.go. File size says nothing about blast radius.

The star now marks hubs from the file graph, with the importer count inline:
`types.ts ←41` for a file, `scanner/ ←73` on the directory of a multi-file Go
package (Go imports name packages, so the count belongs to the package, per
#292). N is the importer count used by get_hubs and the session-start hub
list; a hub needs 3+ non-test importers, so test files are never starred.

One legend line under the tree says what the marker and N mean, and carries
the graph note: partial coverage, or why stars are missing (no graph, or the
repo is above the 5000-file graph limit).

Hubs come from the daemon's validated graph when it was built with the same
filters, else a fresh BuildFileGraph scan (docling, no daemon: 0.41s -> 1.8s
per `codemap .`; codemap with a warm daemon: no measurable change).

The session-start hook drops its own hub block when the tree carries the
legend, so hubs are stated once and the werkzeug tree still fits the 10,000
char cap at full depth.

--json, --deps, --skyline and --diff output are unchanged. MCP get_structure
renders without hub data, so its tree loses the old size stars and gains no
legend; its HUB FILES section is unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWQw8DzwM4bQnL7mvk6Fsq
Builds on the hub stars and legend from #295. All changes apply to the
plain `codemap .` tree; --json, --deps, --skyline and --diff are unchanged.

- Fold same-directory tests into their source: `filegraph.go (+3 tests)` (Go x_test/x_*_test, JS/TS .test/.spec, Python test_x/x_test).
- Count unmatched tests as `+N other tests`, except in a tests tree (test/, tests/, __tests__/, spec/ or no folded test), which lists its files.
- Collapse 4+ siblings that differ only in digit-bearing tokens: `page-*.yml ×9`.
- Collapse a wholly untracked directory (git ls-files --others --directory) to one line with its file count and size.
- Print a single-file directory as `dir/FILE`, at any depth, so .claude/skills/ and plugins/codemap/skills/ render alike.
- Give an overlong name its own row in sorted position instead of forcing a whole directory into one column.
- Show physical line counts at 100+ lines (`hooks.go 2535L`; text files up to 2MB, binaries and assets skipped).
- Read files for line counts and symbol lines only when Lstat says regular (symlinks, FIFOs and devices skipped), through a reader capped at 2MB+1.
- Trailer: `Hubs (top 10 of N)` with full paths, importer counts and line counts, wrapped under 400 chars; `path:line Name` for up to 3 exported top-level functions of the top 5 file hubs, kept only when the reported source line names the symbol; `Next:` commands.
- ast-grep function and type matches now record their line (FileAnalysis.SymbolLines, not serialized).
- Session-start hook: hubs stated once (its own hub block is dropped when the tree prints the legend), and the tree sheds extras before depth via CODEMAP_TREE_LEAN (1: no symbols, top 3 hubs; 2: also no line counts) before fitSessionStart cuts depth. Renders are cached by depth and level.

Measured (`codemap .`, warm, vs origin/main):
- codemap (daemon cache warm): 0.04s -> 0.13s; docling (no daemon): 0.40s -> 1.97s, of which the hub graph scan is ~1.4s, line counts and symbols ~0.2s.
- Output: codemap 307 -> 163 lines, 16.1KB -> 10.3KB; docling 492 -> 456 lines; CodeMachine-CLI 313 -> 324 lines.
- Hook: werkzeug full depth at 8,040 chars (#295: 8,028, full depth); codemap full depth at 8,528 chars (#295: depth 1, 3,369).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWQw8DzwM4bQnL7mvk6Fsq
@JordanCoin
JordanCoin changed the base branch from fix/tree-star-hubs to main November 11, 2026 21:24
JordanCoin and others added 2 commits November 11, 2026 16:27
First-three-exported-in-file-order symbols were arbitrary and Go package hubs got none, so the symbol rows and the ast-grep line recording behind them are gone.
The hub list prints one hub per line, right-aligned count first, so names align and no 400-char wrapping is needed; hook lean level 1 now cuts it to three rows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWQw8DzwM4bQnL7mvk6Fsq
@JordanCoin
JordanCoin merged commit f853208 into main Nov 11, 2026
13 checks passed
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