Per-directory token counts in tree; drop 10MB hard size limit - #45
Open
malakhov-dmitrii wants to merge 1 commit into
Open
Per-directory token counts in tree; drop 10MB hard size limit#45malakhov-dmitrii wants to merge 1 commit into
malakhov-dmitrii wants to merge 1 commit into
Conversation
FileNode now carries size + tokenEstimate (bytes/4), aggregated for dirs (skipping gitignored/customignored children so counts match what actually ships to the LLM). FileTree renders a ~Xk/M badge next to each node so users can see which dirs dominate the context without guess-and-check. Size gate removed from generateShotgunOutputWithProgress: ErrContextTooLong returns at the three check points and the maxOutputSizeBytes constant are gone. The UI already has a color-coded token counter (green < 500k, yellow < 1.5M, red >= 1.5M) that tells the user when they're near an LLM's window - better to trust the user with a visible signal than to hard-stop at a byte count that doesn't map to Gemini's actual tokenizer. Frontend token estimate switched from chars/3 to chars/4 in Step1PrepareContext + LargeTextViewer so the counter matches real Gemini-ish ratios more closely. Docs (design/architecture.md) updated to reflect the new behavior.
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.
Why
Two small pain points when preparing context on a large repo:
ErrContextTooLongand couldn't proceed). The byte-count and token-count don't line up, so the cap blocks valid selections.What changed
Per-directory token counts in the sidebar tree.
FileNodegainssize(int64, bytes) andtokenEstimate(int64, bytes / 4) fields. DuringbuildTreeRecursivethe size/estimate is set per-file fromentry.Info()and aggregated for directories, skipping gitignored/customignored children so the displayed count matches what will actually be emitted to the LLM.FileTree.vuerenders a small~Xk/~X.XMbadge next to each node.Non-blocking generation. Removed
maxOutputSizeBytesandErrContextTooLongand the three size-check branches ingenerateShotgunOutputWithProgress. The existing frontend counter (Step1PrepareContext.vue+LargeTextViewer.vue) already shows a color-coded total that turns yellow at 500k tokens and red at 1.5M. That's a clearer UX than a hard error: the user can see the budget and decide, instead of the app refusing after the fact.Token estimate math. UI divisor switched from
chars/3→chars/4in bothStep1PrepareContextand the reusableLargeTextViewer, and the color thresholds now operate on estimated tokens (green < 500k, yellow < 1.5M, red ≥ 1.5M) instead of raw chars.bytes/4is a rough match for Gemini's code/prose ratio — not perfect, but closer than/3and enough for a visual gauge.Docs.
design/architecture.mdsection 6.2 rewritten to describe the non-blocking design and the per-node token fields.Scope
6 files touched, additive API changes only (two new JSON fields on
FileNode; clients that ignore them are unaffected). No test changes — the project doesn't have Go or Vue tests for these paths today.Test plan
go build ./...passeswails devruns; the tree shows per-dir token badges.git/node_modulesmatches the generated context token count instead of summing everything)Notes for reviewer
bytes/4is a deliberate approximation; happy to make it configurable or swap for a more accurate heuristic if you'd prefer.node_modulesselection), easy to add back.FileNodewith JSON tagssize/tokenEstimate;wailsjs/go/models.tsregenerates cleanly onwails generate.