agent-hours 0.3.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Philipp Mochine
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 ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ 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.
package/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # agent-hours
2
+
3
+ **Billable hours from your local coding-agent session logs — with the split no other tool gives you: hands-on / supervised / AI-autonomous. Plus an hourly worklog for your invoice attachments.**
4
+
5
+ ```
6
+ npx agent-hours --split
7
+ ```
8
+
9
+ ```
10
+ Human/AI split — three-state model (cap 10min / prompt cap 10min):
11
+ Hands-on (provably human): 9.26 h (237 prompts)
12
+ Supervised (weighted est.): 9.39 h
13
+ = Human attention (model): 18.65 h
14
+ Upper bound (inter-prompt): 21.44 h
15
+ AI autonomous (model): 18.99 h
16
+ Total (merged timeline): 37.65 h
17
+ ```
18
+
19
+ No server, no account, no telemetry, no setup. It reads the session logs your agents already write to disk — which means it works **retroactively** on every project you've ever run an agent in.
20
+
21
+ ## Why
22
+
23
+ If you freelance with AI tooling, you need defensible numbers for every invoice conversation:
24
+
25
+ 1. **How long did the work take overall?** (effort evidence)
26
+ 2. **How much of it were *you*, actively driving or supervising** — vs. the agent grinding alone while you made coffee?
27
+ 3. **What was actually done, hour by hour?** (the attachment your client never questions)
28
+
29
+ Existing tools don't answer this:
30
+
31
+ | Tool | What it gives you | What it can't do |
32
+ |---|---|---|
33
+ | WakaTime agent plugins | coding activity dashboards | no billing split, not retroactive, cloud service |
34
+ | Claude Code OpenTelemetry | `active_time` metrics | needs Prometheus/Grafana, only logs from activation onward |
35
+ | ccusage | tokens & API cost | no hours at all |
36
+
37
+ `agent-hours` is local, retroactive, billing-oriented — and it refuses to pretend one fake-precise number is the truth.
38
+
39
+ ## Features
40
+
41
+ - **Three-state human/AI split** — hands-on (provable lower bound), supervised (evidence-weighted), AI-autonomous; the old binary heuristic is always shown as the upper bound, so you get an honest band.
42
+ - **Multi-agent, one timeline** — Claude Code and Codex CLI sessions merge into a single timeline. Parallel agents never double-count wall-clock time; an agent launched *by* another agent counts as AI runtime, not as you.
43
+ - **Hourly worklog** — what was done per hour: your prompts, edited files (incl. subagents), commands, commit messages, and the away-summaries the agent itself wrote.
44
+ - **Descriptions with or without AI** — rule-based summaries are the default (deterministic, free, reproducible). `--summarize` optionally refines them via `claude -p` — the only feature that costs API money, strictly opt-in. Or pipe `--worklog-json` into the AI chat you're already paying for.
45
+ - **Exports** — CSV (hours/days, with description column and project GESAMT row), JSON, markdown worklog.
46
+ - **Battle-tested timekeeping core** — merged-timeline idle-cap math, parallel-session detection, pause analysis, cap-bonus vs. strict columns, per-session breakdown.
47
+ - **All projects at a glance** — `--all-projects` ranks everything on your machine.
48
+
49
+ ## Install (pick your comfort level)
50
+
51
+ **Level 0 — just ask your agent.** Paste this into Claude Code or Codex:
52
+
53
+ > Install agent-hours (`npx agent-hours install`) and then tell me how many hours I worked on this project this month and what I did.
54
+
55
+ **Level 1 — one command, then talk naturally:**
56
+
57
+ ```bash
58
+ npx agent-hours install # drops a skill into ~/.claude and ~/.codex
59
+ ```
60
+
61
+ From then on, questions like *"What did I work on this week?"* or *"Export a CSV of my June hours for the invoice"* just work — your agent runs the CLI and interprets the band for you.
62
+
63
+ **Level 2 — Claude Code plugin** (this repo doubles as one):
64
+
65
+ ```
66
+ /plugin marketplace add pmochine/agent-hours
67
+ /plugin install agent-hours
68
+ ```
69
+
70
+ **Level 3 — raw CLI**, no agent involved:
71
+
72
+ ## Usage
73
+
74
+ ```bash
75
+ npx agent-hours # current project, hours at several idle caps
76
+ npx agent-hours --split # hands-on / supervised / AI-autonomous
77
+ npx agent-hours --by-day --split # per-day table with split
78
+
79
+ # worklog: what was done, hour by hour
80
+ npx agent-hours --worklog # markdown, rule-based descriptions
81
+ npx agent-hours --worklog --summarize # + AI-refined lines (claude -p, paid)
82
+ npx agent-hours --worklog --csv # hourly CSV incl. description column
83
+ npx agent-hours --worklog --csv --by-day # daily CSV incl. descriptions
84
+ npx agent-hours --worklog-json # structured + LLM prompt template
85
+
86
+ # exports & scope
87
+ npx agent-hours --csv > hours.csv # plain per-day CSV (invoice tools)
88
+ npx agent-hours --json # machine-readable, full split
89
+ npx agent-hours --since 2026-06-08 --until 2026-06-12
90
+ npx agent-hours --project /path/to/repo
91
+ npx agent-hours --source claude|codex|auto # default auto: merge all agents
92
+ npx agent-hours --all-projects --split
93
+
94
+ # tuning & debugging
95
+ npx agent-hours --cap 10 --prompt-cap 10 --tz-offset 2
96
+ npx agent-hours --by-session # parallel sessions, per-file
97
+ npx agent-hours --pauses # longest gaps > cap
98
+ ```
99
+
100
+ ## Methodology
101
+
102
+ **Idle-cap timing** is the industry standard for activity-log-based time tracking (WakaTime uses a 5-minute cap, RescueTime 15): sum the gaps between consecutive events, capping each gap. The output always shows several caps (1/2/3/5/10/15) plus a *strict* column (pause > cap counts zero).
103
+
104
+ **The three-state split** answers the question a binary human/AI split gets wrong — *was the human actually there while the agent worked?*
105
+
106
+ - **Hands-on** — reaction tails: the time between the agent's last output and your next prompt. You provably read, thought, or typed. The defensible lower bound.
107
+ - **Supervised** — the agent-working part of each prompt window, weighted by watch evidence: you reacted within 30 s afterwards (you were watching) ⇒ 100 %, within 5 min ⇒ 50 %, slower ⇒ 0 %. Hard presence proof — you typed a queued message mid-turn, or edited a file in your editor while the agent ran — forces 100 %.
108
+ - **AI autonomous** — the rest of agent runtime.
109
+
110
+ What you bill is your decision; the tool gives you the evidence and the band.
111
+
112
+ Classification details verified against real logs: scheduled-task and hook "prompts" are filtered out (`promptSource: "system"`), queued messages are credited at the moment you *typed* them, compact-continuation summaries don't count, subagent transcripts are merged in as machine work, and Codex `exec` sessions (launched by scripts or other agents) count entirely as AI runtime.
113
+
114
+ ## Sources
115
+
116
+ | Agent | Status | Logs read from |
117
+ |---|---|---|
118
+ | Claude Code | ✅ | `~/.claude/projects/<hash>/*.jsonl` + `<session>/subagents/` |
119
+ | Codex CLI | ✅ | `~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl` (matched via `cwd`) |
120
+ | Gemini CLI, opencode, Cursor, Aider | planned | adapter interface in `src/sources/` |
121
+
122
+ Adding an agent = one adapter file that yields `{timestamp, kind: prompt|work, presence}` events. PRs welcome.
123
+
124
+ ## Retroactive use & log retention
125
+
126
+ Everything works retroactively — **as long as the logs are still on disk**:
127
+
128
+ - **Claude Code** prunes old transcripts after `cleanupPeriodDays` (default: 30 days). For billing, raise it in `~/.claude/settings.json`: `{"cleanupPeriodDays": 365}` — do this *before* you need last quarter's hours.
129
+ - **Codex CLI** keeps sessions indefinitely (date-partitioned folders).
130
+
131
+ Rule of thumb: run your exports when you invoice, archive the CSV/JSON next to the invoice, and you're audit-proof regardless of retention.
132
+
133
+ ### Honest caveats
134
+
135
+ - The logs only see the agent CLI. Time in the browser, on calls, reading docs, or in another editor is invisible (external file edits show up only as presence signals). Real-world reconciliation says: **add 15–25 %**.
136
+ - "Supervised" is a weighted estimate, not a stopwatch. A fast reaction proves presence at the end of a window, not throughout — which is exactly why supervision is capped per prompt window.
137
+ - If *cap bonus* and *strict* columns diverge a lot, your sessions had many long waits — quote the strict number to be conservative.
138
+
139
+ ## Roadmap
140
+
141
+ - **Rates & invoice math** — `--rate 90 --currency EUR`: money columns, plus a three-anchor pricing suggestion (AI-hours floor / senior-equivalent / market).
142
+ - **HTML report** — one printable file as the invoice attachment.
143
+ - **Git triangulation** — `--git`: inter-commit hours as a cross-check column.
144
+ - **`--by-week` / `--by-month`** grouping for retainer billing.
145
+ - **Retention guard** — warn when logs approach cleanup age; `agent-hours archive` to snapshot them.
146
+ - **More agents** — Gemini CLI, opencode, Cursor, Aider.
147
+ - **Optional live precision** — opt-in macOS idle-time sampler to separate "watching" from "AFK" with hardware truth.
148
+
149
+ ## Verification
150
+
151
+ The original Python implementation (battle-tested over weeks of real invoicing) ships in [`reference/`](reference/) as a golden master. The test suite runs the same legacy-format fixtures through both implementations and fails on any numeric difference (`npm test`).
152
+
153
+ ## License
154
+
155
+ MIT