@safetnsr/pinch 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/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # pinch
2
+
3
+ know what your agent costs — per session, per model, per day.
4
+
5
+ openclaw plugin that tracks every token and dollar your agent spends. no accounts, no cloud, no surprises.
6
+
7
+ ```
8
+ $ pinch_check
9
+
10
+ today: $4.82 (69% of $7.00 budget)
11
+ this week: $18.40
12
+ this month: $52.10
13
+
14
+ by model:
15
+ claude-opus-4-6 $3.40 71%
16
+ claude-sonnet-4-6 $1.20 25%
17
+ claude-haiku-3.5 $0.22 4%
18
+ ```
19
+
20
+ ---
21
+
22
+ ## install
23
+
24
+ ```bash
25
+ openclaw plugins install @safetnsr/pinch
26
+ ```
27
+
28
+ no config needed. pinch starts tracking immediately.
29
+
30
+ open the dashboard at `http://localhost:3334`.
31
+
32
+ ---
33
+
34
+ ## what you get
35
+
36
+ ### agent tools
37
+
38
+ three tools the agent can call directly:
39
+
40
+ **`pinch_check`** — current spend across today / week / month, with model breakdown
41
+
42
+ **`pinch_breakdown`** — top sessions by cost, useful for spotting expensive crons or heartbeats
43
+
44
+ ```
45
+ top sessions today:
46
+ 1. readme rewrite $0.85
47
+ 2. twitter cron (8 runs) $0.72
48
+ 3. heartbeats (48 runs) $0.42
49
+ ```
50
+
51
+ **`pinch_budget`** — budget status with projection and optimization hints
52
+
53
+ ```
54
+ daily: $4.82 / $7.00 (69%) — on track
55
+ projected: $6.20 today
56
+
57
+ suggestion: heartbeats cost $0.42/day — consider extending interval
58
+ ```
59
+
60
+ ### dashboard
61
+
62
+ one page at `http://localhost:3334`. kpi strip, budget bar, 7d/30d/90d trend chart, breakdown by model/type/session, latest runs. auto-refreshes every 30s. dark mode. 12KB single HTML file.
63
+
64
+ ### budget alerts
65
+
66
+ alerts fire in your chat at 50%, 80%, and 100% of budget. deduplicated per day.
67
+
68
+ ---
69
+
70
+ ## config
71
+
72
+ everything is optional.
73
+
74
+ ```json
75
+ {
76
+ "budget": {
77
+ "daily": 7.00,
78
+ "weekly": 35.00,
79
+ "monthly": 100.00,
80
+ "enforcement": "warn",
81
+ "alertAt": [0.5, 0.8, 1.0]
82
+ },
83
+ "dashboard": { "enabled": true, "port": 3334 },
84
+ "pricing": {
85
+ "my-local-model": { "input": 0, "output": 0 }
86
+ },
87
+ "retentionDays": 90
88
+ }
89
+ ```
90
+
91
+ `enforcement`: `"warn"` logs only · `"throttle"` slows requests · `"block"` halts new sessions.
92
+
93
+ ---
94
+
95
+ ## how it works
96
+
97
+ **cost resolution order:**
98
+ 1. provider-reported cost from api response (most accurate)
99
+ 2. calculated from built-in pricing table
100
+ 3. user config override
101
+ 4. unknown model — tokens tracked, cost = $0
102
+
103
+ **model name normalization:**
104
+ - strips provider prefixes: `anthropic/claude-opus-4` → `claude-opus-4`
105
+ - strips date suffixes: `claude-opus-4-20250514` → `claude-opus-4`
106
+ - resolves aliases: `claude-3-5-haiku` → `claude-haiku-3.5`
107
+
108
+ **storage** — local only, `~/.openclaw/data/pinch/`. raw jsonl records (90d), daily/weekly/monthly aggregates (forever). ~4MB after 2 years of heavy use.
109
+
110
+ **pricing:** ships with 25+ models across 8 providers. to add or update:
111
+
112
+ ```json
113
+ {
114
+ "pricing": {
115
+ "new-model": { "input": 1.00, "output": 5.00 }
116
+ }
117
+ }
118
+ ```
119
+
120
+ or open a PR — pricing PRs merge fast.
121
+
122
+ ---
123
+
124
+ ## development
125
+
126
+ ```bash
127
+ git clone https://github.com/safetnsr/pinch
128
+ cd pinch
129
+ npm install
130
+ npm run build
131
+ npm test
132
+ ```
133
+
134
+ ## license
135
+
136
+ MIT
package/bin/pinch.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ console.log('pinch — know what your agent costs');
4
+ console.log('This is an openclaw plugin. Install via: openclaw plugins install @safetnsr/pinch');
5
+ console.log('Dashboard: http://localhost:3334');
@@ -0,0 +1,45 @@
1
+ {
2
+ "id": "pinch",
3
+ "name": "pinch",
4
+ "version": "0.1.0",
5
+ "description": "know what your agent costs — openclaw cost tracking plugin",
6
+ "configSchema": {
7
+ "type": "object",
8
+ "properties": {
9
+ "budget": {
10
+ "type": "object",
11
+ "description": "Budget limits in USD",
12
+ "properties": {
13
+ "daily": { "type": "number", "description": "Daily budget in USD" },
14
+ "weekly": { "type": "number", "description": "Weekly budget in USD" },
15
+ "monthly": { "type": "number", "description": "Monthly budget in USD" }
16
+ }
17
+ },
18
+ "dashboard": {
19
+ "type": "object",
20
+ "properties": {
21
+ "enabled": { "type": "boolean", "default": true },
22
+ "port": { "type": "number", "default": 3334 }
23
+ }
24
+ },
25
+ "pricing": {
26
+ "type": "object",
27
+ "description": "Model pricing overrides (USD per million tokens)",
28
+ "additionalProperties": {
29
+ "type": "object",
30
+ "properties": {
31
+ "input": { "type": "number" },
32
+ "output": { "type": "number" },
33
+ "cacheRead": { "type": "number" },
34
+ "cacheWrite": { "type": "number" }
35
+ }
36
+ }
37
+ },
38
+ "retentionDays": {
39
+ "type": "number",
40
+ "default": 90,
41
+ "description": "Days to retain raw JSONL records"
42
+ }
43
+ }
44
+ }
45
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@safetnsr/pinch",
3
+ "version": "0.1.0",
4
+ "description": "know what your agent costs — openclaw cost tracking plugin",
5
+ "type": "module",
6
+ "main": "./server/plugin.js",
7
+ "bin": {
8
+ "pinch": "./bin/pinch.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsup",
12
+ "test": "npx tsx --test tests/*.test.ts"
13
+ },
14
+ "openclaw": {
15
+ "extensions": [
16
+ "./server/plugin.js"
17
+ ]
18
+ },
19
+ "dependencies": {
20
+ "@hono/node-server": "^1.14.0",
21
+ "hono": "^4.7.0"
22
+ },
23
+ "devDependencies": {
24
+ "tsup": "^8.4.0",
25
+ "tsx": "^4.21.0",
26
+ "typescript": "^5.7.0"
27
+ },
28
+ "files": [
29
+ "server/",
30
+ "pricing.json",
31
+ "openclaw.plugin.json",
32
+ "bin/",
33
+ "README.md"
34
+ ],
35
+ "engines": {
36
+ "node": ">=20"
37
+ },
38
+ "author": "safetnsr",
39
+ "keywords": [
40
+ "openclaw",
41
+ "cost-tracking",
42
+ "agent",
43
+ "budget",
44
+ "llm"
45
+ ],
46
+ "license": "MIT",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/safetnsr/pinch.git"
50
+ }
51
+ }
package/pricing.json ADDED
@@ -0,0 +1,278 @@
1
+ {
2
+ "version": 5,
3
+ "updatedAt": "2026-02-26",
4
+ "models": {
5
+ "claude-opus-4": {
6
+ "provider": "anthropic",
7
+ "input": 15.0,
8
+ "output": 75.0,
9
+ "cacheRead": 1.5,
10
+ "cacheWrite": 18.75,
11
+ "effectiveDate": "2025-05-14",
12
+ "source": "https://docs.anthropic.com/en/docs/about-claude/models"
13
+ },
14
+ "claude-sonnet-4": {
15
+ "provider": "anthropic",
16
+ "input": 3.0,
17
+ "output": 15.0,
18
+ "cacheRead": 0.3,
19
+ "cacheWrite": 3.75,
20
+ "effectiveDate": "2025-05-14",
21
+ "source": "https://docs.anthropic.com/en/docs/about-claude/models"
22
+ },
23
+ "claude-haiku-3.5": {
24
+ "provider": "anthropic",
25
+ "input": 0.8,
26
+ "output": 4.0,
27
+ "cacheRead": 0.08,
28
+ "cacheWrite": 1.0,
29
+ "effectiveDate": "2024-10-29",
30
+ "source": "https://docs.anthropic.com/en/docs/about-claude/models"
31
+ },
32
+ "gpt-4o": {
33
+ "provider": "openai",
34
+ "input": 2.5,
35
+ "output": 10.0,
36
+ "effectiveDate": "2024-05-13",
37
+ "source": "https://openai.com/api/pricing"
38
+ },
39
+ "gpt-4o-mini": {
40
+ "provider": "openai",
41
+ "input": 0.15,
42
+ "output": 0.6,
43
+ "effectiveDate": "2024-07-18",
44
+ "source": "https://openai.com/api/pricing"
45
+ },
46
+ "gpt-4.1": {
47
+ "provider": "openai",
48
+ "input": 2.0,
49
+ "output": 8.0,
50
+ "effectiveDate": "2025-04-14",
51
+ "source": "https://openai.com/api/pricing"
52
+ },
53
+ "gpt-4.1-mini": {
54
+ "provider": "openai",
55
+ "input": 0.4,
56
+ "output": 1.6,
57
+ "effectiveDate": "2025-04-14",
58
+ "source": "https://openai.com/api/pricing"
59
+ },
60
+ "gpt-4.1-nano": {
61
+ "provider": "openai",
62
+ "input": 0.1,
63
+ "output": 0.4,
64
+ "effectiveDate": "2025-04-14",
65
+ "source": "https://openai.com/api/pricing"
66
+ },
67
+ "o3": {
68
+ "provider": "openai",
69
+ "input": 2.0,
70
+ "output": 8.0,
71
+ "effectiveDate": "2025-04-16",
72
+ "source": "https://openai.com/api/pricing"
73
+ },
74
+ "o4-mini": {
75
+ "provider": "openai",
76
+ "input": 1.1,
77
+ "output": 4.4,
78
+ "effectiveDate": "2025-04-16",
79
+ "source": "https://openai.com/api/pricing"
80
+ },
81
+ "gemini-2.5-pro": {
82
+ "provider": "google",
83
+ "input": 1.25,
84
+ "output": 10.0,
85
+ "effectiveDate": "2025-03-25",
86
+ "source": "https://ai.google.dev/pricing"
87
+ },
88
+ "gemini-2.5-flash": {
89
+ "provider": "google",
90
+ "input": 0.15,
91
+ "output": 0.6,
92
+ "effectiveDate": "2025-04-17",
93
+ "source": "https://ai.google.dev/pricing"
94
+ },
95
+ "gemini-2.0-flash": {
96
+ "provider": "google",
97
+ "input": 0.1,
98
+ "output": 0.4,
99
+ "effectiveDate": "2025-02-05",
100
+ "source": "https://ai.google.dev/pricing"
101
+ },
102
+ "deepseek-chat": {
103
+ "provider": "deepseek",
104
+ "input": 0.27,
105
+ "output": 1.1,
106
+ "cacheRead": 0.07,
107
+ "effectiveDate": "2025-02-08",
108
+ "source": "https://platform.deepseek.com/api-docs/pricing"
109
+ },
110
+ "deepseek-reasoner": {
111
+ "provider": "deepseek",
112
+ "input": 0.55,
113
+ "output": 2.19,
114
+ "effectiveDate": "2025-02-08",
115
+ "source": "https://platform.deepseek.com/api-docs/pricing"
116
+ },
117
+ "mistral-large": {
118
+ "provider": "mistral",
119
+ "input": 2.0,
120
+ "output": 6.0,
121
+ "effectiveDate": "2025-01-29",
122
+ "source": "https://mistral.ai/products/la-plateforme#pricing"
123
+ },
124
+ "codestral": {
125
+ "provider": "mistral",
126
+ "input": 0.3,
127
+ "output": 0.9,
128
+ "effectiveDate": "2025-01-29",
129
+ "source": "https://mistral.ai/products/la-plateforme#pricing"
130
+ },
131
+ "grok-3": {
132
+ "provider": "xai",
133
+ "input": 3.0,
134
+ "output": 15.0,
135
+ "effectiveDate": "2025-02-18",
136
+ "source": "https://docs.x.ai/docs/models"
137
+ },
138
+ "grok-3-mini": {
139
+ "provider": "xai",
140
+ "input": 0.3,
141
+ "output": 0.5,
142
+ "effectiveDate": "2025-02-18",
143
+ "source": "https://docs.x.ai/docs/models"
144
+ },
145
+ "llama-4-maverick": {
146
+ "provider": "meta",
147
+ "input": 0.2,
148
+ "output": 0.6,
149
+ "effectiveDate": "2025-04-05",
150
+ "note": "pricing varies by host provider"
151
+ },
152
+ "llama-4-scout": {
153
+ "provider": "meta",
154
+ "input": 0.15,
155
+ "output": 0.4,
156
+ "effectiveDate": "2025-04-05",
157
+ "note": "pricing varies by host provider"
158
+ },
159
+ "gpt-5": {
160
+ "provider": "openai",
161
+ "input": 1.25,
162
+ "output": 10.0,
163
+ "cacheRead": 0.125,
164
+ "effectiveDate": "2025-08-07",
165
+ "source": "https://platform.openai.com/docs/pricing"
166
+ },
167
+ "gpt-5-mini": {
168
+ "provider": "openai",
169
+ "input": 0.25,
170
+ "output": 2.0,
171
+ "cacheRead": 0.025,
172
+ "effectiveDate": "2025-08-07",
173
+ "source": "https://platform.openai.com/docs/pricing"
174
+ },
175
+ "gpt-5.1": {
176
+ "provider": "openai",
177
+ "input": 1.25,
178
+ "output": 10.0,
179
+ "cacheRead": 0.125,
180
+ "effectiveDate": "2026-01-01",
181
+ "source": "https://platform.openai.com/docs/pricing"
182
+ },
183
+ "gpt-5.2": {
184
+ "provider": "openai",
185
+ "input": 1.75,
186
+ "output": 14.0,
187
+ "cacheRead": 0.175,
188
+ "effectiveDate": "2025-12-10",
189
+ "source": "https://platform.openai.com/docs/pricing"
190
+ },
191
+ "claude-opus-4-6": {
192
+ "provider": "anthropic",
193
+ "input": 5.0,
194
+ "output": 25.0,
195
+ "cacheRead": 0.5,
196
+ "cacheWrite": 6.25,
197
+ "effectiveDate": "2025-08-07",
198
+ "source": "https://platform.claude.com/docs/en/about-claude/pricing"
199
+ },
200
+ "claude-opus-4-5": {
201
+ "provider": "anthropic",
202
+ "input": 5.0,
203
+ "output": 25.0,
204
+ "cacheRead": 0.5,
205
+ "cacheWrite": 6.25,
206
+ "effectiveDate": "2025-06-19",
207
+ "source": "https://platform.claude.com/docs/en/about-claude/pricing"
208
+ },
209
+ "claude-opus-4-1": {
210
+ "provider": "anthropic",
211
+ "input": 15.0,
212
+ "output": 75.0,
213
+ "cacheRead": 1.5,
214
+ "cacheWrite": 18.75,
215
+ "effectiveDate": "2025-05-14",
216
+ "source": "https://platform.claude.com/docs/en/about-claude/pricing"
217
+ },
218
+ "claude-sonnet-4-6": {
219
+ "provider": "anthropic",
220
+ "input": 3.0,
221
+ "output": 15.0,
222
+ "cacheRead": 0.3,
223
+ "cacheWrite": 3.75,
224
+ "effectiveDate": "2025-08-07",
225
+ "source": "https://platform.claude.com/docs/en/about-claude/pricing"
226
+ },
227
+ "claude-sonnet-4-5": {
228
+ "provider": "anthropic",
229
+ "input": 3.0,
230
+ "output": 15.0,
231
+ "cacheRead": 0.3,
232
+ "cacheWrite": 3.75,
233
+ "effectiveDate": "2025-06-19",
234
+ "source": "https://platform.claude.com/docs/en/about-claude/pricing"
235
+ },
236
+ "claude-haiku-4-5": {
237
+ "provider": "anthropic",
238
+ "input": 1.0,
239
+ "output": 5.0,
240
+ "cacheRead": 0.1,
241
+ "cacheWrite": 1.25,
242
+ "effectiveDate": "2025-10-01",
243
+ "source": "https://platform.claude.com/docs/en/about-claude/pricing"
244
+ }
245
+ },
246
+ "aliases": {
247
+ "claude-opus-4-20250514": "claude-opus-4",
248
+ "claude-opus-4-0514": "claude-opus-4",
249
+ "claude-sonnet-4-20250514": "claude-sonnet-4",
250
+ "claude-sonnet-4-0514": "claude-sonnet-4",
251
+ "claude-3-5-haiku-20241022": "claude-haiku-3.5",
252
+ "claude-3-5-haiku": "claude-haiku-3.5",
253
+ "gpt-4o-2024-11-20": "gpt-4o",
254
+ "gpt-4o-mini-2024-07-18": "gpt-4o-mini",
255
+ "deepseek-chat-v3": "deepseek-chat",
256
+ "deepseek-r1": "deepseek-reasoner",
257
+ "claude-opus-4-6-20250807": "claude-opus-4-6",
258
+ "claude-opus-4-5-20250619": "claude-opus-4-5",
259
+ "claude-sonnet-4-6-20250807": "claude-sonnet-4-6",
260
+ "claude-sonnet-4-5-20250619": "claude-sonnet-4-5",
261
+ "claude-haiku-4-5-20251001": "claude-haiku-4-5",
262
+ "claude-haiku-4-5": "claude-haiku-4-5",
263
+ "gpt-5-chat-latest": "gpt-5",
264
+ "gpt-5.1-chat-latest": "gpt-5.1",
265
+ "gpt-5.2-chat-latest": "gpt-5.2"
266
+ },
267
+ "providerPrefixes": [
268
+ "anthropic/",
269
+ "openai/",
270
+ "google/",
271
+ "deepseek/",
272
+ "mistralai/",
273
+ "meta-llama/",
274
+ "xai/",
275
+ "cohere/",
276
+ "together/"
277
+ ]
278
+ }