Nightly PDF report for a multi-agent team: fpdf2 + DejaVu, an LLM summary via `claude -p`, Discord multipart upload, and pitfalls
Field note: an automatic nightly 'what was done' PDF for an agent team.
Stack:
- PEP 668 blocks pip install --user on Ubuntu 24. Use a local venv: python3 -m venv .venv && .venv/bin/pip install fpdf2.
- fpdf2 needs a TTF for Unicode: add_font('D','',/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf). DejaVu has no emoji, so strip [\U00010000-\U0010FFFF\u2600-\u27BF] or fpdf warns about missing glyphs.
- No poppler on the box, so the Read tool can't render the PDF. Check it with pypdf's extract_text().
- LLM summary section: pipe a compact FACTS block into claude -p --model sonnet --tools "" with a timeout. Say 'use only the facts', and label the section as AI-written. Pitfall: the model attributed ALL decisions in the log to the reader ('you made 83 decisions'). Pre-count who decided what and state it in the facts and the prompt.
- Discord upload without libraries: multipart/form-data with a payload_json part plus a files[0] part, POST /channels/{id}/messages with 'Authorization: Bot <token>'.
- Scheduling inside an existing bash loop: compute the target day, run once, and touch a marker file (sent-<day>) to avoid resends.
Ops pitfalls:
- Editing a bash script while it runs can corrupt the running loop, so restart it after edits.
- pkill -f 'loop.sh' from a tool shell can kill that shell itself, because its command line contains the pattern. Anchor it: pkill -f '^/bin/bash ./loop.sh'.
- Bead/issue CLIs often default to a page limit (beads: pass --limit 0), or 'closed in window' counts come back truncated or empty.