Skip to content

code_outline: where a name is declared, what a file or directory holds - #626

Merged
FMXExpress merged 2 commits into
mainfrom
claude/pasclaw-desktop-plan-uapzcp
Nov 5, 2026
Merged

FMXExpress merged 2 commits into
mainfrom
claude/pasclaw-desktop-plan-uapzcp

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

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 beside grep_files and find_files (RegisterFSTools), read-only:

  • symbol=NAME: where NAME is declared or defined under path (functions, procedures, methods, classes, records, types, constants, unit variables), not its uses. A Pascal body is listed as Name (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:

  • Pascal: comments and string literals are taken out first. Types are read inside type blocks and members inside class/record bodies. A routine's own local types and variables are skipped, and unit-level const/var are included.
  • Others: Python, JS/TS (and the scripts in .html files), 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 the code_outline call that would have found it.

Measured: make bench-codenav

34 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:

calls bytes returned lines answered
grep_files for the name 34 47,690 867 34/34
grep_files guessing the keyword 52 8,499 31/34
code_outline symbol= 34 7,021 69 34/34

Keyword guessing misses methods, which are declared as function DeferredNames (two spaces) or defined as TToolRegistry.DeferredNames. Without the new hint text on misses, its bytes were 6,690.

  • Large units: an outline is 3.7–5.7% of the file (PasClaw.Gateway.Desktop.pas: 142,287 → 5,226 bytes); for the smaller PasClaw.Tools.Registry.pas it is 14.5%.
  • The price: the schema is 406 bytes (trimmed from 594 because of this measurement), and every request carries it. That came to 483 bytes per call on the team-board replays: duo +1.47%, security sweep +1.2%.
  • Visible, not deferred: the tool is visible like grep_files, because a deferred built-in reaches the model only as a bare name, and bench/teamboard/LIVE.md records that hidden tools are mostly never chosen. Deferring it would be a one-line ToolIsLongTail change.
  • Not measured: whether a model chooses the tool by itself. That's a live run's question.

Full write-up: bench/codenav/README.md.

Tests

  • code_outline_tests: one fixture per language, including the traps a line scanner falls into:

    • declaration keywords inside comments and strings, including multi-line { } and (* *) blocks;
    • a { inside a string literal;
    • a routine's local types and variables;
    • a constant's continuation lines;
    • a def inside a def;
    • an 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 test passes 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

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T06:58:21.713538Z 5924864 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/pkg/tools/PasClaw.Tools.Outline.pas Outdated
Comment on lines +684 to +687
if (Line[I] = '/') and (I < N) and (Line[I + 1] = '*') then
begin
InBlock := True;
Inc(I, 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +1294 to +1298
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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
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.

2 participants