Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(bots): avatar ADR gets its own number; serve avatars with nosniff (#229)
Salman Qureshi3e23cb4f8ce1
diff --git a/DECISIONS.md b/DECISIONS.mdindex 9fe6e8ba..4360531c 100644--- a/DECISIONS.md+++ b/DECISIONS.md@@ -1,9 +1,3 @@-## ADR-024: A bot has a face — avatars live in the profile dir--- **Context**: Every surface identified a bot by its id and a two-letter monogram derived from it — dashboard, Android client, TUI — because there was nowhere to put a picture: a profile is `bot.yaml` (identity), `persona.md` (character), `permissions.yaml` (what it may do), and nothing else. A fleet of eight bots is a wall of near-identical monograms, and the phone is where a fleet is actually run (ADR-023).-- **Decision**: An avatar is profile data, not settings. One extension-less file `avatar` in the bot's own profile dir — written through a temp file and renamed so a half-written face never serves, `0600`, replacing any previous one. `GET`/`PUT`/`DELETE /api/bots/:id/avatar`: bytes in as `{ data }` (base64, ≤ 2 MB, png/jpeg/webp/gif decided by the signature, never by the client's label), bytes out with the detected type, an `ETag` for cache validation, and `hasAvatar` on `getStatusSummaries()` so a client needs no probe per bot. A write or a delete rebroadcasts the roster frame, so every open dashboard learns the change at once. Nothing is added to `bot.yaml`: an absent file *is* "no custom avatar", which keeps an exported profile without a face byte-identical, and deleting a bot deletes its face along with the directory.-- **Consequence**: Clients stop inventing identity, and the monogram becomes a fallback rather than the only option. The extension-less name is the point: the format is decided by the bytes, so a webp re-upload can never be served as png because a stale filename said so. Not in this ADR: an avatar for the owner (there is one), generated faces, cropping or thumbnail derivatives — the client scales, and a 2 MB cap keeps that honest.-## ADR-022: Operating a fleet — cost, runs, kill switch- **Context**: ADR-020 and ADR-021 made bot behaviour bounded and legible in the journal, but the owner still had no view of where tokens went, no way to see what a run did without opening JSON files, no single stop, and a dead-letter queue full of pre-ADR-020 misclassified failures with no way to clear it. Onboarding presented the budget as optional.@@ -261,3 +255,8 @@- **Decision**: A `create_skill` tool (owner sessions only; stripped for members and bots) saves a procedure that just worked as a *self-made* skill under `~/.mercury/skills/self-made/<slug>/SKILL.md` with `category: self-made`, `origin: mercury`, `made`, `verified`, `uses`, `last_used`. The prompt tells Mercury when to make one (multi-step, repeatable, verified end-to-end) and when never to (one-offs, single tool calls, unverified, credentials). Drafts are validated strictly (slug, description length, ≥1 intent, a real stepwise procedure of ≥200 chars, a verification line, no secrets); a self-made skill never shadows a curated name; saving the same name updates it. They are listed under their own label as unverified until used again; `use_skill` counts uses. Hygiene on the heartbeat: never-used skills go dormant (`.disabled`, not deleted) after 30 days, and the shelf is capped at 40 live skills. `/skills self-made` lists them with use counts and enables, disables or removes them.- **Consequence**: The second time a long task comes up it is one `use_skill` away, with the pitfalls already written down. Curated and self-made skills never blur: different folder, label, and frontmatter. The owner sees every save in one line and can prune from chat; junk ages out on its own without deleting anything.+## ADR-028: A bot has a face — avatars live in the profile dir++- **Context**: Every surface identified a bot by its id and a two-letter monogram derived from it — dashboard, Android client, TUI — because there was nowhere to put a picture: a profile is `bot.yaml` (identity), `persona.md` (character), `permissions.yaml` (what it may do), and nothing else. A fleet of eight bots is a wall of near-identical monograms, and the phone is where a fleet is actually run (ADR-023).+- **Decision**: An avatar is profile data, not settings. One extension-less file `avatar` in the bot's own profile dir — written through a temp file and renamed so a half-written face never serves, `0600`, replacing any previous one. `GET`/`PUT`/`DELETE /api/bots/:id/avatar`: bytes in as `{ data }` (base64, ≤ 2 MB, png/jpeg/webp/gif decided by the signature, never by the client's label), bytes out with the detected type, an `ETag` for cache validation, and `hasAvatar` on `getStatusSummaries()` so a client needs no probe per bot. A write or a delete rebroadcasts the roster frame, so every open dashboard learns the change at once. Nothing is added to `bot.yaml`: an absent file *is* "no custom avatar", which keeps an exported profile without a face byte-identical, and deleting a bot deletes its face along with the directory.+- **Consequence**: Clients stop inventing identity, and the monogram becomes a fallback rather than the only option. The extension-less name is the point: the format is decided by the bytes, so a webp re-upload can never be served as png because a stale filename said so. Not in this ADR: an avatar for the owner (there is one), generated faces, cropping or thumbnail derivatives — the client scales, and a 2 MB cap keeps that honest.diff --git a/src/web/api/bots.test.ts b/src/web/api/bots.test.tsindex ce22b519..fb007f41 100644--- a/src/web/api/bots.test.ts+++ b/src/web/api/bots.test.ts@@ -223,6 +223,7 @@ describe('web bots API — avatars', () => {expect(res.status).toBe(200);expect(res.headers.get('Content-Type')).toBe('image/png');expect(res.headers.get('Cache-Control')).toContain('private');+ expect(res.headers.get('X-Content-Type-Options')).toBe('nosniff');const served = Buffer.from(await res.arrayBuffer());expect(served.equals(PNG)).toBe(true);});diff --git a/src/web/api/bots.ts b/src/web/api/bots.tsindex ba8bd760..2cf88689 100644--- a/src/web/api/bots.ts+++ b/src/web/api/bots.ts@@ -420,6 +420,8 @@ app.get('/api/bots/:id/avatar', (c: any) => {'Content-Type': mime,'Content-Length': String(bytes.length),'Cache-Control': 'private, max-age=0, must-revalidate',+ // The bytes were sniffed as an image; the browser must not re-sniff them as HTML.+ 'X-Content-Type-Options': 'nosniff',ETag: etag,});});