Entity-level code map via sem-core (#315)#321
Merged
Conversation
Adds an optional entity-level code map: for each source file, extract its structural entities (functions, classes, methods) with line ranges and signatures, and expose them to templates both per-file (FileEntry.entities) and as a top-level `code_map`. The default markdown template renders a compact outline before the file contents, so a prompt can lead with structure instead of relying on the LLM to infer it from full files. Design: - Behind the `entity-map` Cargo feature (off by default). sem-core pulls in tree-sitter grammars for ~28 languages, so users who don't want the map pay no build cost. - sem-core (the published crate, not the sem CLI) is offline and carries no telemetry, so enabling this does not change code2prompt's privacy posture. It stays fully air-gapped. - New `--entity-map` CLI flag and `Code2PromptConfig.entity_map`. - One parser registry per worker thread (thread_local) so grammar registration is amortized across files in the rayon pipeline. Tested: unit tests for Rust and Python extraction (feature-gated); full suite passes with and without the feature; verified end to end on a mixed Python/Rust sample.
ODAncona
approved these changes
Jun 18, 2026
ODAncona
left a comment
Collaborator
There was a problem hiding this comment.
LGTM,
I'll take over with the chores =>
- Update doc
- Move unit tests in /test
- Remove some comments
I'll try it out and come back to you for next steps
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.
Implements the entity-level code map from #315. Thanks for the enthusiastic green light @ODAncona, excited to land this.
What it does
With
--entity-map, code2prompt extracts each file's structural entities (functions, classes, methods) with line ranges and signatures via sem-core, and renders a compact outline before the file contents. So a prompt can lead with the shape of the codebase instead of making the model infer it from full files.Example output:
Design decisions (the ones flagged in the issue)
FileEntry.entities, plus a top-levelcode_mapaggregate, since the data is useful both ways and costs nothing to expose twice.--entity-map/Code2PromptConfig.entity_map.entity-mapCargo feature. Standard builds are unaffected.grep -r reqwestin sem-core returns nothing.Try it
Tests
Unit tests for Rust and Python extraction (feature-gated); full suite passes with and without the feature; verified end to end on a mixed sample.
Scope
This is the code map. The natural follow-up is function-level context forging (pull a function plus its real callers/callees across files, token-budgeted, via sem's dependency graph), which is the bigger token-savings win. Happy to do that as a second PR once this lands.