@hasna/economy 0.3.7 → 0.3.8
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/CHANGELOG.md +0 -4
- package/README.md +28 -61
- package/dashboard/README.md +17 -64
- package/dist/cli/index.js +221 -114
- package/dist/db/cloud.d.ts +3 -4
- package/dist/db/cloud.d.ts.map +1 -1
- package/dist/db/database.d.ts +2 -2
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/dialect.d.ts +13 -0
- package/dist/db/dialect.d.ts.map +1 -0
- package/dist/db/pg-migrate.d.ts +30 -0
- package/dist/db/pg-migrate.d.ts.map +1 -0
- package/dist/db/sqlite-adapter.d.ts +36 -0
- package/dist/db/sqlite-adapter.d.ts.map +1 -0
- package/dist/db/sync-pg.d.ts +1 -1
- package/dist/db/sync-pg.d.ts.map +1 -1
- package/dist/index.js +129 -56
- package/dist/ingest/billing.d.ts +1 -1
- package/dist/ingest/billing.d.ts.map +1 -1
- package/dist/ingest/claude-quota.d.ts +1 -1
- package/dist/ingest/claude-quota.d.ts.map +1 -1
- package/dist/ingest/claude.d.ts +1 -1
- package/dist/ingest/claude.d.ts.map +1 -1
- package/dist/ingest/codex-quota.d.ts +1 -1
- package/dist/ingest/codex-quota.d.ts.map +1 -1
- package/dist/ingest/codex.d.ts +1 -1
- package/dist/ingest/codex.d.ts.map +1 -1
- package/dist/ingest/cursor.d.ts +1 -1
- package/dist/ingest/cursor.d.ts.map +1 -1
- package/dist/ingest/gemini.d.ts +1 -1
- package/dist/ingest/gemini.d.ts.map +1 -1
- package/dist/ingest/hermes.d.ts +1 -1
- package/dist/ingest/hermes.d.ts.map +1 -1
- package/dist/ingest/loops.d.ts +1 -1
- package/dist/ingest/loops.d.ts.map +1 -1
- package/dist/ingest/opencode.d.ts +1 -1
- package/dist/ingest/opencode.d.ts.map +1 -1
- package/dist/ingest/otel.d.ts +1 -1
- package/dist/ingest/otel.d.ts.map +1 -1
- package/dist/ingest/pi.d.ts +1 -1
- package/dist/ingest/pi.d.ts.map +1 -1
- package/dist/ingest/plugin.d.ts +1 -1
- package/dist/ingest/plugin.d.ts.map +1 -1
- package/dist/lib/accounts.d.ts.map +1 -1
- package/dist/lib/analytics.d.ts +1 -1
- package/dist/lib/analytics.d.ts.map +1 -1
- package/dist/lib/billing-diff.d.ts +1 -1
- package/dist/lib/billing-diff.d.ts.map +1 -1
- package/dist/lib/brief.d.ts +1 -1
- package/dist/lib/brief.d.ts.map +1 -1
- package/dist/lib/open-projects.d.ts +10 -2
- package/dist/lib/open-projects.d.ts.map +1 -1
- package/dist/lib/pricing.d.ts +1 -1
- package/dist/lib/pricing.d.ts.map +1 -1
- package/dist/lib/savings.d.ts +1 -1
- package/dist/lib/savings.d.ts.map +1 -1
- package/dist/lib/spikes.d.ts +1 -1
- package/dist/lib/spikes.d.ts.map +1 -1
- package/dist/lib/sync-all.d.ts +1 -1
- package/dist/lib/sync-all.d.ts.map +1 -1
- package/dist/lib/webhooks.d.ts +1 -1
- package/dist/lib/webhooks.d.ts.map +1 -1
- package/dist/mcp/index.js +144 -94
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/otel/index.js +69 -4
- package/dist/server/index.js +248 -88
- package/dist/server/serve.d.ts +1 -1
- package/dist/server/serve.d.ts.map +1 -1
- package/docs/README.md +12 -0
- package/docs/cli.md +88 -0
- package/docs/configuration.md +86 -0
- package/docs/ingestion.md +47 -0
- package/docs/mcp.md +65 -0
- package/docs/otel.md +53 -0
- package/docs/rest-api.md +89 -0
- package/package.json +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -29,10 +29,6 @@ three-way merge that keeps **both** histories.
|
|
|
29
29
|
(and with it the `cloud schedule install|status|remove` commands) and
|
|
30
30
|
`src/lib/fleet-sync.ts`. The MCP `sync` tool no longer reports `cloud_pushed` /
|
|
31
31
|
`cloud_pulled` because `SyncAllResult` no longer carries them.
|
|
32
|
-
- Replaced the `@hasna/agent-registry` and `@hasna/mcp-harness` `file:../open-*`
|
|
33
|
-
sibling pins with the registry ranges (`^0.1.0`) that every published tarball has
|
|
34
|
-
carried anyway. `bun install`, `tsc` and `src/mcp/http.test.ts` no longer require
|
|
35
|
-
unpublished sibling checkouts, and `package.json` now matches what actually ships.
|
|
36
32
|
- Bumped strictly above the published `0.3.6` latest. (The `v0.3.6` tag commit itself
|
|
37
33
|
carried `package.json` version `0.3.5`; the `0.3.6` publish bumped the registry
|
|
38
34
|
without a follow-up commit.)
|
package/README.md
CHANGED
|
@@ -39,6 +39,15 @@ Open the dashboard with:
|
|
|
39
39
|
economy dashboard --port 3456
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
- [CLI reference](docs/cli.md)
|
|
45
|
+
- [Ingestion sources and attribution](docs/ingestion.md)
|
|
46
|
+
- [Configuration, storage modes, and deployment](docs/configuration.md)
|
|
47
|
+
- [REST API](docs/rest-api.md)
|
|
48
|
+
- [MCP server](docs/mcp.md)
|
|
49
|
+
- [OTLP/HTTP sidecar](docs/otel.md)
|
|
50
|
+
|
|
42
51
|
## CLI Output Defaults
|
|
43
52
|
|
|
44
53
|
Economy CLI commands are compact by default so agent terminals do not fill their context with full records. High-cardinality list and status commands show essential columns, cap row counts, and print a hint when more rows are available.
|
|
@@ -55,7 +64,7 @@ economy todos list --verbose
|
|
|
55
64
|
economy todos show 9.7
|
|
56
65
|
```
|
|
57
66
|
|
|
58
|
-
`--json` remains the machine-readable path for commands that support it. Human output may truncate rows or long text; use `--json`, `--
|
|
67
|
+
`--json` remains the machine-readable path for commands that support it. Human output may truncate rows or long text; use `--json`, `--limit`, or a `show`/detail command for complete data. `--verbose` expands output where supported; its exact limit is command-specific (for example, `economy session --verbose` shows up to 50 requests).
|
|
59
68
|
|
|
60
69
|
Status subcommands follow the same rule. For example, `economy goal status` prints a compact human summary by default and `economy goal status --limit 5` or `--verbose` controls how many goals are listed.
|
|
61
70
|
|
|
@@ -91,7 +100,7 @@ Gemini settings:
|
|
|
91
100
|
}
|
|
92
101
|
```
|
|
93
102
|
|
|
94
|
-
The MCP server exposes read tools for summaries, sessions, machines, pricing, daily spend, budgets, goals, provider billing, usage snapshots, savings, project/account/agent/cost-center breakdowns, and subscriptions. MCP tools are compact by default for agent context safety; high-cardinality tools accept `limit`, `verbose`, or `json=true` where raw structured output is useful. 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.
|
|
103
|
+
The MCP server exposes read tools for summaries, sessions, machines, pricing, daily spend, budgets, goals, provider billing, usage snapshots, savings, project/account/agent/cost-center breakdowns, and subscriptions. MCP tools are compact by default for agent context safety; high-cardinality tools accept `limit`, `verbose`, or `json=true` where raw structured output is useful. 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. See the [MCP guide](docs/mcp.md) for HTTP mode and the complete tool list.
|
|
95
104
|
|
|
96
105
|
## Ingest
|
|
97
106
|
|
|
@@ -125,7 +134,7 @@ economy sync --recalculate
|
|
|
125
134
|
economy sync --backfill-machine
|
|
126
135
|
```
|
|
127
136
|
|
|
128
|
-
Full sync also imports active project metadata from `@hasna/projects` when the registry is available. The Codex source reads both
|
|
137
|
+
Full sync also imports active project metadata from `@hasna/projects` when the registry is available. The Codex source reads both `~/.codex/state_5.sqlite` and the Codewith store at `~/.codewith/state_5.sqlite` by default; explicit `HASNA_ECONOMY_CODEX_DB_PATH` and `HASNA_ECONOMY_CODEWITH_DB_PATH` values override those locations.
|
|
129
138
|
|
|
130
139
|
Account attribution is automatic when `@hasna/accounts` has a matching active, applied, or env-dir profile for the agent. Account identity is the email address plus coding agent, so `work@example.com` under Codex and Claude is reported as two accounts. You can also force attribution for a process with `ECONOMY_ACCOUNT=tool:name` or agent-specific overrides such as `ECONOMY_CODEX_ACCOUNT=codex:work`.
|
|
131
140
|
|
|
@@ -157,7 +166,7 @@ curl -X POST http://127.0.0.1:4318/ingest \
|
|
|
157
166
|
-d '{"source":"app","cost_center":"alumia","cost_center_kind":"app","project_path":"/workspace/alumia","model":"gpt-5-mini","cost_usd":0.12,"input_tokens":1200,"output_tokens":300}'
|
|
158
167
|
```
|
|
159
168
|
|
|
160
|
-
Accepted `/ingest` attribution fields include `cost_center`, `cost_center_kind`, `cost_center_id`, `attribution_tag`, `project_path`, `repo`, `account_key`, `account_tool`, `account_name`, `account_email`, and explicit `cost_usd`.
|
|
169
|
+
Accepted `/ingest` attribution fields include `cost_center`, `cost_center_kind`, `cost_center_id`, `attribution_tag`, `project_path`, `repo`, `account_key`, `account_tool`, `account_name`, `account_email`, and explicit `cost_usd`. The [OTLP guide](docs/otel.md) documents both payload formats and all aliases.
|
|
161
170
|
|
|
162
171
|
Subscription plans can be configured locally and are used by savings calculations:
|
|
163
172
|
|
|
@@ -187,7 +196,7 @@ OpenRouter-style model IDs ending in `:free` are treated as zero-cost variants e
|
|
|
187
196
|
|
|
188
197
|
## Billing
|
|
189
198
|
|
|
190
|
-
Estimated costs can be reconciled with provider billing:
|
|
199
|
+
Estimated costs can be reconciled with provider billing in local mode:
|
|
191
200
|
|
|
192
201
|
```bash
|
|
193
202
|
economy billing sync --days 31
|
|
@@ -228,37 +237,16 @@ Start the server:
|
|
|
228
237
|
economy-serve --port 3456
|
|
229
238
|
```
|
|
230
239
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
- `GET /health`
|
|
234
|
-
- `GET /
|
|
235
|
-
- `GET /
|
|
236
|
-
- `GET /
|
|
237
|
-
- `
|
|
238
|
-
- `
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
- `GET /api/breakdown?by=loop&period=month`
|
|
242
|
-
- `GET /api/accounts?period=month`
|
|
243
|
-
- `GET /api/usage?period=month`
|
|
244
|
-
- `GET /api/savings?period=month`
|
|
245
|
-
- `GET /api/subscriptions`
|
|
246
|
-
- `POST /api/subscriptions`
|
|
247
|
-
- `DELETE /api/subscriptions/:id`
|
|
248
|
-
- `GET /api/budgets`
|
|
249
|
-
- `POST /api/budgets`
|
|
250
|
-
- `DELETE /api/budgets/:id`
|
|
251
|
-
- `GET /api/pricing`
|
|
252
|
-
- `POST /api/pricing`
|
|
253
|
-
- `DELETE /api/pricing/:model`
|
|
254
|
-
- `GET /api/goals`
|
|
255
|
-
- `POST /api/goals`
|
|
256
|
-
- `DELETE /api/goals/:id`
|
|
257
|
-
- `GET /api/billing?period=month`
|
|
258
|
-
- `POST /api/sync`
|
|
259
|
-
- `POST /api/billing/sync`
|
|
260
|
-
|
|
261
|
-
Budget, goal, and subscription mutation endpoints validate agent scopes against `claude`, `takumi`, `codex`, `gemini`, `opencode`, `cursor`, `pi`, and `hermes`.
|
|
240
|
+
The canonical API uses `/v1`; `/api` remains a legacy alias for the dashboard and older clients. For example:
|
|
241
|
+
|
|
242
|
+
- `GET /health`, `/ready`, `/version`, and `/openapi.json`
|
|
243
|
+
- `GET /v1/summary?period=today`
|
|
244
|
+
- `GET /v1/sessions?agent=codex&account=work@example.com&limit=20`
|
|
245
|
+
- `GET /v1/breakdown?by=cost-center&period=month`
|
|
246
|
+
- `POST /v1/budgets`, `/v1/goals`, `/v1/pricing`, and `/v1/subscriptions`
|
|
247
|
+
- `POST /v1/sync`, `/v1/billing/sync`, and `/v1/ingest`
|
|
248
|
+
|
|
249
|
+
See the [REST API reference](docs/rest-api.md) for every route, response envelopes, authentication, and legacy aliases. The server publishes the current generated contract at `/openapi.json`.
|
|
262
250
|
|
|
263
251
|
The server also serves the built dashboard when `dashboard/dist` is present. The dashboard includes account-scoped session filtering, subscription plan create/update/delete controls in Savings, and savings/usage/account tables for subscription-aware cost analysis.
|
|
264
252
|
|
|
@@ -282,22 +270,13 @@ economy menubar stop
|
|
|
282
270
|
economy menubar uninstall
|
|
283
271
|
```
|
|
284
272
|
|
|
285
|
-
## Cloud Sync
|
|
286
|
-
|
|
287
|
-
Economy can push and pull local SQLite data through `@hasna/cloud` PostgreSQL sync:
|
|
288
|
-
|
|
289
|
-
```bash
|
|
290
|
-
economy cloud status
|
|
291
|
-
economy cloud push
|
|
292
|
-
economy cloud pull
|
|
293
|
-
economy cloud sync
|
|
294
|
-
```
|
|
295
|
-
|
|
296
273
|
## Data Directory
|
|
297
274
|
|
|
298
275
|
Data is stored in `~/.hasna/economy/`.
|
|
299
276
|
|
|
300
|
-
The main SQLite database lives at `~/.hasna/economy/economy.db`. Older `~/.economy/` data is
|
|
277
|
+
The main SQLite database lives at `~/.hasna/economy/economy.db`. Older `~/.economy/` data is copied on first open when the new directory does not exist. Override the database path with `HASNA_ECONOMY_DB_PATH` or `ECONOMY_DB`.
|
|
278
|
+
|
|
279
|
+
For shared deployments, CLI and MCP can use a remote `/v1` API instead of local SQLite by setting `HASNA_ECONOMY_API_URL` and `HASNA_ECONOMY_API_KEY`. See [configuration](docs/configuration.md) for client resolution, server auth, Postgres mode, and all environment variables.
|
|
301
280
|
|
|
302
281
|
## Development
|
|
303
282
|
|
|
@@ -305,6 +284,7 @@ The main SQLite database lives at `~/.hasna/economy/economy.db`. Older `~/.econo
|
|
|
305
284
|
bun test
|
|
306
285
|
bun run typecheck
|
|
307
286
|
bun run build
|
|
287
|
+
bun scripts/sync-openapi.ts
|
|
308
288
|
cd dashboard && bun run lint
|
|
309
289
|
cd menubar && swift build -c release
|
|
310
290
|
```
|
|
@@ -313,19 +293,6 @@ cd menubar && swift build -c release
|
|
|
313
293
|
|
|
314
294
|
Economy is published under the Apache-2.0 license. See [CONTRIBUTING.md](CONTRIBUTING.md) for local development and release hygiene, [SECURITY.md](SECURITY.md) for vulnerability reporting, [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for community expectations, and [CHANGELOG.md](CHANGELOG.md) for release notes.
|
|
315
295
|
|
|
316
|
-
## HTTP mode
|
|
317
|
-
|
|
318
|
-
Shared Streamable HTTP transport for multi-agent sessions (stdio remains the default):
|
|
319
|
-
|
|
320
|
-
```bash
|
|
321
|
-
economy-mcp --http # http://127.0.0.1:8860/mcp
|
|
322
|
-
MCP_HTTP=1 economy-mcp # same
|
|
323
|
-
economy-mcp --http --port 8815 # explicit port
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
- Health: `GET http://127.0.0.1:8860/health` -> `{"status":"ok","name":"economy"}`
|
|
327
|
-
- Override port with `MCP_HTTP_PORT` or `--port`
|
|
328
|
-
|
|
329
296
|
## License
|
|
330
297
|
|
|
331
298
|
Apache-2.0 -- see [LICENSE](LICENSE)
|
package/dashboard/README.md
CHANGED
|
@@ -1,73 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Economy dashboard
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The dashboard is the React/Vite UI served by `economy-serve`. It covers overview, sessions, models, projects, budgets, goals, usage, accounts, savings, fleet, reconciliation, pricing, and provider billing.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Development
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
7
|
+
Run the API from the repository root, then start Vite:
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
|
17
|
-
|
|
18
|
-
```js
|
|
19
|
-
export default defineConfig([
|
|
20
|
-
globalIgnores(['dist']),
|
|
21
|
-
{
|
|
22
|
-
files: ['**/*.{ts,tsx}'],
|
|
23
|
-
extends: [
|
|
24
|
-
// Other configs...
|
|
25
|
-
|
|
26
|
-
// Remove tseslint.configs.recommended and replace with this
|
|
27
|
-
tseslint.configs.recommendedTypeChecked,
|
|
28
|
-
// Alternatively, use this for stricter rules
|
|
29
|
-
tseslint.configs.strictTypeChecked,
|
|
30
|
-
// Optionally, add this for stylistic rules
|
|
31
|
-
tseslint.configs.stylisticTypeChecked,
|
|
32
|
-
|
|
33
|
-
// Other configs...
|
|
34
|
-
],
|
|
35
|
-
languageOptions: {
|
|
36
|
-
parserOptions: {
|
|
37
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
38
|
-
tsconfigRootDir: import.meta.dirname,
|
|
39
|
-
},
|
|
40
|
-
// other options...
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
])
|
|
9
|
+
```bash
|
|
10
|
+
economy-serve --port 3456
|
|
11
|
+
cd dashboard
|
|
12
|
+
bun install
|
|
13
|
+
bun run dev
|
|
44
14
|
```
|
|
45
15
|
|
|
46
|
-
|
|
16
|
+
The development build uses `http://localhost:3456` by default. Set `VITE_API_URL` at build/dev time to use another origin. The dashboard currently calls the server's legacy-compatible `/api` routes; the public canonical API is `/v1`.
|
|
47
17
|
|
|
48
|
-
|
|
49
|
-
// eslint.config.js
|
|
50
|
-
import reactX from 'eslint-plugin-react-x'
|
|
51
|
-
import reactDom from 'eslint-plugin-react-dom'
|
|
18
|
+
## Validation
|
|
52
19
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
extends: [
|
|
58
|
-
// Other configs...
|
|
59
|
-
// Enable lint rules for React
|
|
60
|
-
reactX.configs['recommended-typescript'],
|
|
61
|
-
// Enable lint rules for React DOM
|
|
62
|
-
reactDom.configs.recommended,
|
|
63
|
-
],
|
|
64
|
-
languageOptions: {
|
|
65
|
-
parserOptions: {
|
|
66
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
67
|
-
tsconfigRootDir: import.meta.dirname,
|
|
68
|
-
},
|
|
69
|
-
// other options...
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
])
|
|
20
|
+
```bash
|
|
21
|
+
bun test
|
|
22
|
+
bun run lint
|
|
23
|
+
bun run build
|
|
73
24
|
```
|
|
25
|
+
|
|
26
|
+
The root package build writes production assets to `dashboard/dist`; `economy-serve` serves those assets and provides SPA fallback routing.
|