Skip to main content

Module context

Module context 

Source
Expand description

Task-driven context packs.

Given a natural-language task and a token budget, greplm assembles the most relevant slice of the codebase an agent needs to act — ranked by lexical relevance, call-graph centrality, and (when built with the semantic feature) meaning — and packs it to fit the budget. This is the “give me exactly the code for this task” surface that keeps agents off the grep-then-read-whole-files treadmill.

The ranking helpers here are pure; crate::search::Searcher::context_pack drives them over the index.

Structs§

ContextPack
A budget-bounded bundle of context for a task.
PackItem
One unit of packed context: a symbol, its signature, and a code snippet.
ScoreScratch
Reusable buffers for lexical_score_with.

Constants§

CHARS_PER_TOKEN
Conservative chars-per-token estimate (matches the savings accounting).

Functions§

est_tokens
Estimate the token cost of a string.
lexical_score
Lexical relevance of a symbol to the task terms.
lexical_score_with
Lexical relevance of a symbol, given its document’s precomputed path_term_bonus. Allocation-free once scratch’s buffers are warm.
path_term_bonus
The path component of a symbol’s lexical score: 2.0 per task term that appears in the path. This depends only on the document, so context_pack computes it once per file rather than once per symbol.
split_identifier
Split an identifier into lowercase tokens on camelCase and snake/kebab.
tokenize
Tokenize a free-form task into lowercased search terms: split on non-identifier characters, then split camelCase/snake_case, dropping stopwords and 1-character noise.