codex-agent-hour-tracker 0.3.0__tar.gz → 0.4.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.
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/CHANGELOG.md +5 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/PKG-INFO +30 -2
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/README.md +29 -1
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/pyproject.toml +1 -1
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/__init__.py +1 -1
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/cli.py +7 -1
- codex_agent_hour_tracker-0.4.0/src/agent_hour_tracker/google_timing.py +175 -0
- codex_agent_hour_tracker-0.4.0/src/agent_hour_tracker/google_usage.py +216 -0
- codex_agent_hour_tracker-0.4.0/src/agent_hour_tracker/muse_usage.py +270 -0
- codex_agent_hour_tracker-0.4.0/tests/test_google_usage.py +200 -0
- codex_agent_hour_tracker-0.4.0/tests/test_muse_usage.py +212 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_public_files.py +1 -1
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/.gitignore +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/LICENSE +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/SECURITY.md +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/community/api.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/community/auth.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/community/cookies.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/community/crypto.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/community/db.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/community/score.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/community-env.d.ts +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/docs/account-usage.md +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/docs/community.md +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/docs/exports.md +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/docs/methodology.md +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/functions/api/community/[[path]].js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/functions/community/_middleware.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/migrations/0001_community.sql +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/migrations/0002_provider_scores.sql +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/package-lock.json +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/package.json +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/scripts/export_account_usage.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/scripts/sync_benchmarks.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/_headers +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/app.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/benchmarks/index.html +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/benchmarks-data.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/benchmarks.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/community/index.html +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/community.js +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/favicon.png +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/favicon.svg +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/index.html +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/score.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/social-card.png +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/site/styles.css +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/skills/codex-agent-hour-tracker/SKILL.md +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/skills/codex-agent-hour-tracker/agents/openai.yaml +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/__main__.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/account_usage.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/archive.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/benchmarks.json +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/benchmarks.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/claude_scanner.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/metrics.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/report.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/scanner.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/session_io.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/share.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/community-api.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/community-auth.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/community-database.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/community-headers.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/community-runtime.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/community-score.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/community-security-auth.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/site-local.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/site-score.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/site-ui.mjs +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_account_usage_exporter.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_archive.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_claude_scanner.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_cli.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_compressed_sessions.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_metrics.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_provider_integration.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_public_share.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_report.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_scanner.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/tests/test_v020_reports.py +0 -0
- {codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/wrangler.jsonc +0 -0
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
- Add `agent-hours usage` for private daily token and measured-hours reports for Antigravity and Muse Code. Read retained local journals for Muse Code and show available results when a provider's data is missing.
|
|
6
|
+
- Add `agent-hours google-usage` as an Antigravity-only alias.
|
|
7
|
+
|
|
3
8
|
## 0.3.0
|
|
4
9
|
|
|
5
10
|
- Add Claude Code native main and completed foreground-agent timing scans and Codex, Claude, or combined local reports.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: codex-agent-hour-tracker
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Measure cumulative Codex and Claude Code agent runtime without decoding conversation content.
|
|
5
5
|
Project-URL: Homepage, https://agenthours.dev
|
|
6
6
|
Project-URL: Repository, https://github.com/tim-osterhus/codex-agent-hour-tracker
|
|
@@ -27,7 +27,7 @@ Description-Content-Type: text/markdown
|
|
|
27
27
|
|
|
28
28
|
# Agent Hours
|
|
29
29
|
|
|
30
|
-
Agent Hours is a local CLI that measures
|
|
30
|
+
Agent Hours is a local CLI that measures Codex and Claude Code agent-hours. It also reports local token counts and measured runtime for Antigravity and Muse Code.
|
|
31
31
|
|
|
32
32
|
See your runtime across profiles and machines, calculate optional Agent Leverage, and make a share card at [agenthours.dev](https://agenthours.dev).
|
|
33
33
|
|
|
@@ -99,6 +99,34 @@ agent-hours --provider all --timezone Pacific/Honolulu --monthly \
|
|
|
99
99
|
|
|
100
100
|
Use the same imports with `--provider codex` or `--provider claude` for separate totals. Merge-only commands do not scan local defaults. Copied histories are deduplicated within each provider. Keep archives private. See [export contracts](docs/exports.md).
|
|
101
101
|
|
|
102
|
+
## Antigravity
|
|
103
|
+
|
|
104
|
+
Install [ccusage](https://ccusage.com/guide/installation) v20.0.51 or later for local token counts, including cached tokens. Agent Hours runs it offline. The command defaults to the last 30 completed days.
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm install -g ccusage
|
|
108
|
+
agent-hours google-usage
|
|
109
|
+
agent-hours usage --provider antigravity --format csv --timezone Pacific/Honolulu
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Use `--ccusage EXECUTABLE` if ccusage is outside your PATH. Set `ANTIGRAVITY_DATA_DIR` for a custom data root. Keep daily reports private.
|
|
113
|
+
|
|
114
|
+
Antigravity hours come from recorded generation and execution intervals in local conversation database metadata. Overlapping intervals count once within a conversation, and separate conversations add independently. Each interval is attributed to its start date. Missing timing is displayed as unavailable (a blank CSV cell). These hours are separate from the public Agent-Hour Score.
|
|
115
|
+
|
|
116
|
+
## Muse Code and combined usage
|
|
117
|
+
|
|
118
|
+
`agent-hours usage` reports Antigravity and Muse Code in one private report. The `google-usage` alias reports Antigravity alone. Use repeatable `--muse-sessions-dir PATH` to specify existing Muse Code session roots, or omit it to use default Muse Code session discovery.
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
agent-hours usage --provider muse
|
|
122
|
+
agent-hours usage --provider muse --muse-sessions-dir ~/private/muse-sessions --format csv
|
|
123
|
+
agent-hours usage --provider all
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Muse Code runs without ccusage. With `--provider all`, missing ccusage makes Antigravity and combined token totals unavailable. The report still shows Muse Code usage and available measured hours, and the command exits with status 1. A failed token read for any requested provider also exits with status 1.
|
|
127
|
+
|
|
128
|
+
Muse Code figures come from retained local session logs. Measured hours cover recorded model and tool execution. The report shows Muse Code tokens as unavailable when it finds no readable logs. Skipped or unsupported records produce a partial-coverage warning. [Meta's session audit guide](https://dev.meta.ai/docs/cookbook/audit-agent-sessions)
|
|
129
|
+
|
|
102
130
|
## Private ChatGPT account usage
|
|
103
131
|
|
|
104
132
|
```bash
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Agent Hours
|
|
2
2
|
|
|
3
|
-
Agent Hours is a local CLI that measures
|
|
3
|
+
Agent Hours is a local CLI that measures Codex and Claude Code agent-hours. It also reports local token counts and measured runtime for Antigravity and Muse Code.
|
|
4
4
|
|
|
5
5
|
See your runtime across profiles and machines, calculate optional Agent Leverage, and make a share card at [agenthours.dev](https://agenthours.dev).
|
|
6
6
|
|
|
@@ -72,6 +72,34 @@ agent-hours --provider all --timezone Pacific/Honolulu --monthly \
|
|
|
72
72
|
|
|
73
73
|
Use the same imports with `--provider codex` or `--provider claude` for separate totals. Merge-only commands do not scan local defaults. Copied histories are deduplicated within each provider. Keep archives private. See [export contracts](docs/exports.md).
|
|
74
74
|
|
|
75
|
+
## Antigravity
|
|
76
|
+
|
|
77
|
+
Install [ccusage](https://ccusage.com/guide/installation) v20.0.51 or later for local token counts, including cached tokens. Agent Hours runs it offline. The command defaults to the last 30 completed days.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm install -g ccusage
|
|
81
|
+
agent-hours google-usage
|
|
82
|
+
agent-hours usage --provider antigravity --format csv --timezone Pacific/Honolulu
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Use `--ccusage EXECUTABLE` if ccusage is outside your PATH. Set `ANTIGRAVITY_DATA_DIR` for a custom data root. Keep daily reports private.
|
|
86
|
+
|
|
87
|
+
Antigravity hours come from recorded generation and execution intervals in local conversation database metadata. Overlapping intervals count once within a conversation, and separate conversations add independently. Each interval is attributed to its start date. Missing timing is displayed as unavailable (a blank CSV cell). These hours are separate from the public Agent-Hour Score.
|
|
88
|
+
|
|
89
|
+
## Muse Code and combined usage
|
|
90
|
+
|
|
91
|
+
`agent-hours usage` reports Antigravity and Muse Code in one private report. The `google-usage` alias reports Antigravity alone. Use repeatable `--muse-sessions-dir PATH` to specify existing Muse Code session roots, or omit it to use default Muse Code session discovery.
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
agent-hours usage --provider muse
|
|
95
|
+
agent-hours usage --provider muse --muse-sessions-dir ~/private/muse-sessions --format csv
|
|
96
|
+
agent-hours usage --provider all
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Muse Code runs without ccusage. With `--provider all`, missing ccusage makes Antigravity and combined token totals unavailable. The report still shows Muse Code usage and available measured hours, and the command exits with status 1. A failed token read for any requested provider also exits with status 1.
|
|
100
|
+
|
|
101
|
+
Muse Code figures come from retained local session logs. Measured hours cover recorded model and tool execution. The report shows Muse Code tokens as unavailable when it finds no readable logs. Skipped or unsupported records produce a partial-coverage warning. [Meta's session audit guide](https://dev.meta.ai/docs/cookbook/audit-agent-sessions)
|
|
102
|
+
|
|
75
103
|
## Private ChatGPT account usage
|
|
76
104
|
|
|
77
105
|
```bash
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "codex-agent-hour-tracker"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "Measure cumulative Codex and Claude Code agent runtime without decoding conversation content."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
{codex_agent_hour_tracker-0.3.0 → codex_agent_hour_tracker-0.4.0}/src/agent_hour_tracker/cli.py
RENAMED
|
@@ -47,6 +47,11 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
47
47
|
|
|
48
48
|
return account_usage_main(argv[1:])
|
|
49
49
|
|
|
50
|
+
if argv and argv[0] in ("google-usage", "usage"):
|
|
51
|
+
from .google_usage import main as usage_main
|
|
52
|
+
|
|
53
|
+
return usage_main(argv[1:], combined=argv[0] == "usage")
|
|
54
|
+
|
|
50
55
|
parser = _build_parser()
|
|
51
56
|
try:
|
|
52
57
|
arguments = parser.parse_args(argv)
|
|
@@ -156,7 +161,8 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
156
161
|
parser = argparse.ArgumentParser(
|
|
157
162
|
prog="agent-hours",
|
|
158
163
|
description="Report cumulative Codex and Claude Code agent-hours from local timing metadata.",
|
|
159
|
-
epilog="Private account tokens: agent-hours account-usage --help"
|
|
164
|
+
epilog=("Private account tokens: agent-hours account-usage --help. "
|
|
165
|
+
"Antigravity and Muse Code: agent-hours usage --help."),
|
|
160
166
|
)
|
|
161
167
|
parser.add_argument(
|
|
162
168
|
"--sessions-dir",
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"""Measured time from Antigravity conversation metadata, without decoding content."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sqlite3
|
|
7
|
+
from collections import defaultdict
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
from datetime import date, datetime
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from zoneinfo import ZoneInfo
|
|
12
|
+
|
|
13
|
+
_NS = 1_000_000_000
|
|
14
|
+
_MAX_RECORD = 8 * 1024 * 1024
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class Timing:
|
|
19
|
+
intervals: dict[bytes, set[tuple[int, int]]] = field(default_factory=lambda: defaultdict(set))
|
|
20
|
+
unreadable: int = 0
|
|
21
|
+
|
|
22
|
+
def add(self, identity: bytes, start: int | None, end: int | None) -> None:
|
|
23
|
+
if start is not None and end is not None and 0 < start < end:
|
|
24
|
+
self.intervals[identity].add((start, end))
|
|
25
|
+
|
|
26
|
+
def daily_hours(self, timezone: ZoneInfo) -> dict[date, float]:
|
|
27
|
+
totals: dict[date, int] = defaultdict(int)
|
|
28
|
+
for intervals in self.intervals.values():
|
|
29
|
+
end = 0
|
|
30
|
+
start = 0
|
|
31
|
+
for a, b in sorted(intervals):
|
|
32
|
+
if a > end:
|
|
33
|
+
if end:
|
|
34
|
+
_add_day(totals, start, end, timezone)
|
|
35
|
+
start, end = a, b
|
|
36
|
+
else:
|
|
37
|
+
end = max(end, b)
|
|
38
|
+
if end:
|
|
39
|
+
_add_day(totals, start, end, timezone)
|
|
40
|
+
return {day: duration / (_NS * 3600) for day, duration in totals.items()}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _add_day(totals: dict[date, int], start: int, end: int, timezone: ZoneInfo) -> None:
|
|
44
|
+
try:
|
|
45
|
+
day = datetime.fromtimestamp(start // _NS, timezone).date()
|
|
46
|
+
except (ValueError, OverflowError, OSError):
|
|
47
|
+
return
|
|
48
|
+
totals[day] += end - start
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _antigravity_roots() -> set[Path]:
|
|
52
|
+
configured = os.environ.get("ANTIGRAVITY_DATA_DIR")
|
|
53
|
+
if configured:
|
|
54
|
+
roots = (Path(p.strip()).expanduser() for p in configured.split(",") if p.strip())
|
|
55
|
+
return {root / "conversations" if (root / "conversations").is_dir() else root for root in roots}
|
|
56
|
+
home = Path.home()
|
|
57
|
+
names = ("antigravity", "antigravity-cli", "antigravity-ide", "antigravity-backup", "antigravity-acp")
|
|
58
|
+
config = Path(os.environ.get("XDG_CONFIG_HOME") or home / ".config")
|
|
59
|
+
return {home / ".gemini" / name / "conversations" for name in names} | {
|
|
60
|
+
config / "antigravity" / "conversations"
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def antigravity_timing() -> Timing:
|
|
65
|
+
result = Timing()
|
|
66
|
+
seen: set[Path] = set()
|
|
67
|
+
for directory in _antigravity_roots():
|
|
68
|
+
try:
|
|
69
|
+
for path in directory.rglob("*.db"):
|
|
70
|
+
resolved = path.resolve()
|
|
71
|
+
if resolved in seen:
|
|
72
|
+
continue
|
|
73
|
+
seen.add(resolved)
|
|
74
|
+
try:
|
|
75
|
+
_antigravity_db(resolved, result)
|
|
76
|
+
except (OSError, sqlite3.Error, UnicodeError, ValueError):
|
|
77
|
+
result.unreadable += 1
|
|
78
|
+
except OSError:
|
|
79
|
+
result.unreadable += 1
|
|
80
|
+
return result
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _antigravity_db(path: Path, result: Timing) -> None:
|
|
84
|
+
# Only query the trajectory ID and bounded CortexStepMetadata. The step
|
|
85
|
+
# payload, error details, prompts, and results are in other columns.
|
|
86
|
+
con = sqlite3.connect(path.as_uri() + "?mode=ro", uri=True, timeout=1.0)
|
|
87
|
+
try:
|
|
88
|
+
con.execute("PRAGMA trusted_schema=OFF")
|
|
89
|
+
con.execute("PRAGMA query_only=ON")
|
|
90
|
+
tables = {name for (name,) in con.execute(
|
|
91
|
+
"SELECT name FROM sqlite_schema WHERE type='table' AND name IN ('steps','trajectory_meta')"
|
|
92
|
+
)}
|
|
93
|
+
if "steps" not in tables:
|
|
94
|
+
result.unreadable += 1
|
|
95
|
+
return
|
|
96
|
+
identity = path.stem
|
|
97
|
+
if "trajectory_meta" in tables:
|
|
98
|
+
rows = con.execute("SELECT trajectory_id FROM trajectory_meta LIMIT 2").fetchall()
|
|
99
|
+
if len(rows) == 1 and isinstance(rows[0][0], str) and rows[0][0]:
|
|
100
|
+
identity = rows[0][0]
|
|
101
|
+
key = identity.encode("utf-8")
|
|
102
|
+
for (blob,) in con.execute(
|
|
103
|
+
"SELECT CASE WHEN length(metadata) <= ? THEN metadata END "
|
|
104
|
+
"FROM steps WHERE metadata IS NOT NULL", (_MAX_RECORD,)
|
|
105
|
+
):
|
|
106
|
+
if not isinstance(blob, bytes):
|
|
107
|
+
result.unreadable += 1
|
|
108
|
+
continue
|
|
109
|
+
try:
|
|
110
|
+
metadata = _proto_fields(memoryview(blob), {1, 7, 8, 9, 32})
|
|
111
|
+
# Generation starts at creation and ends when generation
|
|
112
|
+
# finishes. For execution steps use their explicit start/end.
|
|
113
|
+
if 9 in metadata:
|
|
114
|
+
result.add(key, _stamp(metadata.get(1)), _stamp(metadata.get(7)))
|
|
115
|
+
result.add(key, _stamp(metadata.get(32)), _stamp(metadata.get(8)))
|
|
116
|
+
except ValueError:
|
|
117
|
+
result.unreadable += 1
|
|
118
|
+
finally:
|
|
119
|
+
con.close()
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _varint(data: memoryview, at: int) -> tuple[int, int]:
|
|
123
|
+
value = 0
|
|
124
|
+
for shift in range(0, 70, 7):
|
|
125
|
+
if at >= len(data):
|
|
126
|
+
break
|
|
127
|
+
byte = data[at]
|
|
128
|
+
at += 1
|
|
129
|
+
if shift == 63 and byte > 1:
|
|
130
|
+
break
|
|
131
|
+
value |= (byte & 127) << shift
|
|
132
|
+
if byte < 128:
|
|
133
|
+
return value, at
|
|
134
|
+
raise ValueError("invalid protobuf varint")
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _proto_fields(data: memoryview, wanted: set[int]) -> dict[int, int | memoryview]:
|
|
138
|
+
fields: dict[int, int | memoryview] = {}
|
|
139
|
+
at = 0
|
|
140
|
+
while at < len(data):
|
|
141
|
+
tag, at = _varint(data, at)
|
|
142
|
+
field_number, wire = divmod(tag, 8)
|
|
143
|
+
if not field_number:
|
|
144
|
+
raise ValueError("invalid protobuf field")
|
|
145
|
+
if wire == 0:
|
|
146
|
+
value, at = _varint(data, at)
|
|
147
|
+
if field_number in wanted:
|
|
148
|
+
fields[field_number] = value
|
|
149
|
+
continue
|
|
150
|
+
if wire == 2:
|
|
151
|
+
length, at = _varint(data, at)
|
|
152
|
+
elif wire in (1, 5):
|
|
153
|
+
length = 8 if wire == 1 else 4
|
|
154
|
+
else:
|
|
155
|
+
raise ValueError("unsupported protobuf field")
|
|
156
|
+
end = at + length
|
|
157
|
+
if end > len(data):
|
|
158
|
+
raise ValueError("truncated protobuf field")
|
|
159
|
+
if wire == 2 and field_number in wanted:
|
|
160
|
+
fields[field_number] = data[at:end]
|
|
161
|
+
at = end
|
|
162
|
+
return fields
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _stamp(blob: int | memoryview | None) -> int | None:
|
|
166
|
+
if not isinstance(blob, memoryview):
|
|
167
|
+
return None
|
|
168
|
+
fields = _proto_fields(blob, {1, 2})
|
|
169
|
+
return _ns_timestamp(fields.get(1, 0), fields.get(2, 0))
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _ns_timestamp(seconds: object, nanos: object) -> int | None:
|
|
173
|
+
if type(seconds) is int and type(nanos) is int and 0 <= seconds < 253402300800 and 0 <= nanos < _NS:
|
|
174
|
+
return seconds * _NS + nanos
|
|
175
|
+
return None
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"""Private token and measured-hours report for Antigravity and Muse Code."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import csv
|
|
7
|
+
import json
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from datetime import date, timedelta
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from tempfile import TemporaryDirectory
|
|
15
|
+
from zoneinfo import ZoneInfo
|
|
16
|
+
|
|
17
|
+
from .cli import _resolve_report_range, _resolve_timezone, _today_in_timezone
|
|
18
|
+
from .google_timing import antigravity_timing
|
|
19
|
+
|
|
20
|
+
_PROVIDERS = {"antigravity": "Antigravity", "muse": "Muse Code"}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class Usage:
|
|
25
|
+
tokens: dict[date, int] | None
|
|
26
|
+
hours: dict[date, float]
|
|
27
|
+
missing_token_days: set[date] = field(default_factory=set)
|
|
28
|
+
|
|
29
|
+
def tokens_on(self, day: date) -> int | None:
|
|
30
|
+
if self.tokens is None:
|
|
31
|
+
return None
|
|
32
|
+
return self.tokens.get(day, None if day in self.missing_token_days else 0)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _token_usage(executable: str, start: date, end: date, timezone: ZoneInfo) -> dict[date, int]:
|
|
36
|
+
with TemporaryDirectory(prefix="agent-hours-google-") as directory:
|
|
37
|
+
config = Path(directory) / "ccusage.json"
|
|
38
|
+
config.write_text("{}", encoding="utf-8")
|
|
39
|
+
proc = subprocess.run(
|
|
40
|
+
[executable, "antigravity", "daily", "--config", str(config), "--json",
|
|
41
|
+
"--offline", "--no-cost", "--timezone", timezone.key,
|
|
42
|
+
"--since", start.isoformat().replace("-", ""),
|
|
43
|
+
"--until", end.isoformat().replace("-", "")],
|
|
44
|
+
capture_output=True, check=True, timeout=600,
|
|
45
|
+
)
|
|
46
|
+
data = json.loads(proc.stdout)
|
|
47
|
+
if not isinstance(data, dict) or not isinstance(data.get("daily"), list):
|
|
48
|
+
raise ValueError("invalid ccusage report")
|
|
49
|
+
totals: dict[date, int] = {}
|
|
50
|
+
for row in data["daily"]:
|
|
51
|
+
day = date.fromisoformat(row["date"])
|
|
52
|
+
tokens = row["totalTokens"]
|
|
53
|
+
if day in totals or not start <= day <= end or type(tokens) is not int or tokens < 0:
|
|
54
|
+
raise ValueError("invalid ccusage daily row")
|
|
55
|
+
totals[day] = tokens
|
|
56
|
+
if sum(totals.values()) != data["totals"]["totalTokens"]:
|
|
57
|
+
raise ValueError("inconsistent ccusage total")
|
|
58
|
+
if proc.stderr.strip():
|
|
59
|
+
print("warning: ccusage reported diagnostics for Antigravity; "
|
|
60
|
+
"some token records may be unavailable", file=sys.stderr)
|
|
61
|
+
return totals
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _print_csv(results: dict[str, Usage], dates: list[date]) -> None:
|
|
65
|
+
writer = csv.writer(sys.stdout)
|
|
66
|
+
writer.writerow(["date", *(f"{provider}_{field}" for provider in results
|
|
67
|
+
for field in ("tokens", "measured_agent_hours"))])
|
|
68
|
+
for day in dates:
|
|
69
|
+
row: list[object] = [day.isoformat()]
|
|
70
|
+
for result in results.values():
|
|
71
|
+
row.extend((result.tokens_on(day), result.hours.get(day)))
|
|
72
|
+
writer.writerow(row)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _print_text(results: dict[str, Usage], dates: list[date], timezone: ZoneInfo, title: str) -> None:
|
|
76
|
+
print(f"{title} · {dates[0]} to {dates[-1]} ({timezone.key})")
|
|
77
|
+
for provider, result in results.items():
|
|
78
|
+
print(f"\n{_PROVIDERS[provider]}")
|
|
79
|
+
if result.tokens is None:
|
|
80
|
+
print("Tokens: unavailable")
|
|
81
|
+
else:
|
|
82
|
+
total = sum(result.tokens.values())
|
|
83
|
+
print(f"Tokens: {total:,} total · {total / len(dates):,.0f}/day")
|
|
84
|
+
if result.hours:
|
|
85
|
+
print(f"Measured agent hours: {sum(result.hours.values()):.4f}")
|
|
86
|
+
else:
|
|
87
|
+
print("Measured agent hours: unavailable")
|
|
88
|
+
print(f"{'Date':<12} {'Tokens':>16} {'Measured hours':>16}")
|
|
89
|
+
for day in dates:
|
|
90
|
+
count = result.tokens_on(day)
|
|
91
|
+
tokens = f"{count:,}" if count is not None else "n/a"
|
|
92
|
+
hours = f"{result.hours[day]:.4f}" if day in result.hours else "n/a"
|
|
93
|
+
print(f"{day.isoformat():<12} {tokens:>16} {hours:>16}")
|
|
94
|
+
if len(results) > 1:
|
|
95
|
+
missing = [_PROVIDERS[provider] for provider, result in results.items() if result.tokens is None]
|
|
96
|
+
if missing:
|
|
97
|
+
print(f"\nCombined tokens: unavailable (no token counts for {', '.join(missing)})")
|
|
98
|
+
else:
|
|
99
|
+
combined = sum(sum((result.tokens or {}).values()) for result in results.values())
|
|
100
|
+
print(f"\nCombined tokens: {combined:,} total · {combined / len(dates):,.0f}/day")
|
|
101
|
+
notes = []
|
|
102
|
+
if "antigravity" in results:
|
|
103
|
+
notes.append("Antigravity token counts include cached tokens.")
|
|
104
|
+
if "muse" in results:
|
|
105
|
+
notes.append("Muse Code figures cover retained local session logs only.")
|
|
106
|
+
print("\n" + " ".join([*notes, "Measured hours cover recorded work intervals."]))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _muse_usage(roots: list[Path] | None, timezone: ZoneInfo, start: date, end: date) -> tuple[Usage, bool]:
|
|
110
|
+
"""Return Muse usage and whether its token read failed."""
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
from .muse_usage import scan_muse
|
|
114
|
+
|
|
115
|
+
scan = scan_muse(roots, timezone)
|
|
116
|
+
except (ImportError, OSError, ValueError):
|
|
117
|
+
print("error: unable to read Muse Code session logs", file=sys.stderr)
|
|
118
|
+
return Usage(None, {}), True
|
|
119
|
+
skipped = scan.unreadable + scan.unsupported
|
|
120
|
+
hours = {day: value for day, value in scan.hours.items() if start <= day <= end}
|
|
121
|
+
tokens = {day: value for day, value in scan.tokens.items() if start <= day <= end}
|
|
122
|
+
missing = {day: count for day, count in scan.missing_tokens.items() if start <= day <= end}
|
|
123
|
+
if not scan.files_scanned:
|
|
124
|
+
if scan.unreadable:
|
|
125
|
+
print("error: unable to read Muse Code session logs", file=sys.stderr)
|
|
126
|
+
return Usage(None, {}), True
|
|
127
|
+
print("warning: no retained Muse Code session logs found; Muse Code tokens are unavailable",
|
|
128
|
+
file=sys.stderr)
|
|
129
|
+
return Usage(None, hours), False
|
|
130
|
+
skipped_in_report = skipped + sum(missing.values())
|
|
131
|
+
if (missing and not tokens) or (skipped and not scan.tokens):
|
|
132
|
+
print(f"error: no Muse Code tokens read; skipped {skipped_in_report} unreadable, unsupported, or incomplete "
|
|
133
|
+
"inputs or records", file=sys.stderr)
|
|
134
|
+
return Usage(None, hours), True
|
|
135
|
+
if skipped_in_report:
|
|
136
|
+
print(f"warning: skipped {skipped_in_report} unreadable, unsupported, or incomplete Muse Code inputs or records; "
|
|
137
|
+
"Muse Code totals are partial", file=sys.stderr)
|
|
138
|
+
return Usage(tokens, hours, set(missing)), False
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def main(argv: list[str], *, combined: bool = False) -> int:
|
|
142
|
+
"""Run ``google-usage`` for Antigravity or ``usage`` for both providers."""
|
|
143
|
+
|
|
144
|
+
choices = tuple(_PROVIDERS) if combined else ("antigravity",)
|
|
145
|
+
parser = argparse.ArgumentParser(
|
|
146
|
+
prog="agent-hours usage" if combined else "agent-hours google-usage",
|
|
147
|
+
description=("Report local Antigravity and Muse Code tokens and measured agent hours."
|
|
148
|
+
if combined else
|
|
149
|
+
"Report local Antigravity tokens and measured agent hours."),
|
|
150
|
+
)
|
|
151
|
+
parser.add_argument("--provider", choices=(*choices, "all"), default="all")
|
|
152
|
+
parser.add_argument("--ccusage", default="ccusage", metavar="EXECUTABLE",
|
|
153
|
+
help="installed ccusage executable (default: ccusage on PATH)")
|
|
154
|
+
if combined:
|
|
155
|
+
parser.add_argument("--muse-sessions-dir", type=Path, action="append", metavar="PATH",
|
|
156
|
+
help="Muse Code sessions directory; repeat to combine roots")
|
|
157
|
+
parser.add_argument("--start", metavar="YYYY-MM-DD", help="first day, inclusive")
|
|
158
|
+
parser.add_argument("--end", metavar="YYYY-MM-DD", help="last day, inclusive (default: yesterday)")
|
|
159
|
+
parser.add_argument("--timezone", metavar="IANA_ZONE")
|
|
160
|
+
parser.add_argument("--format", choices=("text", "csv"), default="text")
|
|
161
|
+
try:
|
|
162
|
+
args = parser.parse_args(argv)
|
|
163
|
+
except SystemExit as error:
|
|
164
|
+
return int(error.code)
|
|
165
|
+
providers = choices if args.provider == "all" else (args.provider,)
|
|
166
|
+
muse_roots = getattr(args, "muse_sessions_dir", None)
|
|
167
|
+
if muse_roots and "muse" not in providers:
|
|
168
|
+
print("error: --muse-sessions-dir requires Muse Code in the report", file=sys.stderr)
|
|
169
|
+
return 2
|
|
170
|
+
for root in muse_roots or ():
|
|
171
|
+
if not root.is_dir():
|
|
172
|
+
print(f"error: Muse Code sessions directory does not exist: {root}", file=sys.stderr)
|
|
173
|
+
return 2
|
|
174
|
+
timezone = _resolve_timezone(args.timezone, sys.stderr)
|
|
175
|
+
if timezone is None:
|
|
176
|
+
return 2
|
|
177
|
+
period = _resolve_report_range(args.start, args.end, _today_in_timezone(timezone), sys.stderr)
|
|
178
|
+
if period is None:
|
|
179
|
+
return 2
|
|
180
|
+
start, end = period
|
|
181
|
+
include_antigravity = "antigravity" in providers
|
|
182
|
+
executable = shutil.which(args.ccusage) if include_antigravity else None
|
|
183
|
+
failed = False
|
|
184
|
+
if include_antigravity and executable is None:
|
|
185
|
+
message = "install ccusage v20.0.51 or later, or supply --ccusage EXECUTABLE"
|
|
186
|
+
if not combined:
|
|
187
|
+
print(f"error: {message}", file=sys.stderr)
|
|
188
|
+
return 2
|
|
189
|
+
print(f"error: ccusage not found; Antigravity tokens are unavailable ({message})", file=sys.stderr)
|
|
190
|
+
failed = True
|
|
191
|
+
dates = [start + timedelta(days=i) for i in range((end - start).days + 1)]
|
|
192
|
+
results = {}
|
|
193
|
+
for provider in providers:
|
|
194
|
+
if provider == "muse":
|
|
195
|
+
results[provider], muse_failed = _muse_usage(muse_roots, timezone, start, end)
|
|
196
|
+
failed = failed or muse_failed
|
|
197
|
+
continue
|
|
198
|
+
tokens = None
|
|
199
|
+
if executable is not None:
|
|
200
|
+
try:
|
|
201
|
+
tokens = _token_usage(executable, start, end, timezone)
|
|
202
|
+
except (OSError, subprocess.SubprocessError, ValueError, KeyError, TypeError):
|
|
203
|
+
print(f"error: unable to read {_PROVIDERS[provider]} tokens using ccusage", file=sys.stderr)
|
|
204
|
+
failed = True
|
|
205
|
+
timing = antigravity_timing()
|
|
206
|
+
if timing.unreadable:
|
|
207
|
+
print(f"warning: skipped {timing.unreadable} unreadable {_PROVIDERS[provider]} timing inputs or records",
|
|
208
|
+
file=sys.stderr)
|
|
209
|
+
hours = {day: hours for day, hours in timing.daily_hours(timezone).items() if start <= day <= end}
|
|
210
|
+
results[provider] = Usage(tokens, hours)
|
|
211
|
+
if args.format == "csv":
|
|
212
|
+
_print_csv(results, dates)
|
|
213
|
+
else:
|
|
214
|
+
title = "Coding agent usage" if combined else "Google coding agent usage"
|
|
215
|
+
_print_text(results, dates, timezone, title)
|
|
216
|
+
return int(failed)
|