code-meter 0.1.0__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.
Files changed (43) hide show
  1. code_meter-0.1.0/LICENSE +21 -0
  2. code_meter-0.1.0/PKG-INFO +207 -0
  3. code_meter-0.1.0/README.md +183 -0
  4. code_meter-0.1.0/pyproject.toml +46 -0
  5. code_meter-0.1.0/setup.cfg +4 -0
  6. code_meter-0.1.0/setup.py +6 -0
  7. code_meter-0.1.0/src/code_meter/__init__.py +3 -0
  8. code_meter-0.1.0/src/code_meter/analytics/__init__.py +7 -0
  9. code_meter-0.1.0/src/code_meter/analytics/costs.py +43 -0
  10. code_meter-0.1.0/src/code_meter/analytics/reports.py +357 -0
  11. code_meter-0.1.0/src/code_meter/analytics/tokens.py +51 -0
  12. code_meter-0.1.0/src/code_meter/cli.py +334 -0
  13. code_meter-0.1.0/src/code_meter/config.py +116 -0
  14. code_meter-0.1.0/src/code_meter/models/__init__.py +13 -0
  15. code_meter-0.1.0/src/code_meter/models/project.py +85 -0
  16. code_meter-0.1.0/src/code_meter/models/usage.py +61 -0
  17. code_meter-0.1.0/src/code_meter/pricing/__init__.py +14 -0
  18. code_meter-0.1.0/src/code_meter/pricing/anthropic.py +78 -0
  19. code_meter-0.1.0/src/code_meter/pricing/engine.py +97 -0
  20. code_meter-0.1.0/src/code_meter/pricing/google.py +60 -0
  21. code_meter-0.1.0/src/code_meter/pricing/openai.py +69 -0
  22. code_meter-0.1.0/src/code_meter/providers/__init__.py +15 -0
  23. code_meter-0.1.0/src/code_meter/providers/antigravity.py +358 -0
  24. code_meter-0.1.0/src/code_meter/providers/base.py +42 -0
  25. code_meter-0.1.0/src/code_meter/providers/claude_code.py +378 -0
  26. code_meter-0.1.0/src/code_meter/providers/codex.py +356 -0
  27. code_meter-0.1.0/src/code_meter/storage/__init__.py +6 -0
  28. code_meter-0.1.0/src/code_meter/storage/database.py +147 -0
  29. code_meter-0.1.0/src/code_meter/storage/repository.py +482 -0
  30. code_meter-0.1.0/src/code_meter/ui/__init__.py +19 -0
  31. code_meter-0.1.0/src/code_meter/ui/dashboard.py +111 -0
  32. code_meter-0.1.0/src/code_meter/ui/tables.py +195 -0
  33. code_meter-0.1.0/src/code_meter/watcher.py +56 -0
  34. code_meter-0.1.0/src/code_meter.egg-info/PKG-INFO +207 -0
  35. code_meter-0.1.0/src/code_meter.egg-info/SOURCES.txt +41 -0
  36. code_meter-0.1.0/src/code_meter.egg-info/dependency_links.txt +1 -0
  37. code_meter-0.1.0/src/code_meter.egg-info/entry_points.txt +6 -0
  38. code_meter-0.1.0/src/code_meter.egg-info/requires.txt +11 -0
  39. code_meter-0.1.0/src/code_meter.egg-info/top_level.txt +1 -0
  40. code_meter-0.1.0/tests/test_analytics.py +94 -0
  41. code_meter-0.1.0/tests/test_database.py +73 -0
  42. code_meter-0.1.0/tests/test_pricing.py +58 -0
  43. code_meter-0.1.0/tests/test_scanner.py +171 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Antigravity Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
