clockwork-cli 0.1.2__py3-none-any.whl → 0.2.1__py3-none-any.whl
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/__init__.py +129 -61
- {clockwork_cli-0.1.2.dist-info → clockwork_cli-0.2.1.dist-info}/METADATA +36 -7
- clockwork_cli-0.2.1.dist-info/RECORD +8 -0
- {clockwork_cli-0.1.2.dist-info → clockwork_cli-0.2.1.dist-info}/WHEEL +1 -1
- clockwork_cli-0.1.2.dist-info/RECORD +0 -8
- {clockwork_cli-0.1.2.dist-info → clockwork_cli-0.2.1.dist-info}/entry_points.txt +0 -0
- {clockwork_cli-0.1.2.dist-info → clockwork_cli-0.2.1.dist-info}/licenses/LICENSE +0 -0
- {clockwork_cli-0.1.2.dist-info → clockwork_cli-0.2.1.dist-info}/top_level.txt +0 -0
clockwork_cli/__init__.py
CHANGED
|
@@ -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.1
|
|
58
|
+
__version__ = "0.2.1"
|
|
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):
|
|
@@ -265,7 +270,7 @@ def _claude_timestamps_from_files(files):
|
|
|
265
270
|
"""Parse user/human turn timestamps from Claude .jsonl files."""
|
|
266
271
|
timestamps = []
|
|
267
272
|
for f in sorted(files):
|
|
268
|
-
with open(f) as fh:
|
|
273
|
+
with open(f, encoding="utf-8") as fh:
|
|
269
274
|
for line in fh:
|
|
270
275
|
line = line.strip()
|
|
271
276
|
if not line:
|
|
@@ -334,7 +339,7 @@ def _codex_parse_file(path):
|
|
|
334
339
|
canonical = []
|
|
335
340
|
fallback = []
|
|
336
341
|
try:
|
|
337
|
-
with open(path) as fh:
|
|
342
|
+
with open(path, encoding="utf-8") as fh:
|
|
338
343
|
for line in fh:
|
|
339
344
|
line = line.strip()
|
|
340
345
|
if not line:
|
|
@@ -392,7 +397,7 @@ def _codex_cwd_only(path):
|
|
|
392
397
|
the `session_meta` record carrying `cwd` is at the top of the rollout.
|
|
393
398
|
"""
|
|
394
399
|
try:
|
|
395
|
-
with open(path) as fh:
|
|
400
|
+
with open(path, encoding="utf-8") as fh:
|
|
396
401
|
for line in fh:
|
|
397
402
|
line = line.strip()
|
|
398
403
|
if not line:
|
|
@@ -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)
|
|
@@ -933,7 +983,25 @@ def _parse_args(argv):
|
|
|
933
983
|
return positionals, opts
|
|
934
984
|
|
|
935
985
|
|
|
986
|
+
def _force_utf8_streams():
|
|
987
|
+
"""Write UTF-8 on stdout/stderr regardless of the platform locale.
|
|
988
|
+
|
|
989
|
+
Windows falls back to the locale codepage (usually cp1252) whenever output
|
|
990
|
+
is redirected to a file or pipe, and the bar glyph and status marks used
|
|
991
|
+
below are not encodable there. Reconfiguring keeps output byte-identical
|
|
992
|
+
across platforms; the JSON export is pure ASCII either way.
|
|
993
|
+
"""
|
|
994
|
+
for stream in (sys.stdout, sys.stderr):
|
|
995
|
+
try:
|
|
996
|
+
stream.reconfigure(encoding="utf-8")
|
|
997
|
+
except (AttributeError, ValueError):
|
|
998
|
+
# Detached or replaced streams (test capture, some launchers) have
|
|
999
|
+
# nothing to reconfigure; whatever encoding they carry stands.
|
|
1000
|
+
pass
|
|
1001
|
+
|
|
1002
|
+
|
|
936
1003
|
def main():
|
|
1004
|
+
_force_utf8_streams()
|
|
937
1005
|
argv = sys.argv[1:]
|
|
938
1006
|
if "-h" in argv or "--help" in argv:
|
|
939
1007
|
print(__doc__.strip())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: clockwork-cli
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
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
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
clockwork_cli/__init__.py,sha256=qFoEGLod4QKiBAnjLBs8ygtd7NgGk5vp5Tpjn_5V5OM,36452
|
|
2
|
+
clockwork_cli/__main__.py,sha256=HcXz3nL5ocmXEASzCOKbjM3Sj6czPe8sqJSXglAjBw0,39
|
|
3
|
+
clockwork_cli-0.2.1.dist-info/licenses/LICENSE,sha256=pz4uy4Ra9e-Ks0T7UFFi8rGL86-f29m2ZOB0WgixjLY,1068
|
|
4
|
+
clockwork_cli-0.2.1.dist-info/METADATA,sha256=Udvr34v3iVXN7duh-aZLBYEirjQbKrHCjXpa-QpSepU,12227
|
|
5
|
+
clockwork_cli-0.2.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
6
|
+
clockwork_cli-0.2.1.dist-info/entry_points.txt,sha256=wmiWdgLrHpNKK9wDwCOiX4zyLFx71_G5DzydSiu8DWs,49
|
|
7
|
+
clockwork_cli-0.2.1.dist-info/top_level.txt,sha256=g5lh3hqDChq8bNBmiN2Kze86weZTddLJspNABd-2ckg,14
|
|
8
|
+
clockwork_cli-0.2.1.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
clockwork_cli/__init__.py,sha256=gQQ8iu2X08u4etVQEF4VWJgt9crFgdnJrsPTbg8fUio,33383
|
|
2
|
-
clockwork_cli/__main__.py,sha256=HcXz3nL5ocmXEASzCOKbjM3Sj6czPe8sqJSXglAjBw0,39
|
|
3
|
-
clockwork_cli-0.1.2.dist-info/licenses/LICENSE,sha256=pz4uy4Ra9e-Ks0T7UFFi8rGL86-f29m2ZOB0WgixjLY,1068
|
|
4
|
-
clockwork_cli-0.1.2.dist-info/METADATA,sha256=2VhL2BKxlbrFk6TJ0i2LjZHs_LllXBnXippsU9NgwmU,10752
|
|
5
|
-
clockwork_cli-0.1.2.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
6
|
-
clockwork_cli-0.1.2.dist-info/entry_points.txt,sha256=wmiWdgLrHpNKK9wDwCOiX4zyLFx71_G5DzydSiu8DWs,49
|
|
7
|
-
clockwork_cli-0.1.2.dist-info/top_level.txt,sha256=g5lh3hqDChq8bNBmiN2Kze86weZTddLJspNABd-2ckg,14
|
|
8
|
-
clockwork_cli-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|