From 8d0147324b396671e48bd930671f47109ec4d2fa Mon Sep 17 00:00:00 2001 From: rUv Date: Wed, 13 Aug 2025 20:24:44 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20Checkpoint:=20Edit=20/workspaces?= =?UTF-8?q?/claude-code-flow/src/cli/simple-commands/test-tokens.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/checkpoints/task-1755116636.json | 1 + .../token-usage-1755116676493.csv | 8 ++ src/cli/simple-commands/test-tokens.js | 95 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 .claude/checkpoints/task-1755116636.json create mode 100644 analysis-reports/token-usage-1755116676493.csv create mode 100644 src/cli/simple-commands/test-tokens.js diff --git a/.claude/checkpoints/task-1755116636.json b/.claude/checkpoints/task-1755116636.json new file mode 100644 index 0000000000..01742489e8 --- /dev/null +++ b/.claude/checkpoints/task-1755116636.json @@ -0,0 +1 @@ +{"checkpoint": "task-20250813-202355", "task": "still not working ", "timestamp": "2025-08-13T20:23:56Z", "commit": "39e234a7e05090e3d23cb24ff317e20634d9d617", "github_release": "true"} diff --git a/analysis-reports/token-usage-1755116676493.csv b/analysis-reports/token-usage-1755116676493.csv new file mode 100644 index 0000000000..9d4f2b6113 --- /dev/null +++ b/analysis-reports/token-usage-1755116676493.csv @@ -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 diff --git a/src/cli/simple-commands/test-tokens.js b/src/cli/simple-commands/test-tokens.js new file mode 100644 index 0000000000..e92cf6bd93 --- /dev/null +++ b/src/cli/simple-commands/test-tokens.js @@ -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), {}); +} \ No newline at end of file