prune_judge_sessions.py

scripts/prune_judge_sessions.py

Remove the CLI session transcripts the acceptance grader's judge calls leave behind.

main

int prune_judge_sessions.main()

Prune the named directory, or this checkout's session directory.

scripts/prune_judge_sessions.py:63

Source · 11 lines
def main() -> int:
    """@brief Entry point. @return 0."""
    target = Path(sys.argv[1]) if len(sys.argv) > 1 else session_dir(Path.cwd().resolve())
    if not target.is_dir():
        print(f"no session directory at {target}; nothing to prune")
        return 0
    removed, freed = prune(target)
    print(f"removed {removed} judge transcript(s), {freed / 1e9:.2f} GB, from {target}")
    return 0

Activity · 7 steps
lines 65–65target = Path(sys.argv[1]) if len(sys.argv) > 1 else session_dir(Path.cwd().resolve())lines 66–66◇ if not target.is_dir()lines 67–67print(f"no session directory at {target}; nothing to prune")lines 68–68return 0lines 69–69removed, freed = prune(target)lines 70–70print(f"removed {removed} judge transcript(s), {freed / 1e9:.2f} GB, from {target}")lines 71–71return 0

Flows

prune

tuple[int, int] prune_judge_sessions.prune(Path directory)

Remove every judge transcript directly under a directory.

scripts/prune_judge_sessions.py:46

Show on the map →

Called by main

Calls none

Source · 13 lines
def prune(directory: Path) -> tuple[int, int]:
    """@brief Prune. @return (removed, freed)."""
    removed = freed = 0
    for path in directory.glob("*.jsonl"):
        with path.open("rb") as handle:
            head = handle.read(_HEAD_BYTES)
        if _JUDGE_MARK in head:
            freed += path.stat().st_size
            path.unlink()
            removed += 1
    return removed, freed

Activity · 9 steps
lines 48–48removed = freed = 0lines 49–49◇ for path in directory.glob("*.jsonl")lines 50–50with path.open("rb") as handlelines 51–51head = handle.read(_HEAD_BYTES)lines 52–52◇ if _JUDGE_MARK in headlines 53–53freed += path.stat().st_sizelines 54–54path.unlink()lines 55–55removed += 1lines 56–56return removed, freed

Flows

session_dir

Path prune_judge_sessions.session_dir(Path cwd)

The CLI's session directory for a working directory.

scripts/prune_judge_sessions.py:36

Show on the map →

Called by main

Calls none

Source · 5 lines
def session_dir(cwd: Path) -> Path:
    """@brief Session dir for a cwd. @return The path."""
    return Path.home() / ".claude" / "projects" / re.sub(r"[^A-Za-z0-9]", "-", str(cwd))

Activity · 1 steps
lines 38–38return Path.home() / ".claude" / "projects" / re.sub(r"[^A-Za-z0-9]", "-", str(cwd))

Flows