clockwork-cli 0.1.1__py3-none-any.whl → 0.2.0__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 +147 -57
- {clockwork_cli-0.1.1.dist-info → clockwork_cli-0.2.0.dist-info}/METADATA +36 -7
- clockwork_cli-0.2.0.dist-info/RECORD +8 -0
- clockwork_cli-0.1.1.dist-info/RECORD +0 -8
- {clockwork_cli-0.1.1.dist-info → clockwork_cli-0.2.0.dist-info}/WHEEL +0 -0
- {clockwork_cli-0.1.1.dist-info → clockwork_cli-0.2.0.dist-info}/entry_points.txt +0 -0
- {clockwork_cli-0.1.1.dist-info → clockwork_cli-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {clockwork_cli-0.1.1.dist-info → clockwork_cli-0.2.0.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.
|
|
58
|
+
__version__ = "0.2.0"
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
def _resolve_claude_dir():
|
|
@@ -200,9 +200,42 @@ def _print_json(obj):
|
|
|
200
200
|
print(json.dumps(obj, indent=2))
|
|
201
201
|
|
|
202
202
|
|
|
203
|
-
def
|
|
204
|
-
"""
|
|
205
|
-
|
|
203
|
+
def _stdout_target():
|
|
204
|
+
"""Best-effort name of where stdout is going, for status messages.
|
|
205
|
+
|
|
206
|
+
Returns the basename of the file when stdout is redirected to a regular
|
|
207
|
+
file (`> out.json`), or None for a terminal or a pipe. Purely cosmetic;
|
|
208
|
+
any failure degrades to None so it never affects the export itself.
|
|
209
|
+
"""
|
|
210
|
+
try:
|
|
211
|
+
if os.isatty(1):
|
|
212
|
+
return None
|
|
213
|
+
except Exception:
|
|
214
|
+
return None
|
|
215
|
+
path = None
|
|
216
|
+
try: # macOS / BSD: ask the kernel for fd 1's path
|
|
217
|
+
import fcntl
|
|
218
|
+
f_getpath = getattr(fcntl, "F_GETPATH", 50)
|
|
219
|
+
raw = fcntl.fcntl(1, f_getpath, b"\0" * 1024)
|
|
220
|
+
path = raw.split(b"\0", 1)[0].decode() or None
|
|
221
|
+
except Exception:
|
|
222
|
+
try: # Linux: /proc symlink
|
|
223
|
+
path = os.readlink("/proc/self/fd/1")
|
|
224
|
+
except Exception:
|
|
225
|
+
path = None
|
|
226
|
+
if path and os.path.isfile(path):
|
|
227
|
+
return os.path.basename(path)
|
|
228
|
+
return None
|
|
229
|
+
|
|
230
|
+
|
|
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]
|
|
206
239
|
|
|
207
240
|
|
|
208
241
|
def _display_name(path):
|
|
@@ -452,6 +485,15 @@ def _provider_label(provider):
|
|
|
452
485
|
return "CLAUDE + CODEX" if provider == "both" else provider.upper()
|
|
453
486
|
|
|
454
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
|
+
|
|
455
497
|
# --------------------------------------------------------------------------- #
|
|
456
498
|
# Output modes
|
|
457
499
|
# --------------------------------------------------------------------------- #
|
|
@@ -762,67 +804,102 @@ def export_data(provider, idle_threshold, since, until, detail, anonymize):
|
|
|
762
804
|
Higher levels are supersets: a `raw` export still carries the daily and
|
|
763
805
|
session aggregates so a consumer can start simple and drill down.
|
|
764
806
|
Timestamps are UTC-based epoch seconds; the `daily` buckets use UTC dates.
|
|
765
|
-
"""
|
|
766
|
-
projects = PROVIDERS[provider]["all"]()
|
|
767
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
|
+
"""
|
|
768
815
|
out_projects = []
|
|
816
|
+
by_provider = {}
|
|
769
817
|
grand_minutes = 0.0
|
|
770
818
|
grand_prompts = 0
|
|
771
819
|
grand_sessions = 0
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
"
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
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]
|
|
821
897
|
|
|
822
898
|
_print_json({
|
|
823
|
-
"schema": "clockwork/
|
|
899
|
+
"schema": "clockwork/v2",
|
|
824
900
|
"generated_at": datetime.now().astimezone().isoformat(),
|
|
825
|
-
"provider":
|
|
901
|
+
"provider": provider_field,
|
|
902
|
+
"providers": providers,
|
|
826
903
|
"idle_threshold_min": idle_threshold,
|
|
827
904
|
"detail": detail,
|
|
828
905
|
"anonymized": anonymize,
|
|
@@ -835,9 +912,22 @@ def export_data(provider, idle_threshold, since, until, detail, anonymize):
|
|
|
835
912
|
"minutes": round(grand_minutes, 2),
|
|
836
913
|
"prompts": grand_prompts,
|
|
837
914
|
"sessions": grand_sessions,
|
|
915
|
+
"by_provider": by_provider,
|
|
838
916
|
},
|
|
839
917
|
})
|
|
840
918
|
|
|
919
|
+
# A friendly receipt on stderr — keeps stdout pure JSON for redirection.
|
|
920
|
+
dest = _stdout_target()
|
|
921
|
+
where = dest if dest else "stdout"
|
|
922
|
+
tags = [provider_field, f"detail={detail}"]
|
|
923
|
+
if anonymize:
|
|
924
|
+
tags.append("anonymized")
|
|
925
|
+
print(f"\n ✓ export complete → {where}", file=sys.stderr)
|
|
926
|
+
print(f" {' · '.join(tags)}", file=sys.stderr)
|
|
927
|
+
print(f" {len(out_projects)} projects · {grand_prompts:,} prompts "
|
|
928
|
+
f"· {grand_sessions:,} sessions · {grand_minutes / 60:.1f}h active",
|
|
929
|
+
file=sys.stderr)
|
|
930
|
+
|
|
841
931
|
|
|
842
932
|
def list_projects(provider, as_json):
|
|
843
933
|
projects = PROVIDERS[provider]["list"]()
|
|
@@ -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
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
clockwork_cli/__init__.py,sha256=OlRHKN2tPx8eUEwBsEz_E3I9xCxNlppL1IQ9EBCuWCk,35644
|
|
2
|
+
clockwork_cli/__main__.py,sha256=HcXz3nL5ocmXEASzCOKbjM3Sj6czPe8sqJSXglAjBw0,39
|
|
3
|
+
clockwork_cli-0.2.0.dist-info/licenses/LICENSE,sha256=pz4uy4Ra9e-Ks0T7UFFi8rGL86-f29m2ZOB0WgixjLY,1068
|
|
4
|
+
clockwork_cli-0.2.0.dist-info/METADATA,sha256=B4yV8lkbt1U3sfJ2yEm2WHJn4WBstIsJxCHfBnI6d0o,12227
|
|
5
|
+
clockwork_cli-0.2.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
6
|
+
clockwork_cli-0.2.0.dist-info/entry_points.txt,sha256=wmiWdgLrHpNKK9wDwCOiX4zyLFx71_G5DzydSiu8DWs,49
|
|
7
|
+
clockwork_cli-0.2.0.dist-info/top_level.txt,sha256=g5lh3hqDChq8bNBmiN2Kze86weZTddLJspNABd-2ckg,14
|
|
8
|
+
clockwork_cli-0.2.0.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
clockwork_cli/__init__.py,sha256=o16uRA1MQIsN3c4YWx55b9n8vMpjQPRRc5bO8ktAPxs,31903
|
|
2
|
-
clockwork_cli/__main__.py,sha256=HcXz3nL5ocmXEASzCOKbjM3Sj6czPe8sqJSXglAjBw0,39
|
|
3
|
-
clockwork_cli-0.1.1.dist-info/licenses/LICENSE,sha256=pz4uy4Ra9e-Ks0T7UFFi8rGL86-f29m2ZOB0WgixjLY,1068
|
|
4
|
-
clockwork_cli-0.1.1.dist-info/METADATA,sha256=l3Mpj-xjYqAYmTqJEdUtPe5wQCSD6aS6Y9JnIF6IRcw,10752
|
|
5
|
-
clockwork_cli-0.1.1.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
6
|
-
clockwork_cli-0.1.1.dist-info/entry_points.txt,sha256=wmiWdgLrHpNKK9wDwCOiX4zyLFx71_G5DzydSiu8DWs,49
|
|
7
|
-
clockwork_cli-0.1.1.dist-info/top_level.txt,sha256=g5lh3hqDChq8bNBmiN2Kze86weZTddLJspNABd-2ckg,14
|
|
8
|
-
clockwork_cli-0.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|