Skip to content

Warn when individual files have an especially high token count - #30

Merged
foresturquhart merged 4 commits into
mainfrom
individual-file-token-counts
May 23, 2025
Merged

Warn when individual files have an especially high token count#30
foresturquhart merged 4 commits into
mainfrom
individual-file-token-counts

Conversation

@foresturquhart

Copy link
Copy Markdown
Owner

Implemented by Copilot in Agent mode. Resolves #11.

@foresturquhart
foresturquhart requested a review from Copilot May 23, 2025 20:28
@foresturquhart foresturquhart self-assigned this May 23, 2025
@foresturquhart foresturquhart added the enhancement New feature or request label May 23, 2025
@foresturquhart foresturquhart linked an issue May 23, 2025 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds functionality to warn when individual files exceed a configurable token-count threshold during serialization.

  • Introduces CountFileTokens for per-file token analysis.
  • Extends the Serializer interface and implementations (XML, text, markdown) to accept and act on a highTokenCountThreshold.
  • 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

Copilot AI May 23, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The token count warning logic is duplicated across serializer implementations (xml, text, markdown). Consider extracting this into a common helper to reduce duplication.

Copilot uses AI. Check for mistakes.
Comment thread internal/tokens/counter.go Outdated
return 0, nil
}

count, err := CountTokens(content)

Copilot AI May 23, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@foresturquhart
foresturquhart merged commit 0c16c2a into main May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn when individual files have an especially high token count

2 participants