clawculator 2.6.1 → 2.8.0

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.
@@ -1,123 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- const { runAnalysis } = require('../src/analyzer');
5
- const { generateTerminalReport } = require('../src/reporter');
6
- const { generateMarkdownReport } = require('../src/mdReport');
7
- const path = require('path');
8
- const os = require('os');
9
- const fs = require('fs');
10
-
11
- const args = process.argv.slice(2);
12
- const flags = {
13
- report: args.includes('--report'),
14
- json: args.includes('--json'),
15
- md: args.includes('--md'),
16
- help: args.includes('--help') || args.includes('-h'),
17
- config: args.find(a => a.startsWith('--config='))?.split('=')[1],
18
- out: args.find(a => a.startsWith('--out='))?.split('=')[1],
19
- };
20
-
21
- const BANNER = `
22
- \x1b[36m
23
- ██████╗██╗ █████╗ ██╗ ██╗ ██████╗ █████╗ ██╗ ██████╗
24
- ██╔════╝██║ ██╔══██╗██║ ██║██╔════╝██╔══██╗██║ ██╔════╝
25
- ██║ ██║ ███████║██║ █╗ ██║██║ ███████║██║ ██║
26
- ██║ ██║ ██╔══██║██║███╗██║██║ ██╔══██║██║ ██║
27
- ╚██████╗███████╗██║ ██║╚███╔███╔╝╚██████╗██║ ██║███████╗╚██████╗
28
- ╚═════╝╚══════╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═════╝
29
- \x1b[0m
30
- \x1b[33mYour friendly penny pincher.\x1b[0m
31
- \x1b[90m100% offline · Zero AI · Pure deterministic logic · Your data never leaves your machine\x1b[0m
32
- `;
33
-
34
- const HELP = `
35
- Usage: clawculator [options]
36
-
37
- Options:
38
- (no flags) Full terminal analysis
39
- --md Save markdown report to ./clawculator-report.md
40
- --report Generate HTML report and open in browser
41
- --json Output raw JSON
42
- --out=PATH Custom output path for --md or --report
43
- --config=PATH Path to openclaw.json (auto-detected by default)
44
- --help, -h Show this help
45
-
46
- Examples:
47
- npx clawculator # Terminal analysis
48
- npx clawculator --md # Markdown report (readable by your AI agent)
49
- npx clawculator --report # Visual HTML dashboard
50
- npx clawculator --json # JSON for piping
51
- npx clawculator --md --out=~/cost.md # Custom path
52
- `;
53
-
54
- async function main() {
55
- if (flags.help) {
56
- console.log(BANNER);
57
- console.log(HELP);
58
- process.exit(0);
59
- }
60
-
61
- console.log(BANNER);
62
- console.log('\x1b[90mScanning your setup...\x1b[0m\n');
63
-
64
- const openclawHome = process.env.OPENCLAW_HOME || path.join(os.homedir(), '.openclaw');
65
- const configPath = flags.config || path.join(openclawHome, 'openclaw.json');
66
-
67
- // Auto-discover sessions path: find first agent with a sessions.json
68
- let sessionsPath = path.join(openclawHome, 'agents', 'main', 'sessions', 'sessions.json');
69
- if (!fs.existsSync(sessionsPath)) {
70
- const agentsDir = path.join(openclawHome, 'agents');
71
- try {
72
- for (const agent of fs.readdirSync(agentsDir)) {
73
- const candidate = path.join(agentsDir, agent, 'sessions', 'sessions.json');
74
- if (fs.existsSync(candidate)) { sessionsPath = candidate; break; }
75
- }
76
- } catch { /* agents dir missing */ }
77
- }
78
-
79
- const logsDir = '/tmp/openclaw';
80
-
81
- let analysis;
82
- try {
83
- analysis = await runAnalysis({ configPath, sessionsPath, logsDir });
84
- } catch (err) {
85
- console.error('\x1b[31mError:\x1b[0m', err.message);
86
- process.exit(1);
87
- }
88
-
89
- if (flags.json) {
90
- console.log(JSON.stringify(analysis, null, 2));
91
- process.exit(0);
92
- }
93
-
94
- if (flags.md) {
95
- const outPath = flags.out || path.join(process.cwd(), 'clawculator-report.md');
96
- fs.writeFileSync(outPath, generateMarkdownReport(analysis), 'utf8');
97
- console.log(`\x1b[32m✓ Markdown report saved:\x1b[0m ${outPath}`);
98
- generateTerminalReport(analysis);
99
- process.exit(0);
100
- }
101
-
102
- if (flags.report) {
103
- const outPath = flags.out || path.join(process.cwd(), `clawculator-report.html`);
104
- const { generateHTMLReport } = require('../src/htmlReport');
105
- await generateHTMLReport(analysis, outPath);
106
- const { exec } = require('child_process');
107
- exec(`open "${outPath}" 2>/dev/null || xdg-open "${outPath}" 2>/dev/null`);
108
- console.log(`\x1b[32m✓ HTML report saved:\x1b[0m ${outPath}`);
109
- generateTerminalReport(analysis);
110
- process.exit(0);
111
- }
112
-
113
- generateTerminalReport(analysis);
114
- console.log('\x1b[90m────────────────────────────────────────────────────\x1b[0m');
115
- console.log('\x1b[36mClawculator\x1b[0m · github.com/echoudhry/clawculator · Your friendly penny pincher.');
116
- console.log('\x1b[90mTip: --md saves a report your AI agent can read directly\x1b[0m');
117
- console.log('\x1b[90m────────────────────────────────────────────────────\x1b[0m\n');
118
- }
119
-
120
- main().catch(err => {
121
- console.error('\x1b[31mFatal:\x1b[0m', err.message);
122
- process.exit(1);
123
- });