chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.6.0 Latest 5 packages
0
0
Split the README into docs/ pages, in marco's docs voice
.knotless/workflows/docs.ymlnew+16−0
| @@ -0,0 +1,16 @@ | ||
# The docs, as `just lint` checks them (harness/docs.mjs): each page's | ||
# front matter, its links and anchors, and prose as docs/_style.md asks. | ||
# Node's own modules alone: nothing to install. | ||
image: node:24.22.1 | ||
runners: [runner.knotless.dev] | ||
# Every push to main, and pulls into it or a feature/ branch, that change | ||
# the docs, the README, the check, or this file. A pull changing none | ||
# passes at once, noted as skipped. | ||
on: | ||
push: {refs: [refs/heads/main]} | ||
pull: | ||
base: [refs/heads/main, refs/heads/feature/*] | ||
paths: [docs/**, README.md, harness/docs.mjs, .knotless/workflows/docs.yml] | ||
steps: | ||
- name: docs | ||
run: node harness/docs.mjs | ||
docs/_style.mdnew+222−0
| @@ -0,0 +1,222 @@ | ||
# HUD docs: style guide | ||
| ||
Not a page (files starting with `_` aren't pages). Read this before writing or editing one. It's | ||
marco's guide (https://github.com/jazware/marco/blob/main/docs/_style.md), itself vlRelay's and | ||
vlpds's, cut down to what HUD's docs use. HUD has no docs renderer, so pages are plain Markdown, | ||
read on knotless and in an editor. | ||
| ||
It covers `README.md` and the pages in `docs/`. `AGENTS.md`, code comments, lexicon descriptions | ||
and tool text keep their own style. | ||
| ||
## Where things go | ||
| ||
- `README.md` says what HUD is, how to run it and where each page is. Nothing else. | ||
- `docs/<slug>.md` is one page per topic. Each fact has one home page. Other pages state it in a | ||
clause and link there. | ||
- When the code changes a default or a mechanism, update the page that owns it in the same change. | ||
| ||
| Page | Owns | | ||
| --- | --- | | ||
| `overview.md` | what HUD is, its parts, what isn't built | | ||
| `tools.md` | the MCP tools, their inputs and results, `query`, the writes | | ||
| `views.md` | views: joins, summaries, layouts, query joins, the bundled views, trust, profile sections, `records`, `launch` | | ||
| `app-pages.md` | app pages and where an account opens | | ||
| `knotless.md` | knotless's views and how its queries are made | | ||
| `sign-in.md` | sign-in, feed interactions, saved feeds, chats, procedures | | ||
| `workspace.md` | the workspace: canvases, tiles, agents, music, themes, where canvases live | | ||
| `running.md` | running HUD: commands, environment variables, the image | | ||
| `memory.md` | what HUD holds in memory and how to measure it | | ||
| `workspace-api.md` | the workspace's XRPC methods, its event stream, `/icon` | | ||
| `internals.md` | how it works: identity, lexicons, blobs, joins, counts, queries, storage, checks | | ||
| ||
`node harness/docs.mjs` (in `just lint`) checks every page: its front matter, no `#` heading, every | ||
link to a page or heading that exists, and the punctuation rules below in prose. | ||
| ||
## Current version only | ||
| ||
The pages document the HUD that's in the tree, nothing earlier. | ||
| ||
- No history: no "used to", "no longer", "was changed", "now does", "originally", and no comparison | ||
with an earlier HUD. Migration of old data (canvases from before columns) is current behaviour and | ||
stays, stated as what HUD does with such data today. | ||
- No design iterations or rejected alternatives. If a page needs the reasoning, give the current | ||
reason in one sentence. | ||
- Say what isn't built. If something is missing (views published as records), say so plainly. | ||
| ||
## Adding a page | ||
| ||
1. Create `docs/<slug>.md` with front matter: | ||
| ||
```yaml | ||
--- | ||
title: Views # the page's title | ||
section: HUD # "HUD", "Operations" or "Reference" | ||
order: 3 # position in its section (HUD 1-99, Operations 100+, Reference 300+); unique | ||
summary: "One sentence under the title. Quote it if it contains ': '." | ||
--- | ||
``` | ||
| ||
2. Start the body with one or two short paragraphs, then `##` sections. No `#` heading: the title | ||
comes from front matter. | ||
3. Link to other pages by file: `[the workspace's methods](workspace-api.md)`, | ||
`[query joins](views.md#query-joins)`. Anchors are the heading text, lowercased, with spaces | ||
turned into `-` and other punctuation dropped (GitHub's rule). | ||
4. Add it to the table above and to the README's list. | ||
5. Run `node harness/docs.mjs`. | ||
| ||
## Page shape | ||
| ||
1. **One or two short paragraphs** saying what the thing is and why a reader cares. Not a table of | ||
contents for the page: the headings already do that. | ||
2. **Sections** (`##`, `###` under them), each opening with its table, steps or example when the | ||
idea has a shape, then the explanation. | ||
3. **Links out** at the end of a section ("Details: …") rather than repeating another page. | ||
| ||
`overview.md` is the worked example. | ||
| ||
## Tone and content | ||
| ||
- **Reader-focused.** Write for someone running HUD, connecting a host to it, writing a view or | ||
working on its code: what it does, what it costs, what to watch, what to do. | ||
- **Concise.** Short sentences, plain words, active voice. Lead with the point. [Voice](#voice) | ||
spells out what that means sentence by sentence. | ||
- **Numbers with their basis**: "a 695 KB avatar is 6 KB as its thumbnail". Say whether a number is | ||
measured, a limit or a default. | ||
- **Defaults with their variable or flag**: "64 MiB by default (`HUD_CACHE_MEMORY_BYTES`)". Name | ||
methods, fields and files exactly. | ||
- **Code paths sparingly**, as inline code (`hud_core::canvas::store`), when a reader would actually | ||
go read it. | ||
- Callouts: `> [!NOTE]`, `> [!TIP]`, `> [!WARNING]`, `> [!DANGER]` as the first line of a blockquote. | ||
Use them rarely. One warning on a page reads as a warning, but five read as noise. | ||
| ||
## Voice | ||
| ||
The docs should read like the author explaining the system to another engineer, tightened for | ||
reference docs. Most of what makes docs slow to read comes from a handful of habits that a | ||
language model reaches for and a person explaining doesn't. This section lists them so they can be | ||
checked for. | ||
| ||
### What the voice is | ||
| ||
- **Plain declarative sentences, one idea each.** Most sentences run 12-25 words. No semicolons and | ||
no em dashes in prose. | ||
- **Conversational connectives.** Sentences link up with "So", "Since", "Now", "That means", | ||
"Additionally", "In this case", "That being said". They don't link up with punctuation. | ||
- **Contractions everywhere.** it's, don't, can't, isn't, there's, that's, we'd, won't. | ||
- **Person.** The operator, or the person using HUD, is "you" ("If you run HUD behind a proxy…"). | ||
The system is the subject of mechanism sentences ("HUD checks…", "The proxy fetches…", "A view | ||
names…"). "We" is fine when walking the reader through a mechanism or a calculation. No "I". | ||
- **Concrete before abstract.** Name the problem or the scenario, then the mechanism. "A gallery is | ||
three collections" lands faster than "records relate across collections". When a term needs a | ||
definition, give it in one plain sentence ("An app is the domain behind an NSID") and then an | ||
example. | ||
- **Numbers do the arguing.** Round numbers with `~` and units, and the arithmetic when it explains | ||
a cost. One "about" or "~" per number is enough. | ||
- **Trade-offs said plainly.** State the cost, give the number, say why it's acceptable. No | ||
hand-wringing and no stacked hedges. | ||
- **Paragraphs of 1-4 sentences.** Short is good. What's banned is a short paragraph whose only job | ||
is to land a line for effect (see the list below). | ||
- **Parentheses for asides**, not dashes or semicolons: "(the default)", "(`HUD_SPACES`)", "(a | ||
like, a repost)". Keep them short and useful: a flag, a default, a basis, an example. | ||
- **Humour is rare.** At most one light aside on a page, and never in the Operations pages. | ||
- **Words the voice uses:** keep up with, get by on, a bit, pretty, just (sparingly), cheap, plenty, | ||
hold up, spread out, so, since, that's, around, something like. | ||
| ||
### Banned patterns | ||
| ||
Search for each of these on every page you touch. | ||
| ||
| Pattern | Looks like | Do instead | | ||
|---|---|---| | ||
| Semicolon splice | "Slots are permanent; shards are not." | Two sentences, or join with "and", "but" or "so". | | ||
| Em dash or `--` aside | "the log — and only the log — is durable" | Parentheses, a comma, or a second sentence. | | ||
| "X, not Y" / "not X, but Y" flourish | "Logins use the CPU, not commits." | Say X. Mention Y only if readers would assume it, in its own sentence. | | ||
| Colon chains | "The rule is simple: one owner per shard: always." / "A: B, C: D" | One colon per sentence at most, and only to introduce a list, a code span or an example. | | ||
| Rule-of-three lists | "fast, cheap and simple" | Keep the items that carry information. Two is fine. One is often better. | | ||
| Abstract nouns for actions | "the persistence of", "guarantees around", "the handling of" | Use the verb: "stores", "makes sure", "handles". | | ||
| Filler and AI-isms | load-bearing, crucially, critically, importantly, in practice, it's worth noting, notably, essentially, effectively (as filler), robust, seamless(ly), under the hood, the heart of, first-class, by design, key (as in "the key insight"), "this is where X comes in", "the trick is", "the catch is" | Delete the word. If the sentence falls apart, rewrite it. | | ||
| Bold lead-in on every bullet | "- **Fail-stop over guessing.** When a node…" | Plain bullets. Bold only a term at its definition, or a real warning. Reference lists of named things (components, variables, methods) can start with the name in `code` or plain text and a period. | | ||
| Bold for emphasis in running text | "**the PDS is the database**" | No bold. If a phrase matters, put it first in the sentence. | | ||
| One-line paragraph for drama | "Unavailability is recoverable; a forked repo is not." on its own | Fold it into the paragraph it concludes, as a normal sentence. | | ||
| Aphorism endings | "Less to write and less that can disagree." | State the consequence plainly or cut it. | | ||
| Over-precise parentheticals | "(at the default 10 s, 12 s in tests, see below)" | One fact per parenthesis. Move the rest to the section or table that owns it. | | ||
| Narrating the page | "This page covers…" / "The short version:" / "In this section we'll look at" | Delete. Start with the content. A one-line pointer to another page for a related topic is fine. | | ||
| Stacked qualifiers | "typically only briefly and usually safely", "about ~" | One qualifier, or none if the number already has `~`. | | ||
| Sentence fragments as style | "Nothing else." / "By design." | Full sentences in the pages. | | ||
| Italic stress | "only decides *when*" | Rewrite so the stressed word is at the end of the sentence. | | ||
| Restating the obvious | "This matters because…" before something that obviously matters | Cut the lead-in, keep the reason. | | ||
| Exclamation marks | "and it's free!" | None in the docs. | | ||
| Possessive chains | "its query's lexicon's main def's params" / "each its icon, its name" | Name the thing and use a verb: "the params of the main def in the query's lexicon", "each with its icon and name". | | ||
| ||
### Mechanical pass | ||
| ||
Apply these in order to every paragraph, list item and table cell you edit. | ||
| ||
1. Replace every semicolon in prose with a period or with "and", "but" or "so". Table cells may use | ||
`·` to separate short items instead. | ||
2. Replace every em dash or double hyphen used as punctuation. | ||
3. Count colons. More than one in a sentence: split it. A colon that isn't introducing a list, | ||
code or an example: make it a period or "because"/"so". | ||
4. Find ", not " and "rather than". Keep one only when it corrects a real misconception. Otherwise | ||
drop the contrast half. | ||
5. Delete every word in the filler list. Re-read the sentence. | ||
6. Remove bold except (a) a term at its definition, once per page, and (b) callouts. Remove bold | ||
lead-ins from bullets that are prose. Remove italics used for stress. | ||
7. Use contractions: it is → it's, does not → doesn't, cannot → can't, there is → there's. | ||
8. Split any sentence over ~35 words, or with more than two clauses joined by commas. | ||
9. Make the actor the subject: "is checked by the server" → "the server checks". | ||
10. Delete sentences that describe the page or section instead of the system. | ||
11. Turn lists of three into lists of what's needed. | ||
12. Read the paragraph aloud. If you wouldn't say it to a coworker, rewrite it. | ||
| ||
Length usually comes out about the same. Splitting crammed sentences and adding connectives costs a | ||
few words, and cutting flourish wins them back. The goal is faster reading, not a lower word count. | ||
| ||
### Before and after | ||
| ||
From HUD's README, rewritten in the voice: | ||
| ||
> Before: Made with no sign-in, a call is made as no one: public data only, and a query that needs | ||
> an account (`getTimeline`) asks the host to sign in. | ||
> | ||
> After: Without sign-in, HUD makes the call as no one, so it only reads public data. A query that | ||
> needs an account (`getTimeline`) asks the host to sign in. | ||
| ||
> Before: A record that cannot be read is a null or skipped result, never an error. | ||
> | ||
> After: If a record can't be read, its result is null or skipped, and the call still answers. | ||
| ||
> Before: Identity: a handle's DID from DNS (`_atproto.<handle>`, asked of a public resolver) or | ||
> `https://<handle>/.well-known/atproto-did`; the DID's document from PLC or `did:web`; its PDS from | ||
> `#atproto_pds`. | ||
> | ||
> After: HUD finds a handle's DID through DNS (`_atproto.<handle>`, asked of a public resolver) or | ||
> at `https://<handle>/.well-known/atproto-did`. It reads the DID's document from PLC or `did:web`, | ||
> and the PDS from its `#atproto_pds` service. | ||
| ||
### The Operations pages | ||
| ||
The Operations pages (`running.md`, `memory.md`) are read by someone running HUD, sometimes in a | ||
hurry. They're terser than the other pages, and imperative where they say what to do. | ||
| ||
- Every command in backticks, runnable as written. Every limit with its number and variable. | ||
- Explain a mechanism only as far as it changes what to do, and link the page that owns it. | ||
- No humour. | ||
| ||
### What must not change | ||
| ||
A voice pass changes wording only. Check each of these before committing: | ||
| ||
- **Facts.** Every number, unit, default, variable, method, field, path, error name and limit stays | ||
exactly as it is. If a sentence goes, the fact in it moves to another sentence or was already | ||
stated on the page. | ||
- **Nothing new.** Don't add a claim, number, feature or promise that isn't already in the page or | ||
the code. The docs only describe what exists. If something reads wrong, flag it instead of fixing | ||
it in prose. | ||
- **Headings.** `harness/docs.mjs` checks every link and anchor. If a heading must change, update | ||
every link to it in the same commit. | ||
- **Links.** Every link stays and points to the same target. | ||
- **Front matter.** `title`, `section` and `order` stay. `summary` may be reworded for voice (keep it | ||
quoted if it contains `: `). | ||
- **Code blocks** and inline code are untouched. | ||
- Callouts stay callouts, with the same level. | ||
docs/app-pages.mdnew+69−0
| @@ -0,0 +1,69 @@ | ||
--- | ||
title: App pages | ||
section: HUD | ||
order: 4 | ||
summary: How a bundled view draws an app's page, and where an account opens. | ||
--- | ||
| ||
An app's page ([`describe_app`](tools.md)) is generic. It shows the app's head, where to go in it and, for an account, that account's part in it. | ||
| ||
A bundled view can draw an app's page instead. That's an app page view. | ||
| ||
## App page views | ||
| ||
An app page view names the app's `domain` (`"knotless.dev"`) in place of a collection or method. It also gives `app`, `description` and the `service` its joins call. It has one mode, `page`, shaped as `{ "join"?: [query joins], "layout" }`. | ||
| ||
### The page's scope | ||
| ||
The main scope is `{ domain, name, icon, actor, me, mine, entries, joins }`. It holds these: | ||
| ||
- the app (`domain`, `name`, `icon`) | ||
- the page's account (`actor`, `{ did, handle }`), which is the `actor` argument or else the person signed in | ||
- the person signed in (`me`, or null) | ||
- whether they're the same account (`mine`), read as a `List`'s `where` reads it, so `{ "mine": "mine" }` keeps the literal rows that say `"mine": true` | ||
- the app's entry points (`entries`), each `{ title, call }` | ||
- the answers of its query joins (`joins`) | ||
| ||
Its [query joins](views.md) read `domain`, `actor`, `me` and the rest of that scope, as any mode's do. HUD skips a join whose binding doesn't resolve. | ||
| ||
### When it's drawn | ||
| ||
`describe_app` draws that view's layout where the app has one and there's an account to draw it for. With neither an actor nor anyone signed in, it draws the generic page. | ||
| ||
Only a bundled view can be an app's page. HUD refuses an inline view that names `domain` or `page`. | ||
| ||
## The bundled app pages | ||
| ||
### knotless | ||
| ||
knotless's page (`knotless-app`) is its Home. It has three parts: | ||
| ||
- My work. This lists Issues and Pull requests opened (with their counts, `50+` where there's a page more), Review requests, Assigned, Notifications (on the person's own page alone), Repositories and Starred (with its count). Each row opens its query. | ||
- Favorites, the repositories the account starred, each opening it. | ||
- Recent, the last 8 pulls and issues the account's doings touched, each once (`getFeed`). Each opens its thread. HUD leaves Recent out when there are none. | ||
| ||
The page has four joins, the most a mode makes. They're the open issues and pulls (`listActorItems`), the stars (`getActorStars`, for the Starred count and Favorites) and the recent activity. The other rows have no count. | ||
| ||
More on knotless's views is in [knotless](knotless.md). | ||
| ||
### Grain | ||
| ||
Grain's page (`grain-app`) is its profile. It shows the account's avatar large beside its galleries, followers and following, its name, handle and bio, and on one's own page its feeds (For you, Following, Recent, Galleries). It shows its 18 latest galleries as 3:4 tiles, each opening the gallery. The data comes from Grain's AppView (`getProfile` and the `actor` feed of `getFeed`). | ||
| ||
### Bluesky | ||
| ||
Bluesky's page (`bsky-app`) is a profile as Bluesky's app draws one: | ||
| ||
- banner, avatar, name, handle and bio | ||
- followers, following and posts | ||
- where to go, on one's own page (Following, Discover, Saved feeds) | ||
- their posts and their threads (`posts_and_author_threads`), with links to all of them, their replies, media and videos (the filters of `getAuthorFeed`) | ||
- the feeds they made | ||
| ||
## Where an account opens | ||
| ||
A bundled view's drawing names accounts in links, mentions and who reposted. Such an account opens as its page in that view's app, where the app has one (`describe_app { domain, actor }`). So a name in a Bluesky post opens their Bluesky page, and a name in a Grain gallery opens their Grain page. In an app with no page, or from an inline view, it opens as the account's profile across its apps (`describe_repo`). | ||
| ||
The tree says which app (`_meta.ui.people`), for the mentions its clients open. | ||
| ||
A tile's header has the way across. Its @handle opens the account's profile. The profile's apps open their pages. Those apps are the ones a bundled view draws something of, either an app page or a section of the profile. | ||
docs/internals.mdnew+121−0
| @@ -0,0 +1,121 @@ | ||
--- | ||
title: How it works | ||
section: Reference | ||
order: 301 | ||
summary: How HUD resolves identities and lexicons, serves blobs, joins, counts, queries and keeps sign-ins and canvases. | ||
--- | ||
| ||
HUD reads records from each account's PDS and resolves identities and lexicons from the network. It keeps no database of its own, only caches and the files below. | ||
| ||
## Identity | ||
| ||
HUD finds a handle's DID through DNS (`_atproto.<handle>`, asked of a public resolver) or at `https://<handle>/.well-known/atproto-did`. It reads the DID's document from PLC or `did:web`, and the PDS from its `#atproto_pds` service. A handle counts only if the document names it back. | ||
| ||
HUD keeps an identity for 1 hour. It keeps answers that there's none (no document, no DID) for 5 minutes. It doesn't keep a missing answer (none in time, or a server that can't answer now), so the next call asks again. | ||
| ||
## Lexicons | ||
| ||
HUD bundles the records, defs and queries of `com.atproto.*`, `app.bsky.*`, `social.grain.*`, `xyz.statusphere.*` and `fm.plyr.*` in `lexicons/`. `just lexicons` fetches them from their repositories. HUD's own lexicons, `place.hud.*`, are in `schemas/`. | ||
| ||
HUD resolves other lexicons from the network, first the `_lexicon.<authority>` TXT record, then the authority's `com.atproto.lexicon.schema` record. It resolves their refs one level deep. It keeps them for 24 hours and answers misses for 1 hour, in memory and on disk. It doesn't keep a missing answer on the way. | ||
| ||
## Blobs | ||
| ||
Every image, audio and video blob in a record gets a sibling `url`, `<public origin>/blob/<did>/<cid>`. The proxy there fetches the blob from the account's PDS. It serves only these: | ||
| ||
- images (not SVG) up to 20 MB | ||
- audio up to 100 MB | ||
- MP4, QuickTime and WebM video up to 100 MB | ||
| ||
When a PDS sends a blob untyped (`application/octet-stream`), the proxy knows it by its first bytes. It never serves a blob as HTML or SVG. Browsers cache it forever, since a CID never changes. | ||
| ||
Images stream straight through. The proxy keeps audio and video on disk first (`<HUD_CACHE_DIR>/blobs/<cid>`), and only if their bytes hash to their CID. That lets a player seek, because PDSes answer whole blobs only and the proxy answers `Range` from the cache. | ||
| ||
Like every other outbound request, the proxy's requests refuse plain `http` and private, loopback and link-local addresses. A DID document can name any host. | ||
| ||
## Image CDN | ||
| ||
The image CDN (`HUD_IMAGE_CDN`) serves an image of a public record instead of the proxy. That covers images read from the record's repository with `com.atproto.repo.*` or found in the Bluesky AppView's answer. GIFs are the exception, since the CDN would make them still. | ||
| ||
The CDN serves a JPEG at the size HUD draws it: | ||
| ||
- `url` is the CDN's `feed_fullsize` | ||
- `thumb` is its `feed_thumbnail` (`avatar_thumbnail` for an `avatar` or `icon` field) | ||
- `proxy` is the blob proxy's URL, which the renderer loads once instead when the CDN fails | ||
| ||
A 695 KB avatar is 6 KB as its thumbnail. | ||
| ||
Every caller of `blobs::rewrite` says whether what it read is public. A record of a space keeps every blob on the proxy alone and never names it to a public CDN. So does an answer of any service but the AppView's to the signed-in account. | ||
| ||
## Joins | ||
| ||
HUD keeps no index of its own. It lists a repository's records of a backlinks collection whole and keeps them a minute. It reads each record a ref names from its own repository's PDS, eight fetches at a time per call. If a record can't be read, its result is null or skipped, and the call still answers. | ||
| ||
Query joins call their services as `query` does, once per answer, all at once, each within 3 s. So a slow one costs a tile at most 3 s, and a failed one gives a null. | ||
| ||
## Counts | ||
| ||
A network-wide backlink index (Constellation, by default) counts the records pointing at a record, by collection and path. HUD asks it once per record and keeps its answers and failures a minute. It shows null counts when the index is off (`HUD_BACKLINKS=none`) or failing. | ||
| ||
Views name what to count and never name the index, so another index can replace it. `describe_collection` lists the counts of each sample, so a model writing a view can see which there are. | ||
| ||
## Queries | ||
| ||
The service's DID document gives the endpoint of the service that its fragment names. HUD calls it through the same outbound client, within 10 s and 5 MiB. | ||
| ||
Blob refs in an answer get URLs where HUD knows the repository holding them. That's the case for a record beside the `uri` naming it. Images go through the image CDN when HUD asks as no one or asks the AppView. Otherwise they go through the proxy alone. | ||
| ||
Every video the answer shows (`app.bsky.embed.video#view`) gets a `url` of its blob from the proxy, in the repository of the post around it. The video's own playlist is HLS, which browsers other than Safari don't play. With the blob URL, the view plays it natively. | ||
| ||
HUD makes calls as no one. When signed in, it makes them through the account's PDS, which proxies them to the service (`atproto-proxy`). | ||
| ||
## MCP | ||
| ||
HUD serves Streamable HTTP at `POST /mcp`, stateless. It serves 2026-07-28 and `initialize`-era clients (2025-11-25, 2025-06-18) too, with a bearer token in either. | ||
| ||
## Sign-ins | ||
| ||
HUD keeps sign-ins under `<HUD_DATA_DIR>/oauth/`: | ||
| ||
- the client key | ||
- each session, an MCP client's or the workspace's, rewritten whole on every change | ||
- the clients registered | ||
| ||
A session holds its atproto tokens and DPoP key, and the SHA-256 of HUD's tokens or cookie for it. It never holds those tokens or that cookie themselves. | ||
| ||
HUD sweeps expired sessions every hour. It never logs tokens. | ||
| ||
## Canvases | ||
| ||
Canvases sit behind a store trait (`hud_core::canvas::store`). By default it's the server's own files (`FileStore`). Each canvas is `<HUD_DATA_DIR>/canvas/<id>.json`, with its info and tiles. Each person's index is `canvas/by-did/<sha256 of the DID>.json`. It holds their canvases, their tabs in order and their current one, and HUD rebuilds it from the canvases if it's missing. HUD writes these files whole after each change. | ||
| ||
A canvas from before a person could have many is kept as `canvas/<sha256 of the DID>.json.moved` once moved. | ||
| ||
HUD turns tiles from before columns (`x`, `y`, `w`, `h`) into columns as it reads them at start, and writes them back. It orders them by rows, top to bottom, and each row left to right, as 1, 2, 3…. It takes their width from their pixels: under 520 a third, under 760 a half, else two thirds. A person from before tabs gets every canvas they've joined open, ordered by when it was made. | ||
| ||
With `HUD_SPACES=on`, `SpaceStore` (`hud_core::canvas::space`) keeps a canvas in its owner's own space when no one else is in it, as [the workspace](workspace.md) describes. It goes through their OAuth session (`hud_core::space`, the `com.atproto.space.*` methods, DPoP as on every PDS call). It checks each record against its lexicon first. It turns tile records from before columns into columns as it reads them and writes them that way. It holds those canvases in memory as last written, and the person's index stays a file. | ||
| ||
Every change, and who's on each canvas, goes to the members over one broadcast channel per person. HUD makes the channel when it's first needed and lets it go when no stream listens. Each stream passes on what concerns the person's open tabs. | ||
| ||
## Themes | ||
| ||
HUD keeps each person's chosen theme as `<HUD_DATA_DIR>/theme/<sha256 of the DID>.json`, written whole. One of HUD's is kept by its key, and a person's theme is copied whole. With none kept, the workspace follows the system's light or dark. | ||
| ||
## Icons | ||
| ||
HUD asks `HUD_FAVICONS` for an app's favicon at `https://<domain>`, within 5 s. If the answer is a 200 `image/png` of at most 100,000 bytes, HUD keeps it as `<HUD_CACHE_DIR>/icons/<domain>.png` for a week. Otherwise it keeps `<domain>.miss` for a day. | ||
| ||
A domain is a hostname, never an address. It's never a private name unless `HUD_ALLOW_PRIVATE` is set. | ||
| ||
## Checks | ||
| ||
`just check` runs rustfmt, clippy, the tests, svelte-check, `just lint` (the workspace's layers and contrast, and the docs) and `just lex`. `just lex` runs two scripts: | ||
| ||
- `harness/lexicons.mjs` applies goat's lint and the Lexicon Style Guide's rules to `schemas/`, and checks that they only grow from main's. | ||
- `harness/answers.mjs` checks every XRPC answer that hud-server's tests receive against its lexicon. | ||
| ||
The runner (runner.knotless.dev) runs the same checks on every push to main and every pull into it, from `.knotless/workflows/`, the docs as `docs`. It also runs the e2e flows, `e2e` on a stock PDS and `e2e-spaces` on the spaces alpha. Main takes pulls only through the merge queue, each once review.knotless.dev has reviewed its head. | ||
| ||
## The view and the workspace | ||
| ||
Each one is a self-contained HTML file built from `web/` (Svelte 5, Vite) as `web/dist/index.html` and `web/dist/workspace.html`, and embedded in the binary. Both draw with `@hud/renderer` (`web/renderer`), which knows nothing of MCP. | ||
docs/knotless.mdnew+83−0
| @@ -0,0 +1,83 @@ | ||
--- | ||
title: knotless | ||
section: HUD | ||
order: 5 | ||
summary: The bundled views that draw knotless, how its queries are named and asked, and the components made for them. | ||
--- | ||
| ||
knotless keeps git repositories in atproto accounts, with pulls, issues and checks. Its appview at knotless.dev answers XRPC queries (`dev.knotless.*`), and HUD resolves their lexicons from the network. | ||
| ||
Thirteen bundled views draw them. Each calls `did:web:knotless.dev#knotless_appview` by default, so `query` needs no `service`. | ||
| ||
## The views | ||
| ||
| View | Method | Opens | | ||
| --- | --- | --- | | ||
| `knotless-repo` | `getRepo`, joining its README (`getFile`) and latest release (`listReleases`) | owner (`getProfile`), Pulls and Issues (`listItems`), Commits, Checks | | ||
| `knotless-items` | `listItems` | each row opens its thread · Open and Closed tabs | | ||
| `knotless-thread` | `getThread` | each changed file opens its diff (`getPullDiff`) · the repository, authors | | ||
| `knotless-diff` | `getPullDiff` | | | ||
| `knotless-checks` | `listChecks` | each check opens its check record | | ||
| `knotless-commits` | `listCommits` | a commit's pull | | ||
| `knotless-feed` | `getFeed` | actors, repositories, threads | | ||
| `knotless-notifications` | `listNotifications` | actors, repositories, threads | | ||
| `knotless-profile` | `getProfile` | Repositories (`getActorRepos`), Activity (`getFeed`) | | ||
| `knotless-actor-repos` | `getActorRepos` | each repository | | ||
| `knotless-actor-items` | `listActorItems` | each row opens its thread · Open and Closed tabs | | ||
| `knotless-actor-stars` | `getActorStars` | each starred repository | | ||
| `knotless-file` | `getFile` | the repository | | ||
| ||
A knotless record opened by its at-uri draws as one of these views (their [`records`](views.md)), except a release. knotless's [app page](app-pages.md) (`knotless-app`) draws its Home. | ||
| ||
## Naming a repository | ||
| ||
A repository is named by its record's at-uri, with a handle as the authority. Its record key is its name: | ||
| ||
`at://chadtmiller.com/dev.knotless.repo/knotless` | ||
| ||
`query` turns the handle into a DID, as it does in every at-uri param. So naming a repository as `handle/name` needs nothing more. For example: | ||
| ||
```json | ||
{ "method": "dev.knotless.getRepo", "params": { "repo": "at://chadtmiller.com/dev.knotless.repo/knotless" } } | ||
{ "method": "dev.knotless.listItems", "params": { "repo": "at://chadtmiller.com/dev.knotless.repo/knotless", "kind": "pull", "state": "closed" } } | ||
{ "method": "dev.knotless.getThread", "params": { "repo": "at://chadtmiller.com/dev.knotless.repo/knotless", "uri": "at://did:plc:…/dev.knotless.pull/…", "filesOnly": true } } | ||
{ "method": "dev.knotless.getFeed", "params": { "actor": "did:plc:…" } } | ||
{ "method": "dev.knotless.listNotifications" } | ||
``` | ||
| ||
## Signed out and signed in | ||
| ||
Signed out, HUD makes every query to knotless.dev as no one, so it reads public repositories only. | ||
| ||
Signed in, the query goes through the account's PDS with `atproto-proxy: did:web:knotless.dev#knotless_appview`. The PDS signs a service token for it (`aud` is knotless's DID, `lxm` the method), and knotless takes the token's account as the asker. So notifications answer, and answers say what the account may do. | ||
| ||
A service token alone reads no private repository. For those, knotless asks for a member's session or a space delegation token. | ||
| ||
`listNotifications` needs an asker. Signed out, knotless refuses it (`AuthenticationRequired`). With sign-in on, HUD answers the challenge and describes it in the view's own words (`signIn`: "Sign in to see your notifications"). With sign-in off, it's a tool error. | ||
| ||
## Components | ||
| ||
The views use components made for them, and each one is generic. | ||
| ||
- `State` shows what a pull, issue or check is in, by role, as a mark, words or a pill. It uses role colours, the renderer's `--hud-color-open`, `-merged`, `-closed`, `-neutral` and `-running`. | ||
- `Label` draws a label in its own colour. | ||
- `Diff` draws a file's unified diff with line numbers, hunks, and added and removed lines on `--hud-diff-*`. Lines don't wrap and scroll sideways. Without rows, it draws its header, as a list of files changed. | ||
- `Icon` is a menu row's mark. It's a glyph (issue, pull, review, notification, repo, star, check, release, activity, search, people, feed) in white on a rounded square of a tint. The tints are green, blue, purple, gray, yellow, red and orange (the renderer's `--hud-tint-*`, the same colours on iOS). | ||
- `Tabs` holds 2 to 6 tabs, each a label and an `open`. It marks the one whose query is drawn now. A tab replaces what's drawn with the tab's call, in place. A workspace tile keeps its key, place and `from` and draws the tab's call (`updateTile` with its tool and arguments, which every page and the iOS app are told of). The MCP view and the iOS app's signed-out screens replace the screen and don't open another. | ||
| ||
### Additions to other components | ||
| ||
- `Link` takes `open`, a query, as a row opens one. A link naming the query drawn now is marked current (`aria-current`), as the Open filter on the open list is. | ||
- `Row` has an `xs` gap. | ||
- `List` takes `title`, `empty`, `{"$root": path}` items and `where`. A commit's checks use `where`, from the answer's array of every commit's checks. A list given `"open": false` opens nothing. | ||
- A `List`'s items may be a literal array of at most 20 objects, a menu's fixed rows. Each value is literal or `{"$root": path}`, and each row opens its own `open`. | ||
- `Text` takes `words` and `chars`. | ||
- `RichText` takes `gfm`. | ||
- `Stat` of an array counts it. With `more` bound to a cursor that holds one, it draws `N+`. | ||
| ||
### Params of an `open` | ||
| ||
Beside the literals and item bindings any `open` takes ([views](views.md)), an `open`'s params can use two more bindings: | ||
| ||
- `{"$root": path}` reads the view's own scope. So a row's thread opens in the repository the list was asked of. | ||
- `{"$atUri": [authority, collection, rkey]}` builds an at-uri. A repository's at-uri comes from an event's `repo.did` and `repo.name`. | ||
docs/memory.mdnew+45−0
| @@ -0,0 +1,45 @@ | ||
--- | ||
title: Memory | ||
section: Operations | ||
order: 101 | ||
summary: What HUD holds in memory and how to measure it. | ||
--- | ||
| ||
What HUD holds is bounded by what's on screen. What's open doesn't grow it. | ||
| ||
## Server | ||
| ||
Every in-memory cache is bounded by entries and by bytes. `HUD_CACHE_MEMORY_BYTES` is shared out like this: | ||
| ||
- lexicons get a quarter | ||
- joins' records get three eighths | ||
- DID documents get an eighth | ||
- counts get five 32nds | ||
- the rest get a 32nd each | ||
| ||
HUD weighs each value as it keeps it. It doesn't keep a value that weighs more than a quarter of its cache's share. | ||
| ||
HUD keeps audio and video on disk (`HUD_BLOB_CACHE_BYTES`). It streams images through and never holds them whole. Sign-in's pending requests and client documents are capped by count. | ||
| ||
`hud serve` logs each cache's entries and bytes as it stops (`caches at shutdown`). | ||
| ||
## Workspace | ||
| ||
A tile keeps what it read, and never makes it deeply reactive. It draws it only while its column is within a screen's width of what's in view on the tab on screen. Farther away, or on a tab out of sight, the tile's body is empty and its scroll is kept. As it comes near, the tile draws again from what it read, without asking again. | ||
| ||
A player's music goes on in the page's one `<audio>`, apart from the tiles. It holds only the tracks it plays. A video, or an audio field, stops as its tile stops drawing. | ||
| ||
## Renderer | ||
| ||
A long list (rows or cards, past 24 items) draws only the items within two screens of its scroller's view. It draws each item as it comes that near, using an IntersectionObserver and never reading where items are while scrolling. Once scrolling stops, it lets go of items past four screens and holds each at its measured height. The browser skips drawing those out of view (`content-visibility`). | ||
| ||
In a frame (the MCP App's view), a list draws every item and the browser draws them all. A frame from another origin isn't told where its host's screen is, so either technique would leave posts blank as they scroll in. | ||
| ||
The renderer keeps what a person did to an item (a like, a warning seen through, a text opened) by the item's data. So it draws the item again as it was. | ||
| ||
A picture drawn small (an avatar, a gallery's tile, a link card's thumbnail) loads a blob's `thumb`, which is the image CDN's thumbnail (128 px for an avatar). A trusted view's `thumbnails` load the AppView's avatars as their CDN's thumbnails. Both load these instead of full size. Pictures load lazily and decode off the main thread. Video and audio load nothing until played. | ||
| ||
## Measuring | ||
| ||
- `just memory [label]` runs a session against the release build (harness/e2e/memory.spec.mjs). It prints per stage the page's heap, DOM nodes, pictures and image memory, and the server's RSS. | ||
- `just scroll` measures a long feed scrolled in a column (harness/scroll.mjs). It reports long tasks, layouts, frame times, blank frames, heap and nodes. | ||
docs/overview.mdnew+45−0
| @@ -0,0 +1,45 @@ | ||
--- | ||
title: Overview | ||
section: HUD | ||
order: 1 | ||
summary: "A remote MCP server that draws atproto records as interactive UI inside hosts of MCP Apps." | ||
--- | ||
| ||
HUD is a remote MCP server that shows atproto records as interactive UI inside Claude, ChatGPT and | ||
any other host of MCP Apps. Give it a handle and it finds the account's PDS and reads the public | ||
records there. Name a service's XRPC query (an AppView's feeds, say) and it calls it. Hosts without | ||
MCP Apps get the same data as text. | ||
| ||
## What it draws | ||
| ||
Views draw records and answers. A view is either a bundled one or one the host's model writes and | ||
passes in. The bundled views cover Bluesky posts and feeds, Grain's galleries, plyr.fm's playlists | ||
and likes, standard.site's blog posts and blogs, and knotless's repositories. With no view, HUD | ||
builds a card from the collection's lexicon, or falls back to a JSON tree. | ||
| ||
Details: [the tools](tools.md), [views](views.md), [app pages](app-pages.md), | ||
[knotless](knotless.md). | ||
| ||
## Signed in | ||
| ||
Everything public works without signing in. If you sign in once with an atproto account, you can | ||
let Claude write records for you (a like, a repost, a gallery), click a view's buttons (Like) and | ||
read your personal feeds (your timeline) through your own PDS. | ||
| ||
Signed in, you also get a workspace at `/workspace`. It's canvases of tiles that you, the people | ||
you share them with, and any AI you connect to HUD fill, live. | ||
| ||
Details: [sign-in](sign-in.md), [the workspace](workspace.md), | ||
[the workspace's methods](workspace-api.md). | ||
| ||
## Running it | ||
| ||
[Running HUD](running.md) has the commands and every environment variable. | ||
[Memory](memory.md) says what HUD holds and how to measure it, and [how it works](internals.md) | ||
covers identity, lexicons, blobs, joins and storage. | ||
| ||
## What isn't built | ||
| ||
- Views published and found as records. | ||
- References into a repository from others (likes of a gallery), which need an index. | ||
- MCP's scope step-up. A narrower sign-in is a tool error naming the scope. | ||
docs/running.mdnew+47−0
| @@ -0,0 +1,47 @@ | ||
--- | ||
title: Running it | ||
section: Operations | ||
order: 100 | ||
summary: The commands that run HUD, the environment variables it reads and the image. | ||
--- | ||
| ||
Install the web dependencies, then serve HUD. It listens on port 8787 and serves MCP at `/mcp`. | ||
| ||
## Commands | ||
| ||
```sh | ||
cd web && npm ci && cd .. | ||
just serve # http://localhost:8787, MCP at /mcp | ||
``` | ||
| ||
Add `http://localhost:8787/mcp` to a host that reaches it. For a public deployment, add `https://<host>/mcp` as a custom connector in Claude. | ||
| ||
`just dev` serves a dev host at http://localhost:5173/dev/. It shows the view as a host would and sends its tool calls to `just serve`. When the server's sign-in is on, it also plays an MCP client that signs in (dynamic registration, PKCE, the sign-in page in a popup). | ||
| ||
`just local` runs HUD against a PDS of its own, to try by hand. It seeds alice, bob and carol (`.test`, password `password`) and opens a Chromium window at the workspace. `just local --spaces` runs it on the spaces alpha, and `just local --ios` builds the iOS app for a simulator and points it there. Run `just local-setup` once per checkout and Mac first. | ||
| ||
## Environment variables | ||
| ||
| Variable | Default | | | ||
| --- | --- | --- | | ||
| `HUD_PORT` | `8787` | The port HUD listens on. | | ||
| `HUD_BIND` | `::` | The address HUD listens on. | | ||
| `HUD_PUBLIC_URL` | `http://localhost:<port>` | The origin HUD is reached at. Blob URLs, the view's CSP and sign-in name it. | | ||
| `HUD_CACHE_DIR` | `./cache` (`/data` in the image) | Where HUD keeps resolved lexicons, audio blobs and apps' icons. | | ||
| `HUD_BLOB_CACHE_BYTES` | `2147483648` (2 GiB) | The most bytes of audio HUD keeps in the cache. It evicts the least recently used first. | | ||
| `HUD_CACHE_MEMORY_BYTES` | `67108864` (64 MiB) | About the most bytes the in-memory caches hold together (identities, lexicons, joins' records, counts, feed generators, saved feeds). Each cache gets its share. Past it, HUD drops the expired entries first, then those nearest their end. | | ||
| `HUD_DATA_DIR` | `HUD_CACHE_DIR` | Where HUD keeps sign-in's client key, sessions and registered clients (under `oauth/`), the workspace's canvases (under `canvas/`) and each person's theme (under `theme/`). Each file has mode 0600. | | ||
| `HUD_OAUTH` | `on` when `HUD_PUBLIC_URL` is `https`, else `off` | With `off` there are no sign-in endpoints, no write or canvas tools and no workspace, and HUD makes every call as no one. `on` needs an `https` public URL. | | ||
| `HUD_OAUTH_SCOPE` | `atproto transition:generic` | The atproto scope HUD asks of accounts' servers. Add `transition:chat.bsky` for Bluesky chats ([sign-in](sign-in.md)). | | ||
| `HUD_SPACES` | `off` | With `on`, HUD keeps each person's canvases in spaces on their own PDS where it offers them and their sign-in allows it ([the workspace](workspace.md)). HUD then asks for `space:place.hud.workspace?authority=*&manage=create&manage=update&manage=delete` besides `HUD_OAUTH_SCOPE`. Publish that space type first, because a PDS refuses every sign-in asking for a type it can't resolve (`invalid_scope`). It needs sign-in on. | | ||
| `HUD_PLC_URL` | `https://plc.directory` | The PLC directory. | | ||
| `HUD_HANDLE_RESOLVER` | unset | An origin whose `com.atproto.identity.resolveHandle` resolves handles in place of DNS and `/.well-known/atproto-did`, such as a local PDS's for tests. | | ||
| `HUD_ALLOW_PRIVATE` | unset | `1` lets outbound requests reach plain `http` and private addresses. Use it for development only. | | ||
| `HUD_BACKLINKS` | `constellation:https://constellation.microcosm.blue` | The backlink index that counts come from. Set `constellation:<url>`, or `none` for no counts. | | ||
| `HUD_FAVICONS` | `https://cardyb.bsky.app/v1/favicon?url=` | The favicon service HUD asks for apps' icons (`/icon/<domain>`). HUD adds a site's encoded URL to it, as Bluesky's link cards do. Set and empty, HUD asks nowhere. | | ||
| `HUD_IMAGE_CDN` | `https://cdn.bsky.app/img` | The image CDN that serves public records' images, at `<cdn>/<size>/plain/<did>/<cid>@jpeg` (Bluesky's renders any blob on the network). The blob proxy is their fallback. It never serves a space's images, a private answer's images or a GIF. Set and empty, HUD serves every image through the blob proxy. | | ||
| `HUD_RELAY` | `https://bsky.network` | The relay HUD asks which repositories hold people's workspace themes (`com.atproto.sync.listReposByCollection`), so a person can browse everyone's. Set and empty, HUD lists only one account's. | | ||
| ||
## The image | ||
| ||
Build it with `just image` (`Dockerfile`). It runs `hud serve` as uid 10001 and keeps the cache on the volume `/data`, so sign-ins and canvases live there too. | ||
docs/sign-in.mdnew+75−0
| @@ -0,0 +1,75 @@ | ||
--- | ||
title: Sign-in | ||
section: HUD | ||
order: 6 | ||
summary: How HUD signs a person in with OAuth, and what a signed-in account adds to feeds, chats and procedures. | ||
--- | ||
| ||
With sign-in on, HUD plays two OAuth roles, chained. To an MCP host it's the authorization server of its own `/mcp`. To the person's account server it's a confidential atproto OAuth client. | ||
| ||
A signed-in call to `/mcp` acts as the account. That's what lets HUD write records, tell feeds what the person reads, go by saved feeds' names, open chats and call procedures. | ||
| ||
## The OAuth flow | ||
| ||
HUD is the authorization server of its own `/mcp`, as MCP's authorization spec describes one. `/.well-known/oauth-protected-resource/mcp` names it, and `/.well-known/oauth-authorization-server` names its endpoints. | ||
| ||
1. A host names itself by a client ID metadata document (an `https://` `client_id`, fetched and kept an hour). Or it registers at `/oauth/register` (public clients, https or loopback redirect URIs). | ||
2. The host sends the person to `/oauth/authorize` with PKCE (S256) and `resource=<origin>/mcp`. | ||
3. HUD's sign-in page asks for their handle. HUD is a confidential atproto OAuth client to the account's server (`/oauth/client-metadata.json`, with its key at `/oauth/jwks.json`). It pushes the request (PAR, PKCE, DPoP, `private_key_jwt`) and sends the person there to sign in. | ||
4. Back at `/oauth/callback`, HUD checks the answer's `state` and `iss` and exchanges the code. It checks the account is the one named and resolves it again, since the authorization server of its PDS must be the one that answered. Then it keeps the session and sends the host its own code. | ||
5. The host exchanges that code at `/oauth/token` for HUD's tokens. | ||
| ||
HUD's tokens are opaque. The access token lasts an hour and the refresh token 30 days, rotated at each use. If a replaced refresh token is used again, HUD ends the session. `/oauth/revoke` ends a session and revokes its atproto refresh token too. | ||
| ||
## Calls made signed in | ||
| ||
A call to `/mcp` with HUD's access token belongs to the account. Writes go to its PDS with its DPoP-bound token. HUD refreshes that token when it expires or is refused, one refresh at a time, and a refused refresh ends the session. | ||
| ||
If a tool needs an account and is called without one, HUD answers HTTP 401 with `WWW-Authenticate: Bearer resource_metadata="…", scope="hud"`. A token that no longer works gets `error="invalid_token"`, so the host signs in. Tools that need no account answer as before. | ||
| ||
Results made signed in say `cacheScope: private`. If a PDS refuses for want of scope, the tool error names the scope to sign in with (`HUD_OAUTH_SCOPE`). | ||
| ||
## Feed interactions | ||
| ||
Signed in, a reporting feed view tells its feed what the person reads, as Bluesky's app does. It batches the items seen, the items opened and asks for more or less like an item, and sends them through `send_interactions`. | ||
| ||
HUD reads the feed's generator from the AppView (`app.bsky.feed.getFeedGenerator`, through the account's PDS, kept an hour). If the generator takes interactions, HUD sends them through the account's PDS to the generator's own service (`app.bsky.feed.sendInteractions`, `atproto-proxy: <did>#bsky_fg`). A feed that takes none gets `{ sent: 0, reason }`, so the view stops. | ||
| ||
## Saved feeds | ||
| ||
Signed in, the account's saved feeds go by name. HUD reads them from its preferences (`app.bsky.actor.getPreferences`, which its PDS answers). It uses `savedFeedsPrefV2`, else the older `savedFeedsPref`. The AppView names them (`app.bsky.feed.getFeedGenerators`), and HUD keeps them five minutes. | ||
| ||
`query app.bsky.feed.getFeed` takes `params.feed` as a feed's name where its at-uri goes. HUD matches the name ignoring case and spaces, else the one name that holds it. Otherwise it's a tool error listing the saved feeds, pinned first. `following` (or `timeline`, `home`) is the timeline, `app.bsky.feed.getTimeline`. | ||
| ||
`query app.bsky.feed.getFeedGenerators` takes `params.feeds` as `saved` or `pinned` for the account's own feeds, in their order. `views/bsky-feed-generators.json` draws them, and each card opens its feed. Signed out, either query asks the host to sign in. | ||
| ||
## Chats | ||
| ||
Signed in, with `transition:chat.bsky` in `HUD_OAUTH_SCOPE`, Bluesky chats go through the account's PDS to Bluesky's chat service (`atproto-proxy: did:web:api.bsky.chat#bsky_chat`). | ||
| ||
`views/bsky-chats.json` draws `chat.bsky.convo.listConvos`. Each row shows the chat's name or members, the last message and who sent it, and the unread count. Each chat in the list has Mark read, and each row opens `views/bsky-chat.json`. | ||
| ||
`views/bsky-chat.json` draws `chat.bsky.convo.getMessages` with `Messages`. It shows bubbles with the oldest at the top and the newest at the foot. The person's own messages sit on the right, and others' sit beside their faces from the answer's `relatedProfiles`. Earlier messages load at the top, and a box at the foot sends. | ||
| ||
### Starting a chat | ||
| ||
A person starts a chat from an account's profile. Its Message button opens `views/bsky-chat-with.json`, which calls `chat.bsky.convo.getConvoForMembers` (the one-to-one chat with them, made if there's none). It joins the latest 50 messages from `getMessages` and draws them as a conversation, with the box. It has no earlier pages, so open the chat from Chats for those. | ||
| ||
The button is a bundled view's `head` profile section (`profile: { head: true }`). It's drawn under the profile's head, untitled, for any account but the person's own, signed in. `views/bsky-chat-availability.json` asks `chat.bsky.convo.getConvoAvailability` whether the two can chat. It draws the button (a `Link` with `style: "button"`) only where they can. So there's none where sign-in doesn't ask for chat, on one's own profile, or for someone who takes no messages from them. | ||
| ||
## Procedures | ||
| ||
Writes beyond records are procedures that a bundled view calls, and only those. There are two: | ||
| ||
- An `Action`'s `call` (Mark read, `chat.bsky.convo.updateRead`). | ||
- A `Messages`' `send` (`chat.bsky.convo.sendMessage`). | ||
| ||
Each is `{ method, service, input }`. The input is a template of bindings: `{"$root": path}`, `{"$now": true}`, `{"$strongRef": path}` and, in `send`, `{"$text": true}` (what the person wrote). | ||
| ||
The server resolves it into the tree with the rest of the view (`_meta.ui`). That means an Action's `call` and Messages' `send`, each `{ method, service, input }`, from a trusted view only, and `send` only when signed in. The client stamps `$now` and `$text` and calls `call_procedure`. That tool sends a method of a service only if a bundled view calls it (`view::bundled_call`). So an inline view, the model or anyone else reaching the tool can't send anything more. | ||
| ||
HUD checks the input against the procedure's lexicon. It bundles one for every procedure a bundled view calls (`just lexicons` reads `views/`). It sends the call through the PDS with `atproto-proxy`, checks the answer against the output, and hands it back. It logs neither. | ||
| ||
A sent message shows at once, and HUD reads the conversation again so the message arrives as the view draws it. Messages are plain text only (no links or mentions detected). | ||
| ||
A trusted method view may name the one scope token its query needs (`"scope": "transition:chat.bsky"`). HUD offers it only where sign-in asks for that token. That covers the query tool's description, the instructions, the workspace's launchers and its app's page. If a sign-in was made before the token was asked for, the tool error names the scope to sign in again with. | ||
docs/tools.mdnew+132−0
| @@ -0,0 +1,132 @@ | ||
--- | ||
title: Tools | ||
section: HUD | ||
order: 2 | ||
summary: The MCP tools HUD serves, what each takes and answers, and how queries and writes are made. | ||
--- | ||
| ||
HUD serves its reads, writes and workspace as MCP tools. Seven of them read and need no sign-in. The rest only show up with sign-in on. | ||
| ||
`describe_repo`, `describe_app`, `list_records`, `get_record` and `query` draw their results on the server. Views are covered in [views](views.md). | ||
| ||
## The tools | ||
| ||
| Tool | Input | View | | ||
| --- | --- | --- | | ||
| `describe_repo` | `actor` (handle, DID, or `me`) | yes | | ||
| `describe_app` | `domain` (as `bsky.app`), `actor` (optional: handle, DID, or `me`) | yes | | ||
| `describe_collection` | `actor`, `collection` | no | | ||
| `describe_method` | `method` (a query's NSID) | no | | ||
| `list_records` | `actor`, `collection`, `limit` (25, ≤100 · a view's `pageSize`), `cursor`, `view` | yes | | ||
| `get_record` | `uri` (at-uri), `view` | yes | | ||
| `query` | `method`, `params`, `service` (`did:…#fragment` · a bundled view's by default), `cursor`, `view` | yes | | ||
| `create_record` | `collection`, `record`, `rkey` (signed in) | no | | ||
| `delete_record` | `uri` (signed in) | no | | ||
| `canvas_list` | `canvas` (signed in) | no | | ||
| `canvas_add` | `tool` (a read tool), `arguments`, `title`, `from` (a tile it is opened from), `after` (a tile it goes right of), `width`, `canvas` (signed in) | no | | ||
| `canvas_place` | `id`, `before` or `after` (a tile), `width`, `canvas` (signed in) | no | | ||
| `canvas_remove` | `id`, `canvas` (signed in) | no | | ||
| `canvas_create` | `name` (signed in) | no | | ||
| `send_interactions` | `feed` (a feed generator's at-uri), `interactions` (signed in · the view's alone) | no | | ||
| `call_procedure` | `method`, `service`, `input` (signed in · the view's alone, a procedure a bundled view calls) | no | | ||
| ||
The first seven read and need no sign-in. HUD lists the rest only with sign-in on. Two of them write as the signed-in account, and five keep the canvases of that account's [workspace](workspace.md). | ||
| ||
The last two are the view's, and HUD hides them from the model (`_meta.ui.visibility: ["app"]`). The view calls `send_interactions` to tell a feed what was read of it. It calls `call_procedure` for a procedure a bundled view calls, such as sending a chat message. | ||
| ||
### `me` | ||
| ||
With sign-in on, an actor can be `me`, meaning the signed-in account. That holds for a query's `params.actor` and an at-uri's authority too. Signed out, `me` asks the host to sign in. | ||
| ||
## Results | ||
| ||
A result's data is its `structuredContent`, and its `content` is a short summary. What only the view needs goes in `_meta`. | ||
| ||
For `describe_repo`, `describe_app`, `list_records`, `get_record` and `query`, `_meta` holds `ui`. That's the records or answer drawn as their view draws them. The server resolves it against the data into a tree of the catalog's components. While it does, it reads the view's bindings and holds its URLs to the view's origins. It also fetches a document's Bluesky posts and reads in the lexicon's fields and the verified handles of the DIDs named. The tree's `title` is the view's description. The clients (the view, the workspace and the iOS app) only draw that tree. With no view, they get the generic drawing. | ||
| ||
These five tools name the one UI resource, `ui://records/view/<hash>`. Its URI changes with every build of the view, so a host never keeps an old view for a newer server's results. | ||
| ||
Every result made signed in names the account in `_meta.viewer` (`{ did, handle }`). | ||
| ||
## `describe_repo` | ||
| ||
`describe_repo` is an account's universal profile, across the atmosphere's apps. | ||
| ||
An app is the domain behind an NSID, with its first two segments reversed. So `app.bsky.*` is bsky.app, `dev.knotless.*` is knotless.dev and `fm.plyr.*` is plyr.fm. HUD names an app as a bundled view of it names it (`"app": "Bluesky"`), and otherwise by its domain. The app's icon is its favicon (`/icon/<domain>`). | ||
| ||
### Its data | ||
| ||
The data holds four things: | ||
| ||
- the account's profile (its `app.bsky.actor.profile`, or null) | ||
- every collection it holds | ||
- the collections a bundled collection view draws (`views`) | ||
- the apps it uses (`apps`), each with its domain, name, icon and how many of its collections it holds, most first | ||
| ||
### Its tree | ||
| ||
The server builds the tree in this order: | ||
| ||
1. The profile, with banner, avatar, name, handle, bio and where its PDS is. | ||
2. The apps the account uses, each with its icon and name. Each opens the app's page with the account's part in it ([`describe_app`](#describe_app)). Past eight, there's a plain "+N more". | ||
3. Its recent activity. | ||
4. A section from each bundled view that adds one to profiles ([`profile`](views.md)) and whose app the account uses, in the views' order. Each section shows its app's icon, a title and "See all" over a few recent things, drawn by that view's own layout. | ||
| ||
HUD never shows collections directly. No chip, link or list opens an account's collections. An account with none reads "This repository has no records." | ||
| ||
### Recent activity | ||
| ||
Recent activity is the newest record of each collection a bundled view names an activity of. That's a collection view's `activity`, or the `activity` of a method view's `records` entry ([`activity` and `records`](views.md)). HUD takes at most 8 of these, in the apps' order. It reads them with `com.atproto.repo.listRecords` and no joins, and merges them newest first into at most 6 rows. | ||
| ||
Each row shows three things and opens the record: | ||
| ||
- the app's icon | ||
- what the account did, on one short line: the verb and the record's label as its summary reads it ("Posted “main's where the posts go”", or "Posted a post" with no label) | ||
- when, from its `createdAt` or else the TID of its record key (with neither, HUD leaves it out) | ||
| ||
With no activity, there's no section. | ||
| ||
### How sections are asked | ||
| ||
HUD asks for the sections and the activity all at once, as the person asking (signed in or not, as `query` and `list_records` are). Each gets 3 seconds. HUD leaves out one that fails or hasn't answered. | ||
| ||
The text names the person and what can be drawn of theirs. It never gives their bio or every collection. | ||
| ||
## `describe_app` | ||
| ||
`describe_app` is an app's page, by its domain. Its data is the domain, name and icon. With `actor`, it adds the account (`{ did, handle }`). | ||
| ||
The tree shows the app's icon, name and domain, and a link to its site. Then comes "Go to", the app's entry points. These are the `launch` of its bundled method views ([`launch`](views.md)), and each opens its query. | ||
| ||
With `actor`, the page adds "<name> here" ("Yours here" for the person asking). That's the account's profile sections of this app alone, asked as `describe_repo` asks them. HUD shows it only where the account has some. | ||
| ||
Signed out, HUD leaves out an entry point that needs an account. An app with no entry points and no section to show says it has nothing to open. Every client opens an app's page by calling `describe_app`. A bundled view can draw the page instead, as [app pages](app-pages.md) describes. | ||
| ||
## `describe_collection` and `describe_method` | ||
| ||
A model reads `describe_collection` before it writes a view. It answers with four things: | ||
| ||
- the collection's schema, with every lexicon description taken out | ||
- three sample records | ||
- the bundled view, if there is one | ||
- the component catalog | ||
| ||
`describe_method` does the same for a query. It gives the query's parameters and output with the defs they ref (three levels deep, at most 60), descriptions taken out. | ||
| ||
## `query` | ||
| ||
`query` calls an XRPC query, never a procedure. The method must resolve to a lexicon whose main def is a `query`. | ||
| ||
The call goes to a service named by a DID and the fragment of a service in its document (`did:web:api.bsky.app#bsky_appview`). The document gives the endpoint. HUD checks the params against the lexicon first, and the answer after, with the lexicon validation of the `atproto` crate. The answer may hold fields the lexicon doesn't name. Otherwise HUD refuses an answer that isn't what its lexicon says. | ||
| ||
Without sign-in, HUD makes the call as no one, so it only reads public data. A query that needs an account (`getTimeline`) asks the host to sign in. Signed in, the call goes through the account's own PDS, which calls the service for it (`atproto-proxy`, service auth). So personal queries answer. | ||
| ||
A service's error comes back as one line naming the error alone (`AuthMissing`). | ||
| ||
## Writes | ||
| ||
`create_record` writes a record to the signed-in account's own repository. The record must validate against its collection's lexicon, and that lexicon must resolve. HUD sets its `$type` to the collection. | ||
| ||
`delete_record` deletes one of the account's own records. It can't delete anyone else's. | ||
| ||
`create_record` answers `{ uri, cid }` and `delete_record` answers `{ uri }`. | ||
docs/views.mdnew+293−0
docs/workspace-api.mdnew+91−0
docs/workspace.mdnew+133−0
harness/docs.mjsnew+110−0
AGENTS.md+11−7
Justfile+2−1
README.md+34−917
951 lines changed: not loaded until asked for.