refactor(aegis-core): public_symbols → Layer 1 cache (PR #16)#16
Merged
Conversation
Continues PR #10's pattern: any per-file fact whose extraction was duplicated across consumers belongs in `ast::*` with a `OnceCell` cache on `ParsedFile`. Both extractors used to live as private helpers inside `workspace.rs::summarize_file`. They moved to a new `ast::symbols` module: - `extract_public_symbols(parsed) -> HashSet<String>` — top-level function / class / type / trait / variable names this file exposes. Skips function bodies (nested local helpers are not the file's public API). Rust requires `pub` modifier. - `extract_imported_symbols(parsed) -> HashSet<String>` — names pulled in via `from X import Y` (Python) or `import { a, b } from 'x'` (TS / JS). - `walk_export()` — preserved verbatim for `export default` / `export { a, b as c }` shapes. - `is_public_name()` / `is_likely_public()` — moved alongside. `ParsedFile` grows two more lazy caches: - `public_symbols() -> &HashSet<String>` - `imported_symbols() -> &HashSet<String>` `workspace.rs::summarize_file` now reads both caches instead of walking the tree itself. Net: -158 / +257 (the +257 includes 100 lines of moved code + 50 lines of new tests inside ast::symbols + 21 lines of new ParsedFile API). 3 new unit tests in `ast::symbols`: Python public-fn / Python private-skip, Rust pub-only filter, Python `from … import …` including `aliased_import`. `workspace.rs` unchanged behaviour-wise; same 11 existing workspace tests still pass. Total: 164 → 167 tests pass. Architectural rationale: this is the third per-file fact that moved into Layer 1 (after `Import` in PR #10 and Layer 1 was already provider for `ParsedFile`). The pattern is now stable enough that any future "per-file derived fact" (call_sites, function definitions, etc.) just adds another `OnceCell` field + `extract_X` function. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continues PR #10's pattern. Any per-file fact whose extraction was
duplicated across consumers belongs in `ast::*` with a
`OnceCell` cache on `ParsedFile`.
`extract_public_symbols` / `extract_imported_symbols` /
`walk_export` / `is_public_name` / `is_likely_public` all
moved from `workspace.rs` to a new `ast::symbols` module.
`ParsedFile` gains `.public_symbols()` and `.imported_symbols()`
lazy accessors that mirror the existing `.imports()` API.
Changes
Test plan
symbols tests)
`summarize_file` preserved
🤖 Generated with Claude Code