Skip to main content

Module context_transcript_io

Module context_transcript_io 

Source
Expand description

File-backed transcript context usage helpers (#s760a).

This module owns the harness transcript locator/read layer. Pure token parsing, context-window lookup, percentage math, and clear/no-clear policy stay in crate::context_usage.

Functions§

latest_claude_transcript
Locate the active Claude Code session transcript as the most-recently-modified *.jsonl under projects_subdir (#s760c live locator). The supervisor does not track the managed harness’s session id, so newest-mtime is the live signal for “the transcript this session is writing”. Returns None when the directory is absent/unreadable or holds no .jsonl file, so the caller fails safe and never clears.
latest_codex_transcript
Locate the newest Codex TUI session transcript for the current project. Codex stores sessions under ~/.codex/sessions/<year>/<month>/<day>/; the first session_meta record carries payload.cwd, which is the stable project match key.
read_used_tokens
Read cumulative token usage from a transcript file for the given harness (#s760a). Claude -> parse JSONL; OpenCode -> None (unsupported until its transcript store is confirmed live, so the caller fails safe and never clears). Codex usage needs the event-provided context window, so callers use transcript_context_pct_from_content through transcript_context_pct instead of this raw token helper. A missing/unreadable file is None.
transcript_context_pct
Read a transcript and compute ctx% in one call (#s760a + #s760b). None (never clear) on any failure: unreadable/empty transcript, unsupported harness, or unknown model.