@hasna/economy 0.3.6 → 0.3.7
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 +35 -0
- package/README.md +50 -4
- package/dist/cli/commands/extras.d.ts.map +1 -1
- package/dist/cli/commands/todos.d.ts +3 -0
- package/dist/cli/commands/todos.d.ts.map +1 -1
- package/dist/cli/index.js +694 -86
- package/dist/db/database.d.ts +8 -1
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/pg-migrations.d.ts.map +1 -1
- package/dist/index.js +180 -3
- package/dist/ingest/loops.d.ts +6 -0
- package/dist/ingest/loops.d.ts.map +1 -0
- package/dist/ingest/otel.d.ts +15 -2
- package/dist/ingest/otel.d.ts.map +1 -1
- package/dist/lib/store/index.d.ts +9 -1
- package/dist/lib/store/index.d.ts.map +1 -1
- package/dist/lib/sync-all.d.ts +2 -0
- package/dist/lib/sync-all.d.ts.map +1 -1
- package/dist/lib/webhooks.d.ts.map +1 -1
- package/dist/mcp/index.js +613 -72
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/otel/index.js +193 -23
- package/dist/server/index.js +435 -47
- package/dist/server/serve.d.ts.map +1 -1
- package/dist/types/index.d.ts +37 -4
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/lib/cloud-sync.d.ts +0 -35
- package/dist/lib/cloud-sync.d.ts.map +0 -1
- package/dist/lib/fleet-sync.d.ts +0 -61
- package/dist/lib/fleet-sync.d.ts.map +0 -1
- package/dist/lib/peer-sync.d.ts +0 -21
- package/dist/lib/peer-sync.d.ts.map +0 -1
- package/dist/storage.js +0 -2746
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this repository are tracked here. This project follows semantic versioning for published npm packages when practical.
|
|
4
4
|
|
|
5
|
+
## @hasna/economy 0.3.7 - 2026-07-24
|
|
6
|
+
|
|
7
|
+
Reconciliation release: `main` had diverged from the published npm line. The `0.3.x`
|
|
8
|
+
code (`0.3.0`-`0.3.6`, the unified `Store` refactor plus the cloud/self_hosted service
|
|
9
|
+
surfaces) shipped to npm from `feature`-line commits and was never merged back, while
|
|
10
|
+
`main` (`0.2.52`) carried two merged-but-unpublished features. This release is a real
|
|
11
|
+
three-way merge that keeps **both** histories.
|
|
12
|
+
|
|
13
|
+
- Merged the published `v0.3.6` tag (`4f76834`) into `main`, preserving both parents.
|
|
14
|
+
- Forward-ported **compact CLI/MCP output defaults** (#4) onto the `Store` surfaces:
|
|
15
|
+
`--limit`/`--verbose`/`--json` on `breakdown`, `budget list`, `project list`,
|
|
16
|
+
`pricing list`, `goal list`, `goal status`, `usage`, `subscriptions list`, `fleet`;
|
|
17
|
+
`limit`/`verbose`/`json` params on the `get_model_breakdown`, `get_project_breakdown`,
|
|
18
|
+
`get_account_breakdown`, `get_budget_status`, `get_pricing`, `get_goals`,
|
|
19
|
+
`list_machines`, `get_session_detail`, `get_usage`, `get_savings`, `sync` and
|
|
20
|
+
`set_subscription` MCP tools.
|
|
21
|
+
- Forward-ported **token cost centers** (#5) onto the `Store` architecture: added
|
|
22
|
+
`EconomyStore.costCenterBreakdown()` (local SQLite + cloud `/v1` transports),
|
|
23
|
+
`cost_center_id` on `BudgetInput`, and the `breakdown --by cost-center|loop|app|repo`
|
|
24
|
+
CLI dimension plus the `get_cost_center_breakdown` MCP tool. The cloud transport
|
|
25
|
+
drops rows the API did not attribute to a cost center, so an un-upgraded serve
|
|
26
|
+
reports "no cost-center usage" instead of mislabelling model rows.
|
|
27
|
+
- Dropped the main-only code the `0.3.x` refactor deliberately removed as the
|
|
28
|
+
forbidden DSN-on-client pattern: `src/lib/peer-sync.ts`, `src/lib/cloud-sync.ts`
|
|
29
|
+
(and with it the `cloud schedule install|status|remove` commands) and
|
|
30
|
+
`src/lib/fleet-sync.ts`. The MCP `sync` tool no longer reports `cloud_pushed` /
|
|
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
|
+
- Bumped strictly above the published `0.3.6` latest. (The `v0.3.6` tag commit itself
|
|
37
|
+
carried `package.json` version `0.3.5`; the `0.3.6` publish bumped the registry
|
|
38
|
+
without a follow-up commit.)
|
|
39
|
+
|
|
5
40
|
## @hasna/economy 0.2.43 - 2026-07-06
|
|
6
41
|
|
|
7
42
|
- Added the self_hosted service surface: `economy-serve` foundation probes (`GET /health`, `/ready`, `/version` -> `{ status, version, mode }`) and a versioned `/v1` API covering summaries, sessions, breakdowns, budgets, goals, pricing, subscriptions, billing, and sync.
|
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@ AI coding cost tracker for Claude Code, Takumi, Codex, Gemini, OpenCode, Cursor,
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
10
|
- Ingests local Claude Code, Takumi, Codex, Gemini, OpenCode, Cursor, Pi, and Hermes usage.
|
|
11
|
-
- Tracks sessions, requests, projects, machines, models, cache tokens, budgets, goals, and provider billing.
|
|
11
|
+
- Tracks sessions, requests, projects, machines, models, cache tokens, cost centers, budgets, goals, and provider billing.
|
|
12
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
|
|
13
|
+
- Breaks down API-equivalent, metered API, subscription-included, estimated, and unknown cost by account, coding agent, and cost center.
|
|
14
14
|
- Seeds editable model pricing with input, output, cache-read, 5-minute cache-write, 1-hour cache-write, and context-cache storage rates.
|
|
15
15
|
- Handles tiered pricing such as Gemini long-prompt rates and OpenAI long-context rates.
|
|
16
16
|
- Reconciles estimates against Anthropic, OpenAI, and Gemini billing sources.
|
|
@@ -39,6 +39,26 @@ Open the dashboard with:
|
|
|
39
39
|
economy dashboard --port 3456
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
## CLI Output Defaults
|
|
43
|
+
|
|
44
|
+
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.
|
|
45
|
+
|
|
46
|
+
Use explicit detail paths when you need more:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
economy sessions --limit 50
|
|
50
|
+
economy session <id> --verbose
|
|
51
|
+
economy accounts month --json
|
|
52
|
+
economy usage month --verbose
|
|
53
|
+
economy todos list --limit 20
|
|
54
|
+
economy todos list --verbose
|
|
55
|
+
economy todos show 9.7
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`--json` remains the machine-readable path for commands that support it. Human output may truncate rows or long text; use `--json`, `--verbose`, `--limit`, or a `show`/detail command for complete data.
|
|
59
|
+
|
|
60
|
+
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
|
+
|
|
42
62
|
## Agent Integrations
|
|
43
63
|
|
|
44
64
|
Use the MCP server for live cost context inside coding agents:
|
|
@@ -71,7 +91,7 @@ Gemini settings:
|
|
|
71
91
|
}
|
|
72
92
|
```
|
|
73
93
|
|
|
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.
|
|
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.
|
|
75
95
|
|
|
76
96
|
## Ingest
|
|
77
97
|
|
|
@@ -92,8 +112,11 @@ economy sync --opencode
|
|
|
92
112
|
economy sync --cursor
|
|
93
113
|
economy sync --pi
|
|
94
114
|
economy sync --hermes
|
|
115
|
+
economy sync --loops
|
|
95
116
|
```
|
|
96
117
|
|
|
118
|
+
`economy sync --loops` reads `~/.hasna/loops/loops.db` in read-only mode and imports OpenLoops orchestration/judge `goal_runs.tokens_used` into `loop:*` cost centers. It intentionally does not ingest dispatched coding-agent work from loops; heavy agent spend remains captured by the existing per-agent ingesters and can be analyzed alongside loop cost centers through account/profile attribution.
|
|
119
|
+
|
|
97
120
|
Useful repair options:
|
|
98
121
|
|
|
99
122
|
```bash
|
|
@@ -116,6 +139,26 @@ economy breakdown --by account
|
|
|
116
139
|
|
|
117
140
|
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.
|
|
118
141
|
|
|
142
|
+
Cost-center breakdowns group spend across loops, apps, repos, services, and teams:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
economy breakdown --by cost-center
|
|
146
|
+
economy breakdown --by loop
|
|
147
|
+
economy breakdown --by app
|
|
148
|
+
economy breakdown --by repo
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Apps and services can report usage through the local `economy-otel` sidecar:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
economy-otel --port 4318
|
|
155
|
+
curl -X POST http://127.0.0.1:4318/ingest \
|
|
156
|
+
-H 'content-type: application/json' \
|
|
157
|
+
-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
|
+
```
|
|
159
|
+
|
|
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`.
|
|
161
|
+
|
|
119
162
|
Subscription plans can be configured locally and are used by savings calculations:
|
|
120
163
|
|
|
121
164
|
```bash
|
|
@@ -164,6 +207,7 @@ Gemini billing export files may be JSON arrays, JSON objects with `rows`, JSONL,
|
|
|
164
207
|
```bash
|
|
165
208
|
economy budget set --period monthly --limit 50 --alert 80
|
|
166
209
|
economy budget set --agent codex --period weekly --limit 25 --alert 70
|
|
210
|
+
economy budget set --cost-center loop:fleet-evaluator --period weekly --limit 10
|
|
167
211
|
economy budget list
|
|
168
212
|
economy goal set --period month --limit 40
|
|
169
213
|
economy goal set --agent gemini --period week --limit 15
|
|
@@ -172,7 +216,7 @@ economy config set webhook-url https://example.com/economy-webhook
|
|
|
172
216
|
economy config webhook-test
|
|
173
217
|
```
|
|
174
218
|
|
|
175
|
-
Budgets
|
|
219
|
+
Budgets can be global, project-scoped with `--project`, agent-scoped with `--agent`, cost-center scoped with `--cost-center`, or combined. Goals can be global, project-scoped, agent-scoped, or both. Valid agent scopes are `claude`, `takumi`, `codex`, `gemini`, `opencode`, `cursor`, `pi`, and `hermes`.
|
|
176
220
|
|
|
177
221
|
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.
|
|
178
222
|
|
|
@@ -193,6 +237,8 @@ Common endpoints:
|
|
|
193
237
|
- `GET /api/models`
|
|
194
238
|
- `GET /api/projects?period=month`
|
|
195
239
|
- `GET /api/breakdown?by=agent&period=month`
|
|
240
|
+
- `GET /api/breakdown?by=cost-center&period=month`
|
|
241
|
+
- `GET /api/breakdown?by=loop&period=month`
|
|
196
242
|
- `GET /api/accounts?period=month`
|
|
197
243
|
- `GET /api/usage?period=month`
|
|
198
244
|
- `GET /api/savings?period=month`
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"extras.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/extras.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAgDnC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAyS/D;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAyC5D"}
|
|
@@ -20,6 +20,9 @@ export declare function printTodosOverview(): void;
|
|
|
20
20
|
export declare function printTodosList(opts: {
|
|
21
21
|
phase?: string;
|
|
22
22
|
status?: TodoStatus;
|
|
23
|
+
limit?: number;
|
|
24
|
+
verbose?: boolean;
|
|
25
|
+
json?: boolean;
|
|
23
26
|
}): void;
|
|
24
27
|
export declare function printTodoShow(taskId: string): void;
|
|
25
28
|
export declare function registerTodosCommand(program: Command): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"todos.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/todos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGnC,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,aAAa,GAAG,MAAM,CAAA;AAE3D,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,QAAQ,EAAE,CAAA;CAClB;AAED,eAAO,MAAM,eAAe,iBAAiB,CAAA;AAC7C,eAAO,MAAM,YAAY,kOACmM,CAAA;AAE5N,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