agentic-metric-x 0.2.1__tar.gz
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.
- agentic_metric_x-0.2.1/.github/workflows/publish.yml +26 -0
- agentic_metric_x-0.2.1/.gitignore +30 -0
- agentic_metric_x-0.2.1/CHANGELOG.md +78 -0
- agentic_metric_x-0.2.1/LICENSE +22 -0
- agentic_metric_x-0.2.1/PKG-INFO +187 -0
- agentic_metric_x-0.2.1/README-CN.md +152 -0
- agentic_metric_x-0.2.1/README.md +156 -0
- agentic_metric_x-0.2.1/agentic-metric-screenshot.png +0 -0
- agentic_metric_x-0.2.1/pyproject.toml +50 -0
- agentic_metric_x-0.2.1/src/agentic_metric/__init__.py +3 -0
- agentic_metric_x-0.2.1/src/agentic_metric/__main__.py +6 -0
- agentic_metric_x-0.2.1/src/agentic_metric/cli.py +1075 -0
- agentic_metric_x-0.2.1/src/agentic_metric/collectors/__init__.py +74 -0
- agentic_metric_x-0.2.1/src/agentic_metric/collectors/_process.py +67 -0
- agentic_metric_x-0.2.1/src/agentic_metric/collectors/claude_code.py +803 -0
- agentic_metric_x-0.2.1/src/agentic_metric/collectors/codex.py +683 -0
- agentic_metric_x-0.2.1/src/agentic_metric/config.py +43 -0
- agentic_metric_x-0.2.1/src/agentic_metric/models.py +117 -0
- agentic_metric_x-0.2.1/src/agentic_metric/pricing.py +302 -0
- agentic_metric_x-0.2.1/src/agentic_metric/store/__init__.py +5 -0
- agentic_metric_x-0.2.1/src/agentic_metric/store/aggregator.py +829 -0
- agentic_metric_x-0.2.1/src/agentic_metric/store/database.py +392 -0
- agentic_metric_x-0.2.1/src/agentic_metric/tui/__init__.py +1 -0
- agentic_metric_x-0.2.1/src/agentic_metric/tui/app.py +466 -0
- agentic_metric_x-0.2.1/src/agentic_metric/tui/styles.tcss +114 -0
- agentic_metric_x-0.2.1/src/agentic_metric/tui/widgets.py +383 -0
- agentic_metric_x-0.2.1/tests/__init__.py +0 -0
- agentic_metric_x-0.2.1/tests/test_collectors.py +663 -0
- agentic_metric_x-0.2.1/tests/test_pricing.py +232 -0
- agentic_metric_x-0.2.1/tests/test_store.py +485 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write # trusted publishing
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
|
|
20
|
+
- name: Build package
|
|
21
|
+
run: |
|
|
22
|
+
pip install build
|
|
23
|
+
python -m build
|
|
24
|
+
|
|
25
|
+
- name: Publish to PyPI
|
|
26
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.pyc
|
|
4
|
+
*.pyo
|
|
5
|
+
*.egg-info/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.ruff_cache/
|
|
10
|
+
.mypy_cache/
|
|
11
|
+
|
|
12
|
+
# Virtualenvs
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
.env
|
|
16
|
+
|
|
17
|
+
# Editor / IDE
|
|
18
|
+
.vscode/
|
|
19
|
+
.idea/
|
|
20
|
+
*.swp
|
|
21
|
+
|
|
22
|
+
# OS
|
|
23
|
+
.DS_Store
|
|
24
|
+
|
|
25
|
+
# Local data
|
|
26
|
+
*.db
|
|
27
|
+
|
|
28
|
+
# Tooling markers
|
|
29
|
+
.codex
|
|
30
|
+
.claude/
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## v0.2.1 (2026-04-24)
|
|
4
|
+
|
|
5
|
+
Follow-up correctness fixes on top of v0.2.0.
|
|
6
|
+
|
|
7
|
+
### Bug fixes
|
|
8
|
+
|
|
9
|
+
- **Usage billing attribution**: per-session rows are now split into
|
|
10
|
+
`session_usage` per-day buckets so today/week/month rollups no longer
|
|
11
|
+
over-count cross-day sessions. `report` and the TUI both read from the
|
|
12
|
+
new bucketed view.
|
|
13
|
+
- **Codex forked session accounting**: when Codex resumes or forks a
|
|
14
|
+
session it appends a new JSONL file that replays prior turns; the
|
|
15
|
+
collector now dedupes replayed events so the forked session does not
|
|
16
|
+
double-count the parent session's tokens.
|
|
17
|
+
- **Backend usage accounting**: Claude Code and Codex collectors now
|
|
18
|
+
re-emit historical session totals on every sync (instead of only new
|
|
19
|
+
events), so pricing overrides and backfills consistently re-cost past
|
|
20
|
+
sessions. Aggregator queries and a large batch of tests were updated
|
|
21
|
+
alongside.
|
|
22
|
+
|
|
23
|
+
## v0.2.0 (2026-04-23)
|
|
24
|
+
|
|
25
|
+
Focused fork: supports **Codex** and **Claude Code** only, with
|
|
26
|
+
redesigned TUI, a unified `report` command, and several calculation
|
|
27
|
+
correctness fixes.
|
|
28
|
+
|
|
29
|
+
### Breaking changes
|
|
30
|
+
|
|
31
|
+
- Removed collectors: VS Code Copilot Chat, OpenCode, Qwen Code. If you
|
|
32
|
+
still need these, stay on v0.1.8 upstream.
|
|
33
|
+
- Replaced `today` / `history` / `status` CLI commands with a single
|
|
34
|
+
`report` command:
|
|
35
|
+
`report [--today|--week|--month|--range FROM:TO]`.
|
|
36
|
+
|
|
37
|
+
### Bug fixes
|
|
38
|
+
|
|
39
|
+
- **Codex double-counting cached tokens**: OpenAI's `input_tokens` is
|
|
40
|
+
the total (including cached). The collector now stores
|
|
41
|
+
`input_tokens - cached_input_tokens`, so `estimate_cost` no longer
|
|
42
|
+
charges cached tokens at both input and cache-read pricing. This
|
|
43
|
+
dramatically lowers Codex session cost (observed -87% on a large
|
|
44
|
+
session with heavy prompt cache).
|
|
45
|
+
- **Pricing prefix matching**: sort by prefix length descending, so
|
|
46
|
+
`gpt-5.4-mini` matches its own entry rather than `gpt-5.4`.
|
|
47
|
+
- **Date aggregation timezone**: `date(started_at, 'localtime')` is
|
|
48
|
+
used everywhere, fixing UTC-vs-local off-by-one day in today / week /
|
|
49
|
+
month rollups.
|
|
50
|
+
- **File truncation recovery**: if a JSONL file shrinks (truncated or
|
|
51
|
+
rewritten), the collector now re-parses from offset 0 instead of
|
|
52
|
+
silently skipping.
|
|
53
|
+
- **`git_branch` upsert**: the branch column is now updated from later
|
|
54
|
+
syncs, not permanently pinned by the first insert.
|
|
55
|
+
- **User-pricing I/O**: overrides are cached in memory keyed by file
|
|
56
|
+
mtime, avoiding a disk read on every cost estimation.
|
|
57
|
+
|
|
58
|
+
### Pricing table
|
|
59
|
+
|
|
60
|
+
- Added: `claude-opus-4-7`, `gpt-5.4` / `-mini` / `-nano` / `-pro`,
|
|
61
|
+
`gemini-3.1-pro`, `gemini-3.1-flash`.
|
|
62
|
+
- Family fallback now splits `gpt-5` from generic `gpt-` so modern
|
|
63
|
+
5.x models pick up 5.x pricing.
|
|
64
|
+
|
|
65
|
+
### TUI redesign
|
|
66
|
+
|
|
67
|
+
- Top row: three summary cells — TODAY / WEEK / MONTH — switched with
|
|
68
|
+
`t` / `w` / `m`.
|
|
69
|
+
- Active-now table stays compact; dim rows show today's idle sessions.
|
|
70
|
+
- 30-day cost bar chart under the active table.
|
|
71
|
+
- Agent × model nested breakdown with proportion bars, driven by the
|
|
72
|
+
currently-focused time range.
|
|
73
|
+
- Subtle panel borders, muted titles, yellow cost highlights.
|
|
74
|
+
|
|
75
|
+
## v0.1.8 (upstream baseline)
|
|
76
|
+
|
|
77
|
+
- Multiple live sessions in the same directory detected separately.
|
|
78
|
+
- Fix closed sessions being marked active via VS Code-specific fallback.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MrQianjinsi
|
|
4
|
+
Copyright (c) 2026 xihuai18
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentic-metric-x
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Minimal personal-usage monitor for Codex + Claude Code
|
|
5
|
+
Project-URL: Homepage, https://github.com/xihuai18/agentic-metric
|
|
6
|
+
Project-URL: Repository, https://github.com/xihuai18/agentic-metric
|
|
7
|
+
Project-URL: Issues, https://github.com/xihuai18/agentic-metric/issues
|
|
8
|
+
Author: xihuai18
|
|
9
|
+
Author-email: MrQianjinsi <mrqianjinsi@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: ai,claude-code,codex,coding-agent,metrics,tui
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: rich>=13.0.0
|
|
25
|
+
Requires-Dist: textual-plotext>=0.3.0
|
|
26
|
+
Requires-Dist: textual>=1.0.0
|
|
27
|
+
Requires-Dist: typer>=0.9.0
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# Agentic Metric
|
|
33
|
+
|
|
34
|
+
[中文文档](README-CN.md)
|
|
35
|
+
|
|
36
|
+
A local-only monitoring tool for AI coding agents — like `top`, but for your coding agents. Track token usage and costs across **Claude Code** and **Codex** — with a TUI dashboard and CLI.
|
|
37
|
+
|
|
38
|
+
**Supported platforms: Linux and macOS.**
|
|
39
|
+
|
|
40
|
+
**All data stays on your machine. No network requests, no telemetry, no data leaves your computer.** The tool only reads local agent data files (`~/.claude/`, `~/.codex/`) and process info.
|
|
41
|
+
|
|
42
|
+

