Dezio/CLAUDE.md
2026-12-02 16:25:57 -06:00

8.7 KiB

Dezio

Dezio is an all-in-one Discord bot written in Rust (twilight + songbird + axum) that runs on the owner's Chromebook server, with a website and dashboard. The current goal is making it solid: network handling that never hangs or uploads forever on the slow line, a security test of the website, media inputs and commands, and replacing the big /image command with separate /speechbubble and /caption commands. Final deliverable: a deployed bot on the Chromebook with those fixes, committed and pushed to Astar Hub. Vision: PLAN.md. Project history: ROADMAP.md.

0. Session rules — read first

  1. You are started with one plan: Plans/<NN Category>/SNNN-*.md. Read only: this file, your plan, the last 3 entries of docs/PROGRESS.md, and the files/sections your plan names.
  2. Do not open other files in Plans/ (nor ORCHESTRATOR.md, nor all of PLAN.md).
  3. Tick each checkbox in your plan file the moment it is done, one by one, never in batches. Right after each tick, sync the tracker (§Tracker). An interrupted plan resumes at its first unchecked box.
  4. Stay in scope. Out-of-scope ideas go to docs/PROGRESS.md (“Later”), not into the code.
  5. Invent nothing: check the code/docs; if a fact is still missing, ask — the orchestrator if you were started by one (never the user directly), otherwise the user.
  6. End of session: (a) end criteria verified by commands, not memory; (b) docs/PROGRESS.md entry (≤ 15 lines: done, not done, later); (c) docs/DECISIONS.md if a decision binds later plans; (d) tick your line in Plans/INDEX.md (no commentary); (e) commit SNNN: … and push to origin; (f) short report: done, not done, what the user/orchestrator must do, and any instruction that cost more than it gave.
  7. Languages: answer in English. Code, comments and user-facing text in English. Internal docs (CLAUDE.md, Plans/, PROGRESS.md) in English. Plain words, short sentences, like the existing commit messages.

Tracker

Live checklist of every plan: https://claude.ai/artifact/PRAT4HSkqn44d6QFDJeovp (collection plans, one doc per plan id). After ticking a box: ArtifactData update with url = the tracker, collection: "plans", doc_id: "SNNN", data: {"status": "running" or "done" (all boxes ticked), "items": [{"text": "<step>", "done": true/false}, … every checkbox of the plan in order], "updated": "<ISO date-time>"} and if_version = the version returned by your previous write (first time: get the doc once to read it; a doc that doesn't exist yet takes no if_version). Load the tool with ToolSearch select:ArtifactData once. If the tracker call fails, keep working and say so in the report: the plan file is the source of truth.

1. Repository layout

Root: /home/astar76/Projects/Dezio

src/main.rs            startup, gateway loop, Discord HTTP client (timeout set here), interaction dispatch
src/state.rs           shared state, the reqwest client used for web calls
src/cmd.rs             command framework (D! prefix + slash)
src/hosted.rs          files served from the website for a few hours (oversize results)
src/commands/media/    download/ (yt-dlp/ffmpeg/gallery-dl pipeline), images.rs (/image = D!fx), convert.rs, ffmpeg.rs, quote.rs, emoji.rs, mod.rs (upload_limit, safe_redirects)
src/commands/music/    voice, player, animated card upload
src/commands/…         one file/folder per feature (games, fun, lastfm, logs, tools, moderation …)
src/web/               axum website, dashboard API, OAuth, Game Boy Activity
web/                   website pages; assets/ fonts, images, emojis (copied to the server on deploy)
deploy/shape-upload.sh tc upload shaping on the server (dezio-shape.service)
docs/                  PROGRESS.md, DECISIONS.md, topgg.md
Plans/                 one plan per session (INDEX.md lists them)

Never modify: data/ contents on the server (/root/Dezio/data, live user data: back up, never delete), ~/Projects/Discord Bot (old Python bot), assets/roms/, .env.

