@hasna/economy 0.2.21 → 0.2.23

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/LICENSE CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  Apache License
3
2
  Version 2.0, January 2004
4
3
  http://www.apache.org/licenses/
@@ -176,7 +175,7 @@
176
175
 
177
176
  END OF TERMS AND CONDITIONS
178
177
 
179
- Copyright 2026 Hasna, Inc.
178
+ Copyright 2026 hasna
180
179
 
181
180
  Licensed under the Apache License, Version 2.0 (the "License");
182
181
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -1,14 +1,16 @@
1
1
  # @hasna/economy
2
2
 
3
- AI coding cost tracker for Claude Code, Takumi, Codex, and Gemini. It ships as a CLI, MCP server, REST API, web dashboard, and native macOS menu bar app.
3
+ AI coding cost tracker for Claude Code, Takumi, Codex, Gemini, OpenCode, Cursor, Pi, and Hermes. It ships as a CLI, MCP server, REST API, web dashboard, and native macOS menu bar app.
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/@hasna/economy)](https://www.npmjs.com/package/@hasna/economy)
6
6
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
7
7
 
8
8
  ## Features
9
9
 
10
- - Ingests local Claude Code, Takumi, Codex, and Gemini CLI usage.
10
+ - Ingests local Claude Code, Takumi, Codex, Gemini, OpenCode, Cursor, Pi, and Hermes usage.
11
11
  - Tracks sessions, requests, projects, machines, models, cache tokens, budgets, goals, and provider billing.
12
+ - Attributes usage to `@hasna/accounts` profiles when agents run under managed account/profile config dirs.
13
+ - Breaks down API-equivalent, metered API, subscription-included, estimated, and unknown cost by account and coding agent.
12
14
  - Seeds editable model pricing with input, output, cache-read, 5-minute cache-write, 1-hour cache-write, and context-cache storage rates.
13
15
  - Handles tiered pricing such as Gemini long-prompt rates and OpenAI long-context rates.
14
16
  - Reconciles estimates against Anthropic, OpenAI, and Gemini billing sources.
@@ -69,7 +71,7 @@ Gemini settings:
69
71
  }
70
72
  ```
71
73
 
72
- The MCP server exposes read tools for summaries, sessions, machines, pricing, daily spend, budgets, goals, and provider billing. It also exposes mutation tools for budgets, pricing rows, and goals so Claude Code, Codex, and Gemini can manage Economy data through the same validated surface as the CLI and REST API.
74
+ The MCP server exposes read tools for summaries, sessions, machines, pricing, daily spend, budgets, goals, provider billing, usage snapshots, savings, project/account/agent breakdowns, and subscriptions. It also exposes mutation tools for budgets, pricing rows, goals, and subscriptions so coding agents can manage Economy data through the same validated surface as the CLI and REST API.
73
75
 
74
76
  ## Ingest
75
77
 
@@ -86,6 +88,10 @@ economy sync --claude
86
88
  economy sync --codex
87
89
  economy sync --gemini
88
90
  economy sync --takumi
91
+ economy sync --opencode
92
+ economy sync --cursor
93
+ economy sync --pi
94
+ economy sync --hermes
89
95
  ```
90
96
 
91
97
  Useful repair options:
@@ -98,6 +104,19 @@ economy sync --backfill-machine
98
104
 
99
105
  Full sync also imports active project metadata from `@hasna/projects` when the registry is available.
100
106
 
107
+ Account attribution is automatic when `@hasna/accounts` has a matching active, applied, or env-dir profile for the agent. You can also force attribution for a process with `ECONOMY_ACCOUNT=tool:name` or agent-specific overrides such as `ECONOMY_CODEX_ACCOUNT=codex:work`.
108
+
109
+ Account breakdowns report `api_equivalent_usd` for the API list-price value of the usage, plus `billable_usd`/`metered_api_usd` for known direct API spend and `subscription_included_usd` for usage covered by a subscription.
110
+
111
+ Subscription plans can be configured locally and are used by savings calculations:
112
+
113
+ ```bash
114
+ economy subscriptions set --provider cursor --plan pro --fee 20 --included 20 --agent cursor
115
+ economy subscriptions list
116
+ economy savings month
117
+ economy usage month --agent cursor
118
+ ```
119
+
101
120
  ## Pricing
102
121
 
103
122
  Default pricing is seeded into SQLite and can be edited locally:
@@ -145,7 +164,7 @@ economy config set webhook-url https://example.com/economy-webhook
145
164
  economy config webhook-test
146
165
  ```
147
166
 
148
- Budgets and goals can be global, project-scoped with `--project`, agent-scoped with `--agent`, or both. Valid agent scopes are `claude`, `takumi`, `codex`, and `gemini`.
167
+ Budgets and goals can be global, project-scoped with `--project`, agent-scoped with `--agent`, or both. Valid agent scopes are `claude`, `takumi`, `codex`, `gemini`, `opencode`, `cursor`, `pi`, and `hermes`.
149
168
 
150
169
  Budget webhooks fire after sync when the alert threshold is crossed. Failed webhook deliveries are not marked as fired, so the next sync can retry them.
151
170
 
@@ -164,7 +183,14 @@ Common endpoints:
164
183
  - `GET /api/sessions?agent=codex&limit=20`
165
184
  - `GET /api/sessions/:id/requests`
166
185
  - `GET /api/models`
167
- - `GET /api/projects`
186
+ - `GET /api/projects?period=month`
187
+ - `GET /api/breakdown?by=agent&period=month`
188
+ - `GET /api/accounts?period=month`
189
+ - `GET /api/usage?period=month`
190
+ - `GET /api/savings?period=month`
191
+ - `GET /api/subscriptions`
192
+ - `POST /api/subscriptions`
193
+ - `DELETE /api/subscriptions/:id`
168
194
  - `GET /api/budgets`
169
195
  - `POST /api/budgets`
170
196
  - `DELETE /api/budgets/:id`
@@ -178,13 +204,13 @@ Common endpoints:
178
204
  - `POST /api/sync`
179
205
  - `POST /api/billing/sync`
180
206
 
181
- Budget and goal mutation endpoints validate agent scopes against `claude`, `takumi`, `codex`, and `gemini`.
207
+ Budget, goal, and subscription mutation endpoints validate agent scopes against `claude`, `takumi`, `codex`, `gemini`, `opencode`, `cursor`, `pi`, and `hermes`.
182
208
 
183
209
  The server also serves the built dashboard when `dashboard/dist` is present.
184
210
 
185
211
  ## Native macOS Menubar
186
212
 
187
- The `menubar/` app is a native SwiftUI `MenuBarExtra` app, not Electron. It targets Swift 5.9+ and macOS 14+, and talks to the REST API exposed by `economy-serve`. The default server URL is `http://127.0.0.1:3456`.
213
+ The `menubar/` app is a native SwiftUI `MenuBarExtra` app, not Electron. It targets Swift 5.9+ and macOS 14+, and talks to the REST API exposed by `economy-serve`. It shows today/week/month spend, token and request counts, top agents, top accounts, top projects, subscription savings, usage snapshots, recent sessions, and fleet status. The default server URL is `http://127.0.0.1:3456`.
188
214
 
189
215
  Build it on macOS:
190
216
 
@@ -229,19 +255,6 @@ cd dashboard && bun run lint
229
255
  cd menubar && swift build -c release
230
256
  ```
231
257
 
232
- ## HTTP mode
233
-
234
- Shared Streamable HTTP transport for multi-agent sessions (stdio remains the default):
235
-
236
- ```bash
237
- economy-mcp --http # http://127.0.0.1:8815/mcp
238
- MCP_HTTP=1 economy-mcp # same
239
- economy-mcp --http --port 8815 # explicit port
240
- ```
241
-
242
- - Health: `GET http://127.0.0.1:8815/health` → `{"status":"ok","name":"economy"}`
243
- - Override port with `MCP_HTTP_PORT` or `--port`
244
-
245
258
  ## License
246
259
 
247
260
  Apache-2.0 -- see [LICENSE](LICENSE)
@@ -1 +1 @@
1
- {"version":3,"file":"extras.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/extras.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA+CnC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA0R/D;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAkC5D"}
1
+ {"version":3,"file":"extras.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/extras.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA6CnC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA0R/D;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAkC5D"}