cli-consumption 0.4.4__tar.gz → 0.5.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 (71) hide show
  1. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/CHANGELOG.md +92 -1
  2. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/PKG-INFO +18 -14
  3. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/README.md +15 -11
  4. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/pyproject.toml +5 -2
  5. cli_consumption-0.5.0/src/cli_consumption/adapters/_incremental.py +128 -0
  6. cli_consumption-0.5.0/src/cli_consumption/adapters/_kimi_code.py +399 -0
  7. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/_shared.py +37 -3
  8. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/amp.py +71 -17
  9. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/base.py +7 -1
  10. cli_consumption-0.5.0/src/cli_consumption/adapters/claude.py +872 -0
  11. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/cline.py +20 -2
  12. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/codex.py +123 -112
  13. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/continue_cli.py +73 -19
  14. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/copilot.py +28 -17
  15. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/crush.py +14 -1
  16. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/cursor.py +21 -16
  17. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/gemini.py +135 -53
  18. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/grok.py +31 -9
  19. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/kimi.py +12 -4
  20. cli_consumption-0.5.0/src/cli_consumption/adapters/mistral_vibe.py +558 -0
  21. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/opencode.py +389 -98
  22. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/pi.py +87 -25
  23. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/qwen.py +78 -26
  24. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/registry.py +85 -47
  25. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/cli.py +339 -50
  26. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/exporting.py +2 -2
  27. cli_consumption-0.5.0/src/cli_consumption/frontend.py +153 -0
  28. cli_consumption-0.5.0/src/cli_consumption/migrations/versions/v0008_cache_write_duration.py +31 -0
  29. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/models.py +41 -3
  30. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/reporting.py +32 -2
  31. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/schema.py +43 -3
  32. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/snapshot_extraction.py +4 -1
  33. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/storage.py +63 -0
  34. cli_consumption-0.5.0/src/cli_consumption/web_runtime.zip +0 -0
  35. cli_consumption-0.4.4/src/cli_consumption/adapters/claude.py +0 -386
  36. cli_consumption-0.4.4/src/cli_consumption/adapters/mistral_vibe.py +0 -295
  37. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/.gitignore +0 -0
  38. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/LICENSE +0 -0
  39. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/NOTICE +0 -0
  40. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/INTER_FONT_LICENSE.txt +0 -0
  41. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/__init__.py +0 -0
  42. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/__main__.py +0 -0
  43. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/__init__.py +0 -0
  44. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/aider.py +0 -0
  45. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/amazon_q.py +0 -0
  46. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/goose.py +0 -0
  47. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/kilo.py +0 -0
  48. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/openhands.py +0 -0
  49. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/adapters/plandex.py +0 -0
  50. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/api.py +0 -0
  51. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/dashboard.py +0 -0
  52. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/dashboard_layouts.py +0 -0
  53. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/dashboard_react.css +0 -0
  54. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/dashboard_react.js +0 -0
  55. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/migrations/__init__.py +0 -0
  56. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/migrations/env.py +0 -0
  57. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/__init__.py +0 -0
  58. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0001_baseline.py +0 -0
  59. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0002_minimize_subagents.py +0 -0
  60. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0003_canonical_timestamps.py +0 -0
  61. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0004_subagent_scope_freshness.py +0 -0
  62. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0005_sync_receipts.py +0 -0
  63. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0006_dashboard_layouts.py +0 -0
  64. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0007_dashboard_layout_revision.py +0 -0
  65. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/py.typed +0 -0
  66. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/qualifications.py +0 -0
  67. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/reporting_api.py +0 -0
  68. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/retention.py +0 -0
  69. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/snapshot_files.py +0 -0
  70. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/sync.py +0 -0
  71. {cli_consumption-0.4.4 → cli_consumption-0.5.0}/src/cli_consumption/timestamps.py +0 -0
