conduct-cli 0.4.10__tar.gz → 0.4.11__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.
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/PKG-INFO +1 -1
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/pyproject.toml +1 -1
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli/guard.py +34 -2
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli.egg-info/PKG-INFO +1 -1
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/README.md +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/setup.cfg +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/setup.py +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli/__init__.py +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli/api.py +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli/guardmcp.py +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli/main.py +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli.egg-info/SOURCES.txt +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli.egg-info/dependency_links.txt +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli.egg-info/entry_points.txt +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli.egg-info/requires.txt +0 -0
- {conduct_cli-0.4.10 → conduct_cli-0.4.11}/src/conduct_cli.egg-info/top_level.txt +0 -0
|
@@ -199,7 +199,7 @@ def _post_usage(session_id, tool_name, tokens_input, tokens_output, duration_ms)
|
|
|
199
199
|
|
|
200
200
|
|
|
201
201
|
def _read_tokens_from_transcript(transcript_path, tool_use_id):
|
|
202
|
-
"""
|
|
202
|
+
"""Read token counts from Claude Code transcript (matched by tool_use_id)."""
|
|
203
203
|
try:
|
|
204
204
|
path = Path(transcript_path)
|
|
205
205
|
if not path.exists() or not tool_use_id:
|
|
@@ -232,6 +232,35 @@ def _read_tokens_from_transcript(transcript_path, tool_use_id):
|
|
|
232
232
|
return 0, 0
|
|
233
233
|
|
|
234
234
|
|
|
235
|
+
def _read_codex_tokens():
|
|
236
|
+
"""Read last_token_usage from the most recently modified Codex session file."""
|
|
237
|
+
try:
|
|
238
|
+
sessions_dir = Path.home() / ".codex" / "sessions"
|
|
239
|
+
if not sessions_dir.exists():
|
|
240
|
+
return 0, 0
|
|
241
|
+
files = sorted(sessions_dir.rglob("*.jsonl"), key=lambda p: p.stat().st_mtime, reverse=True)
|
|
242
|
+
if not files:
|
|
243
|
+
return 0, 0
|
|
244
|
+
lines = files[0].read_text(encoding="utf-8", errors="ignore").splitlines()
|
|
245
|
+
for line in reversed(lines):
|
|
246
|
+
if "token_count" not in line:
|
|
247
|
+
continue
|
|
248
|
+
try:
|
|
249
|
+
entry = json.loads(line)
|
|
250
|
+
if entry.get("type") == "event_msg":
|
|
251
|
+
info = entry.get("payload", {}).get("info", {})
|
|
252
|
+
usage = info.get("last_token_usage", {})
|
|
253
|
+
if usage:
|
|
254
|
+
total_in = usage.get("input_tokens", 0)
|
|
255
|
+
total_out = usage.get("output_tokens", 0) + usage.get("reasoning_output_tokens", 0)
|
|
256
|
+
return total_in, total_out
|
|
257
|
+
except Exception:
|
|
258
|
+
continue
|
|
259
|
+
except Exception:
|
|
260
|
+
pass
|
|
261
|
+
return 0, 0
|
|
262
|
+
|
|
263
|
+
|
|
235
264
|
def post_usage_main():
|
|
236
265
|
"""PostToolUse hook entrypoint — captures token usage and duration."""
|
|
237
266
|
try:
|
|
@@ -242,7 +271,10 @@ def post_usage_main():
|
|
|
242
271
|
tool_name = (data.get("tool_name") or "").lower()
|
|
243
272
|
tool_use_id = data.get("tool_use_id")
|
|
244
273
|
transcript_path = data.get("transcript_path")
|
|
245
|
-
|
|
274
|
+
if transcript_path:
|
|
275
|
+
tokens_input, tokens_output = _read_tokens_from_transcript(transcript_path, tool_use_id)
|
|
276
|
+
else:
|
|
277
|
+
tokens_input, tokens_output = _read_codex_tokens()
|
|
246
278
|
_post_usage(session_id, tool_name, tokens_input, tokens_output, None)
|
|
247
279
|
sys.exit(0)
|
|
248
280
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|