-
Notifications
You must be signed in to change notification settings - Fork 1
Add LLM token estimation for file selection output #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
alexec
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Please change
main.go
Outdated
| // Estimate tokens for this file | ||
| tokens := estimateTokens(expanded) | ||
| totalTokens += tokens | ||
| fmt.Fprintf(os.Stdout, "Using prompt file: %s (~%d tokens)\n", path, tokens) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should say "task" not "prompt"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to "Using task file:" in commit ad6de93.
token_counter.go
Outdated
| charCount := utf8.RuneCountInString(text) | ||
| // Approximate: 1 token ≈ 4 characters | ||
| tokens := charCount / 4 | ||
| if tokens == 0 && charCount > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the zero check. This will never happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the zero check in commit ad6de93.
…nnecessary zero check Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
|
@copilot Make the requested changes |
There was a problem hiding this comment.
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 token counting functionality to estimate the number of LLM tokens in processed files. The implementation uses a simple heuristic of approximately 4 characters per token.
- Adds
estimateTokens()function with UTF-8 character counting - Updates output messages to display token counts for persona, memory, and task files
- Adds total token count tracking and display
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| token_counter.go | Implements the token estimation function using a 4-char-per-token heuristic |
| token_counter_test.go | Adds unit tests for the token estimation function |
| main.go | Integrates token counting into file processing workflow with per-file and total counts |
| integration_test.go | Adds end-to-end test verifying token counting output |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if !strings.Contains(totalLine, "Total estimated tokens:") { | ||
| t.Errorf("Expected 'Total estimated tokens:' in output, got: %s", totalLine) | ||
| } |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 1356-1358 already verify that totalLine contains 'Total estimated tokens:' (since it's found by searching for that string in lines 1352-1354). The check on lines 1361-1363 is redundant and can be removed.
| if !strings.Contains(totalLine, "Total estimated tokens:") { | |
| t.Errorf("Expected 'Total estimated tokens:' in output, got: %s", totalLine) | |
| } |
Print estimated token count for each file added to context and total tokens used.
Implementation
utf8.RuneCountInString()Output Format
Files
token_counter.go: Estimation functiontoken_counter_test.go: Unit tests covering edge casesmain.go: Integration at persona/memory/task processing pointsintegration_test.go: End-to-end validationOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.