@@ -6,6 +6,95 @@ use [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.5.0] - 2026-12-03
10
+
11
+ ### Added
12
+
13
+ - The `kimi` provider now collects Kimi Code 2.x model calls, tokens, turns, tools,
14
+ compactions, and subagents from the local Wire 1.5 store alongside legacy sessions.
15
+ Sessions imported from other CLIs are skipped.
16
+ - OpenCode 2.x stores (`session_v2`, `session_message`, `session_part`) are collected;
17
+ on upgraded databases the 2.x copy of a session replaces its frozen 1.x copy, forked
18
+ history is not counted twice, and compaction usage is counted once.
19
+ - Mistral Vibe 3.x unified sessions (`logs/session/unified/`) are collected alongside
20
+ 2.x sessions. Resumed imports contribute their post-migration usage, and the saved
21
+ projection supplies totals when the listing cache is missing or behind. Sessions
22
+ imported from other tools are skipped.
23
+ - Pi `usage` entries (cache keep-alive and extension-reported requests) count as model
24
+ calls.
25
+
26
+ ### Fixed
27
+
28
+ - Gemini CLI `$patch` history records are applied, so removed messages are no longer
29
+ counted.
30
+ - Cline sessions imported from other CLIs and display-only error banners are no
31
+ longer counted.
32
+ - Crush subagent reports and hidden continuations no longer open user turns.
33
+ - Copilot replayed `checkpoint` records are ignored; Cursor subagent stores no longer
34
+ appear as separate conversations.
35
+ - Grok turns closed as interrupted on session reopen are marked aborted without an
36
+ inflated duration.
37
+ - Claude Code collection now includes subagent transcripts under
38
+ `<session>/subagents/` and legacy `agent-*.jsonl` files as separate conversations
39
+ linked to their parent session. Their tokens were previously ignored, and a legacy
40
+ agent file could replace its parent session during duplicate selection. Sidechain
41
+ replays of parent responses are not counted twice.
42
+ - Claude Code collection now counts reasoning tokens from
43
+ `output_tokens_details.thinking_tokens` as a bounded subset of output, records each
44
+ advisor sub-inference from `usage.iterations` as its own model call under the
45
+ advisor model, and keeps the provider-reported one-hour cache-write share. Advisor
46
+ tokens were previously ignored. Already stored conversations are recounted only when
47
+ a more complete copy of their transcript is collected.
48
+ - Claude Code and Codex collection now reads each provider file once instead of twice,
49
+ so the aggregate 512 MiB read limit applies to the actual store size and the
50
+ selected copy is no longer parsed a second time. Only the normalized records of the
51
+ most complete copy of each conversation are retained between files.
52
+
53
+ ### Changed
54
+
55
+ - All 21 provider qualifications were rechecked against current upstream releases
56
+ on 2026-12-03 (see the qualification ledger).
57
+
58
+ - `collect` now switches automatically to bounded, restart-safe batches when an
59
+ incremental-capable provider exceeds the aggregate candidate, provider-read, or
60
+ normalized-record limit, instead of failing with `provider_limit_exceeded`. Pass
61
+ `--no-incremental` to keep the previous all-or-nothing failure. Only the
62
+ overflowing provider is batched; JSON output reports `"incremental": true`,
63
+ `"incremental_trigger": "automatic"`, and a per-provider `"batched"` flag.
64
+ `--incremental` still forces batches and now reports
65
+ `"incremental_trigger": "requested"`.
66
+ - Bounded incremental collection now covers Claude Code, Amp, Continue CLI, Gemini
67
+ CLI, Pi, and Qwen Code in addition to Codex. Claude Code batches keep every
68
+ transcript that shares a session identity, across sources and project
69
+ directories, in one batch, so batched results equal one collection, including
70
+ replayed parent responses, and subagent relationships converge instead of being
71
+ skipped. Per-file, per-line, symlink, and single-conversation limits are
72
+ unchanged, and one command is still capped at 10,000 batches.
73
+ - Snapshot schema 2 and database revision `0008` add an optional per-model-call
74
+ `cache_write_1h_input_tokens` counter: the one-hour share of cache-write input, null
75
+ when a provider reports no duration breakdown. Collectors accept schemas 1 and 2;
76
+ clients send schema 2, so upgrade the collector before its clients. The counter is
77
+ stored for cost estimation and is not yet included in dashboards or CSV exports.
78
+
79
+ ### Security
80
+
81
+ - Update the bundled dashboard to Next.js 16.5.0 and patch vulnerable web
82
+ development dependencies.
83
+ - Patch msgpack, certifi, filelock, and virtualenv in the Python lockfile.
84
+ - Update the persistent dashboard to Next.js 16.3.8 and refresh vulnerable web
85
+ dependencies; use Parcel watcher 2.6.0 to remove the unpatched braces dependency
86
+ from the Tailwind build toolchain. Rebuild the bundled dashboard runtime.
87
+ - Refresh vulnerable urllib3 and virtualenv development dependencies in the Python
88
+ lockfile.
89
+
90
+ ## [0.4.5] - 2026-09-11
91
+
92
+ ### Added
93
+
94
+ - `serve --front` now launches the FastAPI service and a bundled production Next.js
95
+ dashboard from the Python distribution, without requiring a repository checkout or
96
+ npm installation at runtime.
97
+
9
98
  ## [0.4.4] - 2026-09-08