|
|
43
|
+
|
|
44
|
+
## Features
|
|
45
|
+
|
|
46
|
+
- **Live monitoring** — Detect running agent processes, incremental JSONL session parsing
|
|
47
|
+
- **Cost estimation** — Per-model pricing table with CLI management, calculates API-equivalent costs
|
|
48
|
+
- **Unified report** — One `report` command for today / week / month / custom date range, with agent × model breakdown, top projects, top sessions, and hourly/daily/weekly heatmaps
|
|
49
|
+
- **TUI dashboard** — Terminal UI with live refresh, stacked summary cells, heatmap strip, 30-day cost chart, and agent × model breakdown
|
|
50
|
+
- **Multi-agent** — Plugin architecture; supports Claude Code and Codex today, extensible
|
|
51
|
+
|
|
52
|
+
## Agent Data Coverage
|
|
53
|
+
|
|
54
|
+
| Field | Claude Code | Codex |
|
|
55
|
+
|-------|:-----------:|:-----:|
|
|
56
|
+
| Session ID | ✓ | ✓ |
|
|
57
|
+
| Project path | ✓ | ✓ |
|
|
58
|
+
| Git branch | ✓ | ✓ |
|
|
59
|
+
| Model | ✓ | ✓ |
|
|
60
|
+
| Input tokens | ✓ | ✓ |
|
|
61
|
+
| Output tokens | ✓ | ✓ |
|
|
62
|
+
| Cache tokens | ✓ | ✓¹ |
|
|
63
|
+
| User turns | ✓ | ✓ |
|
|
64
|
+
| Message count | ✓ | ✓ |
|
|
65
|
+
| First/last prompt | ✓ | ✓ |
|
|
66
|
+
| Cost estimation | ✓ | ✓ |
|
|
67
|
+
| Live active status | ✓ | ✓ |
|
|
68
|
+
|
|
69
|
+
> ¹ Codex exposes cache-read tokens only; cache-write is not reported. Codex's
|
|
70
|
+
> `input_tokens` already includes cached tokens, so the collector stores
|
|
71
|
+
> `input_tokens − cached_input_tokens` to avoid double-charging at both input
|
|
72
|
+
> and cache-read pricing.
|
|
73
|
+
|
|
74
|
+
## Installation
|
|
75
|
+
|
|
76
|
+
Requires Python 3.10+.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install agentic-metric-x
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
uvx agentic-metric-x # Run directly without installing
|
|
86
|
+
uv tool install agentic-metric-x # Or install persistently
|
|
87
|
+
uv tool upgrade agentic-metric-x # Upgrade to latest version
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Usage
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
agentic-metric # Launch TUI dashboard (default when no command given)
|
|
94
|
+
agentic-metric tui # Launch TUI dashboard explicitly
|
|
95
|
+
agentic-metric sync # Force sync collectors to the local database
|
|
96
|
+
agentic-metric report --today # Today's usage report
|
|
97
|
+
agentic-metric report --week # This week (Mon → today)
|
|
98
|
+
agentic-metric report --month # This month
|
|
99
|
+
agentic-metric report --range 2026-04-01:2026-04-23 # Custom date range
|
|
100
|
+
agentic-metric today # Shortcut for `report --today`
|
|
101
|
+
agentic-metric week # Shortcut for `report --week`
|
|
102
|
+
agentic-metric month # Shortcut for `report --month`
|
|
103
|
+
agentic-metric history -d 30 # Last N days (default 14)
|
|
104
|
+
agentic-metric pricing # Manage model pricing
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`report` shows a header with total cost / sessions / turns / tokens / cache-hit
|
|
108
|
+
rate, a delta vs. the previous equivalent period, a heatmap strip (hours for
|
|
109
|
+
`--today`, days for `--week`, weeks for `--month`), a 30-day cost chart, and
|
|
110
|
+
breakdowns by agent × model, top projects, top sessions, and time buckets.
|
|
111
|
+
|
|
112
|
+
### Pricing Management
|
|
113
|
+
|
|
114
|
+
Model pricing is used for cost estimation. Builtin pricing is included for common models. You can add new models or override existing prices via CLI — overrides are stored in `$DATA/agentic_metric/pricing.json`.
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
agentic-metric pricing list # List all model pricing
|
|
118
|
+
agentic-metric pricing set deepseek-r2 -i 0.5 -o 2.0 # Add a new model
|
|
119
|
+
agentic-metric pricing set claude-opus-4-7 -i 4.0 -o 20.0 -cr 0.4 -cw 5.0 # Override builtin
|
|
120
|
+
agentic-metric pricing reset deepseek-r2 # Reset a model to builtin default
|
|
121
|
+
agentic-metric pricing reset --all # Reset all overrides
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
For unknown models, pricing falls back by model family (e.g. `claude-sonnet-*` uses Sonnet pricing, `gpt-5*` uses GPT-5 pricing) before using the global default.
|
|
125
|
+
|
|
126
|
+
### TUI Keybindings
|
|
127
|
+
|
|
128
|
+
| Key | Action |
|
|
129
|
+
|-----|--------|
|
|
130
|
+
| `←` / `→` | Switch view (Today / Week / Month) |
|
|
131
|
+
| `↑` / `↓` | Move time range earlier / later |
|
|
132
|
+
| `.` | Jump back to "now" (reset offset) |
|
|
133
|
+
| `t` / `w` / `m` | Focus Today / Week / Month directly |
|
|
134
|
+
| `r` | Refresh data |
|
|
135
|
+
| `q` | Quit |
|
|
136
|
+
|
|
137
|
+
## Data Sources
|
|
138
|
+
|
|
139
|
+
Paths differ by platform. `$DATA` refers to:
|
|
140
|
+
|
|
141
|
+
| | Linux | macOS |
|
|
142
|
+
|--|-------|-------|
|
|
143
|
+
| `$DATA` | `~/.local/share` | `~/Library/Application Support` |
|
|
144
|
+
|
|
145
|
+
| Agent | Path | Data |
|
|
146
|
+
|-------|------|------|
|
|
147
|
+
| Claude Code | `~/.claude/projects/` | JSONL sessions, token usage, model, branch |
|
|
148
|
+
| Claude Code | `~/.claude/stats-cache.json` | Daily activity stats |
|
|
149
|
+
| Claude Code | Process detection | Running status, working directory |
|
|
150
|
+
| Codex | `~/.codex/sessions/` | JSONL sessions, token usage, model |
|
|
151
|
+
| Codex | Process detection | Running status, working directory |
|
|
152
|
+
|
|
153
|
+
Claude Code honors `CLAUDE_CONFIG_DIR` and Codex honors `CODEX_HOME` — if you
|
|
154
|
+
have relocated either agent's config directory, the collectors pick up the
|
|
155
|
+
environment variable automatically.
|
|
156
|
+
|
|
157
|
+
All aggregated data is stored locally in `$DATA/agentic_metric/data.db` (SQLite).
|
|
158
|
+
|
|
159
|
+
## Unsupported Agents
|
|
160
|
+
|
|
161
|
+
- **Cursor** — Cursor stopped writing token usage data (`tokenCount`) to its local `state.vscdb` database around January 2026 (approximately version 2.0.63+). All `inputTokens`/`outputTokens` values are now zero. Cursor has moved usage tracking to a server-side system. Since this tool is designed to be fully offline with no network requests, monitoring Cursor usage is not supported.
|
|
162
|
+
- **OpenCode / Qwen Code / VS Code Copilot Chat** — collectors for these
|
|
163
|
+
agents existed up to v0.1.8 and were removed in v0.2.0 as this fork narrowed
|
|
164
|
+
its focus to Claude Code and Codex. If you need them, stay on v0.1.8 from
|
|
165
|
+
upstream.
|
|
166
|
+
|
|
167
|
+
## Privacy
|
|
168
|
+
|
|
169
|
+
- **Fully offline** — no network requests, no data sent anywhere
|
|
170
|
+
- **Read-only** — never modifies agent config or data files
|
|
171
|
+
- All stats stored in a local SQLite database
|
|
172
|
+
- Delete the data directory at any time to remove all data (`~/.local/share/agentic_metric/` on Linux, `~/Library/Application Support/agentic_metric/` on macOS)
|
|
173
|
+
|
|
174
|
+
## Development
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
git clone https://github.com/xihuai18/agentic-metric
|
|
178
|
+
cd agentic-metric
|
|
179
|
+
pip install -e ".[dev]"
|
|
180
|
+
pytest
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT — see [LICENSE](LICENSE).
|
|
186
|
+
|
|
187
|
+
Forked from [MrQianjinsi/agentic-metric](https://github.com/MrQianjinsi/agentic-metric) (v0.1.8 upstream). See [CHANGELOG.md](CHANGELOG.md) for what changed in this fork.
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Agentic Metric
|
|
2
|
+
|
|
3
|
+
[English](README.md)
|
|
4
|
+
|
|
5
|
+
本地化的 AI coding agent 指标监控工具 — 类似 `top`,但监控的是你的 coding agent。追踪 **Claude Code** 和 **Codex** 的 token 用量和成本,提供 TUI 仪表盘和 CLI 命令。
|
|
6
|
+
|
|
7
|
+
**支持平台:Linux 和 macOS。**
|
|
8
|
+
|
|
9
|
+
**所有数据完全存储在本地,使用过程不会联网。** 工具仅读取本机的 agent 数据文件(`~/.claude/`、`~/.codex/`)和进程信息,不发送任何数据到外部服务器。
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## 功能
|
|
14
|
+
|
|
15
|
+
- **实时监控** — 检测运行中的 agent 进程,增量解析 JSONL 会话数据
|
|
16
|
+
- **成本估算** — 基于各模型定价表计算 API 等效成本,支持 CLI 管理定价
|
|
17
|
+
- **统一的用量报告** — 单个 `report` 命令覆盖今日 / 本周 / 本月 / 自定义区间,含 agent × model 明细、项目排行、会话排行、小时/天/周热图
|
|
18
|
+
- **TUI 仪表盘** — 终端图形界面,实时刷新,含汇总卡片、热图条、30 天成本柱图、agent × model 分解
|
|
19
|
+
- **多 Agent 支持** — 插件架构;目前支持 Claude Code 和 Codex,可扩展
|
|
20
|
+
|
|
21
|
+
## 各 Agent 指标覆盖情况
|
|
22
|
+
|
|
23
|
+
| 字段 | Claude Code | Codex |
|
|
24
|
+
|------|:-----------:|:-----:|
|
|
25
|
+
| 会话 ID | ✓ | ✓ |
|
|
26
|
+
| 项目路径 | ✓ | ✓ |
|
|
27
|
+
| Git 分支 | ✓ | ✓ |
|
|
28
|
+
| 模型名称 | ✓ | ✓ |
|
|
29
|
+
| Input tokens | ✓ | ✓ |
|
|
30
|
+
| Output tokens | ✓ | ✓ |
|
|
31
|
+
| Cache tokens | ✓ | ✓¹ |
|
|
32
|
+
| 用户轮次 | ✓ | ✓ |
|
|
33
|
+
| 消息总数 | ✓ | ✓ |
|
|
34
|
+
| 首条/末条 prompt | ✓ | ✓ |
|
|
35
|
+
| 成本估算 | ✓ | ✓ |
|
|
36
|
+
| 实时活跃状态 | ✓ | ✓ |
|
|
37
|
+
|
|
38
|
+
> ¹ Codex 仅暴露 cache-read tokens,cache-write 不上报。OpenAI 的 `input_tokens`
|
|
39
|
+
> 字段本身包含了已缓存部分,collector 存储时会扣掉 `cached_input_tokens`,
|
|
40
|
+
> 避免在 input 价和 cache-read 价上重复计费。
|
|
41
|
+
|
|
42
|
+
## 安装
|
|
43
|
+
|
|
44
|
+
需要 Python 3.10+。
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install agentic-metric-x
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
或使用 [uv](https://docs.astral.sh/uv/):
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
uvx agentic-metric-x # 直接运行,无需安装
|
|
54
|
+
uv tool install agentic-metric-x # 持久安装
|
|
55
|
+
uv tool upgrade agentic-metric-x # 升级到最新版
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## 使用
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
agentic-metric # 启动 TUI 仪表盘(无参数时默认启动)
|
|
62
|
+
agentic-metric tui # 显式启动 TUI 仪表盘
|
|
63
|
+
agentic-metric sync # 强制同步各 collector 到本地数据库
|
|
64
|
+
agentic-metric report --today # 今日用量报告
|
|
65
|
+
agentic-metric report --week # 本周(周一至今)
|
|
66
|
+
agentic-metric report --month # 本月
|
|
67
|
+
agentic-metric report --range 2026-04-01:2026-04-23 # 自定义日期区间
|
|
68
|
+
agentic-metric today # `report --today` 的快捷方式
|
|
69
|
+
agentic-metric week # `report --week` 的快捷方式
|
|
70
|
+
agentic-metric month # `report --month` 的快捷方式
|
|
71
|
+
agentic-metric history -d 30 # 最近 N 天(默认 14 天)
|
|
72
|
+
agentic-metric pricing # 管理模型定价
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`report` 会输出:总成本 / sessions / 用户轮次 / tokens / 缓存命中率的汇总条,
|
|
76
|
+
与上一同类周期的差额,一个热图条(`--today` 按小时、`--week` 按日、`--month`
|
|
77
|
+
按周),30 天成本柱图,以及 agent × model、项目、会话、时间桶的明细表。
|
|
78
|
+
|
|
79
|
+
### 定价管理
|
|
80
|
+
|
|
81
|
+
模型定价用于成本估算。常见模型已内置定价,你可以通过 CLI 添加新模型或覆盖现有价格 — 用户自定义定价存储在 `$DATA/agentic_metric/pricing.json`。
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
agentic-metric pricing list # 查看所有模型定价
|
|
85
|
+
agentic-metric pricing set deepseek-r2 -i 0.5 -o 2.0 # 添加新模型
|
|
86
|
+
agentic-metric pricing set claude-opus-4-7 -i 4.0 -o 20.0 -cr 0.4 -cw 5.0 # 覆盖内置定价
|
|
87
|
+
agentic-metric pricing reset deepseek-r2 # 恢复单个模型为内置默认
|
|
88
|
+
agentic-metric pricing reset --all # 恢复所有定价为默认
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
对于未知模型,会按模型族自动匹配定价(如 `claude-sonnet-*` 使用 Sonnet 定价,`gpt-5*` 使用 GPT-5 定价),最后才使用全局默认值。
|
|
92
|
+
|
|
93
|
+
### TUI 快捷键
|
|
94
|
+
|
|
95
|
+
| 键 | 功能 |
|
|
96
|
+
|----|------|
|
|
97
|
+
| `←` / `→` | 切换视图(Today / Week / Month) |
|
|
98
|
+
| `↑` / `↓` | 时间范围往前 / 往后 |
|
|
99
|
+
| `.` | 回到"现在"(清空 offset) |
|
|
100
|
+
| `t` / `w` / `m` | 直接聚焦 Today / Week / Month |
|
|
101
|
+
| `r` | 刷新数据 |
|
|
102
|
+
| `q` | 退出 |
|
|
103
|
+
|
|
104
|
+
## 数据来源
|
|
105
|
+
|
|
106
|
+
数据路径因平台而异,下表中 `$DATA` 含义如下:
|
|
107
|
+
|
|
108
|
+
| | Linux | macOS |
|
|
109
|
+
|--|-------|-------|
|
|
110
|
+
| `$DATA` | `~/.local/share` | `~/Library/Application Support` |
|
|
111
|
+
|
|
112
|
+
| Agent | 数据路径 | 采集内容 |
|
|
113
|
+
|-------|---------|---------|
|
|
114
|
+
| Claude Code | `~/.claude/projects/` | JSONL 会话、token 用量、模型、分支 |
|
|
115
|
+
| Claude Code | `~/.claude/stats-cache.json` | 每日活动统计 |
|
|
116
|
+
| Claude Code | 进程检测 | 运行状态、工作目录 |
|
|
117
|
+
| Codex | `~/.codex/sessions/` | JSONL 会话、token 用量、模型 |
|
|
118
|
+
| Codex | 进程检测 | 运行状态、工作目录 |
|
|
119
|
+
|
|
120
|
+
Claude Code 支持 `CLAUDE_CONFIG_DIR`,Codex 支持 `CODEX_HOME`,如果你改了
|
|
121
|
+
这两个 agent 的配置目录,collector 会自动读取环境变量。
|
|
122
|
+
|
|
123
|
+
所有数据汇总存储在 `$DATA/agentic_metric/data.db`(SQLite)。
|
|
124
|
+
|
|
125
|
+
## 不支持的 Agent
|
|
126
|
+
|
|
127
|
+
- **Cursor** — Cursor 自 2026 年 1 月左右(约 2.0.63+ 版本)起不再向本地 `state.vscdb` 数据库写入 token 用量数据(`tokenCount`),所有 `inputTokens`/`outputTokens` 值均为 0。Cursor 已将用量追踪迁移至服务端。由于本工具的设计原则是完全离线、不联网,无法通过网络 API 获取 Cursor 的用量数据,因此无法支持监测 Cursor 的用量。
|
|
128
|
+
- **OpenCode / Qwen Code / VS Code Copilot Chat** — 这三个 collector 在
|
|
129
|
+
v0.1.8 之前存在,v0.2.0 起因本 fork 聚焦 Claude Code + Codex 而移除。
|
|
130
|
+
如果你仍需要这些 agent 的统计,请使用上游的 v0.1.8。
|
|
131
|
+
|
|
132
|
+
## 隐私
|
|
133
|
+
|
|
134
|
+
- 不联网,不发送任何数据
|
|
135
|
+
- 不修改 agent 的配置或数据文件(只读)
|
|
136
|
+
- 所有统计数据存储在本地 SQLite 数据库
|
|
137
|
+
- 可随时删除数据目录清除所有数据(Linux: `~/.local/share/agentic_metric/`,macOS: `~/Library/Application Support/agentic_metric/`)
|
|
138
|
+
|
|
139
|
+
## 开发
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
git clone https://github.com/xihuai18/agentic-metric
|
|
143
|
+
cd agentic-metric
|
|
144
|
+
pip install -e ".[dev]"
|
|
145
|
+
pytest
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 许可证
|
|
149
|
+
|
|
150
|
+
MIT — 详见 [LICENSE](LICENSE)。
|
|
151
|
+
|
|
152
|
+
Fork 自 [MrQianjinsi/agentic-metric](https://github.com/MrQianjinsi/agentic-metric)(基于上游 v0.1.8)。本 fork 相对上游的变更见 [CHANGELOG.md](CHANGELOG.md)。
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Agentic Metric
|
|
2
|
+
|
|
3
|
+
[中文文档](README-CN.md)
|
|
4
|
+
|
|
5
|
+
A local-only monitoring tool for AI coding agents — like `top`, but for your coding agents. Track token usage and costs across **Claude Code** and **Codex** — with a TUI dashboard and CLI.
|
|
6
|
+
|
|
7
|
+
**Supported platforms: Linux and macOS.**
|
|
8
|
+
|
|
9
|
+
**All data stays on your machine. No network requests, no telemetry, no data leaves your computer.** The tool only reads local agent data files (`~/.claude/`, `~/.codex/`) and process info.
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Live monitoring** — Detect running agent processes, incremental JSONL session parsing
|
|
16
|
+
- **Cost estimation** — Per-model pricing table with CLI management, calculates API-equivalent costs
|
|
17
|
+
- **Unified report** — One `report` command for today / week / month / custom date range, with agent × model breakdown, top projects, top sessions, and hourly/daily/weekly heatmaps
|
|
18
|
+
- **TUI dashboard** — Terminal UI with live refresh, stacked summary cells, heatmap strip, 30-day cost chart, and agent × model breakdown
|
|
19
|
+
- **Multi-agent** — Plugin architecture; supports Claude Code and Codex today, extensible
|
|
20
|
+
|
|
21
|
+
## Agent Data Coverage
|
|
22
|
+
|
|
23
|
+
| Field | Claude Code | Codex |
|
|
24
|
+
|-------|:-----------:|:-----:|
|
|
25
|
+
| Session ID | ✓ | ✓ |
|
|
26
|
+
| Project path | ✓ | ✓ |
|
|
27
|
+
| Git branch | ✓ | ✓ |
|
|
28
|
+
| Model | ✓ | ✓ |
|
|
29
|
+
| Input tokens | ✓ | ✓ |
|
|
30
|
+
| Output tokens | ✓ | ✓ |
|
|
31
|
+
| Cache tokens | ✓ | ✓¹ |
|
|
32
|
+
| User turns | ✓ | ✓ |
|
|
33
|
+
| Message count | ✓ | ✓ |
|
|
34
|
+
| First/last prompt | ✓ | ✓ |
|
|
35
|
+
| Cost estimation | ✓ | ✓ |
|
|
36
|
+
| Live active status | ✓ | ✓ |
|
|
37
|
+
|
|
38
|
+
> ¹ Codex exposes cache-read tokens only; cache-write is not reported. Codex's
|
|
39
|
+
> `input_tokens` already includes cached tokens, so the collector stores
|
|
40
|
+
> `input_tokens − cached_input_tokens` to avoid double-charging at both input
|
|
41
|
+
> and cache-read pricing.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
Requires Python 3.10+.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install agentic-metric-x
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Or with [uv](https://docs.astral.sh/uv/):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
uvx agentic-metric-x # Run directly without installing
|
|
55
|
+
uv tool install agentic-metric-x # Or install persistently
|
|
56
|
+
uv tool upgrade agentic-metric-x # Upgrade to latest version
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
agentic-metric # Launch TUI dashboard (default when no command given)
|
|
63
|
+
agentic-metric tui # Launch TUI dashboard explicitly
|
|
64
|
+
agentic-metric sync # Force sync collectors to the local database
|
|
65
|
+
agentic-metric report --today # Today's usage report
|
|
66
|
+
agentic-metric report --week # This week (Mon → today)
|
|
67
|
+
agentic-metric report --month # This month
|
|
68
|
+
agentic-metric report --range 2026-04-01:2026-04-23 # Custom date range
|
|
69
|
+
agentic-metric today # Shortcut for `report --today`
|
|
70
|
+
agentic-metric week # Shortcut for `report --week`
|
|
71
|
+
agentic-metric month # Shortcut for `report --month`
|
|
72
|
+
agentic-metric history -d 30 # Last N days (default 14)
|
|
73
|
+
agentic-metric pricing # Manage model pricing
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`report` shows a header with total cost / sessions / turns / tokens / cache-hit
|
|
77
|
+
rate, a delta vs. the previous equivalent period, a heatmap strip (hours for
|
|
78
|
+
`--today`, days for `--week`, weeks for `--month`), a 30-day cost chart, and
|
|
79
|
+
breakdowns by agent × model, top projects, top sessions, and time buckets.
|
|
80
|
+
|
|
81
|
+
### Pricing Management
|
|
82
|
+
|
|
83
|
+
Model pricing is used for cost estimation. Builtin pricing is included for common models. You can add new models or override existing prices via CLI — overrides are stored in `$DATA/agentic_metric/pricing.json`.
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
agentic-metric pricing list # List all model pricing
|
|
87
|
+
agentic-metric pricing set deepseek-r2 -i 0.5 -o 2.0 # Add a new model
|
|
88
|
+
agentic-metric pricing set claude-opus-4-7 -i 4.0 -o 20.0 -cr 0.4 -cw 5.0 # Override builtin
|
|
89
|
+
agentic-metric pricing reset deepseek-r2 # Reset a model to builtin default
|
|
90
|
+
agentic-metric pricing reset --all # Reset all overrides
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
For unknown models, pricing falls back by model family (e.g. `claude-sonnet-*` uses Sonnet pricing, `gpt-5*` uses GPT-5 pricing) before using the global default.
|
|
94
|
+
|
|
95
|
+
### TUI Keybindings
|
|
96
|
+
|
|
97
|
+
| Key | Action |
|
|
98
|
+
|-----|--------|
|
|
99
|
+
| `←` / `→` | Switch view (Today / Week / Month) |
|
|
100
|
+
| `↑` / `↓` | Move time range earlier / later |
|
|
101
|
+
| `.` | Jump back to "now" (reset offset) |
|
|
102
|
+
| `t` / `w` / `m` | Focus Today / Week / Month directly |
|
|
103
|
+
| `r` | Refresh data |
|
|
104
|
+
| `q` | Quit |
|
|
105
|
+
|
|
106
|
+
## Data Sources
|
|
107
|
+
|
|
108
|
+
Paths differ by platform. `$DATA` refers to:
|
|
109
|
+
|
|
110
|
+
| | Linux | macOS |
|
|
111
|
+
|--|-------|-------|
|
|
112
|
+
| `$DATA` | `~/.local/share` | `~/Library/Application Support` |
|
|
113
|
+
|
|
114
|
+
| Agent | Path | Data |
|
|
115
|
+
|-------|------|------|
|
|
116
|
+
| Claude Code | `~/.claude/projects/` | JSONL sessions, token usage, model, branch |
|
|
117
|
+
| Claude Code | `~/.claude/stats-cache.json` | Daily activity stats |
|
|
118
|
+
| Claude Code | Process detection | Running status, working directory |
|
|
119
|
+
| Codex | `~/.codex/sessions/` | JSONL sessions, token usage, model |
|
|
120
|
+
| Codex | Process detection | Running status, working directory |
|
|
121
|
+
|
|
122
|
+
Claude Code honors `CLAUDE_CONFIG_DIR` and Codex honors `CODEX_HOME` — if you
|
|
123
|
+
have relocated either agent's config directory, the collectors pick up the
|
|
124
|
+
environment variable automatically.
|
|
125
|
+
|
|
126
|
+
All aggregated data is stored locally in `$DATA/agentic_metric/data.db` (SQLite).
|
|
127
|
+
|
|
128
|
+
## Unsupported Agents
|
|
129
|
+
|
|
130
|
+
- **Cursor** — Cursor stopped writing token usage data (`tokenCount`) to its local `state.vscdb` database around January 2026 (approximately version 2.0.63+). All `inputTokens`/`outputTokens` values are now zero. Cursor has moved usage tracking to a server-side system. Since this tool is designed to be fully offline with no network requests, monitoring Cursor usage is not supported.
|
|
131
|
+
- **OpenCode / Qwen Code / VS Code Copilot Chat** — collectors for these
|
|
132
|
+
agents existed up to v0.1.8 and were removed in v0.2.0 as this fork narrowed
|
|
133
|
+
its focus to Claude Code and Codex. If you need them, stay on v0.1.8 from
|
|
134
|
+
upstream.
|
|
135
|
+
|
|
136
|
+
## Privacy
|
|
137
|
+
|
|
138
|
+
- **Fully offline** — no network requests, no data sent anywhere
|
|
139
|
+
- **Read-only** — never modifies agent config or data files
|
|
140
|
+
- All stats stored in a local SQLite database
|
|
141
|
+
- Delete the data directory at any time to remove all data (`~/.local/share/agentic_metric/` on Linux, `~/Library/Application Support/agentic_metric/` on macOS)
|
|
142
|
+
|
|
143
|
+
## Development
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
git clone https://github.com/xihuai18/agentic-metric
|
|
147
|
+
cd agentic-metric
|
|
148
|
+
pip install -e ".[dev]"
|
|
149
|
+
pytest
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT — see [LICENSE](LICENSE).
|
|
155
|
+
|
|
156
|
+
Forked from [MrQianjinsi/agentic-metric](https://github.com/MrQianjinsi/agentic-metric) (v0.1.8 upstream). See [CHANGELOG.md](CHANGELOG.md) for what changed in this fork.
|
|
Binary file
|