Skip to content
This repository was archived by the owner on Aug 15, 2026. It is now read-only.

Migrate from Tapes to Paper for session recording - #16

Merged
bdougie merged 7 commits into
mainfrom
feat/paper-reader
Jun 26, 2026
Merged

bdougie merged 7 commits into
mainfrom
feat/paper-reader

Conversation

@bdougie

@bdougie bdougie commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replaces the local SQLite Tapes proxy with Paper for LLM session recording
  • Each agent in the evolution loop now spawns as paper start claude --print, giving every variant its own Paper session (visible in the Paper dashboard alongside sweeper sessions)
  • paper_reader.py reads sessions via the local paperd API + Claude Code JSONL transcripts, keeping the same TapeReader/TapeSession/TapeEntry interface so observer.py required only a one-line import change

What changed

  • scripts/paper_reader.py (new): two-source hybrid — Paper API (/v1/sessions) for session discovery filtered by cwd, local ~/.claude/projects/.../session_id.jsonl for transcript content
  • scripts/run_10_agents.py: each variant spawns paper start claude -- --print --dangerously-skip-permissions <prompt> instead of a Python subprocess; strips ANTHROPIC_API_KEY/ANTHROPIC_BASE_URL so Paper handles auth (mirrors sweeper's claude.go)
  • scripts/observer.py: from tape_reader → from paper_reader
  • scripts/observe_cli.py: drops tapes db path detection, memory defaults to pokedex/memory/
  • scripts/install.sh: removes Tapes CLI install, adds ANTHROPIC_BASE_URL presence check
  • jcard.toml: drops tapes sidecar, orchestrator entry point is now run_10_agents.py
  • SKILL.md: fully updated for Paper; adds explicit sub-agent instructions so Claude knows what to do when spawned by run_10_agents.py
  • Deleted: tape_reader.py, tests/tape_helpers.py, tests/test_tape_reader.py
  • tests/test_observer.py: rewritten with FakeTapeReader — no SQLite dependency, 47 tests passing

Test plan

  • paper_reader.py smoke-tested against 2 live pokemon sessions — correctly lists sessions and reads JSONL transcripts
  • uv run python -m pytest tests/test_observer.py — 47 passed
  • Speedrun test: paper start claude -- --print --dangerously-skip-permissions "<prompt>" picked a starter Pokemon in 72s and appeared in Paper as session 019eff8e with cwd=/Users/bdougie/code/pcc-labs/pokemon

bdougie added 7 commits June 25, 2026 20:17
- Add paper_reader.py: reads sessions via Paper API + local JSONL transcripts,
  same TapeReader/TapeSession/TapeEntry interface as tape_reader.py
- Update run_10_agents.py: each agent spawns via 'paper start claude --print'
  instead of a Python subprocess, matching sweeper's worker pattern;
  strips ANTHROPIC_API_KEY/BASE_URL so Paper handles auth
- Update observer.py: import from paper_reader instead of tape_reader
- Update observe_cli.py: drop tapes db path detection, default memory to
  pokedex/memory/
- Update install.sh: remove Tapes CLI install, add ANTHROPIC_BASE_URL check
- Update jcard.toml: drop tapes sidecar, orchestrator runs run_10_agents.py
- Update SKILL.md: remove all Tapes references, document Paper recording,
  add explicit sub-agent instructions for run_10_agents.py prompt
- Delete tape_reader.py, tape_helpers.py, test_tape_reader.py
- Rewrite test_observer.py to use FakeTapeReader (no SQLite dependency)
paper_reader.py:
- Recognize localhost/::1 in addition to 127.0.0.1 for paperd URL
- Cap session pagination at 1000 pages (was unbounded while True)
- Catch JSONDecodeError in list_sessions (paperd non-JSON responses)
- Guard non-dict JSONL lines in _parse_jsonl_entry
- Add filesystem fallback: scan ~/.claude/projects/{slug}/*.jsonl when
  paperd is unavailable, making session discovery self-healing

run_10_agents.py:
- Only strip ANTHROPIC_API_KEY/BASE_URL when use_paper (the bare
  `claude --print` fallback needs the key to authenticate)
- Simplify _extract_fitness to a single regex; the line-scan always
  fell through for agent.py's indented JSON output

tests:
- Rewrite test_observe_cli.py: drop dead detect_db_path/--db/SQLite,
  use FakeTapeReader via monkeypatch
- Add test_paper_reader.py covering _summarize_tool_input (all branches),
  _parse_jsonl_entry, and the filesystem fallback
- Update test_run_10_agents.py for the use_paper arg and WORKSPACE patch
The observer's processed-sessions watermark is keyed by session ID, but
session IDs are namespaced by the reader: the old SQLite tape_reader
emitted SHA hashes while paper_reader emits Paper harness UUIDs. A state
file written by one reader is meaningless to the other and would leave
stale IDs accumulating forever.

Stamp observer_state.json with the reader's READER_ID and drop the
watermark when it doesn't match on load, so a reader swap reprocesses
cleanly once instead of carrying dead IDs. A missing reader key (legacy
state) is treated as a mismatch.
Rewrite README's telemetry and observational-memory sections for Paper:
- Architecture diagram and shared-mount notes drop .tapes/
- "Tapes Telemetry" → "Paper Telemetry" (paperd proxy, dashboard)
- Observational Memory describes the paper_reader two-source hybrid
  (paperd API + JSONL transcripts, offline fallback) and pokedex/memory/
- Remove the deleted --db flag; --session now takes a harness_session_id
- Project tree: tape_reader.py → paper_reader.py, install.sh checks paperd

Also fix observer.py module/class docstrings and swap the stale
.tapes/ gitignore entry for pokedex/memory/.
The old digit-range patterns (log[7-9], log1[0-9], log2[0-9]) missed
log30-69, leaking 40 local run artifacts into git status. Replace with
'ignore all log*.md except the log1-6 examples' so any run number is
covered.
- Add tests for paper_reader.py (66->100%) and run_10_agents.py (->100%),
  restoring the repo's 100% coverage gate.
- Seal test_dunder_main_calls_main at the subprocess boundary so it no longer
  launches real paper/claude/agent.py processes against the stub ROM (the
  cause of sessions stuck "Running" in Paper).
- run_one_agent: launch the child in a new session and SIGKILL the whole
  process group on timeout/error so paper->claude->agent.py descendants are
  not orphaned.
@bdougie
bdougie merged commit 32762c1 into main Jun 26, 2026
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant