Compare commits

..
Author SHA1 Message Date
62e8190d8f Move Astar Hub links to astar76.com
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-02 16:25:57 -06:00
97124682e1 docs: Astar Hub moved to astar76sites.parore-gila.ts.net
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-02 12:15:17 -06:00
9900fcb9db docs: Astar Hub moved to astar76sites.tail7c4f5e.ts.net
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-02 12:08:13 -06:00
32cab8b397 S006a: keep /dezio prefix in the Tailscale mapping
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-01 23:09:41 -06:00
1d1f0b18d0 S006a: server path change applied
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 23:02:47 -06:00
761a95cb67 S011: deploy
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 22:55:13 -06:00
df1f8b39c8 S010: tests for hostile media input, web probes, results filled
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 22:50:24 -06:00
b14d1be17f S009: build and suite check, child-process tests, results filled
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 22:46:37 -06:00
5f6e7e330c S008: audit, url 2.5.9, test file, progress
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-01 22:22:12 -06:00
887e611aeb S008: private-network DNS filter, ffmpeg protocol whitelists, decode limits, one media job per user
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-01 22:19:17 -06:00
ad6850563c S007: website security review, sign-in rate limit, sandboxed hosted files, base path fixes
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-01 22:13:57 -06:00
78370e3146 S006a: tick plan 2026-12-01 22:02:39 -06:00
c7b02db71b S006a: website under /dezio/, minimal landing page
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 22:02:35 -06:00
6d2d005b55 plans: website under /dezio/, landing page at root
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-01 21:56:45 -06:00
e17e5897bf S006: fm audit, topgg text, test file
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 21:53:15 -06:00
10e623affa S005: /speechbubble with transparent or solid bubble for pictures, GIFs and video
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 21:52:34 -06:00
1c90d16ffe S004: tick plan
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 21:50:34 -06:00
dd5e78dda4 S004: remove /image, add /caption for pictures, GIFs and video
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 21:50:16 -06:00
d53eb49f59 S003: gateway exit on dead line, voice rejoin then leave, shaping note
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 21:38:33 -06:00
feed5ec7de S002: timeout errors as user cards
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 21:36:03 -06:00
2168277fe3 S002: timeouts on ffprobe and music ffmpeg, test file
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 21:35:12 -06:00
06b6a44e43 S001: send oversize /download video as a link, tick plan
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 21:33:43 -06:00
5b99a6fad9 S001: upload budget by line speed, retry only retryable, link on timeout
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-12-01 21:32:58 -06:00
ba440ffbe9 plans: network, image commands, fm on MetaBrainz, security, test and release
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-12-01 21:26:35 -06:00
61 changed files with 2042 additions and 555 deletions

View file

