Repository navigation
feat: give the intent planner the contents of the files most related to the issue - #52
Merged
Merged
Conversation
…to the issue The planner has no tools and saw the contents only of the files an issue names by path. For an issue that names none it wrote steps, and limits, about files it had chosen by name alone. planOne now ranks the tracked files against the issue's title and body with a small deterministic scorer (BM25 over each text file's head, plus a boost for terms in its path) and appends the top files' contents as fenced data blocks under their own heading. --context-bytes bounds the named and ranked contents together, with the named files first, and --context-files caps the ranked files; 0 adds none. Binary files, symlinks, lockfiles and vendored code are never ranked. The prompt now lists the files whose contents it holds, in full or cut at a cap, and tells the planner it knows every other file by name alone. pkg/agent/repomap is not reused: it indexes only non-test Go files and ranks by Go declarations, while an issue may be about any file type. Signed-off-by: Christopher Maher <chris@mahercode.io>
Defilan
force-pushed
the
agent/planner-file-context
branch
from
November 27, 2026 22:29
3ce5140 to
b53e5de
Compare
Defilan
approved these changes
Nov 27, 2026
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.
What
The intent planner now gets the contents of the tracked files most related to the issue, not only those the issue names (option 1 of the issue: rank and include, one call, still no tools).
pkg/cli/intents_context.go:relatedFileContentsranks the tracked files against the issue title and body and returns the top ones, best first, skipping the files the issue already names.untrustedTextincludes their paths and contents, so a nonce found in one is refused like any other.meitheal intentsandmeitheal run --plan:--context-bytes(default 64 KiB) bounds the named and ranked contents together, with the named files first and the ranked files filling what they leave;--context-files(default 6) caps the ranked files.0for either adds no ranked files; negative values are refused. The named-file cap is unchanged.Why
Fixes #43
For an issue that names no paths the planner wrote concrete steps, and "use only these sources" limits, about files it had picked by name and never read. With the related files' contents in the prompt, and an explicit list of what it has read, the planner can ground its steps and say "start from" for the rest.
How
pkg/agent/repomapwas evaluated and not reused: it indexes only non-test.gofiles, ranks them by Go declarations, and walks the file system rather than the tracked list. The motivating issue was documentation-only, in a repository that is not Go.The scorer is small and deterministic (same checkout and issue, same files):
-ies/-iedfold to-yand a plural-sis dropped; words under three characters, numbers and English filler are dropped.readRegularFileInsiderefuses (the same rule as named files), files over 1 MiB, lockfiles (go.sum,Cargo.lock,package-lock.jsonand the like) andvendor//node_modules/.The prompt keeps its property of naming no project, path or label (
TestIntentPrompt_IsRepoAgnosticpasses unchanged). The new text is consistent with general rule 9 from #47 ("name files to start from ... unless this message holds their contents") but does not depend on it.Not stacked: branched from
main. A trial merge of #47, #50 and this branch ontomainhas no conflicts, andgo test ./pkg/cli/...passes on the result.Testing
TestRelatedFiles_RanksTheIssueTopic/TestRelatedFiles_FollowsTheTopic: in a fixture repository, an issue about webhook retry backoff pulls indocs/retries.mdandpkg/retry/backoff.goand not the install doc (which has one incidental match), the metrics file, the README,go.sum, the vendored copy, a binary or a symlink that mention the topic. An issue about installing pulls in the install doc and none of the retry files. The ranking is deterministic.TestRelatedFiles_SkipsNamedFilesAndRespectsLimits,TestRelatedFiles_PerFileCap: named files are skipped; the file count, the byte budget (exactly, with the cut file marked) and the per-file cap hold; a zero or negative limit adds nothing.TestRelatedFiles_PathTermsBoost,TestRelatedFiles_LengthNormalized,TestEachTerm,TestQueryTerms_TitleCountsDouble: the scorer's parts.TestIntentPrompt_RelatedFilesFencedAndListed: the related contents sit inside data blocks after the named files,untrustedTextincludes them, and the full/head lists and notes are right.TestPlanIssues_PromptCarriesRelatedFiles(with and without a budget),TestPlanIssues_NamedFilesShareTheContextBudget,TestPlannerSetup_ContextFlags: throughPlanIssuesand the flags.go test -overlay, 24 mutants of the scorer, the prompt and the wiring): 23 killed. The one survivor removes the NUL check on the scanned head; the NUL check on the re-read before inclusion still keeps binaries out of the prompt, so it is defence in depth.go test ./pkg/cli/...,make fmt vet,make lint(0 issues). The full envtestmake testwas not run; nothing outsidepkg/clichanged.Checklist
make testpasses locally (rango test ./pkg/cli/...only)make lintpasses locallymeitheal intentshelp and flag usage)Assisted-by: Claude Code (Claude Opus 5.5) wrote the ranking, the prompt changes, the flags and the tests; the tests were checked against 24 hand-written mutants (23 killed, the survivor explained above), a trial merge with #47 and #50 was tested, and
go test ./pkg/cli/...,make fmt vetandmake lintwere run.