18
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,207 @@
1
+ Metadata-Version: 2.4
2
+ Name: code-meter
3
+ Version: 0.1.0
4
+ Summary: Local AI coding token usage tracker and cost estimator for Claude Code and future agents.
5
+ Author-email: Dhanush Nayak <dhanushnayak.ram@mail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/dhanushnayak/code-meter
8
+ Project-URL: Repository, https://github.com/dhanushnayak/code-meter
9
+ Project-URL: Bug Tracker, https://github.com/dhanushnayak/code-meter/issues
10
+ Requires-Python: >=3.11
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: typer[all]>=0.9.0
14
+ Requires-Dist: rich>=13.0.0
15
+ Requires-Dist: pydantic>=2.0.0
16
+ Requires-Dist: tomli-w>=1.0.0
17
+ Requires-Dist: watchdog>=3.0.0
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
20
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
21
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
22
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
23
+ Dynamic: license-file
24
+
25
+ # code-meter
26
+
27
+ > **Local AI Coding Token Usage Tracker, Prompt Log & Cost Estimator**
28
+
29
+ `code-meter` (also available via `claude-meter`, `codex-meter`, `antigravity-meter`, and `agy-meter` aliases) is a production-quality local CLI application designed to track local usage for **Claude Code**, **OpenAI Codex**, and **Google Antigravity**, including tokens (input, output, cache-read, cache-write), session prompts, and code change history over time.
30
+
31
+ It features an extensible multi-provider architecture so all AI coding agents operate seamlessly within unified analytics and SQLite storage.
32
+
33
+ ---
34
+
35
+ ## ๐Ÿ”’ Privacy First
36
+
37
+ * **100% Local**: Operates completely offline using your local filesystem.
38
+ * **No Gateway / Telemetry**: `code-meter` is NOT an API gateway, proxy, or interceptor.
39
+ * **Zero Uploads**: No prompts, assistant responses, source code files, or conversation texts are uploaded anywhere. Only local token metrics, session prompts, and diff logs are saved to SQLite.
40
+ * **No API Key Required**: Analyzes existing local session logs generated by Claude Code (`~/.claude`), OpenAI Codex (`~/.codex`), and Google Antigravity (`~/.gemini/antigravity-ide`).
41
+
42
+ ---
43
+
44
+ ## ๐Ÿ“ฆ Installation
45
+
46
+ ### From PyPI (Standard Installation)
47
+
48
+ ```bash
49
+ pip install code-meter
50
+ ```
51
+
52
+ ### Local / Development (Editable Mode)
53
+
54
+ ```bash
55
+ git clone https://github.com/dhanushnayak/code-meter.git
56
+ cd code-meter
57
+ pip install -e .
58
+ ```
59
+
60
+ ---
61
+
62
+ ## ๐Ÿš€ Basic Usage
63
+
64
+ Simply run:
65
+
66
+ ```bash
67
+ code-meter
68
+ ```
69
+
70
+ Or use one of the provider aliases (`claude-meter`, `codex-meter`, `antigravity-meter`, `agy-meter`).
71
+
72
+ This launches the interactive Rich terminal dashboard displaying key metrics, model breakdowns, project breakdowns, today's usage, and token burn rates.
73
+
74
+ ---
75
+
76
+ ## ๐Ÿ› ๏ธ CLI Commands
77
+
78
+ | Command | Description |
79
+ | :--- | :--- |
80
+ | `code-meter` | Open interactive Rich terminal dashboard |
81
+ | `code-meter scan` | Force an incremental scan of local usage directories |
82
+ | `code-meter today` | Summary of token usage and cost for today |
83
+ | `code-meter week` | Summary of token usage and cost for the past 7 days |
84
+ | `code-meter month` | Summary of token usage and cost for the past 30 days |
85
+ | `code-meter status` | View system status (scanned files, records, prompts, code edits, DB size) |
86
+ | `code-meter prompts` | View log of user prompts asked per session over time |
87
+ | `code-meter history` | View log of code edits, file writes, and snapshots recorded per session |
88
+ | `code-meter diffs` | View formatted code diff summaries saved in SQLite |
89
+ | `code-meter report` | Detailed aggregated report with optional filters |
90
+ | `code-meter models` | Usage and cost breakdown by model |
91
+ | `code-meter projects` | Usage and cost breakdown by working project directory |
92
+ | `code-meter sessions` | Usage and cost breakdown by session ID |
93
+ | `code-meter export` | Export usage records to CSV or JSON format |
94
+ | `code-meter config` | Display active configuration settings and file paths |
95
+ | `code-meter watch` | Live file watcher mode for real-time dashboard updates |
96
+
97
+ ---
98
+
99
+ ## ๐Ÿ” Filters & Examples
100
+
101
+ Combine filters on reporting, prompts, and history commands:
102
+
103
+ ```bash
104
+ # Filter report by provider, project, model, and timeframe
105
+ code-meter report --provider codex --model gpt-4o --days 30
106
+ code-meter report --provider antigravity --model gemini-2.5-flash
107
+
108
+ # View prompts for a specific session or project
109
+ code-meter prompts --project rag-agent --limit 20
110
+
111
+ # View code changes and diffs for a file or session
112
+ code-meter history --file src/main.py
113
+ code-meter diffs --session abc12345
114
+
115
+ # Export usage stats to CSV or JSON
116
+ code-meter export --format csv --days 7 --output usage_report.csv
117
+ ```
118
+
119
+ ---
120
+
121
+ ## โš™๏ธ Configuration
122
+
123
+ Configuration is stored in `~/.config/code-meter/config.toml` (or Windows `%APPDATA%/code-meter/config.toml`).
124
+
125
+ ```toml
126
+ [general]
127
+ database = "~/.local/share/code-meter/usage.db"
128
+
129
+ [claude_code]
130
+ directory = "~/.claude"
131
+
132
+ [codex]
133
+ directory = "~/.codex"
134
+
135
+ [antigravity]
136
+ directory = "~/.gemini/antigravity-ide"
137
+
138
+ [ui]
139
+ refresh_seconds = 2
140
+
141
+ [pricing]
142
+ currency = "USD"
143
+ ```
144
+
145
+ Environment variables take precedence:
146
+ * `CODE_METER_DB`
147
+ * `CODE_METER_CLAUDE_DIR`
148
+ * `CODE_METER_CODEX_DIR`
149
+ * `CODE_METER_ANTIGRAVITY_DIR`
150
+ * `CODE_METER_REFRESH`
151
+
152
+ ---
153
+
154
+ ## ๐Ÿงฉ Architecture
155
+
156
+ ```text
157
+ Claude Code (~/.claude) Codex (~/.codex) Antigravity (~/.gemini/antigravity-ide)
158
+ โ”‚ โ”‚ โ”‚
159
+ โ–ผ โ–ผ โ–ผ
160
+ ClaudeCodeProvider CodexProvider AntigravityProvider
161
+ โ”‚ โ”‚ โ”‚
162
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
163
+ โ–ผ
164
+ UsageRecord / SessionPrompt / SessionCodeChange (Pydantic models)
165
+ โ”‚
166
+ โ–ผ
167
+ Database Repository & Incremental Scanner (SQLite)
168
+ โ”‚
169
+ โ–ผ
170
+ Pricing Engine (Multi-Provider Model Pricing Tables)
171
+ โ”‚
172
+ โ–ผ
173
+ Analytics Engine (Token counts, Costs, Aggregations)
174
+ โ”‚
175
+ โ–ผ
176
+ Terminal UI & Typer CLI Commands
177
+ ```
178
+ โ”‚
179
+ โ–ผ
180
+ UsageRecord / SessionPrompt / SessionCodeChange (Pydantic models)
181
+ โ”‚
182
+ โ–ผ
183
+ Database Repository & Incremental Scanner (SQLite)
184
+ โ”‚
185
+ โ–ผ
186
+ Pricing Engine (Model Pricing Tables)
187
+ โ”‚
188
+ โ–ผ
189
+ Analytics Engine (Token counts, Costs, Aggregations)
190
+ โ”‚
191
+ โ–ผ
192
+ Terminal UI & Typer CLI Commands
193
+ ```
194
+
195
+ ---
196
+
197
+ ## ๐Ÿงช Running Tests
198
+
199
+ ```bash
200
+ pytest -v
201
+ ```
202
+
203
+ ---
204
+
205
+ ## ๐Ÿ“œ License
206
+
207
+ Distributed under the **MIT License**. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,183 @@
1
+ # code-meter
2
+
3
+ > **Local AI Coding Token Usage Tracker, Prompt Log & Cost Estimator**
4
+
5
+ `code-meter` (also available via `claude-meter`, `codex-meter`, `antigravity-meter`, and `agy-meter` aliases) is a production-quality local CLI application designed to track local usage for **Claude Code**, **OpenAI Codex**, and **Google Antigravity**, including tokens (input, output, cache-read, cache-write), session prompts, and code change history over time.
6
+
7
+ It features an extensible multi-provider architecture so all AI coding agents operate seamlessly within unified analytics and SQLite storage.
8
+
9
+ ---
10
+
11
+ ## ๐Ÿ”’ Privacy First
12
+
13
+ * **100% Local**: Operates completely offline using your local filesystem.
14
+ * **No Gateway / Telemetry**: `code-meter` is NOT an API gateway, proxy, or interceptor.
15
+ * **Zero Uploads**: No prompts, assistant responses, source code files, or conversation texts are uploaded anywhere. Only local token metrics, session prompts, and diff logs are saved to SQLite.
16
+ * **No API Key Required**: Analyzes existing local session logs generated by Claude Code (`~/.claude`), OpenAI Codex (`~/.codex`), and Google Antigravity (`~/.gemini/antigravity-ide`).
17
+
18
+ ---
19
+
20
+ ## ๐Ÿ“ฆ Installation
21
+
22
+ ### From PyPI (Standard Installation)
23
+
24
+ ```bash
25
+ pip install code-meter
26
+ ```
27
+
28
+ ### Local / Development (Editable Mode)
29
+
30
+ ```bash
31
+ git clone https://github.com/dhanushnayak/code-meter.git
32
+ cd code-meter
33
+ pip install -e .
34
+ ```
35
+
36
+ ---
37
+
38
+ ## ๐Ÿš€ Basic Usage
39
+
40
+ Simply run:
41
+
42
+ ```bash
43
+ code-meter
44
+ ```
45
+
46
+ Or use one of the provider aliases (`claude-meter`, `codex-meter`, `antigravity-meter`, `agy-meter`).
47
+
48
+ This launches the interactive Rich terminal dashboard displaying key metrics, model breakdowns, project breakdowns, today's usage, and token burn rates.
49
+
50
+ ---
51
+
52
+ ## ๐Ÿ› ๏ธ CLI Commands
53
+
54
+ | Command | Description |
55
+ | :--- | :--- |
56
+ | `code-meter` | Open interactive Rich terminal dashboard |
57
+ | `code-meter scan` | Force an incremental scan of local usage directories |
58
+ | `code-meter today` | Summary of token usage and cost for today |
59
+ | `code-meter week` | Summary of token usage and cost for the past 7 days |
60
+ | `code-meter month` | Summary of token usage and cost for the past 30 days |
61
+ | `code-meter status` | View system status (scanned files, records, prompts, code edits, DB size) |
62
+ | `code-meter prompts` | View log of user prompts asked per session over time |
63
+ | `code-meter history` | View log of code edits, file writes, and snapshots recorded per session |
64
+ | `code-meter diffs` | View formatted code diff summaries saved in SQLite |
65
+ | `code-meter report` | Detailed aggregated report with optional filters |
66
+ | `code-meter models` | Usage and cost breakdown by model |
67
+ | `code-meter projects` | Usage and cost breakdown by working project directory |
68
+ | `code-meter sessions` | Usage and cost breakdown by session ID |
69
+ | `code-meter export` | Export usage records to CSV or JSON format |
70
+ | `code-meter config` | Display active configuration settings and file paths |
71
+ | `code-meter watch` | Live file watcher mode for real-time dashboard updates |
72
+
73
+ ---
74
+
75
+ ## ๐Ÿ” Filters & Examples
76
+
77
+ Combine filters on reporting, prompts, and history commands:
78
+
79
+ ```bash
80
+ # Filter report by provider, project, model, and timeframe
81
+ code-meter report --provider codex --model gpt-4o --days 30
82
+ code-meter report --provider antigravity --model gemini-2.5-flash
83
+
84
+ # View prompts for a specific session or project
85
+ code-meter prompts --project rag-agent --limit 20
86
+
87
+ # View code changes and diffs for a file or session
88
+ code-meter history --file src/main.py
89
+ code-meter diffs --session abc12345
90
+
91
+ # Export usage stats to CSV or JSON
92
+ code-meter export --format csv --days 7 --output usage_report.csv
93
+ ```
94
+
95
+ ---
96
+
97
+ ## โš™๏ธ Configuration
98
+
99
+ Configuration is stored in `~/.config/code-meter/config.toml` (or Windows `%APPDATA%/code-meter/config.toml`).
100
+
101
+ ```toml
102
+ [general]
103
+ database = "~/.local/share/code-meter/usage.db"
104
+
105
+ [claude_code]
106
+ directory = "~/.claude"
107
+
108
+ [codex]
109
+ directory = "~/.codex"
110
+
111
+ [antigravity]
112
+ directory = "~/.gemini/antigravity-ide"
113
+
114
+ [ui]
115
+ refresh_seconds = 2
116
+
117
+ [pricing]
118
+ currency = "USD"
119
+ ```
120
+
121
+ Environment variables take precedence:
122
+ * `CODE_METER_DB`
123
+ * `CODE_METER_CLAUDE_DIR`
124
+ * `CODE_METER_CODEX_DIR`
125
+ * `CODE_METER_ANTIGRAVITY_DIR`
126
+ * `CODE_METER_REFRESH`
127
+
128
+ ---
129
+
130
+ ## ๐Ÿงฉ Architecture
131
+
132
+ ```text
133
+ Claude Code (~/.claude) Codex (~/.codex) Antigravity (~/.gemini/antigravity-ide)
134
+ โ”‚ โ”‚ โ”‚
135
+ โ–ผ โ–ผ โ–ผ
136
+ ClaudeCodeProvider CodexProvider AntigravityProvider
137
+ โ”‚ โ”‚ โ”‚
138
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
139
+ โ–ผ
140
+ UsageRecord / SessionPrompt / SessionCodeChange (Pydantic models)
141
+ โ”‚
142
+ โ–ผ
143
+ Database Repository & Incremental Scanner (SQLite)
144
+ โ”‚
145
+ โ–ผ
146
+ Pricing Engine (Multi-Provider Model Pricing Tables)
147
+ โ”‚
148
+ โ–ผ
149
+ Analytics Engine (Token counts, Costs, Aggregations)
150
+ โ”‚
151
+ โ–ผ
152
+ Terminal UI & Typer CLI Commands
153
+ ```
154
+ โ”‚
155
+ โ–ผ
156
+ UsageRecord / SessionPrompt / SessionCodeChange (Pydantic models)
157
+ โ”‚
158
+ โ–ผ
159
+ Database Repository & Incremental Scanner (SQLite)
160
+ โ”‚
161
+ โ–ผ
162
+ Pricing Engine (Model Pricing Tables)
163
+ โ”‚
164
+ โ–ผ
165
+ Analytics Engine (Token counts, Costs, Aggregations)
166
+ โ”‚
167
+ โ–ผ
168
+ Terminal UI & Typer CLI Commands
169
+ ```
170
+
171
+ ---
172
+
173
+ ## ๐Ÿงช Running Tests
174
+
175
+ ```bash
176
+ pytest -v
177
+ ```
178
+
179
+ ---
180
+
181
+ ## ๐Ÿ“œ License
182
+
183
+ Distributed under the **MIT License**. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "code-meter"
7
+ version = "0.1.0"
8
+ description = "Local AI coding token usage tracker and cost estimator for Claude Code and future agents."
9
+ readme = "README.md"
10
+ authors = [{ name = "Dhanush Nayak", email = "dhanushnayak.ram@mail.com" }]
11
+ license = { text = "MIT" }
12
+ requires-python = ">=3.11"
13
+ dependencies = [
14
+ "typer[all]>=0.9.0",
15
+ "rich>=13.0.0",
16
+ "pydantic>=2.0.0",
17
+ "tomli-w>=1.0.0",
18
+ "watchdog>=3.0.0",
19
+ ]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/dhanushnayak/code-meter"
23
+ Repository = "https://github.com/dhanushnayak/code-meter"
24
+ "Bug Tracker" = "https://github.com/dhanushnayak/code-meter/issues"
25
+
26
+ [project.optional-dependencies]
27
+ dev = [
28
+ "pytest>=7.0.0",
29
+ "pytest-cov>=4.0.0",
30
+ "mypy>=1.0.0",
31
+ "ruff>=0.1.0",
32
+ ]
33
+
34
+ [project.scripts]
35
+ code-meter = "code_meter.cli:app"
36
+ claude-meter = "code_meter.cli:app"
37
+ codex-meter = "code_meter.cli:app"
38
+ antigravity-meter = "code_meter.cli:app"
39
+ agy-meter = "code_meter.cli:app"
40
+
41
+ [tool.setuptools.packages.find]
42
+ where = ["src"]
43
+
44
+ [tool.pytest.ini_options]
45
+ testpaths = ["tests"]
46
+ python_files = ["test_*.py"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ """Setup configuration script for building and publishing code-meter to PyPI."""
2
+
3
+ from setuptools import setup
4
+
5
+ if __name__ == "__main__":
6
+ setup()
@@ -0,0 +1,3 @@
1
+ """code-meter: Local AI coding token usage tracker and cost estimator."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,7 @@
1
+ """Analytics engine package."""
2
+
3
+ from code_meter.analytics.tokens import TokenAnalytics
4
+ from code_meter.analytics.costs import CostAnalytics
5
+ from code_meter.analytics.reports import ReportGenerator
6
+
7
+ __all__ = ["TokenAnalytics", "CostAnalytics", "ReportGenerator"]
@@ -0,0 +1,43 @@
1
+ """Cost analytics computations."""
2
+
3
+ from typing import List, Optional, Tuple
4
+ from code_meter.models.usage import UsageRecord
5
+ from code_meter.pricing.engine import PricingEngine
6
+
7
+
8
+ class CostAnalytics:
9
+ """Calculates cumulative and per-record estimated costs."""
10
+
11
+ @staticmethod
12
+ def compute_record_costs(
13
+ records: List[UsageRecord],
14
+ pricing_engine: PricingEngine,
15
+ ) -> Tuple[List[Optional[float]], Optional[float], int]:
16
+ """
17
+ Compute cost for each record.
18
+ Returns (costs_list, total_cost_usd, unpriced_count).
19
+ """
20
+ costs: List[Optional[float]] = []
21
+ total_cost: float = 0.0
22
+ has_any_priced = False
23
+ unpriced_count = 0
24
+
25
+ for r in records:
26
+ c = pricing_engine.calculate_cost(
27
+ provider=r.provider,
28
+ model=r.model,
29
+ input_tokens=r.input_tokens,
30
+ output_tokens=r.output_tokens,
31
+ cache_read_tokens=r.cache_read_tokens,
32
+ cache_write_tokens=r.cache_write_tokens,
33
+ timestamp=r.timestamp,
34
+ )
35
+ costs.append(c)
36
+ if c is not None:
37
+ total_cost += c
38
+ has_any_priced = True
39
+ else:
40
+ unpriced_count += 1
41
+
42
+ final_total = round(total_cost, 4) if has_any_priced else None
43
+ return costs, final_total, unpriced_count