claude-flow-novice 2.0.3 ā 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/cli/commands/guidance.js +487 -668
- package/dist/src/cli/commands/index-validate.js +18 -29
- package/dist/src/cli/commands/mcp-troubleshoot.js +230 -282
- package/dist/src/cli/commands/neural-goal-init.js +92 -125
- package/dist/src/cli/commands/swarm-exec.js +317 -393
- package/dist/src/cli/commands/swarm.js +1 -1
- package/dist/src/cli/commands/validate-framework.js +983 -1100
- package/dist/src/cli/commands/validate.js +144 -223
- package/dist/src/cli/simple-commands/__tests__/agent.test.js +265 -277
- package/dist/src/cli/simple-commands/__tests__/memory.test.js +6 -7
- package/dist/src/cli/simple-commands/__tests__/swarm.test.js +373 -356
- package/dist/src/cli/simple-commands/__tests__/task.test.js +6 -7
- package/dist/src/cli/simple-commands/agent.js +157 -193
- package/dist/src/cli/simple-commands/analysis.js +336 -446
- package/dist/src/cli/simple-commands/automation-executor.js +1095 -1339
- package/dist/src/cli/simple-commands/automation.js +481 -469
- package/dist/src/cli/simple-commands/batch-manager.js +261 -313
- package/dist/src/cli/simple-commands/claude-telemetry.js +241 -267
- package/dist/src/cli/simple-commands/claude-track.js +68 -90
- package/dist/src/cli/simple-commands/concurrent-display.js +266 -320
- package/dist/src/cli/simple-commands/config.js +245 -290
- package/dist/src/cli/simple-commands/coordination.js +182 -234
- package/dist/src/cli/simple-commands/enhanced-ui-views.js +812 -615
- package/dist/src/cli/simple-commands/enhanced-webui-complete.js +922 -981
- package/dist/src/cli/simple-commands/fix-hook-variables.js +274 -294
- package/dist/src/cli/simple-commands/github/gh-coordinator.js +378 -457
- package/dist/src/cli/simple-commands/github/github-api.js +535 -574
- package/dist/src/cli/simple-commands/github/init.js +276 -303
- package/dist/src/cli/simple-commands/github.js +222 -247
- package/dist/src/cli/simple-commands/goal.js +51 -63
- package/dist/src/cli/simple-commands/hive-mind/auto-save-middleware.js +208 -278
- package/dist/src/cli/simple-commands/hive-mind/communication.js +601 -696
- package/dist/src/cli/simple-commands/hive-mind/core.js +907 -979
- package/dist/src/cli/simple-commands/hive-mind/db-optimizer.js +406 -655
- package/dist/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1125 -1245
- package/dist/src/cli/simple-commands/hive-mind/memory.js +854 -1090
- package/dist/src/cli/simple-commands/hive-mind/performance-optimizer.js +459 -574
- package/dist/src/cli/simple-commands/hive-mind/performance-test.js +263 -347
- package/dist/src/cli/simple-commands/hive-mind/queen.js +727 -768
- package/dist/src/cli/simple-commands/hive-mind/session-manager.js +745 -1049
- package/dist/src/cli/simple-commands/hive-mind-optimize.js +227 -283
- package/dist/src/cli/simple-commands/hive-mind-wizard.js +174 -217
- package/dist/src/cli/simple-commands/hive-mind.js +1842 -2283
- package/dist/src/cli/simple-commands/hive.js +90 -79
- package/dist/src/cli/simple-commands/hook-safety.js +431 -521
- package/dist/src/cli/simple-commands/hooks/session-start-soul.js +203 -254
- package/dist/src/cli/simple-commands/hooks.js +1064 -1204
- package/dist/src/cli/simple-commands/init/agent-copier.js +294 -319
- package/dist/src/cli/simple-commands/init/batch-init.js +496 -562
- package/dist/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +13 -19
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +13 -19
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +61 -88
- package/dist/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +125 -150
- package/dist/src/cli/simple-commands/init/claude-commands/slash-commands.js +42 -49
- package/dist/src/cli/simple-commands/init/claude-commands/sparc-commands.js +43 -61
- package/dist/src/cli/simple-commands/init/copy-revised-templates.js +141 -147
- package/dist/src/cli/simple-commands/init/executable-wrapper.js +31 -44
- package/dist/src/cli/simple-commands/init/gitignore-updater.js +64 -90
- package/dist/src/cli/simple-commands/init/help.js +104 -107
- package/dist/src/cli/simple-commands/init/hive-mind-init.js +509 -528
- package/dist/src/cli/simple-commands/init/index.js +1510 -1759
- package/dist/src/cli/simple-commands/init/performance-monitor.js +234 -317
- package/dist/src/cli/simple-commands/init/rollback/backup-manager.js +441 -504
- package/dist/src/cli/simple-commands/init/rollback/index.js +289 -364
- package/dist/src/cli/simple-commands/init/rollback/recovery-manager.js +652 -728
- package/dist/src/cli/simple-commands/init/rollback/rollback-executor.js +416 -481
- package/dist/src/cli/simple-commands/init/rollback/state-tracker.js +369 -448
- package/dist/src/cli/simple-commands/init/sparc/roo-readme.js +1 -2
- package/dist/src/cli/simple-commands/init/sparc/roomodes-config.js +122 -99
- package/dist/src/cli/simple-commands/init/sparc/workflows.js +32 -37
- package/dist/src/cli/simple-commands/init/sparc-structure.js +55 -62
- package/dist/src/cli/simple-commands/init/template-copier.js +421 -533
- package/dist/src/cli/simple-commands/init/templates/coordination-md.js +3 -6
- package/dist/src/cli/simple-commands/init/templates/enhanced-templates.js +344 -318
- package/dist/src/cli/simple-commands/init/templates/github-safe-enhanced.js +173 -218
- package/dist/src/cli/simple-commands/init/templates/github-safe.js +65 -75
- package/dist/src/cli/simple-commands/init/templates/memory-bank-md.js +3 -6
- package/dist/src/cli/simple-commands/init/templates/readme-files.js +2 -4
- package/dist/src/cli/simple-commands/init/templates/safe-hook-patterns.js +187 -230
- package/dist/src/cli/simple-commands/init/templates/sparc-modes.js +53 -80
- package/dist/src/cli/simple-commands/init/templates/verification-claude-md.js +101 -85
- package/dist/src/cli/simple-commands/init/validation/config-validator.js +283 -330
- package/dist/src/cli/simple-commands/init/validation/health-checker.js +495 -561
- package/dist/src/cli/simple-commands/init/validation/index.js +302 -358
- package/dist/src/cli/simple-commands/init/validation/mode-validator.js +308 -359
- package/dist/src/cli/simple-commands/init/validation/post-init-validator.js +389 -366
- package/dist/src/cli/simple-commands/init/validation/pre-init-validator.js +270 -268
- package/dist/src/cli/simple-commands/init/validation/test-runner.js +427 -447
- package/dist/src/cli/simple-commands/init.js +1 -2
- package/dist/src/cli/simple-commands/mcp-health.js +131 -158
- package/dist/src/cli/simple-commands/mcp-integration-layer.js +533 -634
- package/dist/src/cli/simple-commands/mcp.js +345 -400
- package/dist/src/cli/simple-commands/memory-consolidation.js +426 -537
- package/dist/src/cli/simple-commands/memory.js +247 -311
- package/dist/src/cli/simple-commands/migrate-hooks.js +39 -46
- package/dist/src/cli/simple-commands/monitor.js +294 -363
- package/dist/src/cli/simple-commands/neural.js +51 -65
- package/dist/src/cli/simple-commands/pair-autofix-only.js +538 -662
- package/dist/src/cli/simple-commands/pair-basic.js +528 -656
- package/dist/src/cli/simple-commands/pair-old.js +430 -543
- package/dist/src/cli/simple-commands/pair-working.js +615 -751
- package/dist/src/cli/simple-commands/pair.js +615 -751
- package/dist/src/cli/simple-commands/performance-hooks.js +83 -111
- package/dist/src/cli/simple-commands/performance-metrics.js +348 -433
- package/dist/src/cli/simple-commands/process-ui-enhanced.js +708 -787
- package/dist/src/cli/simple-commands/process-ui.js +230 -254
- package/dist/src/cli/simple-commands/realtime-update-system.js +525 -611
- package/dist/src/cli/simple-commands/sparc/architecture.js +1704 -1530
- package/dist/src/cli/simple-commands/sparc/commands.js +438 -516
- package/dist/src/cli/simple-commands/sparc/completion.js +1224 -1481
- package/dist/src/cli/simple-commands/sparc/coordinator.js +913 -978
- package/dist/src/cli/simple-commands/sparc/index.js +241 -298
- package/dist/src/cli/simple-commands/sparc/phase-base.js +314 -390
- package/dist/src/cli/simple-commands/sparc/pseudocode.js +965 -869
- package/dist/src/cli/simple-commands/sparc/refinement.js +980 -1273
- package/dist/src/cli/simple-commands/sparc/specification.js +559 -645
- package/dist/src/cli/simple-commands/sparc-modes/architect.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/ask.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/code.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/debug.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/devops.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/docs-writer.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/generic.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/index.js +47 -55
- package/dist/src/cli/simple-commands/sparc-modes/integration.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/mcp.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/monitoring.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/optimization.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/security-review.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/supabase-admin.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/swarm.js +101 -87
- package/dist/src/cli/simple-commands/sparc-modes/tdd.js +1 -1
- package/dist/src/cli/simple-commands/sparc-modes/tutorial.js +1 -1
- package/dist/src/cli/simple-commands/sparc.js +465 -493
- package/dist/src/cli/simple-commands/start-ui.js +108 -132
- package/dist/src/cli/simple-commands/start-wrapper.js +240 -268
- package/dist/src/cli/simple-commands/start.js +1 -1
- package/dist/src/cli/simple-commands/status.js +254 -275
- package/dist/src/cli/simple-commands/stream-chain-clean.js +128 -171
- package/dist/src/cli/simple-commands/stream-chain-fixed.js +61 -82
- package/dist/src/cli/simple-commands/stream-chain-real.js +267 -331
- package/dist/src/cli/simple-commands/stream-chain-working.js +211 -263
- package/dist/src/cli/simple-commands/stream-chain.js +260 -318
- package/dist/src/cli/simple-commands/stream-processor.js +290 -315
- package/dist/src/cli/simple-commands/swarm-executor.js +189 -222
- package/dist/src/cli/simple-commands/swarm-metrics-integration.js +208 -300
- package/dist/src/cli/simple-commands/swarm-ui.js +623 -703
- package/dist/src/cli/simple-commands/swarm-webui-integration.js +258 -286
- package/dist/src/cli/simple-commands/swarm.js +887 -1082
- package/dist/src/cli/simple-commands/task.js +161 -206
- package/dist/src/cli/simple-commands/timestamp-fix.js +59 -89
- package/dist/src/cli/simple-commands/token-tracker.js +258 -316
- package/dist/src/cli/simple-commands/tool-execution-framework.js +433 -519
- package/dist/src/cli/simple-commands/train-and-stream.js +275 -331
- package/dist/src/cli/simple-commands/training-pipeline.js +619 -725
- package/dist/src/cli/simple-commands/training.js +170 -227
- package/dist/src/cli/simple-commands/verification-hooks.js +261 -284
- package/dist/src/cli/simple-commands/verification-integration.js +389 -417
- package/dist/src/cli/simple-commands/verification-training-integration.js +486 -606
- package/dist/src/cli/simple-commands/verification.js +493 -513
- package/dist/src/cli/simple-commands/web-server.js +766 -836
- package/dist/src/cli/simple-commands/webui-validator.js +106 -124
- package/dist/src/coordination/event-bus/demo-wasm-integration.js +212 -251
- package/dist/src/coordination/event-bus/qe-event-bus.js +608 -748
- package/dist/src/coordination/event-bus/qe-event-bus.test.js +379 -454
- package/dist/src/coordination/iteration-tracker.js +363 -454
- package/dist/src/enterprise/analytics-manager.js +1135 -0
- package/dist/src/enterprise/audit-manager.js +1115 -0
- package/dist/src/enterprise/cloud-manager.js +891 -0
- package/dist/src/enterprise/deployment-manager.js +966 -0
- package/dist/src/enterprise/index.js +6 -0
- package/dist/src/enterprise/project-manager.js +584 -0
- package/dist/src/enterprise/security-manager.js +991 -0
- package/dist/src/index.js +1 -1
- package/dist/src/mcp/DEPRECATED.js +46 -60
- package/dist/src/mcp/fixes/mcp-error-fixes.js +115 -134
- package/dist/src/mcp/implementations/agent-tracker.js +114 -128
- package/dist/src/mcp/implementations/daa-tools.js +292 -350
- package/dist/src/mcp/implementations/workflow-tools.js +329 -361
- package/dist/src/mcp/mcp-config-manager.js +1183 -1331
- package/dist/src/mcp/mcp-server-novice-simplified.js +11 -17
- package/dist/src/mcp/mcp-server-novice.js +11 -17
- package/dist/src/mcp/mcp-server-sdk.js +11 -17
- package/dist/src/mcp/mcp-server.js +1620 -1484
- package/dist/src/mcp/ruv-swarm-wrapper.js +209 -239
- package/dist/src/memory/advanced-serializer.js +609 -589
- package/dist/src/memory/enhanced-examples.js +220 -305
- package/dist/src/memory/enhanced-memory.js +295 -336
- package/dist/src/memory/enhanced-session-serializer.js +408 -492
- package/dist/src/memory/fallback-memory-system.js +900 -1021
- package/dist/src/memory/fallback-store.js +93 -131
- package/dist/src/memory/high-performance-serialization.js +592 -730
- package/dist/src/memory/in-memory-store.js +161 -213
- package/dist/src/memory/index.js +123 -157
- package/dist/src/memory/lock-free-structures.js +578 -764
- package/dist/src/memory/memory-mapped-persistence.js +585 -766
- package/dist/src/memory/memory-pressure-manager.js +569 -707
- package/dist/src/memory/migration.js +358 -445
- package/dist/src/memory/shared-memory.js +641 -768
- package/dist/src/memory/sqlite-store.js +245 -325
- package/dist/src/memory/sqlite-wrapper.js +122 -151
- package/dist/src/memory/swarm-memory.js +470 -603
- package/dist/src/memory/test-example.js +126 -134
- package/dist/src/memory/ultra-fast-memory-store.js +622 -821
- package/dist/src/memory/unified-memory-manager.js +356 -437
- package/dist/src/migration/index.js +92 -0
- package/dist/src/migration/logger.js +121 -0
- package/dist/src/migration/migration-analyzer.js +268 -0
- package/dist/src/migration/migration-runner.js +522 -0
- package/dist/src/migration/migration-validator.js +285 -0
- package/dist/src/migration/progress-reporter.js +150 -0
- package/dist/src/migration/rollback-manager.js +321 -0
- package/dist/src/migration/tests/migration-system.test.js +7 -0
- package/dist/src/migration/types.js +3 -0
- package/dist/src/swarm/CodeRefactoringSwarm.js +777 -952
- package/dist/src/swarm/__tests__/integration.test.js +227 -0
- package/dist/src/swarm/__tests__/prompt-copier.test.js +344 -0
- package/dist/src/swarm/advanced-orchestrator.js +1095 -0
- package/dist/src/swarm/claude-code-interface.js +961 -0
- package/dist/src/swarm/claude-flow-executor.js +229 -0
- package/dist/src/swarm/consensus-coordinator.js +475 -0
- package/dist/src/swarm/coordinator.js +2993 -0
- package/dist/src/swarm/direct-executor.js +1180 -0
- package/dist/src/swarm/error-recovery/advanced-error-detection.js +691 -0
- package/dist/src/swarm/error-recovery/automated-recovery-workflows.js +998 -0
- package/dist/src/swarm/error-recovery/error-recovery-coordinator.js +1197 -0
- package/dist/src/swarm/error-recovery/recovery-monitoring.js +772 -0
- package/dist/src/swarm/error-recovery/resilience-architecture.js +714 -0
- package/dist/src/swarm/error-recovery/self-healing-mechanisms.js +1319 -0
- package/dist/src/swarm/error-recovery/test-error-recovery-effectiveness.js +808 -0
- package/dist/src/swarm/executor-v2.js +322 -0
- package/dist/src/swarm/executor.js +815 -0
- package/dist/src/swarm/hive-mind-integration.js +703 -0
- package/dist/src/swarm/index.js +41 -0
- package/dist/src/swarm/json-output-aggregator.js +267 -0
- package/dist/src/swarm/large-scale-coordinator.js +542 -0
- package/dist/src/swarm/mcp-integration-wrapper.js +628 -0
- package/dist/src/swarm/memory.js +1117 -0
- package/dist/src/swarm/optimizations/__tests__/optimization.test.js +348 -0
- package/dist/src/swarm/optimizations/async-file-manager.js +285 -0
- package/dist/src/swarm/optimizations/circular-buffer.js +162 -0
- package/dist/src/swarm/optimizations/connection-pool.js +244 -0
- package/dist/src/swarm/optimizations/index.js +28 -0
- package/dist/src/swarm/optimizations/optimized-executor.js +320 -0
- package/dist/src/swarm/optimizations/ttl-map.js +234 -0
- package/dist/src/swarm/prompt-cli.js +200 -0
- package/dist/src/swarm/prompt-copier-enhanced.js +202 -0
- package/dist/src/swarm/prompt-copier.js +381 -0
- package/dist/src/swarm/prompt-manager.js +295 -0
- package/dist/src/swarm/prompt-utils.js +310 -0
- package/dist/src/swarm/result-aggregator.js +718 -0
- package/dist/src/swarm/sparc-executor.js +1568 -0
- package/dist/src/swarm/strategies/auto.js +758 -0
- package/dist/src/swarm/strategies/base.js +128 -0
- package/dist/src/swarm/strategies/research.js +914 -0
- package/dist/src/swarm/strategies/strategy-metrics-patch.js +2 -0
- package/dist/src/swarm/types.js +52 -0
- package/dist/src/swarm/workers/copy-worker.js +56 -0
- package/dist/src/utils/__tests__/github-cli-safety-wrapper.test.js +332 -400
- package/dist/src/utils/github-cli-safe.js +56 -64
- package/dist/src/utils/github-cli-safety-wrapper.js +451 -546
- package/dist/src/utils/npx-isolated-cache.js +104 -119
- package/dist/src/utils/preference-manager.js +622 -652
- package/dist/src/utils/timezone-utils.js +86 -105
- package/dist/src/validators/epic-config-schema.js +214 -0
- package/dist/src/validators/index.js +10 -0
- package/dist/src/validators/swarm-init-validator.js +259 -0
- package/dist/src/validators/todowrite-batching-validator.js +215 -0
- package/dist/src/validators/todowrite-integration.js +187 -0
- package/package.json +2 -2
|
@@ -1,372 +1,283 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from
|
|
8
|
-
import { promises as fs } from 'fs';
|
|
9
|
-
import path from 'path';
|
|
10
|
-
import { fileURLToPath } from 'url';
|
|
11
|
-
import { dirname } from 'path';
|
|
12
|
-
import {
|
|
13
|
-
initializeMetrics,
|
|
14
|
-
getPerformanceReport,
|
|
15
|
-
getBottleneckAnalysis,
|
|
16
|
-
exportMetrics,
|
|
17
|
-
} from './performance-metrics.js';
|
|
18
|
-
import {
|
|
19
|
-
getRealTokenUsage,
|
|
20
|
-
calculateCost,
|
|
21
|
-
generateOptimizationSuggestions,
|
|
22
|
-
generateTokenUsageReport,
|
|
23
|
-
getAgentIcon,
|
|
24
|
-
trackTokens,
|
|
25
|
-
} from './token-tracker.js';
|
|
26
|
-
|
|
1
|
+
import { printSuccess, printError, printWarning } from "../utils.js";
|
|
2
|
+
import { promises as fs } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { dirname } from "path";
|
|
6
|
+
import { initializeMetrics, getPerformanceReport, getBottleneckAnalysis, exportMetrics } from "./performance-metrics.js";
|
|
7
|
+
import { getRealTokenUsage, calculateCost, generateOptimizationSuggestions, generateTokenUsageReport, getAgentIcon } from "./token-tracker.js";
|
|
27
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
28
9
|
const __dirname = dirname(__filename);
|
|
29
|
-
|
|
30
10
|
async function setupTelemetry() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
11
|
+
console.log(`\nš§ TELEMETRY SETUP FOR TOKEN TRACKING\n`);
|
|
12
|
+
console.log(`${'ā'.repeat(60)}\n`);
|
|
13
|
+
// Check current status
|
|
14
|
+
const currentValue = process.env.CLAUDE_CODE_ENABLE_TELEMETRY;
|
|
15
|
+
const isEnabled = currentValue === '1';
|
|
16
|
+
console.log(`š Current Status: ${isEnabled ? 'ā
ENABLED' : 'ā DISABLED'}`);
|
|
17
|
+
console.log(` Environment Variable: CLAUDE_CODE_ENABLE_TELEMETRY=${currentValue || 'not set'}\n`);
|
|
18
|
+
if (!isEnabled) {
|
|
19
|
+
// Set the environment variable for current session
|
|
20
|
+
process.env.CLAUDE_CODE_ENABLE_TELEMETRY = '1';
|
|
21
|
+
console.log(`ā
Telemetry ENABLED for this session!\n`);
|
|
22
|
+
// Create or update .env file
|
|
23
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
24
|
+
let envContent = '';
|
|
25
|
+
try {
|
|
26
|
+
envContent = await fs.readFile(envPath, 'utf-8');
|
|
27
|
+
} catch (err) {
|
|
28
|
+
// .env doesn't exist yet
|
|
29
|
+
}
|
|
30
|
+
// Check if telemetry is already in .env
|
|
31
|
+
if (!envContent.includes('CLAUDE_CODE_ENABLE_TELEMETRY')) {
|
|
32
|
+
envContent += `\n# Enable token tracking for Claude API calls\nCLAUDE_CODE_ENABLE_TELEMETRY=1\n`;
|
|
33
|
+
try {
|
|
34
|
+
await fs.writeFile(envPath, envContent);
|
|
35
|
+
console.log(`š Updated .env file with telemetry setting`);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.log(`ā ļø Could not update .env file: ${err.message}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Also add to shell profile for persistence
|
|
41
|
+
console.log(`\nš To make this permanent, add to your shell profile:`);
|
|
42
|
+
console.log(` ${'-'.repeat(50)}`);
|
|
43
|
+
console.log(` echo 'export CLAUDE_CODE_ENABLE_TELEMETRY=1' >> ~/.bashrc`);
|
|
44
|
+
console.log(` ${'-'.repeat(50)}\n`);
|
|
45
|
+
}
|
|
46
|
+
// Initialize token tracking directory
|
|
47
|
+
const metricsDir = path.join(process.cwd(), '.claude-flow', 'metrics');
|
|
53
48
|
try {
|
|
54
|
-
|
|
49
|
+
await fs.mkdir(metricsDir, {
|
|
50
|
+
recursive: true
|
|
51
|
+
});
|
|
52
|
+
console.log(`š Token tracking directory: ${metricsDir}`);
|
|
55
53
|
} catch (err) {
|
|
56
|
-
|
|
54
|
+
// Directory already exists
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
console.log(
|
|
66
|
-
|
|
67
|
-
console.log(
|
|
68
|
-
}
|
|
56
|
+
// Check for existing token data
|
|
57
|
+
const tokenFile = path.join(metricsDir, 'token-usage.json');
|
|
58
|
+
try {
|
|
59
|
+
const data = await fs.readFile(tokenFile, 'utf-8');
|
|
60
|
+
const tokenData = JSON.parse(data);
|
|
61
|
+
console.log(`\nš Existing token data found:`);
|
|
62
|
+
console.log(` ⢠Total tokens tracked: ${tokenData.totals?.total || 0}`);
|
|
63
|
+
console.log(` ⢠Sessions recorded: ${Object.keys(tokenData.sessions || {}).length}`);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.log(`\nš No existing token data (will be created on first use)`);
|
|
69
66
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
console.log(
|
|
73
|
-
console.log(`
|
|
74
|
-
console.log(
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Initialize token tracking directory
|
|
79
|
-
const metricsDir = path.join(process.cwd(), '.claude-flow', 'metrics');
|
|
80
|
-
try {
|
|
81
|
-
await fs.mkdir(metricsDir, { recursive: true });
|
|
82
|
-
console.log(`š Token tracking directory: ${metricsDir}`);
|
|
83
|
-
} catch (err) {
|
|
84
|
-
// Directory already exists
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Check for existing token data
|
|
88
|
-
const tokenFile = path.join(metricsDir, 'token-usage.json');
|
|
89
|
-
try {
|
|
90
|
-
const data = await fs.readFile(tokenFile, 'utf-8');
|
|
91
|
-
const tokenData = JSON.parse(data);
|
|
92
|
-
console.log(`\nš Existing token data found:`);
|
|
93
|
-
console.log(` ⢠Total tokens tracked: ${tokenData.totals?.total || 0}`);
|
|
94
|
-
console.log(` ⢠Sessions recorded: ${Object.keys(tokenData.sessions || {}).length}`);
|
|
95
|
-
} catch (err) {
|
|
96
|
-
console.log(`\nš No existing token data (will be created on first use)`);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
console.log(`\nš NEXT STEPS:`);
|
|
100
|
-
console.log(` 1. Run Claude commands with --claude flag`);
|
|
101
|
-
console.log(` 2. Example: ./claude-flow-novice swarm "analyze code" --claude`);
|
|
102
|
-
console.log(` 3. Check usage: ./claude-flow-novice analysis token-usage --breakdown`);
|
|
103
|
-
|
|
104
|
-
console.log(`\n${'ā'.repeat(60)}`);
|
|
105
|
-
printSuccess(`Telemetry setup complete!`);
|
|
67
|
+
console.log(`\nš NEXT STEPS:`);
|
|
68
|
+
console.log(` 1. Run Claude commands with --claude flag`);
|
|
69
|
+
console.log(` 2. Example: ./claude-flow-novice swarm "analyze code" --claude`);
|
|
70
|
+
console.log(` 3. Check usage: ./claude-flow-novice analysis token-usage --breakdown`);
|
|
71
|
+
console.log(`\n${'ā'.repeat(60)}`);
|
|
72
|
+
printSuccess(`Telemetry setup complete!`);
|
|
106
73
|
}
|
|
107
|
-
|
|
108
74
|
export async function analysisAction(subArgs, flags) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (options.help || options.h || !subcommand) {
|
|
113
|
-
showAnalysisHelp();
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Handle telemetry setup
|
|
118
|
-
if (subcommand === 'setup-telemetry' || options['enable-telemetry']) {
|
|
119
|
-
await setupTelemetry();
|
|
120
|
-
if (subcommand === 'setup-telemetry') return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
switch (subcommand) {
|
|
125
|
-
case 'bottleneck-detect':
|
|
126
|
-
await bottleneckDetectCommand(subArgs, flags);
|
|
127
|
-
break;
|
|
128
|
-
case 'performance-report':
|
|
129
|
-
await performanceReportCommand(subArgs, flags);
|
|
130
|
-
break;
|
|
131
|
-
case 'token-usage':
|
|
132
|
-
await tokenUsageCommand(subArgs, flags);
|
|
133
|
-
break;
|
|
134
|
-
case 'claude-monitor':
|
|
135
|
-
await claudeMonitorCommand(subArgs, flags);
|
|
136
|
-
break;
|
|
137
|
-
case 'claude-cost':
|
|
138
|
-
await claudeCostCommand(subArgs, flags);
|
|
139
|
-
break;
|
|
140
|
-
default:
|
|
141
|
-
printError(`Unknown analysis command: ${subcommand}`);
|
|
75
|
+
const subcommand = subArgs[0];
|
|
76
|
+
const options = flags;
|
|
77
|
+
if (options.help || options.h || !subcommand) {
|
|
142
78
|
showAnalysisHelp();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Handle telemetry setup
|
|
82
|
+
if (subcommand === 'setup-telemetry' || options['enable-telemetry']) {
|
|
83
|
+
await setupTelemetry();
|
|
84
|
+
if (subcommand === 'setup-telemetry') return;
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
switch(subcommand){
|
|
88
|
+
case 'bottleneck-detect':
|
|
89
|
+
await bottleneckDetectCommand(subArgs, flags);
|
|
90
|
+
break;
|
|
91
|
+
case 'performance-report':
|
|
92
|
+
await performanceReportCommand(subArgs, flags);
|
|
93
|
+
break;
|
|
94
|
+
case 'token-usage':
|
|
95
|
+
await tokenUsageCommand(subArgs, flags);
|
|
96
|
+
break;
|
|
97
|
+
case 'claude-monitor':
|
|
98
|
+
await claudeMonitorCommand(subArgs, flags);
|
|
99
|
+
break;
|
|
100
|
+
case 'claude-cost':
|
|
101
|
+
await claudeCostCommand(subArgs, flags);
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
printError(`Unknown analysis command: ${subcommand}`);
|
|
105
|
+
showAnalysisHelp();
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
printError(`Analysis command failed: ${err.message}`);
|
|
143
109
|
}
|
|
144
|
-
} catch (err) {
|
|
145
|
-
printError(`Analysis command failed: ${err.message}`);
|
|
146
|
-
}
|
|
147
110
|
}
|
|
148
|
-
|
|
149
111
|
async function bottleneckDetectCommand(subArgs, flags) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
console.log(
|
|
173
|
-
` ${icon} ${bottleneck.severity.toUpperCase()}: ${bottleneck.component} (${bottleneck.metric})`,
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
// Show details if available
|
|
177
|
-
if (bottleneck.details) {
|
|
178
|
-
bottleneck.details.forEach((detail) => {
|
|
179
|
-
console.log(` - ${detail.type || detail.id}: ${detail.duration}s`);
|
|
112
|
+
const options = flags;
|
|
113
|
+
const scope = options.scope || 'system';
|
|
114
|
+
const target = options.target || 'all';
|
|
115
|
+
console.log(`š Detecting performance bottlenecks...`);
|
|
116
|
+
console.log(`š Scope: ${scope}`);
|
|
117
|
+
console.log(`šÆ Target: ${target}`);
|
|
118
|
+
try {
|
|
119
|
+
// Initialize metrics system without starting monitoring
|
|
120
|
+
await initializeMetrics(false);
|
|
121
|
+
// Get real bottleneck analysis
|
|
122
|
+
const analysis = await getBottleneckAnalysis(scope, target);
|
|
123
|
+
printSuccess(`ā
Bottleneck analysis completed`);
|
|
124
|
+
console.log(`\nš BOTTLENECK ANALYSIS RESULTS:`);
|
|
125
|
+
analysis.bottlenecks.forEach((bottleneck)=>{
|
|
126
|
+
const icon = bottleneck.severity === 'critical' ? 'š“' : bottleneck.severity === 'warning' ? 'š”' : 'š¢';
|
|
127
|
+
console.log(` ${icon} ${bottleneck.severity.toUpperCase()}: ${bottleneck.component} (${bottleneck.metric})`);
|
|
128
|
+
// Show details if available
|
|
129
|
+
if (bottleneck.details) {
|
|
130
|
+
bottleneck.details.forEach((detail)=>{
|
|
131
|
+
console.log(` - ${detail.type || detail.id}: ${detail.duration}s`);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
180
134
|
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
console.log(
|
|
188
|
-
|
|
135
|
+
if (analysis.recommendations.length > 0) {
|
|
136
|
+
console.log(`\nš” RECOMMENDATIONS:`);
|
|
137
|
+
analysis.recommendations.forEach((rec)=>{
|
|
138
|
+
console.log(` ⢠${rec}`);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
console.log(`\nš PERFORMANCE METRICS:`);
|
|
142
|
+
console.log(` ⢠Analysis duration: ${analysis.analysisDuration.toFixed(2)}ms`);
|
|
143
|
+
console.log(` ⢠Confidence score: ${(analysis.confidenceScore * 100).toFixed(0)}%`);
|
|
144
|
+
console.log(` ⢠Issues detected: ${analysis.issuesDetected}`);
|
|
145
|
+
// Save detailed report
|
|
146
|
+
const reportPath = path.join(process.cwd(), 'analysis-reports', `bottleneck-${Date.now()}.json`);
|
|
147
|
+
await fs.mkdir(path.dirname(reportPath), {
|
|
148
|
+
recursive: true
|
|
149
|
+
});
|
|
150
|
+
await fs.writeFile(reportPath, JSON.stringify(analysis, null, 2));
|
|
151
|
+
console.log(`\nš Detailed report saved to: ${reportPath}`);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
printError(`Bottleneck analysis failed: ${err.message}`);
|
|
154
|
+
console.log('\nFalling back to simulated analysis...');
|
|
155
|
+
// Fallback to simulated data
|
|
156
|
+
console.log(`\nš BOTTLENECK ANALYSIS RESULTS (SIMULATED):`);
|
|
157
|
+
console.log(` š“ CRITICAL: Memory usage in agent spawn process (85% utilization)`);
|
|
158
|
+
console.log(` š” WARNING: Task queue processing (12s avg)`);
|
|
159
|
+
console.log(` š¢ GOOD: Neural training pipeline (optimal)`);
|
|
160
|
+
console.log(` š¢ GOOD: Swarm coordination latency (within limits)`);
|
|
189
161
|
}
|
|
190
|
-
|
|
191
|
-
console.log(`\nš PERFORMANCE METRICS:`);
|
|
192
|
-
console.log(` ⢠Analysis duration: ${analysis.analysisDuration.toFixed(2)}ms`);
|
|
193
|
-
console.log(` ⢠Confidence score: ${(analysis.confidenceScore * 100).toFixed(0)}%`);
|
|
194
|
-
console.log(` ⢠Issues detected: ${analysis.issuesDetected}`);
|
|
195
|
-
|
|
196
|
-
// Save detailed report
|
|
197
|
-
const reportPath = path.join(
|
|
198
|
-
process.cwd(),
|
|
199
|
-
'analysis-reports',
|
|
200
|
-
`bottleneck-${Date.now()}.json`,
|
|
201
|
-
);
|
|
202
|
-
await fs.mkdir(path.dirname(reportPath), { recursive: true });
|
|
203
|
-
await fs.writeFile(reportPath, JSON.stringify(analysis, null, 2));
|
|
204
|
-
|
|
205
|
-
console.log(`\nš Detailed report saved to: ${reportPath}`);
|
|
206
|
-
} catch (err) {
|
|
207
|
-
printError(`Bottleneck analysis failed: ${err.message}`);
|
|
208
|
-
console.log('\nFalling back to simulated analysis...');
|
|
209
|
-
|
|
210
|
-
// Fallback to simulated data
|
|
211
|
-
console.log(`\nš BOTTLENECK ANALYSIS RESULTS (SIMULATED):`);
|
|
212
|
-
console.log(` š“ CRITICAL: Memory usage in agent spawn process (85% utilization)`);
|
|
213
|
-
console.log(` š” WARNING: Task queue processing (12s avg)`);
|
|
214
|
-
console.log(` š¢ GOOD: Neural training pipeline (optimal)`);
|
|
215
|
-
console.log(` š¢ GOOD: Swarm coordination latency (within limits)`);
|
|
216
|
-
}
|
|
217
162
|
}
|
|
218
|
-
|
|
219
163
|
async function performanceReportCommand(subArgs, flags) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
console.log(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
console.log(
|
|
274
|
-
|
|
275
|
-
);
|
|
276
|
-
|
|
164
|
+
const options = flags;
|
|
165
|
+
const timeframe = options.timeframe || '24h';
|
|
166
|
+
const format = options.format || 'summary';
|
|
167
|
+
console.log(`š Generating performance report...`);
|
|
168
|
+
console.log(`ā° Timeframe: ${timeframe}`);
|
|
169
|
+
console.log(`š Format: ${format}`);
|
|
170
|
+
try {
|
|
171
|
+
// Initialize metrics system without starting monitoring
|
|
172
|
+
await initializeMetrics(false);
|
|
173
|
+
// Get real performance data
|
|
174
|
+
const report = await getPerformanceReport(timeframe);
|
|
175
|
+
printSuccess(`ā
Performance report generated`);
|
|
176
|
+
console.log(`\nš PERFORMANCE SUMMARY (${timeframe}):`);
|
|
177
|
+
console.log(` š Total tasks executed: ${report.summary.totalTasks}`);
|
|
178
|
+
console.log(` ā
Success rate: ${report.summary.successRate.toFixed(1)}%`);
|
|
179
|
+
console.log(` ā±ļø Average execution time: ${report.summary.avgDuration.toFixed(1)}s`);
|
|
180
|
+
console.log(` š¤ Agents spawned: ${report.summary.agentsSpawned}`);
|
|
181
|
+
console.log(` š¾ Memory efficiency: ${report.summary.memoryEfficiency.toFixed(0)}%`);
|
|
182
|
+
console.log(` š§ Neural learning events: ${report.summary.neuralEvents}`);
|
|
183
|
+
// Show trends if available
|
|
184
|
+
if (report.trends) {
|
|
185
|
+
console.log(`\nš TRENDS:`);
|
|
186
|
+
if (report.trends.successRateChange !== 0) {
|
|
187
|
+
const trend = report.trends.successRateChange > 0 ? 'improved' : 'decreased';
|
|
188
|
+
console.log(` ⢠Task success rate ${trend} ${Math.abs(report.trends.successRateChange).toFixed(1)}% vs previous period`);
|
|
189
|
+
}
|
|
190
|
+
if (report.trends.durationChange !== 0) {
|
|
191
|
+
const trend = report.trends.durationChange < 0 ? 'reduced' : 'increased';
|
|
192
|
+
console.log(` ⢠Average execution time ${trend} by ${Math.abs(report.trends.durationChange / 1000).toFixed(1)}s`);
|
|
193
|
+
}
|
|
194
|
+
if (report.trends.taskVolumeChange !== 0) {
|
|
195
|
+
const trend = report.trends.taskVolumeChange > 0 ? 'increased' : 'decreased';
|
|
196
|
+
const percent = Math.abs(report.trends.taskVolumeChange / report.summary.totalTasks * 100).toFixed(0);
|
|
197
|
+
console.log(` ⢠Task volume ${trend} ${percent}%`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (format === 'detailed' && report.agentMetrics) {
|
|
201
|
+
console.log(`\nš DETAILED METRICS:`);
|
|
202
|
+
console.log(` Agent Performance:`);
|
|
203
|
+
Object.entries(report.agentMetrics).forEach(([type, metrics])=>{
|
|
204
|
+
console.log(` - ${type} agents: ${metrics.successRate.toFixed(0)}% success, ${(metrics.avgDuration / 1000).toFixed(1)}s avg`);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
// Export full report
|
|
208
|
+
const reportPath = await exportMetrics(format === 'json' ? 'json' : 'html');
|
|
209
|
+
console.log(`\nš Full report: ${reportPath}`);
|
|
210
|
+
} catch (err) {
|
|
211
|
+
printError(`Failed to generate performance report: ${err.message}`);
|
|
212
|
+
printWarning('Showing simulated data as fallback...');
|
|
213
|
+
// Fallback to simulated data
|
|
214
|
+
console.log(`\nš PERFORMANCE SUMMARY (${timeframe}) - SIMULATED:`);
|
|
215
|
+
console.log(` š Total tasks executed: 127`);
|
|
216
|
+
console.log(` ā
Success rate: 94.5%`);
|
|
217
|
+
console.log(` ā±ļø Average execution time: 8.3s`);
|
|
218
|
+
console.log(` š¤ Agents spawned: 23`);
|
|
219
|
+
console.log(` š¾ Memory efficiency: 78%`);
|
|
220
|
+
console.log(` š§ Neural learning events: 45`);
|
|
277
221
|
}
|
|
278
|
-
|
|
279
|
-
// Export full report
|
|
280
|
-
const reportPath = await exportMetrics(format === 'json' ? 'json' : 'html');
|
|
281
|
-
console.log(`\nš Full report: ${reportPath}`);
|
|
282
|
-
} catch (err) {
|
|
283
|
-
printError(`Failed to generate performance report: ${err.message}`);
|
|
284
|
-
printWarning('Showing simulated data as fallback...');
|
|
285
|
-
|
|
286
|
-
// Fallback to simulated data
|
|
287
|
-
console.log(`\nš PERFORMANCE SUMMARY (${timeframe}) - SIMULATED:`);
|
|
288
|
-
console.log(` š Total tasks executed: 127`);
|
|
289
|
-
console.log(` ā
Success rate: 94.5%`);
|
|
290
|
-
console.log(` ā±ļø Average execution time: 8.3s`);
|
|
291
|
-
console.log(` š¤ Agents spawned: 23`);
|
|
292
|
-
console.log(` š¾ Memory efficiency: 78%`);
|
|
293
|
-
console.log(` š§ Neural learning events: 45`);
|
|
294
|
-
}
|
|
295
222
|
}
|
|
296
|
-
|
|
297
223
|
async function tokenUsageCommand(subArgs, flags) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
console.log(` ⢠${suggestion}`);
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// Generate real CSV report
|
|
356
|
-
const reportPath = await generateTokenUsageReport(tokenData, agent);
|
|
357
|
-
console.log(`\nš Detailed usage log: ${reportPath}`);
|
|
224
|
+
const options = flags;
|
|
225
|
+
const agent = options.agent || 'all';
|
|
226
|
+
const breakdown = options.breakdown || false;
|
|
227
|
+
const costAnalysis = options['cost-analysis'] || false;
|
|
228
|
+
console.log(`š¢ Analyzing token usage...`);
|
|
229
|
+
console.log(`š¤ Agent filter: ${agent}`);
|
|
230
|
+
console.log(`š Include breakdown: ${breakdown ? 'Yes' : 'No'}`);
|
|
231
|
+
console.log(`š° Include cost analysis: ${costAnalysis ? 'Yes' : 'No'}`);
|
|
232
|
+
try {
|
|
233
|
+
// Get real token usage from Claude Code metrics
|
|
234
|
+
const tokenData = await getRealTokenUsage(agent);
|
|
235
|
+
printSuccess(`ā
Token usage analysis completed`);
|
|
236
|
+
// Check if we have any data
|
|
237
|
+
if (tokenData.total === 0) {
|
|
238
|
+
// Show instructions when no data available
|
|
239
|
+
await showSimulatedTokenUsage(breakdown, costAnalysis);
|
|
240
|
+
// Still generate empty report for consistency
|
|
241
|
+
const reportPath = await generateTokenUsageReport(tokenData, agent);
|
|
242
|
+
console.log(`\nš Detailed usage log: ${reportPath}`);
|
|
243
|
+
} else {
|
|
244
|
+
// Display real token usage
|
|
245
|
+
console.log(`\nš¢ TOKEN USAGE SUMMARY:`);
|
|
246
|
+
console.log(` š Total tokens consumed: ${tokenData.total.toLocaleString()}`);
|
|
247
|
+
console.log(` š„ Input tokens: ${tokenData.input.toLocaleString()} (${(tokenData.input / tokenData.total * 100).toFixed(1)}%)`);
|
|
248
|
+
console.log(` š¤ Output tokens: ${tokenData.output.toLocaleString()} (${(tokenData.output / tokenData.total * 100).toFixed(1)}%)`);
|
|
249
|
+
if (costAnalysis) {
|
|
250
|
+
const cost = calculateCost(tokenData);
|
|
251
|
+
console.log(` š° Estimated cost: $${cost.total.toFixed(2)}`);
|
|
252
|
+
console.log(` Input cost: $${cost.input.toFixed(2)}`);
|
|
253
|
+
console.log(` Output cost: $${cost.output.toFixed(2)}`);
|
|
254
|
+
}
|
|
255
|
+
if (breakdown && tokenData.byAgent) {
|
|
256
|
+
console.log(`\nš BREAKDOWN BY AGENT TYPE:`);
|
|
257
|
+
Object.entries(tokenData.byAgent).forEach(([agentType, usage])=>{
|
|
258
|
+
const percentage = (usage / tokenData.total * 100).toFixed(1);
|
|
259
|
+
const icon = getAgentIcon(agentType);
|
|
260
|
+
console.log(` ${icon} ${agentType}: ${usage.toLocaleString()} tokens (${percentage}%)`);
|
|
261
|
+
});
|
|
262
|
+
console.log(`\nš” OPTIMIZATION OPPORTUNITIES:`);
|
|
263
|
+
const opportunities = generateOptimizationSuggestions(tokenData);
|
|
264
|
+
opportunities.forEach((suggestion)=>{
|
|
265
|
+
console.log(` ⢠${suggestion}`);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
// Generate real CSV report
|
|
269
|
+
const reportPath = await generateTokenUsageReport(tokenData, agent);
|
|
270
|
+
console.log(`\nš Detailed usage log: ${reportPath}`);
|
|
271
|
+
}
|
|
272
|
+
} catch (err) {
|
|
273
|
+
printError(`Failed to get real token usage: ${err.message}`);
|
|
274
|
+
printWarning('Falling back to help instructions...');
|
|
275
|
+
// Fallback to instructions
|
|
276
|
+
await showSimulatedTokenUsage(breakdown, costAnalysis);
|
|
358
277
|
}
|
|
359
|
-
} catch (err) {
|
|
360
|
-
printError(`Failed to get real token usage: ${err.message}`);
|
|
361
|
-
printWarning('Falling back to help instructions...');
|
|
362
|
-
|
|
363
|
-
// Fallback to instructions
|
|
364
|
-
await showSimulatedTokenUsage(breakdown, costAnalysis);
|
|
365
|
-
}
|
|
366
278
|
}
|
|
367
|
-
|
|
368
279
|
function showAnalysisHelp() {
|
|
369
|
-
|
|
280
|
+
console.log(`
|
|
370
281
|
š Analysis Commands - Performance & Usage Analytics
|
|
371
282
|
|
|
372
283
|
USAGE:
|
|
@@ -460,111 +371,90 @@ EXAMPLES:
|
|
|
460
371
|
š” TIP: Run 'analysis setup-telemetry' first to enable token tracking!
|
|
461
372
|
`);
|
|
462
373
|
}
|
|
463
|
-
|
|
464
374
|
// Helper functions for real token tracking are now imported from token-tracker.js
|
|
465
|
-
|
|
466
375
|
async function claudeMonitorCommand(subArgs, flags) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
await new Promise(() => {});
|
|
490
|
-
} catch (error) {
|
|
491
|
-
printError(`Failed to start Claude monitor: ${error.message}`);
|
|
492
|
-
console.log('\nš” TIP: Make sure Claude is installed and accessible');
|
|
493
|
-
}
|
|
376
|
+
const sessionId = subArgs[1] || 'current';
|
|
377
|
+
const interval = flags.interval || 5000;
|
|
378
|
+
console.log(`š Starting Claude session monitor...`);
|
|
379
|
+
console.log(` Session ID: ${sessionId}`);
|
|
380
|
+
console.log(` Update interval: ${interval / 1000}s`);
|
|
381
|
+
console.log(` Press Ctrl+C to stop monitoring\n`);
|
|
382
|
+
try {
|
|
383
|
+
// Import the telemetry module
|
|
384
|
+
const { monitorClaudeSession } = await import("./claude-telemetry.js");
|
|
385
|
+
// Start monitoring
|
|
386
|
+
const stopMonitor = await monitorClaudeSession(sessionId, interval);
|
|
387
|
+
// Handle graceful shutdown
|
|
388
|
+
process.on('SIGINT', ()=>{
|
|
389
|
+
stopMonitor();
|
|
390
|
+
process.exit(0);
|
|
391
|
+
});
|
|
392
|
+
// Keep process running
|
|
393
|
+
await new Promise(()=>{});
|
|
394
|
+
} catch (error) {
|
|
395
|
+
printError(`Failed to start Claude monitor: ${error.message}`);
|
|
396
|
+
console.log('\nš” TIP: Make sure Claude is installed and accessible');
|
|
397
|
+
}
|
|
494
398
|
}
|
|
495
|
-
|
|
496
399
|
async function claudeCostCommand(subArgs, flags) {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
400
|
+
console.log(`š° Retrieving Claude session cost information...`);
|
|
401
|
+
try {
|
|
402
|
+
// Import the telemetry module
|
|
403
|
+
const { extractCostCommand } = await import("./claude-telemetry.js");
|
|
404
|
+
// Get cost data
|
|
405
|
+
const costData = await extractCostCommand();
|
|
406
|
+
console.log('\nš Current Session Usage:');
|
|
407
|
+
console.log(` Input Tokens: ${costData.tokens.input || 0}`);
|
|
408
|
+
console.log(` Output Tokens: ${costData.tokens.output || 0}`);
|
|
409
|
+
console.log(` Total Tokens: ${costData.tokens.total || 0}`);
|
|
410
|
+
if (costData.costs.length > 0) {
|
|
411
|
+
console.log(` Estimated Cost: $${costData.costs[0]}`);
|
|
412
|
+
}
|
|
413
|
+
// Also show pricing info
|
|
414
|
+
console.log('\nš° Claude 3 Pricing:');
|
|
415
|
+
console.log(' ⢠Opus: $15/1M input, $75/1M output');
|
|
416
|
+
console.log(' ⢠Sonnet: $3/1M input, $15/1M output');
|
|
417
|
+
console.log(' ⢠Haiku: $0.25/1M input, $1.25/1M output');
|
|
418
|
+
} catch (error) {
|
|
419
|
+
printError(`Failed to retrieve cost data: ${error.message}`);
|
|
420
|
+
console.log('\nš” TIP: Run this while Claude is active or immediately after');
|
|
513
421
|
}
|
|
514
|
-
|
|
515
|
-
// Also show pricing info
|
|
516
|
-
console.log('\nš° Claude 3 Pricing:');
|
|
517
|
-
console.log(' ⢠Opus: $15/1M input, $75/1M output');
|
|
518
|
-
console.log(' ⢠Sonnet: $3/1M input, $15/1M output');
|
|
519
|
-
console.log(' ⢠Haiku: $0.25/1M input, $1.25/1M output');
|
|
520
|
-
} catch (error) {
|
|
521
|
-
printError(`Failed to retrieve cost data: ${error.message}`);
|
|
522
|
-
console.log('\nš” TIP: Run this while Claude is active or immediately after');
|
|
523
|
-
}
|
|
524
422
|
}
|
|
525
|
-
|
|
526
423
|
async function showSimulatedTokenUsage(breakdown, costAnalysis) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
console.log(
|
|
561
|
-
console.log(` ā¢
|
|
562
|
-
console.log(` ā¢
|
|
563
|
-
console.log(` ⢠Provides optimization recommendations`);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
console.log(`\nā TROUBLESHOOTING:`);
|
|
567
|
-
console.log(` ⢠Check telemetry status: echo $CLAUDE_CODE_ENABLE_TELEMETRY`);
|
|
568
|
-
console.log(` ⢠View raw data: cat .claude-flow/metrics/token-usage.json`);
|
|
569
|
-
console.log(` ⢠Reset tracking: rm -rf .claude-flow/metrics/token-usage.json`);
|
|
424
|
+
// Show honest message about no data instead of fake numbers
|
|
425
|
+
console.log(`\nš¢ TOKEN USAGE ANALYSIS:`);
|
|
426
|
+
console.log(` ā¹ļø No token usage data available yet.`);
|
|
427
|
+
console.log(`\nš QUICK SETUP - Choose one option:`);
|
|
428
|
+
console.log(`\n Option 1: Enable Telemetry (Recommended)`);
|
|
429
|
+
console.log(` āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
430
|
+
console.log(` ā ./claude-flow-novice analysis setup-telemetry ā`);
|
|
431
|
+
console.log(` āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
432
|
+
console.log(`\n Option 2: Manual Environment Variable`);
|
|
433
|
+
console.log(` āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
434
|
+
console.log(` ā export CLAUDE_CODE_ENABLE_TELEMETRY=1 ā`);
|
|
435
|
+
console.log(` āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
436
|
+
console.log(`\n Option 3: Use --enable-telemetry Flag`);
|
|
437
|
+
console.log(` āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
438
|
+
console.log(` ā ./claude-flow-novice analysis token-usage --enable-telemetry ā`);
|
|
439
|
+
console.log(` āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā`);
|
|
440
|
+
console.log(`\nā
AFTER SETUP:`);
|
|
441
|
+
console.log(` 1. Run Claude commands: ./claude-flow-novice swarm "task" --claude`);
|
|
442
|
+
console.log(` 2. Token usage will be automatically tracked`);
|
|
443
|
+
console.log(` 3. Return here to see real metrics`);
|
|
444
|
+
if (costAnalysis) {
|
|
445
|
+
console.log(`\nš° COST TRACKING:`);
|
|
446
|
+
console.log(` ⢠Claude 3 Opus: $15/1M input, $75/1M output tokens`);
|
|
447
|
+
console.log(` ⢠Claude 3 Sonnet: $3/1M input, $15/1M output tokens`);
|
|
448
|
+
console.log(` ⢠Claude 3 Haiku: $0.25/1M input, $1.25/1M output tokens`);
|
|
449
|
+
}
|
|
450
|
+
if (breakdown) {
|
|
451
|
+
console.log(`\nš AGENT BREAKDOWN:`);
|
|
452
|
+
console.log(` ⢠Each agent type's usage tracked separately`);
|
|
453
|
+
console.log(` ⢠Identifies high-consumption agents`);
|
|
454
|
+
console.log(` ⢠Provides optimization recommendations`);
|
|
455
|
+
}
|
|
456
|
+
console.log(`\nā TROUBLESHOOTING:`);
|
|
457
|
+
console.log(` ⢠Check telemetry status: echo $CLAUDE_CODE_ENABLE_TELEMETRY`);
|
|
458
|
+
console.log(` ⢠View raw data: cat .claude-flow/metrics/token-usage.json`);
|
|
459
|
+
console.log(` ⢠Reset tracking: rm -rf .claude-flow/metrics/token-usage.json`);
|
|
570
460
|
}
|