conduct-cli 0.4.8__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.
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/PKG-INFO +1 -1
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/pyproject.toml +1 -1
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli/guard.py +40 -7
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli.egg-info/PKG-INFO +1 -1
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/README.md +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/setup.cfg +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/setup.py +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli/__init__.py +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli/api.py +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli/guardmcp.py +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli/main.py +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli.egg-info/SOURCES.txt +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli.egg-info/dependency_links.txt +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli.egg-info/entry_points.txt +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli.egg-info/requires.txt +0 -0
- {conduct_cli-0.4.8 → conduct_cli-0.4.10}/src/conduct_cli.egg-info/top_level.txt +0 -0
|
@@ -198,19 +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
|
-
session_id
|
|
208
|
-
tool_name
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
tokens_output =
|
|
212
|
-
|
|
213
|
-
_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)
|
|
214
247
|
sys.exit(0)
|
|
215
248
|
|
|
216
249
|
|
|
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
|