mirror of
https://github.com/yamadashy/repomix.git
synced 2025-06-11 00:25:54 +03:00
fix(cli): Use actual total tokens for percentage calculation in top files
User identified percentage calculation issue: - User noticed percentage was calculated against partial token sum (only top candidates) - User requested using actual total tokens from entire output instead - Assistant updated printTopFiles to accept totalTokens parameter - Now uses packResult.totalTokens for accurate percentage calculation - Fixed all function calls and tests to include the new parameter - Percentages now reflect actual proportion of each file to total output 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -64,7 +64,12 @@ export const runDefaultAction = async (
|
||||
logger.log('');
|
||||
|
||||
if (config.output.topFilesLength > 0) {
|
||||
printTopFiles(packResult.fileCharCounts, packResult.fileTokenCounts, config.output.topFilesLength);
|
||||
printTopFiles(
|
||||
packResult.fileCharCounts,
|
||||
packResult.fileTokenCounts,
|
||||
config.output.topFilesLength,
|
||||
packResult.totalTokens,
|
||||
);
|
||||
logger.log('');
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ export const printTopFiles = (
|
||||
fileCharCounts: Record<string, number>,
|
||||
fileTokenCounts: Record<string, number>,
|
||||
topFilesLength: number,
|
||||
totalTokens: number,
|
||||
) => {
|
||||
const topFilesLengthStrLen = topFilesLength.toString().length;
|
||||
logger.log(pc.white(`📈 Top ${topFilesLength} Files by Token Count:`));
|
||||
@@ -95,8 +96,7 @@ export const printTopFiles = (
|
||||
.sort((a, b) => b[1] - a[1])
|
||||
.slice(0, topFilesLength);
|
||||
|
||||
// Calculate total token count only from files with token counts
|
||||
const totalTokens = Object.values(fileTokenCounts).reduce((sum, count) => sum + count, 0);
|
||||
// Use the actual total tokens from the entire output
|
||||
|
||||
filesWithTokenCounts.forEach(([filePath, tokenCount], index) => {
|
||||
const charCount = fileCharCounts[filePath];
|
||||
|
||||
@@ -135,7 +135,7 @@ describe('cliPrint', () => {
|
||||
'README.md': 400,
|
||||
};
|
||||
|
||||
printTopFiles(fileCharCounts, fileTokenCounts, 2);
|
||||
printTopFiles(fileCharCounts, fileTokenCounts, 2, 60);
|
||||
|
||||
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('Top 2 Files'));
|
||||
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('README.md'));
|
||||
@@ -144,7 +144,7 @@ describe('cliPrint', () => {
|
||||
});
|
||||
|
||||
test('should handle empty file list', () => {
|
||||
printTopFiles({}, {}, 5);
|
||||
printTopFiles({}, {}, 5, 0);
|
||||
|
||||
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('Top 5 Files'));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user