10
99
 
11
100
  ### Fixed
@@ -201,7 +290,9 @@ use [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
201
290
 
202
291
  - Refreshed the provider guide for the first minor release ([#26]).
203
292
 
204
- [Unreleased]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.4.4...HEAD
293
+ [Unreleased]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.5.0...HEAD
294
+ [0.5.0]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.4.5...v0.5.0
295
+ [0.4.5]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.4.4...v0.4.5
205
296
  [0.4.4]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.4.3...v0.4.4
206
297
  [0.4.3]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.4.2...v0.4.3
207
298
  [0.4.2]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.4.1...v0.4.2
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cli-consumption
3
- Version: 0.4.4
3
+ Version: 0.5.0
4
4
  Summary: Analyze and consolidate AI coding CLI consumption across machines.
5
5
  Project-URL: Homepage, https://github.com/Guillaume-Lombardo/cli-consumption
6
6
  Project-URL: Documentation, https://github.com/Guillaume-Lombardo/cli-consumption#readme
@@ -23,14 +23,14 @@ Classifier: Programming Language :: Python :: 3.14
23
23
  Classifier: Topic :: Software Development :: Quality Assurance
24
24
  Requires-Python: >=3.11
25
25
  Requires-Dist: alembic>=1.14
26
+ Requires-Dist: fastapi>=0.115
26
27
  Requires-Dist: pydantic>=2.10
27
28
  Requires-Dist: sqlalchemy>=2.0
28
29
  Requires-Dist: typer>=0.15
30
+ Requires-Dist: uvicorn>=0.34
29
31
  Provides-Extra: postgres
30
32
  Requires-Dist: psycopg[binary]>=3.2; extra == 'postgres'
31
33
  Provides-Extra: server
32
- Requires-Dist: fastapi>=0.115; extra == 'server'
33
- Requires-Dist: uvicorn>=0.34; extra == 'server'
34
34
  Provides-Extra: snapshots
35
35
  Requires-Dist: cryptography>=45; extra == 'snapshots'
36
36
  Provides-Extra: sync
@@ -72,16 +72,14 @@ CLI Consumption requires Python 3.11 or newer. Run it directly from PyPI with `u
72
72
  uv tool run cli-consumption providers
73
73
  ```
74
74
 
75
- The default package covers local collection, SQLite storage, and exports. Install only
76
- the optional runtime capabilities you use:
75
+ The default package covers local collection, SQLite storage, exports, and the local
76
+ HTTP server. Install only the optional runtime capabilities you use:
77
77
 
78
78
  - `cli-consumption[sync]` for the sync client;
79
- - `cli-consumption[server]` for the collector service;
80
79
  - `cli-consumption[postgres]` for PostgreSQL;
81
80
  - `cli-consumption[snapshots]` for signed, compressed offline snapshot files.
82
81
 
83
- Extras can be combined, for example `cli-consumption[server,postgres]` on a central
84
- collector.
82
+ Extras can be combined, for example `cli-consumption[postgres]` on a central collector.
85
83
 
86
84
  ## Quick start
87
85
 
@@ -100,7 +98,7 @@ tables are generated only when `--csv` is passed.
100
98
  Dashboard development lives in the locked npm workspace under `packages/`. It builds
101
99
  provider-neutral ESM analytics, shared React presentation primitives, and deterministic
102
100
  React/Tailwind browser assets that Python embeds in the wheel. The React runtime is the
103
- only offline renderer; installing or using the Python CLI does not require Node.js.
101
+ only offline renderer; collection and offline reporting do not require Node.js.
104
102
 
105
103
  The authenticated persistent dashboard lives in `apps/web/`. It reads the same
106
104
  minimized reporting contract through a server-side Next.js BFF: the browser never
@@ -117,9 +115,10 @@ To collect one provider or select another database:
117
115
  uv run cli-consumption collect --provider codex --database usage.sqlite
118
116
  ```
119
117
 
120
- For a Codex store that exceeds aggregate collection limits, add `--incremental`.
121
- The command automatically writes bounded, restart-safe batches to the same database;
122
- individual file and line safety limits remain enforced.
118
+ When a Claude Code, Codex, Amp, Continue, Gemini, Pi, or Qwen store exceeds aggregate
119
+ collection limits, the command automatically writes bounded, restart-safe batches to
120
+ the same database; individual file and line safety limits remain enforced. Pass
121
+ `--no-incremental` to fail instead, or `--incremental` to force batches.
123
122
 
124
123
  Use `--source [LABEL=]PATH` for trusted offline copies and repeated
125
124
  `--project NAME=PATH_PREFIX` mappings for stable project labels. See the
@@ -149,8 +148,8 @@ uv run cli-consumption providers --json
149
148
 
150
149
  - Provider files are untrusted. Collection enforces discovery, file, line, SQLite row,
151
150
  structured-field, and total normalized-record limits; direct provider-file symlinks
152
- are refused. Opt-in Codex incremental collection resets only aggregate per-batch
153
- limits and keeps a separate hard batch-count ceiling.
151
+ are refused. Incremental collection resets only aggregate per-batch limits and
152
+ keeps a separate hard batch-count ceiling.
154
153
  - `collect --strict` and `sync --strict` refuse a batch when any provider skipped
155
154
  malformed records. Collection distinguishes `provider_limit_exceeded`,
156
155
  `provider_format_incompatible`, `invalid_snapshot`, and the unexpected-failure
@@ -186,6 +185,11 @@ Run `uv run cli-consumption COMMAND --help` for every option. The
186
185
  [usage guide](https://github.com/Guillaume-Lombardo/cli-consumption/blob/main/docs/usage.md)
187
186
  contains copy-ready examples.
188
187
 
188
+ To run the API and bundled persistent dashboard together, install Node.js 20.9 or
189
+ newer and use `uv tool run cli-consumption serve --front`. The command asks for a
190
+ dashboard password when `CLI_CONSUMPTION_DASHBOARD_PASSWORD` is not set; it does not
191
+ require a repository checkout or npm install.
192
+
189
193
  ## Documentation
190
194
 
191
195
  - [Usage and operations](https://github.com/Guillaume-Lombardo/cli-consumption/blob/main/docs/usage.md)
@@ -33,16 +33,14 @@ CLI Consumption requires Python 3.11 or newer. Run it directly from PyPI with `u
33
33
  uv tool run cli-consumption providers
34
34
  ```
35
35
 
36
- The default package covers local collection, SQLite storage, and exports. Install only
37
- the optional runtime capabilities you use:
36
+ The default package covers local collection, SQLite storage, exports, and the local
37
+ HTTP server. Install only the optional runtime capabilities you use:
38
38
 
39
39
  - `cli-consumption[sync]` for the sync client;
40
- - `cli-consumption[server]` for the collector service;
41
40
  - `cli-consumption[postgres]` for PostgreSQL;
42
41
  - `cli-consumption[snapshots]` for signed, compressed offline snapshot files.
43
42
 
44
- Extras can be combined, for example `cli-consumption[server,postgres]` on a central
45
- collector.
43
+ Extras can be combined, for example `cli-consumption[postgres]` on a central collector.
46
44
 
47
45
  ## Quick start
48
46
 
@@ -61,7 +59,7 @@ tables are generated only when `--csv` is passed.
61
59
  Dashboard development lives in the locked npm workspace under `packages/`. It builds
62
60
  provider-neutral ESM analytics, shared React presentation primitives, and deterministic
63
61
  React/Tailwind browser assets that Python embeds in the wheel. The React runtime is the
64
- only offline renderer; installing or using the Python CLI does not require Node.js.
62
+ only offline renderer; collection and offline reporting do not require Node.js.
65
63
 
66
64
  The authenticated persistent dashboard lives in `apps/web/`. It reads the same
67
65
  minimized reporting contract through a server-side Next.js BFF: the browser never
@@ -78,9 +76,10 @@ To collect one provider or select another database:
78
76
  uv run cli-consumption collect --provider codex --database usage.sqlite
79
77
  ```
80
78
 
81
- For a Codex store that exceeds aggregate collection limits, add `--incremental`.
82
- The command automatically writes bounded, restart-safe batches to the same database;
83
- individual file and line safety limits remain enforced.
79
+ When a Claude Code, Codex, Amp, Continue, Gemini, Pi, or Qwen store exceeds aggregate
80
+ collection limits, the command automatically writes bounded, restart-safe batches to
81
+ the same database; individual file and line safety limits remain enforced. Pass
82
+ `--no-incremental` to fail instead, or `--incremental` to force batches.
84
83
 
85
84
  Use `--source [LABEL=]PATH` for trusted offline copies and repeated
86
85
  `--project NAME=PATH_PREFIX` mappings for stable project labels. See the
@@ -110,8 +109,8 @@ uv run cli-consumption providers --json
110
109
 
111
110
  - Provider files are untrusted. Collection enforces discovery, file, line, SQLite row,
112
111
  structured-field, and total normalized-record limits; direct provider-file symlinks
113
- are refused. Opt-in Codex incremental collection resets only aggregate per-batch
114
- limits and keeps a separate hard batch-count ceiling.
112
+ are refused. Incremental collection resets only aggregate per-batch limits and
113
+ keeps a separate hard batch-count ceiling.
115
114
  - `collect --strict` and `sync --strict` refuse a batch when any provider skipped
116
115
  malformed records. Collection distinguishes `provider_limit_exceeded`,
117
116
  `provider_format_incompatible`, `invalid_snapshot`, and the unexpected-failure
@@ -147,6 +146,11 @@ Run `uv run cli-consumption COMMAND --help` for every option. The
147
146
  [usage guide](https://github.com/Guillaume-Lombardo/cli-consumption/blob/main/docs/usage.md)
148
147
  contains copy-ready examples.
149
148
 
149
+ To run the API and bundled persistent dashboard together, install Node.js 20.9 or
150
+ newer and use `uv tool run cli-consumption serve --front`. The command asks for a
151
+ dashboard password when `CLI_CONSUMPTION_DASHBOARD_PASSWORD` is not set; it does not
152
+ require a repository checkout or npm install.
153
+
150
154
  ## Documentation
151
155
 
152
156
  - [Usage and operations](https://github.com/Guillaume-Lombardo/cli-consumption/blob/main/docs/usage.md)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "cli-consumption"
7
- version = "0.4.4"
7
+ version = "0.5.0"
8
8
  description = "Analyze and consolidate AI coding CLI consumption across machines."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -25,14 +25,16 @@ classifiers = [
25
25
  ]
26
26
  dependencies = [
27
27
  "alembic>=1.14",
28
+ "fastapi>=0.115",
28
29
  "pydantic>=2.10",
29
30
  "sqlalchemy>=2.0",
30
31
  "typer>=0.15",
32
+ "uvicorn>=0.34",
31
33
  ]
32
34
 
33
35
  [project.optional-dependencies]
34
36
  postgres = ["psycopg[binary]>=3.2"]
35
- server = ["fastapi>=0.115", "uvicorn>=0.34"]
37
+ server = []
36
38
  sync = ["httpx>=0.27"]
37
39
  snapshots = [
38
40
  "cryptography>=45",
@@ -108,6 +110,7 @@ select = ["E", "F", "I", "UP", "B", "SIM", "RUF", "S"]
108
110
  "src/cli_consumption/api.py" = ["S608"]
109
111
  "src/cli_consumption/cli.py" = ["S107"]
110
112
  "src/cli_consumption/dashboard.py" = ["E501", "S608"]
113
+ "src/cli_consumption/frontend.py" = ["S603"]
111
114
  "tests/**" = ["S101"]
112
115
  "tests/smoke_minimal_install.py" = ["S603", "S607"]
113
116
  "tests/test_codex_adapter.py" = ["S608"]
@@ -0,0 +1,128 @@
1
+ """Generic bounded batching for adapters that opt into incremental collection.
2
+
3
+ An adapter opts in by implementing ``collect_incrementally``. It describes its store
4
+ as an ordered sequence of indivisible candidate groups (for example one transcript,
5
+ or one session plus its subagent transcripts) and supplies a function that collects
6
+ one batch of candidates with a fresh :class:`ProviderInputBudget`. Batches therefore
7
+ reset only aggregate candidate, read, and normalized-record budgets; per-file,
8
+ per-line, symlink, file-identity, and single-conversation limits stay unchanged.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from collections.abc import Callable, Iterable, Iterator, Sequence
14
+ from pathlib import Path
15
+ from typing import TypeVar
16
+
17
+ from cli_consumption.adapters._shared import ProviderDataLimitError, ProviderInputBudget
18
+ from cli_consumption.adapters.base import CollectionBatch
19
+ from cli_consumption.models import Snapshot, SnapshotValidationError
20
+
21
+ INCREMENTAL_CANDIDATES_PER_BATCH = 1_000
22
+ MAX_INCREMENTAL_LISTING = 1_000_000
23
+ AGGREGATE_LIMIT_CODES = frozenset(
24
+ {
25
+ "provider_candidate_limit_exceeded",
26
+ "provider_read_limit_exceeded",
27
+ "provider_record_limit_exceeded",
28
+ }
29
+ )
30
+
31
+ _Item = TypeVar("_Item")
32
+
33
+
34
+ def is_aggregate_limit(error: BaseException) -> bool:
35
+ """Return whether a smaller batch of the same store could avoid this error."""
36
+ if isinstance(error, ProviderDataLimitError):
37
+ return str(error) in AGGREGATE_LIMIT_CODES
38
+ if isinstance(error, SnapshotValidationError):
39
+ return error.code == "snapshot_too_large"
40
+ return False
41
+
42
+
43
+ def bounded_sorted_paths(paths: Iterable[Path]) -> list[Path]:
44
+ """Sort one discovery listing without charging the per-batch candidate budget."""
45
+ result: list[Path] = []
46
+ for path in paths:
47
+ if len(result) >= MAX_INCREMENTAL_LISTING:
48
+ raise ProviderDataLimitError("provider_incremental_listing_limit_exceeded")
49
+ result.append(path)
50
+ return sorted(result)
51
+
52
+
53
+ def charge_candidates(
54
+ items: Iterable[_Item], budget: ProviderInputBudget
55
+ ) -> Iterator[_Item]:
56
+ """Charge each batch candidate to the batch's own discovery budget."""
57
+ for item in items:
58
+ budget.item()
59
+ yield item
60
+
61
+
62
+ def iter_collection_batches(
63
+ groups: Iterable[Sequence[_Item]],
64
+ collect: Callable[[list[_Item]], Snapshot],
65
+ *,
66
+ candidates_per_batch: int,
67
+ subagent_merge: bool = False,
68
+ ) -> Iterator[CollectionBatch]:
69
+ """Pack ordered groups into bounded batches, splitting only on aggregate limits.
70
+
71
+ A group is never divided between batches. A batch that exceeds an aggregate
72
+ limit is split at a group boundary; a single group that still exceeds a limit
73
+ fails with the original error.
74
+ """
75
+ pending: list[list[_Item]] = []
76
+ size = 0
77
+ for group in groups:
78
+ items = list(group)
79
+ if not items:
80
+ continue
81
+ if pending and size + len(items) > candidates_per_batch:
82
+ yield from _collect_split(pending, collect, subagent_merge)
83
+ pending, size = [], 0
84
+ pending.append(items)
85
+ size += len(items)
86
+ if pending:
87
+ yield from _collect_split(pending, collect, subagent_merge)
88
+
89
+
90
+ def iter_source_batches(
91
+ provider: str,
92
+ sources: list[tuple[str, Path]],
93
+ discover: Callable[[Path], Iterable[Path]],
94
+ collect: Callable[[list[tuple[str, Path]]], Snapshot],
95
+ *,
96
+ candidates_per_batch: int,
97
+ ) -> Iterator[CollectionBatch]:
98
+ """Batch single-file conversations source by source, in discovery order."""
99
+ for machine, home in sources:
100
+ yielded = False
101
+ for batch in iter_collection_batches(
102
+ ([(machine, path)] for path in discover(home)),
103
+ collect,
104
+ candidates_per_batch=candidates_per_batch,
105
+ ):
106
+ yielded = True
107
+ yield batch
108
+ if not yielded:
109
+ yield CollectionBatch(Snapshot(provider=provider), frozenset())
110
+
111
+
112
+ def _collect_split(
113
+ groups: list[list[_Item]],
114
+ collect: Callable[[list[_Item]], Snapshot],
115
+ subagent_merge: bool,
116
+ ) -> Iterator[CollectionBatch]:
117
+ snapshot: Snapshot | None = None
118
+ try:
119
+ snapshot = collect([item for group in groups for item in group])
120
+ except (ProviderDataLimitError, SnapshotValidationError) as error:
121
+ if len(groups) == 1 or not is_aggregate_limit(error):
122
+ raise
123
+ if snapshot is not None:
124
+ yield CollectionBatch(snapshot, frozenset(), subagent_merge=subagent_merge)
125
+ return
126
+ midpoint = len(groups) // 2
127
+ yield from _collect_split(groups[:midpoint], collect, subagent_merge)
128
+ yield from _collect_split(groups[midpoint:], collect, subagent_merge)