🔖 Checkpoint: Edit /workspaces/claude-code-flow/src/cli/simple-commands/test-tokens.js

This commit is contained in:
rUv committed 2025-08-13 20:24:44 +00:00
1 parent 39e234a7e0
commit 8d0147324b
3 files changed
+104

No files matched your search

+1
View File
@@ -0,0 +1 @@
{"checkpoint": "task-20250813-202355", "task": "still not working ", "timestamp": "2025-08-13T20:23:56Z", "commit": "39e234a7e05090e3d23cb24ff317e20634d9d617", "github_release": "true"}
@@ -0,0 +1,8 @@
Timestamp,Session,Agent,Command,Input Tokens,Output Tokens,Total
SUMMARY
Total Input Tokens,0
Total Output Tokens,0
Total Tokens,0
BY AGENT TYPE
1 Timestamp,Session,Agent,Command,Input Tokens,Output Tokens,Total
2 SUMMARY
3 Total Input Tokens,0
4 Total Output Tokens,0
5 Total Tokens,0
6 BY AGENT TYPE
+95
View File
@@ -0,0 +1,95 @@
#!/usr/bin/env node
/**
* Test command to simulate token tracking
* This demonstrates how token tracking would work with real Claude API calls
*/
import { trackTokens } from './token-tracker.js';
import { printSuccess, printInfo } from '../utils.js';
export async function testTokensCommand(args, flags) {
console.log('\n🔬 TOKEN TRACKING TEST\n');
console.log('This simulates token usage from Claude API calls.');
console.log('In production, these values would come from actual API responses.\n');
// Simulate different agent types making API calls
const testScenarios = [
{
agentType: 'researcher',
command: 'swarm',
inputTokens: 1250,
outputTokens: 3420,
description: 'Research task on AI trends'
},
{
agentType: 'coder',
command: 'swarm',
inputTokens: 2100,
outputTokens: 5800,
description: 'Generate API implementation'
},
{
agentType: 'analyzer',
command: 'analysis',
inputTokens: 890,
outputTokens: 2150,
description: 'Code quality analysis'
},
{
agentType: 'coordinator',
command: 'hive-mind',
inputTokens: 650,
outputTokens: 1200,
description: 'Task coordination'
}
];
console.log('📊 Simulating token usage from multiple agents:\n');
for (const scenario of testScenarios) {
console.log(`🤖 ${scenario.agentType.toUpperCase()} Agent`);
console.log(` Task: ${scenario.description}`);
console.log(` Input: ${scenario.inputTokens.toLocaleString()} tokens`);
console.log(` Output: ${scenario.outputTokens.toLocaleString()} tokens`);
// Track the tokens
const result = await trackTokens({
sessionId: `test-session-${Date.now()}`,
agentType: scenario.agentType,
command: scenario.command,
inputTokens: scenario.inputTokens,
outputTokens: scenario.outputTokens,
metadata: {
description: scenario.description,
test: true
}
});
console.log(` ✅ Tracked! Grand total: ${result.grandTotal.toLocaleString()} tokens\n`);
}
// Calculate totals
const totalInput = testScenarios.reduce((sum, s) => sum + s.inputTokens, 0);
const totalOutput = testScenarios.reduce((sum, s) => sum + s.outputTokens, 0);
const totalTokens = totalInput + totalOutput;
// Calculate cost (Claude 3 Opus pricing)
const inputCost = (totalInput / 1000000) * 15.00;
const outputCost = (totalOutput / 1000000) * 75.00;
const totalCost = inputCost + outputCost;
console.log('📈 SESSION SUMMARY:');
console.log(` Total Input: ${totalInput.toLocaleString()} tokens`);
console.log(` Total Output: ${totalOutput.toLocaleString()} tokens`);
console.log(` Total Tokens: ${totalTokens.toLocaleString()} tokens`);
console.log(` Estimated Cost: $${totalCost.toFixed(4)}`);
printSuccess('\n✅ Test tokens tracked successfully!');
console.log('\n💡 Now run: ./claude-flow analysis token-usage --breakdown --cost-analysis');
console.log(' to see the tracked data in the analysis report.\n');
}
// CLI entry point
if (import.meta.url === `file://${process.argv[1]}`) {
testTokensCommand(process.argv.slice(2), {});
}