Warn when individual files have an especially high token count - #30
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to warn when individual files exceed a configurable token-count threshold during serialization.
- Introduces
CountFileTokensfor per-file token analysis. - Extends the
Serializerinterface and implementations (XML, text, markdown) to accept and act on ahighTokenCountThreshold. - Adds CLI flag and config support (
HighTokenCountThreshold) and updates the runner to pass the new threshold through.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/tokens/counter.go | Added CountFileTokens helper for per-file token counting. |
| internal/serializer/xml.go | Extended Serialize and readAndNormalizeContent to warn on high tokens. |
| internal/serializer/text.go | Same threshold logic added to plain-text serializer. |
| internal/serializer/markdown.go | Same threshold logic added to markdown serializer. |
| internal/serializer/serializer.go | Updated Serializer interface signature with new threshold param. |
| internal/core/runner.go | Passed HighTokenCountThreshold into Serialize call. |
| internal/config/defaults.go | Added DefaultHighTokenCountThreshold. |
| internal/config/config.go | Wire up HighTokenCountThreshold in Config and CLI parsing. |
| cmd/grimoire/main.go | Introduced --high-token-threshold CLI flag. |
| go.mod | Added new dependencies (tiktoken-go, updated other modules). |
Comments suppressed due to low confidence (1)
internal/tokens/counter.go:88
- Missing unit tests for CountFileTokens to validate its behavior (including empty content and error paths). Consider adding relevant tests.
func CountFileTokens(filePath, content string) (int, error) {
| } | ||
| } | ||
|
|
||
| // Count tokens for this file and warn if it exceeds the threshold |
There was a problem hiding this comment.
[nitpick] The token count warning logic is duplicated across serializer implementations (xml, text, markdown). Consider extracting this into a common helper to reduce duplication.
| return 0, nil | ||
| } | ||
|
|
||
| count, err := CountTokens(content) |
There was a problem hiding this comment.
CountTokens creates a new encoder for each invocation, which could be costly when processing many files. Consider reusing a shared encoder instance to improve performance.
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.
Implemented by Copilot in Agent mode. Resolves #11.