Seed Exact has one entry point for links: the doc route, /d/:ref. An hm:// link from the system, a pasted site URL, a link inside a document and a tool row in an agent chat all become a location under /d/. This page follows a link from the operating system to a loaded page.
The hm scheme
app.json declares one protocol handler:
"protocol_handlers": [{"protocol": "hm", "url": "/d/%s"}]Exact registers the scheme in the native Apple bundle. %s is the complete incoming URL encoded as a URI component (reference.md). So hm://z6Mk.../notes?v=abc#blk launches the app at /d/hm%3A%2F%2Fz6Mk..., and the doc route's ref parameter is the whole URL. A cold link is the launch location. A warm link fires the root's navigate handler, which is follow.
A ref can be a URL
The ref parameter therefore has two forms, and the data module accepts both:
Form | Example | Handled by |
|---|---|---|
Plain ref |
|
|
Whole URL |
|
|
linkOfRef returns the URL when the ref starts with a scheme, decoding once if it arrived percent-encoded. resolveLink turns it into a ref: hm:// and /hm/ URLs directly through refFromUrl, and a site page such as https://host/a/b by asking that site for its home account (GET <origin>/hm/api/config, registeredAccountUid). When a page is loaded from a web URL, buildPage switches to that URL's origin as the server (linkServer), and the resulting DocPage.server records it. Parsing details are in Read: ids, refs and link targets, and the typed entry form in Read: open a site by URL.
Reader context server
Because a page can come from a server other than the configured one, the root tracks a reader context (lines 95-97):
readContextRef is the ref of the last read or doc entry on the read stack, or a thread opened from Activity.
readContextServer is the server of the loaded page with that ref, falling back to the configured server.
Directory, authors, discussions and comment posts all use readContextServer, so a visitor reading https://other.site/page sees that site's directory and comments without changing their account's server setting.
readScopedHref
Links inside a loaded page are plain in-app hrefs such as /d/<uid>%2Fpath. Followed as they are, they would load from the configured server. readScopedHref rewrites them (one line in the source, wrapped here):
fn readScopedHref(url: string, server: string): string =
url.startsWith("/d/") and not url.slice(3).toLowerCase().includes("%3a%2f%2f")
? `/d/${encodeURIComponent(`${server}/hm/`)}${url.slice(3)}`
: urlA /d/ href whose parameter is not already a URL is prefixed with <server>/hm/, making it a whole web URL that resolveLink reads back and loads from that server. Hrefs that already carry a scheme (%3a%2f%2f is an encoded ://) and all other paths pass through. It is applied in follow and in readDirOpen, both with readContextServer.
flowchart TD
os["System opens hm:// link"] --> ph["protocol_handlers: /d/%s"]
tap["Link tapped in a document"] --> fol["follow: readScopedHref with readContextServer"]
typed["URL typed in open-site sheet"] --> open["readOpenSite validates"]
ph --> doc["doc route, ref is a URL"]
fol --> doc
open --> doc
doc --> res["readDocs: linkOfRef, resolveLink"]
res --> page["DocPage with its server"]What is not handled
Only the hm scheme is registered. https:// universal links are not declared in app.json, so a web URL reaches the app only when typed, pasted or tapped inside it (verified in app.json; no associated domains entry exists).
refFromUrl returns no ref for static /hm/ paths such as api, download, connect and register.
Tests
src/read/__tests__/deep-links.test.ts covers the parsing, and open-site.test.contract the typed entry and server scoping. See Bun unit tests and Contract UI tests.
User stories
The code described here exists to deliver these stories. Each story lists this page in its Trace (traceability).
US-READ-03 Follow links between documents: The doc route as the one entry point; readScopedHref
US-READ-04 Open a Seed site by URL: The typed URL becomes the doc route's ref
US-READ-05 Open an hm:// link from outside the app: The hm protocol handler, the URL-as-ref form, resolveLink and what is not handled
US-READ-06 Keep reading another site in place: Reader context server and readScopedHref
US-READ-07 Browse and search a space's documents: readDirOpen scopes the row's href to the context server
US-READ-11 Share a document: The /hm/ gateway form the shared URL uses, which the app can also read back
US-AGENT-10 Open documents and links an agent refers to: hm:// handling in the app
US-APP-02 Move around the app without losing my place: How hm:// links and web URLs reach the document route
US-TEAM-04 Understand how the app is built: How links reach the document route
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime