conduct-cli 0.4.9__tar.gz → 0.4.10__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.9
3
+ Version: 0.4.10
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.9"
7
+ version = "0.4.10"
8
8
  description = "CLI for Conduct AI — install agents, manage projects, run tests"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -198,25 +198,52 @@ def _post_usage(session_id, tool_name, tokens_input, tokens_output, duration_ms)
198
198
  )
199
199
 
200
200
 
201
+ def _read_tokens_from_transcript(transcript_path, tool_use_id):
202
+ """Scan transcript JSONL backwards for the message that produced tool_use_id."""
203
+ try:
204
+ path = Path(transcript_path)
205
+ if not path.exists() or not tool_use_id:
206
+ return 0, 0
207
+ lines = path.read_text(encoding="utf-8", errors="ignore").splitlines()
208
+ for line in reversed(lines):
209
+ if not line.strip() or "tool_use" not in line:
210
+ continue
211
+ try:
212
+ entry = json.loads(line)
213
+ except Exception:
214
+ continue
215
+ msg = entry.get("message") or {}
216
+ usage = msg.get("usage")
217
+ if not usage:
218
+ continue
219
+ content = msg.get("content") or []
220
+ if any(
221
+ isinstance(b, dict) and b.get("type") == "tool_use" and b.get("id") == tool_use_id
222
+ for b in content
223
+ ):
224
+ total_in = (
225
+ usage.get("input_tokens", 0)
226
+ + usage.get("cache_creation_input_tokens", 0)
227
+ + usage.get("cache_read_input_tokens", 0)
228
+ )
229
+ return total_in, usage.get("output_tokens", 0)
230
+ except Exception:
231
+ pass
232
+ return 0, 0
233
+
234
+
201
235
  def post_usage_main():
202
236
  """PostToolUse hook entrypoint — captures token usage and duration."""
203
237
  try:
204
238
  data = json.load(sys.stdin)
205
239
  except Exception:
206
240
  sys.exit(0)
207
- # Write full payload to debug file so we can inspect what Claude Code sends
208
- try:
209
- debug_path = GUARD_DIR / "debug_post.json"
210
- debug_path.write_text(json.dumps(data, indent=2))
211
- except Exception:
212
- pass
213
- session_id = data.get("session_id")
214
- tool_name = (data.get("tool_name") or "").lower()
215
- usage = data.get("usage") or {}
216
- tokens_input = usage.get("input_tokens", 0)
217
- tokens_output = usage.get("output_tokens", 0)
218
- duration_ms = data.get("duration_ms")
219
- _post_usage(session_id, tool_name, tokens_input, tokens_output, duration_ms)
241
+ session_id = data.get("session_id")
242
+ tool_name = (data.get("tool_name") or "").lower()
243
+ tool_use_id = data.get("tool_use_id")
244
+ transcript_path = data.get("transcript_path")
245
+ tokens_input, tokens_output = _read_tokens_from_transcript(transcript_path, tool_use_id)
246
+ _post_usage(session_id, tool_name, tokens_input, tokens_output, None)
220
247
  sys.exit(0)
221
248
 
222
249
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conduct-cli
3
- Version: 0.4.9
3
+ Version: 0.4.10
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