fix: count Codex user_message turns in _count_human_messages (#347)

The _count_human_messages() function previously only handled Claude Code
transcript format: {"message": {"role": "user", "content": "..."}}

Codex CLI transcripts use a different schema:
{"type": "event_msg", "payload": {"type": "user_message", "message": "..."}}

This meant the stop-hook auto-save threshold never triggered for Codex
sessions because the count always returned 0.

Added detection for the Codex format so both Claude Code and Codex CLI
transcripts are counted correctly.
This commit is contained in:
Luna Mira
2026-04-09 13:33:45 +01:00
parent 26835e30ef
commit e5440e31af
+8
View File
@@ -63,6 +63,14 @@ def _count_human_messages(transcript_path: str) -> int:
if "<command-message>" in text: if "<command-message>" in text:
continue continue
count += 1 count += 1
# Also handle Codex CLI transcript format
# {"type": "event_msg", "payload": {"type": "user_message", "message": "..."}}
elif entry.get("type") == "event_msg":
payload = entry.get("payload", {})
if isinstance(payload, dict) and payload.get("type") == "user_message":
msg_text = payload.get("message", "")
if isinstance(msg_text, str) and "<command-message>" not in msg_text:
count += 1
except (json.JSONDecodeError, AttributeError): except (json.JSONDecodeError, AttributeError):
pass pass
except OSError: except OSError: