Repository navigation
code_outline: where a name is declared, what a file or directory holds - #626
Conversation
A repository map, made on demand instead of carried in every request. Measured on a long session on this repository, 7% of all tool calls were repo-wide "which file is X in" searches, and most were for a definition, which a literal grep answers with every use or, on a wrong keyword guess, with nothing. - symbol=NAME: where NAME is declared or defined under path (functions, methods, classes, types, constants), not its uses. A Pascal body is listed by its line after the declaration's signature. - path=FILE: its declarations with line numbers: interface, then implementation bodies; members indented under their type. - path=DIR: each file's purpose (its leading comment's first paragraph) and the names it declares; subdirectories one line each. Line scanners, no regex engine, so FPC and Delphi behave the same: Pascal (comments and strings taken out first; types in type blocks, members in class/record bodies, a routine's own locals skipped, unit-level const/var), Python, JS/TS (and .html scripts), Go, Rust, Ruby, PHP. It skips the same dependency directories and binaries as grep_files, and every result is capped with a pointer for what to ask next. Registered beside grep_files and find_files (RegisterFSTools). grep_files: a definition-shaped pattern (function X, def X, class X, ...) that finds nothing now names the code_outline call that would. bench/codenav (make bench-codenav), 34 real definition lookups: - grep for the name: 34 calls, 47,690 bytes, 867 lines, 34/34; - grep guessing the keyword: 52 calls, 8,499 bytes, 31/34; - code_outline: 34 calls, 7,021 bytes, 69 lines, 34/34. A large unit's outline is 4-6% of the file. The schema is 406 bytes, 483 per call on the team-board replays (+1.2-1.5%). Tests: code_outline_tests (one fixture per language, with the traps a line scanner falls into; the three modes, the budget, the sandbox, registration, the grep hint). 17 of 17 behaviours revert-checked. make test passes on FPC 3.2.2; not compiled with Delphi here. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 592486479b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (Line[I] = '/') and (I < N) and (Line[I + 1] = '*') then | ||
| begin | ||
| InBlock := True; | ||
| Inc(I, 2); |
There was a problem hiding this comment.
Ignore comment delimiters inside C-family string literals
When a JS/TS, Go, Rust, or PHP string contains /*, this branch sets the persistent InBlock flag even though no comment began. For example, const pattern = "/*"; followed by function real() {} causes real and all subsequent declarations to disappear until a later */ occurs. This makes symbol searches incorrectly report that existing declarations do not exist, rather than merely shortening a declaration's tail as the helper's comment suggests. Track quoted strings before recognizing comment openers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 13399dc. I reproduced it first: const pattern = "/*"; followed by function real() {} gave 0 declarations, and symbol=real reported none.
CCode now skips string literals before it looks for comment openers, and replaces their contents with "" so text inside a string can't look like code. Quotes follow each language:
- JS:
',"and template backticks, where a template may span lines. - PHP:
'and", either of which may span lines. - Go:
"strings, backtick raw strings that may span lines, and'runes that close within a few bytes, so'"'and'`'open nothing. - Rust:
"strings, which may span lines;'is a char literal only when it closes within a few bytes, so a lifetime ('a) opens nothing.
The tests cover all four languages:
- a string holding
/*or//, including a URL string before a class's{; - a template literal spanning lines;
- a Go rune holding a backtick;
- a Rust char literal holding
"; - an
impl<'a>.
Each rule was revert-checked. desktop.html outlines the same 154 functions before and after.
Generated by Claude Code
| for I := 0 to Dirs.Count - 1 do | ||
| begin | ||
| Sub.Clear; | ||
| CollectSources(JoinPath(Dir, Dirs[I]), Sub, 1000); | ||
| Sb.Append(Prefix).Append(Dirs[I]).Append('/ ').Append(IntToStr(Sub.Count)); |
There was a problem hiding this comment.
Apply the output budget to subdirectory listings
For a directory with many immediate subdirectories, this loop appends every subdirectory without checking OutlineBudget; the budget check above applies only to source-file entries. Consequently, a directory-only monorepo root can produce an arbitrarily large response despite the tool's stated bounded-output behavior, consuming the context this tool is intended to save. Stop adding subdirectory entries when the budget is reached and report the omitted count with a narrowing hint.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 13399dc. Reproduced: a root of 3,000 subdirectories returned 424,932 bytes.
The subdirectory loop now applies the same OutlineBudget check as the file entries, and when it stops it reports (+N more subdirectories not shown -- outline one by path). The same root now returns 16 KB. The new test builds 700 subdirectories and asserts the result stays within the budget and reports the omitted count. Undoing the check fails it (39,131 bytes).
Generated by Claude Code
… the budget Two findings from review on #626, both reproduced first: - In JS/TS, Go, Rust and PHP, a string holding "/*" (const pattern = "/*";) set the open-comment flag, and every declaration after it vanished: symbol= reported "no declaration" for code that was there. A "//" in a string also cut its line. CCode now skips string literals before looking for comments, with each language's quotes: - JS: ' " and template backticks (multi-line); - PHP: ' and " (multi-line); - Go: " , raw backticks (multi-line), and runes that close within a few bytes; - Rust: " (multi-line), and ' as a char literal only when it closes within a few bytes, so a lifetime ('a) opens nothing. Contents become "", so text inside a string cannot look like code. desktop.html outlines the same 154 functions before and after. - path=DIR applied its budget to source files but not subdirectories: a root of 3,000 directories returned 425 KB. The subdirectory loop is now held to the same budget and says how many it left out (16 KB). Tests: strings holding comment openers in all four languages, a Go rune holding a backtick, a Rust char literal holding a quote and an impl with a lifetime, a JS template spanning lines, a URL string before a class's {, and 700 subdirectories. Revert-checked: 22 of 22 caught. make test passes on FPC 3.2.2; bench-codenav is unchanged for code_outline (34/34, 7,021 bytes). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
A repository map, made on demand instead of carried in every request.
Why
Measured on a long session on this repository (2,957 tool calls, from its transcript): 7% were repo-wide "which file is X in" searches, and most of those were looking for a definition (
grep -rn "function X"). A literal grep answers that with every use as well, or with nothing when the guessed keyword is wrong. Aider puts a repository map in every request; this is the on-demand version.The tool
code_outline, registered besidegrep_filesandfind_files(RegisterFSTools), read-only:symbol=NAME: where NAME is declared or defined underpath(functions, procedures, methods, classes, records, types, constants, unit variables), not its uses. A Pascal body is listed asName (body)with its line after the declaration's signature.path=FILE: the file's declarations with line numbers. For Pascal, the interface comes first, then the implementation bodies, with members indented under their type.path=DIR: each source file's purpose (the first paragraph of its leading comment) and the names it declares, with subdirectories one line each to drill into.Line scanners, not parsers, and no regex engine, so FPC and Delphi behave the same:
typeblocks and members inside class/record bodies. A routine's own local types and variables are skipped, and unit-levelconst/varare included..htmlfiles), Go, Rust, Ruby and PHP.It skips the same dependency directories and binaries as
grep_files, respects the sandbox, and caps every result with a pointer to what to ask next.grep_files: when a definition-shaped pattern (function X,def X,class X, …) finds nothing, the result now names thecode_outlinecall that would have found it.Measured:
make bench-codenav34 real definition lookups from that session. The defining files were found independently, not by the tool under test. Each lookup goes through the tool registry:
grep_filesfor the namegrep_filesguessing the keywordcode_outline symbol=Keyword guessing misses methods, which are declared as
function DeferredNames(two spaces) or defined asTToolRegistry.DeferredNames. Without the new hint text on misses, its bytes were 6,690.PasClaw.Gateway.Desktop.pas: 142,287 → 5,226 bytes); for the smallerPasClaw.Tools.Registry.pasit is 14.5%.grep_files, because a deferred built-in reaches the model only as a bare name, andbench/teamboard/LIVE.mdrecords that hidden tools are mostly never chosen. Deferring it would be a one-lineToolIsLongTailchange.Full write-up:
bench/codenav/README.md.Tests
code_outline_tests: one fixture per language, including the traps a line scanner falls into:{ }and(* *)blocks;{inside a string literal;definside adef;if (inside a JS class.They also cover the three modes, the budget cut, the sandbox, registration and the grep hint.
Revert-checks: each behaviour was undone one at a time and the suite run to see it fail: 17 of 17 caught.
make testpasses on FPC 3.2.2. Not compiled with Delphi (dcc64 is not available in this environment). A Delphi-only branch handles a UTF-8 BOM decoded as#$FEFF.Generated by Claude Code