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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conduct-cli
3
- Version: 0.4.10
3
+ Version: 0.4.11
4
4
  Summary: CLI for Conduct AI — install agents, manage projects, run tests
5
5
  Author-email: Conduct AI <hello@conductai.ai>
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "conduct-cli"
7
- version = "0.4.10"
7
+ version = "0.4.11"
8
8
  description = "CLI for Conduct AI — install agents, manage projects, run tests"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -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
- """Scan transcript JSONL backwards for the message that produced tool_use_id."""
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
- tokens_input, tokens_output = _read_tokens_from_transcript(transcript_path, tool_use_id)
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conduct-cli
3
- Version: 0.4.10
3
+ Version: 0.4.11
4
4
  Summary: CLI for Conduct AI — install agents, manage projects, run tests
5
5
  Author-email: Conduct AI <hello@conductai.ai>
6
6
  License: MIT
File without changes
File without changes
File without changes