Skip to content
This repository was archived by the owner on Nov 15, 2026. It is now read-only.

feat(readd): the desktop mode, items.render and items.exportMarkdown (plan 0002 Phase 2) - #25

Merged
bketelsen merged 4 commits into
mainfrom
feat/readd-desktop-mode
Oct 28, 2026
Merged

bketelsen merged 4 commits into
mainfrom
feat/readd-desktop-mode

Conversation

@frostyard-machines

Copy link
Copy Markdown
Contributor

Plan 0002 Phase 2: readd's desktop mode (ADR-0008). This change is Go only: no shell, no web UI and no Flatpak.

What changes

  • readd -desktop: it serves only the private socket. It opens no lodge socket, serves no /content/ and no MCP, builds no notes client, and opens no TCP port.
    • Paths: state in $XDG_DATA_HOME/frostread; configuration in $XDG_CONFIG_HOME/frostread/frostread.json (READ_CONFIG wins).
    • Socket: $XDG_RUNTIME_DIR/app/org.frostyard.Frostread/frostread/readd.sock when FLATPAK_ID says so, else $XDG_RUNTIME_DIR/frostread/readd.sock. READ_SOCKET and --socket win.
    • The lock: flock on <state>/readd.lock. It also applies on lodge's host. A second readd exits with "another readd uses ".
    • The mode check: readd reads app.json after it takes the lock. When app.json names lodge, readd releases the lock and exits 0, and it does not open the database.
    • Flags: -log FILE rotates the log past 1 MiB, after readd takes the lock. -build prints the app-commit from /.flatpak-info.
    • Notes fields: one log line says that the notes fields have no effect on a desktop.
    • Stop order: the poller, the extraction workers and the blob sweep stop (WaitGroup) before the database closes and the lock is released.
  • status.build (optional) and daemon.shutdown (caller local; it stops readd through jsonrpc.AfterReply). In lodge mode daemon.shutdown answers unavailable, because systemd runs readd there.
  • items.render {id, scheme?} (callers local and session) uses the same renderer as the content route. Its page adds the CSP meta, and its encoded answer stays under 12 MiB. The order is: the page with no images, then images in document order while they fit, then a measure of the final answer with a fallback. A new error tooLarge (1006).
  • items.exportMarkdown {id} (caller local): the Markdown of a note, without the read_item marker and without the "Open in Read" link.
  • readctl: -desktop, shutdown, and status prints the build.
  • Docs: specs/api.md gets a "Desktop mode" section, a section on rendering and a section on export. Also updated: the schema (schema/rpc/daemon.yaml is new), the design overview, AGENTS.md and the plan's status.

Tests (Phase 2 "Done when")

  • readd -desktop with a temporary XDG tree and FLATPAK_ID serves rpc.hello and status on the derived socket. It polls an httptest feed served on a Unix socket.
  • A second readd fails with "another readd uses". With app.json that names lodge, readd returns nil and no frostread.db exists. After daemon.shutdown, readd returns nil and the lock is free.
  • From /proc/self/fd and /proc/self/net/*: no TCP or UDP socket of the process listens, and the only Unix listeners are the private socket and the test's own feed socket.
  • items.render:
    • 20 MiB of images give an answer under 12 MiB, with the right omittedImages.
    • Text heavy with quotes, backslashes and control characters.
    • One image repeated many times.
    • The tooLarge boundary at exactly the limit.
    • An image that the store never held shows as its alt text and is not counted.
    • A golden test holds the lodge page and the desktop page: they differ only by the CSP meta.
  • make check, make race and make cross pass locally.

Notes

  • web/src/rpc/testdata/items.render.json is a new golden. Phase 3 adds its TypeScript type. No web code changes.
  • Plan 0002's "Done when" is not ticked. Phase 2 is "in review".

…(plan 0002 Phase 2)

readd -desktop is the Flatpak's own readd (ADR-0008): only its private
socket, the XDG state and configuration, the socket under
$XDG_RUNTIME_DIR/app/org.frostyard.Frostread when FLATPAK_ID says so, a
flock on <state>/readd.lock (on lodge's host too), the app.json mode check
under it, -log with rotation past 1 MiB, -build, status.build and
daemon.shutdown. readctl gains -desktop and shutdown.

One renderer serves lodge's content route and items.render, which adds
the CSP meta and keeps the encoded answer under 12 MiB (tooLarge, 1006).
items.exportMarkdown gives a note's Markdown without its marker and link.
… render bound states its id allowance

The lock and database checks used XDG_DATA_HOME instead of the state
directory readd derives in it. The envelope allowance holds an id of up
to 990 bytes, which the kit does not hand a handler; the spec says so,
and a socket test measures the whole answer's line near the bound.
…llowance

The kit hands a handler no request id, so items.render cannot count a long
one. Every connection now refuses a request whose encoded id is longer
than 990 bytes with invalidRequest and id null, before dispatch, so every
answer stays under the 12 MiB bound (ADR-0008).
Step 1 measured the no-image page with omittedImages 0, but the fallback
answers it with every stored image counted, whose digits are on the wire
too. Step 1 now measures that answer, and an exact-boundary test with 100
omitted images and a 990-byte id holds it. The spec limits the 12 MiB
statement to items.render.
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Oct 28, 2026
@bketelsen
bketelsen merged commit 9804a23 into main Oct 28, 2026
5 checks passed
@bketelsen
bketelsen deleted the feat/readd-desktop-mode branch October 28, 2026 15:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants