openclaw-smartmeter 0.2.0 ā 0.2.2
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/README.md +37 -2
- package/package.json +1 -1
- package/src/canvas/api-server.js +1 -1
- package/src/cli/commands.js +90 -8
- package/src/cli/index.js +45 -3
package/README.md
CHANGED
|
@@ -61,7 +61,26 @@ npm link
|
|
|
61
61
|
|
|
62
62
|
## Quick Start
|
|
63
63
|
|
|
64
|
-
###
|
|
64
|
+
### Super Simple - One Command! š
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Install globally
|
|
68
|
+
npm install -g openclaw-smartmeter
|
|
69
|
+
|
|
70
|
+
# Run analysis - dashboard opens automatically in your browser!
|
|
71
|
+
smartmeter analyze
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
That's it! The dashboard opens automatically with:
|
|
75
|
+
|
|
76
|
+
- ā
Cost savings visualization
|
|
77
|
+
- ā
One-click optimization application
|
|
78
|
+
- ā
Export reports
|
|
79
|
+
- ā
Live data updates
|
|
80
|
+
|
|
81
|
+
### Detailed Workflow
|
|
82
|
+
|
|
83
|
+
### 1. Analyze your usage (auto-opens dashboard)
|
|
65
84
|
|
|
66
85
|
```bash
|
|
67
86
|
# Analyze default OpenClaw data (~/.openclaw)
|
|
@@ -84,7 +103,23 @@ Analysis: 2026-02-04 to 2026-02-05 (2 days)
|
|
|
84
103
|
Confidence optimistic
|
|
85
104
|
```
|
|
86
105
|
|
|
87
|
-
### 2.
|
|
106
|
+
### 2. Use the Dashboard (already open!)
|
|
107
|
+
|
|
108
|
+
The dashboard automatically opened in step 1, showing:
|
|
109
|
+
|
|
110
|
+
- Cost savings overview with before/after comparison
|
|
111
|
+
- Model usage breakdown (bar chart)
|
|
112
|
+
- Task classification distribution (doughnut chart)
|
|
113
|
+
- Actionable recommendations with impact estimates
|
|
114
|
+
- Auto-refresh every 5 seconds
|
|
115
|
+
|
|
116
|
+
**Dashboard Actions:**
|
|
117
|
+
|
|
118
|
+
- šÆ **Apply Optimizations** - One click to apply all changes (creates backup)
|
|
119
|
+
- š **Export Report** - Download markdown report
|
|
120
|
+
- āļø **Preview Config** - See exact changes before applying
|
|
121
|
+
|
|
122
|
+
### 3. Evaluate your configuration
|
|
88
123
|
|
|
89
124
|
```bash
|
|
90
125
|
smartmeter evaluate
|
package/package.json
CHANGED
package/src/canvas/api-server.js
CHANGED
|
@@ -228,7 +228,7 @@ export class ApiServer {
|
|
|
228
228
|
- **Current Monthly Cost:** $${s.currentMonthlyCost.toFixed(2)}
|
|
229
229
|
- **Optimized Monthly Cost:** $${s.optimizedMonthlyCost.toFixed(2)}
|
|
230
230
|
- **Potential Savings:** $${s.potentialSavings.toFixed(2)}/month (${s.savingsPercentage.toFixed(1)}%)
|
|
231
|
-
- **Confidence Level:** ${
|
|
231
|
+
- **Confidence Level:** ${s.confidence || 'unknown'}
|
|
232
232
|
|
|
233
233
|
## Model Breakdown
|
|
234
234
|
|
package/src/cli/commands.js
CHANGED
|
@@ -66,15 +66,95 @@ export async function cmdAnalyze(opts = {}) {
|
|
|
66
66
|
const storageDir = opts.storageDir || SMARTMETER_DIR;
|
|
67
67
|
await writeAnalysis(analysis, storageDir);
|
|
68
68
|
|
|
69
|
-
// Auto-update dashboard if canvas is deployed
|
|
70
|
-
const deployer = new CanvasDeployer();
|
|
71
|
-
if (await deployer.isDeployed()) {
|
|
72
|
-
await deployer.generatePublicAnalysis(analysis);
|
|
73
|
-
console.log("ā Dashboard data updated");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
69
|
console.log(formatSummary(analysis));
|
|
77
70
|
console.log(`\nAnalysis saved to ${storageDir}/analysis.json`);
|
|
71
|
+
|
|
72
|
+
// Auto-deploy dashboard and open in browser
|
|
73
|
+
const shouldOpenDashboard = opts.noDashboard !== true;
|
|
74
|
+
|
|
75
|
+
if (shouldOpenDashboard) {
|
|
76
|
+
console.log("\nāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā");
|
|
77
|
+
console.log("š Launching SmartMeter Dashboard...");
|
|
78
|
+
console.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n");
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const deployer = new CanvasDeployer();
|
|
82
|
+
|
|
83
|
+
// Deploy dashboard files
|
|
84
|
+
await deployer.deploy();
|
|
85
|
+
await deployer.generatePublicAnalysis(analysis);
|
|
86
|
+
|
|
87
|
+
const port = opts.port || 8080;
|
|
88
|
+
const apiPort = opts.apiPort || 3001;
|
|
89
|
+
|
|
90
|
+
// Start API server in background
|
|
91
|
+
console.log("ā Starting API server...");
|
|
92
|
+
const apiServer = await startApiServer({ port: apiPort });
|
|
93
|
+
|
|
94
|
+
// Start static file server in background
|
|
95
|
+
console.log("ā Starting dashboard server...");
|
|
96
|
+
const staticServer = await startStaticFileServer(deployer.canvasDir, port);
|
|
97
|
+
|
|
98
|
+
const url = `http://localhost:${port}`;
|
|
99
|
+
|
|
100
|
+
console.log(`
|
|
101
|
+
ā
Dashboard is live!
|
|
102
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
103
|
+
|
|
104
|
+
š Dashboard URL: ${url}
|
|
105
|
+
š” API Server: http://localhost:${apiPort}
|
|
106
|
+
|
|
107
|
+
š” Features:
|
|
108
|
+
⢠View cost savings and recommendations
|
|
109
|
+
⢠Apply optimizations with one click
|
|
110
|
+
⢠Export reports
|
|
111
|
+
⢠Preview config changes
|
|
112
|
+
|
|
113
|
+
š Dashboard updates automatically every 5 seconds
|
|
114
|
+
|
|
115
|
+
Opening in your browser...
|
|
116
|
+
`);
|
|
117
|
+
|
|
118
|
+
// Open browser
|
|
119
|
+
try {
|
|
120
|
+
await deployer.openDashboard(port);
|
|
121
|
+
console.log("ā Browser opened\n");
|
|
122
|
+
} catch (err) {
|
|
123
|
+
console.log(`ā Could not open browser automatically`);
|
|
124
|
+
console.log(` Please open manually: ${url}\n`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
console.log("š” Tip: Press Ctrl+C to stop the servers");
|
|
128
|
+
console.log("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n");
|
|
129
|
+
|
|
130
|
+
// Keep process alive and handle shutdown
|
|
131
|
+
const shutdownHandler = async () => {
|
|
132
|
+
console.log("\n\nš Shutting down servers...");
|
|
133
|
+
try {
|
|
134
|
+
await staticServer.stop();
|
|
135
|
+
await apiServer.stop();
|
|
136
|
+
console.log("ā Servers stopped");
|
|
137
|
+
} catch (err) {
|
|
138
|
+
console.error("Error stopping servers:", err.message);
|
|
139
|
+
}
|
|
140
|
+
process.exit(0);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
process.on("SIGINT", shutdownHandler);
|
|
144
|
+
process.on("SIGTERM", shutdownHandler);
|
|
145
|
+
|
|
146
|
+
// Store server references for cleanup
|
|
147
|
+
analysis._servers = { staticServer, apiServer };
|
|
148
|
+
|
|
149
|
+
} catch (err) {
|
|
150
|
+
console.error(`\nā Could not start dashboard: ${err.message}`);
|
|
151
|
+
console.log(`\nYou can view your analysis by running:`);
|
|
152
|
+
console.log(` smartmeter status`);
|
|
153
|
+
console.log(`\nOr start the dashboard manually:`);
|
|
154
|
+
console.log(` smartmeter serve\n`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
78
158
|
return analysis;
|
|
79
159
|
}
|
|
80
160
|
|
|
@@ -286,7 +366,7 @@ export async function cmdEvaluate(opts = {}) {
|
|
|
286
366
|
š Current Analysis:
|
|
287
367
|
Period: ${analysis.period.days} days (${analysis.period.start} to ${analysis.period.end})
|
|
288
368
|
Tasks Analyzed: ${analysis.period.totalTasks}
|
|
289
|
-
Confidence: ${
|
|
369
|
+
Confidence: ${s.confidence || 'unknown'}
|
|
290
370
|
|
|
291
371
|
š° Cost Analysis:
|
|
292
372
|
Current Monthly Cost: $${s.currentMonthlyCost.toFixed(2)}
|
|
@@ -342,6 +422,8 @@ ${Object.entries(analysis.categories || {})
|
|
|
342
422
|
.map(([name, c]) => ` ⢠${name}: ${c.count} tasks`)
|
|
343
423
|
.join("\n")}
|
|
344
424
|
|
|
425
|
+
**Confidence Level:** ${analysis.summary.confidence || 'unknown'}
|
|
426
|
+
|
|
345
427
|
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
346
428
|
|
|
347
429
|
## š° Optimization Opportunities
|
package/src/cli/index.js
CHANGED
|
@@ -29,7 +29,46 @@ const program = new Command();
|
|
|
29
29
|
program
|
|
30
30
|
.name("smartmeter")
|
|
31
31
|
.description("Analyze OpenClaw usage and generate optimized configs to reduce AI costs")
|
|
32
|
-
.version(packageJson.version)
|
|
32
|
+
.version(packageJson.version)
|
|
33
|
+
.action(() => {
|
|
34
|
+
console.log(`
|
|
35
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
36
|
+
ā Welcome to SmartMeter! šÆ ā
|
|
37
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
38
|
+
|
|
39
|
+
AI Cost Optimization for OpenClaw
|
|
40
|
+
|
|
41
|
+
š Quick Start:
|
|
42
|
+
|
|
43
|
+
1ļøā£ Analyze your usage and launch dashboard:
|
|
44
|
+
$ smartmeter analyze
|
|
45
|
+
|
|
46
|
+
2ļøā£ Dashboard opens automatically in your browser
|
|
47
|
+
⢠View cost savings
|
|
48
|
+
⢠Apply optimizations
|
|
49
|
+
⢠Export reports
|
|
50
|
+
|
|
51
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
52
|
+
|
|
53
|
+
š Other Commands:
|
|
54
|
+
|
|
55
|
+
evaluate - Quick cost evaluation
|
|
56
|
+
guide - Step-by-step optimization guide
|
|
57
|
+
preview - Preview config changes
|
|
58
|
+
apply - Apply optimizations
|
|
59
|
+
serve - Start dashboard server
|
|
60
|
+
status - Show current analysis
|
|
61
|
+
report - Detailed cost breakdown
|
|
62
|
+
|
|
63
|
+
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|
|
64
|
+
|
|
65
|
+
š” Need help with a specific command?
|
|
66
|
+
$ smartmeter <command> --help
|
|
67
|
+
|
|
68
|
+
š Full documentation:
|
|
69
|
+
https://github.com/vajih/openclaw-smartmeter
|
|
70
|
+
`);
|
|
71
|
+
});
|
|
33
72
|
|
|
34
73
|
function dataDirOpts(cmdOpts) {
|
|
35
74
|
if (!cmdOpts.dataDir) return {};
|
|
@@ -38,9 +77,12 @@ function dataDirOpts(cmdOpts) {
|
|
|
38
77
|
|
|
39
78
|
program
|
|
40
79
|
.command("analyze")
|
|
41
|
-
.description("Analyze usage patterns and
|
|
80
|
+
.description("Analyze usage patterns and launch interactive dashboard")
|
|
42
81
|
.option("-d, --data-dir <path>", "OpenClaw data directory (default: ~/.openclaw)")
|
|
43
|
-
.
|
|
82
|
+
.option("-p, --port <number>", "Dashboard port (default: 8080)")
|
|
83
|
+
.option("--api-port <number>", "API server port (default: 3001)")
|
|
84
|
+
.option("--no-dashboard", "Skip launching dashboard (analysis only)")
|
|
85
|
+
.action((opts) => cmdAnalyze({ ...dataDirOpts(opts), port: opts.port ? Number(opts.port) : undefined, apiPort: opts.apiPort ? Number(opts.apiPort) : undefined, noDashboard: opts.noDashboard }));
|
|
44
86
|
|
|
45
87
|
program
|
|
46
88
|
.command("show")
|