2. Facts

  • Build and test on this PC: source ~/.cargo/env; cargo build --release and cargo test (about 227 unit tests). Tests that need the internet are #[ignore]d (cargo test live_ -- --ignored).
  • Without DEZIO_LIVE=1 the binary only lists its commands and exits. Never run it with the real token on this PC: the live bot would answer twice.
  • Local website for testing: cargo build && DISCORD_BOT_TOKEN=dev-placeholder target/debug/dezio --web-dev → http://127.0.0.1:8099 (also the dezio-web-dev entry in .claude/launch.json).
  • Server: the Chromebook, ssh [email protected] (Arch Linux, x86_64). Bot in /root/Dezio (binary dezio, assets/, web/, data/, .env). dezio-bot.service runs /root/Dezio/dezio --headless, Restart=always; website on 127.0.0.1:8080, public at https://astar76.com. Logs: journalctl -u dezio-bot.
  • The server's line is slow: measured about 425 KB/s down and 114 KB/s (≈ 0.9 Mbit/s) up, on wlan0. dezio-shape.service (deploy/shape-upload.sh, installed as /usr/local/bin/dezio-shape) caps internet-bound upload at 800 kbit with fq_codel so voice packets go first. Voice and every upload share that.
  • Discord HTTP client: one twilight Client with a 180 s timeout for every call (src/main.rs). /download retries uploads 3 times (UPLOAD_RETRIES), so a file that can't finish in 180 s costs 9+ minutes (seen 2026-11-12: a 9.2 MB video, 3 timeouts, handler took 792 s).
  • Discord's attachment limit for bots is 10 MiB unless the server is boosted (tier 2: 50 MiB, tier 3: 100 MiB). media::upload_limit reads the server's tier; FALLBACK_UPLOAD_LIMIT lives in download/plan.rs.
  • Deploying is allowed (tell the orchestrator first): cargo build --release; scp target/release/dezio [email protected]:/root/Dezio/dezio.new; on the server cp /root/Dezio/dezio /root/Dezio/dezio.bak-<date> then mv /root/Dezio/dezio.new /root/Dezio/dezio && systemctl restart dezio-bot; copy assets/ or web/ changes with rsync -a; check systemctl status dezio-bot and journalctl -u dezio-bot -n 50. A restart drops music for a few seconds. Back up any server file before changing it.

3. Code rules

  • Write like the neighbouring code. KISS, DRY, YAGNI; no abstraction without ≥ 2 uses.
  • New pure logic gets a test; a bug fix gets a regression test when feasible.
  • Limits, timeouts and retry counts are named constants next to the code that uses them, with a comment saying why the number.
  • User-facing errors go through the existing error cards (bail_user!, src/error.rs), in plain words.
  • Every command works as slash and D! prefix unless the plan says otherwise; /help pages must stay within Discord's limits (there is a test).

4. Domain pitfalls (all agents)

  • Upload time, not file size, is what breaks: at ~100 KB/s a 10 MiB file needs ~105 s on an idle line and much longer with voice. Any upload path must think in seconds.
  • Retrying a whole upload that timed out just repeats the timeout. Retry only on errors that can succeed the second time.
  • yt-dlp, ffmpeg, gallery-dl and curl are child processes fed user links: never pass user text where it can become an option (--), keep the private-network check (safe_redirects, music's check) on every fetch.
  • Security testing runs against a local copy only (--web-dev on 127.0.0.1). Never send attack traffic to https://astar76.com or Discord. Never connect to Tor or proxies.
  • Discord changes can't be tested on this PC; things only the owner checks in Discord are marked 🧑.
  • /help pages and slash registration change when commands are added or removed: run the help-limits test.

5. Verification tools

Tool Role Available after
cargo test unit tests, help-page limits, command registry now
cargo build --release release binary for the server now
target/debug/dezio --web-dev local website/dashboard on 127.0.0.1:8099 with no Discord login now
ssh [email protected] journalctl -u dezio-bot live logs (slow command lines, upload attempts) now
ssh [email protected] tc -s qdisc show dev wlan0 shaping state and drops now

Don't assume a tool exists: check first. When your plan creates a tool, add its row here.

6. Git

Remote origin = forgejo:astar76/Dezio.git (Astar Hub). Commit on master and push to origin after each plan. Never use GitHub or gh. One commit per logical step, message SNNN: … in English. No reset --hard / force push without an explicit request.

7. Definition of done

A plan is done when: all end criteria are verified by command or test; planned builds/tests are green; nothing regressed; PROGRESS / DECISIONS are up to date; the INDEX line and tracker are ticked; the work is committed and pushed. Say explicitly what was not done or verified.