openclaw-smartmeter 0.1.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.
- package/CONTRIBUTING.md +148 -0
- package/LICENSE +190 -0
- package/README.md +275 -0
- package/SECURITY.md +89 -0
- package/SKILL.md +0 -0
- package/SPEC.md +708 -0
- package/canvas-template/README.md +166 -0
- package/canvas-template/analysis.public.json +141 -0
- package/canvas-template/app.js +425 -0
- package/canvas-template/index.html +162 -0
- package/canvas-template/preview-server.py +63 -0
- package/canvas-template/styles.css +575 -0
- package/docs/backlog.md +63 -0
- package/package.json +41 -0
- package/src/analyzer/aggregator.js +256 -0
- package/src/analyzer/classifier.js +160 -0
- package/src/analyzer/parser.js +187 -0
- package/src/analyzer/recommender.js +158 -0
- package/src/analyzer/storage.js +31 -0
- package/src/canvas/deployer.js +321 -0
- package/src/cli/commands.js +267 -0
- package/src/cli/index.js +82 -0
- package/src/cli/utils.js +146 -0
- package/src/generator/agent-creator.js +61 -0
- package/src/generator/config-builder.js +163 -0
- package/src/generator/merger.js +27 -0
- package/src/generator/validator.js +54 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Contributing to SmartMeter
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to SmartMeter. This guide will help you get started.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
- Node.js 18+
|
|
10
|
+
- npm 9+
|
|
11
|
+
- Git
|
|
12
|
+
|
|
13
|
+
### Setup
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/vajih/openclaw-smartmeter.git
|
|
17
|
+
cd openclaw-smartmeter
|
|
18
|
+
npm install
|
|
19
|
+
npm test
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
All 93+ tests should pass before you begin making changes.
|
|
23
|
+
|
|
24
|
+
## Development Workflow
|
|
25
|
+
|
|
26
|
+
### 1. Create a Branch
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
git checkout -b feature/your-feature-name
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Use descriptive branch names:
|
|
33
|
+
- `feature/` for new features
|
|
34
|
+
- `fix/` for bug fixes
|
|
35
|
+
- `docs/` for documentation changes
|
|
36
|
+
- `refactor/` for code restructuring
|
|
37
|
+
|
|
38
|
+
### 2. Make Changes
|
|
39
|
+
|
|
40
|
+
Follow existing code patterns:
|
|
41
|
+
- **ESM modules** (`import`/`export`, not `require`)
|
|
42
|
+
- **Async/await** for all asynchronous operations
|
|
43
|
+
- **Node.js built-in test runner** (`node:test` and `node:assert/strict`)
|
|
44
|
+
- **No unnecessary dependencies** - prefer Node.js built-ins where possible
|
|
45
|
+
|
|
46
|
+
### 3. Write Tests
|
|
47
|
+
|
|
48
|
+
Every new feature or bug fix should include tests:
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
import test from "node:test";
|
|
52
|
+
import assert from "node:assert/strict";
|
|
53
|
+
|
|
54
|
+
test("descriptive test name", async () => {
|
|
55
|
+
// Arrange
|
|
56
|
+
// Act
|
|
57
|
+
// Assert
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Run tests with:
|
|
62
|
+
```bash
|
|
63
|
+
npm test # All tests
|
|
64
|
+
node --test tests/parser.test.js # Single file
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 4. Submit a Pull Request
|
|
68
|
+
|
|
69
|
+
- Ensure all tests pass
|
|
70
|
+
- Write a clear PR description explaining the change
|
|
71
|
+
- Reference any related issues
|
|
72
|
+
|
|
73
|
+
## Project Structure
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
src/
|
|
77
|
+
analyzer/ # Phase 1: Analysis engine
|
|
78
|
+
parser.js # JSONL session parser
|
|
79
|
+
classifier.js # Task classification
|
|
80
|
+
aggregator.js # Statistics aggregation
|
|
81
|
+
recommender.js # Optimization recommendations
|
|
82
|
+
storage.js # Analysis persistence
|
|
83
|
+
generator/ # Phase 2: Config generator
|
|
84
|
+
config-builder.js
|
|
85
|
+
agent-creator.js
|
|
86
|
+
merger.js
|
|
87
|
+
validator.js
|
|
88
|
+
canvas/ # Canvas dashboard
|
|
89
|
+
deployer.js # Dashboard deployment
|
|
90
|
+
cli/ # Phase 3: CLI interface
|
|
91
|
+
index.js # Commander.js entry point
|
|
92
|
+
commands.js # Command handlers
|
|
93
|
+
utils.js # Formatting helpers
|
|
94
|
+
tests/ # Test files (mirror src/ structure)
|
|
95
|
+
canvas-template/ # Dashboard HTML/JS/CSS templates
|
|
96
|
+
docs/ # Documentation
|
|
97
|
+
examples/ # Sample data files
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Code Style
|
|
101
|
+
|
|
102
|
+
- Use `const` by default, `let` when reassignment is needed
|
|
103
|
+
- Prefer early returns over deep nesting
|
|
104
|
+
- Keep functions small and focused
|
|
105
|
+
- No semicolons are fine, but be consistent within a file (this project uses semicolons)
|
|
106
|
+
- No comments for self-explanatory code; add JSDoc for public APIs
|
|
107
|
+
|
|
108
|
+
## Architecture Guidelines
|
|
109
|
+
|
|
110
|
+
### SPEC.md is the Source of Truth
|
|
111
|
+
|
|
112
|
+
All feature work should align with `SPEC.md`. Before adding new functionality:
|
|
113
|
+
|
|
114
|
+
1. Check `docs/SPEC_ALIGNMENT.md` to see what's implemented
|
|
115
|
+
2. Check `docs/backlog.md` for deferred items
|
|
116
|
+
3. If your feature isn't in the SPEC, open an issue to discuss it first
|
|
117
|
+
|
|
118
|
+
### Pipeline Pattern
|
|
119
|
+
|
|
120
|
+
The analysis pipeline flows in one direction:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
parser -> classifier -> aggregator -> recommender -> storage
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Each module receives data from the previous stage and returns a new object (no mutation). This makes testing and debugging straightforward.
|
|
127
|
+
|
|
128
|
+
### Testability
|
|
129
|
+
|
|
130
|
+
Command handlers accept an `opts` parameter for dependency injection:
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
// Production: uses default paths
|
|
134
|
+
await cmdAnalyze();
|
|
135
|
+
|
|
136
|
+
// Testing: uses temp directories
|
|
137
|
+
await cmdAnalyze({ baseDir: tmpDir, storageDir: tmpStorage });
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Reporting Issues
|
|
141
|
+
|
|
142
|
+
- Use GitHub Issues for bug reports and feature requests
|
|
143
|
+
- Include Node.js version, OS, and steps to reproduce
|
|
144
|
+
- For security issues, see [SECURITY.md](SECURITY.md)
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
By contributing, you agree that your contributions will be licensed under the Apache License 2.0.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Vajih Khan
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<h1 align="center">SmartMeter</h1>
|
|
3
|
+
<p align="center">
|
|
4
|
+
<strong>AI cost optimization for OpenClaw</strong>
|
|
5
|
+
</p>
|
|
6
|
+
<p align="center">
|
|
7
|
+
Analyze your AI usage patterns. Generate optimized configs. Cut costs by 48%+.
|
|
8
|
+
</p>
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="License: Apache 2.0"></a>
|
|
11
|
+
<a href="#"><img src="https://img.shields.io/badge/Node.js-18%2B-green.svg" alt="Node.js 18+"></a>
|
|
12
|
+
<a href="#"><img src="https://img.shields.io/badge/Tests-93%20passing-brightgreen.svg" alt="Tests: 93 passing"></a>
|
|
13
|
+
</p>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## What is SmartMeter?
|
|
19
|
+
|
|
20
|
+
SmartMeter is a cost optimization skill for [OpenClaw](https://openclaw.ai) that analyzes your AI agent usage and generates optimized configurations to reduce API spending — without sacrificing quality.
|
|
21
|
+
|
|
22
|
+
It parses your session logs, classifies tasks by type, identifies which models are overkill for routine work, and generates a tuned `openclaw.json` that routes the right tasks to the right models.
|
|
23
|
+
|
|
24
|
+
### Real-World Results
|
|
25
|
+
|
|
26
|
+
Tested on live OpenClaw data (288 tasks across 9 sessions):
|
|
27
|
+
|
|
28
|
+
| Metric | Value |
|
|
29
|
+
|---|---|
|
|
30
|
+
| Current monthly projection | $59.97 |
|
|
31
|
+
| Optimized monthly projection | $31.14 |
|
|
32
|
+
| **Potential savings** | **$28.82/month (48.1%)** |
|
|
33
|
+
| Models analyzed | DeepSeek Chat, Claude Sonnet 4.5, Claude Opus 4.5 |
|
|
34
|
+
| Confidence | Optimistic (2 days of data; improves with 14+ days) |
|
|
35
|
+
|
|
36
|
+
The key insight: DeepSeek Chat handled 69% of tasks at 1/5th the cost of premium models, while Opus was only needed for 15% of complex work.
|
|
37
|
+
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- **Usage Analysis** — Parse JSONL session logs, extract model usage, token counts, costs, and cache performance across all agents
|
|
41
|
+
- **Task Classification** — Automatically categorize tasks into code, writing, research, config, and other using keyword-based classification
|
|
42
|
+
- **Cost Optimization** — Identify where expensive models are being used for simple tasks and recommend cheaper alternatives
|
|
43
|
+
- **Config Generation** — Generate production-ready `openclaw.json` with primary model, fallback chains, specialized agents, budget controls, and caching settings
|
|
44
|
+
- **Live Dashboard** — Interactive web dashboard deployed to OpenClaw Canvas with auto-refresh, charts, and actionable recommendations
|
|
45
|
+
- **Safe Rollback** — Every config change creates a timestamped backup; one command to roll back
|
|
46
|
+
- **CLI Interface** — 8 commands covering the full workflow from analysis to deployment
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
git clone https://github.com/vajih/openclaw-smartmeter.git
|
|
52
|
+
cd openclaw-smartmeter
|
|
53
|
+
npm install
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
To make the `smartmeter` command available globally:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm link
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
### 1. Analyze your usage
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Analyze default OpenClaw data (~/.openclaw)
|
|
68
|
+
smartmeter analyze
|
|
69
|
+
|
|
70
|
+
# Or point to a specific data directory
|
|
71
|
+
smartmeter analyze --data-dir ~/my-openclaw-data
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Output:
|
|
75
|
+
```
|
|
76
|
+
Analysis: 2026-02-04 to 2026-02-05 (2 days)
|
|
77
|
+
|
|
78
|
+
Total tasks 288
|
|
79
|
+
Total cost $4.00
|
|
80
|
+
Monthly cost (projected) $59.97
|
|
81
|
+
Optimized monthly cost $31.14
|
|
82
|
+
Potential savings $28.82/month (48.1%)
|
|
83
|
+
Confidence optimistic
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 2. Preview recommended changes
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
smartmeter preview --data-dir ~/my-openclaw-data
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
Proposed changes:
|
|
94
|
+
- Primary model: (none) -> deepseek/deepseek-chat
|
|
95
|
+
- Fallback chain: delivery-mirror -> anthropic/claude-sonnet-4.5 -> anthropic/claude-opus-4.5
|
|
96
|
+
- New agents: code-reviewer
|
|
97
|
+
- Budget: $2.40/day, $16.80/week
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 3. View the full generated config
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
smartmeter show --data-dir ~/my-openclaw-data
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 4. Apply the optimized config
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
smartmeter apply --data-dir ~/my-openclaw-data
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
This creates a backup of your current config before writing the new one.
|
|
113
|
+
|
|
114
|
+
### 5. Launch the dashboard
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
smartmeter dashboard
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Opens an interactive web dashboard in your browser with:
|
|
121
|
+
- Cost savings overview with confidence indicators
|
|
122
|
+
- Model usage breakdown (bar chart)
|
|
123
|
+
- Task classification distribution (doughnut chart)
|
|
124
|
+
- Actionable recommendations with impact estimates
|
|
125
|
+
- Auto-refresh every 5 seconds
|
|
126
|
+
|
|
127
|
+
### 6. Roll back if needed
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
smartmeter rollback
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## CLI Reference
|
|
134
|
+
|
|
135
|
+
| Command | Description |
|
|
136
|
+
|---|---|
|
|
137
|
+
| `smartmeter analyze` | Run full analysis pipeline and save results |
|
|
138
|
+
| `smartmeter show` | Display the generated optimized config as JSON |
|
|
139
|
+
| `smartmeter preview` | Show what would change without applying |
|
|
140
|
+
| `smartmeter apply` | Apply optimized config (creates backup first) |
|
|
141
|
+
| `smartmeter rollback` | Restore the most recent backup config |
|
|
142
|
+
| `smartmeter status` | Show current optimization status from stored analysis |
|
|
143
|
+
| `smartmeter report` | Detailed breakdown: models, categories, temporal, caching |
|
|
144
|
+
| `smartmeter dashboard` | Deploy and open the web dashboard |
|
|
145
|
+
|
|
146
|
+
**Global options** for commands that run analysis:
|
|
147
|
+
- `-d, --data-dir <path>` — OpenClaw data directory (default: `~/.openclaw`)
|
|
148
|
+
|
|
149
|
+
**Dashboard options:**
|
|
150
|
+
- `-p, --port <number>` — OpenClaw gateway port (default: 8080)
|
|
151
|
+
- `--no-open` — Don't open browser automatically
|
|
152
|
+
|
|
153
|
+
## Screenshots
|
|
154
|
+
|
|
155
|
+
### Dashboard Overview
|
|
156
|
+

|
|
157
|
+
*Live-updating dashboard with cost savings, model breakdown, and actionable recommendations*
|
|
158
|
+
|
|
159
|
+
### Cost Savings Analysis
|
|
160
|
+

|
|
161
|
+
*Real-time savings calculation showing 48% cost reduction with confidence indicators*
|
|
162
|
+
|
|
163
|
+
### Interactive Analytics
|
|
164
|
+

|
|
165
|
+
*Model usage breakdown and task classification powered by Chart.js*
|
|
166
|
+
|
|
167
|
+
## How It Works
|
|
168
|
+
|
|
169
|
+
SmartMeter processes your data through a four-stage pipeline:
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
Session Logs (.jsonl)
|
|
173
|
+
|
|
|
174
|
+
[ Parser ] Stream-parse JSONL, extract assistant messages,
|
|
175
|
+
| pair with user prompts, normalize content formats
|
|
176
|
+
v
|
|
177
|
+
[ Classifier ] Keyword-based task categorization into
|
|
178
|
+
| code / write / research / config / other
|
|
179
|
+
v
|
|
180
|
+
[ Aggregator ] Per-model and per-category statistics,
|
|
181
|
+
| temporal patterns, caching metrics
|
|
182
|
+
v
|
|
183
|
+
[ Recommender ] Per-category model recommendations,
|
|
184
|
+
| savings calculations, confidence scoring
|
|
185
|
+
v
|
|
186
|
+
[ Config Generator ] Optimized openclaw.json with model routing,
|
|
187
|
+
agents, budgets, caching, fallback chains
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### What gets optimized
|
|
191
|
+
|
|
192
|
+
1. **Primary Model** — Switch to the cheapest model that handles your dominant workload
|
|
193
|
+
2. **Specialized Agents** — Auto-create agents for high-volume categories (e.g., a `code-reviewer` agent using DeepSeek for code tasks)
|
|
194
|
+
3. **Fallback Chains** — Ordered by cost so expensive models are only used when needed
|
|
195
|
+
4. **Budget Controls** — Daily/weekly caps with alert thresholds to prevent runaway costs
|
|
196
|
+
5. **Caching** — Long retention and heartbeat settings for burst usage patterns
|
|
197
|
+
6. **Skill Routing** — Ready for per-skill model assignment (awaiting skill log format)
|
|
198
|
+
|
|
199
|
+
## Architecture
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
src/
|
|
203
|
+
analyzer/ # Phase 1: Analysis engine
|
|
204
|
+
parser.js # JSONL stream parser with content normalization
|
|
205
|
+
classifier.js # Keyword-based task classifier
|
|
206
|
+
aggregator.js # Statistics aggregation
|
|
207
|
+
recommender.js # Optimization recommendations
|
|
208
|
+
storage.js # Analysis persistence
|
|
209
|
+
generator/ # Phase 2: Config generator
|
|
210
|
+
config-builder.js # Main orchestrator
|
|
211
|
+
agent-creator.js # Specialized agent creation
|
|
212
|
+
merger.js # Deep merge utility
|
|
213
|
+
validator.js # Config validation
|
|
214
|
+
canvas/ # Canvas dashboard
|
|
215
|
+
deployer.js # Dashboard deployment and public data generation
|
|
216
|
+
cli/ # Phase 3: CLI interface
|
|
217
|
+
index.js # Commander.js entry point (8 commands)
|
|
218
|
+
commands.js # Command handlers
|
|
219
|
+
utils.js # Formatting helpers
|
|
220
|
+
tests/ # 93 tests across all modules
|
|
221
|
+
canvas-template/ # Dashboard HTML/JS/CSS
|
|
222
|
+
docs/ # SPEC alignment, backlog, dashboard docs
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Testing
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
# Run all tests
|
|
229
|
+
npm test
|
|
230
|
+
|
|
231
|
+
# Run a specific test file
|
|
232
|
+
node --test tests/parser.test.js
|
|
233
|
+
|
|
234
|
+
# Run with verbose output
|
|
235
|
+
node --test --reporter spec tests/*.test.js
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
93 tests covering parser, classifier, aggregator, recommender, storage, config generator, and CLI commands.
|
|
239
|
+
|
|
240
|
+
## Documentation
|
|
241
|
+
|
|
242
|
+
- [SPEC.md](SPEC.md) — Full project specification (source of truth)
|
|
243
|
+
- [docs/SPEC_ALIGNMENT.md](docs/SPEC_ALIGNMENT.md) — Implementation status for each SPEC requirement
|
|
244
|
+
- [docs/backlog.md](docs/backlog.md) — Deferred features and future phases
|
|
245
|
+
- [docs/CANVAS_DASHBOARD.md](docs/CANVAS_DASHBOARD.md) — Dashboard quick start guide
|
|
246
|
+
- [docs/CANVAS_BUILD_NOTES.md](docs/CANVAS_BUILD_NOTES.md) — Dashboard build notes
|
|
247
|
+
- [CONTRIBUTING.md](CONTRIBUTING.md) — Contribution guidelines
|
|
248
|
+
- [SECURITY.md](SECURITY.md) — Security policy
|
|
249
|
+
|
|
250
|
+
## Roadmap
|
|
251
|
+
|
|
252
|
+
- [x] **Phase 1** — Analysis Engine (parser, classifier, aggregator, recommender)
|
|
253
|
+
- [x] **Phase 2** — Config Generator (model optimization, agents, budgets, caching)
|
|
254
|
+
- [x] **Phase 3** — CLI Interface (8 commands with `--data-dir` support)
|
|
255
|
+
- [x] **Canvas Dashboard** — Interactive web dashboard with charts and recommendations
|
|
256
|
+
- [ ] **Phase 4** — OpenRouter API integration for live pricing
|
|
257
|
+
- [ ] **Phase 5** — Telegram alerts and notifications
|
|
258
|
+
- [ ] **Phase 6** — Chrome extension for real-time monitoring
|
|
259
|
+
|
|
260
|
+
## Author
|
|
261
|
+
|
|
262
|
+
**Vajih Khan**
|
|
263
|
+
- LinkedIn: [linkedin.com/in/vajihkhan](https://www.linkedin.com/in/vajihkhan/)
|
|
264
|
+
- Twitter: [@vajih](https://twitter.com/vajih)
|
|
265
|
+
- GitHub: [@vajih](https://github.com/vajih)
|
|
266
|
+
|
|
267
|
+
Built with 30+ years of experience in technology innovation, product development, and AI optimization.
|
|
268
|
+
|
|
269
|
+
## License
|
|
270
|
+
|
|
271
|
+
[Apache License 2.0](LICENSE)
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
Built with [OpenClaw](https://openclaw.ai) and [Claude Code](https://claude.ai/claude-code)
|