A live bird collage card for your Home Assistant dashboard.
docs: add AGENTS.md - agent guide to generate illustrations for your area
Adam Oberley0ce11669cbad
diff --git a/AGENTS.md b/AGENTS.mdnew file mode 100644index 00000000..b4171b5b--- /dev/null+++ b/AGENTS.md@@ -0,0 +1,236 @@+# AGENTS.md — generate bird illustrations for your location++**This repo's main agent-assisted task:** generate kachō-e illustrations for+the bird species at *your* location (the ones the bundled library is missing),+in the same style as the rest, and get them into the card.++A human can hand their AI coding agent (Claude Code, Cursor, etc.) this one+line:++> "Follow AGENTS.md to generate bird illustrations for my birds."++The agent should then work through the steps below, pausing only at the points+marked **ASK THE USER**. (Contributor build/test notes are at the very bottom.)++---++## 0. Prerequisites — ASK THE USER first++- **A billing-enabled Google Gemini API key.** Image generation is **not** on+ the free tier — a free key returns `HTTP 429 ... quota ... limit: 0`. Get one+ at <https://aistudio.google.com/apikey> and **enable billing** on its project.+ Cost is roughly **$0.04 per image** (2 images per species); a typical missing+ set runs a few dollars.+- **Python 3.10+** (always) and **Node 18+** (only to rebuild the card).+- Their **BirdNET-Go species list** — Step 1.++Don't generate anything until the user confirms a billing-enabled key. That 429+is the #1 thing that wastes a run.++---++## 1. Get the species list for your location++Pick one:++**A. Download the CSV from the BirdNET-Go dashboard** *(recommended — covers+every species likely at your location, not just what's been heard so far).*++1. Open your BirdNET-Go web UI (e.g. `http://homeassistant.local:8080`).+2. Go to the **Species** page — the per-location species list (each with an+ occurrence score). Use its **export / download** to save a **CSV**.+3. Any CSV with `Common Name` and `Scientific Name` columns works (other+ columns are ignored). Note the file path.++**B. Pull straight from the station** *(no download).* Skip the CSV and let the+pipeline read exactly what your station has detected:+`--from-birdnet http://<your-birdnet-go>:8080` (used in Step 3). Use this only+if the machine running the agent can reach your BirdNET-Go.++---++## 2. One-time setup++From the repo root:++```bash+python3 -m venv .venv+.venv/bin/pip install -r avian/scripts/requirements.txt certifi+```++**macOS only:** the system Python often can't verify HTTPS, which silently+breaks the Wikipedia + Gemini calls (`CERTIFICATE_VERIFY_FAILED`). Export a CA+bundle for **every** pipeline command in this session:++```bash+export SSL_CERT_FILE="$(.venv/bin/python -m certifi)"+```++Provide the Gemini key without putting it in shell history or git:++```bash+echo 'YOUR_GEMINI_KEY' > avian/scripts/.gemini_key # already gitignored+export GEMINI_API_KEY="$(tr -d '[:space:]' < avian/scripts/.gemini_key)"+```++### Style references — do this; it's what keeps your birds matching the set++The bundled art was generated with ~10 public-domain Edo-period kachō-e+woodblock prints as a *style* reference (only the painting technique is+borrowed). They aren't committed (third-party scans). Fetch them:++```bash+mkdir -p avian/assets/references/styles+UA="habird-styleref/1.0 (+https://github.com/adamoberley/HABirdDashboard)"+while IFS='|' read -r fn url; do+ curl -sSL -A "$UA" -o "avian/assets/references/styles/$fn" "$url"+done <<'REFS'+01-sparrows-on-bamboo-Koson.jpg|https://upload.wikimedia.org/wikipedia/commons/a/a0/Tapuit_bij_bamboe%2C_RP-P-1999-489.jpg+02-cawing-crow-Koson.jpg|https://upload.wikimedia.org/wikipedia/commons/a/a3/Cawing_crow_by_Ohara_Koson.jpg+03-jays-on-berry-tree-Koson.jpg|https://upload.wikimedia.org/wikipedia/commons/b/b1/Koson_-_jays-on-berry-tree.jpg+04-kingfisher-Koson.jpg|https://upload.wikimedia.org/wikipedia/commons/1/19/IJsvogel%2C_AK-RAK-2000-9.jpg+05-owl-on-ginkgo-Koson.jpg|https://upload.wikimedia.org/wikipedia/commons/9/90/Scops_Owl%2C_Cherry_Blossoms%2C_and_Moon_by_Sh%C5%8Dson.jpg+06-goose-flying-in-moonlight-Koson.jpg|https://upload.wikimedia.org/wikipedia/commons/7/74/Gans_bij_volle_maan%2C_RP-P-1999-503.jpg+07-swallows-in-flight-Koson.jpg|https://upload.wikimedia.org/wikipedia/commons/4/4c/Drie_roodstuitzwaluwen_in_duikvlucht%2C_RP-P-1999-400.jpg+08-crane-in-small-water-Koson.jpg|https://upload.wikimedia.org/wikipedia/commons/1/1a/Vissende_kraanvogel_in_ondiep_water%2C_RP-P-2005-470.jpg+09-cockatoo-Yoshida.jpg|https://upload.wikimedia.org/wikipedia/commons/c/cf/Twee_kaketoes_op_tak_met_pruimenbloesem%2C_RP-P-2005-472.jpg+10-mandarin-ducks-Yoshida.jpg|https://upload.wikimedia.org/wikipedia/commons/9/99/Mandarijneenden%2C_RP-P-1999-568.jpg+REFS+# Shrink to ~1024px so each API request stays small:+.venv/bin/python - <<'PY'+from pathlib import Path+from PIL import Image+for f in sorted(Path("avian/assets/references/styles").glob("*.jpg")):+ im = Image.open(f).convert("RGB"); w, h = im.size+ if max(w, h) > 1024:+ s = 1024 / max(w, h); im = im.resize((round(w*s), round(h*s)), Image.LANCZOS)+ im.save(f, "JPEG", quality=88, optimize=True)+PY+```++(Generation still works without these, but the style drifts from the bundled+set — so don't skip it if you want them to match.)++---++## 3. Generate → cut out → masks → card++If you used the **CSV** (option A), convert it to the `Sci|Com` label format the+pipeline reads (skip if using `--from-birdnet`):++```bash+.venv/bin/python - "PATH/TO/your-list.csv" <<'PY' > avian/scripts/mybirds.txt+import csv, sys+for r in csv.DictReader(open(sys.argv[1])):+ sci = (r.get("Scientific Name") or "").strip()+ com = (r.get("Common Name") or "").strip()+ if sci and com:+ print(sci + "|" + com)+PY+```++**Generate** — renders each bird on a flat cream ground. It **skips species+already illustrated**, so only the ones your library is missing cost anything:++```bash+.venv/bin/python avian/scripts/pregen.py --labels avian/scripts/mybirds.txt --sleep 6+# …or straight from the station instead of a CSV:+# .venv/bin/python avian/scripts/pregen.py --from-birdnet http://homeassistant.local:8080 --sleep 6+```++**Cut** the cream ground to transparency. First run downloads a ~1 GB matting+model; on CPU it's ~6 s/image:++```bash+caffeinate -i .venv/bin/python avian/scripts/cutout.py # drop `caffeinate -i` off macOS+```++> If your tool kills long-running commands, just run `cutout.py` again — it's+> idempotent (skips already-transparent files) and resumes where it stopped.++**Rebuild masks**, then bake them into the card:++```bash+.venv/bin/python avian/scripts/build_masks.py+node homeassistant/card/build.js # writes dist/habird-card.js with new masks+```++---++## 4. Quality check (recommended)++```bash+.venv/bin/python avian/scripts/verify.py --labels avian/scripts/mybirds.txt+```++This re-shows each new illustration to Gemini Vision *without* telling it the+species and flags wrong-species drift, anatomy errors, and stray perches into+`verify-results.csv`. Also eyeball the new PNGs in `avian/assets/illustrations/`.++To redo a bad one, add a one-line diagnostic note to+`avian/scripts/species-notes.json` (it carries forward), then regenerate just it:++```bash+.venv/bin/python avian/scripts/pregen.py --species "Genus species|Common Name" --force+.venv/bin/python avian/scripts/cutout.py <slug> <slug>-2+.venv/bin/python avian/scripts/build_masks.py && node homeassistant/card/build.js+```++(Slug = scientific name lowercased with non-alphanumerics turned to `-`, e.g.+`Passer domesticus` → `passer-domesticus`.)++---++## 5. Get them into your card++**A. Contribute back (easiest — and it helps the next person).** Open a pull+request adding your new PNGs, the updated `homeassistant/www/masks.js`, and the+rebuilt `dist/habird-card.js`. Once merged and released, the official HACS card+and its CDN cover your birds automatically — nothing for you to host.++**B. Self-host (private / immediate).** New species only show in the collage if+their **masks are baked into the card you load** — so you must use *your*+rebuilt `dist/habird-card.js`, not the official one. Then either:+- push your changes to your fork and point the card's **Artwork base URL**+ (`image_base`) at it:+ `https://cdn.jsdelivr.net/gh/<you>/HABirdDashboard@<branch>/avian/assets/`, or+- go fully offline: copy `avian/assets/` to `/config/www/habird-art/`, set+ `image_base: /local/habird-art/`, and add your rebuilt `dist/habird-card.js`+ as a dashboard resource.++(Standalone webpage install instead of the card? `homeassistant/install.sh`+copies `homeassistant/www/` — including the rebuilt `masks.js` — plus the+artwork into `/config/www/habird/`; no card build needed.)++---++## Gotchas (the ones that actually bite)++- **Gemini `429 ... limit: 0`** — the key is free-tier; image generation needs+ billing enabled on its Google Cloud project.+- **macOS `CERTIFICATE_VERIFY_FAILED`** — you didn't `export SSL_CERT_FILE=…`+ (Step 2). It affects both the Wikipedia reference fetch and the Gemini call.+- **`cutout.py` dies partway** — re-run it (idempotent). On macOS prefix with+ `caffeinate -i` so the machine sleeping mid-run can't interrupt it; if a tool+ times out long commands, cut in batches by passing slugs.+- **New species don't appear in the collage** — the card's silhouette masks are+ inlined in `dist/habird-card.js`; you must rebuild it (`node+ homeassistant/card/build.js`) *and* load that rebuilt file. New PNGs alone+ aren't enough.+- **Style looks off / inconsistent** — you skipped the style references (Step 2).++---++## Working on the card itself (contributors)++Not generating art — changing the card/page code? The source of truth is+`homeassistant/www/` (`apt.js`, `index.html`, `styles.css`); the HACS card is+built from it.++```bash+node homeassistant/card/build.js # rebuild dist/habird-card.js from www/+npm test # jsdom test suite (run after edits)+```++`avian/scripts/README.md` documents the illustration pipeline internals+(prompt, references, per-species tuning). `CHANGELOG.md` tracks releases.diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f0a3f4bf..6bb4a8f8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,6 +18,10 @@warblers, vireos, flycatchers, shorebirds, rails, terns and more —generated through the `avian/scripts` pipeline, lifting the bundledlibrary to 335 species.+- **`AGENTS.md`** — a step-by-step guide an AI coding agent can follow to+ generate kachō-e illustrations for the species at *your* location+ (download the BirdNET-Go list → render → cut out → masks → card), so+ anyone can fill their own regional gaps repeatably.### Changed- **Stats & Atlas** drop the page title, and the stats heatmap now usesdiff --git a/README.md b/README.mdindex 8da0b7db..78677439 100644--- a/README.md+++ b/README.md@@ -263,6 +263,13 @@ regions will have gaps. (Plain photos are deliberately not used as astand-in - they'd break the kachō-e style and have no silhouette masksfor the collage packing.) Two remedies, neither needs code changes:+> 🤖 **Easiest: let an agent do it.** Open this repo in an AI coding agent+> (Claude Code, Cursor, …) and tell it: *"Follow AGENTS.md to generate bird+> illustrations for my birds."* [`AGENTS.md`](AGENTS.md) walks it through+> downloading your BirdNET-Go species list, the whole render → cutout →+> masks → card build, and getting them into your dashboard. The manual+> steps are below.+1. **Generate illustrations for exactly YOUR birds.** The art pipeline(the same one that made the bundled library - see[`avian/scripts/README.md`](avian/scripts/README.md) for prompts,