cli-consumption 0.4.5__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.
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/CHANGELOG.md +83 -1
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/PKG-INFO +7 -6
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/README.md +6 -5
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/pyproject.toml +1 -1
- cli_consumption-0.5.0/src/cli_consumption/adapters/_incremental.py +128 -0
- cli_consumption-0.5.0/src/cli_consumption/adapters/_kimi_code.py +399 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/_shared.py +37 -3
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/amp.py +71 -17
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/base.py +7 -1
- cli_consumption-0.5.0/src/cli_consumption/adapters/claude.py +872 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/cline.py +20 -2
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/codex.py +123 -112
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/continue_cli.py +73 -19
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/copilot.py +28 -17
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/crush.py +14 -1
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/cursor.py +21 -16
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/gemini.py +135 -53
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/grok.py +31 -9
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/kimi.py +12 -4
- cli_consumption-0.5.0/src/cli_consumption/adapters/mistral_vibe.py +558 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/opencode.py +389 -98
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/pi.py +87 -25
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/qwen.py +78 -26
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/registry.py +85 -47
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/cli.py +154 -46
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/exporting.py +2 -2
- cli_consumption-0.5.0/src/cli_consumption/migrations/versions/v0008_cache_write_duration.py +31 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/models.py +41 -3
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/reporting.py +32 -2
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/schema.py +43 -3
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/snapshot_extraction.py +4 -1
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/storage.py +63 -0
- cli_consumption-0.5.0/src/cli_consumption/web_runtime.zip +0 -0
- cli_consumption-0.4.5/src/cli_consumption/adapters/claude.py +0 -386
- cli_consumption-0.4.5/src/cli_consumption/adapters/mistral_vibe.py +0 -295
- cli_consumption-0.4.5/src/cli_consumption/web_runtime.zip +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/.gitignore +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/LICENSE +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/NOTICE +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/INTER_FONT_LICENSE.txt +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/__init__.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/__main__.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/__init__.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/aider.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/amazon_q.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/goose.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/kilo.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/openhands.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/adapters/plandex.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/api.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/dashboard.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/dashboard_layouts.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/dashboard_react.css +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/dashboard_react.js +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/frontend.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/migrations/__init__.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/migrations/env.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/__init__.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0001_baseline.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0002_minimize_subagents.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0003_canonical_timestamps.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0004_subagent_scope_freshness.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0005_sync_receipts.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0006_dashboard_layouts.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/migrations/versions/v0007_dashboard_layout_revision.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/py.typed +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/qualifications.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/reporting_api.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/retention.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/snapshot_files.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/sync.py +0 -0
- {cli_consumption-0.4.5 → cli_consumption-0.5.0}/src/cli_consumption/timestamps.py +0 -0
|
@@ -6,6 +6,87 @@ 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
|
+
|
|
9
90
|
## [0.4.5] - 2026-09-11
|
|
10
91
|
|
|
11
92
|
### Added
|
|
@@ -209,7 +290,8 @@ use [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
209
290
|
|
|
210
291
|
- Refreshed the provider guide for the first minor release ([#26]).
|
|
211
292
|
|
|
212
|
-
[Unreleased]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.
|
|
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
|
|
213
295
|
[0.4.5]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.4.4...v0.4.5
|
|
214
296
|
[0.4.4]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.4.3...v0.4.4
|
|
215
297
|
[0.4.3]: https://github.com/Guillaume-Lombardo/cli-consumption/compare/v0.4.2...v0.4.3
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: cli-consumption
|
|
3
|
-
Version: 0.
|
|
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
|
|
@@ -115,9 +115,10 @@ To collect one provider or select another database:
|
|
|
115
115
|
uv run cli-consumption collect --provider codex --database usage.sqlite
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
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.
|
|
121
122
|
|
|
122
123
|
Use `--source [LABEL=]PATH` for trusted offline copies and repeated
|
|
123
124
|
`--project NAME=PATH_PREFIX` mappings for stable project labels. See the
|
|
@@ -147,8 +148,8 @@ uv run cli-consumption providers --json
|
|
|
147
148
|
|
|
148
149
|
- Provider files are untrusted. Collection enforces discovery, file, line, SQLite row,
|
|
149
150
|
structured-field, and total normalized-record limits; direct provider-file symlinks
|
|
150
|
-
are refused.
|
|
151
|
-
|
|
151
|
+
are refused. Incremental collection resets only aggregate per-batch limits and
|
|
152
|
+
keeps a separate hard batch-count ceiling.
|
|
152
153
|
- `collect --strict` and `sync --strict` refuse a batch when any provider skipped
|
|
153
154
|
malformed records. Collection distinguishes `provider_limit_exceeded`,
|
|
154
155
|
`provider_format_incompatible`, `invalid_snapshot`, and the unexpected-failure
|
|
@@ -76,9 +76,10 @@ To collect one provider or select another database:
|
|
|
76
76
|
uv run cli-consumption collect --provider codex --database usage.sqlite
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
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.
|
|
82
83
|
|
|
83
84
|
Use `--source [LABEL=]PATH` for trusted offline copies and repeated
|
|
84
85
|
`--project NAME=PATH_PREFIX` mappings for stable project labels. See the
|
|
@@ -108,8 +109,8 @@ uv run cli-consumption providers --json
|
|
|
108
109
|
|
|
109
110
|
- Provider files are untrusted. Collection enforces discovery, file, line, SQLite row,
|
|
110
111
|
structured-field, and total normalized-record limits; direct provider-file symlinks
|
|
111
|
-
are refused.
|
|
112
|
-
|
|
112
|
+
are refused. Incremental collection resets only aggregate per-batch limits and
|
|
113
|
+
keeps a separate hard batch-count ceiling.
|
|
113
114
|
- `collect --strict` and `sync --strict` refuse a batch when any provider skipped
|
|
114
115
|
malformed records. Collection distinguishes `provider_limit_exceeded`,
|
|
115
116
|
`provider_format_incompatible`, `invalid_snapshot`, and the unexpected-failure
|
|
@@ -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)
|