clockwork-cli 0.1.2__tar.gz → 0.2.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.
- {clockwork_cli-0.1.2/src/clockwork_cli.egg-info → clockwork_cli-0.2.0}/PKG-INFO +36 -7
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0}/README.md +35 -6
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0}/pyproject.toml +1 -1
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0}/src/clockwork_cli/__init__.py +108 -58
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0/src/clockwork_cli.egg-info}/PKG-INFO +36 -7
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0}/src/clockwork_cli.egg-info/SOURCES.txt +2 -1
- clockwork_cli-0.2.0/tests/test_export.py +142 -0
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0}/LICENSE +0 -0
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0}/setup.cfg +0 -0
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0}/src/clockwork_cli/__main__.py +0 -0
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0}/src/clockwork_cli.egg-info/dependency_links.txt +0 -0
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0}/src/clockwork_cli.egg-info/entry_points.txt +0 -0
- {clockwork_cli-0.1.2 → clockwork_cli-0.2.0}/src/clockwork_cli.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clockwork-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Mine your Claude Code and Codex session logs to estimate active time
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/danielsich/clockwork
|
|
@@ -217,6 +217,9 @@ one pre-aggregated view), the export is designed to be re-analyzed downstream.
|
|
|
217
217
|
# Full-fidelity export you can re-analyze anywhere
|
|
218
218
|
clockwork claude export > clockwork.json
|
|
219
219
|
|
|
220
|
+
# Both tools in one bundle, attributed per provider (see "Provider attribution")
|
|
221
|
+
clockwork both export > clockwork.json
|
|
222
|
+
|
|
220
223
|
# Smaller / shareable: grouped sessions only, with paths stripped
|
|
221
224
|
clockwork codex export --detail sessions --anonymize > share.json
|
|
222
225
|
|
|
@@ -238,13 +241,31 @@ drops the `path`, renames projects to `project-N`, and keeps only a stable
|
|
|
238
241
|
hash `id` — so an uploaded file leaks nothing identifying while still letting a
|
|
239
242
|
tool tell projects apart across exports.
|
|
240
243
|
|
|
241
|
-
###
|
|
244
|
+
### Provider attribution
|
|
245
|
+
|
|
246
|
+
`clockwork both export` carries **both tools in one bundle** without merging
|
|
247
|
+
them: attribution lives at the project level. Every project entry has a
|
|
248
|
+
`provider`, and if the same path was touched by both Claude and Codex it emits
|
|
249
|
+
**one entry per (path, provider)** — each with its own `totals`, `daily`,
|
|
250
|
+
`sessions`, and `prompts`. A viewer can filter by provider or re-merge by path
|
|
251
|
+
for a combined view, so nothing is lost either way.
|
|
252
|
+
|
|
253
|
+
- Top-level `provider` is `"both"` when more than one provider contributed,
|
|
254
|
+
otherwise the single provider name (so a `both` export with only Claude
|
|
255
|
+
activity still reads `"claude"`).
|
|
256
|
+
- `providers` lists the sorted, distinct providers included (always present,
|
|
257
|
+
one element for a single-provider export).
|
|
258
|
+
- `totals.by_provider` breaks the grand totals down per provider; the grand
|
|
259
|
+
`totals` stay the cross-provider sum.
|
|
260
|
+
|
|
261
|
+
### Export schema (`clockwork/v2`)
|
|
242
262
|
|
|
243
263
|
```jsonc
|
|
244
264
|
{
|
|
245
|
-
"schema": "clockwork/
|
|
265
|
+
"schema": "clockwork/v2",
|
|
246
266
|
"generated_at": "2026-07-06T00:30:00+02:00", // local ISO-8601
|
|
247
|
-
"provider": "claude"
|
|
267
|
+
"provider": "both", // "claude" | "codex" | "both"
|
|
268
|
+
"providers": ["claude", "codex"], // sorted, distinct; ≥ 1 element
|
|
248
269
|
"idle_threshold_min": 30,
|
|
249
270
|
"detail": "raw", // raw | sessions | daily
|
|
250
271
|
"anonymized": false,
|
|
@@ -253,7 +274,8 @@ tool tell projects apart across exports.
|
|
|
253
274
|
"until": null,
|
|
254
275
|
"projects": [
|
|
255
276
|
{
|
|
256
|
-
"id": "0ac6be84", // stable sha1(path) prefix; survives --anonymize
|
|
277
|
+
"id": "0ac6be84", // stable sha1(provider + "\0" + path) prefix; survives --anonymize
|
|
278
|
+
"provider": "claude", // the single tool this entry's activity belongs to
|
|
257
279
|
"name": "myproject", // basename, or "project-N" when anonymized
|
|
258
280
|
"path": "/Users/you/dev/myproject", // omitted when anonymized
|
|
259
281
|
"totals": {
|
|
@@ -267,13 +289,20 @@ tool tell projects apart across exports.
|
|
|
267
289
|
"prompts": [ 1780521570, 1780521582 ] // detail == raw
|
|
268
290
|
}
|
|
269
291
|
],
|
|
270
|
-
"totals": {
|
|
292
|
+
"totals": {
|
|
293
|
+
"projects": 6, "minutes": 3392.97, "prompts": 4588, "sessions": 64,
|
|
294
|
+
"by_provider": {
|
|
295
|
+
"claude": { "projects": 4, "minutes": 2500.0, "prompts": 3000, "sessions": 40 },
|
|
296
|
+
"codex": { "projects": 2, "minutes": 892.97, "prompts": 1588, "sessions": 24 }
|
|
297
|
+
}
|
|
298
|
+
}
|
|
271
299
|
}
|
|
272
300
|
```
|
|
273
301
|
|
|
274
302
|
All instants are **UTC-based epoch seconds** (`new Date(sec * 1000)` in JS), so
|
|
275
303
|
the consumer picks the display timezone. The `schema` field is the version
|
|
276
|
-
contract —
|
|
304
|
+
contract — `clockwork/v2` is a breaking bump over `v1` (provider moved to the
|
|
305
|
+
project level), so tools should guard on it.
|
|
277
306
|
|
|
278
307
|
## License
|
|
279
308
|
|
|
@@ -199,6 +199,9 @@ one pre-aggregated view), the export is designed to be re-analyzed downstream.
|
|
|
199
199
|
# Full-fidelity export you can re-analyze anywhere
|
|
200
200
|
clockwork claude export > clockwork.json
|
|
201
201
|
|
|
202
|
+
# Both tools in one bundle, attributed per provider (see "Provider attribution")
|
|
203
|
+
clockwork both export > clockwork.json
|
|
204
|
+
|
|
202
205
|
# Smaller / shareable: grouped sessions only, with paths stripped
|
|
203
206
|
clockwork codex export --detail sessions --anonymize > share.json
|
|
204
207
|
|
|
@@ -220,13 +223,31 @@ drops the `path`, renames projects to `project-N`, and keeps only a stable
|
|
|
220
223
|
hash `id` — so an uploaded file leaks nothing identifying while still letting a
|
|
221
224
|
tool tell projects apart across exports.
|
|
222
225
|
|
|
223
|
-
###
|
|
226
|
+
### Provider attribution
|
|
227
|
+
|
|
228
|
+
`clockwork both export` carries **both tools in one bundle** without merging
|
|
229
|
+
them: attribution lives at the project level. Every project entry has a
|
|
230
|
+
`provider`, and if the same path was touched by both Claude and Codex it emits
|
|
231
|
+
**one entry per (path, provider)** — each with its own `totals`, `daily`,
|
|
232
|
+
`sessions`, and `prompts`. A viewer can filter by provider or re-merge by path
|
|
233
|
+
for a combined view, so nothing is lost either way.
|
|
234
|
+
|
|
235
|
+
- Top-level `provider` is `"both"` when more than one provider contributed,
|
|
236
|
+
otherwise the single provider name (so a `both` export with only Claude
|
|
237
|
+
activity still reads `"claude"`).
|
|
238
|
+
- `providers` lists the sorted, distinct providers included (always present,
|
|
239
|
+
one element for a single-provider export).
|
|
240
|
+
- `totals.by_provider` breaks the grand totals down per provider; the grand
|
|
241
|
+
`totals` stay the cross-provider sum.
|
|
242
|
+
|
|
243
|
+
### Export schema (`clockwork/v2`)
|
|
224
244
|
|
|
225
245
|
```jsonc
|
|
226
246
|
{
|
|
227
|
-
"schema": "clockwork/
|
|
247
|
+
"schema": "clockwork/v2",
|
|
228
248
|
"generated_at": "2026-07-06T00:30:00+02:00", // local ISO-8601
|
|
229
|
-
"provider": "claude"
|
|
249
|
+
"provider": "both", // "claude" | "codex" | "both"
|
|
250
|
+
"providers": ["claude", "codex"], // sorted, distinct; ≥ 1 element
|
|
230
251
|
"idle_threshold_min": 30,
|
|
231
252
|
"detail": "raw", // raw | sessions | daily
|
|
232
253
|
"anonymized": false,
|
|
@@ -235,7 +256,8 @@ tool tell projects apart across exports.
|
|
|
235
256
|
"until": null,
|
|
236
257
|
"projects": [
|
|
237
258
|
{
|
|
238
|
-
"id": "0ac6be84", // stable sha1(path) prefix; survives --anonymize
|
|
259
|
+
"id": "0ac6be84", // stable sha1(provider + "\0" + path) prefix; survives --anonymize
|
|
260
|
+
"provider": "claude", // the single tool this entry's activity belongs to
|
|
239
261
|
"name": "myproject", // basename, or "project-N" when anonymized
|
|
240
262
|
"path": "/Users/you/dev/myproject", // omitted when anonymized
|
|
241
263
|
"totals": {
|
|
@@ -249,13 +271,20 @@ tool tell projects apart across exports.
|
|
|
249
271
|
"prompts": [ 1780521570, 1780521582 ] // detail == raw
|
|
250
272
|
}
|
|
251
273
|
],
|
|
252
|
-
"totals": {
|
|
274
|
+
"totals": {
|
|
275
|
+
"projects": 6, "minutes": 3392.97, "prompts": 4588, "sessions": 64,
|
|
276
|
+
"by_provider": {
|
|
277
|
+
"claude": { "projects": 4, "minutes": 2500.0, "prompts": 3000, "sessions": 40 },
|
|
278
|
+
"codex": { "projects": 2, "minutes": 892.97, "prompts": 1588, "sessions": 24 }
|
|
279
|
+
}
|
|
280
|
+
}
|
|
253
281
|
}
|
|
254
282
|
```
|
|
255
283
|
|
|
256
284
|
All instants are **UTC-based epoch seconds** (`new Date(sec * 1000)` in JS), so
|
|
257
285
|
the consumer picks the display timezone. The `schema` field is the version
|
|
258
|
-
contract —
|
|
286
|
+
contract — `clockwork/v2` is a breaking bump over `v1` (provider moved to the
|
|
287
|
+
project level), so tools should guard on it.
|
|
259
288
|
|
|
260
289
|
## License
|
|
261
290
|
|
|
@@ -55,7 +55,7 @@ import hashlib
|
|
|
55
55
|
from datetime import datetime, timedelta, timezone
|
|
56
56
|
from collections import defaultdict
|
|
57
57
|
|
|
58
|
-
__version__ = "0.
|
|
58
|
+
__version__ = "0.2.0"
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
def _resolve_claude_dir():
|
|
@@ -228,9 +228,14 @@ def _stdout_target():
|
|
|
228
228
|
return None
|
|
229
229
|
|
|
230
230
|
|
|
231
|
-
def _project_id(path):
|
|
232
|
-
"""Stable short id for a
|
|
233
|
-
|
|
231
|
+
def _project_id(provider, path):
|
|
232
|
+
"""Stable short id for a (provider, path) pair (survives anonymization).
|
|
233
|
+
|
|
234
|
+
Hashing the provider alongside the path keeps ids distinct when the same
|
|
235
|
+
project is touched by more than one tool, so a combined export can carry
|
|
236
|
+
two entries for one path without id collisions.
|
|
237
|
+
"""
|
|
238
|
+
return hashlib.sha1(f"{provider}\0{path}".encode("utf-8")).hexdigest()[:8]
|
|
234
239
|
|
|
235
240
|
|
|
236
241
|
def _display_name(path):
|
|
@@ -480,6 +485,15 @@ def _provider_label(provider):
|
|
|
480
485
|
return "CLAUDE + CODEX" if provider == "both" else provider.upper()
|
|
481
486
|
|
|
482
487
|
|
|
488
|
+
def _export_providers(provider):
|
|
489
|
+
"""Concrete single-provider backends to walk for an export.
|
|
490
|
+
|
|
491
|
+
`both` fans out to each real provider so a project's activity can be
|
|
492
|
+
attributed per provider; a single provider exports just itself.
|
|
493
|
+
"""
|
|
494
|
+
return ["claude", "codex"] if provider == "both" else [provider]
|
|
495
|
+
|
|
496
|
+
|
|
483
497
|
# --------------------------------------------------------------------------- #
|
|
484
498
|
# Output modes
|
|
485
499
|
# --------------------------------------------------------------------------- #
|
|
@@ -790,67 +804,102 @@ def export_data(provider, idle_threshold, since, until, detail, anonymize):
|
|
|
790
804
|
Higher levels are supersets: a `raw` export still carries the daily and
|
|
791
805
|
session aggregates so a consumer can start simple and drill down.
|
|
792
806
|
Timestamps are UTC-based epoch seconds; the `daily` buckets use UTC dates.
|
|
793
|
-
"""
|
|
794
|
-
projects = PROVIDERS[provider]["all"]()
|
|
795
807
|
|
|
808
|
+
Provider attribution lives at the project level: every entry carries a
|
|
809
|
+
`provider`, and a `both` export emits one entry per (path, provider) pair
|
|
810
|
+
so a path touched by both tools appears twice — each with its own totals,
|
|
811
|
+
daily, sessions, and prompts. Top-level `provider` is "both" when more than
|
|
812
|
+
one provider contributed; `providers` lists them, and `totals.by_provider`
|
|
813
|
+
breaks the grand totals down per provider.
|
|
814
|
+
"""
|
|
796
815
|
out_projects = []
|
|
816
|
+
by_provider = {}
|
|
797
817
|
grand_minutes = 0.0
|
|
798
818
|
grand_prompts = 0
|
|
799
819
|
grand_sessions = 0
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
"
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
820
|
+
name_counter = 0
|
|
821
|
+
|
|
822
|
+
for prov in _export_providers(provider):
|
|
823
|
+
projects = PROVIDERS[prov]["all"]()
|
|
824
|
+
p_minutes = 0.0
|
|
825
|
+
p_prompts = 0
|
|
826
|
+
p_sessions = 0
|
|
827
|
+
p_projects = 0
|
|
828
|
+
|
|
829
|
+
for label, timestamps in sorted(projects, key=lambda p: p[0]):
|
|
830
|
+
timestamps = _filter_timestamps(timestamps, since, until)
|
|
831
|
+
if not timestamps:
|
|
832
|
+
continue
|
|
833
|
+
daily, _ = compute_active_hours(timestamps, idle_threshold)
|
|
834
|
+
sessions = group_sessions(timestamps, idle_threshold)
|
|
835
|
+
total_minutes = sum(daily.values())
|
|
836
|
+
|
|
837
|
+
prompts_per_day = defaultdict(int)
|
|
838
|
+
for ts in timestamps:
|
|
839
|
+
prompts_per_day[ts.date()] += 1
|
|
840
|
+
|
|
841
|
+
name_counter += 1
|
|
842
|
+
proj = {
|
|
843
|
+
"id": _project_id(prov, label),
|
|
844
|
+
"provider": prov,
|
|
845
|
+
"name": f"project-{name_counter}" if anonymize else _display_name(label),
|
|
846
|
+
"totals": {
|
|
847
|
+
"minutes": round(total_minutes, 2),
|
|
848
|
+
"prompts": len(timestamps),
|
|
849
|
+
"sessions": len(sessions),
|
|
850
|
+
"active_days": len(daily),
|
|
851
|
+
"first": int(timestamps[0].timestamp()),
|
|
852
|
+
"last": int(timestamps[-1].timestamp()),
|
|
853
|
+
},
|
|
854
|
+
"daily": [
|
|
855
|
+
{"date": str(day),
|
|
856
|
+
"minutes": round(daily[day], 2),
|
|
857
|
+
"prompts": prompts_per_day[day]}
|
|
858
|
+
for day in sorted(daily)
|
|
859
|
+
],
|
|
860
|
+
}
|
|
861
|
+
if not anonymize:
|
|
862
|
+
proj["path"] = label
|
|
863
|
+
if detail in ("sessions", "raw"):
|
|
864
|
+
proj["sessions"] = [
|
|
865
|
+
{"start": int(s.timestamp()),
|
|
866
|
+
"end": int(e.timestamp()),
|
|
867
|
+
"minutes": round((e - s).total_seconds() / 60, 2),
|
|
868
|
+
"prompts": c}
|
|
869
|
+
for s, e, c in sessions
|
|
870
|
+
]
|
|
871
|
+
if detail == "raw":
|
|
872
|
+
proj["prompts"] = [int(ts.timestamp()) for ts in timestamps]
|
|
873
|
+
|
|
874
|
+
out_projects.append(proj)
|
|
875
|
+
p_projects += 1
|
|
876
|
+
p_minutes += total_minutes
|
|
877
|
+
p_prompts += len(timestamps)
|
|
878
|
+
p_sessions += len(sessions)
|
|
879
|
+
|
|
880
|
+
if p_projects:
|
|
881
|
+
by_provider[prov] = {
|
|
882
|
+
"projects": p_projects,
|
|
883
|
+
"minutes": round(p_minutes, 2),
|
|
884
|
+
"prompts": p_prompts,
|
|
885
|
+
"sessions": p_sessions,
|
|
886
|
+
}
|
|
887
|
+
grand_minutes += p_minutes
|
|
888
|
+
grand_prompts += p_prompts
|
|
889
|
+
grand_sessions += p_sessions
|
|
890
|
+
|
|
891
|
+
# Report the providers that actually contributed activity; fall back to the
|
|
892
|
+
# requested set so a single-provider export is never emitted with an empty
|
|
893
|
+
# `providers` list even when nothing matched the filters.
|
|
894
|
+
present = sorted(by_provider)
|
|
895
|
+
providers = present if present else sorted(_export_providers(provider))
|
|
896
|
+
provider_field = "both" if len(providers) > 1 else providers[0]
|
|
849
897
|
|
|
850
898
|
_print_json({
|
|
851
|
-
"schema": "clockwork/
|
|
899
|
+
"schema": "clockwork/v2",
|
|
852
900
|
"generated_at": datetime.now().astimezone().isoformat(),
|
|
853
|
-
"provider":
|
|
901
|
+
"provider": provider_field,
|
|
902
|
+
"providers": providers,
|
|
854
903
|
"idle_threshold_min": idle_threshold,
|
|
855
904
|
"detail": detail,
|
|
856
905
|
"anonymized": anonymize,
|
|
@@ -863,13 +912,14 @@ def export_data(provider, idle_threshold, since, until, detail, anonymize):
|
|
|
863
912
|
"minutes": round(grand_minutes, 2),
|
|
864
913
|
"prompts": grand_prompts,
|
|
865
914
|
"sessions": grand_sessions,
|
|
915
|
+
"by_provider": by_provider,
|
|
866
916
|
},
|
|
867
917
|
})
|
|
868
918
|
|
|
869
919
|
# A friendly receipt on stderr — keeps stdout pure JSON for redirection.
|
|
870
920
|
dest = _stdout_target()
|
|
871
921
|
where = dest if dest else "stdout"
|
|
872
|
-
tags = [
|
|
922
|
+
tags = [provider_field, f"detail={detail}"]
|
|
873
923
|
if anonymize:
|
|
874
924
|
tags.append("anonymized")
|
|
875
925
|
print(f"\n ✓ export complete → {where}", file=sys.stderr)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clockwork-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Mine your Claude Code and Codex session logs to estimate active time
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/danielsich/clockwork
|
|
@@ -217,6 +217,9 @@ one pre-aggregated view), the export is designed to be re-analyzed downstream.
|
|
|
217
217
|
# Full-fidelity export you can re-analyze anywhere
|
|
218
218
|
clockwork claude export > clockwork.json
|
|
219
219
|
|
|
220
|
+
# Both tools in one bundle, attributed per provider (see "Provider attribution")
|
|
221
|
+
clockwork both export > clockwork.json
|
|
222
|
+
|
|
220
223
|
# Smaller / shareable: grouped sessions only, with paths stripped
|
|
221
224
|
clockwork codex export --detail sessions --anonymize > share.json
|
|
222
225
|
|
|
@@ -238,13 +241,31 @@ drops the `path`, renames projects to `project-N`, and keeps only a stable
|
|
|
238
241
|
hash `id` — so an uploaded file leaks nothing identifying while still letting a
|
|
239
242
|
tool tell projects apart across exports.
|
|
240
243
|
|
|
241
|
-
###
|
|
244
|
+
### Provider attribution
|
|
245
|
+
|
|
246
|
+
`clockwork both export` carries **both tools in one bundle** without merging
|
|
247
|
+
them: attribution lives at the project level. Every project entry has a
|
|
248
|
+
`provider`, and if the same path was touched by both Claude and Codex it emits
|
|
249
|
+
**one entry per (path, provider)** — each with its own `totals`, `daily`,
|
|
250
|
+
`sessions`, and `prompts`. A viewer can filter by provider or re-merge by path
|
|
251
|
+
for a combined view, so nothing is lost either way.
|
|
252
|
+
|
|
253
|
+
- Top-level `provider` is `"both"` when more than one provider contributed,
|
|
254
|
+
otherwise the single provider name (so a `both` export with only Claude
|
|
255
|
+
activity still reads `"claude"`).
|
|
256
|
+
- `providers` lists the sorted, distinct providers included (always present,
|
|
257
|
+
one element for a single-provider export).
|
|
258
|
+
- `totals.by_provider` breaks the grand totals down per provider; the grand
|
|
259
|
+
`totals` stay the cross-provider sum.
|
|
260
|
+
|
|
261
|
+
### Export schema (`clockwork/v2`)
|
|
242
262
|
|
|
243
263
|
```jsonc
|
|
244
264
|
{
|
|
245
|
-
"schema": "clockwork/
|
|
265
|
+
"schema": "clockwork/v2",
|
|
246
266
|
"generated_at": "2026-07-06T00:30:00+02:00", // local ISO-8601
|
|
247
|
-
"provider": "claude"
|
|
267
|
+
"provider": "both", // "claude" | "codex" | "both"
|
|
268
|
+
"providers": ["claude", "codex"], // sorted, distinct; ≥ 1 element
|
|
248
269
|
"idle_threshold_min": 30,
|
|
249
270
|
"detail": "raw", // raw | sessions | daily
|
|
250
271
|
"anonymized": false,
|
|
@@ -253,7 +274,8 @@ tool tell projects apart across exports.
|
|
|
253
274
|
"until": null,
|
|
254
275
|
"projects": [
|
|
255
276
|
{
|
|
256
|
-
"id": "0ac6be84", // stable sha1(path) prefix; survives --anonymize
|
|
277
|
+
"id": "0ac6be84", // stable sha1(provider + "\0" + path) prefix; survives --anonymize
|
|
278
|
+
"provider": "claude", // the single tool this entry's activity belongs to
|
|
257
279
|
"name": "myproject", // basename, or "project-N" when anonymized
|
|
258
280
|
"path": "/Users/you/dev/myproject", // omitted when anonymized
|
|
259
281
|
"totals": {
|
|
@@ -267,13 +289,20 @@ tool tell projects apart across exports.
|
|
|
267
289
|
"prompts": [ 1780521570, 1780521582 ] // detail == raw
|
|
268
290
|
}
|
|
269
291
|
],
|
|
270
|
-
"totals": {
|
|
292
|
+
"totals": {
|
|
293
|
+
"projects": 6, "minutes": 3392.97, "prompts": 4588, "sessions": 64,
|
|
294
|
+
"by_provider": {
|
|
295
|
+
"claude": { "projects": 4, "minutes": 2500.0, "prompts": 3000, "sessions": 40 },
|
|
296
|
+
"codex": { "projects": 2, "minutes": 892.97, "prompts": 1588, "sessions": 24 }
|
|
297
|
+
}
|
|
298
|
+
}
|
|
271
299
|
}
|
|
272
300
|
```
|
|
273
301
|
|
|
274
302
|
All instants are **UTC-based epoch seconds** (`new Date(sec * 1000)` in JS), so
|
|
275
303
|
the consumer picks the display timezone. The `schema` field is the version
|
|
276
|
-
contract —
|
|
304
|
+
contract — `clockwork/v2` is a breaking bump over `v1` (provider moved to the
|
|
305
|
+
project level), so tools should guard on it.
|
|
277
306
|
|
|
278
307
|
## License
|
|
279
308
|
|
|
@@ -7,4 +7,5 @@ src/clockwork_cli.egg-info/PKG-INFO
|
|
|
7
7
|
src/clockwork_cli.egg-info/SOURCES.txt
|
|
8
8
|
src/clockwork_cli.egg-info/dependency_links.txt
|
|
9
9
|
src/clockwork_cli.egg-info/entry_points.txt
|
|
10
|
-
src/clockwork_cli.egg-info/top_level.txt
|
|
10
|
+
src/clockwork_cli.egg-info/top_level.txt
|
|
11
|
+
tests/test_export.py
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""Tests for the clockwork/v2 combined-provider export bundle.
|
|
2
|
+
|
|
3
|
+
These exercise ``export_data`` directly, stubbing each provider's ``all``
|
|
4
|
+
backend with fixed (path, timestamps) data so no real ~/.claude or ~/.codex
|
|
5
|
+
files are needed. Stdout is pure JSON (the receipt goes to stderr), so the
|
|
6
|
+
captured stdout parses back with ``json.loads``.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
from datetime import datetime, timezone
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
|
|
14
|
+
from clockwork_cli import PROVIDERS, export_data, _project_id
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _ts(*parts):
|
|
18
|
+
"""Build a UTC-aware datetime from (year, month, day, hour, minute)."""
|
|
19
|
+
return datetime(*parts, tzinfo=timezone.utc)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def run_export(monkeypatch, capsys, provider, claude=None, codex=None,
|
|
23
|
+
*, idle=30, detail="raw", anonymize=False,
|
|
24
|
+
since=None, until=None):
|
|
25
|
+
"""Stub the provider backends, run an export, return the parsed JSON."""
|
|
26
|
+
monkeypatch.setitem(PROVIDERS["claude"], "all", lambda: list(claude or []))
|
|
27
|
+
monkeypatch.setitem(PROVIDERS["codex"], "all", lambda: list(codex or []))
|
|
28
|
+
export_data(provider, idle, since, until, detail, anonymize)
|
|
29
|
+
out = capsys.readouterr().out
|
|
30
|
+
return json.loads(out)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# A couple of prompts on two different days for a project.
|
|
34
|
+
CLAUDE_PROJ = ("/Users/you/dev/alpha", [_ts(2026, 7, 1, 10, 0),
|
|
35
|
+
_ts(2026, 7, 1, 10, 20),
|
|
36
|
+
_ts(2026, 7, 2, 9, 0)])
|
|
37
|
+
CODEX_PROJ = ("/Users/you/dev/beta", [_ts(2026, 7, 3, 14, 0),
|
|
38
|
+
_ts(2026, 7, 3, 14, 15)])
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_single_provider_shape_is_backward_compatible(monkeypatch, capsys):
|
|
42
|
+
data = run_export(monkeypatch, capsys, "claude", claude=[CLAUDE_PROJ])
|
|
43
|
+
|
|
44
|
+
assert data["schema"] == "clockwork/v2"
|
|
45
|
+
assert data["provider"] == "claude"
|
|
46
|
+
assert data["providers"] == ["claude"]
|
|
47
|
+
assert len(data["projects"]) == 1
|
|
48
|
+
assert data["projects"][0]["provider"] == "claude"
|
|
49
|
+
assert data["projects"][0]["path"] == CLAUDE_PROJ[0]
|
|
50
|
+
assert set(data["totals"]["by_provider"]) == {"claude"}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_both_provider_export(monkeypatch, capsys):
|
|
54
|
+
data = run_export(monkeypatch, capsys, "both",
|
|
55
|
+
claude=[CLAUDE_PROJ], codex=[CODEX_PROJ])
|
|
56
|
+
|
|
57
|
+
assert data["provider"] == "both"
|
|
58
|
+
assert data["providers"] == ["claude", "codex"]
|
|
59
|
+
|
|
60
|
+
providers_seen = {p["provider"] for p in data["projects"]}
|
|
61
|
+
assert providers_seen == {"claude", "codex"}
|
|
62
|
+
# Every project entry is attributed to exactly one provider.
|
|
63
|
+
assert all(p["provider"] in ("claude", "codex") for p in data["projects"])
|
|
64
|
+
assert set(data["totals"]["by_provider"]) == {"claude", "codex"}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_same_path_two_providers_yields_two_entries(monkeypatch, capsys):
|
|
68
|
+
shared = "/Users/you/dev/shared"
|
|
69
|
+
claude = [(shared, [_ts(2026, 7, 1, 10, 0), _ts(2026, 7, 1, 10, 30)])]
|
|
70
|
+
codex = [(shared, [_ts(2026, 7, 2, 11, 0)])]
|
|
71
|
+
|
|
72
|
+
data = run_export(monkeypatch, capsys, "both", claude=claude, codex=codex)
|
|
73
|
+
|
|
74
|
+
entries = [p for p in data["projects"] if p["path"] == shared]
|
|
75
|
+
assert len(entries) == 2
|
|
76
|
+
assert {e["provider"] for e in entries} == {"claude", "codex"}
|
|
77
|
+
# Distinct, provider-scoped ids for the same path.
|
|
78
|
+
assert entries[0]["id"] != entries[1]["id"]
|
|
79
|
+
assert data["totals"]["projects"] == 2
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_by_provider_totals_sum_to_grand(monkeypatch, capsys):
|
|
83
|
+
data = run_export(monkeypatch, capsys, "both",
|
|
84
|
+
claude=[CLAUDE_PROJ], codex=[CODEX_PROJ])
|
|
85
|
+
|
|
86
|
+
by = data["totals"]["by_provider"]
|
|
87
|
+
grand = data["totals"]
|
|
88
|
+
|
|
89
|
+
assert by["claude"]["projects"] + by["codex"]["projects"] == grand["projects"]
|
|
90
|
+
assert by["claude"]["prompts"] + by["codex"]["prompts"] == grand["prompts"]
|
|
91
|
+
assert by["claude"]["sessions"] + by["codex"]["sessions"] == grand["sessions"]
|
|
92
|
+
assert (round(by["claude"]["minutes"] + by["codex"]["minutes"], 2)
|
|
93
|
+
== grand["minutes"])
|
|
94
|
+
|
|
95
|
+
# Claude side: 3 prompts, two active days.
|
|
96
|
+
assert by["claude"]["prompts"] == 3
|
|
97
|
+
assert by["codex"]["prompts"] == 2
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_id_is_provider_path_hash_and_stable_under_anonymize(monkeypatch, capsys):
|
|
101
|
+
plain = run_export(monkeypatch, capsys, "both",
|
|
102
|
+
claude=[CLAUDE_PROJ], codex=[CODEX_PROJ])
|
|
103
|
+
anon = run_export(monkeypatch, capsys, "both",
|
|
104
|
+
claude=[CLAUDE_PROJ], codex=[CODEX_PROJ], anonymize=True)
|
|
105
|
+
|
|
106
|
+
def ids_by_provider(bundle):
|
|
107
|
+
return {p["provider"]: p["id"] for p in bundle["projects"]}
|
|
108
|
+
|
|
109
|
+
assert ids_by_provider(plain) == ids_by_provider(anon)
|
|
110
|
+
# The id is the documented sha1(provider + "\0" + path) prefix.
|
|
111
|
+
assert ids_by_provider(plain)["claude"] == _project_id("claude", CLAUDE_PROJ[0])
|
|
112
|
+
assert ids_by_provider(plain)["codex"] == _project_id("codex", CODEX_PROJ[0])
|
|
113
|
+
|
|
114
|
+
# Anonymized output drops the path and renames projects.
|
|
115
|
+
assert all("path" not in p for p in anon["projects"])
|
|
116
|
+
assert all(p["name"].startswith("project-") for p in anon["projects"])
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_provider_filtering(monkeypatch, capsys):
|
|
120
|
+
claude_only = run_export(monkeypatch, capsys, "claude",
|
|
121
|
+
claude=[CLAUDE_PROJ], codex=[CODEX_PROJ])
|
|
122
|
+
assert claude_only["providers"] == ["claude"]
|
|
123
|
+
assert {p["provider"] for p in claude_only["projects"]} == {"claude"}
|
|
124
|
+
assert "codex" not in claude_only["totals"]["by_provider"]
|
|
125
|
+
|
|
126
|
+
codex_only = run_export(monkeypatch, capsys, "codex",
|
|
127
|
+
claude=[CLAUDE_PROJ], codex=[CODEX_PROJ])
|
|
128
|
+
assert codex_only["providers"] == ["codex"]
|
|
129
|
+
assert {p["provider"] for p in codex_only["projects"]} == {"codex"}
|
|
130
|
+
assert "claude" not in codex_only["totals"]["by_provider"]
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_both_with_only_one_provider_present_keeps_single_name(monkeypatch, capsys):
|
|
134
|
+
# Requested `both`, but only claude has activity.
|
|
135
|
+
data = run_export(monkeypatch, capsys, "both", claude=[CLAUDE_PROJ], codex=[])
|
|
136
|
+
assert data["provider"] == "claude"
|
|
137
|
+
assert data["providers"] == ["claude"]
|
|
138
|
+
assert set(data["totals"]["by_provider"]) == {"claude"}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
if __name__ == "__main__":
|
|
142
|
+
raise SystemExit(pytest.main([__file__, "-v"]))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|