@ -45,7 +45,7 @@ Never modify: `data/` contents on the server (`/root/Dezio/data`, live user data
- 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://archlinux.tail7c4f5e.ts.net. Logs: `journalctl -u dezio-bot`.
- 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`.
@ -64,7 +64,7 @@ Never modify: `data/` contents on the server (`/root/Dezio/data`, live user data
- 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://archlinux.tail7c4f5e.ts.net or Discord. Never connect to Tor or proxies.
- 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.

10
Cargo.lock generated
View file

@ -745,7 +745,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d045de693cb712d0b22c6a64be5b953f67b3ce00ab5ad3dd5d8b441886ab8e1a"
dependencies = [
"quote",
"syn 3.0.9",
"syn 2.0.119",
]
[[package]]
@ -1408,9 +1408,9 @@ dependencies = [
[[package]]
name = "form_urlencoded"
version = "1.2.2"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e"
dependencies = [
"percent-encoding",
]
@ -5900,9 +5900,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
name = "url"
version = "2.5.8"
version = "2.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a"
dependencies = [
"form_urlencoded",
"idna",

View file

@ -16,6 +16,10 @@ security test has been done beyond earlier spot fixes. `/image` (`D!fx`) bundles
recovering from drops, shaping tuned with the bot.
- Phase 2 — Image commands: `/image` and `D!fx` removed; `/speechbubble` and `/caption` (and their `D!` versions)
work like the well-known caption bots.
- Phase 2b — fm commands: every fm feature gets its data from ListenBrainz and MusicBrainz (plus the cover
fallbacks), with no leftover Last.fm API logic; only song links still point to the Last.fm website.
- Phase 2c — Website path: all of Dezio's website moves to `/dezio/` on the Tailscale URL; the root gets a minimal
landing page (to be improved later).
- Phase 3 — Security: website and dashboard, media inputs, commands and abuse, dependency audit; fixes for what is
found; tested on a local copy only.
- Phase 4 — Deploy and owner check in Discord.

View file

@ -0,0 +1,37 @@
# S001 — Uploads timed by line speed
> Category 01 Network · Model: Sonnet · Effort: medium · Depends on: — · Size: L · Human: no
> Files touched: src/commands/media/mod.rs, src/commands/media/download/{mod,plan}.rs, src/commands/media/convert.rs, src/commands/music/card.rs, src/hosted.rs, src/main.rs, other callers of attachments
## Goal
Every Discord upload is planned in seconds, not bytes (D-001): a result that would not upload in about 60-90 s at the measured ~114 KB/s, or is over the server's Discord limit, is sent as a website link (`hosted.rs`) instead. Uploads are retried only on errors that can succeed the second time; a timed-out upload is never repeated as is. PLAN Phase 1, first bullet.
## Read
- `src/commands/media/mod.rs` `upload_limit` (line ~130; still says 20 MiB for tier 0/1, Discord's real bot limit is 10 MiB)
- `src/commands/media/download/mod.rs` lines ~30-80 (constants) and ~290-400 (`upload`, `download`)
- `src/commands/media/download/plan.rs` top constants (`FALLBACK_UPLOAD_LIMIT`)
- `src/hosted.rs` (whole, 102 lines)
- `src/main.rs` line ~527 (Discord client with 180 s timeout)
- `grep -rn "Attachment::from_bytes\|attachments(" src` to list the other upload paths; read only the call sites
## Steps
- [x] Fold in the owner's loose edit (seen uncommitted in the main checkout, not in this worktree): tier 0/1 limit is 10 MiB, `FALLBACK_UPLOAD_LIMIT` = 10 MiB, `upload_limit` returns the real Discord limit (10/50/100 MiB) — do it here cleanly, with a newline after `let limit = …;`
- [x] Add one shared helper in `media/mod.rs` that returns the byte budget for one upload: `min(discord_limit, UPLOAD_SECONDS × UPLOAD_BYTES_PER_SEC)`, both named constants with a comment (114 KB/s measured 2026-11-12, see CLAUDE.md §2), plus a pure function with a unit test
- [x] `/download`: plan the target size from that budget; anything bigger goes to `hosted.rs` as a link (existing path); retry only on errors that are not timeouts (connection reset before sending, 5xx, rate limit); a timeout ends retries and falls back to the link
- [x] Other upload paths (convert, music animated card, quote, the grep list): use the same budget; oversize → link or a smaller encode, whichever the path already supports
- [x] Discord HTTP timeout: keep 180 s for uploads, but give plain API calls a shorter timeout if twilight allows it per request; otherwise write in PROGRESS "Later" why not (not done: per-request timeout, see PROGRESS Later)
- [x] `docs/tests/S001-upload-by-speed.md` from the test-file template (checks: budget math, link fallback, no retry after timeout, each upload path)
- [x] PROGRESS entry, INDEX line, commit `S001: …`
## End criteria
- `source ~/.cargo/env; cargo build` compiles with no new warnings.
- `grep -n "UPLOAD_RETRIES" src` shows the retry only on retryable errors.
- `ls docs/tests/S001-*` exists.
## Pitfalls
- No test runs, release builds or server deploys in this plan; the test phase does them.
- Don't touch `.env` or `data/`. The hosted link must keep the private-network checks.
- Upload time, not file size, is what breaks (CLAUDE.md §4).
## Handoff (→ PROGRESS.md)
Name of the budget helper and its constants, so S002 and S008 reuse them.

View file

@ -0,0 +1,35 @@
# S002 — Timeouts on every outbound call
> Category 01 Network · Model: Sonnet · Effort: medium · Depends on: S001 · Size: M · Human: no
> Files touched: src/state.rs, src/commands/media/download/tools.rs, src/commands/media/{ffmpeg,convert,quote,emoji}.rs, src/commands/music/{source,ytdl}.rs, other files found by the grep
## Goal
Every outbound HTTP call and every child process (yt-dlp, ffmpeg, gallery-dl, curl) has a named time limit, is killed when it runs over, and ends in a plain error card. Nothing can hang a command forever on the slow line. D-002, PLAN Phase 1 third bullet.
## Read
- `src/state.rs` line ~50 (shared reqwest client, 20 s timeout)
- `src/commands/media/download/tools.rs` lines ~25-130 (the run-with-cancel helper and yt-dlp args)
- `grep -rn "Command::new\|tokio::process" src` and `grep -rn "reqwest::Client\|\.timeout(" src`: read only call sites without a timeout or kill
- `src/error.rs` (`bail_user!`)
## Steps
- [x] List every outbound call site and child process with its current limit; put the list in the test file's Built section
- [x] Child processes: one shared run helper (reuse `tools.rs` if it fits) with a time limit, `kill_on_drop(true)` and a clear error; switch every caller that lacks one
- [x] HTTP: calls that download big bodies (media fetch, covers) get a size cap and a total timeout; separate clients built outside `state.rs` get timeouts
- [x] Time limits as named constants next to their use, with why the number (e.g. download size ÷ 425 KB/s down)
- [x] User errors: timeouts show "took too long" cards through `bail_user!`, not raw errors
- [x] `docs/tests/S002-outbound-timeouts.md` (checks: a stuck child is killed, a slow server times out, error card text)
- [x] PROGRESS entry, INDEX line, commit `S002: …`
## End criteria
- `cargo build` compiles.
- `grep -rn "Command::new" src` call sites all go through a helper with a timeout, or the test file says why not.
- `ls docs/tests/S002-*` exists.
## Pitfalls
- Never pass user text where it can become an option (`--`). Keep `safe_redirects` on every fetch.
- Music streaming processes run for the whole song: their limit is "no data for N s", not total time.
- No test runs here.
## Handoff (→ PROGRESS.md)
The helper's name and the list of limits.

View file

@ -0,0 +1,34 @@
# S003 — Gateway, voice and music recovery; shaping
> Category 01 Network · Model: Sonnet · Effort: medium · Depends on: S002 · Size: M · Human: no
> Files touched: src/main.rs (gateway loop), src/commands/music/{mod,source}.rs, deploy/shape-upload.sh
## Goal
The bot recovers by itself when the line drops: the gateway reconnects, voice reconnects or leaves cleanly, the music queue resumes or tells the user, and nothing stays stuck. The upload shaping (`dezio-shape`) is checked against real numbers and tuned. PLAN Phase 1, bullets four and five.
## Read
- `src/main.rs` lines ~520-600 (client and the `shard.next_event` loop)
- `src/commands/music/mod.rs`: the voice join and track-end/error handlers only (grep `songbird`, `Event::`, `disconnect`)
- `deploy/shape-upload.sh`
- Server, read-only first: `ssh [email protected] 'journalctl -u dezio-bot --since -7d | grep -iE "reconnect|disconnect|gateway|voice" | tail -50; tc -s qdisc show dev wlan0'`
## Steps
- [x] From the logs, list the drop cases that happened; add them to the test file
- [x] Gateway: errors from `next_event` never end the loop silently; fatal ones are logged and the process exits so systemd restarts it (Restart=always)
- [x] Voice/music: on a voice driver disconnect, try to reconnect a named number of times, then leave and tell the channel; no queue or "now playing" state left stuck
- [x] Shaping: measure upload once on the server (small timed upload, no external speed sites besides what the script already uses), adjust the cap in `shape-upload.sh` if the measure says so, with the number and date in a comment. Tell the orchestrator before reinstalling `dezio-shape` on the server; back up `/usr/local/bin/dezio-shape` first (D-005)
- [x] `docs/tests/S003-recovery-and-shaping.md`
- [x] PROGRESS entry, INDEX line, commit `S003: …`
## End criteria
- `cargo build` compiles.
- `ssh [email protected] systemctl is-active dezio-shape` says active (if it was reinstalled).
- `ls docs/tests/S003-*` exists.
## Pitfalls
- Never run the bot with the real token on this PC.
- Do not deploy the bot binary in this plan; S011 does it.
- Never connect to Tor or proxies.
## Handoff (→ PROGRESS.md)
Measured upload speed and the new cap, if changed.

View file

@ -0,0 +1,34 @@
# S004 — Remove /image, add /caption
> Category 02 Image commands · Model: Sonnet · Effort: medium · Depends on: — · Size: M · Human: no
> Files touched: src/commands/media/images.rs, src/commands/media/mod.rs, src/commands/help.rs (if it lists /image), web pages that list commands
## Goal
`/image` and `D!fx` are removed with every effect and filter (D-003). New `/caption` and `D!caption` put a white band with the text above the picture, Assyst style. Inputs: PNG, JPG, WebP (still and animated), GIF, MP4/WebM/MOV (D-008); animated input stays animated, video comes back in a format Discord plays. Options: `source-attachment`, `source-link`, `text`; with no source it uses the replied/latest chat picture (D-007). `/petpet` and `/convert` stay. `convert.rs` imports `images::pick_opt`: keep it working.
## Read
- `src/commands/media/images.rs` lines 160-200 (`speech_bubble`, `caption`), 240-320 (frames, GIF, `process`), 320-560 (`pick_opt`, `pick`, `run_job`, `image_cmd`, `petpet`, `commands`)
- `src/commands/media/ffmpeg.rs` only the parts for decoding video to frames and encoding back (grep `fn `)
- `docs/DECISIONS.md` D-003, D-007, D-008
- `grep -rn "D!fx\|/image\|\"fx\"" src web` for help and website mentions
## Steps
- [x] Remove `/image`, `D!fx`, `apply_filter`, `apply_effect`, effects/filters and their tests; keep `pick_opt`, `pick`, frame and GIF helpers, `petpet`
- [x] Caption drawing: white band sized to the wrapped text (fonts in `assets/`), text centred, black; band width = picture width; pure function with a unit test on band height for 1 and 3 lines
- [x] Media: still → PNG/JPG kept; GIF/animated WebP → GIF with every frame captioned; video → ffmpeg frames out, caption each, encode back (or ffmpeg `pad` + `drawtext` if simpler and the font is available); size limits through S001's budget helper if it exists, else `media::upload_limit`
- [x] Register `/caption` (slash + `D!caption`), help page entry, remove `/image` from help and website lists
- [x] `docs/tests/S004-caption.md` (checks per media type, empty text, very long text, huge input, bad link)
- [x] PROGRESS entry, INDEX line, commit `S004: …`
## End criteria
- `cargo build` compiles.
- `grep -rn "D!fx\|apply_filter\|apply_effect" src web` returns nothing.
- `ls docs/tests/S004-*` exists.
## Pitfalls
- Help pages must stay within Discord's limits (the help-limits test runs in the test phase).
- Video frames can be huge: cap frame count and size with named constants.
- No test runs here.
## Handoff (→ PROGRESS.md)
Names of the shared media in/out helpers S005 reuses.

View file

@ -0,0 +1,33 @@
# S005 — /speechbubble
> Category 02 Image commands · Model: Sonnet · Effort: medium · Depends on: S004 · Size: M · Human: no
> Files touched: src/commands/media/images.rs (or a new speechbubble.rs next to it), src/commands/help.rs
## Goal
`/speechbubble` and `D!speechbubble` as in D-007, D-008 and D-009: a wide ellipse hanging off the top (or bottom) edge with a tail pointing into the picture. Options `source-attachment`, `source-link`, `position` top|bottom, `flip` (tail to the other side), `solid` (white fill with black outline, BSM style); without `solid` the bubble is cut out transparent (Assyst style) where the format allows. Same media types as `/caption`, through the helpers S004 left.
## Read
- `docs/DECISIONS.md` D-007, D-008, D-009
- S004's PROGRESS entry (helper names)
- `src/commands/media/images.rs`: the old `speech_bubble` (if S004 kept it) and the caption command as the pattern
- Look at a few frames of `assets/reference/speechbubble-bsm.gif` and `speechbubble-assyst.gif` (extract 2 frames with ffmpeg to the scratchpad and view them)
## Steps
- [x] Bubble shape as a pure function: ellipse + tail mask for (width, height, position, flip); unit test that the tail side flips and that the mask touches the chosen edge
- [x] Draw: transparent cutout (alpha 0 inside the mask) or solid (white fill + black outline); the picture's edge follows the bubble's curve
- [x] Media: PNG out for still transparent; GIF with transparency for animated; video → GIF (transparency) or same format when `solid`
- [x] Register command (slash + `D!`), help entry
- [x] `docs/tests/S005-speechbubble.md` (checks per option and media type, compare with both reference GIFs on a contact sheet)
- [x] PROGRESS entry, INDEX line, commit `S005: …`
## End criteria
- `cargo build` compiles.
- `ls docs/tests/S005-*` exists.
## Pitfalls
- GIF transparency is one colour index: pick a key colour no frame uses.
- JPG cannot be transparent: output PNG.
- No test runs here; one quick render of a sample to the scratchpad to look at the shape is fine.
## Handoff (→ PROGRESS.md)
What the owner should try in Discord (🧑 in S011).

View file

@ -0,0 +1,36 @@
# S006 — fm logic fully on ListenBrainz and MusicBrainz
> Category 03 fm commands · Model: Sonnet · Effort: medium · Depends on: — · Size: M · Human: no
> Files touched: src/commands/lastfm/{api,mod,views,extras,art,covers}.rs, src/web/api.rs (fm link), web/ dashboard text if needed
## Goal
The owner moved the fm commands from the Last.fm API to ListenBrainz (D-010) with covers from a fallback chain (D-011). Check over all the old fm logic: everything that used Last.fm data must now get it from ListenBrainz and MusicBrainz (plus the D-011 cover/photo fallbacks), with no hidden reliance on Last.fm-only fields. Only song links may still point to the Last.fm website (D-010).
## Read
- `docs/DECISIONS.md` D-010, D-011
- The two 2026-12-01 entries in `docs/PROGRESS.md` (known differences)
- `src/commands/lastfm/api.rs` (whole, 401 lines: the ListenBrainz → old Last.fm shape adapter)
- `grep -n "fn \|\[\"" src/commands/lastfm/{mod,views,extras,art}.rs` to find every field read from the adapter's JSON; read only the call sites
- `src/web/api.rs` lines ~155-240 (dashboard fm link)
## Steps
- [x] List every fm feature (top lists, recent, profile, now playing, Who Knows, chart, Pixel Jumble, lyrics, dashboard link, any other user of `lastfm::`) and, for each, the JSON fields it reads; put the list in the test file's Built section
- [x] For every field, check the adapter fills it from ListenBrainz/MusicBrainz; fields Last.fm used to give that the adapter leaves empty (listeners, global playcount, user registered date, artist bio, tags, images) either get a MusicBrainz/ListenBrainz source or are removed from the card with no empty labels left
- [x] Remove dead Last.fm-only code (API key reads, method names, `audioscrobbler` leftovers, unused shapes); keep song links to the Last.fm website
- [x] User-facing text (help, error cards, dashboard, website, privacy) says ListenBrainz where it means the data source; fm errors (unknown ListenBrainz user, stats not ready yet) give plain cards
- [x] New pure logic (field mapping) gets a unit test with a saved ListenBrainz JSON sample, no network
- [x] `docs/tests/S006-fm-on-metabrainz.md` (one check per feature, live checks marked `cargo test listenbrainz_live -- --ignored`)
- [x] PROGRESS entry, INDEX line, commit `S006: …`
## End criteria
- `cargo build` compiles.
- `grep -rni "audioscrobbler\|api_key\|LASTFM_API" src` returns nothing (or the test file says why a line stays).
- `ls docs/tests/S006-*` exists.
## Pitfalls
- Do not touch `data/lastfm.json` (kept untouched, D-010); links live in `data/listenbrainz.json`.
- MusicBrainz needs the `Dezio/<version> (Discord bot)` user agent and about 1 request per second; don't add calls in loops without the existing rate handling.
- Keep the git tag `lastfm-api-backup` as is. No test runs here besides a compile check.
## Handoff (→ PROGRESS.md)
Fields dropped from cards, and any fm feature that still can't match its Last.fm behaviour.

View file

@ -0,0 +1,38 @@
# S006a — Website under /dezio/, landing page at the root
> Category 03a Website path · Model: Sonnet · Effort: medium · Depends on: — · Size: M · Human: 🧑 Discord Developer Portal (OAuth redirect, Activity URL mapping)
> Files touched: src/web/{mod,activity}.rs, src/hosted.rs, src/commands/gameboy.rs, web/**/*.{html,js,css}, docs/topgg.md, deploy/landing/index.html (new)
## Goal
Move all of Dezio's website (site, dashboard, API, OAuth, Game Boy Activity, hosted `/f/` files) from the root of https://astar76.com to https://astar76.com/dezio/ (D-013). The root `/` becomes a very simple static landing page with links to `/dezio/` and `/git/`; the owner will improve it later, so keep it minimal. `/git` (Forgejo) stays as is.
## Read
- `src/web/mod.rs` lines 1–70 (config, `DASHBOARD_URL`) and 280–320 (router)
- `src/web/activity.rs` lines 1–30 and 485–510 (routes)
- `src/hosted.rs` lines 15–35, `src/commands/gameboy.rs` lines 1–40
- `grep -rn '"/' web` for absolute paths in pages, JS and CSS
- `docs/topgg.md` URL lines
## Steps
- [x] Base path: derive it from the path part of `DASHBOARD_URL` (e.g. `https://…ts.net/dezio` → `/dezio`; none → `/`). Check with `tailscale serve --help` / docs whether `--set-path /dezio` strips the prefix before proxying (it is believed to strip it). Make the router work both ways: nest all routes under the base path and also accept un-prefixed paths, OR rely on stripping — pick one, say which in DECISIONS (D-013 addition). Cookie `Path` must match the base path.
- [x] Pages: every absolute link in `web/site`, `web/dashboard`, `web/activity` (`href="/…"`, `src="/…"`, `fetch("/api…")`, `/login`, `/assets`, `/images`, `/dashboard`, `/activity/api/…`) works under `/dezio/`. Prefer relative paths; where a page needs the base, inject it from the server once (no per-page copy-paste). OAuth `redirect_uri` stays `DASHBOARD_URL + "/callback"`. Redirects the server sends (login, logout, `slash_redirect`) carry the base path.
- [x] Hosted links (`hosted::store`) and `/gameboy` links come from `DASHBOARD_URL`, so they follow; check nothing else hard-codes `/f/` or `/activity` at the root.
- [x] Landing page: `deploy/landing/index.html`, one small static page (title, two links: Dezio → `/dezio/`, Source → `/git/`), plain inline CSS, no JS. Write the deploy commands into the plan's test file for S011, do not run them: copy to `/srv/landing/` on the server, `tailscale serve --bg --set-path / /srv/landing` (static files), `tailscale serve --bg --set-path /dezio http://127.0.0.1:8080`, set `DASHBOARD_URL=https://astar76.com/dezio` in `/root/Dezio/.env` (back it up first). Keep Funnel on.
- [x] Docs: `docs/topgg.md` website URL → `/dezio/`; the module comments in `src/web/mod.rs`, `src/web/activity.rs`, `src/commands/gameboy.rs` that name the portal setup. 🧑 list for the owner in the test file: Discord Developer Portal → OAuth2 Redirects add `https://astar76.com/dezio/callback`; Activities → URL Mappings `/` → `astar76.com/dezio/activity`; top.gg website field.
- [x] Unit test for the base-path parsing (pure function).
- [x] Test file `docs/tests/S006a-dezio-path.md`: local checks with `DASHBOARD_URL=http://127.0.0.1:8099/dezio --web-dev` (every page, asset, API call, login redirect, `/f/` link, activity page under the prefix; root of the local server does not serve Dezio pages), the deploy commands above, and the 🧑 portal list.
- [x] PROGRESS entry, INDEX line, commit `S006a: …`
## End criteria
- `cargo check` passes; the new base-path unit test passes (`cargo test base_path`).
- `grep -rnE '(href|src|action)="/[a-z]|fetch\("/' web` shows no root-absolute path left (or each one is explained in the test file).
- `deploy/landing/index.html` exists.
## Pitfalls
- Do not change the live server or Tailscale config in this plan; deploying is S011.
- The Game Boy Activity is loaded by Discord through its URL mapping; Discord's proxy prefixes paths itself (`/.proxy/`), so check how the page builds its API URLs before changing them.
- `--web-dev` without a path in `DASHBOARD_URL` must still work at `/` (base `/`).
- Old root links (`/dashboard`, `/f/…`) will no longer reach Dezio after the move; that is accepted (owner chose the landing page).
## Handoff (→ PROGRESS.md)
Base-path rule, the server commands for S011, and the 🧑 portal changes.

View file

@ -0,0 +1,33 @@
# S007 — Website and dashboard security
> Category 04 Security · Model: Opus (hostile input, auth) · Effort: medium · Depends on: — · Size: L · Human: no
> Files touched: src/web/{mod,api,activity}.rs, web/ pages if needed
## Goal
Find and fix security faults in the website, dashboard API, OAuth sign-in and Game Boy Activity (D-004). Attack traffic only against the local copy on 127.0.0.1:8099 (`--web-dev`), never the live site.
## Read
- `src/web/mod.rs` (whole, 512 lines: sessions, cookies, `check_write`, OAuth, headers middleware, router)
- `src/web/api.rs` routes and the handlers that write
- `src/web/activity.rs` routes only (grep `route`, `fn `)
- CLAUDE.md §2 (local website command)
## Steps
- [x] Review against a checklist written into the test file: auth on every API route, guild permission checks (user must manage the guild he edits), CSRF on writes (`check_write`), OAuth state, cookie flags, session expiry, input size limits, path traversal in static files, security headers, error leaks, rate limits on login and writes, WebSocket/activity input
- [x] Probe the local copy with curl for each item (start `--web-dev`, stop it at the end); write findings with severity in the test file
- [x] Fix every HIGH and MED finding in the code; each fix gets a unit test when it is pure logic, otherwise a check in the test file
- [x] LOW findings: fix if under a few lines, else PROGRESS "Later"
- [x] `docs/tests/S007-website-security.md` (checklist, findings, checks)
- [x] PROGRESS entry, INDEX line, commit `S007: …`
## End criteria
- `cargo build` compiles.
- The test file lists every checklist item with a finding or "fine because …".
## Pitfalls
- Never send traffic to https://astar76.com or Discord. No Tor or proxies.
- Never run the bot with the real token; `--web-dev` uses `DISCORD_BOT_TOKEN=dev-placeholder`.
- Don't break the existing web tests in `src/web/mod.rs`.
## Handoff (→ PROGRESS.md)
Open findings not fixed, with severity.

View file

@ -0,0 +1,34 @@
# S008 — Media inputs, commands and dependencies
> Category 04 Security · Model: Opus (hostile input) · Effort: medium · Depends on: S002 · Size: M · Human: no
> Files touched: src/commands/media/**, src/commands/music/{source,ytdl}.rs, src/cmd.rs, Cargo.toml/Cargo.lock if a dependency must move
## Goal
Make media inputs, commands and dependencies safe against hostile users (D-004): links and files fed to yt-dlp, ffmpeg, gallery-dl and curl; decoding bombs; private-network fetches; command spam; known-vulnerable crates.
## Read
- `src/commands/media/mod.rs` (`safe_redirects`, media fetch, line ~40-130)
- S002's PROGRESS entry (process helper) and the call-site list in `docs/tests/S002-outbound-timeouts.md`
- `src/commands/music/source.rs` the private-network check (grep `private\|loopback`)
- `src/cmd.rs` the dispatch and any cooldown code (grep `cooldown\|rate`)
## Steps
- [x] Child processes: every user link goes after `--`, scheme limited to http(s), no `file:`/`data:`/local paths; ffmpeg protocol whitelist on inputs
- [x] Private network: every fetch (reqwest, yt-dlp, gallery-dl, ffmpeg, curl) blocks loopback/LAN/Tailscale ranges, including after redirects and DNS rebinding where it can be checked
- [x] Decode bombs: image and GIF decoding has limits on width, height, frame count and memory (`image` crate `Limits`); named constants
- [x] Abuse: per-user cooldown or concurrency limit on heavy commands (media, download, caption, speechbubble) if none exists
- [x] Dependencies: install and run `cargo audit` and `cargo deny check advisories`; update crates with fixes where it is a patch/minor bump, list the rest
- [x] `docs/tests/S008-media-commands-deps.md` (hostile inputs list, audit output summary)
- [x] PROGRESS entry, INDEX line, commit `S008: …`
## End criteria
- `cargo build` compiles.
- `cargo audit` output saved in the test file; no unfixed HIGH advisory without a reason.
## Pitfalls
- No attack traffic outside 127.0.0.1. Never connect to Tor or proxies.
- Don't loosen the existing checks while refactoring them.
- No test runs here.
## Handoff (→ PROGRESS.md)
Advisories left open.

View file

@ -0,0 +1,28 @@
# S009 — Test: it runs, and network
> Category 05 Test and release · Model: Sonnet · Effort: medium · Depends on: S001, S002, S003 · Phase: test · Human: no
> Files touched: tests and fixes in src/**, docs/tests/S001-*, S002-*, S003-*, docs/TEST-REPORT.md
## Goal
First make sure everything builds and the existing suite passes (fix breakage first). Then run the checks of `docs/tests/S001-upload-by-speed.md`, `S002-outbound-timeouts.md`, `S003-recovery-and-shaping.md`, fix what fails, and fill in every Result.
## Read
- those three test files, all in one command; code only where a check needs it
- CLAUDE.md §2 and §5 for the build and test commands
## Steps
- [x] It runs: `cargo build --release`, `cargo test` once (worktree-only failures from missing `assets/data` and ROMs are known, see PROGRESS), `target/debug/dezio` lists commands and exits; fix breakage first
- [x] Doubts first: read the code behind each doubt in the three files and add a check, or write why it is fine
- [x] Write the tests for all HIGH and MED checks in one go; share fixtures (a local slow HTTP server on 127.0.0.1, a stuck child process); no test for what the compiler already proves
- [x] Run them once, all together, short output; save the log to a file and read only the failures
- [x] Sort the failures by cause, then fix all causes in one go; a wrong test is corrected, never weakened to pass
- [x] Rerun only what failed; three rounds at most, then `KNOWN BUG` with the cause
- [x] Results filled in, `docs/TEST-REPORT.md` line, PROGRESS entry, INDEX line, commit `S009: …`
## End criteria
- `cargo test` green, except listed known bugs and worktree-only asset failures
- no `—` left in the Result column of the three files: `pass`, `fixed`, `KNOWN BUG`, or `not run: why`
## Pitfalls
- Never run with the real token; never call Discord. Discord-only checks are `not run: needs Discord`.
- Live-internet tests stay `#[ignore]`.

View file

@ -0,0 +1,29 @@
# S010 — Test: images, fm, security, whole app
> Category 05 Test and release · Model: Sonnet · Effort: medium · Depends on: S004, S005, S006, S007, S008, S009 · Phase: test · Human: no
> Files touched: tests and fixes in src/**, docs/tests/S004-* to S008-*, docs/TEST-REPORT.md
## Goal
Run the checks of `docs/tests/S004-caption.md`, `S005-speechbubble.md`, `S006-fm-on-metabrainz.md`, `S007-website-security.md`, `S008-media-commands-deps.md`, fix what fails, fill in every Result. Then the whole-app pass: help limits, command registry, website journeys, hostile input on everything that listens or parses, restart with old data.
## Read
- those five test files, all in one command; code only where a check needs it
- CLAUDE.md §2 and §5
## Steps
- [x] Doubts first: read the code behind each doubt and add a check, or write why it is fine
- [x] Write the tests for all HIGH and MED checks in one go; share fixtures (sample PNG, JPG, GIF, animated WebP, short MP4/WebM/MOV generated with ffmpeg into the scratchpad)
- [x] Run them once, all together, short output; save the log and read only the failures
- [x] Sort the failures by cause, fix all causes in one go; rerun only what failed; three rounds at most, then `KNOWN BUG`
- [x] Screen checks: one contact sheet of caption and speechbubble outputs (every option, every media type) next to both reference GIFs, looked at once, faults fixed in one go, one more sheet
- [x] Whole app: `cargo test` (help-limits and registry tests included); `--web-dev` journey (pages, sign-in gate, dashboard API refuses without session); hostile input replay from S007/S008; start with a copy of old-format data files from the repo fixtures if any
- [x] Results filled in, `docs/TEST-REPORT.md` lines, PROGRESS entry, INDEX line, commit `S010: …`
## End criteria
- `cargo test` green, except listed known bugs
- no `—` left in the Result column of the five files
- `rg -n "\| — \||KNOWN BUG|not run" docs/tests` shows no open HIGH
## Pitfalls
- Local copy only for security replays; never the live site, Discord, Tor or proxies.
- Discord rendering is checked by the owner in S011 (🧑), not here.

View file

@ -0,0 +1,48 @@
# S011 — Deploy and owner check
> Category 05 Test and release · Model: Sonnet · Effort: medium · Depends on: S010 · Phase: test · Human: 🧑 owner tries /speechbubble and /caption in Discord
> Files touched: server /root/Dezio (binary, assets/, web/), docs/PROGRESS.md, docs/TEST-REPORT.md
## Goal
Deploy the finished bot to the Chromebook, check it starts cleanly, and have the owner check the two image commands in Discord (D-006). PLAN Phase 4.
## Read
- CLAUDE.md §2 (deploy steps)
- `docs/TEST-REPORT.md` and `rg -n "\| — \||KNOWN BUG|not run" docs/tests` (gate: no open HIGH)
- S005's PROGRESS entry (what the owner should try)
## Steps
- [x] Gate: no open HIGH check or HIGH known bug; otherwise stop and report to the orchestrator (open HIGH are only "not run" Discord/voice/browser checks; owner accepted: "Yes, deploy")
- [x] Tell the orchestrator before deploying; `cargo build --release`; scp to `dezio.new`; on the server back up `dezio` as `dezio.bak-<date>`, move in, `rsync -a` changed `assets/` and `web/`, `systemctl restart dezio-bot`
- [x] Check `systemctl status dezio-bot` and `journalctl -u dezio-bot -n 50`: logged in, commands registered, no errors; `curl -sI https://astar76.com` (plain GET, not attack traffic) returns 200
- [ ] 🧑 Owner tries `/caption` and `/speechbubble` (every option, a GIF and a video) and `/download` of a ~9 MB video; record the answers in the test report
- [ ] PROGRESS entry, INDEX line, commit `S011: …` and push to `origin`
## End criteria
- `ssh [email protected] systemctl is-active dezio-bot` says active
- Owner's answers recorded in `docs/TEST-REPORT.md`
## Pitfalls
- Never run the bot with the real token on this PC.
- Never touch `/root/Dezio/data` or `.env`; back up any server file before changing it.
- A restart drops music for a few seconds.
## Deployed 2026-12-01
Binary + `web/` deployed (backups on server: `dezio.bak-2026-12-01`, `web.bak-2026-12-01`). Server has no rsync; web copied with tar. Service active, 208 commands, 71 slash synced, ready in 9 guilds, site GET `/` and `/dezio/` return 200. The S006a tailscale/`.env` DASHBOARD_URL changes were NOT done (not in steps 1-3).
## Owner must try in Discord/browser (step 4, HIGH first)
HIGH
1. `/download` of a clip that compresses to ~8-9 MB: arrives as attachment, one attempt, no long wait (S001-3).
2. `/download` of a source too big for 8.5 MB: gets a website link with 24 h notice, no attachment (S001-4).
3. Slow upload: link replaces attachment after one timeout, no 3x retry (S001-5, if you can force it).
4. Voice: play a song, check stays smooth during an upload; cut network ~60 s then restore: playback resumes; 3+ min: bot leaves with "Lost the voice connection" notice, `/play` works again (S003-1,2).
5. Stalled stream while playing: moves on after ~20 s (S002-1); `/convert` of a hanging host link answers within ~60 s (S002-2).
6. Server network cut 12 min: bot exits and systemd restarts it (S003-3) (optional, disruptive).
7. Browser: open a `/f/<token>/<file>` hosted link in Firefox/Chrome: video plays inline (S007-4).
8. `/caption` and `/speechbubble`: every option, on an image, a GIF and a video (S004, S005, S008-13).
9. `/download` of a ~9 MB video (S011 step 4).
MED
10. `/convert` result over 8.5 MB gives a link (S001-8); `/convert` and caption on a normal mp4 work (S008-13).
11. Start `/caption` on a long video, then another at once: "You already have a media job running" (S008-14).
12. fm commands with a linked account (S006); `/convert` timeout and `/play` lookup timeout messages (S002-10,11).
13. Open `https://astar76.com/dezio/` (S007-10; works only after the S006a tailscale/.env change, still pending).

View file

@ -6,8 +6,30 @@ Tracker: https://claude.ai/artifact/PRAT4HSkqn44d6QFDJeovp
## 01 Network
- [x] [S001 — Uploads timed by line speed](01%20Network/S001-upload-by-speed.md)
- [x] [S002 — Timeouts on every outbound call](01%20Network/S002-outbound-timeouts.md)
- [x] [S003 — Gateway, voice and music recovery; shaping](01%20Network/S003-recovery-and-shaping.md)
## 02 Image commands
## 03 Security
- [x] [S004 — Remove /image, add /caption](02%20Image%20commands/S004-remove-image-add-caption.md)
- [x] [S005 — /speechbubble](02%20Image%20commands/S005-speechbubble.md)
## 04 Deploy
## 03 fm commands
- [x] [S006 — fm logic fully on ListenBrainz and MusicBrainz](03%20fm%20commands/S006-fm-on-metabrainz.md)
## 03a Website path
- [x] [S006a — Website under /dezio/, landing page at the root](03a%20Website%20path/S006a-dezio-path.md) 🧑
## 04 Security
- [x] [S007 — Website and dashboard security](04%20Security/S007-website-security.md)
- [x] [S008 — Media inputs, commands and dependencies](04%20Security/S008-media-commands-deps.md)
## 05 Test and release
- [x] [S009 — Test: it runs, and network](05%20Test%20and%20release/S009-test-runs-and-network.md)
- [x] [S010 — Test: images, fm, security, whole app](05%20Test%20and%20release/S010-test-images-security-app.md)
- [ ] [S011 — Deploy and owner check](05%20Test%20and%20release/S011-deploy-and-owner-check.md) 🧑

View file

@ -9,7 +9,7 @@
<p align="center">
<a href="https://discord.com/oauth2/authorize?client_id=1387839600017412106&scope=bot%20applications.commands&permissions=8"><b>➕ Add to your server</b></a> ·
<a href="https://archlinux.tail7c4f5e.ts.net">Website</a> ·
<a href="https://astar76.com">Website</a> ·
<a href="https://discord.gg/UnSga5DmR7">Support server</a>
</p>

19
deploy/landing/index.html Normal file
View file

@ -0,0 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Astar Hub</title>
<style>
body { font-family: system-ui, sans-serif; background: #15171a; color: #e8e8e8; margin: 0; min-height: 100vh; display: grid; place-items: center; text-align: center; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
a { color: #8bd450; font-size: 1.1rem; margin: 0 .8rem; }
</style>
</head>
<body>
<main>
<h1>Astar Hub</h1>
<p><a href="/dezio/">Dezio</a> <a href="/git/">Source</a></p>
</main>
</body>
</html>

View file

@ -11,6 +11,8 @@
# It turns itself off again after 2 minutes unless `keep` is the second word, so a mistake can't lock anyone out.
set -eu
DEV=wlan0
# 800 kbit = 100 KB/s, 88% of the 114 KB/s measured on this line (CLAUDE.md). Checked 2026-12-01 against `tc -s qdisc`:
# 247 of 121k packets dropped in the capped class, none in the voice class, so the cap is kept.
RATE=800kbit
off() { tc qdisc del dev "$DEV" root 2>/dev/null || true; }

View file

@ -13,3 +13,6 @@
- D-009 — 2026-11-12 — The Assyst-style output described in D-007 (transparent cutout, no outline, tail toward the right) is saved as `assets/reference/speechbubble-assyst.gif`, next to the BSM-style `speechbubble-bsm.gif` (D-008). Compare the drawn bubbles against both. — Owner request. — 02 Image commands.
- D-010 — 2026-12-01 — The fm commands read ListenBrainz (free, no key) instead of the Last.fm API, which needs Pro for everything but scrobbling from 2026-12-01. Same commands and cards; links are stored separately in `data/listenbrainz.json` (`data/lastfm.json` is kept, untouched); song links still go to the Last.fm website (free, and the Listen button reads them). Lyrics song search uses Deezer (popularity-ranked, no key). The Last.fm version is the git tag `lastfm-api-backup`. — Owner request. — all fm commands.
- D-011 — 2026-12-01 — Covers come from a chain (`src/commands/lastfm/covers.rs`): the release ID in the player's own tags (Cover Art Archive) → ListenBrainz's match → the release group → Deezer → iTunes; Deezer/iTunes results count only when artist and title match. Artist photos: Deezer → MusicBrainz/Wikimedia. Play counts match by MusicBrainz ID before names. — MusicBrainz art alone left many covers blank; owner asked for the most reliable sources with fallbacks. — fm commands.
- D-012 — 2026-12-01 — All fm logic must get its data from ListenBrainz and MusicBrainz (plus the D-011 cover/photo fallbacks); leftover Last.fm API logic and Last.fm-only fields are replaced or removed. Song links to the Last.fm website stay. — Owner request after the Last.fm API change. — S006, S010.
- D-013 — 2026-12-01 — All of Dezio's website (site, dashboard, API, OAuth, Game Boy Activity, hosted `/f/` files) moves to https://astar76.com/dezio/. The root `/` serves a minimal static landing page (links to `/dezio/` and `/git/`), which the owner will improve in a later session; old root links to Dezio are not redirected. `/git` stays Forgejo. — Owner request. — S006a, S007, S011.
- D-013 addition — 2026-12-01 — Base path = path part of `DASHBOARD_URL` (`/dezio`, none → root). The router serves every route both under the base and un-prefixed, so it works whether `tailscale serve --set-path` strips the prefix or not. HTML pages carry `__BASE__` (server replaces it); dashboard JS reads `<html data-base>`; site pages use relative paths; the Activity derives its base from `location.pathname` (so it also works at `/` inside Discord). Cookie `Path` = base. — Avoids guessing tailscale's behaviour. — S006a, S011.

Some files were not shown because too many files have changed in this diff Show more